Purpose

To obtain the current exchange rates from the web for all other currencies used in the specific FA install for the chosen company vis-a-vis the default currency of the company and then tweak the value before storing it along with an settable date (default today) from which it should be operational.

Procedure

  • Currencies acceptable to the company are set in Banking and General Ledger -> Currencies
  • Default Currency of Company is set in Setup -> Company Setup
  • Get Current Exchange Rates from the Web and set the optionally tweaked rate and Effective Date at Banking and General Ledger -> Exchange Rates
  • The Exchange Rate Request page still lists the default currency for choice but does not display the default currency in the rate obtained page.
  • If any currency rate is huge against the domestic currency and the rounding errors are getting big, then increase the currency rate decimals in Preferences (Setup -> Display Setup) say from 4 to 6 or 8. Forum Post
  • Forum Post: Exchange rate is got from selected web source when first transaction on the day made in a given currency is entered. So, if you do not make transactions on every day, you will not have complete exchange rate tables.

Tips and Tricks

As of v2.3+, the order of using the Exchange Rate Provider is: ECB, YAHOO and then GOOGLE. No fiddling with code is necessary now. The file called /gl/includes/db/gl_db_rates.inc contains the code and the order of processing that can be rearranged for quicker and differently ordered rate acquisition as the case may be. As of v2.3.12+, the default Exchange Rate Provider can be set in the config.php file and BLOOMBERG is now an additional choice. The URLs used are:

It is possible that in the case of YAHOO (Old URL), more than one entry arises whence the first one will be chosen. Hence in BugFix 1792 - FA v2.3.12+ a new processing code with a new url came into effect:

Development Notes

  • As of FA v2.3.12+ only rate_buy field in the exchange_rates table is used in FA.
  • The field rate_sell is not used (may be used in future).
  • The rate_sell field is populated with the same value using line 74 (FA v2.3.22+) in gl/includes/db/gl_db_rates.inc:

add_exchange_rate($curr_code, $date_, $ex_rate, $ex_rate);

Archive

We still use ECB as our stable exchange rates provider, however, we are avare of that the coverage is not good for South America, Africa and Asia, so we have implemented it so that it is possible to swap provider. In CVS Main, a file called /gl/includes/db/gl_db_rates.inc has been updated so it is possible to use YAHOO or GOOGLE instead of ECB. Both YAHOO and GOOGLE have almost all currency rates in the world. These changes are going to release 2.2.2, but if you want this to be available in your 2.2 you will have to download this file from the CVS repository. http://frontaccounting.cvs.sourceforge.net/viewvc/frontaccounting/frontaccount/gl/includes/db/gl_db_rates.inc?view=log And you will have to create the following locale.inc file and place it in the /lang/xx_YY folder, where xx is the language and YY is the country. F.i. en_US.

<?php

class Hooks {

    function retrieve_exrate($curr, $date)
    {
        return get_extern_rate($curr, 'YAHOO', $date);
        //return get_extern_rate($curr, 'GOOGLE', $date);
    }

}

?>

This will use YAHOO instead of ECB. Comment the YAHOO line and uncomment the GOOGLE line if you want to use GOOGLE instead. We do not guarantee that the currency rates are provided correctly, but I guess this is better than nothing for countries not served by ECB.

Troubleshooting

  • Most common errors that prevent the exchange rate from getting into FA is the lack of a proper DNS
  • php5-curl and possibly curl) need to be installed
  • Use the following in a script to check some functions availability in FA:
<?php
// Checks PHP functions availability
// Author: Ap.Muthu
// Released on: 2017-10-28

echo 'Curl: ', (function_exists('curl_version') ? 'Enabled' : 'Disabled') . '<'.'br>';
echo 'Curl Init: ', (function_exists('curl_init') ? 'Enabled' : 'Disabled') . '<'.'br>';
echo 'file_get_contents: ', (file_get_contents(__FILE__) ? 'Enabled' : 'Disabled');
// FA Function
// echo 'url_get_contents: ', (function_exists('url_get_contents') ? 'Enabled' : 'Disabled') '<'.'br>';

?>
  • Use the following to check the GOOGLE Exchange Rate Provider and modify it for others
<?php
// This script outputs the GOOGLE Exchange Rate Provider response
// It can be modified for other providers as well
// Author: Ap.Muthu
// First Released on 2017-10-28
// Code based on FA exchange rate acquiring script
// Check that your DNS resolves like with a Trace Route or Ping

	$filename = "/finance/converter?a=1&from=USD&to=INR";
	$site = "finance.google.com";

ob_start();
$out = fopen('php://output', 'w');
$contents = '';

   	$ch = curl_init();

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $out);

    curl_setopt ($ch, CURLOPT_URL, 'http://'.$site.$filename);
	curl_setopt ($ch, CURLOPT_COOKIEJAR, "tmp/cookie.txt");
    curl_setopt ($ch, CURLOPT_HEADER, 0);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	// prevent warning while safe_mode/open_basedir on (redirection doesn't occur at least on ECB page)
	if (!ini_get('safe_mode') && !ini_get('open_basedir'))
    	curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
    $contents = curl_exec ($ch);
	curl_close($ch);

$debug = ob_get_clean();
echo "<"."pre>".$debug."</"."pre>";
//	echo (strlen($contents) > 10) ? 'Curl can get Exchange Rates' : 'Curl Fails';

?>

These scripts are available here.