/**
  * 
  * 
  * @author Erick Guevara Martínez
  * @param PurchaseOrderEntryCollection $purchaseOrderEntries
  * @param PurchaseOrderPaymentTermCatalog $paymentTermCatalog
  * @return \Application\Model\Collection\PurchaseOrderPaymentTermCollection
  */
 public function createPaymentTerms(PurchaseOrderEntryCollection $purchaseOrderEntries)
 {
     $proformaInvoiceEntriesQuery = ProformaInvoiceEntryQuery::create();
     $proformaInvoiceEntriesQuery->where()->setOR();
     while ($purchaseOrderEntries->valid()) {
         $purchaseOrderEntry = $purchaseOrderEntries->read();
         $where = "(" . ProformaInvoiceEntry::ID_PROFORMA_INVOICE . " = " . $purchaseOrderEntry->getBaseEntry() . " AND " . ProformaInvoiceEntry::LINE . " = " . $purchaseOrderEntry->getBaseLine() . ")";
         $proformaInvoiceEntriesQuery->whereAdd("", null, null, $where, BaseQuery::AS_FIELD);
     }
     $purchaseOrderEntries->rewind();
     $proformaInvoiceEntries = $proformaInvoiceEntriesQuery->find();
     $PIPaymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY, $proformaInvoiceEntries->getPrimaryKeys())->find();
     $POPaymentTerms = new PurchaseOrderPaymentTermCollection();
     while ($purchaseOrderEntries->valid()) {
         $purchaseOrderEntry = $purchaseOrderEntries->read();
         $proformaInvoiceEntry = $proformaInvoiceEntries->getByIdProformaInvoiceAndLine($purchaseOrderEntry->getBaseEntry(), $purchaseOrderEntry->getBaseLine());
         $paymentTerms = $PIPaymentTerms->filterByProformaInvoiceEntry($proformaInvoiceEntry);
         while ($paymentTerms->valid()) {
             $paymentTerm = $paymentTerms->read();
             $payment = $purchaseOrderEntry->getQuantity() * $paymentTerm->getPayment() / $paymentTerm->getPieces();
             $POPaymentTerm = PurchaseOrderPaymentTermFactory::createFromArray(array(PurchaseOrderPaymentTerm::AMOUNT => $payment, PurchaseOrderPaymentTerm::CURRENCY => $purchaseOrderEntry->getCurrency(), PurchaseOrderPaymentTerm::ID_EVENT => $paymentTerm->getIdEvent(), PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER => $purchaseOrderEntry->getIdPurchaseOrder(), PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER_ENTRY => $purchaseOrderEntry->getIdPurchaseOrderEntry(), PurchaseOrderPaymentTerm::ID_PROFORMA_INVOICE_PAYMENT_TERM => $paymentTerm->getIdProformaInvoicePayment(), PurchaseOrderPaymentTerm::LINE => $purchaseOrderEntry->getLine(), PurchaseOrderPaymentTerm::PIECES => $purchaseOrderEntry->getQuantity(), PurchaseOrderPaymentTerm::STATUS => PurchaseOrderPaymentTerm::$Status["Active"]));
             $this->getPurchaseOrderPaymentTermsCatalog()->create($POPaymentTerm);
             $POPaymentTerms->append($POPaymentTerm);
         }
     }
     return $POPaymentTerms;
 }
Exemplo n.º 2
0
 public function createPaymentFromProformaInvoice(ProformaInvoiceEvent $event, $type)
 {
     $proformaInvoiceEntries = $event->getProformaInvoiceEntries();
     $proformaInvoice = $event->getProformaInvoice();
     $payments = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_EVENT, $type)->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY, $proformaInvoiceEntries->getPrimaryKeys())->find();
     if (!$payments->isEmpty()) {
         try {
             $this->getProformaInvoiceProgrammedPaymentCatalog()->beginTransaction();
             while ($paymentEvent = $payments->read()) {
                 $proformaInvoiceProgrammendPayment = ProformaInvoiceProgrammedPaymentFactory::createFromArray(array(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM => $paymentEvent->getIdProformaInvoicePayment(), ProformaInvoiceProgrammedPayment::AMMOUNT => $paymentEvent->getPayment(), ProformaInvoiceProgrammedPayment::PIECES => $paymentEvent->getPieces(), ProformaInvoiceProgrammedPayment::ID_CURRENCY => $paymentEvent->getCurrency(), ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE => $paymentEvent->getIdProformaInvoice(), ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_ENTRY => $paymentEvent->getIdProformaInvoiceEntry(), ProformaInvoiceProgrammedPayment::LINE => $paymentEvent->getLine(), ProformaInvoiceProgrammedPayment::TYPE => ProgrammedPayment::$TypePayment['ProformaInvoice'], ProformaInvoiceProgrammedPayment::ID_COMPANY => $proformaInvoice->getIdSupplier(), ProformaInvoiceProgrammedPayment::DUE_DATE => \Zend_Date::now()->addDay(15)->get("YYYY-MM-dd"), ProformaInvoiceProgrammedPayment::STATUS => ProgrammedPayment::$TypeStatus['Pending'], ProformaInvoiceProgrammedPayment::FOLIO => $proformaInvoice->getFolio()));
                 $this->getProformaInvoiceProgrammedPaymentCatalog()->create($proformaInvoiceProgrammendPayment);
             }
             $this->getProformaInvoiceProgrammedPaymentCatalog()->commit();
         } catch (Exception $e) {
             $this->getProformaInvoiceProgrammedPaymentCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
 }
Exemplo n.º 3
0
 /**
  *
  */
 private function setProformaInvoiceCollection()
 {
     if (empty($this->filters['type']) && empty($this->filters['purchase_order_doc_num']) || $this->filters['type'] == ProgrammedPayment::$TypePayment['ProformaInvoice']) {
         $proformaInvoiceQuery = ProformaInvoiceQuery::create();
         if (!empty($this->filters['id_company'])) {
             $proformaInvoiceQuery->whereAdd(ProformaInvoice::ID_SUPPLIER, $this->filters['id_company']);
         }
         if (!empty($this->filters['id_requisition'])) {
             $proformaInvoiceQuery->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $this->getProformaInvoiceByRequisition()->getPrimaryKeys());
         }
         if (!empty($this->filters['proforma_invoice_doc_num'])) {
             $proformaInvoiceQuery->whereAdd(ProformaInvoice::SAP_DOCUMENT_NUMBER, $this->filters['proforma_invoice_doc_num']);
         } else {
             $proformaInvoicesIds = ProformaInvoicePaymentTermQuery::create()->addColumn(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE)->distinct()->fetchAll();
             $proformaInvoiceQuery->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $proformaInvoicesIds);
         }
         $proformaInvoiceCollection = $proformaInvoiceQuery->find();
     } else {
         $proformaInvoiceCollection = new ProformaInvoiceCollection();
     }
     $this->proformaInvoiceCollection = $proformaInvoiceCollection;
 }
Exemplo n.º 4
0
 public function updatePaymentEntriesIdsAction()
 {
     $paymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY, "", ProformaInvoicePaymentTermQuery::IS_NULL)->find();
     $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->find();
     $proformaInvoiceProgrammedPayments = ProformaInvoiceProgrammedPaymentQuery::create()->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_ENTRY, "", ProformaInvoiceProgrammedPaymentQuery::IS_NULL)->find();
     $this->getProformaInvoicePaymentTermCatalog()->beginTransaction();
     try {
         while ($paymentTerms->valid()) {
             $paymentTerm = $paymentTerms->read();
             $proformaInvoiceEntry = $proformaInvoiceEntries->getByIdProformaInvoiceAndLine($paymentTerm->getIdProformaInvoice(), $paymentTerm->getLine());
             if ($proformaInvoiceEntry->getIdProformaInvoiceEntry() > 0) {
                 $paymentTerm->setIdProformaInvoiceEntry($proformaInvoiceEntry->getIdProformaInvoiceEntry());
                 $this->getProformaInvoicePaymentTermCatalog()->update($paymentTerm);
                 $programmedPayments = $proformaInvoiceProgrammedPayments->filterByPaymentTerm($paymentTerm);
                 while ($programmedPayments->valid()) {
                     $programmedPayment = $programmedPayments->read();
                     $programmedPayment->setIdProformaInvoiceEntry($proformaInvoiceEntry->getIdProformaInvoiceEntry());
                     $this->getProformaInvoiceProgrammedPaymentCatalog()->update($programmedPayment);
                 }
             }
         }
         $this->getProformaInvoicePaymentTermCatalog()->commit();
         die("FIN");
     } catch (Exception $e) {
         die("<pre>" . print_r($e, true));
     }
 }
 /**
  *
  * @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;
 }
Exemplo n.º 6
0
 public function fixPaymentTermsAction()
 {
     $POPaymentTerms = PurchaseOrderPaymentTermQuery::create()->find();
     $this->getPurchaseOrderPaymentTermsCatalog()->beginTransaction();
     try {
         while ($POPaymentTerms->valid()) {
             $POPaymentTerm = $POPaymentTerms->read();
             $this->getPurchaseOrderPaymentTermsCatalog()->deleteById($POPaymentTerm->getIdPurchaseOrderPaymentTerm());
         }
         $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::BASE_ENTRY, "", PurchaseOrderEntryQuery::IS_NOT_NULL)->whereAdd(PurchaseOrderEntry::BASE_LINE, "", PurchaseOrderEntryQuery::IS_NOT_NULL)->find();
         $purchaseOrderPaymentTerm = new PurchaseOrderPaymentsManager();
         $POPaymentTerms = $purchaseOrderPaymentTerm->createPaymentTerms($purchaseOrderEntries);
         $programmedPayments = PurchaseOrderProgrammedPaymentQuery::create()->find();
         $proformaInvoicePaymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_PAYMENT, $programmedPayments->getProformaInvoicePaymentTermIds())->find();
         while ($programmedPayments->valid()) {
             $programmedPayment = $programmedPayments->read();
             $proformaInvoicePaymentTerm = $proformaInvoicePaymentTerms->getByPK($programmedPayment->getIdProformaInvoicePaymentTerm());
             $POPaymentTerm = null;
             $POPaymentTerms->each(function (PurchaseOrderPaymentTerm $purchaseOrderPaymentTerm) use($programmedPayment, $proformaInvoicePaymentTerm, &$POPaymentTerm) {
                 if ($purchaseOrderPaymentTerm->getIdEvent() == $proformaInvoicePaymentTerm->getIdEvent() && $purchaseOrderPaymentTerm->getLine() == $programmedPayment->getLine() && $purchaseOrderPaymentTerm->getIdPurchaseOrder() == $programmedPayment->getIdPurchaseOrder()) {
                     $POPaymentTerm = $purchaseOrderPaymentTerm;
                 }
             });
             if ($POPaymentTerm instanceof PurchaseOrderPaymentTerm) {
                 $programmedPayment->setIdPurchaseOrderPaymentTerm($POPaymentTerm->getIdPurchaseOrderPaymentTerm());
                 $this->getPurchaseOrderProgrammedPaymentCatalog()->update($programmedPayment);
             }
         }
         $this->getPurchaseOrderPaymentTermsCatalog()->commit();
         die("fin");
     } catch (Exception $e) {
         $this->getPurchaseOrderPaymentTermsCatalog()->rollBack();
         die($e->getMessage());
     }
 }
 /**
  *
  */
 public function reactivateAction()
 {
     $id = $this->getRequest()->getParam('id');
     $proformaInvoicePaymentTerm = ProformaInvoicePaymentTermQuery::create()->findByPKOrThrow($id, $this->i18n->_("Not exists the ProformaInvoicePaymentTerm with id {$id}"));
     try {
         $this->getProformaInvoicePaymentTermCatalog()->beginTransaction();
         $this->getProformaInvoicePaymentTermCatalog()->update($proformaInvoicePaymentTerm);
         $this->getProformaInvoicePaymentTermCatalog()->commit();
         $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el ProformaInvoicePaymentTerm"));
     } catch (Exception $e) {
         $this->getProformaInvoicePaymentTermCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->_redirect('proforma-invoice-payment-term/list');
 }