/**
  * (non-PHPdoc)
  * @see Application\Controller.CrudController::editAction()
  */
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id');
     $this->view->salesParameter = SalesParameterQuery::create()->findByPK($id)->toArray();
     $this->view->setTpl('New');
     $this->view->contentTitle = $this->i18n->_('Edit Sales Parameter');
     $this->view->onsubmit = $this->getBaseUrl() . '/sales-parameter/update';
 }
 /**
  *
  * @return array
  */
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id_product');
     if (ProductPriceListQuery::create()->whereAdd(ProductPriceList::ID_PRODUCT, $id)->count()) {
         $productPriceList = ProductPriceListQuery::create()->whereAdd(ProductPriceList::ID_PRODUCT, $id)->findOneOrElse($id, new ProductPriceList());
     } else {
         $productPriceList = new ProductPriceList();
         $productPriceList->setIdProduct($id);
     }
     $product = ProductQuery::create()->findByPK($id);
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $product->getKeyMother(), ProductQuery::LIKE)->find();
     $productPriceListHistoryArray = array();
     while ($p = $products->read()) {
         for ($i = 1; $i <= 12; $i++) {
             $productPriceListHistoryQuery = ProductPriceListHistoryQuery::create()->whereAdd(ProductPriceListHistory::ITEMCODE, $p->getItemCode())->whereAdd(ProductPriceListHistory::PRICELIST, $i)->whereAdd(ProductPriceListHistory::PRICE, '0.0', ProductPriceListHistoryQuery::NOT_EQUAL)->orderBy(ProductPriceListHistory::LOGINSTANCE, ProductPriceListHistoryQuery::DESC)->findByPage(1, 10);
             $j = 0;
             while ($productPriceListHistory = $productPriceListHistoryQuery->read()) {
                 $productPriceListHistoryArray[$p->getItemCode()][$i][$j]['price'] = $productPriceListHistory->getPrice();
                 $productPriceListHistoryArray[$p->getItemCode()][$i][$j]['date'] = $productPriceListHistory->getUpdateDate();
                 $j++;
             }
         }
     }
     // 		echo '<pre>';
     // 		print_r($productPriceList);
     // 		die;
     $productPrintingArea = ProductPrintingAreaQuery::create()->whereAdd(ProductPrintingArea::ID_PRODUCT, $product->getKeyMother())->findOne();
     $printingTechnique = ProductionTimePrintingTechniqueQuery::create()->whereAdd(ProductionTimePrintingTechnique::ID_PRODUCT_PRINTING_AREA, $productPrintingArea->getIdProductPrintingArea())->getFavorite()->findOne();
     $rangeAndVolume = RangeAndVolumeQuery::create()->whereAdd(RangeAndVolume::RANGE, $product->getCost(), RangeAndVolumeQuery::GREATER_THAN)->orderBy(RangeAndVolume::RANGE, RangeAndVolumeQuery::ASC)->findOne();
     $technique = PrintingTechniqueQuery::create()->findByPK($printingTechnique->getIdPrintingTechnique());
     $size = PrintingSizeQuery::create()->findByPK($productPrintingArea->getIdPrintingSize());
     $printingPrice = PrintingTechniqueSizeQuery::create()->whereAdd(PrintingTechniqueSize::ID_PRINTING_SIZE, $size->getIdPrintingSize())->whereAdd(PrintingTechniqueSize::ID_PRINTING_TECHNIQUE, $technique->getIdPrintingTechnique())->findOne();
     $salesParameters = SalesParameterQuery::create()->find();
     $this->view->id_product = $id;
     $this->view->contentTitle = $this->i18n->_('Edit Product Price List');
     $this->view->products = $products->toArray();
     $this->view->priceListHistory = $productPriceListHistoryArray;
     $this->view->productPrintingArea = $productPrintingArea->toArray();
     $this->view->printingTechnique = $printingTechnique->toArray();
     $this->view->rangeAndVolume = $rangeAndVolume->toArray();
     $this->view->technique = $technique->getAbbreviation();
     $this->view->size = $size->getName();
     $this->view->printingPrice = $printingPrice->getPrice();
     $this->view->statuses = Product::$StatusFullName;
     $this->view->onsubmit = $this->getBaseUrl() . "/product-price-list/update";
     $this->view->freightFactor = $salesParameters->getByPK(SalesParameter::$SalesParameters['FreightFactorAndPromptPayment'])->getValue();
     if (!$productPriceList->getExchangeRateUsdToPesos()) {
         $productPriceList->setExchangeRateUsdToPesos($salesParameters->getByPK(SalesParameter::$SalesParameters['ExchangeRate'])->getValue());
     }
     if (!$productPriceList->getExchangeRateEurToUsd()) {
         $productPriceList->setExchangeRateEurToUsd($salesParameters->getByPK(SalesParameter::$SalesParameters['ExchangeRateEurtoUsd'])->getValue());
     }
     if (!$productPriceList->getMarginEximagen()) {
         $productPriceList->setMarginEximagen($salesParameters->getByPK(SalesParameter::$SalesParameters['EximagenRange'])->getValue());
     }
     /**
      *
      * @todo cambiar estos valores
      */
     $result = $this->getLandedCost($id, $productPriceList);
     if (!$result['result']) {
         $this->setFlash('warning', $this->i18n->_('You must edit the Product before the Product Printing List') . $result['message']);
         $this->_redirect('product/list');
     }
     $landedCost = $result['result'];
     $this->view->productPriceList = $productPriceList->toArray();
     //         $this->view->priceHistory = $this->getPriceHistoryAsCombo($id);
     $this->view->landedCost = $landedCost;
     $this->view->landedCostInfo = $this->getValuesUsedForLandedCost($id, $productPriceList);
     $url = $this->generateUrl('price-list', 'update', compact('id'));
     $this->view->form = $form;
     $this->view->setTpl("New");
 }