project QadFinancials > class BAPMatching > 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 BAPMatching.AdditionalUpdatesAllExtCInvoice
method BAPMatching.ValidateComponentPreAPMCInvoice


program code (program5/bapmatching.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 idExpectedAmount   = ?               then assign idExpectedAmount   = 0.
    if idCalculatedAmount = ?               then assign idCalculatedAmount = 0.

	/* Round calculated amount first */
	assign idCalculatedAmount = <M-87 RoundAmount
                                   (input  idCalculatedAmount (idUnroundedAmount), 
                                    input  iiCurrencyId (iiCurrencyID), 
                                    input  ? (icCurrencyCode)) in BAPMatching>.
	
    /* If there is not passed expeced value, return directly Calculated value */
    if idExpectedAmount = 0
    then return idCalculatedAmount.                                   

    /* If fiscal receiving is activated, we are re starting from the LC values, so always use prefferend amount */
    if vlDomainIsFiscalConfirm
    then assign vdFinalAmount = idExpectedAmount.

    /* Non fiscal receiving */
    else do:
        assign idExpectedAmount   =  <M-63 RoundAmount
                                        (input  idExpectedAmount (idUnroundedAmount), 
                                         input  iiCurrencyId (iiCurrencyID), 
                                         input  ? (icCurrencyCode)) in BAPMatching>
               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. /* Non fiscal receiving */
end. /* MAIN_BLOCK */

return vdFinalAmount.