/** * * * @author Erick Guevara Martínez * @param ProgrammedPaymentCollection $proformaProgrammedPayments * @param ProformaInvoicePaymentTermCollection $proformaPaymentTerms * @return CondensedProgrammedPaymentCollection */ private function condenseProformaPayments(ProformaInvoiceProgrammedPaymentCollection $proformaProgrammedPayments, ProformaInvoicePaymentTermCollection $proformaPaymentTerms) { $condensedPayments = new CondensedProgrammedPaymentCollection(); $actualPayments = ActualPaymentQuery::create()->whereAdd(ActualPayment::ID_PROGRAMMED_PAYMENT, $proformaProgrammedPayments->getProgrammedPaymentIds())->find(); $proformasInvoice = ProformaInvoiceQuery::create()->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $proformaProgrammedPayments->getProformaInvoiceIds())->find(); while ($proformaProgrammedPayments->valid()) { $programmedPayment = $proformaProgrammedPayments->read(); $paymentTerm = $proformaPaymentTerms->getByPK($programmedPayment->getIdProformaInvoicePaymentTerm()); $credits = $actualPayments->filterByProgrammedPayment($programmedPayment); $proformaInvoice = $proformasInvoice->getByPK($programmedPayment->getIdProformaInvoice()); $pk = $programmedPayment->getIdProformaInvoice() . $programmedPayment->getType() . $paymentTerm->getIdEvent(); $condensedPayment = $condensedPayments->getByPkOrElse($pk, new CondensedProgrammedPayment()); $programmedPaymentIds = array_merge($condensedPayment->getProgrammedPaymentIds(), array($programmedPayment->getIdProgrammedPayment())); CondensedProgrammedPaymentFactory::populate($condensedPayment, array(CondensedProgrammedPayment::ID_DOCUMENT => $programmedPayment->getIdProformaInvoice(), CondensedProgrammedPayment::SAP_DOCNUM => $proformaInvoice->getSapDocumentNumber(), CondensedProgrammedPayment::ID_EVENT => $paymentTerm->getIdEvent(), CondensedProgrammedPayment::ID_SUPPLIER => $programmedPayment->getIdCompany(), CondensedProgrammedPayment::TYPE => $programmedPayment->getType(), CondensedProgrammedPayment::AMMOUNT => $condensedPayment->getAmmount() + $programmedPayment->getAmmount(), CondensedProgrammedPayment::CREDITS => $condensedPayment->getCredits() + $credits->getTotalAmmount(), CondensedProgrammedPayment::CURRENCY => $programmedPayment->getIdCurrency(), CondensedProgrammedPayment::DUE_DATE => $programmedPayment->getDueDate(), CondensedProgrammedPayment::PROGRAMMED_PAYMENT_IDS => $programmedPaymentIds, CondensedProgrammedPayment::STATUS => $programmedPayment->getStatus())); $condensedPayments->append($condensedPayment); } return $condensedPayments; }
/** * * @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; }