Exchange Rate feed from RBA

I have made changes to the Exchange Rates function to include the RBA as a FrontAccounting Exchange Rate provider.

FrontAccounting can work with multiple currencies and uses a feed from an exchange rate provider to convert between the default currency. The default provider is the European Central Bank (ECB).

The Reserve Bank of Australia (RBA) is Australia’s central bank, and they supply an official exchange rate at https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml. I have made changes to the Exchange Rates function to include the RBA as a provider.

Once the changes have been made, to use this, change the config file (config.php) so that:

$xr_providers = array("ECB", "YAHOO", "GOOGLE", "BLOOMBERG","RBA");
$dflt_xr_provider = 4;

The Exchange Rate function will now look like this.

All of these changes can be found on my GitHub at https://github.com/PaulShipley/rba_xr_feed

gl/includes/db/gl_db_rates.inc

@@ -170,6 +170,13 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
        $proto = 'https://';
        $contents=file_get_contents($proto.$site.$filename);
    }
+    elseif ($provider == 'RBA')
+    {
+        $filename = "/rss/rss-cb-exchange-rates.xml";
+        $site = "www.rba.gov.au";
+        $proto = 'https://';
+        $contents=file_get_contents($proto.$site.$filename);
+    }
    if (empty($contents)) {
        if (function_exists('curl_init'))
        {    // first check with curl as we can set short timeout;

@@ -240,6 +258,40 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
        $val = getInnerStr($contents, '<span id="ctl00_M_lblToAmount">', '<');
        $val = str_replace (',', '', $val);
     }
+    elseif ($provider == 'RBA')
+    {
+        $data = new SimpleXMLElement($contents);
+        $data->registerXPathNamespace('ns', 'http://purl.org/rss/1.0/');
+        $data->registerXPathNamespace('cb', 'http://www.cbwiki.net/wiki/index.php/Specification_1.2/');
+
+        $val_a = 0;
+        $val_b = 0;
+       
+        for ($i = 0; $i < count($data->xpath('ns:item')); $i++) {
+            if ($curr_a == 'AUD')
+            {
+                $val_a = 1;
+            }
+            elseif ($curr_a == $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->targetCurrency )
+            {
+                $val_a = (float) $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->observation[0]->value;
+            }
+
+            if ($curr_b == 'AUD') {
+                $val_b = 1;
+            }
+            elseif ($curr_b == $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->targetCurrency )
+            {
+                $val_b = (float) $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->observation[0]->value;
+            }
+        }
+
+        if ($val_b) {
+            $val = $val_a / $val_b;
+        } else {
+            $val = 0;
+        }
+    }
    return $val;
}  /* end function get_extern_rate */

On the Exchange Rates screen (Banking and General Ledger) there is a message towards the bottom of the screen which states “Exchange rates are entered against the company currency.”. This is not very informative. A slight addition to the code will show what the current company currency is and the exchange rate provider. Like so:

   Exchange rates are entered against the company currency = USD (Provider = ECB)

gl/manage/exchange_rates.php

@@ -146,7 +146,7 @@ function display_rate_edit()
    submit_add_or_update_center($selected_id == '', '', 'both');
-    display_note(_("Exchange rates are entered against the company currency."), 1);
+    display_note(_("Exchange rates are entered against the company currency = ".get_company_pref('curr_default')." (Provider = ".$xchg_rate_provider.")"), 1);
}
//---------------------------------------------------------------------------------------------
277 views

Need help? Let me take care of your IT issues.

Share this page

Scroll to Top