project QadFinancials > class BDebtorFinanceCharge > method FCDInvoiceCommitCalculate

Description

Method to calculate the Finance Charges after user selection of Debtor's and Invoices


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorFinanceCharge.FCDInvoiceCommit


program code (program5/bdebtorfinancecharge.p)

for each  bDebtorFinChgMaster:
    assign vdChargedAmountUnApp = 0.
    if  bDebtorFinChgMaster.tlIsDebtorSelected = true 
    then
        for each bDebtorFinanceCharge where
            bDebtorFinanceCharge.tcCustomer = bDebtorFinChgMaster.tcCustomerCode AND
            bDebtorFinanceCharge.tlSelectInvoice = true AND
            (bDebtorFinanceCharge.tcInvoiceType NE {&INVOICETYPE-INVOICE} AND
             bDebtorFinanceCharge.tcInvoiceType NE {&INVOICETYPE-FINANCECHARGE} AND
             bDebtorFinanceCharge.tcInvoiceType NE {&INVOICETYPE-ADJUSTMENT}):
                assign vdChargedAmountUnApp = vdChargedAmountUnApp + bDebtorFinanceCharge.tdOpenAmount.
        end. /* for each bDebtorFinanceCharge where */
        for each bDebtorFinanceCharge where
            bDebtorFinanceCharge.tcCustomer = bDebtorFinChgMaster.tcCustomerCode:
        if bDebtorFinanceCharge.tlSelectInvoice = true
        then do:
             if bDebtorFinanceCharge.tiDInvoice_ID <> 0
                AND bDebtorFinanceCharge.ttDueDate <> ? 
             then do:
                if (bDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-INVOICE} OR
                    bDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE} OR
                    bDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-ADJUSTMENT}) 
                then
                    if not can-do(vcReasonCodeNAFinChg,bDebtorFinanceCharge.tcReasonCode) then
                        assign
                                vdChargedAmountNRC                           = bDebtorFinanceCharge.tdOpenAmount + vdChargedAmountUnApp
                                vdUnappliedCreditAmount                      = bDebtorFinanceCharge.tdOpenAmount - vdChargedAmountNRC
                                vdChargedAmountUnApp                         = if vdChargedAmountUnApp < 0 then 
                                                                                    0 - (ABS(vdChargedAmountUnApp) - ABS(vdUnappliedCreditAmount))
                                                                               else 
                                                                                    ABS(vdChargedAmountUnApp) - ABS(vdUnappliedCreditAmount)
                                vdFinChgNRC                                  = (vdChargedAmountNRC) * (bDebtorFinanceCharge.tiChargedDays / 365) * (vdInterestRate / 100)      
                                bDebtorFinanceCharge.tdChargedAmount         = vdChargedAmountNRC
                                bDebtorFinanceCharge.tdUnappliedCreditAmount = vdUnappliedCreditAmount
                                bDebtorFinanceCharge.tdFinanceCharge         = <M-1 RoundAmount
                                                                                  (input  vdFinChgNRC (idUnroundedAmount), 
                                                                                   input  ? (iiCurrencyID), 
                                                                                   input  vcFCCurrencyCode (icCurrencyCode)) in BDebtorFinanceCharge>.
                assign vcInvoiceDebtorCode         = bDebtorFinanceCharge.tcCustomer
                       vdOpenInvoicesAmount        = vdOpenInvoicesAmount + bDebtorFinanceCharge.tdOpenAmount
                       vdOpenInvoiceUnAppCre       = vdOpenInvoiceUnAppCre + bDebtorFinanceCharge.tdUnappliedCreditAmount
                       vdChargedAmount             = vdChargedAmount + bDebtorFinanceCharge.tdChargedAmount 
                       vdOpenInvoiceFinChg         = vdOpenInvoiceFinChg + bDebtorFinanceCharge.tdFinanceCharge.
             end. /* if bDebtorFinanceCharge.tiDInvoice_ID <> 0 */
             else do: 
                 find first tDebtorFinanceCharge
                     where tDebtorFinanceCharge.tcCustomer  =  bDebtorFinChgMaster.tcCustomerCode
                     AND tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                     AND tDebtorFinanceCharge.tiDInvoice_ID = 0 no-error.
                 if available tDebtorFinanceCharge 
                 then assign
                        tDebtorFinanceCharge.tcCustomer              = bDebtorFinanceCharge.tcCustomer
                        tDebtorFinanceCharge.tcCustDescription       = bDebtorFinanceCharge.tcCustomer
                        tDebtorFinanceCharge.tcInvoiceType           = {&INVOICETYPE-FINANCECHARGE}
                        tDebtorFinanceCharge.tdOpenAmount            = vdOpenInvoicesAmount 
                        tDebtorFinanceCharge.tdUnappliedCreditAmount = vdOpenInvoiceUnAppCre
                        tDebtorFinanceCharge.tdChargedAmount         = vdChargedAmount
                        tDebtorFinanceCharge.tiChargedDays           = 0
                        tDebtorFinanceCharge.tdFinanceCharge         = if vdOpenInvoiceFinChg > vdMinimumFinanceCharge
                                                                            then vdOpenInvoiceFinChg
                                                                       else 
                                                                            vdMinimumFinanceCharge
                        tDebtorFinanceCharge.tlSelectDebtor          = true
                        tDebtorFinanceCharge.tlSelectInvoice         = true
                        vdOpenInvoicesAmount                         = 0
                        vdOpenInvoiceUnAppCre                        = 0
                        vdChargedAmount                              = 0
                        vdChargedAmountNRC                           = 0
                        vdChargedAmountRC                            = 0
                        vdChargedAmountUnApp                         = 0
                        viOverdueDays                                = 0
                        vdOpenInvoiceFinChg                          = 0
                        vdFinChgNRC                                  = 0
                        vdFinChgRC                                   = 0
                        vdFinChgUnApp                                = 0.
             end.           
         end. /* if bDebtorFinanceCharge.tlSelectInvoice = true */
    end. /* for each bDebtorFinanceCharge */
end. /* for each  bDebtorFinChgMaster */