コード例 #1
0
 /**
  * This function calculates the exchange rate of a value
  * 
  * @param string $from
  * @param string $to
  * @param float $value
  * @return $convertedValue
  */
 public function converter($from, $to, $value)
 {
     $convertedValue = $value;
     if ($from != $to) {
         if ($from == CurrencyExchange::$baseCurrency) {
             $exchangeRate = CurrencyExchangeQuery::create()->whereAdd(CurrencyExchange::CURRENCY, $to)->addAscendingOrderBy(CurrencyExchange::RATEDATE)->findOneOrThrow("The ExchangeRate from {$from} to {$to} can't be calculate.");
             $exchangeRate->setRate($exchangeRate->invertExchangeRate());
         } else {
             if ($to == CurrencyExchange::$baseCurrency) {
                 $exchangeRate = CurrencyExchangeQuery::create()->whereAdd(CurrencyExchange::CURRENCY, $from)->addAscendingOrderBy(CurrencyExchange::RATEDATE)->findOneOrThrow("The ExchangeRate from {$from} to {$to} can't be calculate.");
             } else {
                 $rateFrom = CurrencyExchangeQuery::create()->whereAdd(CurrencyExchange::CURRENCY, $from)->addDescendingOrderBy(CurrencyExchange::RATEDATE)->findOneOrThrow("The ExchangeRate from {$from} to {$to} can't be calculate.");
                 $rateTo = CurrencyExchangeQuery::create()->whereAdd(CurrencyExchange::CURRENCY, $to)->addDescendingOrderBy(CurrencyExchange::RATEDATE)->findOneOrThrow("The ExchangeRate from {$from} to {$to} can't be calculate.");
                 $exchangeRate = CurrencyExchangeFactory::createFromArray(array(CurrencyExchange::CURRENCY => $to, CurrencyExchange::RATE => $rateFrom->getRate() / $rateTo->getRate()));
             }
         }
         $convertedValue = $value * $exchangeRate->getRate();
     }
     return $convertedValue;
 }
コード例 #2
0
ファイル: RestockController.php プロジェクト: Eximagen/sochi
 public function generateRequisitionAction()
 {
     $restocks = RestockQuery::create()->find();
     if (!$restocks->isEmpty()) {
         $restockEntries = RestockEntryQuery::create()->whereAdd(RestockEntry::ID_RESTOCK, $restocks->current()->getIdRestock(), RestockQuery::EQUAL)->find();
         if (!$restockEntries->isEmpty()) {
             $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $restockEntries->getDistinctProducts(), ProductQuery::IN)->find();
             $currencies = CurrencyQuery::create()->find();
             $exchangeRates = CurrencyExchangeQuery::create()->find();
             $restockFinalResultManager = new RestockFinalResultsManager($restockEntries, $products);
             try {
                 $this->getRequisitionCatalog()->beginTransaction();
                 $requisition = RequisitionFactory::createFromArray(array(Requisition::ID_DESTINATION_COUNTRY => Country::$defaultIdCountry, Requisition::TYPE => Requisition::$Type["Weekly"], Requisition::STATUS => Requisition::$Status["New"], Requisition::NUM_REQUISITION => "Weekly Restock."));
                 $this->getRequisitionCatalog()->create($requisition);
                 while ($restockEntries->valid()) {
                     $restockEntry = $restockEntries->read();
                     if ($restockEntry->isChecked()) {
                         $quantity = $restockFinalResultManager->getTotalCartonsByIdRestockEntry($restockEntry->getIdRestockEntry());
                         if ($quantity > 0) {
                             $product = $products->getByPK($restockEntry->getIdProduct());
                             $requisitionEntry = RequisitionEntryFactory::createFromArray(array(RequisitionEntry::ID_REQUISITION => $requisition->getIdRequisition(), RequisitionEntry::ID_PRODUCT => $product->getItemCode(), RequisitionEntry::PRICE => $restockEntry->getMinTargetPrice() * $exchangeRates->getByFromAndTo(Currency::$defaultCurrency, $product->getCurrency())->getRate(), RequisitionEntry::ID_CURRENCY => $product->getCurrency(), RequisitionEntry::ID_SUPPLIER_DEFAULT => $product->getIdSupplier(), RequisitionEntry::QUANTITY => $quantity, RequisitionEntry::STATUS => RequisitionEntry::$Status["New"]));
                             $this->getRequisitionEntryCatalog()->create($requisitionEntry);
                         }
                     }
                 }
                 $this->getRestockEntryCatalog()->truncate();
                 $this->getRestockCatalog()->truncate();
                 $this->getRequisitionCatalog()->commit();
                 $this->setFlash('ok', $this->i18n->_("Requisition was saved with folio {$requisition->getIdRequisition()}"));
             } catch (Exception $e) {
                 $this->getRequisitionCatalog()->rollBack();
                 $this->setFlash('error', $this->i18n->_($e->getMessage()));
             }
         }
     }
     $this->_redirect('requisition/list');
 }
コード例 #3
0
 /**
  *
  */
 public function reactivateAction()
 {
     $id = $this->getRequest()->getParam('id');
     $currencyExchange = CurrencyExchangeQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the CurrencyExchange with id {$id}"));
     try {
         $this->getCurrencyExchangeCatalog()->beginTransaction();
         $currencyExchange->setStatus(CurrencyExchange::$Status['Active']);
         $this->getCurrencyExchangeCatalog()->update($currencyExchange);
         $this->getCurrencyExchangeCatalog()->commit();
         $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el CurrencyExchange"));
     } catch (Exception $e) {
         $this->getCurrencyExchangeCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->_redirect('currency-exchange/list');
 }
コード例 #4
0
 /**
  *
  * @return array
  */
 public function listAction()
 {
     $this->view->page = $page = $this->getRequest()->getParam('page') ?: 1;
     $this->view->contentTitle = $this->i18n->_("Requisition List");
     $this->view->setTpl("Index");
     // Get all filter params
     $post = array(Requisition::ID_REQUISITION => $this->getRequest()->getParam(Requisition::ID_REQUISITION, ""), Requisition::STATUS => $this->getRequest()->getParam(Requisition::STATUS, ""), Requisition::NUM_REQUISITION => $this->getRequest()->getParam(Requisition::NUM_REQUISITION, ""), Requisition::ID_DESTINATION_COUNTRY => $this->getRequest()->getParam(Requisition::ID_DESTINATION_COUNTRY, ""), "startDate" => $this->getRequest()->getParam("startDate", ""), "endDate" => $this->getRequest()->getParam("endDate", ""), Requisition::TYPE => $this->getRequest()->getParam(Requisition::TYPE, ""));
     $this->view->post = $post;
     $this->view->filter = $this->createFilterForUrl($post);
     $total = RequisitionQuery::create()->filter($post)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->count();
     $this->view->requisitions = $requisitions = RequisitionQuery::create()->filter($post)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->page($page, $this->getMaxPerPage())->addAscendingOrderBy(Requisition::STATUS)->addAscendingOrderBy(Requisition::DATE)->find();
     if ($requisitions->count() > 0) {
         // Get all requisition entries
         $this->view->entries = $entries = RequisitionEntryQuery::create()->noInactives()->whereAdd(RequisitionEntry::ID_REQUISITION, $requisitions->getPrimaryKeys(), BaseQuery::IN)->find();
         if ($entries->count() > 0) {
             // Get all entry products by product id
             $this->view->products = $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $entries->getDistinctProducts(), BaseQuery::IN)->find();
             // Get all distinct Suppliers
             $supplierIds = $entries->getDistinctSuppliers();
             if ($supplierIds > 0) {
                 $this->view->suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $supplierIds, SapSupplierQuery::IN)->find();
             }
         }
     }
     $emptyProduct = new Product();
     $emptyMessage = $this->i18n->_('N/S');
     $emptyProduct->setItemCode($emptyMessage);
     $emptyProduct->setKeyMother($emptyMessage);
     $emptyProduct->setStatus($emptyMessage);
     $this->view->emptyProduct = $emptyProduct;
     // Get all currencies
     $this->view->currencies = $currencies = CurrencyQuery::create()->find();
     $this->view->usd = $usd = CurrencyQuery::create()->findByPK(Currency::$defaultCurrency);
     $this->view->emptyCurrency = new Currency();
     $this->view->currencyExchanges = $a = CurrencyExchangeQuery::create()->addAscendingOrderBy(CurrencyExchange::RATEDATE)->find();
     $this->view->manager = new RequisitionEntryProcessor();
     $this->view->countries = array("" => $this->i18n->_("All")) + CountryQuery::create()->find()->toCombo();
     // Get all status
     $status = Requisition::$Status;
     // Discard status active and inactive and create a array to status combo
     $status = array_filter($status, function ($var) {
         return $var != Requisition::$Status["Active"] && $var != Requisition::$Status["Inactive"] ? true : false;
     });
     $this->view->status = array("" => $this->i18n->_("All")) + array_flip($status);
     // Get requisition Types
     $this->view->types = array("" => $this->i18n->_("All")) + array_flip(Requisition::$Type);
     $this->view->paginator = $this->createPaginator($total, $page);
 }