project QadFinancials > class BDebtorReport > method GetExchangeRateForEntity


Parameters


iiTargetEntityIdinputinteger
iiFromEntityIdinputinteger
iiTargetCurrencyIdinputinteger
itExchangeRateDateinputdate
icTargetCurrencyCodeinputcharacter
odOutExchangeRateoutputdecimal
odOutExchangeRateSFoutputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorReport.DebtorAgingHistAcroDomain


program code (program1/bdebtorreport.p)

if iiFromEntityId = iiTargetEntityId then
do:
    assign odOutExchangeRate = 1
           odOutExchangeRateSF = 1.
    return.
end.

/* Get currency of target entity */
<Q-49 run DebtorCurrencyByEntity (all) (Read) (NoCache)
   (input iiFromEntityId, (CompanyId)
    output dataset tqDebtorCurrencyByEntity) in BDebtorReport>

find first tqDebtorCurrencyByEntity where tqDebtorCurrencyByEntity.tiCompany_ID = iiFromEntityId no-error.
if available tqDebtorCurrencyByEntity then
do:
    if vcReportingCurrencyFilter = {&CURRENCYTYPE-CC} 
    then assign viFromCurrencyId   = tqDebtorCurrencyByEntity.tiStatutoryCurrency_ID
                vcFromCurrencyCode = tqDebtorCurrencyByEntity.tcCurrencyCode1
                vcExchangeRateType = {&EXCHANGERATETYPE-STATUTORY}.
    else assign viFromCurrencyId   = tqDebtorCurrencyByEntity.tiCurrency_ID
                vcFromCurrencyCode = tqDebtorCurrencyByEntity.tcCurrencyCode
                vcExchangeRateType = {&EXCHANGERATETYPE-ACCOUNTING}.
    /* Check if currency is the same */
    if viFromCurrencyId = iitargetCurrencyId then
    do:
        assign odOutExchangeRate = 1
               odOutExchangeRateSF = 1.
        return.
    end.

    find first tExchangeRateInfo where 
        tExchangeRateInfo.tcBaseCurrency = vcFromCurrencyCode and
        tExchangeRateInfo.tcToCurrency  = icTargetCurrencyCode no-error.
    if not available tExchangeRateInfo 
    then do:
        /* Get exchange rate */
        <M-11 run GetExchangeRate
           (input  ? (iiCompanyID), 
            input  viFromCurrencyId (iiFromCurrencyID), 
            input  vcFromCurrencyCode (icFromCurrencyCode), 
            input  iiTargetCurrencyId (iiToCurrencyID), 
            input  ? (icToCurrencyCode), 
            input  ? (iiExchangeRateTypeID), 
            input  vcExchangeRateType (icExchangeRateTypeCode), 
            input  itExchangeRateDate (itValidityDate), 
            output odOutExchangeRate (odExchangeRate), 
            output odOutExchangeRateSF (odExchangeScaleFactor), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
        create tExchangeRateInfo.
        assign tExchangeRateInfo.tcCompanyCode              = tqDebtorCurrencyByEntity.tcCompanyCode
               tExchangeRateInfo.tcBaseCurrency             = vcFromCurrencyCode
               tExchangeRateInfo.tcToCurrency               = icTargetCurrencyCode
               tExchangeRateInfo.tcExchangeRateType         = if vcExchangeRateType = {&EXCHANGERATETYPE-ACCOUNTING}
                                                                then {&EXCHANGERATETYPE-ACCOUNTING-TR}
                                                                else {&EXCHANGERATETYPE-STATUTORY-TR}
               tExchangeRateInfo.ttExchangeRateDate         = itExchangeRateDate
               tExchangeRateInfo.tdExchangeRate             = odOutExchangeRate
               tExchangeRateInfo.tdExchangeRateScaleFactor  = odOutExchangeRateSF.
    end.
    else do:
        assign odOutExchangeRate = tExchangeRateInfo.tdExchangeRate
               odOutExchangeRateSF = tExchangeRateInfo.tdExchangeRateScaleFactor.
        return.
    end.
end.