File: /home/cafsindia/hrms_patroniss_com/application/controllers/Previous_company_income.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Previous_company_income extends Base_controller{
public function __construct(){
parent::__construct('previous_company_income');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$this->collect_base_info();
}
// LOAD PAGE WITH TABLE DATA
public function index(){
$data['table_headers']= $this->xss_clean(get_previous_company_headers());
$this->load->view("$this->control_name/manage",$data);
}
public function search(){
$fin_default_qry = 'select * from cw_financial_setting where trans_status =1 and set_as_default_financial_year =1';
$fin_default_data = $this->db->query("CALL sp_a_run ('SELECT','$fin_default_qry')");
$fin_default_result = $fin_default_data->result();
$fin_default_data->next_result();
$fin_start_date = $fin_default_result[0]->start_date;
$fin_end_date = $fin_default_result[0]->end_date;
$financial_setting_id = $fin_default_result[0]->prime_financial_setting_id;
$emp_details_qry = 'select * from cw_employees where date_of_joining between "'.$fin_start_date.'" and "'.$fin_end_date.'" and trans_status = 1 and role !=1';
$emp_details_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_details_qry')");
$emp_details_result = $emp_details_info->result();
$emp_details_info->next_result();
$logged_id = $this->session->userdata('logged_id');
$today_date = date("Y-m-d H:i:s");
foreach($emp_details_result as $emp_rslt){
$employee_code = $emp_rslt->employee_code;
$prime_qry_key = "financial_setting_id,employee_code,trans_created_by,trans_created_date";
$prime_qry_value = '"'.$financial_setting_id.'","'.$employee_code.'","'.$logged_id.'","'.$today_date.'"';
$exit_count_qry = 'select count(*) as rslt_count from cw_previous_company_income where trans_status =1 and financial_setting_id = "'.$financial_setting_id.'" and employee_code = "'.$employee_code.'"';
$exit_count_info = $this->db->query("CALL sp_a_run ('SELECT','$exit_count_qry')");
$exit_count_result = $exit_count_info->result();
$exit_count_info->next_result();
$rslt_count = $exit_count_result[0]->rslt_count;
if((int)$rslt_count === 0){
$insert_fin_query = "insert into cw_previous_company_income ($prime_qry_key) value ($prime_qry_value)";
$insert_fin_info = $this->db->query("CALL sp_a_run ('INSERT','$insert_fin_query')");
$insert_fin_result = $insert_fin_info->result();
$insert_fin_info->next_result();
}
}
$previous_tds_qry = 'select * from cw_previous_company_income inner join cw_employees on cw_employees.employee_code=cw_previous_company_income.employee_code where financial_setting_id = "'.$financial_setting_id.'" and cw_employees.trans_status = 1';
$previous_tds_info = $this->db->query("CALL sp_a_run ('SELECT','$previous_tds_qry')");
$previous_tds_result = $previous_tds_info->result();
$num_rows_count = $previous_tds_info->num_rows();
$previous_tds_info->next_result();
$data_rows = array();
foreach ($previous_tds_result as $tds_rslt){
$data_rows[]=get_previous_company_data_row($tds_rslt,$this);
}
echo json_encode(array('total'=>$num_rows_count,'rows'=>$data_rows));
}
public function update_previous_tax(){
$pre_company_id = $this->input->post('pre_company_id');
$pre_tax = $this->input->post('pre_tax');
if($pre_company_id){
$update_query = 'UPDATE cw_previous_company_income SET previous_tax = "'. $pre_tax .'" WHERE prime_previous_company_income_id = "'. $pre_company_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
}
echo json_encode(array('success' => TRUE, 'msg' => "Successfully TDS is updated"));
}
//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;
$this->load->view("$this->control_name/import",$data);
}
public function rowset_remove_file(){
$table_name = $this->input->post('table_name_set');
$row_id = (int)$this->input->post('row_id');
$input_name = $this->input->post('input_name');
$view_id = (int)$this->input->post('view_id');
$primes_id = (int)$this->input->post('primes_id');
$remove_cw = str_replace("cw_","",$table_name);
$primary_id = "prime_".$remove_cw."_id";
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 '.$primary_id.' = "'. $row_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
$row_set_edit = $this->get_row_set_data($view_id,$primes_id);
$div_id = $row_set_edit['div_id'];
$table_id = $row_set_edit['table_id'];
$row_set_view = $row_set_edit['row_set_view'];
echo json_encode(array('success' => TRUE, 'message' => "Successfully updated",'div_id' => $div_id, 'table_id' => $table_id,'row_set_view'=>$row_set_view));
}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));
}
}
?>