public function editAction()
 {
     $whscode = $this->getRequest()->getParam('whscode');
     $stores = StoreHouseByLocationQuery::create()->addColumn(StoreHouseByLocation::TYPE)->addColumn(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_DESTINATION)->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_PPV, $whscode)->fetchPairs();
     // 		echo '<pre>';
     // 		print_r($stores);
     // 		die;
     $this->view->whscode = $whscode;
     $this->view->onsubmit = $this->getBaseUrl() . '/store-house-by-location/update';
     $this->view->stores = $stores;
     $this->view->storesCombo = WarehouseStoreQuery::create()->find()->toCombo('All');
     $this->view->contentTitle = $this->i18n->_('Edit Reception Storehouses');
     $this->view->types = WarehouseStore::$TypeName;
     $this->view->setTpl('Form');
 }
Пример #2
0
 /**
  *
  * @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');
     }
 }
 /**
  * 
  * 
  */
 public function getQuarantineListResultsAction()
 {
     $page = $this->getRequest()->getParam('page') ?: 1;
     $warehouseEntries = WarehouseEntranceQuery::create()->whereAdd(WarehouseEntrance::ID_FOLIO_IMPORT, null, WarehouseEntranceQuery::NOT_EQUAL)->whereAdd(WarehouseEntrance::ID_FOLIO_IMPORT, '0', WarehouseEntranceQuery::NOT_EQUAL)->find();
     $params = $this->getRequest()->getParams();
     $params['id_purchase_order'] = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::SAP_DOCUMENT_NUMBER, $params['sap_document_number'])->fetchOne();
     if (empty($params['id_purchase_order']) && !empty($params['sap_document_number'])) {
         $params['id_purchase_order'] = -1;
     }
     $warehouseEntryProductQuery = WarehouseEntranceProductQuery::create()->whereAdd(WarehouseEntranceProduct::ID_PURCHASE_ORDER, null, WarehouseEntranceProductQuery::NOT_EQUAL)->whereAdd(WarehouseEntranceProduct::STATUS, WarehouseEntranceProduct::$Status['Quarantine'], WarehouseEntranceProductQuery::EQUAL)->whereAdd(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE, $warehouseEntries->getPrimaryKeys(), WarehouseEntranceProductQuery::IN)->filter($params)->orderBy(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE, 'DESC')->findByPage($page, $this->getMaxPerPage());
     $purchaseOrderCollection = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $warehouseEntryProductQuery->getPurchaseOrderIds(), PurchaseOrderQuery::IN)->find();
     $purchaseOrderEntryCollection = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrderCollection->getPrimaryKeys(), PurchaseOrderEntryQuery::IN)->find();
     $i = 0;
     $this->getCatalog('QuarantineCatalog')->beginTransaction();
     while ($warehouseEntryLine = $warehouseEntryProductQuery->read()) {
         $warehouseEntry = WarehouseEntranceQuery::create()->whereAdd(WarehouseEntrance::ID_WAREHOUSE_ENTRANCE, $warehouseEntryLine->getIdWarehouseEntrance())->findOne();
         if (TransferLineLogQuery::create()->whereAdd(TransferLineLog::BASEENTRY, $warehouseEntryLine->getIdWarehouseEntrance())->whereAdd(TransferLineLog::BASELINE, $warehouseEntryLine->getIdWarehouseEntranceProduct())->count()) {
             $transferLine = TransferLineLogQuery::create()->whereAdd(TransferLineLog::BASEENTRY, $warehouseEntryLine->getIdWarehouseEntrance())->whereAdd(TransferLineLog::BASELINE, $warehouseEntryLine->getIdWarehouseEntranceProduct())->findOne();
             $warehouseEntryLines[$i]['warehouse'] = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::CODE, $transferLine->getWhsCode())->findOne()->getName();
         } else {
             $warehouseEntryLines[$i]['warehouse'] = $this->i18n->_('Not Available');
         }
         $claimReport = $this->getClaimReport($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct());
         $folioImport = $this->getWarehouseEntryFolioImport($warehouseEntry->getIdFolioImport());
         $quarantine = $this->getQuarantine($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct());
         $product = ProductQuery::create()->findByPK($warehouseEntryLine->getIdProduct());
         $warehouseEntryLines[$i]['id_warehouse_entrance_product'] = $warehouseEntryLine->getIdWarehouseEntranceProduct();
         $warehouseEntryLines[$i]['id_warehouse_entrance'] = $warehouseEntry->getIdWarehouseEntrance();
         $warehouseEntryLines[$i]['id_folio_import'] = $folioImport->getIdFolioImport();
         $warehouseEntryLines[$i]['folio_import'] = $folioImport->getFolio();
         if (PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $warehouseEntryLine->getIdPurchaseOrder())->find()->count()) {
             $purchaseOrder = PurchaseOrderQuery::create()->findByPK($warehouseEntryLine->getIdPurchaseOrder());
         } else {
             $purchaseOrder = new PurchaseOrder();
         }
         $purchaseOrderEntry = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderEntry::LINE, (string) $warehouseEntryLine->getBaseLine())->findOneOrElse(new PurchaseOrderEntry());
         $proformaInvoice = ProformaInvoiceQuery::create()->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $purchaseOrderEntry->getBaseEntry())->findOneOrElse(new ProformaInvoice());
         $warehouseEntryLines[$i]['proforma_invoice'] = $proformaInvoice->getSapDocumentNumber();
         $warehouseEntryLines[$i]['purchase_order'] = $purchaseOrder->getSapDocumentNumber();
         $warehouseEntryLines[$i]['item_code'] = $product->getItemCode();
         $warehouseEntryLines[$i]['item_name'] = $product->getItemName();
         $warehouseEntryLines[$i]['original_quantity'] = $warehouseEntryLine->getQuantity();
         $warehouseEntryLines[$i]['current_quantity'] = $currentQuantity = $quarantine->getQuantity();
         if ($warehouseEntryLine->getLineStatus() == 'C') {
             // 				$warehouseEntryLines[$i]['cancelled'] = true;
             // 				$warehouseEntryLines[$i]['status'] = 'Cancelled';
             // 				$warehouseEntryLines[$i]['statusRow'] = ' ';
         } else {
             $warehouseEntryLines[$i]['cancelled'] = false;
             if (!$currentQuantity) {
                 $warehouseEntryLines[$i]['status'] = 'Debugged';
                 $warehouseEntryLines[$i]['statusRow'] = 'success';
             } else {
                 $warehouseEntryLines[$i]['status'] = $warehouseEntryLine->getStatusName();
                 $warehouseEntryLines[$i]['statusRow'] = 'warning';
             }
         }
         $warehouseEntryLines[$i]['quarantine'] = $warehouseEntryLine->getStatusName();
         $warehouseEntryLines[$i]['claimed_amount'] = $claimReport->getClaimedAmount();
         $warehouseEntryLines[$i]['final_amount'] = $claimReport->getFinalAmount();
         $warehouseEntryLines[$i]['claim_report_status'] = $claimReport->getStatusName();
         $warehouseEntryLines[$i]['allow_debug'] = TransferLineLogQuery::create()->whereAdd(TransferLineLog::BASEENTRY, $warehouseEntryLine->getIdWarehouseEntrance())->whereAdd(TransferLineLog::BASELINE, $warehouseEntryLine->getIdWarehouseEntranceProduct())->count();
         if ($warehouseEntryLine->getStatus() == WarehouseEntranceProduct::$Status['Quarantine']) {
             $quarantineProduct = $this->getQuarantine($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct());
             $warehouseEntryLines[$i]['initial_quantity'] = $quarantineProduct->getQuantity();
         }
         $i++;
     }
     $this->getCatalog('QuarantineCatalog')->commit();
     die(json_encode($warehouseEntryLines));
 }
Пример #4
0
 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;
 }
Пример #5
0
 public function warehouseStoresByIdWarehouseAction()
 {
     if ($this->getRequest()->isPost()) {
         $id = $this->getRequest()->getParam("warehouse");
         $warehouseStores = array("" => $this->i18n->_("Select a Warehouse Store")) + WarehouseStoreQuery::create()->whereAdd(WarehouseStore::LOCATION, $id, WarehouseStoreQuery::EQUAL)->whereAdd(WarehouseStore::TYPE, WarehouseStore::$Type["ppv"], WarehouseStoreQuery::EQUAL)->find()->toCombo();
         die(Zend_Json::encode($warehouseStores));
     }
 }
Пример #6
0
 /**
  *
  * 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;
 }
Пример #7
0
 /**
  * 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("&#8364;", "€", $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)));
     }
 }