/** * * @return array */ public function editAction() { $params = $this->getRequest()->getParams(); $id = $this->view->id = $params['id']; $portQuery = PortCustomQuery::create()->addColumn(PortCustom::NAME)->actives()->fetchAll(); $warehouseQuery = WarehouseQuery::create()->addColumn(Warehouse::NAME)->actives()->fetchAll(); $transportCount = TransportQuery::create()->whereAdd(Transport::ID_BOOKING, $id)->count(); $transportQuery = TransportQuery::create()->whereAdd(Transport::ID_BOOKING, $id)->fetchAll(); foreach ($portQuery as $port) { $ports[$port['name']] = $port['name']; } foreach ($warehouseQuery as $warehouse) { $warehouses[$warehouse['name']] = $warehouse['name']; } $places[''] = $this->i18n->_('Select a source'); $places[$this->i18n->_('Ports')] = $ports; $places[$this->i18n->_('Warehouses')] = $warehouses; $this->view->sources = $places; $places[''] = $this->i18n->_('Select a destination'); $this->view->destinations = $places; $this->view->transportCount = $transportCount; $this->view->transports = $transportQuery; $this->view->contentTitle = "New Transportation"; $this->view->onSubmit = 'update'; $this->view->setTpl('Form'); }
/** * * @return array */ public function listAction() { $this->view->page = $page = $this->getRequest()->getParam('page') ?: 1; if ($this->getRequest()->isPost()) { $this->view->post = $post = $this->getRequest()->getParams(); } $total = PurchaseOrderEntryQuery::create()->filter($post)->count(); $this->view->purchaseOrderEntries = $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->filter($post)->page($page, $this->getMaxPerPage())->find(); $this->view->paginator = $this->createPaginator($total, $page); $this->view->purchaseOrders = \Application\Query\PurchaseOrderQuery::create()->find()->toCombo(); $this->view->products = \Application\Query\ProductQuery::create()->find()->toCombo(); $this->view->warehouses = \Application\Query\WarehouseQuery::create()->find()->toCombo(); }
/** * */ public function detailsAction() { $params = $this->getRequest()->getParams(); $id = $params['id']; $this->view->contentTitle = $this->i18n->_('Folio Import Details'); $folioImport = FolioImportQuery::create()->findByPK($id)->toArray(); $typeIncome = array_flip(Folioimport::$TypeIncome); $folioImport['type_income'] = $typeIncome[$folioImport['type_income']]; $preInspected = array_flip(FolioImport::$PreInspected); $folioImport['pre_inspected'] = $preInspected[$folioImport['pre_inspected']]; $folioImport['status'] = $this->getStatus($folioImport['status']); $folioImport['forwarder'] = ForwarderQuery::create()->findByPK($folioImport['id_forwarder'])->getName(); $folioImport['departure_port'] = PortCustomQuery::create()->findByPK($folioImport['id_port_custom'])->getName(); $folioImport['destination_port'] = PortCustomQuery::create()->findByPK($folioImport['id_port_destination'])->getName(); if (!$folioImport['id_customs_broker'] == Null) { $folioImport['customs_broker'] = CustomsBrokerQuery::create()->findByPK($folioImport['id_customs_broker'])->getName(); } $folioImport['warehouse'] = WarehouseQuery::create()->findByPK($folioImport['id_warehouse'])->getName(); $folioImport['purchase_orders'] = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->count(); $folioImportFreightFareQuery = FolioImportFreightFareQuery::create()->addColumn(FreightFare::ID_FREIGHT_FARE)->whereAdd(FolioImportFreightFare::ID_FOLIO_IMPORT, $id); $freightFareQuery = FreightFareQuery::create()->addColumn('FreightType.' . FreightType::NAME)->addColumn('FreightFare.' . FreightFare::ID_FREIGHT_FARE)->addColumn('FreightFare.' . FreightFare::UNIT_COST)->whereAdd(FreightFare::ID_FREIGHT_FARE, $folioImportFreightFareQuery, FreightFareQuery::IN)->innerJoinFreightType()->fetchAll(); $i = 0; $total = 0; $folioImport['containers'] = '<ul>'; foreach ($freightFareQuery as $freightFare) { $quantity = FolioImportFreightFareQuery::create()->addColumn(FolioImportFreightFare::QUANTITY)->whereAdd(FolioImportFreightFare::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFreightFare::ID_FREIGHT_FARE, $freightFare['id_freight_fare'])->fetchOne(); $freightFareQuery[$i]['quantity'] = $quantity; $total += $quantity * $freightFare['unit_cost']; if ($quantity != 0) { $folioImport['containers'] .= '<li>' . $freightFare['name'] . ' (' . $quantity . ')</li>'; } $i++; } $folioImport['containers'] .= '</ul>'; $folioImport['containers_cost'] = number_format($total, 2); if ($folioImport['customs_broker'] == '') { $folioImport['customs_broker'] = $this->i18n->_('Not Defined'); } $documentType = FolioImportFile::$DocumentType; $transitLetter = FolioImportFileQuery::create()->whereAdd(FolioImportFile::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFile::DOCUMENT_TYPE, $documentType['TransitLetter'])->count(); if ($transitLetter) { $transitLetter = FolioImportFileQuery::create()->whereAdd(FolioImportFile::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFile::DOCUMENT_TYPE, $documentType['TransitLetter'])->findOne()->getContent(); $folioImport['transit_letter'] = basename($transitLetter); } $noMarketingLetter = FolioImportFileQuery::create()->whereAdd(FolioImportFile::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFile::DOCUMENT_TYPE, $documentType['NoMarketingLetter'])->count(); if ($noMarketingLetter) { $noMarketingLetter = FolioImportFileQuery::create()->whereAdd(FolioImportFile::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFile::DOCUMENT_TYPE, $documentType['NoMarketingLetter'])->findOne()->getContent(); $folioImport['no_marketing_letter'] = basename($noMarketingLetter); } $proxy = FolioImportFileQuery::create()->whereAdd(FolioImportFile::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFile::DOCUMENT_TYPE, $documentType['Proxy'])->count(); if ($proxy) { $proxy = FolioImportFileQuery::create()->whereAdd(FolioImportFile::ID_FOLIO_IMPORT, $id)->whereAdd(FolioImportFile::DOCUMENT_TYPE, $documentType['Proxy'])->findOne()->getContent(); $folioImport['proxy'] = basename($proxy); } $idBooking = $this->getIdBooking($id); if ($idBooking) { $this->view->booking = $this->getBooking($idBooking); $folioImport['id_booking'] = $idBooking; $this->view->itinerary = $this->getItinerary($idBooking)->toArray(); } // if($folioImport['status']!='Inspected'){ $purchaseOrders = $this->getPurchaseOrders($id, $status, false); if ($purchaseOrders != null) { // $purchaseOrderFolioQuery = PurchaseOrderFolioQuery::create()->addColumn(PurchaseOrderFolio::ID_PURCHASE_ORDER)->whereAdd(PurchaseOrderFolio::ID_FOLIO_IMPORT, $id); $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->find(); $this->view->purchaseOrders = $this->getPurchaseOrdersWithEntries($purchaseOrderQuery); } // }else{ // //Traer las warehouse Entrances // } // $warehouseEntries = $this->getWarehouseEntries($id); // if($warehouseEntries != null){ // $this->view->warehouseEntries = $warehouseEntries; // } $idBooking = $this->getIdBooking($id); $this->view->purchaseOrdersSelectable = false; $this->view->folioImport = $folioImport; $this->view->setTpl('Details'); }
/** * * @return array */ public function editAction() { try { $id = $this->getRequest()->getParam('id'); $this->view->proformaInvoice = $proformaInvoice = ProformaInvoiceQuery::create()->findByPKOrThrow($id, $this->i18n->_("ProformaInvoice with id {$id} not found")); $accessRole = $this->getUser()->getAccessRole(); $accessRoleManager = new AccessRoleManager(); $suppliers = $accessRoleManager->getAssociateSuppliers($accessRole); if (!$suppliers->containsIndex($proformaInvoice->getIdSupplier())) { throw new ProformaInvoiceException($this->i18n->_("You don't have permission to edit this Proforma Invoice.")); } $this->view->proformaInvoiceEntries = $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find(); $this->view->locations = WarehouseQuery::create()->find()->toCombo($this->i18n->_("Select Warehouse Location")); if (!$proformaInvoiceEntries->isEmpty()) { $this->view->warehouseStore = $warehouseStore = WarehouseStoreQuery::create()->findByPKOrThrow($proformaInvoiceEntries->current()->getIdWarehouseStore(), $this->i18n->_("WarehouseStore with id {$proformaInvoiceEntries->current()->getIdWarehouseStore()} not found")); $this->view->warehouseStores = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::LOCATION, $warehouseStore->getLocation())->find()->toCombo($this->i18n->_("Select Warehouse Store")); $this->view->products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $proformaInvoiceEntries->getIdProducts(), ProductQuery::IN)->find(); } else { $this->view->warehouseStore = new Warehouse(); $this->view->warehouseStores = array("" => $this->i18n->_("Select Warehouse Store")); } $this->view->forwarders = array("" => $this->i18n->_("Select Forwarder")) + ForwarderQuery::create()->find()->toCombo(); if ($proformaInvoice->getIdCourtyard() > 0) { $this->view->courtyard = $courtyard = CourtyardQuery::create()->findByPKOrThrow($proformaInvoice->getIdCourtyard(), $this->i18n->_("Courtyard with id {$proformaInvoice->getIdCourtyard()} not found")); $this->view->portsCustom = array("" => $this->i18n->_("Select Port Custom")) + PortCustomQuery::create()->innerJoinForwarder()->whereAdd("Forwarder." . Forwarder::ID_FORWARDER, $courtyard->getIdForwarder())->find()->toCombo(); $this->view->courtyards = array("" => $this->i18n->_("Select Courtyard")) + CourtyardQuery::create()->whereAdd(Courtyard::ID_PORT_CUSTOM, $courtyard->getIdPortCustom())->whereAdd(Courtyard::ID_FORWARDER, $courtyard->getIdForwarder())->find()->toCombo(); } else { $this->view->courtyard = new Courtyard(); $this->view->portCustoms = array("" => $this->i18n->_("Select Port Custom")); $this->view->courtyards = array("" => $this->i18n->_("Select Courtyard")); } $this->view->currencies = CurrencyQuery::create()->find(); $this->view->events = EventQuery::create()->find(); $paymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find(); $proformaInvoiceProgrammedPayment = ProformaInvoiceProgrammedPaymentQuery::create()->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find(); $purchaseOrderProgrammedPayment = PurchaseOrderProgrammedPaymentQuery::create()->whereAdd(PurchaseOrderProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM, $paymentTerms->getPrimaryKeys()); $this->view->proformaInvoiceProgrammedPayment = $proformaInvoiceProgrammedPayment; $this->view->purchaseOrderProgrammedPayment = $purchaseOrderProgrammedPayment; $this->view->paymentTerms = $paymentTerms; $this->view->contentTitle = $this->i18n->_("Edit Proforma Invoice DocNum ") . $proformaInvoice->getSapDocumentNumber(); $this->view->setTpl("Edit"); } catch (Exception $e) { $this->setFlash('error', $this->i18n->_($e->getMessage())); $this->_redirect('proforma-invoice/list'); } }
/** * @author Jose Luis Suarez Nieto * @return array */ private function getWarehouses() { $myWarehouseQuery = WarehouseQuery::create()->actives()->find()->toArray(); $warehouses[''] = $this->i18n->_('Select a Warehouse'); foreach ($myWarehouseQuery as $warehouse) { $id = $warehouse['id_warehouse']; $warehouses[$id] = $warehouse['name']; } return $warehouses; }
public function exportToExcelAction() { $params = $this->getRequest()->getParams(); $allPurchaseOrderEntries = PurchaseOrderEntryQuery::create()->find(); $purchaseOrders = PurchaseOrderQuery::create()->filter($params)->addDescendingOrderBy(PurchaseOrder::PURCHASE_ORDER_DATE)->whereAdd("PurchaseOrder.DocType", "I")->whereAdd("PurchaseOrderEntry.ItemCode", "TR%", 'NOT LIKE')->whereAdd("PurchaseOrderEntry.WhsCode", "9999", PurchaseOrderQuery::NOT_LIKE)->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $allPurchaseOrderEntries->getDistinctPurchaseOrder(), PurchaseOrderQuery::IN)->find(); $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $allPurchaseOrderEntries->getProducts(), ProductQuery::IN)->find(); $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $purchaseOrders->getDistinctSuppliers(), SapSupplierQuery::IN)->find(); $warehousesStores = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::CODE, $allPurchaseOrderEntries->getDistinctIdWarehouseStore(), WarehouseStoreQuery::IN)->find(); $warehouses = WarehouseQuery::create()->whereAdd(Warehouse::CODE, $warehousesStores->getDistinctWarehouses(), WarehouseQuery::IN)->find(); $currencies = CurrencyQuery::create()->find(); $countries = CountryQuery::create()->find(); require_once 'PHPExcel.php'; $objPHPExcel = new PHPExcel(); $activeSheet = $objPHPExcel->setActiveSheetIndex(0); $activeSheet->setCellValue('A1', $this->i18n->_('Purchase Order Folio'))->setCellValue('B1', $this->i18n->_('Destination Country'))->setCellValue('C1', $this->i18n->_('Supplier Code'))->setCellValue('D1', $this->i18n->_('Supplier Name'))->setCellValue('E1', $this->i18n->_('Creation Date'))->setCellValue('F1', $this->i18n->_('Status'))->setCellValue('G1', $this->i18n->_('Entry Line'))->setCellValue('H1', $this->i18n->_('Product Code'))->setCellValue('I1', $this->i18n->_('Product Description'))->setCellValue('J1', $this->i18n->_('Amount'))->setCellValue('K1', $this->i18n->_('Price'))->setCellValue('L1', $this->i18n->_('Import'))->setCellValue('M1', $this->i18n->_('Currency'))->setCellValue('N1', $this->i18n->_('Location'))->setCellValue('O1', $this->i18n->_('Warehouse')); $activeSheet->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $i = 2; while ($purchaseOrders->valid()) { $purchaseOrder = $purchaseOrders->read(); $currency = $currencies->getByPkOrEmpty($purchaseOrder->getIdCurrency()); $supplier = $suppliers->getByPkOrElse($purchaseOrder->getIdSupplier(), new SapSupplier()); $country = $countries->getByPK($purchaseOrder->getIdDestinationCountry()); $purchaseOrderEntries = $allPurchaseOrderEntries->filterByPurchaseOrderPk($purchaseOrder->getIdPurchaseOrder()); $entriesCount = $i; while ($purchaseOrderEntries->valid()) { $purchaseOrderEntry = $purchaseOrderEntries->read(); $product = $products->getByPK($purchaseOrderEntry->getIdProduct()) ? $products->getByPK($purchaseOrderEntry->getIdProduct()) : new Product(); $warehouseStore = $warehousesStores->getByPkOrElse($purchaseOrderEntry->getIdWarehouseStore(), new WarehouseStore()); $warehouse = $warehouseStore->getLocation() > 0 ? $warehouses->getByPK($warehouseStore->getLocation()) : new WarehouseStore(); $activeSheet->setCellValue('A' . $entriesCount, $purchaseOrder->getSapDocumentNumber())->setCellValue('B' . $entriesCount, utf8_encode($country->getName()))->setCellValue('C' . $entriesCount, $supplier->getCardCode())->setCellValue('D' . $entriesCount, $supplier->getCardname())->setCellValue('E' . $entriesCount, $purchaseOrder->getPurchaseOrderDate())->setCellValue('F' . $entriesCount, $purchaseOrder->getStatusName())->setCellValue("G" . $entriesCount, $purchaseOrderEntry->getLine())->setCellValue("H" . $entriesCount, $product->getItemCode())->setCellValue("I" . $entriesCount, $product->getItemName())->setCellValue("J" . $entriesCount, $purchaseOrderEntry->getAmount())->setCellValue("K" . $entriesCount, $purchaseOrderEntry->getPrice())->setCellValue("L" . $entriesCount, $purchaseOrderEntry->getImport())->setCellValue("M" . $entriesCount, $currency->getCurrCode())->setCellValue("N" . $entriesCount, $warehouse->getName())->setCellValue("O" . $entriesCount, $warehouseStore->getName()); $entriesCount++; } $i = $entriesCount; } $columns = range('A', 'O'); foreach ($columns as $column) { $activeSheet->getColumnDimension($column)->setAutoSize(true); } header("Content-Type: application/vnd.ms-excel"); $date = \Zend_Date::now(); $fileName = $this->i18n->_("Purchase_orders_report") . $date->get("ddMMyyyy"); header("Content-Disposition: attachment; filename=\"{$fileName}.xlsx\""); header("Cache-Control: max-age=0"); $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save("php://output"); exit; }
public function getListResultsAction() { $params = $this->getRequest()->getParams(); $warehouses = WarehouseQuery::create()->filter($params)->findByPage($params['page'], $this->getMaxPerPage()); while ($warehouse = $warehouses->read()) { $warehouse->setName(utf8_encode($warehouse->getName())); } die(json_encode($warehouses->toArray())); }
/** * * Gets all WareHouses from SAP, searches the DB for the WarehouseCode, then updates or creates */ public function syncWarehousesAction() { $r = SapWarehouseQuery::create()->find(); echo "<pre>"; $errors = 0; $new = 0; $updated = 0; while ($r->valid()) { $save = 0; $sapWarehouse = $r->read(); echo "Name: " . $sapWarehouse->getWhsName() . " Code: " . $sapWarehouse->getWhscode() . "\n"; $warehouseStore = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::CODE, $sapWarehouse->getWhscode(), WarehouseStoreQuery::EQUAL)->findOne(); if (!$warehouseStore instanceof WarehouseStore) { $warehouseStore = new WarehouseStore(); $save = 1; } $warehouse = WarehouseQuery::create()->whereAdd(Warehouse::CODE, $sapWarehouse->getLocation(), WarehouseQuery::EQUAL)->findOne(); if (!$warehouse instanceof Warehouse) { echo " Error! Wrong Location: " . $sapWarehouse->getLocation() . "\n"; continue; $errors++; } $warehouseStore->setIdWarehouse($warehouse->getIdWarehouse()); $warehouseStore->setCode($sapWarehouse->getWhscode()); $warehouseStore->setName($sapWarehouse->getWhsName()); $warehouseStore->setStatus(1); try { $this->getWarehouseStoreCatalog()->beginTransaction(); if ($save) { $this->getWarehouseStoreCatalog()->create($warehouseStore); $new++; } else { $this->getWarehouseStoreCatalog()->update($warehouseStore); $updated++; } $this->getWarehouseStoreCatalog()->commit(); } catch (Exception $e) { $this->getWarehouseStoreCatalog()->rollBack(); echo "\nError al intentar guardar el Warehouse Store: " . $e->getMessage(); } } echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated; die; }
/** * 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))); } }