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

	class Mod_price extends CI_Model
	{
		var $table = "tblprice";
		function __construct()
		{
			parent::__construct();
		}	
		
		function getprice ()
		{
			$sql = "select a.*,(select tblroutes.routecode from tblroutes where a.RID = tblroutes.id) as routecode, (select b.typename from tblservices as b where a.service_id = b.id) as servicename,(select c.username from tbluser as c where a.createby = c.userid)as username,(select d.fullname from tblcar as d where a.car_id = d.id)as carname from tblprice as a order by a.id DESC";
			return $this->db->query($sql);	
		}
		
		 
		function countAll()
		{
			return $this->db->count_all_results('tblprice');
		}
		
			
		function add($data)
		{
			$this->db->insert($this->table,$data);	
		}


		function update($data,$id)
		{
			$this->db->where("id",$id);
			$this->db->update($this->table,$data);
		}
		

		function delete($id)
		{
			$this->db->where("id",$id);
			$this->db->delete($this->table);
		}
		
	
		function getById($id)
		{
			$this->db->where("id",$id);
			$q = $this->db->get($this->table);
			if($q->num_rows() > 0)
			{
				return $q->row();
			}
			return false;
		}
		
	   function showprice($ID)
	   {
		 	$this->db->SELECT("*");
			$this->db->from('tblroutes');
			$this->db->where("service_id",$ID);
			return $this->db->get();  
	   }	
		
	  function compprice($car_id,$service_id,$RID)
	  {
		  $this->db->select('*');
		  $this->db->where('RID', $RID);
          //$this->db->where('brand_id', $car_id);
		  $this->db->where('car_id', $car_id);
		  $this->db->where('service_id', $service_id);
          $this->db->from('tblprice');
          $data=$this->db->get();
          if($data->num_rows()>0)
		  {
             $userData=$data->row_array();
			 return FALSE;	
          }else{
			 return TRUE;
          }  
	  }
	
	  function editcompprice($id,$brand_id,$service_id,$RID)
	  {
		  $this->db->select('*');
		  $this->db->where('RID', $RID);
          //$this->db->where('brand_id', $brand_id);
		  $this->db->where('car_id', $brand_id);
		  $this->db->where('service_id', $service_id);
		  $this->db->where('id !=',$id);
          $this->db->from('tblprice');
          $data=$this->db->get();
          if($data->num_rows()>0)
		  {
             $userData = $data->row_array();
			 return FALSE;	
          }else{
			 return TRUE;
          }  
	  }

	
	}