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/allyindian_com/backend/application/models/Package_ticket_model.php
<?php
class Package_ticket_model extends CI_Model{	
	public function GetInfo($package_id){
		$this->db->from('package');
		$this->db->where('package_id',$package_id);
		$a=$this->db->get();
		if($a->num_rows() === 1){
			return $a->row();
		
		}else{
			foreach ($this->db->list_fields('package') as $field){
				$PersonObj->field= '';
			}
			return $PersonObj;
		}
	}
	public function get_found_rows($search){
		$this->db->select('*');
		$this->db->from('package');
		return $this->db->get()->num_rows();
	}	
	public function get_packages(){
		$this->db->from('package');
		$this->db->where('status',1);
		return $this->db->get()->result_array();
	}	
	public function get_banks(){
		$this->db->from('banks');
		$this->db->where('status',1);
		return $this->db->get()->result_array();
	}
	public function get_package_data($id){
		$this->db->from('vehicletrips');
		$this->db->join('package', 'package.package_id = vehicletrips.trippackid');
		$this->db->join('vehicle', 'vehicle.vehicle_id = vehicletrips.vehicleid');
		$this->db->where('package.package_id', $id);
		$this->db->where('package.status', 1);	
		$this->db->where('vehicletrips.status', 1);	
		$result = $this->db->get()->result_array();

		$package     = array();
		$trip_dates  = $this->get_package_trip_dates($id);
		$dep_date    = explode(",",$trip_dates->dep_date);
		$dep_count   = count($dep_date);

	    function date_sort($a, $b){
    		return strtotime($a) - strtotime($b);
		}
		usort($dep_date, "date_sort");	
		for($i=0;$i<$dep_count;$i++){
			$date = $dep_date[$i];
			
			$pack_line = array();
			$pack_line['date_info'] = $date;
			$pack_line['pack_info'] = $result;
			$package[] =$pack_line;
		}	
		return $package;
	}
	public function get_booked_count($package_id,$date,$tripid){
		$date = date("Y-m-d",strtotime($date));
		$this->db->from('ticketorder');
		$this->db->join('passlist', 'passlist.ticketorderid = ticketorder.orderid');
		$this->db->where('ticketorder.packid', $package_id);
		$this->db->where('ticketorder.doj', $date);
		$this->db->where('ticketorder.otripid', $tripid);
		$this->db->group_start();
		$this->db->where('passlist.passstatus', 0)->or_where('passlist.passstatus', 2);				
		$this->db->group_end();
		$this->db->where_in('ticketorder.orderstat', array('1','2','4'));
		$this->db->where('passlist.pnrno >', 0);		
		return $this->db->get()->num_rows();
	}
	public function get_cancelled_count($package_id,$date,$tripid){
		$date = date("Y-m-d",strtotime($date));
		$this->db->from('ticketorder');
		$this->db->join('passlist', 'passlist.ticketorderid = ticketorder.orderid');
		$this->db->where('ticketorder.packid', $package_id);
		$this->db->where('ticketorder.doj', $date);
		$this->db->where('ticketorder.otripid', $tripid);
		$this->db->where('passlist.passstatus', 1);		
		$this->db->where('passlist.pnrno >', 0);	
		$this->db->where_in('ticketorder.orderstat', array('1','2','4'));	
		return $this->db->get()->num_rows();
	}
	
	public function get_blocked_count($package_id,$date,$tripid){
		$date = date("Y-m-d",strtotime($date));
		$this->db->from('seatquotanew');
		$this->db->where('qupackid', $package_id);
		$this->db->where('qupackdate', $date);
		$this->db->where('qutripid', $tripid);
		$this->db->group_start();
		$this->db->where('quseatstat', 2);
		$this->db->group_end();
		return $this->db->get()->num_rows();
	}
	public function get_package_trip_dates($id){
		$this->db->select('dep_date');
		$this->db->from('package');
		$this->db->where('package_id',$id);
		$this->db->where('status',1);
		return $this->db->get()->row();
	}
	public function get_boarding($package_id){
		$this->db->from('boarding');
		$this->db->join('boarding_point', 'boarding_point.board_point_id = boarding.board_point_id');		
		$this->db->where('boarding.package_id',$package_id);
		$this->db->where('boarding.status',1);
		$this->db->order_by('boarding_name', 'asc');
		return $this->db->get()->result_array();
	}
	
	public function get_tariff($package_id,$tripid){
		$this->db->from('packcost');
		$this->db->join('package_type', 'package_type.package_type_id = packcost.packtypeid');		
		$this->db->where('packcost.packid',$package_id);
		$this->db->where('pcoststatus',1);
		$this->db->order_by('package_type', 'asc');
		return $this->db->get()->result_array();
	}
	public function get_vehicle_data($package_id,$tripid){
		$this->db->from('vehicletrips');
		$this->db->join('package', 'package.package_id = vehicletrips.trippackid');
		$this->db->join('vehicle', 'vehicle.vehicle_id = vehicletrips.vehicleid');
		$this->db->join('veh_type', 'veh_type.veh_type_id = vehicle.vehicle_type');
		$this->db->where('trippackid', $package_id);
		$this->db->where('tripid', $tripid);		
		return $this->db->get()->result_array();
	}
	public function get_vehicle_seat_data($vehicle_id,$package_date,$package_id,$trip_id){
		$emp_id       = $this->session->userdata('emp_id');
		$package_date = date("Y-m-d",strtotime($package_date));
		$qry = $this->db->query("SELECT *,(SELECT GROUP_CONCAT(quseat SEPARATOR ',') from sblttweb_seatquotanew where qupackid ='$package_id' and qupackdate = '$package_date' and quseatstat = '2' and qutripid = '$trip_id') as blocked,(SELECT GROUP_CONCAT(quseat SEPARATOR ',') from sblttweb_seatquotanew where qupackid ='$package_id' and qupackdate = '$package_date' and (quseatstat = '1' or quseatstat = '0') and qutripid = '$trip_id') as active,(SELECT GROUP_CONCAT(quseat SEPARATOR ',') from sblttweb_seatquotanew where qupackid ='$package_id' and qupackdate = '$package_date' and quseatstat = '2' and qutripid = '$trip_id' and qublockuserid = '$emp_id') as b_by_u,(SELECT GROUP_CONCAT(seatno SEPARATOR ',') from sblttweb_passlist inner join sblttweb_ticketorder on sblttweb_ticketorder.orderid = sblttweb_passlist.ticketorderid inner join sblttweb_package on sblttweb_package.package_id = sblttweb_ticketorder.packid where doj = '$package_date' and (passstatus = '0' or passstatus = '2') and orderstat IN (1,2,4) and sblttweb_passlist.pnrno > 0 and otripid = '$trip_id') as booked from sblttweb_vehicletrips where tripid = '$trip_id' and status = '1'");	
		return $qry->result_array();
	}
	public function save_blocked_seat($package_id,$seat_no,$status,$package_date,$seat_data,$trip_id){
		$package_date = date("Y-m-d",strtotime($package_date));
		$blocked_data = array(
			'qupackid'        => $package_id,
			'qupackdate'      => $package_date,
			'quseat'          => $seat_no,
			'quseatstat'      => $status,
			'qtimed'          => date('Y-m-d h:i:s'),
			'qutripid'        => $trip_id,			
			'qublockuserid'   => $this->session->userdata('emp_id'));
	if($status === "2"){
		if($this->is_exist_temp($package_id,$seat_no,$trip_id,$package_date) === 0){
			if($this->is_exist($package_id,$seat_no,$trip_id,$package_date) === 0){
				$this->db->insert('seatquotanew',$blocked_data);
	            return $this->get_block_seatdata($package_id,$package_date,$trip_id);
			}else{ 
			$this->db->where('qupackid',$package_id);
			$this->db->where('qupackdate',$package_date);
			$this->db->where('qutripid',$trip_id);
			$this->db->where('quseat',$seat_no);
		    $this->db->update('seatquotanew',$blocked_data);
		    return $this->get_block_seatdata($package_id,$package_date,$trip_id);
			}
		}else{
			return false;
		}
	}else{ 
		$this->db->where('qupackid',$package_id);
		$this->db->where('qupackdate',$package_date);
		$this->db->where('qutripid',$trip_id);
		$this->db->where('quseat',$seat_no);
	    $upd = $this->db->update('seatquotanew',$blocked_data);
		    if($upd){
		    	return $this->get_block_seatdata($package_id,$package_date,$trip_id);
		    }
		}		
	}
	public function is_exist_temp($package_id,$seat_no,$trip_id,$package_date){
		$this->db->from('seattemp');		
		$this->db->where('packid', $package_id);
		$this->db->where('packdate', $package_date);
		$this->db->where('ttripid', $trip_id);		
		$this->db->where('tseatno', $seat_no);
		return $this->db->get()->num_rows();
	}	
	public function is_exist($package_id,$seat_no,$trip_id,$package_date){
		$this->db->from('seatquotanew');		
		$this->db->where('qupackid', $package_id);
		$this->db->where('qupackdate', $package_date);
		$this->db->where('qutripid', $trip_id);		
		$this->db->where('quseat', $seat_no);
		return $this->db->get()->num_rows();
	}
	public function is_exist_seatquota($package_id,$seat_no,$trip_id,$package_date){
		$this->db->from('seatquotanew');		
		$this->db->where('qupackid', $package_id);
		$this->db->where('qupackdate', $package_date);
		$this->db->where('qutripid', $trip_id);		
		$this->db->where('quseat', $seat_no);
		$this->db->where('quseatstat', 2);
		return $this->db->get()->num_rows();
		//echo $this->db->last_query();
	}
	public function get_block_seatdata($package_id,$package_date,$tripid){
		$package_date = date("Y-m-d",strtotime($package_date));
		$this->db->from('seatquotanew');
		$this->db->join('people', 'people.person_id = seatquotanew.qublockuserid');
		$this->db->where('qupackid', $package_id);
		$this->db->where('qutripid', $tripid);
		$this->db->where('qupackdate', $package_date);		
		$this->db->where('quseatstat', 2);
		$this->db->order_by('quseat', 'ASC');
		return $this->db->get()->result_array();
	}
	public function update_blocked_seat($id,$blocked_remarks,$status,$package_id,$package_date,$trip_id){
		 $this->db->where('quid', $id);
		 $this->db->update('seatquotanew',array('quremarks'=>$blocked_remarks,'quseatstat'=>$status,'qublockuserid'=>$this->session->userdata('emp_id')));
		 return $this->get_block_seatdata($package_id,$package_date,$trip_id);
	}
	public function get_customer_data($search_by,$search_text){
		if($search_by === "1"){
			$search_by = "custid";
		}else
		if($search_by === "2"){
			$search_by = "custfname";
		}else
		if($search_by === "3"){
			$search_by = "custmobile";
		}else
		if($search_by === "4"){
			$search_by = "custemail";
		}else
		if($search_by === "5"){
			$search_by = "custphone";
		}else
		if($search_by === "6"){
			$search_by = "custloginid";
		}

		$this->db->from('customers');
		$this->db->like($search_by, $search_text);	
		return $this->db->get()->result_array();
	}
	public function save_booked_seat_temp($cust_id,$package_id,$seat_no,$status,$package_date,$seat_data,$trip_id){
		$package_date = date("Y-m-d",strtotime($package_date));
		$booked_data = array(
			'packid'        => $package_id,
			'packdate'      => $package_date,
			'tseatno'       => $seat_no,
			'custid'        => $status,
			'ttim'          => date('Y-m-d h:i:s'),
			'ttripid'       => $trip_id,
			'custid'        => $cust_id,			
			'adminid'       => $this->session->userdata('emp_id'));				
	if($status === "1"){
		if($this->is_exist_temp($package_id,$seat_no,$trip_id,$package_date) === 0){
			if($this->is_exist_seatquota($package_id,$seat_no,$trip_id,$package_date) === 0){
				$this->db->insert('seattemp',$booked_data);
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}	
	}else{
		$this->db->where('packid', $package_id);
		$this->db->where('packdate', $package_date);
		$this->db->where_in('tseatno', $seat_no);
		$this->db->delete('seattemp');
		return true;
	}		
}
	public function save_order($order_data,$seat_nos,$pass_data,$pack_disc,$admin_disc,$admin_discount){
		$packid = $order_data['packid'];
		$custid = $order_data['custid'];
		$this->db->insert('ticketorder',$order_data);
			
		$order_id = $this->db->insert_id();
		$this->db->insert('pnrnogen',array('pnrdate'=>date('Y-m-d h:i:s'),'custid'=>$custid,'packid'=>$packid,'orderid' => $order_id));		
		$pnr = $this->db->insert_id();
		if($pnr){
			$this->db->where('orderid', $order_id);
			$this->db->update('ticketorder',array('pnrno' => $pnr));
		}		
		$seat_no      = count($seat_nos);
		if($order_id){			
			for($i=0; $i<$seat_no; $i++){
			$package_id   = $order_data['packid'];								
			$package_date = $order_data['doj'];	
			$trip_id      = $order_data['otripid'];
			$balance      = $order_data['balamt'];
			$cust_id      = $order_data['custid'];
			$seat_no      = $seat_nos[$i];
			if($balance === 0){
				$paystatus       = 1;
			}else{
				$paystatus       = 0;
			}			
			$this->db->where('qupackid',$package_id);
			$this->db->where('qupackdate',$package_date);
			$this->db->where('qutripid',$trip_id);
			$this->db->where('quseat',$seat_no);
		   	$res = $this->db->update('seatquotanew',array('orderid'=>$order_id,'paystatus'=>$paystatus,'quseatstat'=>'4'));		
			}
			$pass_insert = $this->save_passenger($order_data,$seat_nos,$pass_data,$order_id,$pack_disc,$admin_disc,$admin_discount);
			if($pass_insert){
				return $order_id;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	public function save_passenger($order_data,$seat_nos,$pass_data,$order_id,$pack_disc,$admin_disc,$admin_discount){
		$pnr    = $this->get_pnr($order_id); 
		$pnr_no = $pnr->pnrno;	
		$seat_no      = count($seat_nos);
		//Check Amount Division
		$tariffamt  = $order_data['tariffamt'];
		$check_tot  = $order_data['ticketamt'];
		$check_paid = $order_data['paidamt']; 
		$admin_disc_amt = 0;
		$disc_amt       = 0;
		//$tot_disc   = $pack_disc + $admin_disc;
		if($pack_disc !== "0"){
			$disc_amt = ($tariffamt * ($pack_disc / 100));
			$final_tariff = $tariffamt - $disc_amt;
		}else{
			$final_tariff = $tariffamt;
		}
		// if($admin_disc !== "0"){
		// 	$admin_disc_amt = ($tariffamt * ($admin_disc / 100));
		// 	$tariffamt      = $tariffamt - $admin_disc_amt;
		// }
		//$final_discount_amt = $disc_amt + $admin_disc_amt;
		//$final_tariff = $tariffamt;
		$paidamt      = 0;
		$pss_discount = 0;
		$due = $check_tot - $check_paid;		
		for($i=0,$j=1; $i<$seat_no; $i++,$j++){
	   		$name    = $pass_data['pass_name'][$i];
	   		$gender  = $pass_data['pass_gender'][$i];
	   		$age     = $pass_data['pass_age'][$i];
	   		$mobile  = $pass_data['pass_mobile'][$i];
	   		$admin_passdiscount=$admin_discount[$i];
			$pss_discount  = ($tariffamt * ($admin_discount[$i]/100));
			$ticketamt     = $final_tariff - $pss_discount;
			
	   		if($check_paid >= $final_tariff){
	   			$paidamt = $final_tariff - $pss_discount;
	   			$due_amt = 0;
	   			$pay_status = 1;
	   		}else
	   		if(($check_paid < $final_tariff) && ($check_paid > 0)){
	   			$paidamt = $check_paid;
	   			$due_amt = ($final_tariff - $pss_discount) - $check_paid;
	   			$pay_status = 0;
	   			$check_paid = $check_paid - ($due - $pss_discount);
	   		}else
	   		if($check_paid <= 0){
	   			$paidamt = 0;
	   			$pay_status = 0;
	   			if($due >= $final_tariff){
	   				$due_amt = $final_tariff- $pss_discount;
	   			}else
		   		if($due < $final_tariff){
		   			$due_amt = ($final_tariff - $pss_discount) - $due;
		   		}else{
		   			$due_amt = 0;
		   		}
	   		}

	   		if($due_amt === 0){
	   			$passstatus = 2;
	   		}else{
	   			$passstatus = 0;
	   		}	 
	   	$passenger_data = array(
	   		'passdate'            => date('Y-m-d h:i:s'),
	   		'ticketorderid'       => $order_id,
	   		'pnrno'               => $pnr_no,
	   		'pslno'               => $j,
	   		'passname'            => $name,
	   		'passgender'          => $gender,
	   		'passage'             => $age,
	   		'tariffamt'           => $order_data['tariffamt'],
	   		'discount'            => $pack_disc,
	   		'discountamt'         => $disc_amt,
	   		'admin_discount'      => $admin_passdiscount,
	   		'admin_discountamt'   => $pss_discount,
	   		'ticketamt'           => $ticketamt,
	   		'cashpaid'            => $paidamt,
	   		'cashdue'             => $due_amt,
	   		'passstatus'          => $passstatus,
	   		'pay_status'          => $pay_status,
	   		'seatno'              => $seat_nos[$i],
	   		'passmobile'          => $mobile,
	   		'passtripid'          => $order_data['otripid'] 
	   	);	
	   	
	   	$pass_insert = $this->db->insert('passlist',$passenger_data);
	   	$check_paid = $check_paid - ($final_tariff - $pss_discount);
	   	//echo "paidamt : $paidamt :: due_amt : $due_amt :: admin_discountamt : $pss_discount :: check_paid : $check_paid :: final_tariff : $final_tariff<br/>";
	   }
	   if($pass_insert){
	   		return true;
	   }else{
	   		return false;
	   }
	}
	public function get_pnr($order_id){
		$this->db->select('pnrno');
		$this->db->from('pnrnogen');
		$this->db->where('orderid',$order_id);		
		return $this->db->get()->row();
	}
	public function clear_temp_data($cust_id){
		$admin = $this->session->userdata('emp_id');
		$this->db->where('custid', $cust_id);
		$this->db->where('adminid', $admin);
		$result = $this->db->delete('seattemp');
		if($result){
			return true;
		}
	}
	public function get_numbers($package_id,$package_date,$trip_id){
		$this->db->select('GROUP_CONCAT(DISTINCT custmobile SEPARATOR ",") as numbers');		
		$this->db->from('customers');
		$this->db->join('ticketorder', 'ticketorder.custid = customers.custid');
		$this->db->join('passlist', 'passlist.ticketorderid = ticketorder.orderid');
		$this->db->where('ticketorder.packid', $package_id);
		$this->db->where('ticketorder.doj', $package_date);
		$this->db->where('ticketorder.otripid', $trip_id);
		$this->db->group_start();
		$this->db->where('passlist.passstatus', 0)->or_where('passlist.passstatus', 2);
		$this->db->group_end();
		$this->db->where_in('ticketorder.orderstat', array('1','2','4'));
		return $this->db->get()->result_array();
	} 
	public function get_custmobile($custid){
		$this->db->select('custmobile');	
		$this->db->from('customers');
		$this->db->where('custid', $custid);
		return $this->db->get()->row();
	}
	public function view_passengers_data($search_by,$search_text){		
		$this->db->from('passlist');
		$this->db->join('ticketorder', 'ticketorder.orderid = passlist.ticketorderid');
		if($search_by === "1"){
			$this->db->where('passlist.pnrno', $search_text);
		}else
		if($search_by === "2"){
			$this->db->where('ticketorder.orderid', $search_text);
		}	
		$this->db->group_start();
		$this->db->where('passstatus', 0)->or_where('passstatus', 2);	
		$this->db->group_end();	
		$this->db->where_in('ticketorder.orderstat', array('1','2','4'));
		return $this->db->get()->result_array();
	}
	public function update_passenger($passid,$pass_data,$boarding,$orderid){
		$this->db->where('orderid',$orderid);
		$result = $this->db->update('ticketorder',array('boarding'=>$boarding));
		if($result){
			$this->db->where('passid',$passid);
		return $this->db->update('passlist',$pass_data);
		}else{
			return false;
		}
				
	}
	public function save_irumudi($pass_data,$packid,$custid,$passtripid,$orderid){	
		$rows = $this->is_exist_irumudi($packid,$custid,$passtripid,$orderid);
		$pass_data['irumudi_no'] = $rows + 1;
		$result = $this->db->insert('irumudi',$pass_data);
		if($result){
			return $this->get_irumudi_data($packid,$custid,$passtripid,$orderid);
		}else{
			return false;
		}
	}
	public function is_exist_irumudi($packid,$custid,$passtripid,$orderid){
		$this->db->from('irumudi');		
		$this->db->where('package_id', $packid);
		$this->db->where('trip_id', $passtripid);		
		$this->db->where('order_id', $orderid);
		return $this->db->get()->num_rows();
	}
	public function get_irumudi_data($packid,$custid,$passtripid,$orderid){
		$this->db->from('irumudi');		
		$this->db->where('package_id', $packid);
		$this->db->where('trip_id', $passtripid);		
		$this->db->where('order_id', $orderid);
		return $this->db->get()->result_array();
	}
}
?>