<?php
class Hall_booking_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->hall_booking = TBL_BH;
    }
    
    public function list_service_type(){
        $this->db->select('id,name as service_name');
        $this->db->where('menu_name',7);
        $this->db->where('status',1);
        return $this->db->get($this->services)->result();
    }
    
    public function get_data($start_date='',$end_date='',$type='',$date_type){
        $this->db->select('s.name as service_name, s.prefix, CASE hp.bh_period WHEN 1 THEN "Morning" ELSE "Evening" END as period_str, hp.*',FALSE);
        //$this->db->join($this->hall_booking . ' as h','h.self_id = hp.id','left');
        $this->db->join($this->services . ' as s','s.id = hp.service_id');
        if($date_type == 1) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('hp.bh_from_date >=',date('Y-m-d 00:00:00',strtotime($start_date)));
                $this->db->where('hp.bh_from_date <=',date('Y-m-d 23:59:59',strtotime($end_date)));
            } else {
                $this->db->where('hp.bh_from_date >=',date('Y-m-d 00:00:00'));
                $this->db->where('hp.bh_from_date <=',date('Y-m-d 23:59:59'));
            } 
        } elseif($date_type == 2) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('hp.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
                $this->db->where('hp.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
            } else {
                $this->db->where('hp.created_on >=',date('Y-m-d 00:00:00'));
                $this->db->where('hp.created_on <=',date('Y-m-d 23:59:59'));
            }
        }
        if(!empty($type)) {
            $this->db->where('hp.service_id',$type);
        }
        #$this->db->where('hp.status',1);
        //$this->db->group_by('h.self_id');
        return $this->db->get($this->hall_booking . ' as hp')->result();
    }
    
    public function get_part_pay_rec_no($id) {
        $this->db->select('*, GROUP_CONCAT(DISTINCT bh_rec_no SEPARATOR ",") as receipt_no',FALSE);
        $this->db->where('self_id',$id);
        return $this->db->get($this->hall_booking)->row();
    }
    
    
}
?>