<?php
class Gold_inventory_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->gold_silver = TBL_INV_GOLD;
        $this->type = TBL_INV_GOLD_TYPE;
    }
    
    public function get_data($start_date='',$end_date='',$item=''){
        $this->db->select('t.type as type_name, gs.*, CASE gs.item WHEN 1 THEN "Gold" WHEN 2 THEN "Silver" END as item_str',FALSE);
        $this->db->join($this->type . ' as t','t.id = gs.type');
        if(!empty($start_date) && !empty($end_date)) {
            $this->db->where('gs.created_on >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('gs.created_on <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('gs.created_on >=',date('Y-m-d 00:00:00'));
            $this->db->where('gs.created_on <=',date('Y-m-d 23:59:59'));
        } 
        if(!empty($item)) {
            $this->db->where('gs.item',$item);
        }
        $this->db->where('gs.status',1);
        return $this->db->get($this->gold_silver . ' as gs')->result();
    }
}
?>


