/**
  * This function verify if exist all needded exchange rates to calculate a import in one currency
  * 
  * @author Erick Guevara Mart�nez
  * @param RequisitionEntryCollection $requisitionEntries
  * @param Currency $currencyTo
  * @param ExchangeRateCollection $currenciesExchanges
  * @return array
  */
 public function validateExchangeRates(RequisitionEntryCollection $requisitionEntries, Currency $currencyTo, CurrencyExchangeCollection $currenciesExchanges)
 {
     $validation["valid"] = true;
     $requisitionEntries->rewind();
     while ($requisitionEntries->valid()) {
         $requisitionEntry = $requisitionEntries->read();
         if ($requisitionEntry->getIdCurrency() != $currencyTo->getCurrCode()) {
             if (!$currenciesExchanges->hasCurrency($requisitionEntry->getIdCurrency()) || !$currenciesExchanges->hasCurrency($currencyTo->getCurrCode())) {
                 $validation["valid"] = false;
                 $validation["from"] = $requisitionEntry->getIdCurrency();
                 $validation["to"] = $currencyTo->getCurrCode();
                 break;
             }
         }
     }
     $requisitionEntries->rewind();
     return $validation;
 }
Example #2
0
 /**
  *
  * @return array
  */
 public function newAction()
 {
     $params = $this->getRequest()->getParams();
     $product['key'] = $params['composition'];
     $product['id_product_group'] = $params['id_product_group'];
     $product['id_family'] = $params['id_family'];
     $product['id_subfamily'] = $params['id_subfamily'];
     $product['id_brand'] = $params['id_brand'];
     $product['brand_code'] = $params['id_brand'] ? BrandQuery::create()->findByPK($product['id_brand'])->getName() : null;
     $product['productGroupCode'] = $productGroupCode = $product['id_product_group'] ? ProductGroupQuery::create()->findByPK($product['id_product_group'])->getCode() : null;
     $product['familyCode'] = $familyCode = $product['id_family'] ? FamilyQuery::create()->findByPK($product['id_family'])->getCode() : null;
     $product['subfamilyCode'] = $subfamilyCode = $product['id_subfamily'] ? SubfamilyQuery::create()->findByPK($product['id_subfamily'])->getCode() : "";
     $idNpd = $params['id_npd_sheet'];
     $pendingProduct = $params['pendingProduct'];
     if ($idNpd) {
         $npdSheet = NpdSheetQuery::create()->findByPKOrThrow($idNpd, $this->i18n->_("Npd with id {$idNpd} does no exist"));
         $npdSuppliersQuery = \Application\Query\NpdSheetSupplierQuery::create()->whereAdd(\Application\Model\Bean\NpdSheetSupplier::ID_NPD_SHEET, $idNpd);
         //obtiene el precio autorizado del npd
         $authorizedBudget = \Application\Query\SupplierBudgetQuery::create()->whereAdd(SupplierBudget::ID_NPD_SUPPLIER, $npdSuppliersQuery->fetchIds(), BaseQuery::IN)->whereAdd(SupplierBudget::IS_AUTHORIZED, 1)->findOne();
         //obtiene el supplier autorizado
         $authorizedSupplier = $npdSuppliersQuery->addColumn("NpdSheetSupplier.*")->whereAdd(\Application\Model\Bean\NpdSheetSupplier::ID_NPD_SUPPLIER, $authorizedBudget->getIdNpdSupplier())->findOne();
         if (SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $authorizedSupplier->getIdSupplier())->count()) {
             $supplier = SapSupplierQuery::create()->findByPK($authorizedSupplier->getIdSupplier());
         } else {
             $supplier = new SapSupplier();
         }
         $currency = CurrencyQuery::create()->whereAdd(Currency::CURRCODE, $npdSheet->getIdCurrency())->findOne();
         $product['id_npd_sheet'] = $npdSheet->getIdNpdSheet();
         if (!$this->getRequest()->isPost()) {
             $product['id_product_group'] = $npdSheet->getIdProductGroup();
             $product['id_family'] = $npdSheet->getIdFamily();
             $product['id_subfamily'] = $npdSheet->getIdSubfamily();
             $product['id_brand'] = $npdSheet->getIdBrand();
         }
         $product['target_price'] = $npdSheet->getPrice();
         $product['long_description'] = $npdSheet->getLongDescription();
         $pendingProduct ? $pendingProduct : ($npdProduct = true);
         $npdFileQuery = \Application\Query\FileQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheet.id_npd_sheet', $params["id_npd_sheet"])->whereAdd('File.Type', file::$typeFile["typeFile"])->findOne();
         if ($product['id_brand']) {
             $product['brand_code'] = BrandQuery::create()->findByPK($product['id_brand'])->getName();
         }
         if ($product['id_color']) {
             $product['colorCode'] = ColorQuery::create()->findByPK($product['id_color'])->getCode();
         }
         if ($npdFileQuery) {
             $filePath = $npdFileQuery->getContent();
             $idFile = $npdFileQuery->getIdFile();
         }
         $itemsQuery = \Application\Query\ColorQuery::create()->innerJoinNpdSheet()->whereAdd("Color2NpdSheet.id_npd_sheet", $idNpd)->find();
         $itemCode = $product['productGroupCode'] . $product['subfamilyCode'] . $product['familyCode'] . $product['key'] . $product['brand_code'];
         $i = 0;
         while ($item = $itemsQuery->read()) {
             $npdItem = NpdSheetItemQuery::create()->findByColor($item->getIdColor(), $npdSheet->getIndex());
             $items[$i]['idColor'] = $item->getIdColor();
             $items[$i]['colorCode'] = $item->getCode();
             $items[$i]['itemName'] = $npdItem ? $npdItem->getName() : $npdSheet->getName();
             $items[$i]['itemCode'] = $itemCode . $item->getCode();
             $items[$i]['vim'] = $npdItem ? $npdItem->getVim() : "";
             $items[$i]['idNpdSheetItem'] = $npdItem ? $npdItem->getIndex() : "";
             $i++;
         }
         if ($pendingProduct) {
             $controller = "product";
             $action = "create";
         } else {
             $controller = "npd-sheet";
             $action = "new-product";
         }
         $product['itemName'] = $npdSheet->getName();
     } else {
         $npSheet = new NpdSheet();
         $authorizedBudget = new SupplierBudget();
         $authorizedSupplier = new NpdSheetSupplier();
         $supplier = new Supplier();
         $currency = new Currency();
         $npdProduct = false;
         $controller = "product";
         $action = "create";
     }
     $this->view->npdSheetFile = $filePath;
     $this->view->product = $product;
     $this->view->incoterms = $this->getIncoterms();
     $this->view->years = $this->getLastYears();
     $this->view->brands = $this->getBrands();
     $this->view->countries = $this->getCountries();
     $this->view->currencies = $this->getCurrencies();
     $this->view->productGroups = $this->getProductGroup();
     $this->view->families = $this->getFamilies($product['id_product_group']);
     $this->view->subfamilies = $this->getSubFamilies($product['id_family']);
     $this->view->defaultShipping = $this->getDefaultShipping();
     $this->view->customsTariffCodes = $this->getCustomsTariffCode();
     $this->view->colors = $this->getColors();
     $this->view->status = $this->getStatus();
     $this->view->authorizedBudget = $authorizedBudget;
     $this->view->authorizedSupplier = $authorizedSupplier;
     $this->view->supplier = $supplier->toArray();
     $this->view->currency = $currency->getCurrCode();
     $this->view->contentTitle = $this->i18n->_('New Product');
     $this->view->edit = false;
     $this->view->new = "ok";
     $this->view->controller = $controller;
     $this->view->action = $action;
     $this->view->npdProduct = $npdProduct;
     $this->view->items = $items;
     $this->view->pendingProduct = $pendingProduct;
     $this->view->setTpl('Form');
 }
 /**
  * 
  * 
  * @author Erick Guevara Martínez
  * @param Currency $currency
  * @return \Application\Model\Collection\CondensedProgrammedPaymentCollection|boolean
  */
 public function filterByCurrency(Currency $currency)
 {
     return $this->filter(function (CondensedProgrammedPayment $condensedProgrammedPayment) use($currency) {
         return $condensedProgrammedPayment->getCurrency() == $currency->getCurrCode();
     });
 }