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


