Friday 4 October 2019

Get exchange rate

Somehow it may be not obvious how to get exchange rate for currency code and given date

I've just put a code below to Global class, to have an access from any place in system to this easy way of getting exchange rate.
But of course you can put it wherever you want.

public static CurrencyExchangeRate getExchangeRate(CurrencyCode _transactionCurrency, TransDate _transactionDate)
{
    ExchangeRateHelper      exchangeRateHelper;
    CurrencyExchangeRate    exchangeRate;


    exchangeRateHelper  = ExchangeRateHelper::newExchangeDate(Ledger::current(), _transactionCurrency, _transactionDate);

    exchangeRate       = exchangeRateHelper.getExchangeRate1();

    exchangeRate = exchangeRate / 100; //please be aware of that 100! Check how it is in your system.

    return exchangeRate;
}

There are similar methods in the system in class ExchangeRateHelper, but you have to give one more argument, which in my opinion should be defaulted, but it isn't
Anyway, you can use standard method getExchangeRate1_Static()