<?php
class Prasadam_sale_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->prasadam = TBL_BP;
        $this->prasadam_item = TBL_BPI;
        $this->star = TBL_STAR;
        $this->prasadam_list = TBL_PRASADAM;
    }
    
    public function get_data($start_date='',$end_date=''){
        $this->db->select('p.bp_fn_date, SUM(pi.bpi_qty) as qty, SUM(pi.bpi_sub_total) as total, pl.name as prasadam',FALSE);
        $this->db->join($this->prasadam . ' as p','p.id = pi.bp_id');
        $this->db->join($this->prasadam_list . ' as pl','pl.id = pi.prasadam_id');
        if(!empty($start_date) && !empty($end_date)) {
            $this->db->where('p.bp_fn_date >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('p.bp_fn_date <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('p.bp_fn_date >=',date('Y-m-d 00:00:00'));
            $this->db->where('p.bp_fn_date <=',date('Y-m-d 23:59:59'));
        }
        #$this->db->where('p.status',1);
        $this->db->where('pi.status',1);
        $this->db->group_by('pi.prasadam_id');
        return $this->db->get($this->prasadam_item . ' as pi')->result();
    }
}
?>