Exchange Rates Handler

Belias
Member Posts: 2,998
Hi everyone, I recently have had to deal with exchange rates, and a thing I found really boring is to manage all the cases below:
if i start from LCY amount and i put it on FCY amount then exchrateLCYtoFCY
if i start from FCY amount and i put it on LCY amount then exchrateFCYtoLCY
and so on....
the function i post here, receive the six parameters, and depending on the values of CDFromCurrency and CDToCurrency decides what is the function to run (and if it must be run). At the end, it rounds the value to the correct amount.
Parameters:
Var Name DataType Subtype Length
No vDECAmount Decimal
No vCDFromCurrency Code 10
No vCDToCurrency Code 10
No vGMADate Date
No vDECCurrFactor Decimal
No vTFUnitAmount Boolean
Locals:
Name DataType Subtype Length
lTBCurrency Record Currency
if i start from LCY amount and i put it on FCY amount then exchrateLCYtoFCY
if i start from FCY amount and i put it on LCY amount then exchrateFCYtoLCY
and so on....
the function i post here, receive the six parameters, and depending on the values of CDFromCurrency and CDToCurrency decides what is the function to run (and if it must be run). At the end, it rounds the value to the correct amount.
Parameters:
Var Name DataType Subtype Length
No vDECAmount Decimal
No vCDFromCurrency Code 10
No vCDToCurrency Code 10
No vGMADate Date
No vDECCurrFactor Decimal
No vTFUnitAmount Boolean
Locals:
Name DataType Subtype Length
lTBCurrency Record Currency
IF vDECAmount <> 0 THEN BEGIN IF vCDFromCurrency <> vCDToCurrency THEN BEGIN IF vCDToCurrency = '' THEN BEGIN IF (vDECCurrFactor = 0) OR (vDECCurrFactor = 1) THEN //Correction For Currency factor vDECCurrFactor := TBCurrExhRate.ExchangeRate(vGMADate,vCDFromCurrency); vDECAmount := TBCurrExhRate.ExchangeAmtFCYToLCY(vGMADate,vCDFromCurrency,vDECAmount,vDECCurrFactor); END ELSE BEGIN IF vCDFromCurrency = '' THEN BEGIN IF (vDECCurrFactor = 0) OR (vDECCurrFactor = 1) THEN //Correction For Currency factor vDECCurrFactor := TBCurrExhRate.ExchangeRate(vGMADate,vCDToCurrency); vDECAmount := TBCurrExhRate.ExchangeAmtLCYToFCY(vGMADate,vCDToCurrency,vDECAmount,vDECCurrFactor); END ELSE BEGIN vDECAmount := TBCurrExhRate.ExchangeAmtFCYToFCY(vGMADate,vCDFromCurrency,vCDToCurrency,vDECAmount); END; END; END; IF vTFUnitAmount THEN BEGIN IF vCDToCurrency = '' THEN BEGIN TBGLSetup.GET; vDECAmount := ROUND(vDECAmount,TBGLSetup."Unit-Amount Rounding Precision"); END ELSE BEGIN lTBCurrency.GET(vCDToCurrency); vDECAmount := ROUND(vDECAmount,lTBCurrency."Unit-Amount Rounding Precision"); END; END ELSE BEGIN IF vCDToCurrency = '' THEN BEGIN TBGLSetup.GET; vDECAmount := ROUND(vDECAmount,TBGLSetup."Amount Rounding Precision"); END ELSE BEGIN lTBCurrency.GET(vCDToCurrency); vDECAmount := ROUND(vDECAmount,lTBCurrency."Amount Rounding Precision"); END; END; END; EXIT(vDECAmount);
0
Comments
-
Neat.0
-
I automated the "choice" of the standard functions of nav
P.S.: there's a little bug if the user is on an invoice and changes the currency factor: i already corrected it and i'll post it as soon as possible...i'm a little busy now, sorry0 -
yes, I saw it in the function as I was looking at it.
As for the bug. I suggest to send it to MS.0 -
ara3n wrote:yes, I saw it in the function as I was looking at it.
As for the bug. I suggest to send it to MS.
i didn't thought that the user can change the currency factor, and this function does not receive a currency factor as parameter, therefore the currency factor is always recalculated, and there can be some inconsistencies.
I'm now editing my post in order to correct the function0 -
Belias wrote:Neat.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
#-o another little bug (before the go live...phew)
here's the old lineIF vDECCurrFactor = 0 THEN
here's the new lineIF (vDECCurrFactor = 0) OR (vDECCurrFactor = 1) THEN
i corrected the code above, too.
this is an important correction in my project, because i am adding lines to an invoice, taking values from other documents: if the invoice is in LCY and someone does asalesinvhead."currency factor" := currencyexchrates.exchangerate(salesinvhead."posting date","salesinvhead"."currency code");
the resulting factor is 1.
if my "other document" is in USD, it must be converted, before adding it to the sales invoice line
@kriki: i posted this to MS connect...were you meaning to post this in that place when you said "send it to MS"?0 -
They said that they'll take into consideration my function for the next release!
Should i hope for it or MS said this to everyone?
I'd be really proud if will become a standard functionality 8)
P.S.: i forgot a TBGLSetup.GET; in the function :oops: -Just added-0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions