<?php
class Cash_log_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->payment_type = TBL_PAY_TYPE;
        $this->payments = TBL_PAY;
        $this->ubayam = TBL_BILL_UBAYAM;
        $this->star = TBL_STAR;
    }
    
    public function list_payment_type(){
        $this->db->select('id,name as payment_name, slug');
        $this->db->where('status',1);
        return $this->db->get($this->payment_type)->result();
    }
    
    public function get_data($start_date='',$end_date=''){
        $this->db->select('p.id, p.pay_type_id, p.pay_amount, p.created_on, p.pay_ref_id, p.pay_ref_type');
        if(!empty($start_date) && !empty($end_date)) {
            $this->db->where('p.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('p.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('p.created_on >=',date('Y-m-d 00:00:00'));
            $this->db->where('p.created_on <=',date('Y-m-d 23:59:59'));
        }
        $this->db->where('p.status',1);
        $this->db->group_by('p.pay_ref_type,p.pay_ref_id');
        $this->db->order_by('p.created_on','desc');
        return $this->db->get($this->payments . ' as p')->result();
    }
    
    public function get_pay_amount_by_type($pay_ref_type,$pay_ref_id,$start_date='',$end_date='') {
        $this->db->select('p.pay_amount, p.pay_type_id, pt.name as PayName, pt.slug, p.created_on',FALSE);
        $this->db->join($this->payment_type . ' as pt','pt.id = p.pay_type_id');
        $this->db->where('p.pay_ref_type',$pay_ref_type);
        $this->db->where('p.pay_ref_id',$pay_ref_id);
        if(!empty($start_date) && !empty($end_date)) {
            $this->db->where('p.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('p.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('p.created_on >=',date('Y-m-d 00:00:00'));
            $this->db->where('p.created_on <=',date('Y-m-d 23:59:59'));
        }
        $this->db->where('p.status',1);
        return $this->db->get($this->payments . ' as p')->result();
    }
}
?>


