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/hrms_cafsindia_com/application/controllers/Unpunch.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Unpunch  extends Action_controller{	
	public function __construct(){
		parent::__construct('unpunch');
		$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 check_unpunch_info(){
		$choose_date   = date('Y-m-d',strtotime($this->input->post('choose_date')));
		$manager_list  = $this->input->post('manager_list');
		$process_type  = $this->input->post('process_type');
		if((int)$process_type === 1){
			$unpunched_data_qry    = 'select dailyunpunch_id,cw_employees.emp_name,dailyunpunch.empcode,dailyunpunch.att_date from dailyunpunch inner join cw_employees on cw_employees.thumb_no = dailyunpunch.dcode where leave_reporting in ('.$manager_list.') and dailyunpunch.empcode not in (select cw_dailyunpunch.empcode from cw_dailyunpunch where cw_dailyunpunch.att_date = "'.$choose_date.'") and dailyunpunch.att_date = "'.$choose_date.'"';
			$unpunched_data   = $this->db->query("CALL sp_a_run ('SELECT','$unpunched_data_qry')");
			$unpunched_result = $unpunched_data->result();
			$unpunched_data->next_result();
			$leave_status   = $this->get_leave_status();
			$table_content = "";
			if($unpunched_result){
				$tr_line = "";
				$i =1;
				foreach ($unpunched_result as $unpunched_info){
					$dailyunpunch_id = $unpunched_info->dailyunpunch_id;
					$emp_name        = $unpunched_info->emp_name;
					$emp_code        = $unpunched_info->empcode;
					$att_date        = date('d-m-Y',strtotime($unpunched_info->att_date));
					$tr_line         .="<tr><td>$i</td><td>$emp_code</td><td>$emp_name</td><td>$att_date</td><td><select id='manager_status_$dailyunpunch_id' name='manager_status_$dailyunpunch_id' class='form-control manage_sts'>
						$leave_status
						</select>
						</td>
						</tr>";
					$i++;
				}
				$table_content = "<form id='unpunched_form' class='form-inline' autocomplete='off' method='post' accept-charset='utf-8' novalidate='novalidate' action=''>			
									<table class='table table-striped table-bordered'>
										<thead>
											<tr>
												<th>Si.No</th>
												<th>Employee Code</th>
												<th>Employee Name</th>
												<th>Leave Date</th>
												<th>Leave Status</th>
											</tr>
										</thead>
										<tbody>
											$tr_line
										</tbody>
									</table>
									<button type='button' class='btn btn-primary center-block' id='unpunched_submit' style='margin-top:10px;'>Submit</button>
								</form>";
				echo json_encode(array('success' => TRUE, 'message' => "See Unpunched leave details",'table_content'=>$table_content));
			}else{
				echo json_encode(array('success' => FALSE, 'message' => "No data is available"));
			}
		}else{
			$unpunch_upd_data_qry    = 'select cw_employees.emp_name,empcode,att_date,leave_status 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  where leave_reporting in ('.$manager_list.') and att_date = "'.$choose_date.'"';
			$unpunched_upd_data   = $this->db->query("CALL sp_a_run ('SELECT','$unpunch_upd_data_qry')");
			$unpunched_upd_result = $unpunched_upd_data->result();
			$unpunched_upd_data->next_result();
			$table_content = "";
			if($unpunched_upd_result){
				$tr_line = "";
				$i =1;
				foreach ($unpunched_upd_result as $unpunch_info){
					$emp_name        = $unpunch_info->emp_name;
					$emp_code        = $unpunch_info->empcode;
					$att_date        = date('d-m-Y',strtotime($unpunch_info->att_date));
					$manager_status  = $unpunch_info->leave_status;
					$tr_line         .="<tr><td>$i</td><td>$emp_code</td><td>$emp_name</td><td>$att_date</td><td>$manager_status</td>
						</tr>";
					$i++;
				}
				$table_content = "<div style='margin:20px;'><table class='table table-striped table-bordered'>
										<thead>
											<tr>
												<th>Si.No</th>
												<th>Employee Code</th>
												<th>Employee Name</th>
												<th>Leave Date</th>
												<th>Leave Status</th>
											</tr>
										</thead>
										<tbody>
											$tr_line
										</tbody>
									</table>
									</div>";
				echo json_encode(array('success' => TRUE, 'message' => "See Unpunched leave details",'table_content'=>$table_content));
			}else{
				echo json_encode(array('success' => FALSE, 'message' => "No data is available"));
			}
		}
	}
	
	public function get_leave_status(){
		$leave_status_qry    = 'select prime_leave_status_id,leave_status,leave_value from cw_leave_status where trans_status =1';
		$leave_status_info    = $this->db->query("CALL sp_a_run ('SELECT','$leave_status_qry')");
		$leave_status_result  = $leave_status_info->result();
		$leave_status_info->next_result();
		$leave_sts_data = "<option value=''>--- Select any one---</option>";
		foreach ($leave_status_result as $leave_info){
			$leave_sts_data .= "<option value='".$leave_info->leave_value."'>$leave_info->leave_status</option>";
		}
		return $leave_sts_data;
	}
	
	public function save_leave_status(){
		$manager_code = $this->input->post('manager_list');
		$fdata        = $this->input->post('fdata');
		$created_on   = date('Y-m-d H:m:s');
		$logged_id    = $this->logged_id;
		$fdata = json_decode($fdata);
		if(!empty($fdata)){
			foreach($fdata as $form_data){
				$name            = $form_data->name;
				$value           = $form_data->value;
				$unpunched_id    = str_replace("manager_status_",'',$name);
				$ins_manager_sts_qry    = 'insert into cw_dailyunpunch (att_date,empcode,dcode,swipe_status,manager_status,trans_created_by,trans_created_date,trans_updated_by,trans_updated_date) select att_date,empcode,dcode,swipe_status,"'.$value .'","'.$manager_code .'","'.$created_on .'","'.$logged_id .'","'.$created_on .'" from dailyunpunch where dailyunpunch_id = "'.$unpunched_id.'"';
				$insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$ins_manager_sts_qry')");
				$insert_result      = $insert_info->result();
				$insert_info->next_result();
			}
			echo json_encode(array('success' => True,'message' => "Updated successfully"));
		}else{
			echo json_encode(array('success' => False,'message' => "Server Problem"));
		}
	}
	
	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 leave_reporting) as leave_reporting 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]->leave_reporting;
			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>";
				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 leave_reporting';
			$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>";
				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"));
			}
		}
		
	}
}
?>