Exchange rate is one of the common factor used in D365 F&O used usually when conversion in between Accounting currency-Reporting currency or transnational currency-Accounting currency is required. Purpose of this code is to retrieve current conversion rate configured in our AX for a particular date.
public CurrencyExchangeRate CMTExchangeRateCalculator( TransDate transDate,VendCurrencyCode fromCurrency,VendCurrencyCode toCurrency)
{
ExchangeRateType ExchangeRateType;
ExchangeRateCurrencyPair exchangeRateCurrencyPair;
real exchRate;
if(fromCurrency != toCurrency)
{
select firstonly exchangeRateCurrencyPair
where
exchangeRateCurrencyPair.ExchangeRateType == Ledger::find(Ledger::current()).DefaultExchangeRateType
&& exchangeRateCurrencyPair.FromCurrencyCode == fromCurrency
&& exchangeRateCurrencyPair.ToCurrencyCode == toCurrency;
exchRate = ExchangeRate::findByDate(exchangeRateCurrencyPair.RecId,transDate).ExchangeRate;
if(exchangeRateCurrencyPair)
{
return (exchRate/100);
}
//for vise-versa case of conversion
else
{
select firstonly exchangeRateCurrencyPair
where
exchangeRateCurrencyPair.ExchangeRateType == Ledger::find(Ledger::current()).DefaultExchangeRateType
&& exchangeRateCurrencyPair.FromCurrencyCode == toCurrency
&& exchangeRateCurrencyPair.ToCurrencyCode == fromCurrency;
exchRate = exchangeRate::findByDate(exchangeRateCurrencyPair.RecId,transDate).ExchangeRate;
return (1/minOne((exchRate/100)));
}
}
//for No conversion rate case
else
{
return 1;
}
}
Comments
Post a Comment