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

	//AUTOCOMPLETE
	public function rea_suggest_name(){
		$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);
		}
		$search_term  = $this->input->post_get('term');
		$final_qry    = 'SELECT rea FROM cw_project_list WHERE trans_status = 1 AND rea like "%'.$search_term.'%"';
		$final_data   = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
		$final_result = $final_data->result();
		$final_data->next_result();
		foreach($final_result as $rslt){
			$rea      = $rslt->rea;
			$suggestions[] = array('value' => "$rea", 'label' =>"$rea");
		}
		if(empty($suggestions)){
			$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
		}
		echo json_encode($suggestions);
	}

    //MASTER CHECKER INACTIVE -> CHECKER AUTOCOMPLETE
	public function master_checker_suggest_name(){
		$search_term  = $this->input->post_get('term');
		$final_qry    = 'SELECT employee_code,emp_name FROM cw_employees WHERE trans_status = 1 AND prime_employees_id != 1 AND (employee_code like "'.$search_term.'%" OR emp_name like "'.$search_term.'%") AND role = 13';
		$final_data   = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
		$final_result = $final_data->result();
		$final_data->next_result();
		foreach($final_result as $rslt){
			$employee_code = $rslt->employee_code;
			$emp_name      = $rslt->emp_name;
			$suggestions[] = array('value' => "$employee_code", 'label' =>"$employee_code - $emp_name",'mas_chk_name' => "$employee_code - $emp_name");
		}
		if(empty($suggestions)){
			$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
		}
		echo json_encode($suggestions);
	}

	//FETCH PROJECT DATA BASED ON REA
	public function fetch_rea_data(){
		$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);
		}
		$rea      = $this->input->post('rea');
		$pro_qry  = 'SELECT project_name,client_name,prime_project_list_id,master_checker FROM cw_project_list WHERE trans_status = 1 AND rea = "'.$rea.'"';
		$pro_data = $this->db->query("CALL sp_a_run ('SELECT','$pro_qry')");
		$pro_rslt = $pro_data->result();
		$pro_data->next_result();
		$project  = $pro_rslt[0]->project_name;
		$client   = $pro_rslt[0]->client_name;
		$pro_id   = $pro_rslt[0]->prime_project_list_id;
		$master_checker = $pro_rslt[0]->master_checker;
		if($master_checker){
			$mas_qry  = 'SELECT CONCAT_WS(" - ", employee_code,emp_name) AS mas_name FROM cw_employees WHERE trans_status = 1 AND employee_code = "'.$master_checker.'"';
			$mas_data = $this->db->query("CALL sp_a_run ('SELECT','$mas_qry')");
			$mas_rslt = $mas_data->result();
			$mas_data->next_result();
			$mas_name = $mas_rslt[0]->mas_name;
		}
		echo json_encode(array('success' => TRUE, 'project' => $project, 'client' => $client, 'pro_id' => $pro_id, 'master_checker' => $master_checker,'mas_name' => $mas_name));
	}

	public function qa_data_save(){
		$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);
		}
		$rea             = $this->input->post('rea');
		$qa_id           = $this->input->post('qa_id');
		$project         = $this->input->post('project');
		$project_name    = $this->input->post('project_name');
		$master_checker  = $this->input->post('master_checker');
		$weight_tons     = $this->input->post('weight_tons');
		$ratings         = $this->input->post('ratings');
		$created_on      = date("Y-m-d h:i:s"); 
		$chk_box         = [
			'check_1'    => $this->input->post('check_1'),
			'check_2'    => $this->input->post('check_2'),
			'check_3'    => $this->input->post('check_3'),
			'check_4'    => $this->input->post('check_4'),
			'check_5'    => $this->input->post('check_5'),
			'check_6'    => $this->input->post('check_6'),
			'check_7'    => $this->input->post('check_7'),
			'check_8'    => $this->input->post('check_8'),
			'check_9'    => $this->input->post('check_9'),
			'check_10'   => $this->input->post('check_10'),
		];
		$text_area       = [
			'remarks_1'  => $this->input->post('remarks_1'),
			'remarks_2'  => $this->input->post('remarks_2'),
			'remarks_3'  => $this->input->post('remarks_3'),
			'remarks_4'  => $this->input->post('remarks_4'),
			'remarks_5'  => $this->input->post('remarks_5'),
			'remarks_6'  => $this->input->post('remarks_6'),
			'remarks_7'  => $this->input->post('remarks_7'),
			'remarks_8'  => $this->input->post('remarks_8'),
			'remarks_9'  => $this->input->post('remarks_9'),
			'remarks_10' => $this->input->post('remarks_10'),
		];
		//CHECKBOX
		$checked = array();
		for($i = 1; $i <= 10; $i++){
		    $id  = 'check_' . $i;
		    if(isset($chk_box[$id]) && $chk_box[$id] == 'on'){
		        $checked[] = '1';
		    }else{
		        $checked[] = '0';
		    }
		}
		$checked   = implode(',', $checked ?? []);
		//REMARKS
		for($i = 1; $i <= 10; $i++){
		    $id    = 'remarks_' . $i;
		  	$val[] = $text_area[$id];
		}
		$remarks   = implode('|', $val ?? []);
		$rea_qry   = 'SELECT count(*) as data from cw_project_list WHERE trans_status = 1 AND rea = "'.$rea.'"';
		$rea_info  = $this->db->query("CALL sp_a_run ('SELECT','$rea_qry')");
		$rea_rslt  = $rea_info->result();
		$rea_info->next_result();
		$rea_count = (int)$rea_rslt[0]->data;
		if($rea_count === 0){
			echo json_encode(array('success' => false,'message' => 'Invalid REA number!'));
			exit(0);
		}
		$qa_qry    = 'SELECT * from cw_qa_checking WHERE trans_status = 1 AND prime_qa_checking_id = "'.$qa_id.'"';
		$qa_info   = $this->db->query("CALL sp_a_run ('SELECT','$qa_qry')");
		$qa_rslt   = $qa_info->result();
		$qa_info->next_result();
		$qa_count  = count($qa_rslt);
		# DATA TO INSERT/UPDATE
		$data      = [
			'rea'            => $rea,
			'project'        => $project,
			'project_name'   => $project_name,
			'master_checker' => $master_checker,
			'weight_tons'    => $weight_tons,
			'checked'        => $checked,
			'remarks'        => $remarks,
			'ratings'        => $ratings,
		];
		if((int)$qa_count === 0){ # INSERT
			$data['trans_created_date'] = $created_on;
			$data['trans_created_by']   = $this->logged_id;
			$this->db->insert('cw_qa_checking', $data);
			echo json_encode(array('success' => true,'message' => 'QA log Inserted Successfully!'));
			exit(0);
		}else{ # UPDATE
			$data['trans_updated_date'] = $created_on;
			$data['trans_updated_by']   = $this->logged_id;
			$this->db->where('prime_qa_checking_id', $qa_id);
			$this->db->update('cw_qa_checking', $data);
			echo json_encode(array('success' => true,'message' => 'QA log Updated Successfully!'));
			exit(0);
		}
	}

	// PROJECT DATA ONLOAD
	public function search(){
		$dec_data           = $this->cryptoDecrypt($_POST['Payload']);
		$_POST              = $dec_data['data'];
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Invalid Request..'));
			exit(0);
		}
		$draw               = $this->input->post('draw');
		$start              = $this->input->post('start');
		$per_page           = $this->input->post('length');
		$order              = $this->input->post('order');
		$order_col          = $this->input->post('columns');
		$search             = $this->input->post('search');
		$column             = $order[0]['column'];
		$order_sor          = $order[0]['dir'];
		$order_col          = $order_col[$column]['data'];
		$search             = trim($search['value']);
		$logged_est_team    = $this->session->userdata('logged_est_team');
		$fil_rea            = $this->input->post('fil_rea');
		//FILTER
		$filter_query       = "";
		if($fil_rea){
			$filter_query  .= ' AND cw_qa_checking.rea like ("%'.$fil_rea.'%")';
		}
		$common_search      = "";
		if($search){
			$common_search .= ' or cw_project_list.client_name like "'.$search.'%" or cw_qa_checking.rea like "'.$search.'%" or cw_qa_checking.project_name like "'.$search.'%" ';
			$common_search  = ltrim($common_search,' or ');
			$common_search  = " and ($common_search)";
			$common_search  = str_replace("(,","(",$common_search);
			$common_search  = str_replace("()","(0)",$common_search); 
		}
		$search_query       = 'SELECT prime_qa_checking_id,cw_qa_checking.rea,cw_qa_checking.project_name,cw_project_list.client_name,cw_project_list.billable_ton,ratings,cw_qa_checking.weight_tons,employee_code,CONCAT_WS(" - ", employee_code,emp_name) as trans_created_by FROM cw_qa_checking INNER JOIN cw_project_list ON cw_project_list.prime_project_list_id = cw_qa_checking.project INNER JOIN cw_employees ON cw_employees.prime_employees_id = cw_qa_checking.trans_created_by WHERE cw_employees.trans_status = 1 AND cw_project_list.trans_status = 1 AND cw_qa_checking.trans_status = 1 '.$filter_query.' '.$common_search.' ';
		$search_query      .= " ORDER BY $order_col $order_sor";
		if((int)$per_page !== -1){
			$search_query  .= " LIMIT $start,$per_page";
		}	
		$count_all_query    = 'SELECT count(*) as allcount FROM cw_qa_checking where trans_status = 1  ';
		$count_query        = 'SELECT count(*) FROM cw_qa_checking INNER JOIN cw_project_list ON cw_project_list.prime_project_list_id = cw_qa_checking.project INNER JOIN cw_employees ON cw_employees.prime_employees_id = cw_qa_checking.trans_created_by WHERE cw_employees.trans_status = 1 AND cw_project_list.trans_status = 1 AND cw_qa_checking.trans_status = 1 '.$filter_query.' '.$common_search.' ' ;
		$search_pro_qry     = [];
		$search_pro_qry[]   = array("return"=>"total_count","qry"=>$count_all_query);
		$search_pro_qry[]   = array("return"=>"filtered_count","qry"=>$count_query);
		$search_pro_qry[]   = array("return"=>"search_result","qry"=>$search_query);
		$search_info_rslt   = $this->run_multi_qry($search_pro_qry);
		$total_count        = $search_info_rslt->rslt->total_count[0]->allcount;
		$filtered_count     = $search_info_rslt->rslt->filtered_count[0]->allcount;
		$search_result      = json_decode(json_encode($search_info_rslt->rslt->search_result),true);
		if($search_result === null || $search_result === ''){
			$search_result  = [];
		}
		echo json_encode(array("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $search_result));
	}

	//QA DATA EDIT
	public function qa_edit(){
		$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);
		}
		$prime_id = $this->input->post('prime_id');
		$qa_qry   = 'SELECT prime_qa_checking_id,project,rea,project_name,master_checker,weight_tons,ratings,emp_name,checked,remarks from cw_qa_checking INNER JOIN cw_employees ON cw_qa_checking.master_checker = cw_employees.employee_code WHERE cw_employees.trans_status = 1 AND cw_qa_checking.trans_status = 1 AND prime_qa_checking_id = "'.$prime_id.'" ';
		$qa_info  = $this->db->query("CALL sp_a_run ('SELECT','$qa_qry')");
		$qa_rslt  = $qa_info->result();
		$qa_info->next_result();
		echo json_encode(array('success' => True,'qa_rslt' => $qa_rslt));
	}
}
?>