<?php
class EditVehicle_model extends CI_Model {
	public function __construct(){
		$this->load->database();
	}
	function vehicleDetails($vehicleId){
		$query = $this->db->query("SELECT vehicleGroupId,makeId,modelId,vehicleName,plateNo,
										  istimaraNo,expiryDate,lastServiceDate,nextServiceDate,
										  serviceKmLast,serviceKmNext,description	 
								   FROM vehicle 
								   WHERE vehicleId='".$vehicleId."'
								   AND vehicleStatus='".AVAILABLE."'
								   AND status='".ACTIVE."'");
		return $query->result_array();
	}
	function resListVehicleGroupName(){
		$query = $this->db->query("SELECT vehicleGroupId,vehicleGroupName 
								   FROM vehicleGroup 
								   WHERE status='".ACTIVE."' ");
		return $query->result_array();
	}
	function resListMakeName(){
		$query = $this->db->query("SELECT makeId,makeName 
								   FROM make 
								   WHERE status='".ACTIVE."' ");
		return $query->result_array();
	}
    function resListModelByMakeId($makeId){
	   $query = $this->db->query("SELECT makeId,modelId,modelName 
								   FROM model 
								   WHERE makeId='".$makeId."'
								   AND status='".ACTIVE."' ");
		return $query->result_array();
   }
   function  isDuplicateButNotThis($columnName,$tableName,$whereColumnName1,$whereColumnName2,
	   									$columnValue1,$columnValue2){
       	$query = $this->db->query  ("SELECT ".$columnName."
                                     FROM   ".$tableName."
                                     WHERE  ".$whereColumnName1." = '".$columnValue1."' 
                                     AND    ".$whereColumnName2." != '".$columnValue2."'  ");
		if ($query->num_rows() > 0)
			{
				$dup= '1';
			}
		else
			$dup='0';
		return $dup;
   }
   function updateVehicleDetails($newVehicleGroup,$newMakeName,
				 			$newModelName,$newVehicleName,$newPlateNo,$newIstimaraNo,
				 			$newExpiryDate,
				 			$newLastServiceDate,$newNextServiceDate,$newServiceKmLast,$newServiceKmNext,$newDescription,$vehicleId){
		 $query = $this->db->query("UPDATE vehicle 
		 							SET vehicleGroupId='".$newVehicleGroup."',makeId='".$newMakeName."',
										modelId='".$newModelName."',vehicleName ='".$newVehicleName."',
										plateNo='".$newPlateNo."',
										istimaraNo='".$newIstimaraNo."',expiryDate='".$newExpiryDate."',
										lastServiceDate='".$newLastServiceDate."',
										nextServiceDate='".$newNextServiceDate."',
										serviceKmLast ='".$newServiceKmLast."',
										serviceKmNext ='".$newServiceKmNext."',
										description='".$newDescription."'
									WHERE vehicleId='".$vehicleId."'");
		return  $query;
  }
  function vehicleDetailsMake($vehicleId){
	    $query = $this->db->query("SELECT makeId
										  FROM vehicle where vehicleId='".$vehicleId."'
										  AND vehicleStatus='".AVAILABLE."'
										  AND status='".ACTIVE."' ");
		return $query;
  }
}