<?php
class Ubayam_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->ubayam = TBL_BILL_UBAYAM;
        $this->star = TBL_STAR;
        $this->deity = TBL_GOD_NAME;
    }
    
    public function list_service_type(){
        $this->db->select('id,name as service_name');
        $this->db->where('menu_name',17);
        $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, star.name as star, star2.name as star2, d.name as deity, CASE u.period WHEN 1 THEN "Morning" ELSE "Evening" END as period_str, u.*',FALSE);
        $this->db->join($this->services . ' as s','s.id = u.service_id');
        $this->db->join($this->deity . ' as d','d.id = u.deity_id','left');
        $this->db->join($this->star . ' as star','star.id = u.star1','left');
        $this->db->join($this->star . ' as star2','star2.id = u.star2','left');
        if($date_type == 1) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('u.date >=',date('Y-m-d',strtotime($start_date)));
                $this->db->where('u.date <=',date('Y-m-d',strtotime($end_date)));
            } else {
                $this->db->where('u.date >=',date('Y-m-d'));
                $this->db->where('u.date <=',date('Y-m-d'));
            } 
        } elseif($date_type == 2) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('u.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
                $this->db->where('u.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
            } else {
                $this->db->where('u.created_on >=',date('Y-m-d 00:00:00'));
                $this->db->where('u.created_on <=',date('Y-m-d 23:59:59'));
            }
        }
        if(!empty($type)) {
            $this->db->where('u.service_id',$type);
        }
        #$this->db->where('u.status',1);
        $this->db->where('u.book_status',1);
        return $this->db->get($this->ubayam . ' as u')->result();
    }
}
?>


