<?php 
class Vehicle_model extends CI_Model {
	public function _consruct(){
		parent::_construct();
 	}

 	public function getvehicleData($vehicle_id='',$view=''){

 		$cond  = (!empty($view))?" USR.user_type IN ($view) ":" USR.status != '2' ";
 		$cond .= (!empty($vehicle_id))?" AND VM.cust_id='$vehicle_id'":"";

 		$sql = "SELECT VM.*,USR.status,CTR.name AS customer_name
			    FROM vehicle_model AS VM
			    INNER JOIN users AS USR ON (USR.id=VM.cust_id)
			    INNER JOIN customer AS CTR ON (CTR.cust_id=VM.cust_id)
			    WHERE $cond AND USR.user_type='1' Order by id DESC";

	    $vehicleData = $this->db->query($sql);
//echo $this->db->last_query();exit;
	    if(isset($vehicleData)){

	    	return (empty($vehicle_id))?$vehicleData->result():$vehicleData->row();
	    }
	    return 0;
 	}

 	public function add_vehicle($vehicle_data = array()){

	if(empty($vehicle_data))
 			return 0;


    $status = $this->db->insert('vehicle_model',$vehicle_data );
		                     
 		return $status;
 	}




 	function update_Vehicle($vehicle_id = '', $vehicle_data = array()){

 		
 		                
 		$status = $this->db->update('vehicle_model',$vehicle_data,array('cust_id'=>$vehicle_id));
 		
 		if($status) {
          return $status;  
        }

	
 		
 	}

 

 	function get_all_vehicle($filter=null) {
    	if($filter){
    		$this->db->order_by($filter['order_by'], $filter['order_type']);
    		if(!empty($filter['where'])){
    			$this->db->where($filter['where']);
    		}
    		if($filter['length']!=-1)
    			$this->db->limit($filter['length'],$filter['start']);
    	}
    	$this->db->where('users.user_type', 1);
    	$this->db->where('users.status!=','2');
    	$this->db->order_by('customer.id','desc');
    	$this->db->select('customer.*,users.status');
    	$this->db->from('customer');
    	$this->db->join('users', 'users.user_id = customer.id');
        
    	$res = $this->db->get();
    	
    	return $res->result();
    }


}
?>