File: /home/cafsindia/cloud_cafsinfotech_in/application/controllers/Increment_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Increment_report extends Action_controller{
public function __construct(){
parent::__construct('increment_report');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
}
// LOAD PAGE DATA
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();
$process_role[""] = "---- Select Role ----";
foreach($role_result as $for){
$role_id = $for->prime_category_id;
$category_name = $for->category_name;
$process_role[$role_id] = $category_name;
}
$data['process_role'] = $process_role;
$this->load->view("$this->control_name/manage",$data);
}
// AUTOCOMPLETE FOR SERACH EMPLOYEE
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.'%"';
$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);
}
public function get_table_data(){
$process_month = $this->input->post('process_month');
$process_type = $this->input->post('process_type');
$process_emp_id = $this->input->post('process_emp_id');
$process_role = $this->input->post('process_role');
if($process_type == '1'){
$type_qry = 'and cw_arrear_cumulative.employee_code ="'.$process_emp_id.'"';
$inc_qry = 'and cw_increment.employee_code ="'.$process_emp_id.'"';
}else
if($process_type == '2'){
$type_qry = 'and cw_arrear_cumulative.category ="'.$process_role.'"';
$inc_qry = 'and cw_increment.category ="'.$process_role.'"';
}
$inc_value_qry = 'select employee_code,column_name,current_value,current_value,new_value from cw_increment where cw_increment.trans_status = 1 and apply_on ="'.$process_month.'" '.$inc_qry.'';
$inc_value_info = $this->db->query("CALL sp_a_run ('SELECT','$inc_value_qry')");
$inc_value_rslt = $inc_value_info->result_array();
$inc_value_info->next_result();
$inc_value_rslt = array_reduce($inc_value_rslt, function($result, $arr){
$result[$arr['employee_code']][$arr['column_name']] = $arr;
return $result;
}, array());
$qry = 'select cw_arrear_cumulative.employee_code,cw_employees.emp_name,transaction_column,arrear_value,increment_apply_month,effective_date,category from cw_arrear_cumulative inner join cw_employees on cw_employees.employee_code = cw_arrear_cumulative.employee_code where increment_apply_month ="'.$process_month.'" '.$type_qry.' group by cw_arrear_cumulative.employee_code,transaction_column';
$arrear_emp_info = $this->db->query("CALL sp_a_run ('SELECT','$qry')");
$arrear_emp_result = $arrear_emp_info->result_array();
$arrear_emp_info->next_result();
$arrear_emp_result = array_reduce($arrear_emp_result, function($result, $arr){
$result[$arr['employee_code']][$arr['transaction_column']] = $arr;
return $result;
}, array());
$arrear_array = array();
foreach($arrear_emp_result as $emp_code => $emp_rslt){
foreach($emp_rslt as $arr_col => $emp_data){
$increment_apply_month = $emp_data['increment_apply_month'];
$effective_date = $emp_data['effective_date'];
$category = $emp_data['category'];
$emp_name = $emp_data['emp_name'];
$transaction_column = $emp_data['transaction_column'];
$array_value = $emp_data['arrear_value'];
$arrear_array[$emp_code][$transaction_column]['transaction_column'] = $array_value;
$arrear_array[$emp_code][$transaction_column]['employee_name'] = $emp_name;
}
}
if(!$arrear_array){
echo json_encode(array("success" => FALSE,'message' => "No Data"));
exit(0);
}
$form_setting_rslt = $this->get_form_setting();
$role_qry = 'select GROUP_CONCAT(DISTINCT(cw_arrear_cumulative.transaction_column) ORDER BY transaction_column asc) as transaction_column,GROUP_CONCAT(cw_arrear_cumulative.arrear_value ORDER BY transaction_column asc) as arrear_value from cw_arrear_cumulative where increment_apply_month ="'.$process_month.'" '.$type_qry;
$arrear_role_info = $this->db->query("CALL sp_a_run ('SELECT','$role_qry')");
$arrear_role_result = $arrear_role_info->result_array();
$arrear_role_info->next_result();
$tfoot = "";
$transaction_column = explode(',',$arrear_role_result[0]['transaction_column']);
$tbl_line = "";
foreach($arrear_array as $key =>$val){
$total = 0;
$arr_td = "";
$role_line = "";
$tfoot = "";
foreach($transaction_column as $name =>$arrear){
$current_value = $inc_value_rslt[$key][$arrear]['current_value'];
$new_value = $inc_value_rslt[$key][$arrear]['new_value'];
if(!$current_value){
$current_value = '0.00';
}
if(!$new_value){
$new_value = '0.00';
}
$role_line .= "<th>".$form_setting_rslt[$arrear]."<span style='float:left;'> Current</span></th><th>".$form_setting_rslt[$arrear]."<span style='float:left;'> New</th>";
$arr_td .="<td>".$current_value."</td><td>".$new_value."</td>";
$employee_name = $arrear_array[$key][$arrear]['employee_name'];
$total = $total + $current_value;
$tfoot .= "<th></th><th></th>";
}
$tbl_line .= "<tr onclick=view_arrear_info('$prime_cumulative_id','$increment_apply_month','$effective_date','$key','$category')><td>$key</td><td>$employee_name</td>$arr_td<td style='color:red;'>$total</td></tr>";
}
$view_content = "<table class='table table-striped table-bordered' id='role'>
<thead>
<tr>
<th scope='col'>Employee Code</th>
<th scope='col'>Employee Name</th>
$role_line
<th scope='col'>Total</th>
</tr>
</thead>
$tbl_line
<tfoot>
<tr style='font-weight: bold; color: red;'>
<th></th>
<th></th>
$tfoot
<th></th>
</tr>
</tfoot>
</table>";
echo json_encode(array("success" => TRUE,'message' => $view_content,"count" => $count));
}
public function get_form_setting(){
$form_setting_qry = 'select label_name,view_name from cw_form_setting where cw_form_setting.trans_status = 1 and cw_form_setting.prime_module_id ="employees"';
$form_setting_info = $this->db->query("CALL sp_a_run ('SELECT','$form_setting_qry')");
$form_setting_rslt = $form_setting_info->result_array();
$form_setting_info->next_result();
$form_setting_rslt = array_reduce($form_setting_rslt, function($result, $arr){
$result[$arr['label_name']] = $arr['view_name'];
return $result;
}, array());
return $form_setting_rslt;
}
}
?>