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_cafsinfotech_in/OLD/ZRM/application/controllers/Remove_wrong_entries.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Remove_wrong_entries  extends Action_controller{	
	public function __construct(){
		parent::__construct('remove_wrong_entries');
		$this->control_name  = 'remove_wrong_entries';
	}
	
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		//Get Category
		$role_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
		$role_result = $role_info->result();
		$role_info->next_result();
		$category_list[""] = "---- Select Category ----";
		foreach($role_result as $for){
			$role_id                 = $for->prime_category_id;
			$category_name           = $for->category_name;
			$category_list[$role_id] = $category_name;
		}
		$data['category_list'] = $category_list;
		$this->load->view("$this->control_name/manage",$data);
	}

	// Get Employee Code
	public function get_employees_list(){
		$process_type      = $this->input->post('process_type');
		$category          = $this->input->post('category');
		$from_date         = $this->input->post('from_date');
		$to_date           = $this->input->post('to_date');
		if((int)$process_type === 1){
			$table_name = 'cw_weekoff_import';
			$column     = 'weekoff_date';
		}else{
			$table_name = 'cw_shift_import';
			$column     = 'shift_date';
		}
		/* Custom Code for Component value and Weekoff Component */
		$component_query  = 'SELECT pick_table,pick_list,components,based_on FROM cw_general_setting inner join cw_form_setting on cw_form_setting.prime_form_id = cw_general_setting.components WHERE entry_parameter_type = 1 and cw_general_setting.trans_status = 1';
		$component_info   = $this->db->query("CALL sp_a_run ('SELECT','$component_query')");
		$component_result = $component_info->result();
		$component_info->next_result();

		$based_on = (int)$component_result[0]->based_on;

		//Check whether the company has employee wise weekoff or Company wise
		if(($based_on === 1 && (int)$process_type === 1) || (int)$process_type === 2){
			$emp_detail_query  = 'SELECT CONCAT("<option value =",cw_employees.employee_code," >",cw_employees.emp_name," - ",cw_employees.employee_code,"</option>") as result_data FROM cw_employees inner join '.$table_name.' on '.$table_name.'.employee_code = cw_employees.employee_code WHERE cw_employees.role in ('.$category.') and '.$column.' between "'.$from_date.'" and "'.$to_date.'" and cw_employees.termination_status = 0 group by cw_employees.employee_code';
		}else{
			$emp_detail_query  = 'SELECT CONCAT("<option value =",cw_employees.employee_code," >",cw_employees.emp_name," - ",cw_employees.employee_code,"</option>") as result_data FROM cw_employees WHERE cw_employees.role in ('.$category.')  and cw_employees.termination_status = 0';			
		}
		$emp_detail_info   = $this->db->query("CALL sp_a_run ('SELECT','$emp_detail_query')");
		$emp_detail_result = $emp_detail_info->result();
		$emp_detail_info->next_result();
		$result_data       = array_column($emp_detail_result,'result_data');
    
		$option            = "<option value=''>---- Select Employee ----</option>".implode('',$result_data);		
		if(empty($emp_detail_result)){
			echo json_encode(array('success'=>FALSE,'message'=>"No Data Found for these Dates"));
		}else{
			echo json_encode(array('success'=>TRUE,'option'=>$option));
		}	
	}	
	
	//Process Remove wrong Entries
	 public function remove_process(){
	 	$process_type  = $this->input->post('process_type');
		$category      = $this->input->post('category');
		$from_date     = date("Y-m-d",strtotime($this->input->post('from_date')));
		$to_date       = date("Y-m-d",strtotime($this->input->post('to_date')));		
		$employees     = implode('","',$this->input->post('select_employees[]'));
		//Check leaves not exist in the system
		$check_cond    = '"P","O","M","L","FL","SL","LP","PL","LM","ML","OL","LO","LL","WL","LW","UL","LU"';
		if((int)$process_type === 1){
			$table_name = 'cw_weekoff_import';
			$table_dlt  = 'cw_weekoff_import_dlt';
			$column     = 'weekoff_date';
		}else{
			$table_name = 'cw_shift_import';
			$table_dlt  = 'cw_shift_import_dlt';
			$column     = 'shift_date';
		}			
		$check_table_query  = 'SELECT count(*) as check_count from cw_time_entry inner join '.$table_name.' on '.$table_name.'.employee_code = cw_time_entry.employee_code and '.$table_name.'.'.$column.' = cw_time_entry.att_date WHERE whole_day_status in ('.$check_cond.') and cw_time_entry.trans_status = 1 and '.$table_name.'.employee_code in ("'.$employees.'") and '.$column.' between "'.$from_date.'" and "'.$to_date.'"';
		//echo $check_table_query; die;
		$check_table_info   = $this->db->query("CALL sp_a_run ('SELECT','$check_table_query')");
		$check_table_rlst   = $check_table_info->result();
		$check_table_info->next_result();
		$check_count = $check_table_rlst[0]->check_count;
		$ids         = $check_table_rlst[0]->ids;
		if((int)$check_count  === 0){
			//Get ids from the Time Entry
			$get_ids_query  = 'SELECT GROUP_CONCAT(prime_time_entry_id) as ids from cw_time_entry inner join '.$table_name.' on '.$table_name.'.employee_code = cw_time_entry.employee_code and '.$table_name.'.'.$column.' = cw_time_entry.att_date WHERE cw_time_entry.trans_status = 1 and '.$table_name.'.employee_code in ("'.$employees.'") and '.$column.' between "'.$from_date.'" and "'.$to_date.'"';
			$get_ids_info   = $this->db->query("CALL sp_a_run ('SELECT','$get_ids_query')");
			$get_ids_rlst   = $get_ids_info->result();
			$get_ids_info->next_result();
			$ids            = $get_ids_rlst[0]->ids;
			if($ids){
				//Move Data to Time Entry Dump table
				$delete_insert_query  = 'INSERT INTO cw_time_entry_dlt SELECT * FROM cw_time_entry WHERE prime_time_entry_id  in ('.$ids.') and trans_status = 1';
				$delete_insert_info   = $this->db->query("CALL sp_a_run ('INSERT','$delete_insert_query')");
				$delete_insert_rlst   = $delete_insert_info->result();
				$delete_insert_info->next_result();
				if($delete_insert_rlst){
					//Move Data from Time Entry table
					$delete_query  = 'DELETE FROM cw_time_entry WHERE prime_time_entry_id in ('.$ids.') and trans_status = 1';
					$delete_info = $this->db->query("CALL sp_a_run ('RUN','$delete_query')");
					if($delete_info){
						//Move to Dump table and Delete Data from Weekoff or Shift table
						$insert_qry = 'INSERT into '.$table_dlt.' SELECT * from '.$table_name.' where employee_code in ("'.$employees.'") and '.$column.' between "'.$from_date.'" and "'.$to_date.'"';
						$insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$insert_qry')");
						$insert_result      = $insert_info->result();
						$insert_info->next_result();
						if($insert_result){
							$delete_qry  = 'DELETE from '.$table_name.' where employee_code in ("'.$employees.'") and '.$column.' between "'.$from_date.'" and "'.$to_date.'"';
							$delete_rslt = $this->db->query("CALL sp_a_run ('RUN','$delete_qry')");
							if($delete_rslt){
								echo json_encode(array('success' => TRUE, 'message' => "Successfully Deleted"));
							}else{
								echo json_encode(array('success' => FALSE, 'message' => "Unable to Delete"));
							}	
						}else{
							echo json_encode(array('success' => FALSE, 'message' => "Please Try After Sometime..."));
						}												
					}else{
						echo json_encode(array('success' => FALSE, 'message' => "Unable to Delete"));
					}						
				}else{
					echo json_encode(array('success' => FALSE, 'message' => "Unable to Delete"));
				}
			}else{
				echo json_encode(array('success' => FALSE, 'message' => "No Employees Found.."));
			}				
		}else{
			echo json_encode(array('success' => FALSE, 'message' => "Unable to Delete.. Full Day Attendance or Leave Approved in the list..."));
		}	
	 }
	 public function get_salary_date(){
	 	$category       = $this->input->post('category');
	 	$month_day_info = $this->month_day_info($category);
	 	if(count($month_day_info)){
			$salary_start_date    = $month_day_info['salary_start_date'];
			$salary_end_date      = $month_day_info['salary_end_date'];
		}
		echo json_encode(array("success"=>true,"salary_start_date"=>$salary_start_date,"salary_end_date"=>$salary_end_date));

	 }
}
?>