project QadFinancials > class BCInvoice > method GetAmountPreferencingExpected

function returns decimal

Description

This method calculates amount based on expected amount and calculated amount. It is trying to prioritize expected amount if the amount is almost the same as calcualted amount (based on rounding method of currency). If the amounts are really differnet, then the calculated is retrieved.


Parameters


idExpectedAmountinputdecimalExpected amount. Prioritized over calcualted when almost the same.
idCalculatedAmountinputdecimal
iiCurrencyIdinputinteger


Internal usage


QadFinancials
method BCInvoice.CreateCIPostingTax
method BCInvoice.UpdateCInvoiceFromAPM
method BCInvoice.ValidateComponentPreVat


program code (program5/bcinvoice.p)

/* ====================================================================================== *
 * Description  : This method calculates amount based on expected amount and calculated   *
 *                amount. It is trying to prioritize expected amount if the amount is     *
 *                almost the same as calcualted amount (based on rounding method of       *
 *                currency). If the amounts are really differnet, then the calculated is  * 
 *                retrieved.                                                              *
 * ====================================================================================== */
 
MAIN_BLOCK:
do on error undo, throw:
    /* Default output parameters */
    assign vdFinalAmount = 0.
    
    /* Pre-validation block */
    if iiCurrencyId = 0 or iiCurrencyId = ? then assign iiCurrencyId       = viCompanyLCId.
    if idCalculatedAmount = ?               then assign idCalculatedAmount = 0.
	
	/* Round calculated amount first */
	assign idCalculatedAmount = <M-87 RoundAmount
                                   (input  idCalculatedAmount (idUnroundedAmount), 
                                    input  iiCurrencyId (iiCurrencyID), 
                                    input  ? (icCurrencyCode)) in BCInvoice>.

    /* If there is not passed expeced value, return directly Calculated value */
    if idExpectedAmount = 0 or
       idExpectedAmount = ?
    then return idCalculatedAmount.
    
    /* If this invoice is created with activated fiscal receiving, retuern expected amount */
    if vlDomainIsFiscalConfirmBCI
    then assign vdFinalAmount = idExpectedAmount.

    else do:
        assign idExpectedAmount   = <M-68 RoundAmount
                                       (input  idExpectedAmount (idUnroundedAmount), 
                                        input  iiCurrencyId (iiCurrencyID), 
                                        input  ? (icCurrencyCode)) in BCInvoice> 
               
               vdAmountDifference = abs(idCalculatedAmount - idExpectedAmount).
               
        /* Is expected value almost the same as calculated */
        find tCurrencyRounding where
             tCurrencyRounding.tiCurrencyID = iiCurrencyId
             no-error.
             
        if available tCurrencyRounding
        then if vdAmountDifference <= tCurrencyRounding.tdRoundingMethodUnit
             then assign vdFinalAmount = idExpectedAmount.
             else assign vdFinalAmount = idCalculatedAmount.
        else assign vdFinalAmount = idCalculatedAmount.    
    end. /* NOT if vlDomainIsFiscalConfirmBC */
end. /* MAIN_BLOCK */

return vdFinalAmount.