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_allyindian_com/application/controllers/Manual_unpunch_update.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Manual_unpunch_update  extends Action_controller{	
	public function __construct(){
		parent::__construct('manual_unpunch_update');
	}
	
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		//PAGE INFO FUNCTION
		$data['key']      = $this->generateKey();
		$this->load->view("$this->control_name/manage");
	}

	//AUTO COMPLETE MANAGER CODE
	public function autocomplete(){
		$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);
		}
		$manager_code     = $this->input->post('term');
		$att_date         = date_create($this->input->post('att_date'));
		$att_date         = date_format($att_date,"Y-m-d");
		if($manager_code){
			$get_manager_codes_qry     = 'SELECT cw_employees.employee_code as manager_code,cw_employees.emp_name FROM cw_employees WHERE cw_employees.employee_code in (SELECT cw_employees.first_level_approval FROM `cw_employees` INNER JOIN cw_time_entry ON cw_employees.employee_code = cw_time_entry.employee_code WHERE cw_time_entry.whole_day_status = "U" and (cw_employees.first_level_approval LIKE ("'.$manager_code.'%") or cw_employees.emp_name LIKE ("'.$manager_code.'%")) and cw_time_entry.att_date ="'.$att_date.'" GROUP BY cw_employees.first_level_approval)';
			// echo $get_manager_codes_qry;die;
			$get_manager_codes_query   = $this->db->query("$get_manager_codes_qry");//call spa run error
			$get_manager_codes_rslt    = $get_manager_codes_query->result_array();
            $get_manager_codes_count   = (int) $get_manager_codes_query->num_rows();
			if($get_manager_codes_count){
				$manager_code = array();
				foreach($get_manager_codes_rslt as $manager){
					$manager_code[] = array('key'=>$manager['manager_code'],'value'=>$manager['manager_code'].' - '.$manager['emp_name']);
				}
				echo json_encode(array("success"=>$manager_code));
			}else{
				$no_data[0]   =  array('key'=>'No Data','value'=>'No Data Available In Selected Date');
				echo json_encode (array("status"=>"no_data","data"=>$no_data));
			}
		}
	}
	//EMP CODE VALIDATION FOR DUPLICATE DATA
	public function duplicate_validation(){
		$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);
		}
		$att_date              = date_create($this->input->post('att_date'));
		$att_date              = date_format($att_date,"Y-m-d");
		// $att_date              = "2024-03-11";
		$manager_code          = $this->input->post('manager_code');
		$validate_qry          = 'SELECT * FROM cw_dailyunpunch WHERE att_date ="'.$att_date.'" AND manager_code="'.$manager_code.'"';
		$validate_query        = $this->db->query("$validate_qry");
		$validate_rslt         = $validate_query->result_array();
		if(count($validate_rslt) > 0){
			echo "data already inserted";
		}else{
			$view_result =  $this->get_emp_status($att_date,$manager_code);
			if(count($view_result) > 0){
				echo json_encode(array("success"=>$view_result));
			}else{
				echo json_encode(array("status"=>"failed","message"=>"No Data Available"));
			}
		}
	}
	//GET EMPLOYEE STATUS BASED ON MANAGER CODE
	public function get_emp_status($att_date,$manager_code){
		$get_emp_status_qry    = 'SELECT cw_employees.first_level_approval as manager_code,cw_employees.emp_name,Date_format(cw_time_entry.att_date,"%d-%m-%Y") as att_date,cw_time_entry.whole_day_status,cw_time_entry.employee_code FROM cw_time_entry INNER JOIN cw_employees ON cw_time_entry.employee_code = cw_employees.employee_code WHERE cw_time_entry.whole_day_status = "U" and cw_time_entry.att_date ="'.$att_date.'" AND cw_employees.first_level_approval ="'.$manager_code.'"';
		$get_emp_status_query  = $this->db->query("$get_emp_status_qry");
		$get_emp_status_rslt   = $get_emp_status_query->result_array();
		return $get_emp_status_rslt;
	}
	//SEND MAIL TO SELECTED EMPOYEES
	public function emp_mail_process($hr_sts,$employee_code){
		$get_emp_mail_qry   = 'SELECT cw_employees.personal_email_id FROM cw_employees WHERE cw_employees.employee_code ="'.$employee_code.'"';
		$get_emp_mail_query = $this->db->query("$get_emp_mail_qry");
		$get_emp_mail_rslt  = $get_emp_mail_query->result_array();
		foreach($get_emp_mail_rslt as $mail){
			$to_email = $mail['personal_email_id'];
		}
		$emp_sts       = array("5"=>"Resigned With Salary","6"=>"Resigned Without Salary","8"=>"Terminated With Salary","9"=>"Terminated Without Salary","7"=>"Abscond");
		$emp_leave_sts = $emp_sts[$hr_sts];
		$body_content       = "Dear Employee, As Per Your Manager's Status You Are $emp_leave_sts.";
		$mail_status_name   = "Empolyee Status";
		$email_subject      = "Employee Status-$employee_code";
		$bcc_mails          = '';
		$email_attachment   = '';
		$first_to_email     = '';
		$second_to_email    = '';
		if($to_email){
			$mail_send_status = $this->send_email_notification($to_email,$first_to_email,$second_to_email,$bcc_mails,$email_subject,$body_content,$email_attachment);
			return "Done";
		}
	}

	//INSERT AND EMPLOYEE MASTER UPDATION
	public function manual_unpunch_save(){
		$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);
		}
		$att_date             = date_create($this->input->post('att_date'));
		$att_date             = date_format($att_date,"Y-m-d");
		$manager_code         = $this->input->post('manager_code');
		$employee_code        = $this->input->post('emp_code');
		$hr_sts               = $this->input->post('hr_sts_val');
		$trans_created_date   = date("Y-m-d H:i:s");	
		$trans_created_by     = '1';
		//
		$insert_qry    = 'INSERT INTO cw_dailyunpunch(employee_code,manager_code,att_date,day_status,trans_created_date,trans_created_by)VALUES("'.$employee_code.'","'.$manager_code.'","'.$att_date.'","'.$hr_sts.'","'.$trans_created_date.'","'.$trans_created_by.'")';
		$single_insert_query  = $this->db->query("$insert_qry");

		$emp_master_cond      = array('5','6','8','9','7');
		if(in_array($hr_sts,$emp_master_cond)){
			$update_emp_master_qry       = 'UPDATE cw_employees SET cw_employees.resignation_date = "'.$att_date.'",cw_employees.last_working_date ="'.$att_date.'",cw_employees.separation_type = "separation by emp code",cw_employees.separation_reason = "for example",cw_employees.termination_status = 1,cw_employees.trans_updated_date = "'.$att_date.'" WHERE cw_employees.employee_code   = "'.$employee_code.'"';
			$update_emp_master_query     = $this->db->query("$update_emp_master_qry");
			$email_process               = $this->emp_mail_process($hr_sts,$employee_code);
			if($email_process === "Done"){
				echo json_encode(array("status"=>"mail send successfully"));
			}
		}else{
			echo json_encode(array("status"=>"success"));
		}
	}

	//RESULT TABLE VIEW
	public function result_table(){
		$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);
		}
		$manager_code       = $this->input->post('manager_code');
		$att_date           = date_create($this->input->post('att_date'));
		$att_date           = date_format($att_date,"Y-m-d");
		// $att_date           = "2024-03-11";
		$result_table_qry   = 'SELECT cw_dailyunpunch.att_date,cw_dailyunpunch.employee_code,cw_employees.emp_name,cw_dailyunpunch.day_status FROM cw_dailyunpunch INNER JOIN cw_employees ON cw_employees.employee_code = cw_dailyunpunch.employee_code WHERE cw_dailyunpunch.att_date = "'.$att_date.'" AND cw_dailyunpunch.manager_code = "'.$manager_code.'"';
		$result_table_query = $this->db->query("$result_table_qry");
		$result_table_rslt  = $result_table_query->result_array();
		echo json_encode(array("status"=>"success","result_table"=>$result_table_rslt));
	}
}
?>