From a1e0df1ef259550f26bc150cf912fd518c7344e3 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 19 May 2009 15:16:02 +0000 Subject: [PATCH] Automatic update currency option added. --- gl/includes/db/gl_db_currencies.inc | 16 +++++++++++----- gl/manage/currencies.php | 14 +++++++++----- includes/ui/ui_view.inc | 9 ++++++--- sql/alter2.2.sql | 3 ++- sql/en_US-demo.sql | 13 +++++++------ sql/en_US-new.sql | 9 +++++---- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/gl/includes/db/gl_db_currencies.inc b/gl/includes/db/gl_db_currencies.inc index 111b83dc..342cddc4 100644 --- a/gl/includes/db/gl_db_currencies.inc +++ b/gl/includes/db/gl_db_currencies.inc @@ -11,20 +11,26 @@ ***********************************************************************/ //--------------------------------------------------------------------------------------------- -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"); } diff --git a/gl/manage/currencies.php b/gl/manage/currencies.php index 2ea60107..4d5bf918 100644 --- a/gl/manage/currencies.php +++ b/gl/manage/currencies.php @@ -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'); diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 186c7a14..f95182ab 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -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) diff --git a/sql/alter2.2.sql b/sql/alter2.2.sql index 719b7d2f..d303fd35 100644 --- a/sql/alter2.2.sql +++ b/sql/alter2.2.sql @@ -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'; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 60650bd3..57fdacf0 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -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` ### diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 76658b74..c0952a65 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -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` ### -- 2.30.2