Example #1
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\Restock
  */
 protected function makeBean($resultset)
 {
     return RestockFactory::createFromArray($resultset);
 }
Example #2
0
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         $params[Restock::ID_RESTOCK] = $this->getRequest()->getParam("id_restock", "");
         $params[Restock::PERCENT_A] = $this->getRequest()->getParam("percent_A", "");
         $params[Restock::PERCENT_B] = $this->getRequest()->getParam("percent_B", "");
         $params[Restock::PERCENT_C] = $this->getRequest()->getParam("percent_C", "");
         $params[Restock::PERCENT_D] = $this->getRequest()->getParam("percent_D", "");
         $params[Restock::PERCENT_E] = $this->getRequest()->getParam("percent_E", "");
         $params[Restock::PERCENT_R] = $this->getRequest()->getParam("percent_R", "");
         $params[Restock::RESTOCK_TYPE] = $this->getRequest()->getParam("restock_type", "");
         $params[Restock::CURRENT_PRODUCT_CATALOG] = $this->getRequest()->getParam("current_product_catalog", "");
         $restock = RestockQuery::create()->findByPKOrThrow($params[Restock::ID_RESTOCK], $this->i18n->_("The Restock with id {$params[Restock::ID_RESTOCK]} does not exist."));
         try {
             $this->getRestockCatalog()->beginTransaction();
             RestockFactory::populate($restock, $params);
             $this->getRestockCatalog()->update($restock);
             $restockEntries = RestockEntryQuery::create()->whereAdd(RestockEntry::ID_RESTOCK, $restock->getIdRestock())->find();
             $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $restockEntries->getDistinctProducts(), ProductQuery::IN)->find();
             $currencies = CurrencyQuery::create()->find();
             $currencyExchanges = CurrencyExchangeQuery::create()->addAscendingOrderBy(CurrencyExchange::RATEDATE)->find();
             $productCosts = $this->getCostLogByIdProducts();
             $restockCalculatorManager = new RestockCalculatorManager($restock, $restockEntries, $products, $productCosts, $currencies, $currencyExchanges);
             $restockEntries->rewind();
             while ($restockEntries->valid()) {
                 $restockEntry = $restockEntries->read();
                 $product = $products->getByPK($restockEntry->getIdProduct());
                 RestockEntryFactory::populate($restockEntry, array(RestockEntry::DESITION => $restockCalculatorManager->getDesitionByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::NEW_QUANTITY_MIN => $restockCalculatorManager->getNewQuantityMinByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::PRICE_MIN => $restockCalculatorManager->getNewImportMinByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::NEW_QUANTITY_MAX => $restockCalculatorManager->getNewQuantityMaxByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::PRICE_MAX => $restockCalculatorManager->getNewImportMaxByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::PURCHASE_PRICE => $restockCalculatorManager->getPurchaseByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::PURCHASE_PRICE_PERCENT => $restockCalculatorManager->getPurchasePercentByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::PURCHASE_QUANTITY => $restockCalculatorManager->getQuantityByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::PURCHASE_QUANTITY_PERCERNT => $restockCalculatorManager->getQuantityPercentByIdRestockEntry($restockEntry->getIdRestockEntry()), RestockEntry::MIN_TARGET_PRICE => $restockCalculatorManager->getMinTargetPriceUSDByIdProduct($restockEntry->getIdProduct()), RestockEntry::MANUAL_RESTOCK => $product->isManual() ? RestockEntry::$ManualRestock["Yes"] : RestockEntry::$ManualRestock["No"]));
                 $this->getRestockEntryCatalog()->update($restockEntry);
             }
             $this->getRestockCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The Restock was updated"));
         } catch (Exception $e) {
             $this->getRestockCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('restock/edit');
 }