Handling of Foreign Currencies: Difference between revisions

From OpenPetra Wiki
Jump to navigation Jump to search
(Created page with 'Actually I've put put the requirements based on ... and ... into a new object GetCurrencyInfo (in File GL.CommonTools.cs). The object is tested in Test.GL.CommonTools.cs and the …')
 
No edit summary
Line 1: Line 1:
Actually I've put put the requirements based on ... and ... into a new object GetCurrencyInfo (in File GL.CommonTools.cs). The object is tested in Test.GL.CommonTools.cs and the informative test is the routine Test_05_GetCurrencyInfo_2.  
Actually I've put put the requirements based on [[Foreign Currency Transactions]] and [[Testcase requirements for the CommonAccountingTool]] into a new object GetCurrencyInfo (in File GL.CommonTools.cs). The object is tested in Test.GL.CommonTools.cs and the informative test is the routine Test_05_GetCurrencyInfo_2.  


  GetCurrencyInfo getCurrencyInfo = new GetCurrencyInfo("EUR", "JPY");
  GetCurrencyInfo getCurrencyInfo = new GetCurrencyInfo("EUR", "JPY");
Line 16: Line 16:
  decimal exchangeRate = 1/119.7295m;
  decimal exchangeRate = 1/119.7295m;


where 119.7295 is the todays value elsewhere from the internet and in [...] I've explained why we have to use the reziprokal value here.  
where 119.7295 is the todays value elsewhere from the internet and in [[Testcase requirements for the CommonAccountingTool]] I've explained why we have to use the reziprokal value here.  


  decimal exchangeRate = 1/119.7295m;
  decimal exchangeRate = 1/119.7295m;

Revision as of 08:11, 5 April 2011

Actually I've put put the requirements based on Foreign Currency Transactions and Testcase requirements for the CommonAccountingTool into a new object GetCurrencyInfo (in File GL.CommonTools.cs). The object is tested in Test.GL.CommonTools.cs and the informative test is the routine Test_05_GetCurrencyInfo_2.

GetCurrencyInfo getCurrencyInfo = new GetCurrencyInfo("EUR", "JPY");

The constructor of GetCurrencyInfo contains a loadAll-database request for the table a_currency. In this table you can set two row pointer one for the base currency and one for the foreign currency. The base pointer is set once by the constructor and cannot be changed later.

Then you can use RoundBaseCurrencyValue and - if a pointer is set - RoundForeignCurrencyValue to round a currency value to the correct number of digits.

Assert.AreEqual(1.23m, getCurrencyInfo.RoundBaseCurrencyValue(1.23456m), "Round to 2 digits");
Assert.AreEqual(1.0m, getCurrencyInfo.RoundForeignCurrencyValue(1.23456m), "Round to 0 digits");

Above this you can use ToBaseValue and or ToForeignValue to calculate the foreign currency calculations.

The example begins with a

decimal exchangeRate = 1/119.7295m;

where 119.7295 is the todays value elsewhere from the internet and in Testcase requirements for the CommonAccountingTool I've explained why we have to use the reziprokal value here.

decimal exchangeRate = 1/119.7295m;
      	
Assert.AreEqual(0.84m, getCurrencyInfo.ToBaseValue(100.00m, exchangeRate), "Conversion from 100 YEN to 0.83 EUR");
Assert.AreEqual(11973, getCurrencyInfo.ToForeignValue(100.00m, exchangeRate), "Conversion from 100 EUR to 11983 YEN");
Assert.AreEqual(120, getCurrencyInfo.ToForeignValue(1.00m, exchangeRate), "Conversion from 1 EUR to 120 YEN");
       	
getCurrencyInfo.ForeignCurrencyCode = "GBP"; // Change foreign Currency to Pound ...
exchangeRate = 1/0.8801m;
Assert.AreEqual(113.62m, getCurrencyInfo.ToBaseValue(100.00m, exchangeRate), "Conversion from 100 GBP to 113.62 EUR");
Assert.AreEqual(88.01m, getCurrencyInfo.ToForeignValue(100.00m, exchangeRate), "Conversion from 100 EUR to 88.01 GBP");

So you have one object

  1. to handle all available currency infos
  2. and of course the base currency infos too
  3. can easily be switched to an other currency
  4. handles the base-foreign calculation correctly in the sense of om