/**
  *
  * @param int $idRequisition
  * @return boolean
  */
 private function configureProformaInvoicesAndPurchaseOrderByRequisition($idRequisition)
 {
     if (!$this->proformaInvoiceByRequisition instanceof ProformaInvoiceCollection) {
         $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION, $idRequisition)->find();
         $proformaInvoiceQuery = ProformaInvoiceQuery::create();
         $proformaInvoiceQuery->where()->end()->setAND();
         $proformaInvoiceQuery->where()->setOR();
         while ($requisitionEntry = $requisitionEntries->read()) {
             $proformaInvoiceQuery->whereAdd('ProformaInvoiceEntry.' . ProformaInvoiceEntry::REQUISITION_IDS, $requisitionEntry->getIdRequisitionEntry(), BaseQuery::LIKE);
         }
         $this->proformaInvoiceByRequisition = $proformaInvoiceQuery->find();
         $this->purchaseOrderByRequisition = PurchaseOrderQuery::create()->whereAdd('PurchaseOrderEntry.' . PurchaseOrderEntry::BASE_ENTRY, $this->getProformaInvoiceByRequisition()->getPrimaryKeys())->find();
     }
 }
 /**
  * This action create a proforma invoice and link with respective budgets and requisition entries
  *
  * @author Erick Guevara Martinez
  */
 public function createAction()
 {
     $proformaParams["proforma_invoice_number"] = $this->getRequest()->getParam("proforma_invoice_number", "");
     $proformaParams["date"] = $this->getRequest()->getParam("required_date", "");
     $proformaParams["delivery_estimate_date"] = $this->getRequest()->getParam("required_date", "");
     $proformaParams["id_forwarder"] = $this->getRequest()->getParam("id_forwarder", "");
     $proformaParams["id_supplier"] = $this->getRequest()->getParam("id_supplier", "");
     $proformaParams["id_port_custom"] = $this->getRequest()->getParam("id_port_custom", "");
     $proformaParams["id_courtyard"] = $this->getRequest()->getParam("id_courtyard", "");
     $proformaParams["idCurrencyPI"] = $this->getRequest()->getParam("idCurrencyPI", "");
     $supplier = SapSupplierQuery::create()->findByPKOrThrow($proformaParams["id_supplier"], $this->i18n->_("The Supplier with id {$proformaParams["id_supplier"]} does not exist"));
     $date = \Zend_Date::now();
     $accessRole = $this->getUser()->getAccessRole();
     $proformaInvoice = ProformaInvoiceFactory::createFromArray(array("id_proforma_invoice" => 0, "folio" => $proformaParams["proforma_invoice_number"], "groupnum" => $supplier->getGroupnum(), "id_courtyard" => $proformaParams["id_courtyard"], "id_currency" => $proformaParams["idCurrencyPI"], "id_supplier" => $proformaParams["id_supplier"], "date" => $proformaParams["date"], "delivery_estimate_date" => $proformaParams["delivery_estimate_date"], "creation_date" => $date->get("yyyy-MM-dd"), "status" => ProformaInvoice::$Status["New"]));
     $proformaInvoiceEntries = new ProformaInvoiceEntryCollection();
     $proformaEntriesParams["parentKeys"] = $this->getRequest()->getParam("parentKeys", "");
     $proformaEntriesParams["warehouse_store"] = $this->getRequest()->getParam("warehouse_store", WarehouseStore::$defaultWarehouseStore);
     $arrayRequisitionEntries = array();
     $lineCount = 0;
     foreach ($proformaEntriesParams["parentKeys"] as $parentKey) {
         foreach ($parentKey["products"] as $key => $product) {
             $proformaInvoiceEntry = ProformaInvoiceEntryFactory::createFromArray(array("id_proforma_invoice_entry" => 0, "line" => $lineCount, "vis_order" => $lineCount, "id_product" => $product["product"], "id_warehouse_store" => $proformaEntriesParams["warehouse_store"], "lead_time" => $parentKey["lead_time"], "quantity" => $product["Quantity"], "status" => ProformaInvoiceEntry::$Status["New"], "price" => $parentKey["price"], "currency" => $proformaParams["idCurrencyPI"], "tax_code" => "W0", "requisition_ids" => implode('-', $product['entries'])));
             $proformaInvoiceEntries->append($proformaInvoiceEntry);
             $lineCount++;
             $arrayRequisitionEntries = array_merge($arrayRequisitionEntries, $product["entries"]);
         }
     }
     $sapConnectionClient = new SAPConnectorClient();
     $result = $sapConnectionClient->purchaseQuotation($proformaInvoice, $proformaInvoiceEntries);
     if ($result->purchaseQuotationResult->code == 200) {
         try {
             $this->getFileCatalog()->beginTransaction();
             $proformaInvoice->setIdProformaInvoice($result->purchaseQuotationResult->id);
             while ($proformaInvoiceEntry = $proformaInvoiceEntries->read()) {
                 $proformaInvoiceEntry->setIdProformaInvoice($result->purchaseQuotationResult->id);
                 $this->newEntryLogForCreate($proformaInvoiceEntry);
             }
             $fileUploader = new FileUploader("proforma_invoice_file");
             $filePath = "files/proformas/" . $result->purchaseQuotationResult->id;
             $uploadPath = 'public/' . $filePath;
             $fileUploader->saveFile($uploadPath, false);
             // Create the file record in database
             $file = new File();
             $file->setType(File::$typeFile["typeFile"])->setContent($filePath . $fileUploader->getFileName());
             $this->getFileCatalog()->create($file);
             $proformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_FILE => $file->getIdFile(), ProformaInvoiceFile::ID_PROFORMA_INVOICE => $result->purchaseQuotationResult->id, ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PINew"]));
             $this->getProformaInvoiceFileCatalog()->create($proformaInvoiceFile);
             // Create Payment terms by Proforma invoice Line
             // Se consultan las entries debido a que hasta el momento no tenian id
             $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $result->purchaseQuotationResult->id)->find();
             //die("<pre>".print_r($proformaInvoiceEntries, true));
             $events = EventQuery::create()->addColumns(array("Event2PaymentTerm.*", "Event.*"))->innerJoinPaymentTerm()->whereAdd("Event2PaymentTerm." . PaymentTerm::ID_PAYMENT_TERM, $supplier->getIdPaymentTerm(), BaseQuery::EQUAL)->fetchAll();
             foreach ($events as $event) {
                 $proformaInvoiceEntries->rewind();
                 while ($proformaInvoiceEntries->valid()) {
                     $proformaInvoiceEntry = $proformaInvoiceEntries->read();
                     $proformaInvoicePaymentTerm = ProformaInvoicePaymentTermFactory::createFromArray(array(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE => $proformaInvoiceEntry->getIdProformaInvoice(), ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY => $proformaInvoiceEntry->getIdProformaInvoiceEntry(), ProformaInvoicePaymentTerm::ID_EVENT => $event["id_event"], ProformaInvoicePaymentTerm::LINE => $proformaInvoiceEntry->getVisOrder(), ProformaInvoicePaymentTerm::PIECES => $proformaInvoiceEntry->getQuantity(), ProformaInvoicePaymentTerm::PAYMENT => $proformaInvoiceEntry->getTotalImport() * $event["percent"] / 100, ProformaInvoicePaymentTerm::CURRENCY => $proformaInvoiceEntry->getCurrency(), ProformaInvoicePaymentTerm::STATUS => ProformaInvoicePaymentTerm::$Status["Active"]));
                     $this->getProformaInvoicePaymentTermCatalog()->create($proformaInvoicePaymentTerm);
                 }
             }
             // Close requisition entries and requisition
             $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $arrayRequisitionEntries, RequisitionEntryQuery::IN)->find();
             $requisitions = RequisitionQuery::create()->whereAdd(Requisition::ID_REQUISITION, $requisitionEntries->getDistinctRequisitions(), RequisitionQuery::IN)->find();
             while ($requisitionEntries->valid()) {
                 $requisitionEntry = $requisitionEntries->read();
                 $requisitionEntry->setStatus(RequisitionEntry::$Status["Closed"]);
                 $this->getRequisitionEntryCatalog()->update($requisitionEntry);
                 $requisition = $requisitions->getByPK($requisitionEntry->getIdRequisition());
                 $requisitionEntriesByRequisition = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION, $requisition->getIdRequisition(), RequisitionEntryQuery::EQUAL)->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $requisitionEntry->getIdRequisitionEntry(), RequisitionEntryQuery::NOT_EQUAL)->find();
                 if ($requisitionEntriesByRequisition->checkClosed()) {
                     $requisition->setStatus(Requisition::$Status["Closed"]);
                     $this->getRequisitionCatalog()->update($requisition);
                 }
             }
             $keyMotherSupplierBudgets = KeyMotherSupplierBudgetQuery::create()->innerJoinRequisitionEntry()->whereAdd("RequisitionEntry." . RequisitionEntry::ID_REQUISITION_ENTRY, $requisitionEntries->getPrimaryKeys(), KeyMotherSupplierBudgetQuery::IN)->find();
             while ($keyMotherSupplierBudgets->valid()) {
                 $budget = $keyMotherSupplierBudgets->read();
                 $budget->setStatus(KeyMotherSupplierBudget::$Status["Inactive"]);
                 $this->getKeyMotherSupplierBudgetCatalog()->update($budget);
             }
             $this->newLogForCreate($proformaInvoice, $proformaInvoiceEntries);
             $this->getFileCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The Proforma Invoice was created with id {$result->purchaseQuotationResult->id}."));
         } catch (Exception $e) {
             $this->getFileCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     } else {
         $this->setFlash('error', $result->purchaseQuotationResult->code . " - " . $result->purchaseQuotationResult->message);
     }
     $this->_redirect('proforma-invoice/list');
 }
 /**
  *
  * @param int $idProformaInvoice
  * @param int $idEvent
  */
 private function getMissingProformaInformation($idProformaInvoice, $idEvent)
 {
     $event = EventQuery::create()->findByPKOrThrow($idEvent, $this->i18n->_("Event with id {$idEvent} not found."));
     $proformaInvoice = ProformaInvoiceQuery::create()->findByPKOrThrow($idProformaInvoice, $this->i18n->_("ProformaInvoice with id {$idProformaInvoice} not found."));
     $supplier = SapSupplierQuery::create()->findByPKOrThrow($proformaInvoice->getIdSupplier(), $this->i18n->_("SapSupplier with id {$proformaInvoice->getIdSupplier()} not found."));
     $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find();
     if (count($proformaInvoiceEntries->getDistinctRequisitionEntryIdsToArray()) > 0) {
         $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $proformaInvoiceEntries->getDistinctRequisitionEntryIdsToArray())->find();
     }
     $paymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->whereAdd(ProformaInvoicePaymentTerm::ID_EVENT, $event->getIdEvent())->find();
     $programmedPayments = new ProformaInvoiceProgrammedPaymentCollection();
     while ($paymentTerm = $paymentTerms->valid()) {
         $proformaInvoicePaymentTerm = $paymentTerms->read();
         $proformaInvoiceMissingProgrammedPayment = ProformaInvoiceProgrammedPaymentFactory::createFromArray(array('id_proforma_invoice_programmed_payment' => 'VPIPP' . $proformaInvoicePaymentTerm->getIdProformaInvoicePayment(), 'id_proforma_invoice_payment_term' => $proformaInvoicePaymentTerm->getIdProformaInvoicePayment(), 'pieces' => $proformaInvoicePaymentTerm->getPieces(), 'id_proforma_invoice' => $proformaInvoicePaymentTerm->getIdProformaInvoice(), 'line' => $proformaInvoicePaymentTerm->getLine(), 'id_programmed_payment' => 'VPP' . $proformaInvoicePaymentTerm->getIdProformaInvoicePayment(), 'id_currency' => $proformaInvoicePaymentTerm->getCurrency(), 'id_company' => $proformaInvoice->getIdSupplier(), 'type' => ProgrammedPayment::$TypePayment['ProformaInvoice'], 'ammount' => $proformaInvoicePaymentTerm->getPayment(), 'folio' => 'Not Available', 'due_date' => 'Not Available', 'status' => ProgrammedPayment::$TypeStatus['Virtual']));
         $programmedPayments->append($proformaInvoiceMissingProgrammedPayment);
     }
     $response = array("docNum" => $proformaInvoice->getSapDocumentNumber(), "docEntry" => $proformaInvoice->getIdProformaInvoice(), "createDate" => $proformaInvoice->getDocDate(), "supplier" => $supplier->getCardCode(), "supplierName" => $supplier->getCardname(), "event" => $event->getName());
     while ($proformaInvoiceEntries->valid()) {
         $proformaInvoiceEntry = $proformaInvoiceEntries->read();
         $paymentTerm = $paymentTerms->filterByProformaInvoiceEntry($proformaInvoiceEntry)->getOne();
         $programmedPayment = $programmedPayments->filterByPaymentTerm($paymentTerm)->getOne();
         $entryIds = $proformaInvoiceEntry->getRequisitionIdsToArray();
         if (count($entryIds) > 0) {
             $entries = $requisitionEntries->filter(function (RequisitionEntry $entry) use($entryIds) {
                 return in_array($entry->getIdRequisitionEntry(), $entryIds);
             });
         } else {
             $entries = new RequisitionEntryCollection();
         }
         $response["entries"][] = array("line" => $proformaInvoiceEntry->getLine(), "product" => $proformaInvoiceEntry->getIdProduct(), "quantity" => $proformaInvoiceEntry->getQuantity(), "price" => $proformaInvoiceEntry->getPrice(), "currency" => $proformaInvoiceEntry->getCurrency(), "requisitions" => $entries->isEmpty() ? "-" : implode($entries->getDistinctRequisitions()), "ammount" => $programmedPayment->getAmmount(), "credits" => 0, "pendingBalance" => $programmedPayment->getAmmount());
     }
     return $response;
 }
 /**
  * 
  * @return \Application\Model\Collection\RequisitionEntryCollection
  */
 public function getRequisitionEntryCollection()
 {
     if (!$this->requisitionEntryCollection instanceof RequisitionEntryCollection) {
         $this->requisitionEntryCollection = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $this->getProformaInvoiceEntryCollection()->getDistinctRequisitionEntryIdsToArray())->find();
     }
     return $this->requisitionEntryCollection;
 }
Esempio n. 5
0
 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)));
     }
 }
Esempio n. 6
0
 public function exportToExcelAction()
 {
     $params = $this->getRequest()->getParams();
     $requisitions = RequisitionQuery::create()->filter($params)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->find();
     $requisitionIds = RequisitionQuery::create()->filter($params)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->fetchCol();
     $allRequisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION, $requisitionIds, RequisitionEntryQuery::IN)->find();
     $currencies = CurrencyQuery::create()->find();
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $allRequisitionEntries->getDistinctProducts(), ProductQuery::IN)->find();
     $countries = CountryQuery::create()->find();
     $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $allRequisitionEntries->getDistinctSuppliers(), SupplierQuery::IN)->find();
     require_once 'PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet->setCellValue('A1', $this->i18n->_('Requisition Folio'))->setCellValue('B1', $this->i18n->_('Requisition Status'))->setCellValue('C1', $this->i18n->_('Reference'))->setCellValue('D1', $this->i18n->_('Creation Date'))->setCellValue('E1', $this->i18n->_('Destination'))->setCellValue('F1', $this->i18n->_('Parent Key'))->setCellValue('G1', $this->i18n->_('Product Status'))->setCellValue('H1', $this->i18n->_('Product Code'))->setCellValue('I1', $this->i18n->_('Product Description'))->setCellValue('J1', $this->i18n->_('Line Status'))->setCellValue('K1', $this->i18n->_('Supplier Default Code'))->setCellValue('L1', $this->i18n->_('Supplier Default Name'))->setCellValue('M1', $this->i18n->_('Ammount'))->setCellValue('N1', $this->i18n->_('Target Price'))->setCellValue('O1', $this->i18n->_('Price'))->setCellValue('P1', $this->i18n->_('Import'))->setCellValue('Q1', $this->i18n->_('currency'));
     $i = 2;
     while ($requisitions->valid()) {
         $requisition = $requisitions->read();
         $requisitionEntries = $allRequisitionEntries->filterByIdRequisition($requisition->getIdRequisition());
         $country = $countries->getByPK($requisition->getIdDestinationCountry());
         $entriesCount = $i;
         while ($requisitionEntries->valid()) {
             $requisitionEntry = $requisitionEntries->read();
             $product = $products->containsIndex($requisitionEntry->getIdProduct()) ? $products->getByPK($requisitionEntry->getIdProduct()) : new Product();
             $supplier = $requisitionEntry->getIdSupplierDefault() > 0 ? $suppliers->getByPkOrElse($requisitionEntry->getIdSupplierDefault(), new SapSupplier()) : new SapSupplier();
             $currency = $currencies->getByPK($requisitionEntry->getIdCurrency());
             $activeSheet->setCellValue("F" . $entriesCount, $product->getKeyMother())->setCellValue("G" . $entriesCount, $product->getStatus())->setCellValue("H" . $entriesCount, $product->getItemCode())->setCellValue("I" . $entriesCount, $product->getItemName())->setCellValue("J" . $entriesCount, $requisitionEntry->getStatusName())->setCellValue("K" . $entriesCount, $supplier->getCardCode())->setCellValue("L" . $entriesCount, $supplier->getCardname())->setCellValue("M" . $entriesCount, $requisitionEntry->getQuantity())->setCellValue("N" . $entriesCount, $product->getCost())->setCellValue("O" . $entriesCount, $requisitionEntry->getPrice())->setCellValue("P" . $entriesCount, $requisitionEntry->getImport())->setCellValue("Q" . $entriesCount, $currency->getCurrCode());
             $entriesCount++;
         }
         $activeSheet->mergeCells('A' . $i . ':A' . ($entriesCount - 1))->setCellValue('A' . $i, $requisition->getIdRequisition())->mergeCells('B' . $i . ':B' . ($entriesCount - 1))->setCellValue('B' . $i, $requisition->getStatusName())->mergeCells('C' . $i . ':C' . ($entriesCount - 1))->setCellValue('C' . $i, $requisition->getNumRequisition())->mergeCells('D' . $i . ':D' . ($entriesCount - 1))->setCellValue('D' . $i, $requisition->getDate())->mergeCells('E' . $i . ':E' . ($entriesCount - 1))->setCellValue('E' . $i, utf8_encode($country->getName()));
         $i = $entriesCount;
     }
     header("Content-Type: application/vnd.ms-excel");
     $date = \Zend_Date::now();
     $fileName = $this->i18n->_("Requisitions_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;
 }