I am trying to use Epicor’s currency logic to convert a value from a Price list in one currency to the customer’s currency. Ideally, I would give it the “from” and “to” currency and it would provide an exchange rate.
Erp.Internal.Lib.Shared has Erp.Internal.Lib.GetCurrencyRatesEF. This looks very close:
public void searchrate(string pRateGrpCode, string pFromCode, string pToCode, DateTime? searchDate, out decimal pRate, string company = "")
However, it only returns rates that are directly defined. Otherwise, it returns 1.
For example:
I have a rate for EUR > GBP and a rate for USD > GBP. The system can calulate the EUR > USD from this, but the code above does not do that (or I’m using it wrong).
Here is my code:
var convList = new Dictionary<string, decimal>();
using (var rateLib = new Erp.Internal.Lib.GetCurrencyRatesEF(Db))
{
decimal rate = 0;
foreach (var conv in result.Results.Select(conv => new {conv.PriceLst_CurrencyCode, conv.Customer_CurrencyCode, conv.Customer_Company}).Distinct())
{
rateLib.searchrate("MAIN",conv.PriceLst_CurrencyCode,conv.Customer_CurrencyCode,DateTime.Today, out rate, conv.Customer_Company);
convList[conv.PriceLst_CurrencyCode + ">" + conv.Customer_CurrencyCode] = rate;
PublishInfoMessage(conv.PriceLst_CurrencyCode + ">" + conv.Customer_CurrencyCode + ": " + convList[conv.PriceLst_CurrencyCode + ">" + conv.Customer_CurrencyCode],0,0,"","");
}
}