File: //home/cafsindia/hrms_allyindian_com/application/controllers/Absent_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Absent_report extends Action_controller{
public function __construct(){
parent::__construct('absent_report');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
//PAGE INFO FUNCTION
$this->page_info();
$data['key'] = $this->generateKey();
$data['module_sts'] = (int)$this->module_sts;
$data['quick_link'] = $this->quick_link;
$data['pick_list'] = $this->pick_list;
$data['form_info'] = $this->form_info;
$data['table_head'] = $this->table_head;
$data['fliter_list'] = $this->fliter_list;
$data['freeze_list'] = $this->freeze_list;
$category_qry = 'select prime_category_id,category_name from cw_category where trans_status = 1 and prime_category_id != 1';
$category_info = $this->db->query("CALL sp_a_run ('SELECT','$category_qry')");
$category_rslt = $category_info->result_array();
$category_info->next_result();
$pick_key = array_column($category_rslt, 'prime_category_id');
$pick_val = array_column($category_rslt, 'category_name');
$final_pick = array_combine( $pick_key, $pick_val);
$data['category_list'] = array("" => "---- label_name ----") + $final_pick;
$this->load->view("$this->control_name/manage",$data);
}
public function absent_report(){
//SEARCH INFO FUNCTION
$this->search_info();
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
exit(0);
}
$category = $this->input->post("category");
$attendance_month = $this->input->post("attendance_month");
$minimum_count = $this->input->post("minimum_count");
$process_type = (int)$this->input->post("process_type");
$month_day_arr = $this->salary_start_end_info($category,$attendance_month);
if($month_day_arr){
$day_start = date('Y-m-d',strtotime($month_day_arr['salary_start_date']));
$day_end = date('Y-m-d',strtotime($month_day_arr['salary_end_date']));
}
$role_condition = "";
if($this->role_condition){
$role_condition = $this->role_condition;
}
$time_entry_qry = 'SELECT GROUP_CONCAT(cw_time_entry.prime_time_entry_id) as ids,cw_employees.emp_name,cw_time_entry.employee_code,att_date,prime_time_entry_id,cw_department.department,count(*) as leave_count from cw_time_entry inner join cw_employees on cw_employees.employee_code = cw_time_entry.employee_code inner join cw_department on cw_employees.department = cw_department.prime_department_id where cw_time_entry.trans_status = 1 and cw_time_entry.att_date >= "'.$day_start.'" and cw_time_entry.att_date <= "'.$day_end.'" and cw_employees.role = "'.$category.'" and whole_day_status in ("U","L") '.$role_condition.' group by cw_time_entry.employee_code HAVING COUNT(cw_time_entry.att_date) > "'.$minimum_count.'"';
$time_entry_info = $this->db->query("CALL sp_a_run ('SELECT','$time_entry_qry')");
$time_entry_rslt = $time_entry_info->result_array();
$time_entry_info->next_result();
if((int)$process_type === 1){
$td_line = "";
foreach ($time_entry_rslt as $key => $value){
$ids = $value['ids'];
$employee_code = $value['employee_code'];
$emp_name = $value['emp_name'];
$department = $value['department'];
$att_date = date('d-m-Y',strtotime($value['att_date']));
$leave_count = $value['leave_count'];
$td_line .="<tr onclick=get_data('$ids','$day_start','$day_end')><td>$employee_code</td><td>$emp_name</td><td>$department</td><td>$leave_count</td></tr>";
}
}else if((int) $process_type === 2){
$present_report_qry = 'SELECT cw_employees.emp_name,cw_time_entry.employee_code,att_date,prime_time_entry_id,cw_department.department from cw_time_entry inner join cw_employees on cw_employees.employee_code = cw_time_entry.employee_code inner join cw_department on cw_employees.department = cw_department.prime_department_id where cw_time_entry.trans_status = 1 and cw_time_entry.att_date >= "'.$day_start.'" and cw_time_entry.att_date <= "'.$day_end.'" and cw_employees.role = "'.$category.'" and whole_day_status in ("U","L") '.$role_condition.' order by att_date ASC';
$absent_report_info = $this->db->query("CALL sp_a_run ('SELECT','$present_report_qry')");
$absent_report_rslt = $absent_report_info->result_array();
$absent_report_info->next_result();
$absent_report_arr = array_reduce($absent_report_rslt, function($result, $arr){
$result[$arr['employee_code']][] = $arr;
return $result;
}, array());
$td_line = "";
foreach ($absent_report_arr as $emp_data){
$x = 0;
$emp_arr = array();
foreach ($emp_data as $value){
$att_date = date('d-m-Y',strtotime($value['att_date']));
$employee_code = $value['employee_code'];
$emp_name = $value['emp_name'];
$department = $value['department'];
if($x === 0){
$prev = $att_date;
}
if($prev === $att_date){
$x = $x+1;
$emp_arr[] = $value['prime_time_entry_id'];
}else{
$x = 0;
$emp_arr = array();
}
$prev = date('d-m-Y', strtotime($value['att_date'] . ' +1 day'));
}
if($x >= $minimum_count){
$ids = implode(",",$emp_arr);
$td_line .="<tr onclick = get_data('$ids','$day_start','$day_end')><td>$employee_code</td><td>$emp_name</td><td>$department</td><td>$x</td></tr>";
}
}
}
if($time_entry_rslt){
$table_data = "<table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Employee Code</th>
<th>Employee name</th>
<th>Department</th>
<th>Total Leave Count</th>
</tr>
</thead>
<tbody>
$td_line
</tbody>
</table>";
echo json_encode(array('success'=>TRUE,'message'=>"",'table_data' => $table_data));
}else{
echo json_encode(array('success'=>false,'message'=>'NO DATA AVAILABLE','table_data'=>$table_data));
}
}
}
?>