<?php
class Inventory_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }
    

    public function get_goods_status()
    {
        $this->db->order_by ( 'status_id', "asc" );
        $query = $this->db->get('status');
         return $query->result ();
    }   
    
    public function get_inventory($_goods_name=null,$_goods_code=null,$_goods_postil=null,$_docput_nums=null,$_docin_nums=null,$_send_nums=null,$_from=null,$_to=null,$_offset=null,$_num=null){
        if(!empty($_offset) and !empty($_num)) $this->db->limit($_num,$_offset);
        if(!empty($_docput_nums)) $this->db->where('inventory.docput_number', $_docput_nums);        
        if(!empty($_docin_nums)) $this->db->where('inventory.docin_number', $_docin_nums);
        if(!empty($_send_nums)) $this->db->where('inventory.docin_send_number', $_send_nums);
        if(!empty($_from)) $this->db->where('inventory.inventory_datetime >=', $_from);
        if(!empty($_to)) $this->db->where('inventory.inventory_datetime <=', $_to);
        if(!empty($_goods_name)) $this->db->where('goods.goods_name like', "%$_goods_name%");
        if(!empty($_goods_code)) $this->db->where('goods.goods_code like ', "%$_goods_code%");
        if(!empty($_goods_postil)) $this->db->where("FIND_IN_SET('$_goods_postil',goods_postil) !=", 0);
        $this->db->select('inventory.*,goods.goods_name,goods.goods_code');
        $this->db->from('inventory');
        $this->db->join('goods','goods.goods_id = inventory.goods_id ');
        $this->db->order_by ( 'inventory.inventory_id', "desc" );
        $query = $this->db->get();
//         return  $this->db->last_query();
        return $query->result ();
    }


    public function get_all_area(){
        $query = $this->db->get('area');
        return $query->result ();
    }    
    
    public function get_all_position(){
        $query = $this->db->get('position');
        return $query->result ();
    }    
    


}

