MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/hrms_patroniss_com/application/controllers/Declartion_entry.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
	require_once("Action_controller.php");
	class Declartion_entry  extends Action_controller{
		
		public function __construct(){
			parent::__construct('declartion_entry');
			if(!$this->Appconfig->isAppvalid()){
				redirect('config');
			}
			$this->collect_base_info();
		}
		
		// LOAD PAGE WITH TABLE DATA
		public function index(){
			$data['module_id']     = $this->control_name;
			$category_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
			$category_result = $category_info->result();
			$category_info->next_result();
			$category_list[""] = "---- Category For ----";
			foreach($category_result as $for){
				$cat_id                 = $for->prime_category_id;
				$category_name          = $for->category_name;
				$category_list[$cat_id] = $category_name;
			}
			$data['category_list']  = $category_list;
			
			$temp_format_qry = 'select prime_inc_temp_setting_id,template_name from cw_inc_temp_setting where trans_status = 1 and module_id="'.$this->control_name.'"';
			$temp_format   = $this->db->query("CALL sp_a_run ('SELECT','$temp_format_qry')");
			$temp_result   = $temp_format->result();
			$temp_format->next_result();
			$temp_format_drop[""] = "---- Template Format ----";
			foreach($temp_result as $template){
				$temp_format_id = $template->prime_inc_temp_setting_id;
				$template_name  = $template->template_name;
				$temp_format_drop[$temp_format_id] = $template_name;
			}
			$data['temp_format_drop'] = $temp_format_drop;
			$data['financial_info'] = $this->financial_info;
			$this->load->view("$this->control_name/manage",$data);
		}
				
		//IMPORT FILE VIEW INFORMATION
		public function import(){
			$data['module_id']     = $this->control_name;		
			$excel_format_qry = 'select prime_excel_format_id,excel_name from cw_util_excel_format where excel_module_id = "'.$this->control_name.'" and trans_status = 1';
			$excel_format   = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
			$excel_result    = $excel_format->result();
			$excel_format->next_result();
			$excel_format_drop[""] = "---- Excel Format ----";
			foreach($excel_result as $excel){
				$prime_excel_format_id = $excel->prime_excel_format_id;
				$excel_name            = $excel->excel_name;
				$excel_format_drop[$prime_excel_format_id] = $excel_name;
			}
			$data['excel_format_drop'] = $excel_format_drop;
			
			$temp_format_qry = 'select prime_inc_temp_setting_id,template_name from cw_inc_temp_setting where trans_status = 1 and module_id="declartion_entry"';
			$temp_format   = $this->db->query("CALL sp_a_run ('SELECT','$temp_format_qry')");
			$temp_result   = $temp_format->result();
			$temp_format->next_result();
			$temp_format_drop[""] = "---- Template Format ----";
			foreach($temp_result as $template){
				$temp_format_id = $template->prime_inc_temp_setting_id;
				$template_name  = $template->template_name;
				$temp_format_drop[$temp_format_id] = $template_name;
			}
			$data['temp_format_drop'] = $temp_format_drop;
			
			$this->load->view("$this->control_name/manage",$data);
		}
		
		public function excel($module_id,$excel_format){
			/* //category = "'.$category.'" and
			$format_qry 	= 'select employee_code,column_name,column_map from cw_declaration_template where temp_name = "'.$excel_format.'" and trans_status = 1';
			$format_data    = $this->db->query("CALL sp_a_run ('SELECT','$format_qry')");
			$format_result  = $format_data->result();
			$format_data->next_result(); */
			
		$excel_format_qry = 'select excel_line_column_name,excel_line_value from cw_util_excel_format_line where excel_line_module_id = "'.$module_id.'" and prime_excel_format_id ="'.$excel_format.'" and trans_status = 1';
		$excel_format   = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
		$excel_result    = $excel_format->result();
		$excel_format->next_result();
		require_once APPPATH."/third_party/PHPExcel.php";
		$obj = new PHPExcel();		
		//Set the first row as the header row
		foreach($format_result as $excel){
			$excel_line_column_name = $excel->excel_line_column_name;
			$excel_line_value       = $excel->excel_line_value;
			$obj->getActiveSheet()->setCellValue($excel_line_value."1", $excel_line_column_name);
		}		
		// Rename worksheet name
		 $filename= $module_id.".xls"; //save our workbook as this file name
		 header('Content-Type: application/vnd.ms-excel'); //mime type
		 header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		 header('Cache-Control: max-age=0'); //no cache
		 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		 //if you want to save it as .XLSX Excel 2007 format
		 $objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel5');
		 //force user to download the Excel file without writing it to server's HD
		 $objWriter->save('php://output');
		echo json_encode(array('success' => TRUE, 'output' => $excelOutput));
	}
		
		
		//UPDATE STATUS TO DELETE FOR UPLOAD FILES or DOCUMENTS
		public function remove_file(){
			$prime_id_val  = $this->input->post('prime_id_val');
			$is_defult     = (int)$this->input->post('is_defult');
			$input_name     = $this->input->post('input_name');
			$table_name = '';
			if($is_defult === 1){
				$table_name = $this->prime_table;
			}else
			if($is_defult === 2){
				$table_name = $this->cf_table;
			}
			if($table_name){
				$created_on    = date("Y-m-d h:i:s");
				$set_query     = $input_name .' = "" ,trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
				$update_query  = 'UPDATE '.$table_name .' SET '. $set_query .' WHERE '. $this->prime_id .' = "'. $prime_id_val .'"';
				$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
				echo json_encode(array('success' => TRUE, 'message' => "Successfully updated"));
				}else{
				echo json_encode(array('success' => FALSE, 'message' => "Unable to process your request"));
			}
		}
		
		//Sheet Name display in import page
		public function sheet_name(){
			$file_path  = $this->input->post('file_path');
			$filename = dirname(__FILE__)."/php_excel/PHPExcel/IOFactory.php";
			include($filename);
			$excel_obj   = PHPExcel_IOFactory::load($file_path);
			$sheet_count = $excel_obj->getSheetCount();
			$sheet_name = array();
			for($i= 0; $i< $sheet_count; $i++){
				$sheet        = $excel_obj->getSheet($i);
				$sheet_name[] = $sheet->getTitle();
			}
			echo json_encode(array('sheet_name' =>$sheet_name));
		}
		
		//category based employee list -- 27AUG2019
		public function get_employee_list(){
			$category = $this->input->post('category');
			$emp_query  = 'SELECT * FROM cw_employees WHERE role = "'.$category.'" and trans_status =1';
			$emp_info   = $this->db->query("CALL sp_a_run ('SELECT','$emp_query')");
			$emp_result = $emp_info->result();
			$emp_info->next_result();
			$emp_list = "<option value=''>---- Select Employee ----</option>";
			foreach($emp_result as $result){
				$name      = $result->emp_name;
				$emp_code  = $result->employee_code;
				$emp_list .= "<option value='$emp_code'>$emp_code - $name</option>";
			}
			echo $emp_list;
		}
		
		//section and subsection details
		public function get_sec_sub_list(){
			$tax_section_qry  = 'select cw_tax_section.tax_section,tax_act_details,tax_subsection_column  from cw_tax_section inner join cw_tax_sub_section on cw_tax_sub_section.tax_section = cw_tax_section.prime_tax_section_id where cw_tax_sub_section.trans_status = 1  and ((cw_tax_sub_section.tax_section = 1 AND bill_required = 1) OR (cw_tax_sub_section.tax_section != 1)) order by cw_tax_section.tax_order';
			//and prime_tax_sub_section_id != (select tax_sub_section from cw_section_matching where cw_section_matching.trans_status = 1)  and
			//echo $tax_section_qry; die;
			$tax_section_info   = $this->db->query("CALL sp_a_run ('SELECT','$tax_section_qry')");
			$tax_section_result = $tax_section_info->result();
			$tax_section_info->next_result();
			$tr_line = "";
			foreach($tax_section_result as $tax_rslt){
				$subsec_column_name   =  $tax_rslt->tax_subsection_column;
				$tax_section_head     =  $tax_rslt->tax_section;
				$tax_subsection_head  =  $tax_rslt->tax_act_details;
				$tr_line .= "<tr><td>".$tax_section_head."</td><td>".$tax_subsection_head."</td><td><input type='text' id='".$subsec_column_name."' name='".$subsec_column_name."' value ='0'/></td></tr>";
			}
			$table_info = "<table class='table table-bordered'>
			<thead>
			<tr>
			<th>Tax Section</th>
			<th>Tax Subsection</th>
			<th>Yearly Value</th>
			</tr>
			</thead>
			<tbody>
			<tr>
			<td>House Rent Paid (Annual)</td>
			<td></td>
			<td><input type='text' id='tax_house_rent' name='tax_house_rent' value='0' class='number'/></td>
			</tr>
			<tr>
			<td>No of Children Eligible for Education</td>
			<td></td>
			<td><input type='text' id='childran_elig' name='childran_elig' value='0' class='number'/></td>
			</tr>
			$tr_line
			</tbody>
			</table>";
			echo $table_info;
		}
		
		public function save_section(){
			$declaration_data = json_decode($this->input->post('declaration_data'));
			$created_on = date("Y-m-d H:i:s");
			$finacial_setting_id = $this->financial_info[0]->prime_financial_setting_id;
			$prime_qry_key   = '';
			$prime_qry_value = '';
			if(!empty($declaration_data)){
				foreach($declaration_data as $entry_data){
					$column_name      = $entry_data->name;
					$column_value     = $entry_data->value;
					if($column_name === "effective_month"){
						$column_value = $entry_data->value;
						$month_exit   = $column_value;
					}
					if($column_name === "emp_code"){
						$emp_code = $column_value;
					}
					$prime_qry_key   .= $column_name.",";
					$prime_qry_value .= '"'.$column_value.'",';
					
					$update_qry_key     .= $column_name.",";
					$update_qry_value   .= '"'.$column_value.'",';
					$update_upd_query   .= $column_name.' = "'.$column_value.'",';
					
				}
				$tax_process_exit_qry   = 'select count(*) as rslt_count from cw_tax_calculation where emp_code="'.$emp_code.'" and process_month="'.$month_exit.'" and trans_status =1';
				$tax_process_exit_info   = $this->db->query("CALL sp_a_run ('SELECT','$tax_process_exit_qry')");
				$tax_process_exit_result = $tax_process_exit_info->result();
				$tax_process_exit_info->next_result();
				$tax_exit_count = $tax_process_exit_result[0]->rslt_count;
				if((int)$tax_exit_count === 1){
					echo json_encode(array('success' => false, 'message' => "Already Tax Proceed, Please Delete the tax process?"));
					exit();
				}else{
					$exit_emp_qry   = 'select count(*) as rslt_count from cw_declaration_entry where finacial_setting_id="'.$finacial_setting_id.'" and emp_code="'.$emp_code.'" and effective_month="'.$month_exit.'" and trans_status =1';
					$exit_emp_info   = $this->db->query("CALL sp_a_run ('SELECT','$exit_emp_qry')");
					$exit_emp_result = $exit_emp_info->result();
					$exit_emp_info->next_result();
					$rslt_count = $exit_emp_result[0]->rslt_count;
					if((int)$rslt_count === 0){
						$prime_qry_key     .= "finacial_setting_id,trans_created_by,trans_created_date";
						$prime_qry_value   .= '"'.$finacial_setting_id.'","'.$this->logged_id.'",'.'"'.$created_on.'"';
						$dec_entry_insert_qry = "insert into cw_declaration_entry ($prime_qry_key) values ($prime_qry_value)";
						$dec_entry_insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$dec_entry_insert_qry')");
						$dec_entry_insert_result      = $dec_entry_insert_info->result();
						$dec_entry_insert_info->next_result();
						echo json_encode(array('success' => true, 'message' => "Successfully added your declaration entry"));
					}else{
						$update_upd_query     .= 'trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
						$update_query  = 'UPDATE cw_declaration_entry SET '. $update_upd_query .' WHERE finacial_setting_id = "'. $finacial_setting_id .'" and emp_code = "'. $emp_code .'" and effective_month = "'. $month_exit .'"';
						$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
						echo json_encode(array('success' => true, 'message' => "Successfully data is updated!!!"));
					}
				}
			}
		}
		
		public function update_section(){
			$category            = $this->input->post('category');
			$emp_code            = $this->input->post('emp_code');
			$effective_month     = $this->input->post('effective_month');
			
			$tax_section_qry  = 'select cw_tax_section.tax_section,tax_act_details,tax_subsection_column  from cw_tax_section inner join cw_tax_sub_section on cw_tax_sub_section.tax_section =cw_tax_section.prime_tax_section_id where cw_tax_sub_section.trans_status = 1 and prime_tax_sub_section_id NOT IN (select tax_sub_section from cw_section_matching where cw_section_matching.trans_status = 1)  and ((cw_tax_sub_section.tax_section = 1 AND bill_required = 1) OR (cw_tax_sub_section.tax_section != 1)) order by cw_tax_section.tax_order';
			$tax_section_info   = $this->db->query("CALL sp_a_run ('SELECT','$tax_section_qry')");
			$tax_section_result = $tax_section_info->result();
			$tax_section_info->next_result();
			$tr_line = "";
			foreach($tax_section_result as $tax_rslt){
				$subsec_column_name   =  $tax_rslt->tax_subsection_column;
				$tax_section_head     =  $tax_rslt->tax_section;
				$tax_subsection_head  =  $tax_rslt->tax_act_details;
				$finacial_setting_id = $this->financial_info[0]->prime_financial_setting_id;
				//echo "BSK $finacial_setting_id :: $emp_code::$effective_month";
				$collect_dec_entry_qry   = 'select '.$subsec_column_name.',tax_house_rent,childran_elig,tax_senior_citizen from cw_declaration_entry where finacial_setting_id="'.$finacial_setting_id.'" and emp_code="'.$emp_code.'" and effective_month="'.$effective_month.'" and trans_status =1';
				$collect_dec_entry_info   = $this->db->query("CALL sp_a_run ('SELECT','$collect_dec_entry_qry')");
				$collect_dec_entry_result = $collect_dec_entry_info->result();
				$collect_dec_entry_info->next_result();
				if($collect_dec_entry_result){
					$subsec_column_val   = $collect_dec_entry_result[0]->$subsec_column_name;
					$tax_house_rent      = $collect_dec_entry_result[0]->tax_house_rent;
					$childran_elig       = $collect_dec_entry_result[0]->childran_elig;
					$tax_senior_citizen  = $collect_dec_entry_result[0]->tax_senior_citizen;
				}else{
					$subsec_column_val  = 0;
					$tax_house_rent     = 0;
					$childran_elig      = 0;
					$entry_id           = 0;
					$tax_senior_citizen = 0;
				}
				$tr_line .= "<tr><td>".$tax_section_head."</td><td>".$tax_subsection_head."</td><td><input type='text' id='".$subsec_column_name."' name='".$subsec_column_name."' value ='".$subsec_column_val."' class='number'/></td></tr>";
			}
			$table_info = "<table class='table table-bordered'>
			<thead>
			<tr>
			<th>Tax Section</th>
			<th>Tax Subsection</th>
			<th>Yearly Value</th>
			</tr>
			</thead>
			<tbody>
			<tr>
			<td>House Rent Paid (Annual)</td>
			<td></td>
			<td><input type='text' id='tax_house_rent' name='tax_house_rent' value='$tax_house_rent' class='number'/></td>
			</tr>
			<tr>
			<td>No of Children Eligible for Education</td>
			<td></td>
			<td><input type='text' id='childran_elig' name='childran_elig' value='$childran_elig' class='number'/></td>
			</tr>
			$tr_line
			</tbody>
			</table>";
			echo json_encode(array('success' => True, 'table_info' => $table_info,'tax_senior_citizen'=>$tax_senior_citizen));
		}
		
		public function delete_section(){
			$category            = $this->input->post('category');
			$emp_code            = $this->input->post('emp_code');
			$effective_month     = $this->input->post('effective_month');
			$tax_process_exit_qry   = 'select count(*) as rslt_count from cw_tax_calculation where emp_code="'.$emp_code.'" and process_month="'.$effective_month.'" and trans_status =1';
			$tax_process_exit_info   = $this->db->query("CALL sp_a_run ('SELECT','$tax_process_exit_qry')");
			$tax_process_exit_result = $tax_process_exit_info->result();
			$tax_process_exit_info->next_result();
			$tax_exit_count = $tax_process_exit_result[0]->rslt_count;
			if((int)$tax_exit_count === 1){
				echo json_encode(array('success' => false, 'message' => "Already Tax Proceed, Please Delete the tax process?"));
				exit();
			}else{
				$created_on = date("Y-m-d H:i:s");
				$finacial_setting_id = $this->financial_info[0]->prime_financial_setting_id;
				$update_upd_query     .= 'trans_deleted_by = "'. $this->logged_id .'",trans_deleted_date = "'.$created_on.'"';
				if($effective_month){
					$update_query  = 'UPDATE cw_declaration_entry SET trans_status = 0, '. $update_upd_query .' WHERE finacial_setting_id = "'. $finacial_setting_id .'" and emp_code = "'. $emp_code .'" and effective_month = "'. $effective_month .'"';
					$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
					echo json_encode(array('success' => true, 'message' => "Deleted your data successfully!!!"));
				}
			}
		}
		
		public function check_template_details(){
			$category   = $this->input->post('category_name');
			$sel_format_qry = 'select prime_inc_temp_setting_id,template_name from cw_inc_temp_setting inner join cw_declaration_template on cw_declaration_template.temp_name=cw_inc_temp_setting.prime_inc_temp_setting_id where category = "'.$category.'"  and cw_declaration_template.trans_status= 1  group by template_name';
			$sel_format   = $this->db->query("CALL sp_a_run ('SELECT','$sel_format_qry')");
			$sel_result   = $sel_format->result();
			$sel_format->next_result();
			echo json_encode(array('success' => true, 'sel_result' => $sel_result));
		}
		
		//Import function start
		public function save_dec_import(){
			$category         = $this->input->post('category_name');
			$template_name    = $this->input->post('template_name');
			$apply_month      = $this->input->post('imp_effective_month');
			$excel_file_path  = $this->input->post('excel_file_path');
			$excel_sheet_name = $this->input->post('excel_sheet_name');
			$excel_start_row  = $this->input->post('excel_start_row');
			$excel_end_row    = $this->input->post('excel_end_row');
			$logged_id        = $this->session->userdata('logged_id');
			$today_date       = date("Y-m-d H:i:s");
			$import_query = 'insert into cw_inc_import (category,template_name,apply_month,excel_file_path,excel_sheet_name,excel_start_row,excel_end_row,trans_created_by,trans_created_date) value ("'.$category.'","'.$template_name.'","'.$apply_month.'","'.$excel_file_path.'","'.$excel_sheet_name.'","'.$excel_start_row.'","'.$excel_end_row.'","'.$logged_id.'","'.$today_date.'")';
			$import_info   = $this->db->query("CALL sp_a_run ('INSERT','$import_query')");
			$import_result = $import_info->result();
			$import_info->next_result();
			$import_id = $import_result[0]->ins_id;
			echo $this->do_excel_dec_import($import_id);
		}
		
		//import validation and checking updated
		public function do_excel_dec_import($import_id){
			$logged_id         = $this->session->userdata('logged_id');
			$filename          = dirname(__FILE__)."/php_excel/PHPExcel/IOFactory.php";
			include($filename);
			if($import_id < 0){
				return json_encode(array('success' => false, 'message' => "Invalid file upload"));
			}
			
			$excel_path_qry    = 'select * from cw_inc_import where import_id = "'.$import_id.'"';
			$excel_path_info   = $this->db->query("CALL sp_a_run ('SELECT','$excel_path_qry')");
			$excel_path_result = $excel_path_info->result();
			$excel_path_info->next_result();
			if(!$excel_path_result){
				return json_encode(array('success' => false, 'message' => "Invalid file upload"));
				}else{
				$category           = $excel_path_result[0]->category;
				$excel_format       = $excel_path_result[0]->template_name;		
				$effective_month    = $excel_path_result[0]->apply_month;
				$excel_file_path    = $excel_path_result[0]->excel_file_path;			
				$excel_sheet_name   = (int)$excel_path_result[0]->excel_sheet_name;
				$excel_row_start    = (int)$excel_path_result[0]->excel_start_row;
				$excel_row_end      = (int)$excel_path_result[0]->excel_end_row;
				
				$format_qry 	= 'select employee_code,GROUP_CONCAT(column_name) as column_name, GROUP_CONCAT(column_map) as column_map from cw_declaration_template where temp_name = "'.$excel_format.'" and category = "'.$category.'" and trans_status = 1';
				$format_info    = $this->db->query("CALL sp_a_run ('SELECT','$format_qry')");
				$format_rslt    = $format_info->result();
				$format_info->next_result();
				$employee_code      = $format_rslt[0]->employee_code;
				$column_name        = explode(",",$format_rslt[0]->column_name);
				$column_map         = explode(",",$format_rslt[0]->column_map);
				$column_value       = array_combine($column_name,$column_map);
				if(!$format_rslt){
					return json_encode(array('success' => false, 'message' => "Please add excel format before import"));
					}else{
					try{
						$excel_obj = PHPExcel_IOFactory::load($excel_file_path);
						}catch(Exception $e){
						die('Error loading file "' . pathinfo($excel_file_path, PATHINFO_BASENAME). '": ' . $e->getMessage());
						return json_encode(array('success' => false, 'message' => "Invalid file or path"));
					}
					$sheet          = $excel_obj->getSheet($excel_sheet_name);
					if($excel_row_end){
						$total_rows = $excel_row_end;
						}else{
						$total_rows = $sheet->getHighestRow();
					}
					$created_on         = date("Y-m-d h:i:s");
					$fin_id = $this->financial_info[0]->prime_financial_setting_id;
					$primary_column_key = "";
					$primary_column_val = "";
					$status_array	 = array();
					$error_array	 = array();
					for($row = $excel_row_start; $row <= $total_rows; $row++){//validation purpose
						$employee_code_val  = trim($sheet->getCell("$employee_code$row")->getCalculatedValue());
						$emp_exist_query = 'select count(*) as emp_exist_count from cw_employees where trans_status = 1 and employee_code ="'.$employee_code_val.'" and role ="'.$category.'"';
						$emp_exist_info   = $this->db->query("CALL sp_a_run ('RUN','$emp_exist_query')");
						$emp_exist_result = $emp_exist_info->result();
						$emp_exist_info->next_result();
						$emp_exist_count = $emp_exist_result[0]->emp_exist_count;
						if((int)$emp_exist_count === 0){
							$error_array["$employee_code$row"] = "Invalid employee code";
						}
					}
					$status_count_info = count($error_array);
					if((int)$status_count_info > 0){
						$table_info = $this->get_excel_import_error_sts($error_array);
						return json_encode(array('success'=>False,'message'=>"Please check your excel file",'table_info'=>$table_info));
						exit();
						}else{
							for($row = $excel_row_start; $row <= $total_rows; $row++){
								$employee_code_val  = trim($sheet->getCell("$employee_code$row")->getCalculatedValue());
								$primary_column_key = "category,emp_code,effective_month,finacial_setting_id,trans_created_by,trans_created_date,";
								$primary_column_val = '"'.$category.'","'.$employee_code_val.'","'.$effective_month.'","'.$fin_id.'","'.$this->logged_id.'",'.'"'.$created_on.'",';
								foreach($column_value as $column_name_key => $column_name_val){
									$column_val          = $column_value[$column_name_key];
									$column_name_value   = trim($sheet->getCell("$column_val$row")->getCalculatedValue());
									$primary_column_key  .= $column_name_key.",";
									$primary_column_val  .= '"'.$column_name_value.'",';
								}					
								$exist_query = 'select count(*) as exist_count from cw_declaration_entry where trans_status = 1 and emp_code ="'.$employee_code_val.'" and effective_month ="'.$effective_month.'"';
								$exist_info   = $this->db->query("CALL sp_a_run ('RUN','$exist_query')");
								$exist_result = $exist_info->result();
								$exist_info->next_result();
								$exist_count = $exist_result[0]->exist_count;
								if((int)$exist_count === 0){
									$primary_column_key  = rtrim($primary_column_key,",");
									$primary_column_val  = rtrim($primary_column_val,",");
									$prime_dec_ent_qry      = "insert into cw_declaration_entry ($primary_column_key) VALUES ($primary_column_val)";
									$insert_info   = $this->db->query("CALL sp_a_run ('RUN','$prime_dec_ent_qry')");
									$sts = True;
									$sts_message = "Successfully file imported";
									$status_info['Status'] = "Inserted to DB";
									}else{
										$sts = False;
										$sts_message = "Data already exit";
										$status_info['Status'] = "Already Exist in DB";
									}
								$status_array[] = $status_info;
							}
						}
					}
				}
			$table_info = $this->get_excel_import_sts($status_array);
			return json_encode(array('success'=>$sts,'message'=>$sts_message,'table_info'=>$table_info));
		}
		
		//import upload success table view
		public function get_excel_import_sts($status_array){
			$table_info = "";
			$th_line = "";
			$tr_line = "";		
			$count = 0;
			foreach($status_array as $status){
				$count++;
				$status_array_count  = count($status);
				$status_count = 0;
				foreach($status as $key => $value){
					$status_count++;
					if((int)$count === 1){
						$th_line .= "<th style='text-align:center !important;'>Si.No</th><th style='text-align:center !important;'>Column Status</th>";
					}
					$td_line .= "<td>$count</td><td>$value</td>";
					if((int)$status_count === (int)$status_array_count){
						$color = "style='color:#15da15 !important;'";
						if($value === "Already Exist in DB"){
							$color = "style='color:#ff0303 !important;'";
						}
						$tr_line .= "<tr $color>$td_line</tr>";
						$td_line = "";
					}
				}
			}
			if($th_line !== ""){
				$table_info = "<table class='table table-bordered' style='text-align:center;'>
								<thead>
									<tr>
									$th_line
									</tr>
								</thead>
								<tbody>
								$tr_line
								</tbody>
								</table>";
			}
			return $table_info;
		}
		
		//import error table view
		public function get_excel_import_error_sts($error_array){
			$table_info = "";
			$th_line = "";
			$tr_line = "";		
			$count = 0;
			foreach($error_array as $key => $value){
				$th_line = "<th style='text-align:center !important;'>Column Name</th><th style='text-align:center !important;'>Column Status</th>";
				$tr_line .= "<tr style='color:#ff0303 !important;'><td>$key</td><td>$value</td></tr>";
			}
			if($th_line !== ""){
				$table_info = "<table class='table table-bordered' style='text-align:center;'>
								<thead>
									<tr>
									$th_line
									</tr>
								</thead>
									<tbody>
									$tr_line
									</tbody>
								</table>";
			}
			return $table_info;
		}
	}
?>