project QadFinancials > class BPaymentSelection > method CreateProposedStagedLines

Description

This method creates tProposedLineStage records and recomments default payment and discount amount for each stage record that is due for the invoice being processed


Parameters


iiCInvoiceIDinputinteger
iiBankNumberIDinputinteger
itDueDateinputdate
icPaymentSelectionDueinputcharacterParameter indicating, for which invoices payment amount should be proposed.
icCInvoiceCurrencyCodeinputcharacterSupplier invoice Currency Code
idOriginalInvoiceAmountTCinputdecimalOriginal invoice amount including Taxes
idOriginalInvoiceAmountNetTCinputdecimalOriginal invoice amount without Taxes
idOpenInvoiceAmountTCinputdecimal
idWhtAmountTCinputdecimalWith-holding tax amount
idNonDiscountableAmountTCinputdecimalNon Discount Amount
ilIsProposePaymentinputlogicalPropose payment of that invoice
ilIsDiscountTaxAtPaymentinputlogicalDiscount tax at payment
odLineTotalPaymentAmountoutputdecimal
odLineTotalDiscountAmountoutputdecimal
odLineTotalWhtAmountoutputdecimalTotal allocated WHT amount
olIsAllStagesSelectedoutputlogicalAre all stages selected
tProposedLineStageoutputtemp-table
itDisCountRefDueDateinputdate
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPaymentSelection.GetToPayObjectsForCInvoice


program code (program3/bpaymentselection.p)

/* Default output values */
assign odLineTotalPaymentAmount  = 0
       odLineTotalDiscountAmount = 0
       odLineTotalWhtAmount      = 0
       olIsAllStagesSelected     = true.


<Q-1 run CInvoiceStageByDueDate (all) (Read) (NoCache)
   (input iiCinvoiceID, (CInvoice_ID)
    input ?, (DueDate)
    output dataset tqCInvoiceStageByDueDate) in BCInvoice >

/* Process all open stages for this invoice that are due */    
for each tqCInvoiceStageByDueDate
    break by tqCInvoiceStageByDueDate.tiCInvoice_ID
          by tqCInvoiceStageByDueDate.ttCInvoiceStageDueDate:
    
    create tProposedLineStage.
    assign tProposedLineStage.tiObject_ID               = iiCInvoiceID
           tProposedLineStage.tiBankNumber_ID           = iiBankNumberID
           tProposedLineStage.tiProposedLine_ID         = tProposedLine.tiProposedLine_ID
           tProposedLineStage.tdOriginalStageAmounTC    = tqCInvoiceStageByDueDate.tdCInvoiceStageAmountTC
           tProposedLineStage.tdOpenStageAmountTC       = tqCInvoiceStageByDueDate.tdCInvoiceStageAmountTC - tqCInvoiceStageByDueDate.tdCInvoiceStageAmtAppliedTC
           tProposedLineStage.tiCInvoiceStage_ID        = tqCInvoiceStageByDueDate.tiCInvoiceStage_ID
           tProposedLineStage.ttStageDueDate            = tqCInvoiceStageByDueDate.ttCInvoiceStageDueDate
           tProposedLineStage.ttStageDiscountDueDate    = tqCInvoiceStageByDueDate.ttCInvoiceStageDiscDate
           tProposedLineStage.tdStageDiscountPercentage = tqCInvoiceStageByDueDate.tdCInvoiceStageDiscPerc.
                    
    /* Distribute Wht amount to stages */
    if not last-of(tqCInvoiceStageByDueDate.tiCInvoice_ID)
    then assign tProposedLineStage.tdDefaultWhtAmtTC = idWhtAmountTC
                                                     * tProposedLineStage.tdOpenStageAmountTC
                                                     / idOpenInvoiceAmountTC
                tProposedLineStage.tdDefaultWhtAmtTC = <M-10 RoundAmount
                                                          (input  tProposedLineStage.tdDefaultWhtAmtTC (idUnroundedAmount), 
                                                           input  ? (iiCurrencyID), 
                                                           input  icCInvoiceCurrencyCode (icCurrencyCode)) in BPaymentSelection>
                vdTotalWhtAmountTC                   = vdTotalWhtAmountTC + tProposedLineStage.tdDefaultWhtAmtTC.
    else assign tProposedLineStage.tdDefaultWhtAmtTC = idWhtAmountTC - vdTotalWhtAmountTC
                vdTotalWhtAmountTC                   = 0.

    /* if we are within the discount due date then apply discount */               
    if itDueDate < tqCInvoiceStageByDueDate.ttCInvoiceStageDiscDate
    then do: 
         if ilIsDiscountTaxAtPayment
         then assign tProposedLineStage.tdDefaultStageDiscountAmountTC = (tProposedLineStage.tdOpenStageAmountTC - 
                                                                         (idNonDiscountableAmountTC * (tProposedLineStage.tdOpenStageAmountTC / tProposedLineStage.tdOriginalStageAmounTC) *  tqCInvoiceStageByDueDate.tdCInvoiceStagePercent / 100)) *  /* part of non-discountable amount for the stage */
                                                                         (tProposedLineStage.tdStageDiscountPercentage / 100).
         else assign tProposedLineStage.tdDefaultStageDiscountAmountTC = ((tProposedLineStage.tdOpenStageAmountTC * idOriginalInvoiceAmountNetTC / idOriginalInvoiceAmountTC) - /* Net amount of the stage which can be discounted - stage amount without taxes */
                                                                         (idNonDiscountableAmountTC * (tProposedLineStage.tdOpenStageAmountTC / tProposedLineStage.tdOriginalStageAmounTC) *  tqCInvoiceStageByDueDate.tdCInvoiceStagePercent / 100)) *  /* part of non-discountable amount for the stage */
                                                                         (tProposedLineStage.tdStageDiscountPercentage / 100).
                
         assign tProposedLineStage.tdDefaultStageDiscountAmountTC = <M-2 RoundAmount
                                                                       (input  tProposedLineStage.tdDefaultStageDiscountAmountTC (idUnroundedAmount), 
                                                                        input  ? (iiCurrencyID), 
                                                                        input  icCInvoiceCurrencyCode (icCurrencyCode)) in BPaymentSelection>
                tProposedLineStage.tdDefaultStagePaymentAmountTC  = tProposedLineStage.tdOpenStageAmountTC
                                                                  - tProposedLineStage.tdDefaultStageDiscountAmountTC
                                                                  - tProposedLineStage.tdDefaultWhtAmtTC.
    end.
    else assign tProposedLineStage.tdDefaultStageDiscountAmountTC = 0
                tProposedLineStage.tdDefaultStagePaymentAmountTC  = tProposedLineStage.tdOpenStageAmountTC
                                                                  - tProposedLineStage.tdDefaultWhtAmtTC.

    /* default the real payment */
    if ilIsProposePayment                                                  AND
       (
        (icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-ALL})              OR
        (icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-DUE} and tProposedLineStage.ttStageDueDate <= itDueDate) OR
        (
          icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-DUEORFINDISC}  and
         (tProposedLineStage.ttStageDueDate <= itDueDate             or
            (itDisCountRefDueDate <> ? and
             tProposedLineStage.ttStageDiscountDueDate <= itDisCountRefDueDate and
             tProposedLineStage.ttStageDiscountDueDate >= itDueDate and
             tProposedLineStage.tdStageDiscountPercentage <> 0) or
            (itDisCountRefDueDate = ? and
             tProposedLineStage.ttStageDiscountDueDate >= itDueDate and
             tProposedLineStage.tdStageDiscountPercentage <> 0)
          )
         )
       )
    then assign tProposedLineStage.tdStageAllocAmountTC    = tProposedLineStage.tdOpenStageAmountTC
                tProposedLineStage.tdStagePaymentAmountTC  = tProposedLineStage.tdDefaultStagePaymentAmountTC
                tProposedLineStage.tdStageDiscountAmountTC = tProposedLineStage.tdDefaultStageDiscountAmountTC
                tProposedLineStage.tdWHTAmtTC              = tProposedLineStage.tdDefaultWhtAmtTC
                tProposedLineStage.tlIsSelected            = true.
    else assign olIsAllStagesSelected                      = false.

    /* keep track of totals for parent */
    assign odLineTotalPaymentAmount  = odLineTotalPaymentAmount  + tProposedLineStage.tdStagePaymentAmountTC
           odLineTotalDiscountAmount = odLineTotalDiscountAmount + tProposedLineStage.tdStageDiscountAmountTC
           odLineTotalWhtAmount      = odLineTotalWhtAmount      + tProposedLineStage.tdWHTAmtTC.
end. /* for each tqCInvoiceStageByDueDate: */