/** * * @author Erick Guevara Martínez * @param array $filters * @return ProgrammedPaymentCollection */ public function getProgrammedPayments(array $filters, $paidBills = false) { $idRequisition = $filters['id_requisition']; $proformaInvoiceDocNum = $filters['proforma_invoice_doc_num']; $purchaseOrderDocNum = $filters['purchase_order_doc_num']; $payments = ProgrammedPaymentQuery::create()->filter($filters); if ($paidBills) { $payments->whereAdd(ProgrammedPayment::STATUS, array(ProgrammedPayment::$TypeStatus['Paid'], ProgrammedPayment::$TypeStatus['Canceled'])); } else { $payments->whereAdd(ProgrammedPayment::STATUS, array(ProgrammedPayment::$TypeStatus['Pending'], ProgrammedPayment::$TypeStatus['Partial'])); } if ($idRequisition) { $this->configureProformaInvoicesAndPurchaseOrderByRequisition($idRequisition); } $payments->where()->setOr(); if ($proformaInvoiceDocNum || $idRequisition) { $proformaInvoice = ProformaInvoiceQuery::create()->whereAdd(ProformaInvoice::SAP_DOCUMENT_NUMBER, $proformaInvoiceDocNum)->findOneOrElse(new ProformaInvoice()); $proformaInvoiceProgrammedPayment = ProformaInvoiceProgrammedPaymentQuery::create()->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE, (array) $proformaInvoice->getIdProformaInvoice() + $this->getProformaInvoiceByRequisition()->getPrimaryKeys())->find(); $payments->whereAdd(ProgrammedPayment::ID_PROGRAMMED_PAYMENT, $proformaInvoiceProgrammedPayment->getProgrammedPaymentIds(), ProgrammedPaymentQuery::IN); } if ($purchaseOrderDocNum || $idRequisition) { $purchaseOrder = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::SAP_DOCUMENT_NUMBER, $purchaseOrderDocNum)->findOneOrElse(new PurchaseOrder()); $purchaseOrderProgrammedPayment = PurchaseOrderProgrammedPaymentQuery::create()->whereAdd(PurchaseOrderProgrammedPayment::ID_PURCHASE_ORDER, (array) $purchaseOrder->getIdPurchaseOrder() + $this->getPurchaseOrderByRequisition()->getPrimaryKeys())->find(); $payments->whereAdd(ProgrammedPayment::ID_PROGRAMMED_PAYMENT, $purchaseOrderProgrammedPayment->getProgrammedPaymentIds()); } $payments = $payments->addAscendingOrderBy(ProgrammedPayment::DUE_DATE)->find(); return $payments; }
public function toPaymentAction() { try { //die("<pre>".print_r($this->getRequest()->getParams(), true)); $ids = Zend_Json::decode(stripslashes($this->getRequest()->getParam("ids", "[]"))); $this->view->returnAction = $returnAction = $this->getRequest()->getParam("returnAction", "list"); $events = EventQuery::create()->find(); $programmedPayments = ProgrammedPaymentQuery::create()->whereAdd(ProgrammedPayment::ID_PROGRAMMED_PAYMENT, $ids)->find(); //die("<pre>".print_r($programmedPayments, true)); $actualPayments = ActualPaymentQuery::create()->whereAdd(ActualPayment::ID_PROGRAMMED_PAYMENT, $programmedPayments->getProgrammedPaymentIds())->find(); $programmedPaymentManager = new ProgrammedPaymentManager(); $condensedPayments = $programmedPaymentManager->getCondensedProgrammedPayments($programmedPayments, false); $payments = array(); //die("<pre>".print_r($condensedPayments, true)); while ($condensedPayments->valid()) { $condensedPayment = $condensedPayments->read(); $payment = array("condensedIndex" => $condensedPayment->getIndex(), "documentType" => $condensedPayment->getTypeName(), "docNum" => $condensedPayment->getSapDocnum(), "event" => $events->getByPK($condensedPayment->getIdEvent())->getName(), "ammount" => $condensedPayment->getAmmount(), "credits" => $condensedPayment->getCredits(), "pendingBalance" => $condensedPayment->getPendingBalance()); foreach ($condensedPayment->getProgrammedPaymentIds() as $idProgrammedPayment) { $programmedPayment = $programmedPayments->getByPK($idProgrammedPayment); $actualPayment = $actualPayments->filterByProgrammedPayment($programmedPayment); $payment["payments"][$idProgrammedPayment]["id"] = $idProgrammedPayment; $payment["payments"][$idProgrammedPayment]["toPay"] = $programmedPayment->getAmmount() - $actualPayment->getTotalAmmount(); } $payments[] = $payment; } $this->view->payments = $payments; //die("<pre>".print_r($payments, true)); $idSupplier = $this->getRequest()->getParam("supplier"); $this->view->supplier = SapSupplierQuery::create()->findByPKOrThrow($idSupplier, $this->i18n->_("SapSupplier with CardCode {$idSupplier} not found.")); $idCurrency = $this->getRequest()->getParam("currency"); $this->view->currency = CurrencyQuery::create()->findByPKOrThrow($idCurrency, $this->i18n->_("Currency with DocCurr {$idCurrency} not found.")); } catch (Exception $e) { $this->setFlash("error", $this->i18n->_($e->getMessage())); $this->getHelper('redirector')->goto($returnAction); } }