project QadFinancials > class BCInvoice > method CreatePostingCalculateTotInvAmount

Description

This method calculates total invoice amount including taxes. It can be used when option "Tax excluded" flag is set to true. Then we are getting from the UI invoice amount without taxes (base tax amount).


Parameters


iiCInvoiceIdinputinteger
icCurrencyCodeinputcharacter
ilCInvoiceIsTaxExcludedinputlogical
tApiCInvoiceVatinputtemp-table
icCInvoiceRowidinputcharacter
icCInvoiceTypeinputcharacter
idExchangeRateinputdecimal
idExchangeRateScaleinputdecimal
bdInvoiceAmountTCinput-outputdecimal
bdInvoiceAmountLCinput-outputdecimal
bdInvoiceAmountCCinput-outputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.CreateCIPosting
method BCInvoice.CreateMFPosting
method BCInvoice.DefaultValuesPaymentCondition


program code (program3/bcinvoice.p)

/* ====================================================================================== *
 * Method       : CreatePostingCalculateTotInvAmount                                      *
 * Description  : This method calculates total invoice amount including taxes. It can be  *
 *                used when option "Tax excluded" flag is set to true. Then we are        *
 *                getting from the UI invoice amount without taxes (base tax amount).     *
 * ====================================================================================== */
 
MAIN_BLOCK:
do on error undo, throw:
    /* Pre-validation block */
    if ilCInvoiceIsTaxExcluded <> true then leave MAIN_BLOCK.
   
    /* cumulate values posting on VAT */
    assign vdVatTC  = 0
           vdVatCC  = 0
           vdVatLC  = 0.

    for each tApiCInvoiceVat where
             tApiCInvoiceVat.tc_ParentRowid = icCInvoiceRowid and
             tApiCInvoiceVat.tc_Status     <> "D":U:

        /* TC */
        if icCInvoiceType = {&INVOICETYPE-INVOICE} or
           icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
        then assign vdVatTC = vdVatTC + tApiCInvoiceVat.CInvoiceVatVatDebitTC - tApiCInvoiceVat.CInvoiceVatVatCreditTC.
        else assign vdVatTC = vdVatTC + tApiCInvoiceVat.CInvoiceVatVatCreditTC - tApiCInvoiceVat.CInvoiceVatVatDebitTC.

        /* LC */
        if icCurrencyCode = vcCompanyLC
        then assign vdVatLC = vdVatTC.
        else assign vdVatLC  = <M-20 RoundAmount
                                  (input  vdVatTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                   input  viCompanyLCId (iiCurrencyID), 
                                   input  vcCompanyLC (icCurrencyCode)) in BApplicationProperty>.
    
        /* CC */
        if bdInvoiceAmountCC <> 0 and bdInvoiceAmountCC <> ?
        then do:
            if viCompanyCCId = viCompanyLCId or
               vcCompanyCC   = vcCompanyLC
            then assign vdVatCC = vdVatLC.
            else if vcCompanyCC   = icCurrencyCode                       
            then assign vdVatCC  = vdVatTC.
            else
            do:
                assign vdExRateCC      = bdInvoiceAmountTC / bdInvoiceAmountCC
                       vdExRateScaleCC = 1
                       vdVatCC         = <M-23 RoundAmount
                                            (input  vdVatTC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount), 
                                             input  viCompanyCCId (iiCurrencyID), 
                                             input  vcCompanyCC (icCurrencyCode)) in BCInvoice>.
            end.                
        end. /*if idInvoiceAmountCC <> 0 and idInvoiceAmountCC <> ? then */
    end. /* for each tApiCInvoiceVat where */

    /* Adjust invoice amount */
    assign bdInvoiceAmountTC = bdInvoiceAmountTC + vdVatTC
           bdInvoiceAmountLC = (if bdInvoiceAmountLC <> 0 and bdInvoiceAmountLC <> ? 
                                then bdInvoiceAmountLC + vdVatLC
                                else bdInvoiceAmountLC)
           bdInvoiceAmountCC = (if bdInvoiceAmountCC <> 0 and bdInvoiceAmountCC <> ? 
                                then bdInvoiceAmountCC + vdVatCC
                                else bdInvoiceAmountCC).
end. /* MAIN_BLOCK */