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))); } }
public function rateSupplier(SapSupplier $supplier) { $addresses = array(); $contactEmployees = array(); $sapSupplierAddresses = $supplier->getAddresses(); $sapSupplierContactEmployees = $supplier->getContacts(); while ($sapSupplierAddress = $sapSupplierAddresses->read()) { $addresses[] = self::createSapSupplierAddress($sapSupplierAddress); } while ($sapSupplierContactEmployee = $sapSupplierContactEmployees->read()) { $contactEmployees[] = self::createSapSupplierContactEmployee($sapSupplierContactEmployee); } $parameters['sapBusinessPartner'] = array("Cardcode" => $supplier->getCardcode(), "Cardname" => utf8_encode($supplier->getCardname()), "Currency" => $supplier->getCurrency(), "GroupNum" => $supplier->getGroupnum(), "GroupCode" => $supplier->getGroupCode(), "LicTradNum" => utf8_encode($supplier->getRfc()), "CmpRegistrationNumber" => 123, "concistency" => $supplier->getConsistency(), "idApprovalStatus" => $supplier->getIdApprovalStatus(), "idDefinedPort" => $supplier->getIdDefaultPort(), "idFinalGrandRisk" => $supplier->getIdFinalRisk(), "idPaymentTerms" => $supplier->getIdPaymentTerm(), "quality" => $supplier->getQuality(), "time" => $supplier->getTime(), "remarks" => utf8_encode($supplier->getNotes()), "paydays" => $supplier->getPayDays(), "typeCompany" => $supplier->getCmpPrivate(), "SupplierAddresses" => $addresses, "contactPersons" => $contactEmployees); $result = $this->soapClient->rateSupplier($parameters); return $result; }
/** * 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))); } }