/** * * @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); } }
/** * build fromArray * @param Query $query * @param array $fields * @param string $prefix */ public static function build(Query $query, $fields, $prefix = 'FolioImportProgrammedPayment') { parent::build($query, $fields); $criteria = $query->where(); $criteria->prefix($prefix); if (isset($fields['id_folios_import_programmed_payment']) && !empty($fields['id_folios_import_programmed_payment'])) { $criteria->add(FolioImportProgrammedPayment::ID_FOLIOS_IMPORT_PROGRAMMED_PAYMENT, $fields['id_folios_import_programmed_payment']); } if (isset($fields['id_folio_import']) && !empty($fields['id_folio_import'])) { $criteria->add(FolioImportProgrammedPayment::ID_FOLIO_IMPORT, $fields['id_folio_import']); } if (isset($fields['id_programmed_payment']) && !empty($fields['id_programmed_payment'])) { $criteria->add(FolioImportProgrammedPayment::ID_PROGRAMMED_PAYMENT, $fields['id_programmed_payment']); } if (isset($fields['concept']) && !empty($fields['concept'])) { $criteria->add(FolioImportProgrammedPayment::CONCEPT, $fields['concept']); } if (isset($fields['doc_num']) && !empty($fields['doc_num'])) { $criteria->add(FolioImportProgrammedPayment::DOC_NUM, $fields['doc_num']); } if (isset($fields['doc_entry']) && !empty($fields['doc_entry'])) { $criteria->add(FolioImportProgrammedPayment::DOC_ENTRY, $fields['doc_entry']); } $criteria->endPrefix(); }
/** * build fromArray * @param Query $query * @param array $fields * @param string $prefix */ public static function build(Query $query, $fields, $prefix = 'PurchaseOrderProgrammedPayment') { parent::build($query, $fields); $criteria = $query->where(); $criteria->prefix($prefix); if (isset($fields['id_purchase_orders_programmed_payment']) && !empty($fields['id_purchase_orders_programmed_payment'])) { $criteria->add(PurchaseOrderProgrammedPayment::ID_PURCHASE_ORDERS_PROGRAMMED_PAYMENT, $fields['id_purchase_orders_programmed_payment']); } if (isset($fields['id_programmed_payment']) && !empty($fields['id_programmed_payment'])) { $criteria->add(PurchaseOrderProgrammedPayment::ID_PROGRAMMED_PAYMENT, $fields['id_programmed_payment']); } if (isset($fields['id_purchase_order']) && !empty($fields['id_purchase_order'])) { $criteria->add(PurchaseOrderProgrammedPayment::ID_PURCHASE_ORDER, $fields['id_purchase_order']); } if (isset($fields['id_purchase_order_entry']) && !empty($fields['id_purchase_order_entry'])) { $criteria->add(PurchaseOrderProgrammedPayment::ID_PURCHASE_ORDER_ENTRY, $fields['id_purchase_order_entry']); } if (isset($fields['id_proforma_invoice_payment_term']) && !empty($fields['id_proforma_invoice_payment_term'])) { $criteria->add(PurchaseOrderProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM, $fields['id_proforma_invoice_payment_term']); } if (isset($fields['line']) && !empty($fields['line'])) { $criteria->add(PurchaseOrderProgrammedPayment::LINE, $fields['line']); } if (isset($fields['pieces']) && !empty($fields['pieces'])) { $criteria->add(PurchaseOrderProgrammedPayment::PIECES, $fields['pieces']); } if (isset($fields['id_purchase_order_payment_term']) && !empty($fields['id_purchase_order_payment_term'])) { $criteria->add(PurchaseOrderProgrammedPayment::ID_PURCHASE_ORDER_PAYMENT_TERM, $fields['id_purchase_order_payment_term']); } $criteria->endPrefix(); }