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/ntc_cafsinfotech_in_bk/application/controllers/Trip_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Trip_report  extends Action_controller{	
	public function __construct(){
		parent::__construct('trip_report');
		$this->collect_base_info();
	}
	
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		$customer_type[""] = "--Select Customer--";
		$this->db->from('load_customer_type');
		$this->db->where('trans_status',1);
		$customer_type_result =  $this->db->get()->result();		
		foreach($customer_type_result as $key => $value){
			$load_customer_type_id  = $value->prime_load_customer_type_id;
			$load_customer_type     = $value->load_customer_type;
			$customer_type[$load_customer_type_id] = $load_customer_type;			
		}
		$data['load_customer_type'] = $customer_type;
		$this->load->view("$this->control_name/manage",$data);
	}
	//GET REPORT
	public function get_report(){
		$from_date 		= date('Y-m-d',strtotime($this->input->post("from_date")));
		$to_date 		= date('Y-m-d',strtotime($this->input->post("to_date")));
		$load_customer_arr 	= $this->input->post("load_customer_type");
		$array_filter       = array_filter($load_customer_arr);
		$load_customer_type = implode('","', $array_filter);

		$filter_qry 	= ' and cw_ntc_load.load_customer_type in ("'.$load_customer_type.'")';
		if(!$load_customer_type){
			$filter_qry = '';
		}

		$trailer_qry  	= 'select GROUP_CONCAT(reg_no,"-",register_no) as trailer,cw_ntc_load.prime_ntc_load_id as prime_ntc_load_id  from cw_ntc_load_trailer inner join cw_ntc_load on cw_ntc_load.prime_ntc_load_id = cw_ntc_load_trailer.ntc_load_id_trailer inner join cw_vehicle_master on cw_vehicle_master.prime_vehicle_master_id = cw_ntc_load_trailer.trailer_id where cw_ntc_load.from_date >= "'.$from_date.'" and cw_ntc_load.to_date <= "'.$to_date.'" and cw_ntc_load_trailer.trans_status = 1 and cw_ntc_load.trans_status = 1 and cw_vehicle_master.trans_status = 1 '.$filter_qry.' GROUP By cw_ntc_load.prime_ntc_load_id';
		$trailer_info   = $this->db->query("CALL sp_a_run ('SELECT','$trailer_qry')");
		$trailer_rslt 	= $trailer_info->result_array();
		$trailer_info->next_result();

		$trailer_rslt = array_reduce($trailer_rslt, function($result, $arr){			
		    $result[$arr['prime_ntc_load_id']] = $arr;
		    return $result;
		}, array());

		$get_data_qry  	= 'select cw_ntc_load.prime_ntc_load_id,cw_ntc_load.from_date,cw_ntc_load.to_date,cw_load_customer_type.load_customer_type,trip_status,cw_ntc_pickup_drop.shipment_number,cw_ntc_pickup_drop.amsa_shipment_no,cw_ntc_pickup_drop.number,cw_ntc_pickup_drop.mass,cw_ntc_pickup_drop.product,cw_vehicle_master.reg_no,cw_vehicle_master.register_no from cw_ntc_pickup_drop inner join cw_ntc_load on cw_ntc_load.prime_ntc_load_id = cw_ntc_pickup_drop.ntc_load_id_pickup_drop inner join cw_load_customer_type on cw_load_customer_type.prime_load_customer_type_id = cw_ntc_load.load_customer_type inner join cw_vehicle_master on cw_vehicle_master.prime_vehicle_master_id = cw_ntc_load.horse where cw_ntc_load.from_date >= "'.$from_date.'" and cw_ntc_load.to_date <= "'.$to_date.'" and cw_ntc_pickup_drop.trans_status = 1 and cw_ntc_load.trans_status = 1 and cw_load_customer_type.trans_status = 1 and cw_vehicle_master.trans_status = 1 '.$filter_qry.'';
		$get_data_info  = $this->db->query("CALL sp_a_run ('SELECT','$get_data_qry')");
		$get_data_rslt 	= $get_data_info->result();
		$get_data_info->next_result();

		$tr_line	= "";
		foreach ($get_data_rslt as $key => $value) {
			$trailer 			= $trailer_rslt[$value->prime_ntc_load_id]['trailer'];
			$shipment_number 	= $value->shipment_number;
			if(!$shipment_number){
				$shipment_number	= $value->amsa_shipment_no;
			}
			$trip_status		= $value->trip_status;
			if((int)$trip_status === 1){
				$trip_status 	= 'Schedule';
			}else
			if((int)$trip_status === 2){
				$trip_status 	= 'Confirm';
			}else
			if((int)$trip_status === 3){
				$trip_status 	= 'Onprogress';
			}else
			if((int)$trip_status === 4){
				$trip_status 	= 'Cancelled';
			}else
			if((int)$trip_status === 5){
				$trip_status 	= 'Completed';
			}else
			if((int)$trip_status === 6){
				$trip_status 	= 'Incompleted';
			}

			$horse_reg = $value->reg_no.' - '.$value->register_no;
			$tr_line  .="<tr><td>".$value->load_customer_type."</td><td>".$trip_status."</td><td>".$value->from_date."</td><td>".$to_date."</td><td>".$horse_reg."</td><td>".$trailer."</td><td>".$value->number."</td><td>".$shipment_number."</td><td>".$value->mass."</td><td>".$value->product."</td></tr>";
		}
		if($get_data_rslt){
			$table_content = "<div style='margin:20px;'>
							<table class='table table-striped table-bordered' id='trip_report'>
								<thead>
									<tr>
									<td>CUSTOMER</td>
									<td>TRIP STATUS</td>
									<td>FROM</td>
									<td>TO</td>
									<td>HORSE REG</td>
									<td>TRAILER</td>
									<td>LOAD NO</td>
									<td>SHIPMENT</td>
									<td>MASS</td>
									<td>PRODUCT</td>
									</tr>
								</thead>
								<tbody>
									$tr_line
								</tbody>
							</table>
						</div>";
			echo json_encode(array('success'=>true,'table_content'=>$table_content));
		}else{
			echo json_encode(array('success'=>false,'message'=>'NO DATA AVAILABLE','table_content'=>$table_content));
		}
	}
}