<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
	class Mod_report extends CI_Model
	{
		private $table = "tblcarservices";
		function __construct()
		{
			parent::__construct();
		}	
		
		function getReport()
		{
			$condition = 'Month(CreatedDate) = '.date('m').' AND Year(CreatedDate) = '.date('Y').'';
			$this->db->SELECT("*");
			$this->db->from($this->table);
			$this->db->join("tbluser","tbluser.userid = tblcarservices.CreatedBy","left");	
			$this->db->where($condition);
			$this->db->where('tblcarservices.Status',1);
			$this->db->order_by('tblcarservices.Date','DESC');	
			return $this->db->get();
		}
		
		
		function add($data)
		{
			$this->db->insert($this->table,$data);
		}
		
		function update_ref_id($id)
		{
			$this->db->set("ref_id",$id);
			$this->db->where("id",$id);
			$this->db->update($this->table);
		}

		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->set('Status', 0);
			$this->db->update($this->table);
		}
		
		function getById($id)
		{
			$this->db->where("id",$id);
			$this->db->from($this->table);
			$q = $this->db->get();
			if($q->num_rows() > 0)
			{
				return $q->row();
			}
			return false;
		}
		
		function get_report_ById($id)
		{
			$this->db->where("ref_id",$id);
			$this->db->from($this->table);
			return $q = $this->db->get();
			/*if($q->num_rows() > 0)
			{
				return $q->row();
			}
			return false;*/
		}
		
		function report_countAll($from,$to,$name=null)
		{
			$condition = 'Date BETWEEN "'.$from.'" AND "'.$to.'"';
			$this->db->where($condition);
			$this->db->where('tblcarservices.Status',1);
			if($name !=null){
				$this->db->like('Company',$name);
			}
			return $this->db->count_all_results($this->table);
		}
		
		
		function getSort($from,$to,$name=null)
		{
			$condition = 'Date BETWEEN "'.$from.'" AND "'.$to.'"';
			$this->db->SELECT("*");
			$this->db->from($this->table);
			$this->db->where('tblcarservices.Status',1);
			$this->db->where($condition);
			if($name!=null){
				$this->db->like('Company',$name);
			}
			//$this->db->join("tblseller","tblseller.SellerID = tblcarservices.CreatedBy","left");
			$this->db->join("tbluser","tbluser.userid = tblcarservices.CreatedBy","left");		
			$this->db->order_by('id','DESC');
			return $this->db->get();	
		}


	}