Automatic update currency option added.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 19 May 2009 15:16:02 +0000 (15:16 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 19 May 2009 15:16:02 +0000 (15:16 +0000)
gl/includes/db/gl_db_currencies.inc
gl/manage/currencies.php
includes/ui/ui_view.inc
sql/alter2.2.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index 111b83dc8ee67a9612e055054a16a0d095d0ed92..342cddc4eb6275c6a45424fa861c760547cc8eb7 100644 (file)
 ***********************************************************************/
 //---------------------------------------------------------------------------------------------
 
-function update_currency($curr_abrev, $symbol, $currency, $country, $hundreds_name)
+function update_currency($curr_abrev, $symbol, $currency, $country, 
+       $hundreds_name, $auto_update)
 {
        $sql = "UPDATE ".TB_PREF."currencies SET currency=".db_escape($currency).", curr_symbol='$symbol',
-               country=".db_escape($country).", hundreds_name=".db_escape($hundreds_name)." WHERE curr_abrev = '$curr_abrev'";
+               country=".db_escape($country).", hundreds_name=".db_escape($hundreds_name)
+               .",auto_update = '$auto_update'"." WHERE curr_abrev = '$curr_abrev'";
 
        db_query($sql, "could not update currency for $curr_abrev");
 }
 
 //---------------------------------------------------------------------------------------------
 
-function add_currency($curr_abrev, $symbol, $currency, $country, $hundreds_name)
+function add_currency($curr_abrev, $symbol, $currency, $country, 
+       $hundreds_name, $auto_update)
 {
-       $sql = "INSERT INTO ".TB_PREF."currencies (curr_abrev, curr_symbol, currency, country, hundreds_name)
-               VALUES (".db_escape($curr_abrev).", '$symbol', ".db_escape($currency).", ".db_escape($country).", ".db_escape($hundreds_name).")";
+       $sql = "INSERT INTO ".TB_PREF."currencies (curr_abrev, curr_symbol, currency, country, 
+               hundreds_name, auto_update)
+               VALUES (".db_escape($curr_abrev).", '$symbol', ".db_escape($currency)
+               .", ".db_escape($country).", ".db_escape($hundreds_name)
+               .",".db_escape($auto_update).")";
 
        db_query($sql, "could not add currency for $curr_abrev");
 }
index 2ea60107e55b8573f3e290ab19fe828515af4d50..4d5bf91892f1dc1557fb2b05b0c1345991c03f6c 100644 (file)
@@ -65,14 +65,14 @@ function handle_submit()
        {
 
                update_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'], 
-                       $_POST['country'], $_POST['hundreds_name']);
+                       $_POST['country'], $_POST['hundreds_name'], check_value('auto_update'));
                display_notification(_('Selected currency settings has been updated'));
        } 
        else 
        {
 
                add_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'], 
-                       $_POST['country'], $_POST['hundreds_name']);
+                       $_POST['country'], $_POST['hundreds_name'], check_value('auto_update'));
                display_notification(_('New currency has been added'));
        }       
        $Mode = 'RESET';
@@ -151,7 +151,7 @@ function display_currencies()
     $result = get_currencies(check_value('show_inactive'));
     start_table($table_style);
     $th = array(_("Abbreviation"), _("Symbol"), _("Currency Name"),
-       _("Hundredths name"), _("Country"), "", "");
+       _("Hundredths name"), _("Country"), _("Auto update"), "", "");
        inactive_control_column($th);
     table_header($th); 
     
@@ -172,6 +172,8 @@ function display_currencies()
                label_cell($myrow["currency"]);
                label_cell($myrow["hundreds_name"]);
                label_cell($myrow["country"]);
+               label_cell(     $myrow[1] == $company_currency ? '-' : 
+                       ($myrow["auto_update"] ? _('Yes') :_('No')), "align='center'");
                inactive_control_cell($myrow["curr_abrev"], $myrow["inactive"], 'currencies', 'curr_abrev');
                edit_button_cell("Edit".$myrow["curr_abrev"], _("Edit"));
                if ($myrow["curr_abrev"] != $company_currency)
@@ -206,6 +208,7 @@ function display_currency_edit($selected_id)
                        $_POST['CurrencyName']  = $myrow["currency"];
                        $_POST['country']  = $myrow["country"];
                        $_POST['hundreds_name']  = $myrow["hundreds_name"];
+                       $_POST['auto_update']  = $myrow["auto_update"];
                }
                hidden('Abbreviation');
                hidden('selected_id', $selected_id);
@@ -213,14 +216,15 @@ function display_currency_edit($selected_id)
        } 
        else 
        { 
-               text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);         
+               $_POST['auto_update']  = 1;
+               text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);
        }
 
        text_row_ex(_("Currency Symbol:"), 'Symbol', 10);
        text_row_ex(_("Currency Name:"), 'CurrencyName', 20);
        text_row_ex(_("Hundredths Name:"), 'hundreds_name', 15);        
        text_row_ex(_("Country:"), 'country', 40);      
-
+       check_row(_("Automatic exchange rate update:"), 'auto_update', get_post('auto_update'));
        end_table(1);
 
        submit_add_or_update_center($selected_id == '', '', 'both');
index 186c7a1414d70b1f6ab7924e2468dcd1939bf1f2..f95182abe46bfa9514d1ce73b1018e72bc5e9707 100644 (file)
@@ -257,9 +257,12 @@ function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=
                if ($date_ == Today()) {
                        $rate = get_date_exchange_rate($currency, $date_);
                        if (!$rate) {
-                               $rate = get_ecb_rate($currency);
-                               if ($rate) 
-                                       add_exchange_rate($currency, $date_, $rate, $rate);
+                               $row = get_currency($currency);
+                               if ($row['auto_update']) {
+                                       $rate = retrieve_exrate($currency, $date_);
+                                       if ($rate) 
+                                               add_exchange_rate($currency, $date_, $rate, $rate);
+                               }
                        }
                }
                if (!$rate)
index 719b7d2faf1348e8c9ee497548792ae4bcc892d5..d303fd35d2e51afecfd82ef1ee191863c8ac8741 100644 (file)
@@ -67,4 +67,5 @@ CREATE TABLE `0_audit_trail` (
   KEY (`fiscal_year`, `gl_seq`)
 ) TYPE=InnoDB  ;
 
-ALTER TABLE `0_stock_master` ADD COLUMN  `no_sale` tinyint(1) NOT NULL default '0';
+ALTER TABLE `0_stock_master` ADD COLUMN `no_sale` tinyint(1) NOT NULL default '0';
+ALTER TABLE `0_currencies` ADD COLUMN `auto_update` tinyint(1) NOT NULL default '1';
index 60650bd33c5effecd064f9938ffd817dea1f109c..57fdacf09d485f70a645b0c868c66924600edb1a 100644 (file)
@@ -59,7 +59,7 @@ CREATE TABLE `0_audit_trail` (
   `type` smallint(6) unsigned NOT NULL default '0',
   `trans_no` int(11) unsigned NOT NULL default '0',
   `user` smallint(6) unsigned NOT NULL default '0',
-  `stamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `stamp` timestamp NOT NULL,
   `description` varchar(60) default NULL,
   `fiscal_year` int(11) NOT NULL,
   `gl_date` date NOT NULL default '0000-00-00',
@@ -432,6 +432,7 @@ CREATE TABLE `0_currencies` (
   `curr_symbol` varchar(10) NOT NULL default '',
   `country` varchar(100) NOT NULL default '',
   `hundreds_name` varchar(15) NOT NULL default '',
+  `auto_update` tinyint(1) NOT NULL default '1',
   `inactive` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`curr_abrev`)
 ) TYPE=MyISAM  ;
@@ -439,11 +440,11 @@ CREATE TABLE `0_currencies` (
 
 ### Data of table `0_currencies` ###
 
-INSERT INTO `0_currencies` VALUES ('Kronor', 'SEK', 'kr', 'Sweden', '?ren', '0');
-INSERT INTO `0_currencies` VALUES ('Kroner', 'DKK', 'kr.', 'Denmark', '?re', '0');
-INSERT INTO `0_currencies` VALUES ('Euro', 'EUR', '?', 'Europe', 'Cents', '0');
-INSERT INTO `0_currencies` VALUES ('Pounds', 'GBP', '?', 'England', 'Pence', '0');
-INSERT INTO `0_currencies` VALUES ('US Dollars', 'USD', '$', 'United States', 'Cents', '0');
+INSERT INTO `0_currencies` VALUES ('Kronor', 'SEK', 'kr', 'Sweden', '?ren', '1', '0');
+INSERT INTO `0_currencies` VALUES ('Kroner', 'DKK', 'kr.', 'Denmark', '?re', '1', '0');
+INSERT INTO `0_currencies` VALUES ('Euro', 'EUR', '?', 'Europe', 'Cents', '1', '0');
+INSERT INTO `0_currencies` VALUES ('Pounds', 'GBP', '?', 'England', 'Pence', '1', '0');
+INSERT INTO `0_currencies` VALUES ('US Dollars', 'USD', '$', 'United States', 'Cents', '1', '0');
 
 
 ### Structure of table `0_cust_allocations` ###
index 76658b745b7505e6a07358fb95284ec5a91bdb8a..c0952a6567f2ec76fda61348e454f5dc6d3774a8 100644 (file)
@@ -54,7 +54,7 @@ CREATE TABLE `0_audit_trail` (
   `type` smallint(6) unsigned NOT NULL default '0',
   `trans_no` int(11) unsigned NOT NULL default '0',
   `user` smallint(6) unsigned NOT NULL default '0',
-  `stamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `stamp` timestamp NOT NULL,
   `description` varchar(60) default NULL,
   `fiscal_year` int(11) NOT NULL,
   `gl_date` date NOT NULL default '0000-00-00',
@@ -400,6 +400,7 @@ CREATE TABLE `0_currencies` (
   `curr_symbol` varchar(10) NOT NULL default '',
   `country` varchar(100) NOT NULL default '',
   `hundreds_name` varchar(15) NOT NULL default '',
+  `auto_update` tinyint(1) NOT NULL default '1',
   `inactive` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`curr_abrev`)
 ) TYPE=MyISAM  ;
@@ -407,9 +408,9 @@ CREATE TABLE `0_currencies` (
 
 ### Data of table `0_currencies` ###
 
-INSERT INTO `0_currencies` VALUES ('Euro', 'EUR', '?', 'Europe', 'Cents', '0');
-INSERT INTO `0_currencies` VALUES ('Pounds', 'GBP', '?', 'England', 'Pence', '0');
-INSERT INTO `0_currencies` VALUES ('US Dollars', 'USD', '$', 'United States', 'Cents', '0');
+INSERT INTO `0_currencies` VALUES ('Euro', 'EUR', '?', 'Europe', 'Cents', '1', '0');
+INSERT INTO `0_currencies` VALUES ('Pounds', 'GBP', '?', 'England', 'Pence', '1', '0');
+INSERT INTO `0_currencies` VALUES ('US Dollars', 'USD', '$', 'United States', 'Cents', '1', '0');
 
 
 ### Structure of table `0_cust_allocations` ###