<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 18-8-14
 * Time: 下午3:02
 * To change this template use File | Settings | File Templates.
 */
class Warehouse_InventoryBatchSerialController extends Ec_Controller_Action
{
    public function preDispatch()
    {
        $this->tplDirectory = "warehouse/views/inventory/";
        $this->serviceClass = new Service_InventoryBatchSerial();
    }

    public function listAction(){
        if ($this->_request->isPost()) {
            $page = $this->_request->getParam('page', 1);
            $pageSize = $this->_request->getParam('pageSize', 20);

            $page = $page ? $page : 1;
            $pageSize = $pageSize ? $pageSize : 20;

            $return = array(
                "state" => 0,
                "message" => "No Data"
            );

            $params = $this->_request->getParams();
            $condition = $params;
            $condition['ibs_status'] = 1;
            $count = $this->serviceClass->getJoinProductByCondition($condition, 'count(*)');
            $return['total'] = $count;

            if ($count) {
                /*$showFields = array(
                    'lc_code',
                    'product_barcode',
                    'reference_no',
                    'warehouse_id',
                    'receiving_code',
                    'ib_status',
                    'ib_hold_status',
                    'ib_quantity',
                    'ib_fifo_time',
                    'ib_update_time',
                    'ib_id',
                    'product_id',
                    'hs_serial_no',
                    'batch_goods_id'
                );*/
                //$showFields = $this->serviceClass->getFieldsAlias($showFields);
                $rows = $this->serviceClass->getJoinProductByCondition($condition, "*", $pageSize, $page, array('ibs_id desc'));
                $return['data'] = $rows;
                $return['state'] = 1;
                $return['message'] = "";
            }
            die(Zend_Json::encode($return));
        }
        $this->view->warehouseArea = Common_DataCache::getWarehouseArea();
        $this->view->locationType = Common_DataCache::getLocationType();
        echo Ec::renderTpl($this->tplDirectory . "inventory_batch_serial_index.tpl", 'layout');
    }
}
