Tuesday 7 September 2021

CurrencyExchangeHelper class in Ax / X++

In AX 2012, a class CurrencyExchangeHelper is available to do conversions from one currency to another. Here are some important examples

This method will convert amounts from one currency to another currency:

Static void main(Args args)
{
CurrencyExchangeHelper currencyExchangeHelper;
AmountMst convertedamount;
CurrencyCode FromCurrency =  ‘USD’;
CurrencyCode toCurrency =  ‘EUR’;    
        AmountMst amountToConvert = 5000;
TransDate transactionDate = systemDateGet();

//initializing class CurrencyExchangeHelper
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), transactionDate);

//converting AED to USD
        convertedamount =  currencyExchangeHelper.calculateCurrencyToCurrency(toCurrency, fromCurrency, amountToConvert, true); 
 
info(strFmt(“Converted Amount: %1”, Convertedamount));
}

transaction currency into accounting currency:

Static void main(Args args)
{
CurrencyExchangeHelper currencyExchangeHelper;
AmountMst convertedamount;
CurrencyCode transCurCode = ‘EUR’;   
        AmountMst amountToConvert = 5000;
TransDate transactionDate = systemDateGet();
//initializing class CurrencyExchangeHelper
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), transactionDate );

//converting Transaction To Accounting
    convertedamount =  currencyExchangeHelper.calculateTransactionToAccounting(transCurCode, amountToConvert, true);  
info(strFmt(“Converted Amount: %1”, Convertedamount));

}

accounting  currency into transaction currency:

Static void main(Args args)
{
CurrencyExchangeHelper currencyExchangeHelper;
AmountMst convertedamount;
CurrencyCode AccCurCode = ‘USD’;   
        AmountMst amountToConvert = 5000;
TransDate transactionDate = systemDateGet();
//initializing class CurrencyExchangeHelper
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea("ISL").RecId), transactionDate );

//converting accounting into trancastion currency
    convertedamount =  currencyExchangeHelper.calculateAccountingToTransaction(AccCurCode, amountToConvert, true);  

info(strFmt(“Converted Amount: %1”, Convertedamount));

}



No comments:

Post a Comment

Difference Between Edit And Display Method in Ax

Display Method: The display method means that the method’s return value is being displayed on a form or a report.  This value is fixed and c...