/** * * @return array */ public function updateAction() { $params = $this->getRequest()->getParams(); //die("<pre>".print_r($params, true)."</pre>"); $baseProduct = ProductQuery::create()->findByPK($params['id']); $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, substr($params['id'], 0, 9), ProductQuery::LIKE)->find(); $brand = BrandQuery::create()->findByPKOrThrow($params["idBrand"], $this->i18n->_("The Brand with id {$params["idBrand"]} does not exist.")); if ($params["supplier_id"] != '') { $supplier = SapSupplierQuery::create()->findByPKOrThrow($params["supplier_id"], $this->i18n->_("The Supplier with id {$params["supplier_id"]} does not exist.")); } else { $supplier = new SapSupplier(); } $path = 'product/' . $params["keyMother"] . '/'; $savedFile = $this->saveFile('importationPermission', $path); if ($savedFile instanceof File) { $this->getFileCatalog()->beginTransaction(); try { $this->getFileCatalog()->create($savedFile); $this->getFileCatalog()->commit(); } catch (Exception $e) { $this->getFileCatalog()->rollBack(); throw new \InvalidArgumentException($this->i18n->_("The Import Permit File can't be saved.")); } } else { $savedFile = new File(); $savedFile->setIdFile(0); } $colors = ColorQuery::create()->find(); $test = 1; $responses = array(); foreach ($params["colors"] as $item) { $error = false; $new = false; if (!empty($item["idItem"])) { $itemcode = $item["idItem"]; $codPro = $params["keyMother"] . $brand->getName(); $color = new Color(); } else { $new = true; $color = $colors->getByPkOrElse($item["idColor"], new Color()); $itemcode = ($codPro = $baseProduct->getKeyMother() . $brand->getName()) . $color->getCode(); if (ProductGroupQuery::create()->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $params["idProductGroup"])->count()) { $productGroup = ProductGroupQuery::create()->findByPK($params["idProductGroup"]); } else { $error = true; $response[0] = false; $response[1] = $itemcode; $responses[] = $response; } if (FamilyQuery::create()->whereAdd(Family::ID_FAMILY, $params["IdCategory"])->count()) { $family = FamilyQuery::create()->findByPK($params["IdCategory"]); } else { $family = new Family(); $family->setName(0); $family->setIdFamily(0); } if (SubfamilyQuery::create()->whereAdd(Subfamily::ID_SUBFAMILY, $params['idSubfamily'])->count()) { $subfamily = SubfamilyQuery::create()->findByPK($params["idSubfamily"]); } else { $subfamily = new Subfamily(); $subfamily->setCode(0); } } if (!empty($params["goodTrough"])) { $date = new Zend_Date(strtolower($params["goodTrough"]), "MMM dd yyyy"); } if (!$error) { $productArray = array('CstGrpCode' => $params["idCustomsTariffCode"], 'FirmCode' => $brand->getCode(), 'U_Color' => $color->getCode(), 'U_Categoria' => 0, 'U_PCS_Id_Categoria' => 0, 'ItmsGrpCod' => 0, 'U_Id_Familia' => 0, 'U_Familia' => 0, 'U_id_subcategoria' => 0, 'U_PCS_Impor_per_id' => $savedFile ? $savedFile->getIdFile() : $products->current()->getImportPermit(), 'CardCode' => $supplier->getCardCode(), 'U_PCSid_npd_sheet' => $params["idNpd"] > 0 ? $params["idNpd"] : -1, 'ItemCode' => $itemcode, 'ItemName' => $item["itemName"], 'SWW' => $item["status"], 'Invntitem' => 1, 'PrchseItem' => 1, 'U_id_marca' => $brand->getName(), 'U_Marca' => $brand->getName(), 'SellItem' => 1, 'U_Madre_09' => $params["keyMother"], 'U_CODPRO' => $codPro, 'BuyUnitMsr' => "PZA", 'NumInBuy' => 1, 'SalUnitMsr' => "PZA", 'NumInSale' => 1, 'InvntryUom' => "PZA", 'U_MCFrente' => $params["mcFront"], 'U_MCAltura' => $params["mcHeight"], 'U_MCProfundida' => $params["mcDepth"], 'U_MCPeso' => $params["mcWeight"], 'U_PzasXCaja' => $params["mcParts"], 'U_PCS_Pieces_per_inn' => $params["piecesPerInner"], 'U_pzafrente' => $params["pzaFront"], 'U_pzaaltura' => $params["pzaHeight"], 'U_pzaprofu' => $params["pzaDepth"], 'U_PesoxPza' => $params["pzaWeight"], 'U_pzadiametro' => $params["pzaDiameter"], 'U_PCS_Individual_Pac' => $params["individualPackage"], 'U_PCS_Packing_Front' => $params["packingFront"], 'U_PCS_Packing_Height' => $params["packingHeight"], 'U_PCS_Packing_Depth' => $params["packingDepth"], 'U_PCS_Packing_Weight' => $params["packingWeight"], 'U_PCS_Packing_Diamet' => $params["packingDiameter"], 'U_PCS_Def_Freight_Fa' => $params["defaultFreightFare"], 'U_PCS_Important' => $params["important"] ? 1 : 0, 'U_PCS_Rescue' => $params["rescue"] ? 1 : 0, 'U_PCS_VIM' => $params["vim"], 'U_PCS_Individual_VIM' => $item["vim"], 'U_PCS_import_permit' => $params["remarks"], 'U_PCS_Put_trougth' => $date instanceof Zend_Date ? $date->get("yyyy-MM-dd") : "", 'U_PCS_Catalog_Year' => $params["catalogYear"], 'LeadTime' => $params["lead_time"], 'U_PCS_id_incoterm' => $params["incoterm"], 'U_PCS_manual_restock' => $params["manual_restock"] ? 1 : 0, 'Price' => $params["price"], 'Currency' => $params["currency"], 'U_ShortName' => $params['U_ShortName']); if ($new) { $productArray['U_Categoria'] = $family->getName(); $productArray['U_PCS_Id_Categoria'] = $family->getIdFamily(); $productArray['ItmsGrpCod'] = $productGroup->getIdProductGroup(); $productArray['U_Id_Familia'] = $productGroup->getCode(); $productArray['U_Familia'] = $productGroup->getName(); $productArray['U_id_subcategoria'] = $subfamily->getCode(); } if ($products->containsIndex($itemcode)) { $product = $products->getByPK($itemcode); ProductFactory::populate($product, $productArray); } else { $product = ProductFactory::createFromArray($productArray); } $test++; $products->append($product); } } // die("<pre>".print_r($products, true)."</pre>"); $SAPProductManager = new SapProductSaveManager(); $responses += $SAPProductManager->save($products, $this->getUser()->getBean()); foreach ($responses as $response) { if ($response[0] == 200) { $success .= "<br>" . $this->i18n->_("The Product with id {$response[1]} was updated correctly."); } else { $error .= "<br>" . $this->i18n->_("The Product with id {$response[1]} can't be updated."); } } if (strlen($success) > 0) { $this->setFlash('ok', $success); } if (strlen($error) > 0) { $this->setFlash('error', $error); } $this->_redirect('product/list'); }
public function zoomInAction() { if ($this->getRequest()->isPost()) { $keyMother = $this->getRequest()->getParam("key_mother"); $itemCode = $this->getRequest()->getParam("item_code"); $products = ProductQuery::create()->find(); $keyMotherProducts = $products->filterByKeyMother($keyMother); $restock = RestockQuery::create()->findOne(); $allRestockEntries = RestockEntryQuery::create()->find(); $restockEntries = $allRestockEntries->filterByArrayIdProduct($keyMotherProducts->getPrimaryKeys()); $freightTypes = FreightTypeQuery::create()->actives()->find(); $restockFinalResultsManager = new RestockFinalResultsManager($allRestockEntries, $products); $product = $products->getByPK($itemCode); $restockAbcClass = RestockAbcClassQuery::create()->find(); $freightFares = FreightFareQuery::create()->find(); $freightFare = $freightFares->getByPK($product->getDefaultFreightFare()); $fobPort = PortCustomQuery::create()->findByPKOrElse($freightFare->getFobPort(), new PortCustom()); $fobPortFreightFares = $freightFares->filterByFobPort($fobPort); $freightTypeList = $freightTypes->containsIndex($freightFare->getIdFreightType()) ? $freightTypes->getByPK($freightFare->getIdFreightType()) : new FreightType(); if ($product->getIdSupplier() != "") { $supplier = SapSupplierQuery::create()->findByPK($product->getIdSupplier()); } else { $supplier = new SapSupplier(); } $keyMotherInfo["keyMother"] = $product->getKeyMother(); $keyMotherInfo["PurchaseKeyMother"] = $restockFinalResultsManager->getTotalPurchaseByKeyMother($keyMother); $keyMotherInfo["catalog"] = $product->getCodPro(); $keyMotherInfo["port"] = $fobPort->getName(); $keyMotherInfo["freightList"] = $freightTypeList->getName(); $keyMotherInfo["supplier"] = $supplier->getCardCode() . " - " . $supplier->getCardname(); $keyMotherInfo["supplierPurchase"] = $restockFinalResultsManager->getTotalPurchaseByIdSupplier($supplier->getIdSupplier()); $keyMotherInfo["fobPortPurchase"] = $restockFinalResultsManager->getTotalByIdFreigthFare($fobPortFreightFares->getPrimaryKeys()); while ($restockEntries->valid()) { $restockEntry = $restockEntries->read(); $product = $products->getByPK($restockEntry->getIdProduct()); $restockInfo[$restockEntry->getIndex()]["idRestockEntry"] = $restockEntry->getIdRestockEntry(); $restockInfo[$restockEntry->getIndex()]["mcParts"] = $product->getMcParts(); $restockInfo[$restockEntry->getIndex()]["volume"] = $product->getVolume(); $restockInfo[$restockEntry->getIndex()]["status"] = $product->getStatus(); $restockInfo[$restockEntry->getIndex()]["itemCode"] = $product->getItemCode(); $restockInfo[$restockEntry->getIndex()]["name"] = $product->getItemName(); $restockInfo[$restockEntry->getIndex()]["onStock"] = $restockEntry->getInvRelat(); $restockInfo[$restockEntry->getIndex()]["VIM"] = $product->getIndividualVim(); $restockInfo[$restockEntry->getIndex()]["VIMMin"] = $restockEntry->getVimMin(); $restockInfo[$restockEntry->getIndex()]["VIMMax"] = $restockEntry->getVimMax(); $restockInfo[$restockEntry->getIndex()]["newQuantityMin"] = $restockEntry->getNewQuantityMin(); $restockInfo[$restockEntry->getIndex()]["newImportMin"] = $restockEntry->getPriceMin(); $restockInfo[$restockEntry->getIndex()]["newQuantityMax"] = $restockEntry->getNewQuantityMax(); $restockInfo[$restockEntry->getIndex()]["newImportMax"] = $restockEntry->getPriceMax(); $restockInfo[$restockEntry->getIndex()]["coverMin"] = $restockEntry->getMinCoverPercent(); $restockInfo[$restockEntry->getIndex()]["coverMax"] = $restockEntry->getMaxCoverPercent(); $restockInfo[$restockEntry->getIndex()]["ABCMin"] = $restockAbcClass->getByPK($restockEntry->getAbcMix())->getName(); $restockInfo[$restockEntry->getIndex()]["desition"] = $restockEntry->getDesitionName(); $restockInfo[$restockEntry->getIndex()]["lastFOB"] = $product->getCost(); $restockInfo[$restockEntry->getIndex()]["targetFOB"] = $restockEntry->getMinTargetPrice(); $restockInfo[$restockEntry->getIndex()]["quantityPurchase"] = $restockEntry->getPurchaseQuantity(); $restockInfo[$restockEntry->getIndex()]["importPurchase"] = $restockEntry->getPurchasePrice(); $restockInfo[$restockEntry->getIndex()]["quantityPercent"] = $restockEntry->getPurchaseQuantityPercernt(); $restockInfo[$restockEntry->getIndex()]["importPercent"] = $restockEntry->getPurchasePricePercent(); $restockInfo[$restockEntry->getIndex()]["quantitySetted"] = $restockEntry->getQuantity(); $restockInfo[$restockEntry->getIndex()]["purchaseSetted"] = $restockFinalResultsManager->getTotalCartonsByIdRestockEntry($restockEntry->getIdRestockEntry()); $restockInfo[$restockEntry->getIndex()]["importPurchaseSetted"] = $restockFinalResultsManager->getPurchaseSettedByIdRestockEntry($restockEntry->getIdRestockEntry()); $restockInfo[$restockEntry->getIndex()]["isManual"] = $product->isManual(); $restockInfo[$restockEntry->getIndex()]["cbm"] = $totalVolume = $restockFinalResultsManager->getTotalVolumeByIdRestockEntry($restockEntry->getIdRestockEntry()); $restockInfo[$restockEntry->getIndex()]["suggestedFreight"] = implode(" / ", $freightTypes->getSuggestedFreights($totalVolume)->toCombo()); $restockInfo[$restockEntry->getIndex()]["checked"] = $restockEntry->getChecked(); } $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_PRODUCT, $keyMotherProducts->getPrimaryKeys(), RequisitionEntryQuery::IN)->whereAdd(RequisitionEntry::STATUS, array(RequisitionEntry::$Status["Closed"], RequisitionEntry::$Status["Canceled"], RequisitionEntry::$Status["Inactive"]), RequisitionEntryQuery::NOT_IN)->find()->toArrayForZoomIn(); $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PRODUCT, $keyMotherProducts->getPrimaryKeys(), ProformaInvoiceEntryQuery::IN)->whereAdd(ProformaInvoiceEntry::LINE_STATUS, ProformaInvoiceEntry::$LineStatus["Open"])->find()->toArrayForZoomIn(); $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PRODUCT, $keyMotherProducts->getPrimaryKeys(), PurchaseOrderEntryQuery::IN)->whereAdd(PurchaseOrderEntry::LINE_STATUS, PurchaseOrderEntry::$LineStatus["Open"])->find()->toArrayForZoomIn(); $documents = array_merge(array_merge($requisitionEntries, $proformaInvoiceEntries), $purchaseOrderEntries); $currencies = CurrencyQuery::create()->find()->toArray(); die(Zend_Json::encode(array("keyMother" => $keyMotherInfo, "restock" => $restockInfo, "documents" => $documents, "currecies" => $currencies))); } }
/** * * * @author Erick Guevara Martínez * @param SapSupplier $sapSupplier * @return \Application\Model\Collection\CondensedProgrammedPaymentCollection|boolean */ public function filterBySapSupplier(SapSupplier $sapSupplier) { return $this->filter(function (CondensedProgrammedPayment $condensedProgrammedPayment) use($sapSupplier) { return $condensedProgrammedPayment->getIdSupplier() == $sapSupplier->getCardCode(); }); }
/** * This function prepare all info to can save a proforma invoice * * @author Erick Guevara Martinez * @return Json */ public function consolidateEntriesAction() { if ($this->getRequest()->isPost()) { // Get the id entries to consolidate in a proforma invoice $idRequisitionEntries = $this->getRequest()->getParam("idEntries", array()); // Set the consolidate status in true (This will help us see if the consolidation is ok or fail) $success = true; // Search all currencies to get your codes, ids and symbols $currencies = CurrencyQuery::create()->find(); // If the entries greater than zero then continue if (count($idRequisitionEntries) > 0) { // Search the requisition Entries to will consolidate $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $idRequisitionEntries, RequisitionEntryQuery::IN)->find(); // If the requisition entries are found then continue if ($requisitionEntries->count() > 0) { // Search the requisition entries products $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $requisitionEntries->getDistinctProducts(), ProductQuery::IN)->find(); // Get the id destination country (all requisition entries must have the same id country) $idDestinationCountry = RequisitionQuery::create()->findByPK($requisitionEntries->current()->getIdRequisition())->getIdDestinationCountry(); // Search the destination country $country = CountryQuery::create()->findByPK($idDestinationCountry); $countryLocations = WarehouseStoreQuery::create()->addColumns(array(WarehouseStore::LOCATION))->distinct()->whereAdd(WarehouseStore::COUNTRY, $idDestinationCountry)->fetchCol(); $locations = WarehouseQuery::create()->whereAdd(WareHouse::CODE, $countryLocations, WarehouseQuery::IN)->find()->toCombo($this->i18n->_("Select a Warehouse")); $warehouseStores = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::LOCATION, Warehouse::$defaultLocation)->whereAdd(WarehouseStore::TYPE, WarehouseStore::$Type["ppv"])->find()->toCombo($this->i18n->_("Select a Warehouse Store")); // Check if the selected requisition entries have budgets autorized (one by key mother only) $budgets = KeyMotherSupplierBudgetQuery::create()->innerJoinRequisitionEntry()->whereAdd("RequisitionEntry." . RequisitionEntry::ID_REQUISITION_ENTRY, $requisitionEntries->getPrimaryKeys(), BaseQuery::IN)->actives()->autorized()->find(); $defaultCurrency = !$budgets->isEmpty() ? $budgets->current()->getIdCurrency() : ""; $currencies = CurrencyQuery::create()->find(); // Get the products key mother to group by key mother $parentKeys = $products->getKeyMother(); $exhangeRateConversor = new ExchangeRateConversorManager(); // Proccess the info searched to get the ajax response foreach ($parentKeys as $parentKey) { // Filter the products by key mother to consolide the entries by product $parentKeyProducts = $products->filterByKeyMother($parentKey); // Filter the requisition entries by product $parentKeyRequisitionEntries = $requisitionEntries->filterByIdProduct($parentKeyProducts->getPrimaryKeys()); // Get the currency of key mother (all the requisition entries must have the same currency) $parentKeyCurrency = $currencies->getByPK($parentKeyRequisitionEntries->current()->getIdCurrency()); // Get the specific data to create the proforma invoice $response[$parentKey]["parentKey"] = $parentKey; // Get the budgets of the current key mother $KeyMotherBudget = $budgets->filterByKeyMother($parentKey); // One budget autorized only by key mother // If key mother have a autorized budget the set the budget info if ($KeyMotherBudget->count() == 1) { // Set the budget min price $originalMinPrice = $minPrice = $KeyMotherBudget->current()->getPrice(); // Set the id budget $response[$parentKey]["idBudget"] = $KeyMotherBudget->current()->getIdKeyMotherSupplierBudget(); // Set the currency budget $originalCurrency = $currency = $currencies->getByPkOrEmpty($KeyMotherBudget->current()->getIdCurrency()); // Search the supplier to autoselect him $supplier = SapSupplierQuery::create()->findByPKOrThrow($KeyMotherBudget->current()->getIdSupplier(), $this->i18n->_("The Supplier with CardCode {$KeyMotherBudget->current()->getIdSupplier()} does not exist.")); // Set the pieces quantity in the budget $totalAmount = $KeyMotherBudget->current()->getQuantity(); // if does not have a autorized budget then compare the min price and set the id budget to empty } else { // Check if the min open price and the target price and return the less to define the max price can be the products of this key mother if ($parentKeyProducts->current()->getCost() > 0) { $originalMinPrice = $parentKeyRequisitionEntries->getMinOpenPrice() < $parentKeyProducts->current()->getCost() ? $parentKeyRequisitionEntries->getMinOpenPrice() : $parentKeyProducts->current()->getCost(); } else { $originalMinPrice = $parentKeyRequisitionEntries->getMinOpenPrice(); } $minPrice = $originalMinPrice; $currency = $originalCurrency = $currencies->getByPkOrEmpty($parentKeyCurrency->getCurrCode()); $supplier = new Supplier(); // If exist a defaultCurrency then convert all min prices to exchange rate default currency if ($defaultCurrency != "") { $minPrice = $exhangeRateConversor->converter($originalCurrency->getCurrCode(), $defaultCurrency, $originalMinPrice); $currency = $currencies->getByPkOrEmpty($defaultCurrency); } $response[$parentKey]["idBudget"] = ""; $totalAmount = $parentKeyRequisitionEntries->getTotalQuantity(); $supplier = new SapSupplier(); } $response[$parentKey]["minPrice"] = $minPrice; $response[$parentKey]["originalMinPrice"] = $originalMinPrice; $response[$parentKey]["totalAmount"] = $totalAmount; $response[$parentKey]["originalCurrency"] = $originalCurrency->getCurrCode(); $response[$parentKey]["currency"] = $currency->getCurrCode(); $response[$parentKey]["currencyCode"] = $currency->getCurrCode(); $response[$parentKey]["currencySymbol"] = str_replace("€", "€", $currency->getDocCurrCode()); // Group the requisitoion entry info by product to get the total by product while ($parentKeyProduct = $parentKeyProducts->read()) { $productRequisitionEntries = $parentKeyRequisitionEntries->filterByIdProduct($parentKeyProduct->getItemCode()); $response[$parentKey]["products"][$parentKeyProduct->getItemCode()]["productKey"] = $parentKeyProduct->getItemCode(); $response[$parentKey]["products"][$parentKeyProduct->getItemCode()]["description"] = $parentKeyProduct->getItemName(); $response[$parentKey]["products"][$parentKeyProduct->getItemCode()]["totalAmount"] = $productRequisitionEntries->getTotalQuantity(); // Need the ids of requisition entries to create the proforma invoice and make a link to requisition $response[$parentKey]["products"][$parentKeyProduct->getItemCode()]["requisitionEntries"] = $productRequisitionEntries->getPrimaryKeys(); } } // If the requisition entries not found then the consolidation fail } else { $success = false; } // if does not have id requisition entries the consolidation fail } else { $success = false; } die(Zend_Json::encode(array("success" => $success, "parentKeys" => $response, "idDestinationCountry" => $country->getCode(), "destinationCountryName" => utf8_encode($country->getName()), "supplierName" => $supplier->getCardCode() . "-" . utf8_encode($supplier->getCardname()), "supplierId" => $supplier->getCardCode(), "defaultCurrency" => $defaultCurrency, "warehouses" => $locations, "warehouseStores" => $warehouseStores, "defaultWarehouse" => Warehouse::$defaultLocation, "defaultWarehouseStore" => WarehouseStore::$defaultWarehouseStore))); } }