<?php
class Ship_PriceHistoryController extends Ec_Controller_Action
{
    public function preDispatch()
    {
        $this->tplDirectory = "ship/views/";
        $this->serviceClass = new Service_ShipPriceHistory();
    }
    /**
     * 列表
     * (non-PHPdoc)
     * @see Ec_Controller_Action::listAction()
     */
    public function listAction()
    {
        $currency=Common_DataCache::getCurrency();
        $type=Common_Type::SMFeeType('auto');
        $warehouse=Common_DataCache::getWarehouseSimple();
        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 = $this->serviceClass->getMatchFields($params);
            unset($params);
            $count = $this->serviceClass->getByCondition($condition, 'count(*)');
            $return['total'] = $count;

            if ($count) {
                $showFields=array(
                    'sm_code',
                    'sp_weight',
                    'sp_cost',
                    'sp_price',
                    'currency_code',
                    'area',
                    'sp_fee_type',
                    'warehouse_id',
                    'sp_id',
                    'sp_ticket_cost',
                    'cost_currency_code',
                    'one_ticket_cbcost',
                    'price_batch_number',
                    'date_start',
                    'date_end'
                );
                $showFields = $this->serviceClass->getFieldsAlias($showFields);
                $rows = $this->serviceClass->getByCondition($condition,$showFields, $pageSize, $page, array('date_start desc', 'sp_id desc'));
                $return['data'] = $rows;
                $return['state'] = 1;
                $return['type'] = $type;
                $return['warehouse'] = $warehouse;
                $return['message'] = "";
            }
            die(Zend_Json::encode($return));
        }
        $this->view->currency=$currency;
        $this->view->type=$type;
        //$this->view->SM=Common_DataCache::getShippingMethodSimple();
        $sm=Service_ShippingMethod::getAll();
        $sm=Common_Common::multisort($sm);
        $this->view->SM =$sm; 
        $this->view->warehouse=$warehouse;
        echo Ec::renderTpl($this->tplDirectory . "price_history_index.tpl", 'layout');
    }

    /**
     * 列表
     * (non-PHPdoc)
     * @see Ec_Controller_Action::listAction()
     */
    public function customerListAction()
    {
        $type=Common_Type::SMFeeType('auto');
        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();
            $obj = new Service_ShipCustomerPriceHistory();
            $condition = $obj->getMatchFields($params);
            unset($params);
            $count = Service_ShipCustomerPriceHistory::getByCondition($condition, 'count(*)');
            $return['total'] = $count;

            if ($count) {
                $showFields=array(
                    'scp_id',
                    'sm_code',
                    'area',
                    'scp_weight',
                    'scp_price',
                    'scp_cost',
                    'currency_code',
                    'scp_fee_type',
                    'sm_id',
                    'warehouse_id',
                    'scp_ticket_cost',
                    'cost_currency_code',
                    'one_ticket_cbcost',
                    'price_batch_number',
                    'date_start',
                    'date_end',
                    'customer_code',
                );
                $showFields = $obj->getFieldsAlias($showFields);
                $rows = Service_ShipCustomerPriceHistory::getByCondition($condition,$showFields, $pageSize, $page, array('date_start desc', 'scp_id desc'));
                $return['data'] = $rows;
                $return['state'] = 1;
                $return['message'] = "";
            }
            die(Zend_Json::encode($return));
        }
        $currency=Common_DataCache::getCurrency();
        $warehouse=Common_DataCache::getWarehouseSimple();
        $this->view->currency=$currency;
        $this->view->type=$type;
        //$this->view->SM=Common_DataCache::getShippingMethodSimple();
        $sm=Service_ShippingMethod::getAll();
        $sm=Common_Common::multisort($sm);
        $this->view->SM =$sm;
        $this->view->warehouse=$warehouse;
        echo Ec::renderTpl($this->tplDirectory . "customer_price_history_index.tpl", 'layout');
    }
}