<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 16-12-24
 * Time: 上午10:40
 * To change this template use File | Settings | File Templates.
 */
class Warehouse_WarehouseGraphicController  extends Ec_Controller_Action
{
    public function preDispatch()
    {
        $this->NotREGEXPLccode = "HQ751|MK-A01|MK-A02|MK-A03|MK-A04|MK-A05|MK-A06|BK-A06|BK-A05|BK-A04|BK-A03|BK-A02|BK-A01|CK-A08|FX-B01|FX-B02|FX-B03|FX-B04|FX-B05|FX-B06|FX-B07|FX-B08|CK-A01|CK-A02|CK-A03|CK-A04|CK-A07|BH-C02|CK-A09|CK-A10|BH-C01|BH-C02|BH-C03|BH-C04|BH-C05|BH-C06|BH-C07|BH-C08|BH-C09|BH-C10|TK751";
        $this->tplDirectory = "warehouse/views/default/";
        $this->serviceClass = new Service_Warehouse();
    }

    public function indexAction(){
        $lcCodeArr = explode("|",$this->NotREGEXPLccode);
        $existData = array();
        foreach($lcCodeArr as $lc_code){
            $condition = array(
                'lc_code_like'=>$lc_code,
            );
            $count		= Service_InventoryBatch::getLeftJoinByCondition($condition, 'count(*)');
            if($count){
                $existData[$lc_code] = "1";
            }
        }
        $condition = array(
            'LC_CODE_NOT_REGEXP'=>$this->NotREGEXPLccode,
        );
        $count		= Service_InventoryBatch::getLeftJoinByCondition($condition, 'count(*)');
        if($count){
            $existData['OTHER'] = "1";
        }
        $this->view->existData = $existData;
        echo Ec::renderTpl($this->tplDirectory . "warehouse-graphic.tpl", 'layout');
    }

    public function getInventoryBatchAction(){
        $return = array(
            'state'=>1,
            'data'=>'',
            'page'=>'',
            'pageSize'=>'',
        );
        //$from = $this->_request->getParam('from','');
        $lc_code = $this->_request->getParam('lc_code',"");
        $hs_code = $this->_request->getParam('hs_code',"");
        $hs_goods_name = $this->_request->getParam('hs_goods_name',"");
        $goods_id = $this->_request->getParam('goods_id',"");
        $wa_code = $this->_request->getParam('wa_code',"");
        $warehouse_id = $this->_request->getParam("warehouse_id","");
        $page		= $this->getRequest()->getParam('page', 1);
        $pageSize	= $this->getRequest()->getParam('pageSize', 20);
        if($lc_code=="OTHER"){
            $condition = array(
                'LC_CODE_NOT_REGEXP'=>$this->NotREGEXPLccode,
                'hs_code_like'=>$hs_code,
                'hs_goods_name_like'=>$hs_goods_name,
                'goods_id_like'=>$goods_id,
                'lc_code_like2'=>$wa_code,
                'warehouse_id'=>$warehouse_id
            );
        }else{
            $condition = array(
                'lc_code_like'=>$lc_code,
                'hs_code_like'=>$hs_code,
                'hs_goods_name_like'=>$hs_goods_name,
                'goods_id_like'=>$goods_id,
                'lc_code_like2'=>$wa_code,
                'warehouse_id'=>$warehouse_id
            );
        }
        $count		= Service_InventoryBatch::getLeftJoinByCondition($condition, 'count(*)');
        $ibList = Service_InventoryBatch::getLeftJoinByCondition($condition,"*",$pageSize,$page,'ib_id asc');

        $return['data'] = $ibList;
        $return['page'] = $page;
        $return['pageSize'] = $pageSize;
        $return['lc_code_like'] = $lc_code;
        $return['total'] = $count;
        die(Zend_Json::encode($return));


    }

    public function searchDataAction(){
        //$lc_code = $this->_request->getParam('lc_code',"");
        $hs_code = $this->_request->getParam('hs_code',"");
        $hs_goods_name = $this->_request->getParam('hs_goods_name',"");
        $goods_id = $this->_request->getParam('goods_id',"");
        $wa_code = $this->_request->getParam('wa_code',"");
        $warehouse_id = $this->_request->getParam("warehouse_id","");
        $return = array(
            'state'=>0,
            'data'=>array(),
        );
        $lcCodeArr = explode("|",$this->NotREGEXPLccode);
        foreach($lcCodeArr as $lc_code){
            $condition = array(
                'lc_code_like'=>$lc_code,
                'hs_code_like'=>$hs_code,
                'hs_goods_name_like'=>$hs_goods_name,
                'goods_id_like'=>$goods_id,
                'lc_code_like2'=>$wa_code,
                'warehouse_id'=>$warehouse_id
            );
            $count		= Service_InventoryBatch::getLeftJoinByCondition($condition, 'count(*)');
            if($count){
                $return['data'][] = $lc_code;
            }
        }
        $condition = array(
            'LC_CODE_NOT_REGEXP'=>$this->NotREGEXPLccode,
            'hs_code_like'=>$hs_code,
            'hs_goods_name_like'=>$hs_goods_name,
            'goods_id_like'=>$goods_id,
            'lc_code_like2'=>$wa_code,
            'warehouse_id'=>$warehouse_id
        );
        $count		= Service_InventoryBatch::getLeftJoinByCondition($condition, 'count(*)');
        if($count){
            $return['data'][] = "OTHER";
        }
        if(!empty($return['data'])) $return['state'] = 1;
        die(Zend_Json::encode($return));
    }

}
