<?php
/**
 * Author:echo
 * Email:sqlgun@qq.com
 * Date: 2018-7-17
 * 有偿二次开发，邮件联系
 */
class Inventory extends MY_Controller{
    
    public function __construct(){
        parent::__construct();
        $this->load->model('kpi/inventory_model');
    }
    public function index(){
        $_data ['button']=$this->navButton('Kpi');
        $_data ['url'] = $this->url;
        $_data['status']=$this->get_goods_status();
        $_data['area']=$this->get_area();
        $_data['position']=$this->get_position();
        $this->load->view('kpi/inventory',$_data); 
    }
    

    public function get_area(){
        $_row=$this->inventory_model->get_all_area();
        return $_row;
    }    
    

    public function get_position(){
        $_row=$this->inventory_model->get_all_position();
        return $_row;
    }    
    
    public function get_goods_status(){
        $_row = $this->inventory_model->get_goods_status();
        foreach ($_row as $_key=>$_value){
            $_rows[$_key]->id=$_value->status_id;
            $_rows[$_key]->text=$_value->status_name;
        }
        $_row=array_values($_rows);
         return $_row;
    }    
    
    
    public function get_inventory(){
       $_page=$this->input->post('page');
       $_num=$this->input->post('rows');
       $_offset = ($_page-1)*$_num;
       
       $_docput_number=$this->input->post('docput_number');
       $_docin_number=$this->input->post('docin_number');
       $_docin_send_number=$this->input->post('docin_send_number');
       
       $_goods_name=$this->input->post('goods_name');
       $_goods_code=$this->input->post('goods_code');
       $_goods_postil=$this->input->post('goods_postil');
       
       $_inventory_date_from=$this->input->post('inventory_date_from');
       if($_inventory_date_from) $_inventory_date_from=strtotime($_inventory_date_from);
       $_inventory_date_to=$this->input->post('inventory_date_to');
       if($_inventory_date_to) $_inventory_date_to=strtotime($_inventory_date_to);
      
       $_result["total"] =count($this->inventory_model->get_inventory($_goods_name,$_goods_code,$_goods_postil,$_docput_number,$_docin_number,$_docin_send_number,$_inventory_date_from,$_inventory_date_to));
       $_row = $this->inventory_model->get_inventory($_goods_name,$_goods_code,$_goods_postil,$_docput_number,$_docin_number,$_docin_send_number,$_inventory_date_from,$_inventory_date_to,$_offset,$_num);
// echo $_row;exit;
       $_row=array_values($_row);
        foreach ($_row as $_key=>$_value){
            $_row[$_key]->inventory_datetime=date('Y-m-d H:i:s',$_value->inventory_datetime);
        }
       $_result["rows"]=$_row;
        echo json_encode($_result);
    }

}