project QadFinancials > class BDPaymentSelection > method GetToPayObjectsStages

Description

Get invoices to pay for staged payments


Parameters


iiDInvoiceIDinputinteger
icParentRowIDinputcharacter
itRefDueDateinputdate
icDInvoiceCurrencyCodeinputcharacter
idInvoiceOriginalAmountTCinputdecimalOriginal Invoice Amount TC
idNonDiscountableAmountTCinputdecimal
idInvoiceVatTCinputdecimalVAT TC
ilIsDiscountTaxAtPaymentinputlogical
ilIsProposePaymentinputlogical
icPaymentSelectionDueinputcharacter
odInvoiceTotalPaymentAmountTCoutputdecimal
odInvoiceTotalDiscountAmountTCoutputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDPaymentSelection.GetToPayObjects


program code (program6/bdpaymentselection.p)

assign viCount                        = 0
       odInvoiceTotalPaymentAmountTC  = 0
       odInvoiceTotalDiscountAmountTC = 0
       vdInvoiceDiscountableAmountTC  = (if ilIsDiscountTaxAtPayment
                                         then idInvoiceOriginalAmountTC - idNonDiscountableAmountTC
                                         else idInvoiceOriginalAmountTC - idNonDiscountableAmountTC - idInvoiceVatTC).

<Q-57 run DInvoiceStageByDueDate (all) (Read) (NoCache)
   (input iiDInvoiceID, (DInvoiceID)
    input ?, (DueDate)
    output dataset tqDInvoiceStageByDueDate) in BDInvoice>
 
for each tqDInvoiceStageByDueDate:

    /* Check, if there is still free amount on the stage, which can be allocated */
    if tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC = tqDInvoiceStageByDueDate.tdDInvoiceStageAmtAppliedTC
    then next.

    create tDIncSelLineStage.
    assign tDIncSelLineStage.tc_ParentRowid                 = icParentRowID
           tDIncSelLineStage.tiDInvoiceStageId              = tqDInvoiceStageByDueDate.tiDInvoiceStage_ID
           tDIncSelLineStage.tdStageDiscountPerc            = tqDInvoiceStageByDueDate.tdDInvoiceStageDiscPerc
           tDIncSelLineStage.ttStageDueDate                 = tqDInvoiceStageByDueDate.ttDInvoiceStageDueDate
           tDIncSelLineStage.ttStageDiscDate                = tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
           tDIncSelLineStage.tdOpenStageAmountTC            = tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC 
                                                              - tqDInvoiceStageByDueDate.tdDInvoiceStageAmtAppliedTC
           tDIncSelLineStage.tdDefaultIncSelLineStageIntRat = tDIncSelLineStage.tdIncSelLineStageIntRate
           tDIncSelLineStage.ttDefaultIncSelLineStageDueDat = tDIncSelLineStage.ttStageDueDate
           tDIncSelLineStage.tcDefaultIncSelLineStageStatus = tDIncSelLineStage.tcIncSelLineStageStatus
           tDIncSelLineStage.tdOriginalStageAmountTC        = tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC.
    
    /* Calculate Payment and discount amount */
    /* Currently Discount Tax at Payment is not considered for staged credit terms */
    if itRefDueDate <= tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
    then assign tDIncSelLineStage.tdDefaultStageDiscountAmountTC = vdInvoiceDiscountableAmountTC
                                                                        * (tDIncSelLineStage.tdOpenStageAmountTC / idInvoiceOriginalAmountTC)
                                                                        * (tqDInvoiceStageByDueDate.tdDInvoiceStageDiscPerc / 100)
                tDIncSelLineStage.tdDefaultStageDiscountAmountTC = <M-65 RoundAmount
                                                                      (input  tDIncSelLineStage.tdDefaultStageDiscountAmountTC (idUnroundedAmount), 
                                                                       input  ? (iiCurrencyID), 
                                                                       input  icDInvoiceCurrencyCode (icCurrencyCode)) in BDPaymentSelection>
                tDIncSelLineStage.tdDefaultStagePaymentAmountTC  = tDIncSelLineStage.tdOpenStageAmountTC
                                                                   - tDIncSelLineStage.tdDefaultStageDiscountAmountTC.
                                                                     
    else assign tDIncSelLineStage.tdDefaultStageDiscountAmountTC = 0
                tDIncSelLineStage.tdDefaultStagePaymentAmountTC  = tDIncSelLineStage.tdOpenStageAmountTC.
    
    /* Default the real payment amounts when the line is selected */
    if ilIsProposePayment                                                  and
       ((icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-ALL})              or
        (icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-DUE}           and
         tDIncSelLineStage.ttStageDueDate <= itRefDueDate            )    or
        (icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-DUEORFINDISC}  and
         (tDIncSelLineStage.ttStageDueDate <= itRefDueDate          or
          (tDIncSelLineStage.ttStageDiscDate >= itRefDueDate and
           tDIncSelLineStage.tdStageDiscountPerc <> 0))))
    then assign tDIncSelLineStage.tlIsSelected            = true
                tDIncSelLineStage.tdStageAllocAmountTC    = tDIncSelLineStage.tdOpenStageAmountTC
                tDIncSelLineStage.tdStagePaymentAmountTC  = tDIncSelLineStage.tdDefaultStagePaymentAmountTC
                tDIncSelLineStage.tdStageDiscountAmountTC = tDIncSelLineStage.tdDefaultStageDiscountAmountTC.
    else assign tDIncSelLineStage.tlIsSelected            = false.

    /* keep track of the total amounts for the invoice */
    assign odInvoiceTotalDiscountAmountTC = odInvoiceTotalDiscountAmountTC + tDIncSelLineStage.tdDefaultStageDiscountAmountTC
           odInvoiceTotalPaymentAmountTC  = odInvoiceTotalPaymentAmountTC  + tDIncSelLineStage.tdDefaultStagePaymentAmountTC.       
end. /* for each tqDInvoiceStageDueDate */