<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class Mod_checkout extends CI_Model
	{
		var $table = "tblreservation";
		var $booking = "tblbooking";
		var $reservation = "tblroutes";
		function __construct()
		{
			parent::__construct();
		}	
			
		function add($data)
		{
			$this->db->insert($this->booking,$data);
			
		}
		
		function reserve($brand_id,$from_date,$from_time,$to_date,$to_time){
			$sql="SELECT * FROM (`tblreservation`) WHERE `brand_id` = '".$brand_id."' AND (`from_date` between '".$from_date."' and '".$from_date."') and (to_date between '".$to_date."' and '".$to_date."') AND ('".$from_time."' >= from_time and '".$from_time."' <=  to_time ) and ('".$to_time."' >= from_time and '".$to_time."' >=  to_time ) and `confirm` = 1";
			return $this->db->query($sql);
			//return $this->db->get();

		}
		
		function getcar($brand_id){
			$this->db->select('id');
			$this->db->from('tblcar');	
			$this->db->where('brandname',$brand_id);
			$this->db->where('status',1);
			$show = $this->db->get();
			$result = $show->result_array();
			if($show->num_rows() > 0)
			{
				return $result[0]['id'];
			}
			return false;
		}
		
		function showcar($brand_id,$cars){
			$car_id = array();
			foreach($cars as $v) {
		 		$car_id[] = $v['car_id'];
			}			
			
			//$car_id = array('2', '16');
			$this->db->select('*');
			$this->db->from('tblcar');	
			//$this->db->where_not_in('id',$car_id);
			$this->db->where_in('id',$car_id);
			$this->db->where('brandname',$brand_id);
			$this->db->where('status',1);
			return $this->db->get();
		}
		
		function tranfer($from,$to)
		{
			$this->db->select('*');
			$this->db->from('tblroutes');
        	$this->db->where('locationfrom', $from);
        	$this->db->where('locationto', $to);
			$this->db->or_where('locationto', $from);
			$this->db->where('locationfrom', $to);
        	$result = $this->db->get();
			if($result->num_rows() > 0)
			{				
				$result = $result->result_array();
				return $result[0]['id'];
			}
			return false;
					
		}
			
		function services($pickup_from,$service)
		{
			$this->db->select('*');
			$this->db->from('tblroutes');
			$this->db->where('service_id', $service);
        	$this->db->where('locationfrom', $pickup_from);
        	$result = $this->db->get();
			if($result->num_rows() > 0)
			{				
				
				$result = $result->result_array();
				return $result[0]['id'];
				
			}
			return false;
					
		}
		
		function getlocation($ID)
		{	
			$this->db->SELECT("*");
			$this->db->from('tbllocation');
			$this->db->where("id !=",$ID);
			return $this->db->get();
				
		}
		
		function free_time($from,$to)
		{
			$this->db->select('*');
			$this->db->from('tblroutes');
        	$this->db->where('locationfrom', $from);
        	$this->db->where('locationto', $to);
			$this->db->or_where('locationto', $from);
			$this->db->where('locationfrom', $to);
        	$result = $this->db->get();
			if($result->num_rows() > 0)
			{				
				$result = $result->result_array();
				return $result[0]['time'];
			}
			return false;	
		}
		
		function pickup_hotel($pickup_hotel)
		{
			$this->db->select('*');
			$this->db->from('tbllocation');
			$this->db->like('locationname',$pickup_hotel);
			$this->db->where('type',2);
			$result = $this->db->get();
			if($result->num_rows() > 0)
			{				
				$result = $result->result_array();
				return $result[0]['id'];
			}
			return false;	
		}
		
		function dropoff_hotel($dropoff_hotel)
		{
			$this->db->select('*');
			$this->db->from('tbllocation');
			$this->db->like('locationname',$dropoff_hotel);
			$this->db->where('type',2);
			$result = $this->db->get();
			if($result->num_rows() > 0)
			{				
				$result = $result->result_array();
				return $result[0]['id'];
			}
			return false;	
		}
		
						
}