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