<?php
class Homam_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->homam = TBL_BHM;
        $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',20);
        $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, star.tamil_name as tamil_star1, star2.tamil_name as tamil_star2, star2.name as star2, d.name as deity, CASE h.bhm_period WHEN 1 THEN "Morning" ELSE "Evening" END as period_str, h.*',FALSE);
        $this->db->join($this->services . ' as s','s.id = h.service_id');
        $this->db->join($this->star . ' as star','star.id = h.star_id_1','left');
        $this->db->join($this->star . ' as star2','star2.id = h.star_id_2','left');
        $this->db->join($this->deity . ' as d','d.id = h.god_id','left');
        if($date_type == 1) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('h.bhm_fn_from_date >=',date('Y-m-d 00:00:00',strtotime($start_date)));
                $this->db->where('h.bhm_fn_from_date <=',date('Y-m-d 23:59:59',strtotime($end_date)));
            } else {
                $this->db->where('h.bhm_fn_from_date >=',date('Y-m-d 00:00:00'));
                $this->db->where('h.bhm_fn_from_date <=',date('Y-m-d 23:59:59'));
            } 
        } elseif($date_type == 2){
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('h.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
                $this->db->where('h.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
            } else {
                $this->db->where('h.created_on >=',date('Y-m-d 00:00:00'));
                $this->db->where('h.created_on <=',date('Y-m-d 23:59:59'));
            }
        }
        if(!empty($type)) {
            $this->db->where('h.service_id',$type);
        }
        #$this->db->where('a.status',1);
        $this->db->where('h.bhm_book_status',1);
        return $this->db->get($this->homam . ' as h')->result();
    }
}
?>