<?php
class Archanai_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->archanai = TBL_BAR;
        $this->archanai_item = TBL_BARI;
        $this->category = TBL_CATEGORY;
        $this->item = TBL_ITEM;
    }
    
    public function list_categories(){
        $this->db->select('id,category_name');
        $this->db->where('status',1);
        return $this->db->get($this->category)->result();
    }
	
	 public function get_data($start_date='',$end_date='',$type=''){
         $this->db->select('a.id, a.bar_rec_no, ai.bari_qty, ai.bari_price, ai.bari_sub_total, ai.bari_rec_no, cat.category_name as type_name, cat.id as service_id, item.name as item_name, a.gst, a.gst_value, item.id as item_id, cat.grouping, ai.is_category', FALSE);
        $this->db->join($this->archanai_item . ' as ai','a.id = ai.bar_id','left');
        $this->db->join($this->category . ' as cat','cat.id = ai.bari_cat_id','left');
        $this->db->join($this->item . ' as item','item.id = ai.bari_item_id','left');
        if(!empty($start_date)) {
            $this->db->where('a.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('a.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('a.created_on >=',date('Y-m-d 00:00:00'));
            $this->db->where('a.created_on <=',date('Y-m-d 23:59:59'));
        }
        $this->db->where('a.status',1);
		
		if(!empty($type)) {
            $this->db->where('ai.bari_cat_id',$type);
        }
				
        $this->db->order_by('type_name', 'ASC');
        return $this->db->get($this->archanai . ' as a')->result_array();
    }
    
}
?>