File: /home/cafsindia/.trash/application.1/controllers/Early_and_late.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Early_and_late extends Action_controller{
public function __construct(){
parent::__construct('early_and_late');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
//PAGE INFO FUNCTION
$this->page_info();
$data['encKey'] = $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 early_and_late(){
//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);
}
$category = $this->input->post("category");
$attendance_month = $this->input->post("attendance_month");
$minimum_count = $this->input->post("minimum_count");
$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,cw_department.department , count(*) as late_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.'" '.$role_condition.' group by cw_time_entry.employee_code HAVING COUNT(cw_time_entry.att_date) > "'.$minimum_count.'"';
$exist_info = $this->db->query("CALL sp_a_run ('SELECT','$time_entry_qry')");
$exist_rslt = $exist_info->result();
$exist_info->next_result();
$exist_count = $exist_rslt[0]->exist_count;
$td_line = "";
foreach ($exist_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));
$late_count = $value->late_count;
$td_line .="<tr onclick=get_data('$ids','$day_start','$day_end')><td>$employee_code</td><td>$emp_name</td><td>$department</td><td>$late_count</td></tr>";
}
if($exist_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 Late 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));
}
}
}
?>