<?php
class Outdoor_service_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->outdoor = TBL_BILL_OUTDOOR_SERVICES;
        $this->priest = TBL_PRIEST;
    }
    
    public function list_service_type(){
        $this->db->select('id,name as service_name');
        $this->db->where('menu_name',13);
        $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, p.name as priest, n.name as nathaswaram, m.name as melam, CASE os.period WHEN 1 THEN "Morning" ELSE "Evening" END as period_str, os.*',FALSE);
        $this->db->join($this->services . ' as s','s.id = os.service_id');
        $this->db->join($this->priest . ' as p','p.id = os.priest_id','left');
        $this->db->join($this->priest . ' as n','n.id = os.nathaswaram_id','left');
        $this->db->join($this->priest . ' as m','m.id = os.melam_id','left');
        if($date_type == 1) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('os.date >=',date('Y-m-d',strtotime($start_date)));
                $this->db->where('os.date <=',date('Y-m-d',strtotime($end_date)));
            } else {
                $this->db->where('os.date >=',date('Y-m-d'));
                $this->db->where('os.date <=',date('Y-m-d'));
            }
        } elseif($date_type == 2) {
            if(!empty($start_date) && !empty($end_date)) {
                $this->db->where('os.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
                $this->db->where('os.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
            } else {
                $this->db->where('os.created_on >=',date('Y-m-d 00:00:00'));
                $this->db->where('os.created_on <=',date('Y-m-d 23:59:59'));
            } 
        }
        if(!empty($type)) {
            $this->db->where('os.service_id',$type);
        }
        #$this->db->where('os.status',1);
        return $this->db->get($this->outdoor . ' as os')->result();
    }
}
?>