File: //home/cafsindia/.trash/application.1/controllers/Previous_company_income.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Previous_company_income extends Action_controller{
public function __construct(){
parent::__construct('Previous_company_income');
//$this->collect_base_info();
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$this->page_info();
$data['encKey'] = $this->generateKey();
$data['quick_link'] = $this->quick_link;
$data['master_pick'] = $this->master_pick;
$data['fliter_list'] = $this->fliter_list;
$data['freeze_list'] = $this->freeze_list;
$data['table_head'] = $this->get_previous_company_headerss();
$this->load->view("$this->control_name/manage",$data);
}
function get_previous_company_headerss(){
// $CI =& get_instance();
$headers = array(
array('label_name'=>'employee_code','view_name'=>"Employee Code",'field_type'=>1,'date_type'=>0),
array('label_name'=>'emp_name','view_name'=>"Employee Name",'field_type'=>1,'date_type'=>0),
array('label_name'=>'date_of_joining','view_name'=>"Date of Joining",'field_type'=>4,'date_type'=>1),
array('label_name'=>'previous_tax','view_name'=>"Tax",'field_type'=>2,'date_type'=>0)
//array('trans_status'=>"Process Status")
);
return $headers;
// return transform_headers($headers);
}
//LOAD TABEL WITH FILTERS
public function search(){
$dec_data = $this->cryptoDecrypt($_POST['Payload']);
$_POST = $dec_data['data'];
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..'));
exit(0);
}
$this->search_info();
$draw = $this->input->post('draw');
$start = $this->input->post('start');
$per_page = $this->input->post('length');
$order = $this->input->post('order');
$order_col = $this->input->post('columns');
$search = $this->input->post('search');
$column = $order[0]['column'];
$order_sor = $order[0]['dir'];
$order_col = $order_col[$column]['data'];
$search = trim($search['value']);
$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");
$common_search = ' or cw_previous_company_income.employee_code like "%'.$search.'%" or cw_previous_company_income.previous_tax like "%'.$search.'%" or cw_employees.emp_name like "%'.$search.'%" or cw_employees.date_of_joining like "%'.$search.'%"';
if($common_search){
$common_search = ltrim($common_search,' or ');
$common_search = " and ($common_search)";
$common_search = str_replace("(,","(",$common_search);
$common_search = str_replace("()","(0)",$common_search);
}
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();
}
}
$count_all_query = 'select count(*) as allcount from cw_previous_company_income inner join cw_employees on cw_employees.employee_code=cw_previous_company_income.employee_code where cw_employees.trans_status = 1 '.$common_search.'';
$search_total = $this->db->query($count_all_query);
$search_total_info = $search_total->result();
$total_count = $search_total_info[0]->allcount;
$count_query = 'select count(*) as allcount from cw_previous_company_income inner join cw_employees on cw_employees.employee_code=cw_previous_company_income.employee_code';
$count_query .= ' where financial_setting_id = "'.$financial_setting_id.'" and cw_employees.trans_status = 1 '.$common_search.'';
$search_count = $this->db->query($count_query);
$search_info = $search_count->result();
$filtered_count = $search_info[0]->allcount;
$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 '.$common_search.'';
if((int)$per_page !== -1){
$previous_tds_qry .= " LIMIT $start,$per_page";
}
$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("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $data_rows));
}
public function update_previous_tax(){
//Encryption
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$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
//IMPORT FILE VIEW INFORMATION
public function import(){
$data['encKey'] = $this->generateKey();
$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);
}
//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 = \PhpOffice\PhpSpreadsheet\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));
}
}
?>