File: /home/cafsindia/cpaqua.cafsinfotech.in/dump/ZRM/application/controllers/Monthly_input_posting.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Monthly_input_posting extends Action_controller{
public function __construct(){
parent::__construct('monthly_input_posting');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$role_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id != 1')");
$role_result = $role_info->result();
$role_info->next_result();
$category_list[""] = "---- Select Category ----";
foreach ($role_result as $for) {
$role_id = $for->prime_category_id;
$category_name = $for->category_name;
$category_list[$role_id] = $category_name;
}
$data['category_list'] = $category_list;
$this->load->view("$this->control_name/manage",$data);
}
public function mi_posting(){
$process_month = $this->input->post('process_month');
$category = $this->input->post('category');
$process_type = (int)$this->input->post('process_type');
$process_emp_code = $this->input->post('process_emp_code');
$date = DateTime::createFromFormat('m-Y', $process_month);
$date->modify('-1 month');
$previousMonth = $date->format('m-Y');
$fandf_processed_emp_qry = 'select employee_code from cw_transactions where process_month="'.$previousMonth.'" and termination_status = 1 and fandf = 1';
$fandf_emp_info = $this->db->query("CALL sp_a_run ('SELECT','$fandf_processed_emp_qry')");
$fandf_emp_result = $fandf_emp_info->result();
$fandf_emp_info->next_result();
$fandf_employees = array_column($fandf_emp_result,"employee_code");
$fandf_emp = implode('","',$fandf_employees);
$where_query = "";
if($process_type === 1){
$where_query = ' and employee_code = "'.$process_emp_code.'" ';
}else
if($process_type === 2){
$where_query = ' and role = "'.$category.'"';
}
$posting_lock_qry = 'SELECT COUNT(*) as count FROM cw_payroll_posting_lock WHERE trans_status = 1 and posting_month = "'.$process_month.'" and category = "'.$category.'" and posting_lock = 1';
$posting_lock_info = $this->db->query("CALL sp_a_run ('SELECT','$posting_lock_qry')");
$posting_lock_result = $posting_lock_info->result();
$posting_lock_info->next_result();
$lock_count = $posting_lock_result[0]->count;
if((int)$lock_count > 0){
echo json_encode(array('success' => FALSE, 'message' => "Payroll Posting Locked for This Month!!"));
exit(0);
}
$count = $this->checkisprocessed($process_month,$where_query,'cw_transactions');
if((int)$count > 0){
echo json_encode(array('success' => FALSE, 'message' => "Payroll Already Processed for This Month!!"));
exit(0);
}
//Get salary date info
$tos_salary_dates = $this->tos_sal_strt_end_info("4",$process_month); // 4 => Posting Entry
$start_date = date("Y-m-d",strtotime($tos_salary_dates['salary_start_date']));
$end_date = date("Y-m-d",strtotime($tos_salary_dates['salary_end_date']));
//MI MAPPING QUERY
$mapping_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT time_office_component,mi_component FROM cw_monthly_input_mapping WHERE trans_status = 1')");
$mapping_result = $mapping_info->result_array();
$mapping_info->next_result();
$time_office_components = array_column($mapping_result, 'time_office_component');
$mi_components = array_column($mapping_result, 'mi_component');
$posting_columns = array_combine( $mi_components, $time_office_components);
//Get from company info module.
$company_info = $this->company_info();
$coff_based_on = $company_info[0]->coff_based_on;
$coff_check_qry = "";
if($coff_based_on !== 'role' && $coff_based_on !== '0'){
$coff_check_qry = ' ,'.$coff_based_on;
}
//Get Employee Details //OLD QUERY (RAGU COMMENT THIS BECAUSE OF TERMINATION STATUS)
// $emp_qry = 'SELECT cw_employees.employee_code,cw_employees.emp_name,cw_employees.termination_status,date_of_joining,last_working_date,prime_employees_id,role '.$coff_check_qry.' FROM `cw_employees` where cw_employees.trans_status = 1 and (cw_employees.termination_status = 0 or cw_employees.resignation_date >= "'.$start_date.'") '.$where_query;
//New query
$emp_qry = 'SELECT cw_employees.employee_code,cw_employees.emp_name,cw_employees.termination_status,date_of_joining,last_working_date,prime_employees_id,role '.$coff_check_qry.' FROM `cw_employees` where cw_employees.trans_status = 1 and (cw_employees.termination_status = 0 or DATE_FORMAT(cw_employees.last_working_date, "%Y-%m-%d") between "' . $start_date . '" and "' . $end_date . '") and employee_code NOT IN ("'.$fandf_emp.'") '.$where_query;
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
$emp_rslt = $emp_info->result_array();
$emp_info->next_result();
$emp_rslt_arr = array_reduce($emp_rslt, function($result, $arr){
$result[$arr['employee_code']] = $arr;
return $result;
}, array());
$result = $this->get_muster_details($emp_rslt_arr,$start_date,$end_date,$category,$emp_component,$posting_columns,'posting',$process_month,$process_type);
if($result){
echo json_encode(array('success' => TRUE, 'message' => "Posting Completed Successfully..!!"));
}else{
echo json_encode(array('success' => FALSE, 'message' => "Please try After sometime!!"));
}
}
public function emp_suggest(){
$search_term = $this->input->post_get('term');
$final_qry = 'select employee_code,emp_name from cw_employees where trans_status = 1 and (employee_code like "'.$search_term.'%" or emp_name like "%'.$search_term.'%")';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
foreach($final_result as $rslt){
$employee_code = $rslt->employee_code;
$emp_name = $rslt->emp_name;
$suggestions[] = array('value' => $employee_code, 'label' => "$employee_code - $emp_name");
}
if(empty($suggestions)){
$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
}
echo json_encode($suggestions);
}
}
?>