Fixed exchange rate ui to be editable for new rates only, bank payment/deposit use...
[fa-stable.git] / gl / includes / db / gl_db_rates.inc
index f3237d55e575f9d78eea50daaa3ebb99ee0f03d2..1d358ec8ac501d6daf80e68cb1e808fa919d6339 100644 (file)
@@ -65,6 +65,17 @@ function add_exchange_rate($curr_code, $date_, $buy_rate, $sell_rate)
 
 //---------------------------------------------------------------------------------------------
 
+function add_new_exchange_rate($curr_code, $date_, $ex_rate)
+{
+       if (is_company_currency($curr_code) || !$ex_rate)
+               return;
+
+       if (!get_date_exchange_rate($curr_code, $date_))
+               add_exchange_rate($curr_code, $date_, 1.0/$ex_rate, 1.0/$ex_rate);
+}
+
+//---------------------------------------------------------------------------------------------
+
 function delete_exchange_rate($rate_id)
 {
        $sql = "DELETE FROM ".TB_PREF."exchange_rates WHERE id=".db_escape($rate_id);
@@ -90,6 +101,9 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
 {
        global  $path_to_root;
 
+       if ($date != Today())   // no historical rates available
+               return 0;
+
        $curr_a = get_company_pref('curr_default');
        if ($provider == 'ECB')
        {
@@ -137,9 +151,6 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
        } else {
                $contents = url_get_contents("http://".$site.$filename);
        }
-       if (!$contents) {
-               display_warning(sprintf(_("Cannot retrieve currency rate from %s page. Please set the rate manually."), $provider));
-       }
        if ($provider == 'ECB')
        {
                $contents = str_replace ("<Cube currency='USD'", " <Cube currency='EUR' rate='1'/> <Cube currency='USD'", $contents);