MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/groups_cafsindia_com/application/controllers/Unpunch_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Unpunch_Report  extends Action_controller{	
	public function __construct(){
		parent::__construct('unpunch_report');
		$this->collect_base_info();
	}
	
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		$this->load->view("$this->control_name/manage",$data);
	}
	
	public function manager_info(){
		$choose_date  = date('Y-m-d',strtotime($this->input->post('choose_date')));
		$process_type = $this->input->post('process_type');
		if((int)$process_type === 1){
			$pending_manager_qry    = 'select group_concat(distinct manager_report) as manager_report from dailyunpunch inner join cw_employees on cw_employees.thumb_no = dailyunpunch.dcode 
			where dailyunpunch.empcode not in (select cw_dailyunpunch.empcode from cw_dailyunpunch where cw_dailyunpunch.att_date = "'.$choose_date.'") and dailyunpunch.att_date = "'.$choose_date.'"';
			$pending_manager_data   = $this->db->query("CALL sp_a_run ('SELECT','$pending_manager_qry')");
			$pending_manager_result = $pending_manager_data->result();
			$pending_manager_data->next_result();
			$manger_code            = $pending_manager_result[0]->manager_report;
			if($manger_code){
				$manger_code          = str_replace(",",'","',$manger_code);
				$manger_code          = '"'.$manger_code.'"';
				$get_manager_name_qry    = 'select emp_name,employee_code from cw_employees where trans_status=1 and employee_code in ('.$manger_code.')';
				$manager_name_data   = $this->db->query("CALL sp_a_run ('SELECT','$get_manager_name_qry')");
				$manager_name_result = $manager_name_data->result();
				$manager_name_data->next_result();
				$manager_data = "<option value=''>--- Select any one---</option><option value='ALL'> ALL</option><option value='Auto Updated'>Auto Updated</option>";
				foreach ($manager_name_result as $manager_rslt){
					$manager_data .= "<option value='".$manager_rslt->employee_code."'>$manager_rslt->emp_name</option>";
				}
				echo json_encode(array('success' => True,'manager_data' => $manager_data));
			}else{
				echo json_encode(array('success' => False,'message' => "No Pending manager information available, please choose another date"));
			}
		}else{
			$comp_manager_qry    = 'select employee_code,emp_name from cw_dailyunpunch inner join cw_employees on cw_employees.employee_code=cw_dailyunpunch.`trans_created_by` where att_date="'.$choose_date.'" group by manager_report';
			$comp_manager_data   = $this->db->query("CALL sp_a_run ('SELECT','$comp_manager_qry')");
			$comp_manager_result = $comp_manager_data->result();
			$comp_manager_data->next_result();
			if($comp_manager_result){
				$manager_data = "<option value=''>--- Select any one---</option><option value='ALL'> ALL</option><option value='Auto Updated'>Auto Updated</option>";
				foreach ($comp_manager_result as $comp_rslt){
					$manager_data .= "<option value='".$comp_rslt->employee_code."'>$comp_rslt->emp_name</option>";
				}
				echo json_encode(array('success' => True,'manager_data' => $manager_data));
			}else{
				echo json_encode(array('success' => False,'message' => "No Complete manager informations available, please choose another date"));
			}
		}
		
	}
	
	public function get_unpunch_data(){
		$choose_date  = date('Y-m-d',strtotime($this->input->post('choose_date')));
		$process_type = (int)$this->input->post('process_type');
		$manager_list = $this->input->post('manager_list');
		$swipe_status = $this->input->post('swipe_status');
		if($swipe_status === 'All'){
			$swipe_query = '';
		}else
		if($swipe_status === 'SU'){
			$swipe_query = ' and swipe_status = "I" and (out_time IS NULL OR out_time = "") ';
		}else
		if($swipe_status === 'FU'){
			$swipe_query = ' and swipe_status = "I" and (in_time IS NULL OR in_time = "")';
		}else{
			$swipe_query = ' and swipe_status = "'.$swipe_status.'"';
		}
		if($manager_list == 'ALL'){
			$manager_query = '';
		}else
		if($manager_list == 'Auto Updated'){
			if($process_type === 1){
				$manager_query = '';
			}else{
				$manager_query = 'cw_dailyunpunch.trans_created_by = "1" and ';
			}
		}else{
			$manager_query = 'cw_employees.leave_reporting in (\"'.$manager_list.'\") and';
		}
		if($process_type === 1){
			$unpunched_data_qry    = 'select cw_employees.emp_name,dailyunpunch.dailyunpunch_id,dailyunpunch.empcode,IFNULL(dailyunpunch.att_date, 0) as att_date,dailyunpunch.in_time,dailyunpunch.out_time,dailyunpunch.dcode,dailyunpunch.swipe_status,NULL as leave_status,NULL as trans_created_by from dailyunpunch inner join cw_employees on cw_employees.thumb_no = dailyunpunch.dcode where '. $manager_query.' dailyunpunch.empcode not in (select cw_dailyunpunch.empcode from cw_dailyunpunch where cw_dailyunpunch.att_date = "'.$choose_date.'") and dailyunpunch.att_date = "'.$choose_date.'" '.$swipe_query.'';
		}else
		if($process_type === 2){
			$unpunched_data_qry    = 'select cw_employees.emp_name,cw_dailyunpunch.empcode,IFNULL(cw_dailyunpunch.att_date, 0) as att_date,cw_dailyunpunch.dcode,leave_status,cw_dailyunpunch.swipe_status,cw_dailyunpunch.in_time,cw_dailyunpunch.out_time,IFNULL(cw_emp.emp_name, "Auto Updated by system") as trans_created_by from cw_dailyunpunch inner join cw_employees on cw_employees.thumb_no = cw_dailyunpunch.dcode  inner join cw_leave_status on cw_leave_status.leave_value = cw_dailyunpunch.manager_status left join cw_employees as cw_emp on cw_emp.employee_code = cw_dailyunpunch.trans_created_by  where '. $manager_query.' att_date = "'.$choose_date.'" '.$swipe_query.'';
		}else{
			echo json_encode(array('success'=>false,'message'=>'something went wrong..!'));
			exit(0);
		}
		$unpunched_data   = $this->db->query("CALL sp_a_run ('SELECT','$unpunched_data_qry')");
		$unpunched_result = $unpunched_data->result();
		$unpunched_data->next_result();
		$table_content = "";
		if($unpunched_result){
			$tr_line = "";
			$i =1;
			foreach($unpunched_result as $rslt){			
				$empcode         = $rslt->empcode;
				$emp_name        = $rslt->emp_name;
				$dcode           = $rslt->dcode;
				$manager_status  = $rslt->leave_status;
				if($rslt->att_date){
					$att_date      = date('d-m-Y',strtotime($rslt->att_date));
				}else{
					$att_date      = "-";
				}				
				if($rslt->in_time){
					$in_time      = date('h:i A',strtotime($rslt->in_time));
				}else{
					$in_time      = "-";
				}
				if($rslt->out_time){
					$out_time     = date('h:i A',strtotime($rslt->out_time));
				}else{
					$out_time     = "-";
				}					
				$i_sts     = "Invalid Punch"; 
				if($rslt->swipe_status === "I" && $in_time === "-"){
					$i_sts = "Intime Not punched";
				}else
				if($rslt->swipe_status === "I" && $out_time === "-"){
					$i_sts = "Outtime Not punched";
				}
				$swipe_array      = array('U' =>'Unpunched','I' =>$i_sts,'SU' =>'Second Half Unpunch','FU' =>'First Half Unpunch','LP' =>'Late Punch');
				$swipe_status      = $swipe_array[$rslt->swipe_status];
				$approved_by       = $rslt->trans_created_by;
				$tr_line         .="<tr><td>$i</td><td>$empcode</td><td>$emp_name</td><td>$dcode</td><td>$in_time</td><td>$out_time</td><td>$swipe_status</td><td>$att_date</td><td>$manager_status</td><td>$approved_by</td>
					</tr>";
				$i++;
			}
		}else{
			$tr_line   ="<tr><td></td><td></td><td></td><td></td><td></td><td>No Data Available</td><td></td><td></td><td></td><td></td></tr>";
		}
		$table_content = "<div style='margin:20px;'><table class='table table-striped table-bordered' id='dailyunpunch_data'>
								<thead>
									<tr>
										<th>Sr. No.</th>
										<th>Employee Code</th>
										<th>Employee Name</th>
										<th>Dcode</th>
										<th>In Time</th>							
										<th>Out Time</th>
										<th>Swipe Status</th>
										<th>Unpunched Date</th>
										<th>Unpunched Status</th>
										<th>Approved By</th>
									</tr>
								</thead>
								<tbody>
									$tr_line
								</tbody>
							</table>
							</div>";
		echo json_encode(array('success' => TRUE, 'message' => "See Unpunched leave details",'table_content'=>$table_content));
	}
}
?>