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/Ntc_load.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Ntc_load  extends Base_controller{
	
	public function __construct(){
		parent::__construct('ntc_load');
	}
	
	// LOAD PAGE WITH TABLE DATA
	public function index(){
		$data['table_headers']= $this->xss_clean(get_ntc_load_headers());
		$data['load_customer_type'] = $this->get_load_customer_type();
		$this->load->view("ntc_load/manage",$data);
	}
	
	//LOAD PAGE TABLE VIEW WITH DATA BASED ON SEARCH FILTERS
	public function search(){
		$search        = $this->input->get('search');
		$limit         = $this->input->get('limit');
		$offset        = $this->input->get('offset');
		$sort          = $this->input->get('sort');
		$order         = $this->input->get('order');
		$start_date    = str_replace("/","-",$this->input->get('start_date'));
		$end_date      = str_replace("/","-",$this->input->get('end_date'));	
		$from_date     = date('Y-m-d',strtotime($start_date));
		$to_date       = date('Y-m-d',strtotime($end_date));			
		$filters       = $this->input->get('filters');
		$load_customer_type = $this->input->get('load_customer_type');
	
		$this->db->select('ntc_load.prime_ntc_load_id,ntc_load.to_date,ntc_load.from_date,load_customer_type.load_customer_type,ntc_load.trip_status,ntc_load.delivery_note,ntc_load.return_note,ntc_load.note,ntc_load.cancel_note,ntc_load.incomplete_note,vehicle_master.reg_no,vehicle_master.register_no');
		$this->db->from('ntc_load');
		$this->db->join('vehicle_master', 'vehicle_master.prime_vehicle_master_id = ntc_load.horse','inner');
		$this->db->join('load_customer_type', 'load_customer_type.prime_load_customer_type_id = ntc_load.load_customer_type','inner');
		$this->db->where('ntc_load.trans_status', 1);		
		if($search){
			$this->db->group_start();
				$this->db->like('prime_ntc_load_id',$search);
				$this->db->or_like('delivery_note',$search);
				$this->db->or_like('return_note',$search);
				$this->db->or_like('note',$search);
				$this->db->or_like('cancel_note',$search);
				$this->db->or_like('incomplete_note',$search);
				$this->db->or_like('reg_no',$search);
				$this->db->or_like('register_no',$search);
				if(strpos($search, '-') !== false){
				  $this->db->or_like('from_date', date('Y-m-d',strtotime($search))); 
				  $this->db->or_like('to_date', date('Y-m-d',strtotime($search)));
				}
			$this->db->group_end();	
		}
		$this->db->group_start();
		$this->db->where('DATE_FORMAT(from_date, "%Y-%m-%d") BETWEEN '. $this->db->escape($from_date).' AND '.$this->db->escape($to_date));
		$this->db->group_end();
		if($filters[0] > 0){
			$this->db->where_in('trip_status', $filters);
		}
		$filters_sts = array();
		foreach($load_customer_type as $key=>$value){
			if($value){ $filters_sts[] = $value; }
		}
		if(count($filters_sts) > 0){
			$this->db->where_in('load_customer_type.prime_load_customer_type_id', $filters_sts);
		}
		
		$this->db->order_by($sort,$order);
		$ntc_load_data = $this->db->get();
		$ntc_load_rslt = $ntc_load_data->result();
		$num_rows      = $ntc_load_data->num_rows();
		$datarows=array();		
		foreach($ntc_load_rslt as $ntc_load){	
			$datarows[]=get_ntc_load_datarows($ntc_load,$this);
		}
		echo json_encode(array('total'=>$num_rows,'rows'=>$datarows));
	}
	public function get_load_customer_type(){
		$this->db->from('load_customer_type');
		$this->db->where('trans_status',1);
		$customer_type_info =  $this->db->get()->result();
	    foreach($customer_type_info as $row){
		$load_customer_type[$row->prime_load_customer_type_id] = $row->load_customer_type;
	    }
	 return $load_customer_type;
	}
	/**************************************************************
					COMMON INFORMATION  - START
	***************************************************************/	
	//LOAD MODEL PAGE VIEW WITH DATA
	public function view($prime_ntc_load_id=-1){
		$this->db->from('ntc_load');
		$this->db->where('prime_ntc_load_id',$prime_ntc_load_id);
		$this->db->where('ntc_load.trans_status', 1);
		$data['ntc_load'] = $this->db->get()->row();
		//$load_cust_type   = $data['ntc_load']->load_customer_type;
		//vehicle List
		$horse_list[""] = "--Select Horse--";
		$trailer_list[""] = "--select Trailer--";
		$this->db->from('vehicle_master');
		$this->db->where('trans_status',1);
		$vehicle_result =  $this->db->get()->result();
		foreach($vehicle_result as $value){
			$prime_vehicle_master_id = $value->prime_vehicle_master_id;	
			if((int)$value->vehicle_category === 1){
				$reg_no_horse                  = $value->reg_no;
				$register_no_horse  		   = $value->register_no;
				$horse_list[$prime_vehicle_master_id] = "$reg_no_horse - $register_no_horse";
			}
			if((int)$value->vehicle_category === 2){
				$reg_no_trailer                 = $value->reg_no;
				$register_no_trailer			 = $value->register_no;	
				$trailer_list[$prime_vehicle_master_id] = "$reg_no_trailer - $register_no_trailer";
			}
		}
		//Origin and Destination inputs from Depo master
		$this->db->select('cw_sab_depo_master.prime_sab_depo_master_id,depo_short_name,depo_name');
		$this->db->from('cw_sab_depo_master');
		$this->db->where('cw_sab_depo_master.trans_status',1);
		$location_result =  $this->db->get()->result();
		$origin_destination[""] = "--Select Horse--";
		foreach($location_result as $location_result_data){
			$prime_sab_depo_master_id = $location_result_data->prime_sab_depo_master_id;	
			$depo_short_name          = $location_result_data->depo_short_name;
			$depo_name                = $location_result_data->depo_name;
			$origin_destination[$prime_sab_depo_master_id] = "$depo_short_name - $depo_name";				
		}
		//Load Customer Type List
		$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){
			//print_r($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;
		$data['origin_destination'] = $origin_destination;
		$data['trailer_list']       = $trailer_list;
		$data['horse_list']         = $horse_list;
		$trailer_save_list          = $this->get_trailer_list($prime_ntc_load_id);
		$data['trailer_save_list']  = $trailer_save_list['table_content'];
		//SAB Table Data
		$get_pickup_drop_info          = $this->get_pickup_drop_info($prime_ntc_load_id);
		$data['get_pickup_drop_info']  = $get_pickup_drop_info['table_content'];
		//Delivery Note
		$get_delivery_note_info          = $this->get_delivery_note_info($prime_ntc_load_id);
		$data['get_delivery_note_info']  = $get_delivery_note_info['table_content'];
		//ADHOC Table Data
		$get_adhoc_pickup_drop_info          = $this->get_adhoc_pickup_drop_info($prime_ntc_load_id);
		$data['get_adhoc_pickup_drop_info']  = $get_adhoc_pickup_drop_info['table_content'];
		//AFRISM Table Data		
		$get_pickup_drop_afrism_info          = $this->get_pickup_drop_afrism_info($prime_ntc_load_id);
		$data['get_pickup_drop_afrism_info']  = $get_pickup_drop_afrism_info['table_content'];
		//AMSA Table Data		
		$get_amsa_pickup_drop_info          = $this->get_amsa_pickup_drop_info($prime_ntc_load_id);
		$data['get_amsa_pickup_drop_info']  = $get_amsa_pickup_drop_info['table_content'];
		$this->load->view("ntc_load/form",$data);
	}
	/**************************************************************
					COMMON INFORMATION  - END
	***************************************************************/
	
	
	//TRIP INFORMATION SAVE
	public function ntc_load_save(){
		$prime_ntc_load_id = (int)$this->input->post('prime_ntc_load_id');
		$from_date         = date('Y-m-d',strtotime($this->input->post('from_date')));
		$to_date           = date('Y-m-d',strtotime($this->input->post('to_date')));
		$trip_information   = array(
			'from_date'          => $from_date,
			'to_date'            => $to_date,	
			'horse'              => $this->input->post('horse'),
			'load_customer_type' => $this->input->post('customer_type'),
			'trip_status'        => $this->input->post('trip_status'),
			'delivery_note'      => $this->input->post('delivery_note'),
			'return_note'        => $this->input->post('return_note'),
			'note'               => $this->input->post('note'),
			'cancel_note'        => $this->input->post('cancel_note'),
			'incomplete_note'    => $this->input->post('incomplete_note')
		);		
		$this->db->from('ntc_load');
		$this->db->group_start();
		$this->db->where('from_date',$from_date);
		$this->db->or_where('to_date',$to_date);
		$this->db->group_end();
		$this->db->where('horse',$this->input->post('horse'));
		$this->db->where('prime_ntc_load_id',$prime_ntc_load_id);
		$this->db->where('trans_status',1);
		$sab_info  =  $this->db->get();
		$sab_count = $sab_info->num_rows();
		if((int)$sab_count === 0){
			$trip_information['trans_created_by'] = $this->session->userdata('logged_id');
			$trip_information['trans_created_date'] = date("Y-m-d H:i:s");
			$this->db->insert('ntc_load',$trip_information);
			$prime_ntc_load_id = $this->db->insert_id();
			echo json_encode(array('success' => TRUE, 'message' => "Trip Information successfully added",'prime_ntc_load_id' => $prime_ntc_load_id));
		}else
		if((int)$sab_count === 1){
			$sab_rslt = $sab_info->row();
			$db_prime_ntc_load_id = (int)$sab_rslt->prime_ntc_load_id;
			if($db_prime_ntc_load_id === $prime_ntc_load_id){
				$trip_information['trans_updated_by'] = $this->session->userdata('logged_id');
				$trip_information['trans_updated_date'] = date("Y-m-d H:i:s");
				$this->db->where('prime_ntc_load_id', $prime_ntc_load_id);
				$this->db->update('ntc_load',$trip_information);
				echo json_encode(array('success' => TRUE, 'message' => "Trip Information successfully updated",'prime_ntc_load_id' => $prime_ntc_load_id));
			}else{
				echo json_encode(array('success' => false, 'message' => "Record already exist in different trip"));
			}
		}else{
			echo json_encode(array('success' => false, 'message' => "unable to process please contact admin"));
		}
	}
	
	//TRAILER SAVE
	public function trailer_prime_id_exist($prime_ntc_load_trailer_id){
		$this->db->from('ntc_load_trailer');
		$this->db->where('prime_ntc_load_trailer_id', $prime_ntc_load_trailer_id);
		return ($this->db->get()->num_rows() == 1);
	}
	public function trailer_exist($trailer_id,$ntc_load_id_trailer,$prime_ntc_load_trailer_id){		
		$sts = "";
		$this->db->from('ntc_load_trailer');
		$this->db->where('ntc_load_id_trailer',$ntc_load_id_trailer);
		$this->db->where('trailer_id',$trailer_id);
		$this->db->where('trans_status',1);
		$sab_info  =  $this->db->get();
		$sab_count = $sab_info->num_rows();
		if((int)$sab_count === 0){
			if(!$prime_ntc_load_trailer_id || !$this->trailer_prime_id_exist($prime_ntc_load_trailer_id, TRUE)){
				$sts = "INSERT";
			}else{
				$sts = "UPDATE";
			}
		}else
		if((int)$sab_count === 1){
			$sab_rslt = $sab_info->row();
			$db_prime_ntc_load_trailer_id = (int)$sab_rslt->prime_ntc_load_trailer_id;
			if($db_prime_ntc_load_trailer_id === $prime_ntc_load_trailer_id){
				$sts = "UPDATE";
			}else{
				$sts = "EXIST";
			}
		}else{
			$sts = "UNK";
		}
		return $sts;
	}
	
	
	public function trailer_save(){
		$prime_ntc_load_trailer_id  = (int)$this->input->post('prime_ntc_load_trailer_id');
		$ntc_load_id_trailer      	= (int)$this->input->post('ntc_load_id_trailer');
		if($ntc_load_id_trailer > 0){
			$remarks_trailer      		=  $this->input->post('remarks_trailer');
			$trailer_id  				= (int)$this->input->post('trailer_id');
			$trailer_information  = array(	
				'ntc_load_id_trailer'       => $ntc_load_id_trailer,
				'trailer_id'                => $trailer_id,
				'remarks_trailer'           => $remarks_trailer
			);
			
			$process_info = $this->trailer_exist($trailer_id,$ntc_load_id_trailer,$prime_ntc_load_trailer_id);
			if($process_info === "INSERT"){
				$trailer_information['trans_created_by'] = $this->session->userdata('logged_id');
				$trailer_information['trans_created_date'] = date("Y-m-d H:i:s");
				$this->db->insert('ntc_load_trailer',$trailer_information);
				$prime_ntc_load_trailer_id = $this->db->insert_id();
				$trailer_assigned = $this->get_trailer_list($ntc_load_id_trailer);
				$trailer_assigned = $trailer_assigned['table_content'];
				echo json_encode(array('success' => TRUE, 'message' => "Trailer Information successfully added",'trailer_assigned' => $trailer_assigned));
			}else
			if($process_info === "UPDATE"){
				$trailer_information['trans_updated_by'] = $this->session->userdata('logged_id');
				$trailer_information['trans_updated_date'] = date("Y-m-d H:i:s");
				$this->db->where('prime_ntc_load_trailer_id', $prime_ntc_load_trailer_id);
				$this->db->update('ntc_load_trailer',$trailer_information);
				$trailer_assigned = $this->get_trailer_list($ntc_load_id_trailer);
				$trailer_assigned = $trailer_assigned['table_content'];
				echo json_encode(array('success' => TRUE, 'message' => "Trailer Information successfully updated",'trailer_assigned' => $trailer_assigned));
			}else
			if($process_info === "EXIST"){
				echo json_encode(array('success' => false, 'message' => "Record already exist"));
			}else{
				echo json_encode(array('success' => false, 'message' => "Unable to process your request please contact admin"));
			}
		}else{
			echo json_encode(array('success' => false, 'message' => "Please complete the trip information"));
		}
	}	
	
	// AFRISM PICKUP AND DROP INFORMATION SAVE
	public function pickup_drop_afrism_save(){
		$prime_pickup_drop_id    = (int)$this->input->post('prime_afrism_pickup_drop_id');
		$ntc_load_id_pickup_drop = (int)$this->input->post('ntc_load_id_pickup_drop');
		$origin                  = $this->input->post('loading_from');
		$destination             = $this->input->post('destination_add');
		if($ntc_load_id_pickup_drop > 0){
			if(($this->input->post('loading_from')) === ($this->input->post('destination_add'))){
				echo json_encode(array('success' => false, 'message' => "Origin & Destination Cannot be same"));die;
			}
			$pickup_drop_afrism_information  = array(
		        'ntc_load_id_pickup_drop'=> $ntc_load_id_pickup_drop,
				'trip_type'              => $this->input->post('trip_type_afrism'),
				'origin'                 => $origin,
				'destination'            => $destination,
				'origin_landmark'        => $this->input->post('loading_add'),
				'destination_landmark'   => $this->input->post('offloading_add'),
				'loading_tat'            => date("Y-m-d H:i:s",strtotime($this->input->post('loading_time'))),
				'offloading_tat'         => date("Y-m-d H:i:s",strtotime($this->input->post('offloading_time'))),
				'cartage_zone'           => $this->input->post('cartage_zone'),
				'product'                => $this->input->post('product'),
				'seq_no'                 => $this->input->post('seq_no'),
				'time_in'                => date("Y-m-d H:i:s",strtotime($this->input->post('time_in'))),
				'time_out'               => date("Y-m-d H:i:s",strtotime($this->input->post('time_out'))),
				'gross'                  => $this->input->post('gross'),
				'tare'                   => $this->input->post('tare'),
				'net'                    => $this->input->post('net'),
				'loading_kms'            => $this->input->post('km_loading'),
				'afrisam_delivery_note'  => $this->input->post('afrisam_delivery_note'),
				'afrisam_return_note'    => $this->input->post('afrisam_return_note'),
				'afrisam_note'           => $this->input->post('afrisam_note'),
				'offloading_kms'         => $this->input->post('km_offloading')
			);			
			$process_info_pickup_drop = $this->pickup_drop_exists($origin,$destination,$prime_pickup_drop_id,$ntc_load_id_pickup_drop);
			if($process_info_pickup_drop === "INSERT"){
					$pickup_drop_afrism_information['trans_created_by'] = $this->session->userdata('logged_id');
					$pickup_drop_afrism_information['trans_created_date'] = date("Y-m-d H:i:s");
					$this->db->insert('cw_ntc_pickup_drop',$pickup_drop_afrism_information);
					$insert_id = $this->db->insert_id();
					$this->update_trip_map_info($insert_id,$ntc_load_id_pickup_drop);
					$trailer_assigned = $this->get_pickup_drop_afrism_info($ntc_load_id_pickup_drop);
					$trailer_assigned = $trailer_assigned['table_content'];
					echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully added",'trailer_assigned' => $trailer_assigned));
			}else
			if($process_info_pickup_drop === "UPDATE"){
					$pickup_drop_afrism_information['trans_updated_by'] = $this->session->userdata('logged_id');
					$pickup_drop_afrism_information['trans_updated_date'] = date("Y-m-d H:i:s");
					$this->db->where('prime_pickup_drop_id', $prime_pickup_drop_id);
					$this->db->update('cw_ntc_pickup_drop',$pickup_drop_afrism_information);
					$this->update_trip_map_info($prime_pickup_drop_id,$ntc_load_id_pickup_drop);
					$trailer_assigned = $this->get_pickup_drop_afrism_info($ntc_load_id_pickup_drop);
					$trailer_assigned = $trailer_assigned['table_content'];
					echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully updated",'trailer_assigned' => $trailer_assigned));
			}else
			if($process_info_pickup_drop === "EXIST"){
				echo json_encode(array('success' => false, 'message' => "Record already exist"));
			}else{
				echo json_encode(array('success' => false, 'message' => "Unable to process your request please contact admin"));
			}
		}else{
			echo json_encode(array('success' => false, 'message' => "Please complete the trip information"));
		}
	}
	
	//GET TRAILER LIST
	public function get_trailer_list($ntc_load_id){
		$this->db->select('vehicle_master.reg_no,vehicle_master.register_no,ntc_load_trailer.prime_ntc_load_trailer_id,ntc_load_trailer.remarks_trailer');
		$this->db->from('vehicle_master');
		$this->db->join('ntc_load_trailer', 'vehicle_master.prime_vehicle_master_id = ntc_load_trailer.trailer_id','inner');
		$this->db->where('ntc_load_trailer.ntc_load_id_trailer',$ntc_load_id);
		$this->db->where('ntc_load_trailer.trans_status',1);
		$this->db->where('vehicle_master.vehicle_category',2);
		$this->db->where('vehicle_master.trans_status',1);
		$trailer_list = $this->db->get();
		$trailer_list = $trailer_list->result();
		foreach($trailer_list as $value){
			$reg_no      = $value->reg_no;
			$register_no = $value->register_no;
			$remarks_trailer = $value->remarks_trailer;
			$prime_ntc_load_trailer_id = $value->prime_ntc_load_trailer_id;
			$edit_id      = "edit_"."$prime_ntc_load_trailer_id";		
			$delete_id    = "delete_"."$prime_ntc_load_trailer_id";
			$tr_line     .= "<tr>
							<td>$reg_no.$register_no</td>
							<td>$remarks_trailer</td>
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='$edit_id' onclick=edit_trailer_record('$prime_ntc_load_trailer_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Edit</button>
							</td>
							<td>
								<button type='button' class='btn btn-danger btn-xs btn_action' id='$delete_id' onclick=delete_trailer_record('$prime_ntc_load_trailer_id')><i class='fa fa-trash fa-large' aria-hidden='true'></i> Delete</button>
							</td>
						</tr>";
		}
		$table_content = "<table class='table table-bordered' id='assign_trailer_list_table' style='background-color:#FFFFFF;'>
							<thead>
								<tr>
									<th>Trailer Assigned</th>
									<th>Remarks</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
								$tr_line
							</tbody>
						</table>";
		return array('table_content' => $table_content);
	}
	
	//DELETE TRAILER RECORD
	public function delete_trailer_record(){
		$delete_id = $this->input->post('delete_trailer_id');
		$this->db->select('ntc_load_id_trailer');
		$this->db->from('ntc_load_trailer');
		$this->db->where('prime_ntc_load_trailer_id',$delete_id);
		$prime_ntc_load_id = $this->db->get();
		$prime_ntc_load_id = $prime_ntc_load_id->row();
		$prime_ntc_load_id = $prime_ntc_load_id->ntc_load_id_trailer;
		$ntc_load_trailer = array(
					'trans_status'       =>0,
					'trans_deleted_by'   =>$this->session->userdata('logged_id'),
					'trans_deleted_date' =>  date("Y-m-d H:i:s"),
				);
		$this->db->where('prime_ntc_load_trailer_id', $delete_id);
		if($this->db->update('ntc_load_trailer', $ntc_load_trailer)){
			$get_trailer_list = $this->get_trailer_list($prime_ntc_load_id);
			$get_trailer_list = $get_trailer_list['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "Deleted Successfully",'trailer_assigned' => $get_trailer_list));
		}else{
			echo json_encode(array('success' => false, 'message' => "Unable to process your request"));
		}
	}
	
	//EDIT TRAILER RECORD //ntc_load_id_pickup_drop
	public function edit_trailer_record(){
	$edit_record_id = (int)$this->input->post('edit_record_id');
		if($edit_record_id >0){			
			$this->db->select('prime_ntc_load_trailer_id,ntc_load_id_trailer,trailer_id,remarks_trailer');
			$this->db->from('ntc_load_trailer');
			$this->db->where('prime_ntc_load_trailer_id', $edit_record_id);
			$this->db->where('trans_status', 1);
			$edit_trailer_record    = $this->db->get()->row();
			echo json_encode(array('success' =>true,'edit_trailer_record'=>$edit_trailer_record));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Unable to process your request, Please refresh page and retry"));
		}
	}
	
	//PICKUP AND DROP INFORMATION SAVE
	public function pickup_drop_id_exists($prime_pickup_drop_id){
		$this->db->from('cw_ntc_pickup_drop');
		$this->db->where('prime_pickup_drop_id',$prime_pickup_drop_id);
		return ($this->db->get()->num_rows() == 1);
	}
	
	public function pickup_drop_exists($origin,$destination,$prime_pickup_drop_id,$ntc_load_id_pickup_drop){	
		$this->db->from('cw_ntc_pickup_drop');
		$this->db->where('destination',$destination);
		$this->db->where('origin',$origin);
		$this->db->where('ntc_load_id_pickup_drop',$ntc_load_id_pickup_drop);
		$this->db->where('trans_status',1);
		$sab_info_pickup_drop  =  $this->db->get();
		$sab_count_pickup = $sab_info_pickup_drop->num_rows();
		if((int)$sab_count_pickup === 0){
			if(!$prime_pickup_drop_id || !$this->pickup_drop_id_exists($prime_pickup_drop_id, TRUE)){
				$sts = "INSERT";
			}else{
				$sts = "UPDATE";
			}
		}else
		if((int)$sab_count_pickup === 1){
			$sab_rslt_pickup = $sab_info_pickup_drop->row();
			$db_prime_ntc_load_trailer_id = (int)$sab_rslt_pickup->prime_pickup_drop_id;
			if($db_prime_ntc_load_trailer_id === $prime_pickup_drop_id){
				$sts = "UPDATE";
			}else{
				$sts = "EXIST";
			}
		}else{
			$sts = "SVK";
		}
		return $sts;
	}
	
	//SAB Data
	public function pickup_drop_save(){
		$prime_pickup_drop_id    = (int)$this->input->post('prime_pickup_drop_id');
		$ntc_load_id_pickup_drop = (int)$this->input->post('ntc_load_id_pickup_drop');
		$origin                  = $this->input->post('origin');
		$destination             = $this->input->post('destination');
		
		if($ntc_load_id_pickup_drop > 0){
			if($origin === $destination){
				echo json_encode(array('success' => false, 'message' => "Origin & Destination Cannot be same"));die;
			}
			$pickup_drop_information  = array(
			'ntc_load_id_pickup_drop'	 => $ntc_load_id_pickup_drop,
			'trip_type'                  => $this->input->post('trip_type'),
			'origin'                     => $origin ,
			'destination'                => $destination,
			'origin_landmark'            => $this->input->post('origin_landmark'),
			'destination_landmark'       => $this->input->post('destination_landmark'),
			'offload_arrival_time'       => $this->input->post('offload_arrival_time'),
			'type_number'                => $this->input->post('type_number'),
			'number'                     => $this->input->post('number'),
			'shipment_number'            => $this->input->post('shipment_number'),
			'dc_tat'                     => $this->input->post('dc_tat'),
			'km'                         => $this->input->post('km'),
			'departure_time'             => $this->input->post('departure_time'),
			'arrival_time'               => $this->input->post('arrival_time'),
			'sab_delivery_note'          => $this->input->post('sab_delivery_note'),
			'sab_return_note'            => $this->input->post('sab_return_note'),
			'sab_note'               	 => $this->input->post('sab_note'),
			'eta_dc'                     => $this->input->post('eta_dc'),
			'mass'                       => $this->input->post('mass'),
			'offload_departure_time'     => $this->input->post('offload_departure_time')
			);					
			$process_info_pickup_drop = $this->pickup_drop_exists($origin,$destination,$prime_pickup_drop_id,$ntc_load_id_pickup_drop);
			if($process_info_pickup_drop === "INSERT"){
					$pickup_drop_information['trans_created_by'] = $this->session->userdata('logged_id');
					$pickup_drop_information['trans_created_date'] = date("Y-m-d H:i:s");
					$this->db->insert('cw_ntc_pickup_drop',$pickup_drop_information);
					$insert_id = $this->db->insert_id();
					$this->update_trip_map_info($insert_id,$ntc_load_id_pickup_drop);
					$trailer_assigned = $this->get_pickup_drop_info($ntc_load_id_pickup_drop,$load_customer_type);
					$trailer_assigned = $trailer_assigned['table_content'];
					echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully added",'trailer_assigned' => $trailer_assigned));
			}else
			if($process_info_pickup_drop === "UPDATE"){
					$pickup_drop_information['trans_updated_by'] = $this->session->userdata('logged_id');
					$pickup_drop_information['trans_updated_date'] = date("Y-m-d H:i:s");
					$this->db->where('prime_pickup_drop_id', $prime_pickup_drop_id);
					$this->db->update('cw_ntc_pickup_drop',$pickup_drop_information);
					$this->update_trip_map_info($prime_pickup_drop_id,$ntc_load_id_pickup_drop);
					$trailer_assigned = $this->get_pickup_drop_info($ntc_load_id_pickup_drop,$load_customer_type);
					$trailer_assigned = $trailer_assigned['table_content'];
					echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully updated",'trailer_assigned' => $trailer_assigned));
			}else
			if($process_info_pickup_drop === "EXIST"){
				echo json_encode(array('success' => false, 'message' => "Record already exist"));
			}else{
				echo json_encode(array('success' => false, 'message' => "Unable to process your request please contact admin"));
			}
		}else{
			echo json_encode(array('success' => false, 'message' => "Please complete the trip information"));
		}
	}
	
	//ADHOC Data
	public function adhoc_pickup_drop_save(){
		$prime_pickup_drop_id    = (int)$this->input->post('prime_adhoc_pickup_drop_id');
		$ntc_load_id_pickup_drop = (int)$this->input->post('ntc_load_id_pickup_drop');
		$load_customer_type      = (int)$this->input->post('load_customer_type');
		$origin                  = $this->input->post('adhoc_origin');
		$destination             = $this->input->post('adhoc_destination');	
		if($ntc_load_id_pickup_drop > 0){
			if($origin === $destination){
				echo json_encode(array('success' => false, 'message' => "Origin & Destination Cannot be same"));die;
			}	
			$pickup_drop_information  = array(
				'ntc_load_id_pickup_drop' => $ntc_load_id_pickup_drop,
				'trip_type'            => $this->input->post('adhoc_trip_type'),
				'origin'               => $origin,
				'origin_landmark'      => $this->input->post('adhoc_origin_landmark'),	
				'loading_tat'          => date("Y-m-d H:i:s",strtotime($this->input->post('loading_tat'))),		
				'destination'          => $destination,
				'destination_landmark' => $this->input->post('adhoc_destination_landmark'),
				'offloading_tat'       => date("Y-m-d H:i:s",strtotime($this->input->post('offloading_tat'))),
				'type_number'          => $this->input->post('adhoc_type_number'),
				'number'               => $this->input->post('adhoc_number'),
				'shipment_number'      => $this->input->post('adhoc_shipment_number'),
				'mass'                 => $this->input->post('adhoc_mass'),
				'loading_kms'          => $this->input->post('loading_kms'),
				'adhoc_delivery_note'  => $this->input->post('adhoc_delivery_note'),
				'adhoc_return_note'    => $this->input->post('adhoc_return_note'),
				'adhoc_note'           => $this->input->post('adhoc_note'),
				'offloading_kms'       => $this->input->post('offloading_kms')
			);
			$process_info_pickup_drop = $this->pickup_drop_exists($origin,$destination,$prime_pickup_drop_id,$ntc_load_id_pickup_drop);
				if($process_info_pickup_drop === "INSERT"){
						$pickup_drop_information['trans_created_by'] = $this->session->userdata('logged_id');
						$pickup_drop_information['trans_created_date'] = date("Y-m-d H:i:s");
						$this->db->insert('cw_ntc_pickup_drop',$pickup_drop_information);
						$insert_id = $this->db->insert_id();
						$this->update_trip_map_info($insert_id,$ntc_load_id_pickup_drop);
						$trailer_assigned = $this->get_adhoc_pickup_drop_info($ntc_load_id_pickup_drop,$load_customer_type);
						$trailer_assigned = $trailer_assigned['table_content'];
						echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully added",'trailer_assigned' => $trailer_assigned));
				}else
				if($process_info_pickup_drop === "UPDATE"){
						$pickup_drop_information['trans_updated_by'] = $this->session->userdata('logged_id');
						$pickup_drop_information['trans_updated_date'] = date("Y-m-d H:i:s");
						$this->db->where('prime_pickup_drop_id', $prime_pickup_drop_id);
						$this->db->update('cw_ntc_pickup_drop',$pickup_drop_information);
						$this->update_trip_map_info($prime_pickup_drop_id,$ntc_load_id_pickup_drop);
						$trailer_assigned = $this->get_adhoc_pickup_drop_info($ntc_load_id_pickup_drop,$load_customer_type);
						$trailer_assigned = $trailer_assigned['table_content'];
						echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully updated",'trailer_assigned' => $trailer_assigned));
				}else
				if($process_info_pickup_drop === "EXIST"){
					echo json_encode(array('success' => false, 'message' => "Record already exist"));
				}else{
					echo json_encode(array('success' => false, 'message' => "Unable to process your request please contact admin"));
				}
		}else{
			echo json_encode(array('success' => false, 'message' => "Please complete the trip information"));
		}
	}
	//AMSA Data
	public function amsa_pickup_drop_save(){
		$prime_pickup_drop_id    = (int)$this->input->post('prime_amsa_pickup_drop_id');
		$ntc_load_id_pickup_drop = (int)$this->input->post('ntc_load_id_pickup_drop');
		$load_customer_type      = (int)$this->input->post('load_customer_type');
		$origin                  = $this->input->post('amsa_origin');
		$destination             = $this->input->post('amsa_destination');
		$amsa_shipment_no        = $this->input->post('amsa_shipment_no');	
		if($ntc_load_id_pickup_drop > 0){
			if($origin === $destination){
				echo json_encode(array('success' => false, 'message' => "Origin & Destination Cannot be same"));die;
			}	
			$pickup_drop_information  = array(
				'ntc_load_id_pickup_drop' => $ntc_load_id_pickup_drop,
				'trip_type'            => $this->input->post('amsa_trip_type'),				
				'destination'          => $destination,
				'destination_landmark' => $this->input->post('amsa_destination_landmark'),
				'dunnage_in'           => $this->input->post('dunnage_in'),
				'dunnage_out'          => $this->input->post('dunnage_out'),
				'dunnage_total'        => $this->input->post('dunnage_total'),
				'dunnage_cust'         => $this->input->post('dunnage_cust'),
				'tarps'                => $this->input->post('tarps'),
				'dispatched_from'      => $this->input->post('dispatched_from'),
				'dispatched_to'        => $this->input->post('dispatched_to'),
				'amsa_shipment_no'	   => $amsa_shipment_no,
				'dispatched_time'      => date("Y-m-d H:i:s",strtotime($this->input->post('dispatched_time'))),
				'eta'                  => date("Y-m-d H:i:s",strtotime($this->input->post('eta'))),
				'trip_time'            => date("Y-m-d H:i:s",strtotime($this->input->post('trip_time'))),
				'exception'            => $this->input->post('exception'),
				'loading_time'         => date("Y-m-d H:i:s",strtotime($this->input->post('loading_time'))),
				'loading_tat'          => $this->input->post('amsa_loading_tat'),	
				'time_depart_nc'       => date("Y-m-d H:i:s",strtotime($this->input->post('time_depart_nc'))),
				'nc_tat'               => $this->input->post('nc_tat'),
				'delay'                => $this->input->post('delay'),
				'customer_eta'         => date("Y-m-d H:i:s",strtotime($this->input->post('customer_eta'))),
				'arrival_time_customer' => date("Y-m-d H:i:s",strtotime($this->input->post('arrival_time_customer'))),
				'return_trip_time'     => $this->input->post('return_trip_time'),
				'time_completed'       => date("Y-m-d H:i:s",strtotime($this->input->post('time_completed'))),
				'customer_tat'         => $this->input->post('customer_tat'),
				'depot_arrival'        => date("Y-m-d H:i:s",strtotime($this->input->post('depot_arrival'))),
				'depart_from_depot'    => date("Y-m-d H:i:s",strtotime($this->input->post('depart_from_depot'))),
				'depot_tat'            => $this->input->post('depot_tat'),
				'km_nc'                => $this->input->post('km_nc'),
				'mass'                 => $this->input->post('amsa_mass'),
				'loading_kms'          => $this->input->post('amsa_loading_kms'),
				'amsa_delivery_note'   => $this->input->post('amsa_delivery_note'),
				'amsa_return_note'     => $this->input->post('amsa_return_note'),
				'amsa_note'            => $this->input->post('amsa_note'),
				'depot_time_checkbox'  => (int)$this->input->post('depot_time_checkbox'),
				'offloading_kms'       => $this->input->post('amsa_offloading_kms')
			);
			$process_info_pickup_drop = $this->pickup_drop_exists($origin,$destination,$prime_pickup_drop_id,$ntc_load_id_pickup_drop);
				if($process_info_pickup_drop === "INSERT"){
						$pickup_drop_information['trans_created_by'] = $this->session->userdata('logged_id');
						$pickup_drop_information['trans_created_date'] = date("Y-m-d H:i:s");
						$this->db->insert('cw_ntc_pickup_drop',$pickup_drop_information);
						$insert_id = $this->db->insert_id();
						$this->update_trip_map_info($insert_id,$ntc_load_id_pickup_drop);
						$trailer_assigned = $this->get_amsa_pickup_drop_info($ntc_load_id_pickup_drop,$load_customer_type);
						$trailer_assigned = $trailer_assigned['table_content'];
						echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully added",'trailer_assigned' => $trailer_assigned));
				}else
				if($process_info_pickup_drop === "UPDATE"){
						$pickup_drop_information['trans_updated_by'] = $this->session->userdata('logged_id');
						$pickup_drop_information['trans_updated_date'] = date("Y-m-d H:i:s");
						$this->db->where('prime_pickup_drop_id', $prime_pickup_drop_id);
						$this->db->update('cw_ntc_pickup_drop',$pickup_drop_information);
						$this->update_trip_map_info($prime_pickup_drop_id,$ntc_load_id_pickup_drop);
						$trailer_assigned = $this->get_amsa_pickup_drop_info($ntc_load_id_pickup_drop,$load_customer_type);
						$trailer_assigned = $trailer_assigned['table_content'];
						echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Information successfully updated",'trailer_assigned' => $trailer_assigned));
				}else
				if($process_info_pickup_drop === "EXIST"){
					echo json_encode(array('success' => false, 'message' => "Record already exist"));
				}else{
					echo json_encode(array('success' => false, 'message' => "Unable to process your request please contact admin"));
				}
		}else{
			echo json_encode(array('success' => false, 'message' => "Please complete the trip information"));
		}
	}
						/********** SAB START **********/
	//GET SAB PICKUP AND DROP INFORMATION
	public function get_pickup_drop_info($ntc_load_id){
		$this->db->select('km,arrival_time,mass,departure_time,dc_tat,eta_dc,prime_pickup_drop_id,trip_type,type_number,number,shipment_number,origin_tlb.depo_short_name as origin_short,origin_tlb.depo_name as origin_full,destination_tlb.depo_short_name as destination_short,destination_tlb.depo_name as destination_full,destination_landmark,origin_landmark');
		$this->db->from('ntc_load');
		$this->db->join('ntc_pickup_drop', 'ntc_pickup_drop.ntc_load_id_pickup_drop = ntc_load.prime_ntc_load_id','inner');
		$this->db->join('sab_depo_master as origin_tlb', 'origin_tlb.prime_sab_depo_master_id = ntc_pickup_drop.origin','inner');
		$this->db->join('sab_depo_master as destination_tlb', 'destination_tlb.prime_sab_depo_master_id = ntc_pickup_drop.destination','inner');
		$this->db->where('ntc_pickup_drop.ntc_load_id_pickup_drop',$ntc_load_id);
		
		$this->db->where('ntc_pickup_drop.trans_status',1);
		$pickup_drop = $this->db->get();
		$pickup_drop = $pickup_drop->result();
		foreach($pickup_drop as $pickup_drop_value){
			$trip_type = array(1 => 'One way',2 => 'Round Trip');
			$trip_type             = $trip_type[$pickup_drop_value->trip_type];
			$origin_short_name     = $pickup_drop_value->origin_short;
			$origin_full_name      = $pickup_drop_value->origin_full;
			$origin_landmark       = $pickup_drop_value->origin_landmark;
			$destination_landmark  = $pickup_drop_value->destination_landmark;
			$destination_short     = $pickup_drop_value->destination_short;
			$mass                  = $pickup_drop_value->mass;
			$destination_full      = $pickup_drop_value->destination_full;
			$type_number           = array(1 => 'NPF',2 => 'STO',3 => 'PLE',4 => 'Manual');
			$type_number           =  $type_number[$pickup_drop_value->type_number];
			$shipment_number       = $pickup_drop_value->shipment_number;
			$number                = $pickup_drop_value->number;
			$prime_pickup_drop_id = $pickup_drop_value->prime_pickup_drop_id;
			$km                    = $pickup_drop_value->km;
			$arrival_time          = $pickup_drop_value->arrival_time;
			$departure_time        = $pickup_drop_value->departure_time;
			$dc_tat                 = $pickup_drop_value->dc_tat;
			$eta_dc                = $pickup_drop_value->eta_dc;
			$edit_id               = "edit_pickup_"."$prime_pickup_drop_id";		
			$delete_id             = "delete_pickup_"."$prime_pickup_drop_id";
			
			$tr_line     .= "<tr>
							<td>$trip_type</td>
							<td>$origin_short_name.$origin_landmark</td>
							<td>$destination_short.$destination_landmark</td>
							<td>$type_number</td>
							<td>$number</td>
							<td>$shipment_number</td>
							<td>$km</td>
							<td>$mass</td>
							<td>$arrival_time</td>
							<td>$departure_time</td>
							<td>$dc_tat</td>
							<td>$eta_dc</td>
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='$edit_id' onclick=edit_pickup_record('$prime_pickup_drop_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Edit</button>
							</td>
							<td>
								<button type='button' class='btn btn-danger btn-xs btn_action' id='$delete_id' onclick=delete_pickup_record('$prime_pickup_drop_id')><i class='fa fa-trash fa-large' aria-hidden='true'></i> Delete</button>
							</td>
						</tr>";
		}
		$table_content = "<table class='table table-bordered' id='assign_trailer_list_table' style='background-color:#FFFFFF;'>
							<thead>
								<tr>
									<th>Trip Type</th>
									<th>Origin</th>
									<th>Destination</th>
									<th>Type Number</th>
									<th>Number</th>
									<th>Shipment Number</th>
									<th>Kilometer</th>
									<th>Mass</th>
									<th>Arrival Time</th>
									<th>Departure Time</th>
									<th>DC TAT</th>
									<th>ETA@DC</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
								$tr_line
							</tbody>
						</table>";
		return array('table_content' => $table_content);
	}
	// GET DELIVERY NOTE
	public function get_delivery_note_info($ntc_load_id){
		$this->db->select('del_shipment_no,del_note_internal,return_del_note,prime_pickup_drop_del_id');
		$this->db->from('cw_ntc_pickup_drop_delivery');
		$this->db->join('ntc_load','ntc_load.prime_ntc_load_id = cw_ntc_pickup_drop_delivery.ntc_load_id_pickup_drop','inner');
		$this->db->where('cw_ntc_pickup_drop_delivery.ntc_load_id_pickup_drop',$ntc_load_id);
		$this->db->where('cw_ntc_pickup_drop_delivery.trans_status',1);
		$delivery_rslt = $this->db->get();
		$delivery_rslt = $delivery_rslt->result();
		foreach($delivery_rslt as $delivery_note){
			$prime_pickup_drop_del_id     = $delivery_note->prime_pickup_drop_del_id;
			$del_shipment_no     = $delivery_note->del_shipment_no;
			$del_note_internal   = $delivery_note->del_note_internal;
			$return_del_note     = $delivery_note->return_del_note;
			$edit_id             = "edit_delivery_"."$prime_pickup_drop_del_id";		
			$delete_id           = "delete_delivery_"."$prime_pickup_drop_del_id";
			
			$tr_line     .= "<tr>
							<td>$del_shipment_no</td>
							<td>$del_note_internal</td>
							<td>$return_del_note</td>
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='$edit_id' onclick=edit_delivery_note_record('$prime_pickup_drop_del_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Edit</button>
							</td>
							<td>
								<button type='button' class='btn btn-danger btn-xs btn_action' id='$delete_id' onclick=delete_delivery_note_record('$prime_pickup_drop_del_id')><i class='fa fa-trash fa-large' aria-hidden='true'></i> Delete</button>
							</td>
						</tr>";
		}
		$table_content = "<table class='table table-bordered' id='assign_trailer_list_table' style='background-color:#FFFFFF;'>
							<thead>
								<tr>
									<th>Shipment No</th>
									<th>Delivery Note Internal</th>
									<th>Return Delivery Note</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
								$tr_line
							</tbody>
						</table>";
		return array('table_content' => $table_content);
	}
	// Edit Delivery Note
	public function edit_delivery_note_id(){
		$edit_delivery_note_id 	= (int)$this->input->post("edit_delivery_note_id");
		if($edit_delivery_note_id >0){			
			$this->db->select('prime_pickup_drop_del_id,ntc_load_id_pickup_drop,	del_shipment_no,del_note_internal,return_del_note,del_notes');
			$this->db->from('cw_ntc_pickup_drop_delivery');
			$this->db->where('prime_pickup_drop_del_id', $edit_delivery_note_id);
			$this->db->where('trans_status', 1);
			$edit_delivery_note_record    = $this->db->get()->row();
			echo json_encode(array('success' =>true,'edit_delivery_note_record'=>$edit_delivery_note_record));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Unable to process your request, Please refresh page and retry"));
		}
	}
	// DELETE DELIVERY NOTE
	public function delete_delivery_note_record(){
		$delete_id = $this->input->post('prime_pickup_drop_del_id');
		$this->db->select('*');
		$this->db->from('cw_ntc_pickup_drop_delivery');
		$this->db->where('prime_pickup_drop_del_id',$delete_id);
		$prime_ntc_load_id = $this->db->get();
		$prime_ntc_load_id = $prime_ntc_load_id->row();
		$prime_ntc_load_id = $prime_ntc_load_id->ntc_load_id_pickup_drop;
		$ntc_load_trailer = array(
					'trans_status'       =>0,
					'trans_deleted_by'   =>$this->session->userdata('logged_id'),
					'trans_deleted_date' =>  date("Y-m-d H:i:s"),
				);
		$this->db->where('prime_pickup_drop_del_id', $delete_id);
		if($this->db->update('cw_ntc_pickup_drop_delivery', $ntc_load_trailer)){
			$get_delivery_note_info = $this->get_delivery_note_info($prime_ntc_load_id);
			$get_delivery_note_info = $get_delivery_note_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "Deleted Successfully",'get_delivery_note_info' => $get_delivery_note_info));
		}else{
			echo json_encode(array('success' => false, 'message' => "Unable to process your request"));
		}
		
	}
	// SAVE DELIVERY NOTE
	public function pickup_drop_delivery_note(){
		$prime_pickup_drop_del_id 	= (int)$this->input->post("prime_pickup_drop_del_id");
		$ntc_load_id_pickup_drop 	= (int)$this->input->post("ntc_load_id_pickup_drop");
		$del_shipment_no 			= $this->input->post("del_shipment_no");
		$del_note_internal 			= $this->input->post("del_note_internal");
		$return_del_note 			= $this->input->post("return_del_note");
		$del_notes 					= $this->input->post("del_notes");
		$pickup_drop_del_information  = array(
			'ntc_load_id_pickup_drop' => $ntc_load_id_pickup_drop,
			'del_shipment_no' 		  => $del_shipment_no,
			'del_note_internal' 	  => $del_note_internal,
			'return_del_note' 		  => $return_del_note,
			'del_notes' 			  => $del_notes
		);
		if($prime_pickup_drop_del_id === 0){
			$pickup_drop_del_information['trans_created_by'] = $this->session->userdata('logged_id');
			$pickup_drop_del_information['trans_created_date'] = date("Y-m-d H:i:s");
			$this->db->insert('cw_ntc_pickup_drop_delivery',$pickup_drop_del_information);
			$insert_id = $this->db->insert_id();
			$delivery_note_info = $this->get_delivery_note_info($ntc_load_id_pickup_drop);
			$delivery_note_info = $delivery_note_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Delivery Information successfully added",'delivery_note_info' => $delivery_note_info));
		}else{
			$pickup_drop_del_information['trans_updated_by'] = $this->session->userdata('logged_id');
			$pickup_drop_del_information['trans_updated_date'] = date("Y-m-d H:i:s");
			$this->db->where('prime_pickup_drop_del_id', $prime_pickup_drop_del_id);
			$this->db->update('cw_ntc_pickup_drop_delivery',$pickup_drop_del_information);
			$delivery_note_info = $this->get_delivery_note_info($ntc_load_id_pickup_drop);
			$delivery_note_info = $delivery_note_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "pickup and Drop Delivery Note Information successfully updated",'delivery_note_info' => $delivery_note_info));
		}
	}
	//EDIT PICKUP AND DROP
	public function edit_pickup_record(){
		$edit_record_id = (int)$this->input->post('edit_record_id');
		if($edit_record_id >0){			
			$this->db->select('prime_pickup_drop_id,ntc_load_id_pickup_drop,trip_type,mass,origin,destination,type_number,km,arrival_time,departure_time,origin_landmark,destination_landmark,offload_departure_time,offload_arrival_time,dc_tat,eta_dc,number,shipment_number,sab_delivery_note,sab_return_note,sab_note');
			$this->db->from('cw_ntc_pickup_drop');
			$this->db->where('prime_pickup_drop_id', $edit_record_id);
			$this->db->where('trans_status', 1);
			$edit_pickup_record    = $this->db->get()->row();
			echo json_encode(array('success' =>true,'edit_pickup_record'=>$edit_pickup_record));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Unable to process your request, Please refresh page and retry"));
		}
	}	
	//DELETE PICKUP AND DROP
	public function delete_pickup_record(){
		$delete_id = $this->input->post('delete_pickup_id');
		$this->db->select('ntc_load_id_pickup_drop');
		$this->db->from('cw_ntc_pickup_drop');
		$this->db->where('prime_pickup_drop_id',$delete_id);
		$prime_ntc_load_id = $this->db->get();
		$prime_ntc_load_id = $prime_ntc_load_id->row();
		$prime_ntc_load_id = $prime_ntc_load_id->ntc_load_id_pickup_drop;
		$ntc_load_trailer = array(
					'trans_status'       =>0,
					'trans_deleted_by'   =>$this->session->userdata('logged_id'),
					'trans_deleted_date' =>  date("Y-m-d H:i:s"),
				);
		$this->db->where('prime_pickup_drop_id', $delete_id);
		if($this->db->update('cw_ntc_pickup_drop', $ntc_load_trailer)){
			$get_pickup_drop_info = $this->get_pickup_drop_info($prime_ntc_load_id);
			$get_pickup_drop_info = $get_pickup_drop_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "Deleted Successfully",'get_pickup_drop_info' => $get_pickup_drop_info));
		}else{
			echo json_encode(array('success' => false, 'message' => "Unable to process your request"));
		}
		
	}
				/********** SAB END **********/
				/********** ADHOC START **********/
	//GET ADHOC PICKUP AND DROP INFORMATION
	public function get_adhoc_pickup_drop_info($ntc_load_id){
		$this->db->select('origin,destination,destination_landmark,origin_landmark,trip_type,mass,loading_tat,offloading_tat,prime_pickup_drop_id,type_number,shipment_number,loading_kms,offloading_kms,number as adhoc_number');
		$this->db->from('ntc_load');
		$this->db->join('ntc_pickup_drop', 'ntc_pickup_drop.ntc_load_id_pickup_drop = ntc_load.prime_ntc_load_id','inner');		
		$this->db->where('ntc_pickup_drop.ntc_load_id_pickup_drop',$ntc_load_id);
		//$this->db->where('ntc_load.load_customer_type',$load_cust_type);
		$this->db->where('ntc_pickup_drop.trans_status',1);
		$pickup_drop = $this->db->get();
		$pickup_drop = $pickup_drop->result();
		foreach($pickup_drop as $pickup_drop_value){
			$trip_type = array(1 => 'One way',2 => 'Round Trip');
			$trip_type             = $trip_type[$pickup_drop_value->trip_type];
			$origin_short_name     = $pickup_drop_value->origin;
			$origin_landmark       = $pickup_drop_value->origin_landmark;
			$destination_landmark  = $pickup_drop_value->destination_landmark;
			$destination_short     = $pickup_drop_value->destination;
			$mass                  = $pickup_drop_value->mass;
			$type_number           = array(1 => 'NPF',2 => 'STO',3 => 'PLE',4 => 'Manual');
			$type_number           = $type_number[$pickup_drop_value->type_number];
			$adhoc_number          = $pickup_drop_value->adhoc_number;
			$shipment_number       = $pickup_drop_value->shipment_number;
			$prime_pickup_drop_id  = $pickup_drop_value->prime_pickup_drop_id;
			$loading_tat           = $pickup_drop_value->loading_tat;
			$offloading_tat        = $pickup_drop_value->offloading_tat;
			$loading_kms           = $pickup_drop_value->loading_kms;
			$offloading_kms        = $pickup_drop_value->offloading_kms;
			$edit_id               = "edit_adhoc_pickup_"."$prime_pickup_drop_id";		
			$delete_id             = "delete_adhoc_pickup_"."$prime_pickup_drop_id";
			
			$tr_line     .= "<tr>
							<td>$trip_type</td>
							<td>$origin_short_name</td>
							<td>$destination_short</td>
							<td>$type_number</td>
							<td>$adhoc_number</td>
							<td>$shipment_number</td>
							<td>$mass</td>
							<td>$loading_tat</td>
							<td>$offloading_tat</td>
							<td>$loading_kms</td>
							<td>$offloading_kms</td>
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='$edit_id' onclick=edit_adhoc_pickup_record('$prime_pickup_drop_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Edit</button>
							</td>
							<td>
								<button type='button' class='btn btn-danger btn-xs btn_action' id='$delete_id' onclick=delete_adhoc_pickup_record('$prime_pickup_drop_id')><i class='fa fa-trash fa-large' aria-hidden='true'></i> Delete</button>
							</td>
						</tr>";
		}
		$table_content = "<table class='table table-bordered' id='assign_trailer_list_table' style='background-color:#FFFFFF;'>
							<thead>
								<tr>
									<th>Trip Type</th>
									<th>Origin</th>
									<th>Destination</th>
									<th>Type Number</th>
									<th>Number</th>
									<th>Shipment Number</th>
									<th>Mass</th>
									<th>Loading TAT</th>
									<th>Offloading TAT</th>
									<th>Loading Kms</th>
									<th>Offloading Kms</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
								$tr_line
							</tbody>
						</table>";
		return array('table_content' => $table_content);
	}
		//EDIT ADHOC PICKUP AND DROP
	public function edit_adhoc_pickup_record(){
		$edit_record_id = (int)$this->input->post('edit_record_id');
		if($edit_record_id >0){			
			$this->db->select('prime_pickup_drop_id as prime_adhoc_pickup_drop_id,ntc_load_id_pickup_drop,trip_type,origin,destination,origin_landmark,destination_landmark,loading_tat,offloading_tat,mass as adhoc_mass,type_number as adhoc_type_number,number as adhoc_number,shipment_number as adhoc_shipment_number,loading_kms,offloading_kms,adhoc_delivery_note,adhoc_return_note,adhoc_note');
			$this->db->from('cw_ntc_pickup_drop');
			$this->db->where('prime_pickup_drop_id', $edit_record_id);
			$this->db->where('trans_status', 1);
			$edit_pickup_record    = $this->db->get()->row();
			echo json_encode(array('success' =>true,'edit_pickup_record'=>$edit_pickup_record));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Unable to process your request, Please refresh page and retry"));
		}
	}
	//DELETE ADHOC PICKUP AND DROP
	public function delete_adhoc_pickup_record(){
		$delete_id = $this->input->post('delete_pickup_id');
		$this->db->select('ntc_load_id_pickup_drop');
		$this->db->from('cw_ntc_pickup_drop');
		$this->db->where('prime_pickup_drop_id',$delete_id);
		$prime_ntc_load_id = $this->db->get();
		$prime_ntc_load_id = $prime_ntc_load_id->row();
		$prime_ntc_load_id = $prime_ntc_load_id->ntc_load_id_pickup_drop;
		$ntc_load_trailer = array(
					'trans_status'       =>0,
					'trans_deleted_by'   =>$this->session->userdata('logged_id'),
					'trans_deleted_date' =>  date("Y-m-d H:i:s"),
				);
		$this->db->where('prime_pickup_drop_id', $delete_id);
		if($this->db->update('cw_ntc_pickup_drop', $ntc_load_trailer)){
			$get_pickup_drop_info = $this->get_adhoc_pickup_drop_info($prime_ntc_load_id);
			$get_pickup_drop_info = $get_pickup_drop_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "Deleted Successfully",'get_pickup_drop_info' => $get_pickup_drop_info));
		}else{
			echo json_encode(array('success' => false, 'message' => "Unable to process your request"));
		}
		
	}
						/********** ADHOC END **********/
						/********** AMSA START **********/
	//GET AMSA PICKUP AND DROP INFORMATION
	public function get_amsa_pickup_drop_info($ntc_load_id){
		$this->db->select('destination,destination_landmark,trip_type,mass,loading_tat,prime_pickup_drop_id,dunnage_in,dunnage_out,dunnage_total,loading_kms,offloading_kms,amsa_shipment_no');		
		$this->db->from('ntc_load');
		$this->db->join('ntc_pickup_drop', 'ntc_pickup_drop.ntc_load_id_pickup_drop = ntc_load.prime_ntc_load_id','inner');		
		$this->db->where('ntc_pickup_drop.ntc_load_id_pickup_drop',$ntc_load_id);
		//$this->db->where('ntc_load.load_customer_type',$load_cust_type);
		$this->db->where('ntc_pickup_drop.trans_status',1);
		$pickup_drop = $this->db->get();
		$pickup_drop = $pickup_drop->result();
		foreach($pickup_drop as $pickup_drop_value){
			$trip_type = array(1 => 'One way',2 => 'Round Trip');
			$trip_type             = $trip_type[$pickup_drop_value->trip_type];
			$destination_landmark  = $pickup_drop_value->destination_landmark;
			$destination_short     = $pickup_drop_value->destination;
			$mass                  = $pickup_drop_value->mass;
			$dunnage_in            = $pickup_drop_value->dunnage_in;
			$dunnage_out           = $pickup_drop_value->dunnage_out;
			$dunnage_total         = $pickup_drop_value->dunnage_total;
			$prime_pickup_drop_id  = $pickup_drop_value->prime_pickup_drop_id;
			$loading_tat           = $pickup_drop_value->loading_tat;
			$loading_kms           = $pickup_drop_value->loading_kms;
			$offloading_kms        = $pickup_drop_value->offloading_kms;
			$amsa_shipment_no      = $pickup_drop_value->amsa_shipment_no;
			$edit_id               = "edit_amsa_pickup_"."$prime_pickup_drop_id";		
			$delete_id             = "delete_amsa_pickup_"."$prime_pickup_drop_id";
			
			$tr_line     .= "<tr>
							<td>$trip_type</td>
							<td>$destination_short</td>
							<td>$dunnage_in</td>
							<td>$dunnage_out</td>
							<td>$dunnage_total</td>
							<td>$mass</td>
							<td>$loading_tat</td>
							<td>$loading_kms</td>
							<td>$offloading_kms</td>
							<td>$amsa_shipment_no</td>
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='$edit_id' onclick=edit_amsa_pickup_record('$prime_pickup_drop_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Edit</button>
							</td>
							<td>
								<button type='button' class='btn btn-danger btn-xs btn_action' id='$delete_id' onclick=delete_amsa_pickup_record('$prime_pickup_drop_id')><i class='fa fa-trash fa-large' aria-hidden='true'></i> Delete</button>
							</td>
						</tr>";
		}
		$table_content = "<table class='table table-bordered' id='assign_trailer_list_table' style='background-color:#FFFFFF;'>
							<thead>
								<tr>
									<th>Trip Type</th>
									<th>Destination</th>
									<th>Dunnage In</th>
									<th>Dunnage Out</th>
									<th>Dunnage Total</th>
									<th>Mass</th>
									<th>Loading TAT</th>
									<th>Loading Kms</th>
									<th>Offloading Kms</th>
									<th>Shipment No</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
								$tr_line
							</tbody>
						</table>";
		return array('table_content' => $table_content);
	}
	//EDIT AMSA PICKUP AND DROP
	public function edit_amsa_pickup_record(){
		$edit_record_id = (int)$this->input->post('edit_record_id');
		if($edit_record_id >0){
			$this->db->select('prime_pickup_drop_id as prime_amsa_pickup_drop_id,ntc_load_id_pickup_drop,trip_type,destination,destination_landmark,loading_tat as amsa_loading_tat,dunnage_in,dunnage_out,dunnage_total,dunnage_cust,tarps,dispatched_from,dispatched_to,dispatched_time,exception,time_depart_nc,eta,time_depart_nc,trip_time,customer_eta,arrival_time_customer,nc_tat,return_trip_time,time_completed,customer_tat,depot_arrival,depart_from_depot,depot_arrival,depot_tat,loading_time as amsa_loading_time,delay,mass as amsa_mass,km_nc,loading_kms as amsa_loading_kms,offloading_kms as amsa_offloading_kms,amsa_shipment_no as amsa_shipment_no,amsa_delivery_note,amsa_return_note,amsa_note,depot_time_checkbox');
			$this->db->from('cw_ntc_pickup_drop');
			$this->db->where('prime_pickup_drop_id', $edit_record_id);
			$this->db->where('trans_status', 1);
			$edit_pickup_record    = $this->db->get()->row();
			echo json_encode(array('success' =>true,'edit_pickup_record'=>$edit_pickup_record));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Unable to process your request, Please refresh page and retry"));
		}
	}
	//DELETE AMSA PICKUP AND DROP
	public function delete_amsa_pickup_record(){
		$delete_id = $this->input->post('delete_pickup_id');
		$this->db->select('ntc_load_id_pickup_drop');
		$this->db->from('cw_ntc_pickup_drop');
		$this->db->where('prime_pickup_drop_id',$delete_id);
		$prime_ntc_load_id = $this->db->get();
		$prime_ntc_load_id = $prime_ntc_load_id->row();
		$prime_ntc_load_id = $prime_ntc_load_id->ntc_load_id_pickup_drop;
		$ntc_load_trailer = array(
					'trans_status'       =>0,
					'trans_deleted_by'   =>$this->session->userdata('logged_id'),
					'trans_deleted_date' =>  date("Y-m-d H:i:s"),
				);
		$this->db->where('prime_pickup_drop_id', $delete_id);
		if($this->db->update('cw_ntc_pickup_drop', $ntc_load_trailer)){
			$get_pickup_drop_info = $this->get_amsa_pickup_drop_info($prime_ntc_load_id);
			$get_pickup_drop_info = $get_pickup_drop_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "Deleted Successfully",'get_pickup_drop_info' => $get_pickup_drop_info));
		}else{
			echo json_encode(array('success' => false, 'message' => "Unable to process your request"));
		}
		
	}
	/********** AMSA END **********/
	/********** AFRISM START **********/
	//GET PICKUP AND DROP AFRISM INFORMATION
	public function get_pickup_drop_afrism_info($ntc_load_id){
		$this->db->select('prime_pickup_drop_id,ntc_load_id_pickup_drop,trip_type,origin,destination,loading_tat,offloading_tat,loading_kms,offloading_kms,cartage_zone,product,seq_no,time_in,time_out,gross,tare,net');
		$this->db->from('ntc_pickup_drop');
		$this->db->where('ntc_pickup_drop.ntc_load_id_pickup_drop',$ntc_load_id);
		$this->db->where('ntc_pickup_drop.trans_status',1);
		$pickup_drop_afrism = $this->db->get();
		$pickup_drop_afrism = $pickup_drop_afrism->result();
		foreach($pickup_drop_afrism as $pickup_drop_value){
			$trip_type             = array(1 => 'One way',2 => 'Round Trip');
			$trip_type             = $trip_type[$pickup_drop_value->trip_type];
			$origin                = $pickup_drop_value->origin;
			$destination           = $pickup_drop_value->destination;
			$loading_tat           = $pickup_drop_value->loading_tat;
			$offloading_tat        = $pickup_drop_value->offloading_tat;
			$loading_kms           = $pickup_drop_value->loading_kms;
			$offloading_kms        = $pickup_drop_value->offloading_kms;
			$cartage_zone          = $pickup_drop_value->cartage_zone;
			$product               = $pickup_drop_value->product;
			$seq_no                = $pickup_drop_value->seq_no;
			$time_in               = $pickup_drop_value->time_in;
			$time_out              = $pickup_drop_value->time_out;
			$gross                 = $pickup_drop_value->gross;
			$tare                  = $pickup_drop_value->tare;
			$net                   = $pickup_drop_value->net;
			$prime_pickup_drop_id  = $pickup_drop_value->prime_pickup_drop_id;
			$edit_id               = "edit_pickup_"."$prime_pickup_drop_id";		
			$delete_id             = "delete_pickup_"."$prime_pickup_drop_id";
			
			$tr_line     .= "<tr>
							<td>$trip_type</td>
							<td>$origin</td>
							<td>$destination</td>
							<td>$loading_tat</td>
							<td>$offloading_tat</td>							
							<td>$cartage_zone</td>
							<td>$product</td>
							<td>$seq_no</td>
							<td>$time_in</td>
							<td>$time_out</td>
							<td>$gross</td>
							<td>$tare</td>
							<td>$net</td>
							<td>$loading_kms</td>
							<td>$offloading_kms</td>
							
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='$edit_id' onclick=edit_pickup_afrism_record('$prime_pickup_drop_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Edit</button>
							</td>
							<td>
								<button type='button' class='btn btn-danger btn-xs btn_action' id='$delete_id' onclick=delete_pickup_afrism_record('$prime_pickup_drop_id')><i class='fa fa-trash fa-large' aria-hidden='true'></i> Delete</button>
							</td>
						</tr>";
		}
		$table_content = "<table class='table table-bordered' id='assign_trailer_list_table' style='background-color:#FFFFFF;'>
							<thead>
								<tr>
									<th>Trip Type</th>
									<th>Origin</th>
									<th>Destination</th>
									<th>Loading TAT</th>
									<th>Offloading TAT</th>
									<th>Cartage Zone</th>
									<th>Product</th>
									<th>Seq No</th>
									<th>Time In</th>
									<th>Time Out</th>
									<th>Gross(tonnes)</th>
									<th>Tare(tonnes)</th>
									<th>Net(tonnes)</th>
									<th>KMs at loading</th>
									<th>KMs at offloading</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
								$tr_line
							</tbody>
						</table>";
		return array('table_content' => $table_content);
	}
	
		//DELETE PICKUP AND AFRISM DROP
	public function delete_pickup_afrism_record(){
		$delete_id = $this->input->post('delete_pickup_id');
		$this->db->select('ntc_load_id_pickup_drop');
		$this->db->from('cw_ntc_pickup_drop');
		$this->db->where('prime_pickup_drop_id',$delete_id);
		$prime_ntc_load_id = $this->db->get();
		$prime_ntc_load_id = $prime_ntc_load_id->row();
		$prime_ntc_load_id = $prime_ntc_load_id->ntc_load_id_pickup_drop;
		$ntc_load_trailer = array(
					'trans_status'       =>0,
					'trans_deleted_by'   =>$this->session->userdata('logged_id'),
					'trans_deleted_date' =>  date("Y-m-d H:i:s"),
				);
		$this->db->where('prime_pickup_drop_id', $delete_id);
		if($this->db->update('cw_ntc_pickup_drop', $ntc_load_trailer)){
			$get_pickup_drop_afrism_info = $this->get_pickup_drop_afrism_info($prime_ntc_load_id);
			$get_pickup_drop_afrism_info = $get_pickup_drop_afrism_info['table_content'];
			echo json_encode(array('success' => TRUE, 'message' => "Deleted Successfully",'get_pickup_drop_afrism_info' => $get_pickup_drop_afrism_info));
		}else{
			echo json_encode(array('success' => false, 'message' => "Unable to process your request"));
		}		
	}
	
	//EDIT PICKUP AND DROP AFRISM
	public function edit_pickup_afrism_record(){
		$edit_record_id = (int)$this->input->post('edit_record_id');
		if($edit_record_id >0){			
			$this->db->select('prime_pickup_drop_id as prime_afrism_pickup_drop_id,ntc_load_id_pickup_drop,trip_type as trip_type_afrism ,origin_landmark as loading_add,destination as destination_add ,origin as loading_from,destination_landmark as offloading_add,loading_tat as loading_time,offloading_tat as offloading_time,loading_kms as km_loading,offloading_kms as km_offloading,cartage_zone,product,seq_no,time_in,time_out,gross,tare,net,afrisam_delivery_note,afrisam_return_note,afrisam_note');
			$this->db->from('cw_ntc_pickup_drop');
			$this->db->where('prime_pickup_drop_id', $edit_record_id);
			$this->db->where('trans_status', 1);
			$edit_pickup_afrism_record    = $this->db->get()->row();
			echo json_encode(array('success' =>true,'edit_pickup_afrism_record'=>$edit_pickup_afrism_record));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Unable to process your request, Please refresh page and retry"));
		}
	}
		/********** AFRISM END **********/
	
	//CALCULATING TAT TIME
	public function calculate_tat(){
		$arrival_time     = date('Y-m-d H:i:s',strtotime($this->input->post('arrival_time')));
		$departure_time   = date('Y-m-d H:i:s',strtotime($this->input->post('departure_time')));
		$arrival_time = new DateTime($arrival_time);
		$departure_time = new DateTime($departure_time);
		$interval = $arrival_time->diff($departure_time);
		$tat = $interval->format('%d days')." ".$interval->format('%h').":".$interval->format('%i');
		echo json_encode($tat);
	}
	
	//GET KM FROM SAB RATE MASTER
	public function sab_kilometer(){
		$origin      = (int)$this->input->post('origin');
		$destination = (int)$this->input->post('destination');
		$this->db->select('km');
		$this->db->from('cw_sab_rate_master');
		$this->db->where('destination',$destination);
		$this->db->where('origin',$origin);
		$this->db->where('month_and_year >=',date('m-Y'));
		$this->db->where('trans_status',1);
		$rslt_km  = $this->db->get();
		$rslt_num = $rslt_km->num_rows();
		if($rslt_num > 0){
			$rslt_km = $rslt_km->row();
			echo json_encode(array('success' =>true, 'message' =>$rslt_km->km));
		}else{
			echo json_encode(array('success' =>false, 'message' =>"Kilometer Not found Please Contact Admin"));
		}
	}
	//CHECK ALREADY EXIST HORSE  BETWEEN DATES
	public function check_exists_horse_trailer(){
		$from_date     = date('Y-m-d',strtotime($this->input->post('from_date')));
		$to_date       = date('Y-m-d',strtotime($this->input->post('to_date')));
		$horse         = (int)$this->input->post('horse');
		$trailer       = (int)$this->input->post('trailer_id');
		if($horse  > 0 && $trailer === 0){
			$this->db->select('from_date,to_date');
			$this->db->from('cw_ntc_load');
			$this->db->where('horse',$horse);
		}
		if($trailer > 0 && $horse > 0){
			$this->db->select('from_date,to_date');
			$this->db->from('cw_ntc_load');
			$this->db->join('cw_ntc_load_trailer', 'cw_ntc_load_trailer.ntc_load_id_trailer = ntc_load.prime_ntc_load_id','inner');
			$this->db->where('trailer_id',$trailer);
			$this->db->where('cw_ntc_load_trailer.trans_status',1);
		}
		$this->db->where('cw_ntc_load.trans_status',1);
		$rslt_horse   = $this->db->get()->row();
		 $start_date   = $rslt_horse->from_date;
		 $end_date     = $rslt_horse->to_date;
		if($start_date && $end_date){
			if($from_date >= $start_date && $from_date <= $end_date){
			echo json_encode(array('success' =>true, 'message' => 'Already assigned to other Customer'));
			}else{
			echo json_encode(array('success' =>false, 'message' => 'You can proceed!'));
			}
		}else
		echo json_encode(array('success' =>false, 'message' => 'You can proceed!'));
	}
	
	//Check Data is Exists for the Customer
	public function check_data_exist(){
		$prime_id           = (int)$this->input->post('prime_id');
		$load_customer_type = (int)$this->input->post('prime_customer_type');
		$this->db->from('ntc_load');
		$this->db->join('ntc_pickup_drop', 'cw_ntc_pickup_drop.ntc_load_id_pickup_drop = ntc_load.prime_ntc_load_id','inner');
		$this->db->where('ntc_load_id_pickup_drop', $prime_id);
		$this->db->where('load_customer_type', $load_customer_type);
		$this->db->where('ntc_pickup_drop.trans_status',1);
		echo (int)$this->db->get()->num_rows();
	}

	public function get_table(){
		$prime_id           = (int)$this->input->post('ntc_load_id_pickup_drop');
		$get_function       = $this->input->post('get_function');
		$table_info         = $this->$get_function($prime_id);
		$table_info         = $table_info['table_content'];
		echo json_encode(array('success' => TRUE,'message'=>$get_function,'table_info' => $table_info));
	}
	
	/*SVK EDIT START */
	public function update_trip_map_info($trip_id,$pickup_drop_id){
		//prime_trip_map_id  trip_id pickup_drop_id asset_id trip_start_date trip_end_date trans_created_date trans_updated_date
		//trip_id pickup_drop_id asset_id trip_start_date trip_end_date
		$this->db->select('cw_vehicle_master.prime_vehicle_master_id,cw_vehicle_master.register_no,cw_vehicle_master.asset_id');
		$this->db->from('cw_ntc_load');
		$this->db->join('cw_vehicle_master','cw_ntc_load.horse = cw_vehicle_master.prime_vehicle_master_id');
		$this->db->where('cw_ntc_load.prime_ntc_load_id', (int)$trip_id);
		$this->db->where('cw_vehicle_master.trans_status',1);
		$vehicle_info = $this->db->get()->row();
		$register_no  = $vehicle_info->register_no;
		$asset_id     = $vehicle_info->asset_id;
		$created_by  = date("Y-m-d H:i:s");
		$info_data = array(
					'trip_id'            =>  $trip_id,
					'pickup_drop_id'     =>  $pickup_drop_id,
					'asset_id'           =>  $asset_id,
					'vehicle_no'         =>  $register_no
				);
		if(!$this->check_trip_map_exists($trip_id)){
			$info_data['trans_created_by']   =  $this->session->userdata('logged_id');
			$info_data['trans_created_date'] =  $created_by;
			$this->db->insert('cw_trip_map', $info_data);
		}else{
			$info_data['trans_updated_by']   =  $this->session->userdata('logged_id');
			$info_data['trans_updated_date'] =  $created_by;
			$this->db->where('trip_id', $trip_id);
			$this->db->update('cw_trip_map', $info_data);
		}
	}

	public function check_trip_map_exists($trip_id){
		$this->db->from('cw_trip_map');
		$this->db->where('cw_trip_map.trip_id',(int)$trip_id);
		$this->db->where('cw_trip_map.trans_status',1);
		$count = (int)$this->db->get()->num_rows();
		if($count > 0){
			return true;
		}else{
			return false;
		}
	}
	/*SVK EDIT END */
	
}
?>