/**
  * 
  * 
  * @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;
 }
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\PurchaseOrderPaymentTerm
  */
 protected function makeBean($resultset)
 {
     return PurchaseOrderPaymentTermFactory::createFromArray($resultset);
 }