<?php
class Ship_WeightHistoryController extends Ec_Controller_Action
{
    public function preDispatch()
    {
        $this->tplDirectory = "ship/views/";
        $this->serviceClass = new Service_ShipWeightPriceHistory();
    }
	/**
	 * 列表
	 * (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(
					'swp_weight',
	                'swp_exces_weight',
	                'swp_cost',
	                'swp_exces_cost',
	                'currency_code',
	                'swp_price',
	                'swp_exces_price',
	                'area',
	                'sm_code',
	                'swp_fee_type',
	                'warehouse_id',
	                'swp_id',
	                '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', 'swp_id desc'));
                $return['data'] = $rows;
                $return['state'] = 1;
                $return['message'] = "";
                $return['type'] = $type;
                $return['warehouse'] =$warehouse;
            }
            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 . "weight_history_index.tpl", 'layout');
    }

    /**
     * 列表
     * (non-PHPdoc)
     * @see Ec_Controller_Action::listAction()
     */
    public function customerListAction()
    {
        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_ShipCustomerWeightPriceHistory();
            $condition = $obj->getMatchFields($params);
            unset($params);
            $count = Service_ShipCustomerWeightPriceHistory::getByCondition($condition, 'count(*)');
            $return['total'] = $count;
            if ($count) {
                $showFields=array(
                    'scwp_id',
                    'sm_code',
                    'area',
                    'scwp_weight',
                    'scwp_price',
                    'scwp_cost',
                    'scwp_exces_weight',
                    'scwp_exces_price',
                    'scwp_exces_cost',
                    'currency_code',
                    'scwp_fee_type',
                    'sm_id',
                    'warehouse_id',
                    'one_ticket_fee',
                    'cost_currency_code',
                    'one_ticket_cbcost',
                    'price_batch_number',
                    'date_start',
                    'date_end',
                    'customer_code',
                );
                $showFields = $obj->getFieldsAlias($showFields);
                $rows = Service_ShipCustomerWeightPriceHistory::getByCondition($condition,$showFields, $pageSize, $page, array('date_start desc', 'scwp_id desc'));
                $return['data'] = $rows;
                $return['state'] = 1;
                $return['message'] = "";
            }
            die(Zend_Json::encode($return));
        }
        $currency=Common_DataCache::getCurrency();
        $type=Common_Type::SMFeeType('auto');
        $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_weight_history_index.tpl", 'layout');
    }
}