/** * This function verify if exist all needded exchange rates to calculate a import in one currency * * @author Erick Guevara Mart�nez * @param RequisitionEntryCollection $requisitionEntries * @param Currency $currencyTo * @param ExchangeRateCollection $currenciesExchanges * @return array */ public function validateExchangeRates(RequisitionEntryCollection $requisitionEntries, Currency $currencyTo, CurrencyExchangeCollection $currenciesExchanges) { $validation["valid"] = true; $requisitionEntries->rewind(); while ($requisitionEntries->valid()) { $requisitionEntry = $requisitionEntries->read(); if ($requisitionEntry->getIdCurrency() != $currencyTo->getCurrCode()) { if (!$currenciesExchanges->hasCurrency($requisitionEntry->getIdCurrency()) || !$currenciesExchanges->hasCurrency($currencyTo->getCurrCode())) { $validation["valid"] = false; $validation["from"] = $requisitionEntry->getIdCurrency(); $validation["to"] = $currencyTo->getCurrCode(); break; } } } $requisitionEntries->rewind(); return $validation; }
/** * * @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; }