<?php
class Temple_activity_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->temple = TBL_BILL_TEMPLE;
        $this->priest = TBL_PRIEST;
    }
    
    public function list_service_type(){
        $this->db->select('id,name as service_name');
        $this->db->where('menu_name',16);
        $this->db->where('status',1);
        return $this->db->get($this->services)->result();
    }
    
    public function get_data($start_date='',$end_date='',$type=''){
        $this->db->select('s.name as service_name, s.prefix, CASE t.class WHEN 1 THEN "Morning" ELSE "Evening" END as class_str, CASE t.class_type WHEN 1 THEN "Individual in Home" WHEN 2 THEN "Individual in Temple" WHEN 3 THEN "Group in Home" WHEN 4 THEN "Group in Temple" END as class_type_str, CASE t.term WHEN 1 THEN "Yearly" WHEN 2 THEN "Monthly" WHEN 3 THEN "Weekly" WHEN 4 THEN "Daily" END term_str, t.*',FALSE);
        $this->db->join($this->services . ' as s','s.id = t.service_id');
        if(!empty($start_date) && !empty($end_date)) {
            $this->db->where('t.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('t.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('t.created_on >=',date('Y-m-d 00:00:00'));
            $this->db->where('t.created_on <=',date('Y-m-d 23:59:59'));
        } 
        if(!empty($type)) {
            $this->db->where('t.service_id',$type);
        }
        #$this->db->where('t.status',1);
        return $this->db->get($this->temple . ' as t')->result();
    }
}
?>