Пример #1
0
 /**
  *
  * @param CondensedProgrammedPaymentCollection $condensedPayments
  * @param PurchaseOrderProgrammedPaymentCollection $purchaseOrderProgrammedPayments
  * @param ProformaInvoiceProgrammedPaymentCollection $proformaInvoiceProgrammedPayments
  * @return CondensedProgrammedPaymentCollection
  */
 private function generateMissingPurchaseOrderProgrammedPayments(CondensedProgrammedPaymentCollection $condensedPayments, PurchaseOrderProgrammedPaymentCollection $purchaseOrderProgrammedPayments, ProformaInvoiceProgrammedPaymentCollection $proformaInvoiceProgrammedPayments)
 {
     $purchaseOrders = $this->getPurchaseOrderCollection();
     $purchaseOrderPaymentTerms = PurchaseOrderPaymentTermQuery::create()->whereAdd(PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER_PAYMENT_TERM, $purchaseOrderProgrammedPayments->getPurchaseOrderPaymentTermIds(), ProformaInvoicePaymentTermQuery::NOT_IN)->whereAdd(PurchaseOrderPaymentTerm::ID_PROFORMA_INVOICE_PAYMENT_TERM, $proformaInvoiceProgrammedPayments->getProformaInvoicePaymentTermIds(), ProformaInvoicePaymentTermQuery::NOT_IN)->whereAdd(PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER, $purchaseOrders->getPrimaryKeys())->actives()->find();
     $proformaInvoicePaymentTerms = ProformaInvoicePaymentTermQuery::create()->find();
     $purchaseOrderMissingProgrammedPaymentCollection = new PurchaseOrderProgrammedPaymentCollection();
     $i = 0;
     while ($purchaseOrderPaymentTerm = $purchaseOrderPaymentTerms->read()) {
         $purchaseOrder = $purchaseOrders->getByPK($purchaseOrderPaymentTerm->getIdPurchaseOrder());
         $programmedPayment = ProgrammedPaymentFactory::createFromArray(array('id_programmed_payment' => 'VPP' . $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_currency' => $purchaseOrderPaymentTerm->getCurrency(), 'id_company' => $purchaseOrder->getIdSupplier(), 'type' => ProgrammedPayment::$TypePayment['PurchaseOrder'], 'ammount' => $purchaseOrderPaymentTerm->getAmount(), 'folio' => 'Not Available', 'due_date' => 'Not Available', 'status' => ProgrammedPayment::$TypeStatus['Virtual']));
         $this->getVirtualProgrammedPaymentCollection()->append($programmedPayment);
         $purchaseOrderMissingProgrammedPayment = PurchaseOrderProgrammedPaymentFactory::createFromArray(array('id_purchase_order_programmed_payment' => 'VPOPP' . $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_proforma_invoice_payment_term' => $purchaseOrderPaymentTerm->getIdProformaInvoicePaymentTerm(), 'id_purchase_order_payment_term' => $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_programmed_payment' => $programmedPayment->getIdProgrammedPayment(), 'pieces' => $purchaseOrderPaymentTerm->getPieces(), 'id_purchase_order' => $purchaseOrderPaymentTerm->getIdPurchaseOrder(), 'line' => $purchaseOrderPaymentTerm->getLine()) + $programmedPayment->toArray());
         // 			$proformaInvoiceMissingProgrammedPayment->setIdProgrammedPayment($programmedPayment->getIdProgrammedPayment());
         $purchaseOrderMissingProgrammedPaymentCollection->append($purchaseOrderMissingProgrammedPayment);
         $i++;
     }
     // 		print_r($this->condensePurchasePayments($purchaseOrderMissingProgrammedPaymentCollection, $proformaInvoicePaymentTerms));die;
     $condensedPayments = $condensedPayments->merge($this->condensePurchasePayments($purchaseOrderMissingProgrammedPaymentCollection, $proformaInvoicePaymentTerms));
     return $condensedPayments;
 }
 /**
  *
  * @param int $idPurchaseOrder
  * @param int $idEvent
  */
 private function getMissingPurchaseInformation($idPurchaseOrder, $idEvent)
 {
     $purchaseOrder = PurchaseOrderQuery::create()->findByPKOrThrow($idPurchaseOrder, $this->i18n->_("PurchaseOrder with id {$idPurchaseOrder} not found."));
     $supplier = SapSupplierQuery::create()->findByPKOrThrow($purchaseOrder->getIdSupplier(), $this->i18n->_("SapSupplier with id {$purchaseOrder->getIdSupplier()} not found."));
     $event = EventQuery::create()->findByPKOrThrow($idEvent, $this->i18n->_("Event with id {$idEvent} not found."));
     $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
     $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $purchaseOrderEntries->getDisctinctProformaInvoiceIds())->find();
     $paymentTerms = PurchaseOrderPaymentTermQuery::create()->whereAdd(PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(ProformaInvoicePaymentTerm::ID_EVENT, $event->getIdEvent())->find();
     $purchasePayments = new PurchaseOrderProgrammedPaymentCollection();
     while ($purchaseOrderPaymentTerm = $paymentTerms->read()) {
         $purchaseOrderMissingProgrammedPayment = PurchaseOrderProgrammedPaymentFactory::createFromArray(array('id_purchase_order_programmed_payment' => 'VPOPP' . $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_proforma_invoice_payment_term' => $purchaseOrderPaymentTerm->getIdProformaInvoicePaymentTerm(), 'id_purchase_order_payment_term' => $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'pieces' => $purchaseOrderPaymentTerm->getPieces(), 'id_purchase_order' => $purchaseOrderPaymentTerm->getIdPurchaseOrder(), 'line' => $purchaseOrderPaymentTerm->getLine(), 'id_purchase_order_entry' => $purchaseOrderPaymentTerm->getIdPurchaseOrderEntry(), 'id_programmed_payment' => 'VPP' . $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_currency' => $purchaseOrderPaymentTerm->getCurrency(), 'id_company' => $purchaseOrder->getIdSupplier(), 'type' => ProgrammedPayment::$TypePayment['PurchaseOrder'], 'ammount' => $purchaseOrderPaymentTerm->getAmount(), 'folio' => 'Not Available', 'due_date' => 'Not Available', 'status' => ProgrammedPayment::$TypeStatus['Virtual']));
         $purchasePayments->append($purchaseOrderMissingProgrammedPayment);
     }
     $response = array("docNum" => $purchaseOrder->getSapDocumentNumber(), "docEntry" => $purchaseOrder->getIdPurchaseOrder(), "createDate" => $purchaseOrder->getDeliveryEstimateDate(), "supplier" => $supplier->getCardCode(), "supplierName" => $supplier->getCardname(), "event" => $event->getName());
     while ($purchaseOrderEntries->valid()) {
         $purchaseOrderEntry = $purchaseOrderEntries->read();
         $proformaInvoiceEntry = $proformaInvoiceEntries->getByIdProformaInvoiceAndLine($purchaseOrderEntry->getBaseEntry(), $purchaseOrderEntry->getBaseLine());
         $programmedPayment = $purchasePayments->filterByPurchaseOrderEntry($purchaseOrderEntry)->getOne();
         $response["entries"][] = array("line" => $purchaseOrderEntry->getLine(), "product" => $purchaseOrderEntry->getIdProduct(), "quantity" => $purchaseOrderEntry->getQuantity(), "price" => $purchaseOrderEntry->getPrice(), "currency" => $purchaseOrderEntry->getCurrency(), "requisitions" => implode($proformaInvoiceEntry->getRequisitionIdsToArray()), "PI_Line" => $purchaseOrderEntry->getBaseEntry() . "/" . $purchaseOrderEntry->getBaseLine(), "ammount" => $programmedPayment->getAmmount(), "credits" => 0, "pendingBalance" => $programmedPayment->getAmmount());
     }
     return $response;
 }