X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Fmanage%2Fexchange_rates.php;h=05953c04bd452d77714077edc71d386fe1b7cc18;hb=9451db1760036985de791ba24c442801e37f37de;hp=77decb39f46c778501c961806e9754e7a24e6093;hpb=0eadb0e7549a8e90af92dac51b560f57918084ac;p=fa-stable.git diff --git a/gl/manage/exchange_rates.php b/gl/manage/exchange_rates.php index 77decb39..05953c04 100644 --- a/gl/manage/exchange_rates.php +++ b/gl/manage/exchange_rates.php @@ -1,7 +1,17 @@ . +***********************************************************************/ +$page_security = 'SA_EXCHANGERATE'; +$path_to_root = "../.."; +include($path_to_root . "/includes/db_pager.inc"); include_once($path_to_root . "/includes/session.inc"); include_once($path_to_root . "/includes/date_functions.inc"); @@ -9,41 +19,33 @@ include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/banking.inc"); $js = ""; -if ($use_date_picker) +if (user_use_date_picker()) $js .= get_js_date_picker(); -page(_("Exchange Rates"), false, false, "", $js); +page(_($help_context = "Exchange Rates"), false, false, "", $js); -//--------------------------------------------------------------------------------------------- +simple_page_mode(false); -if (isset($_GET['selected_id'])) -{ - $selected_id = $_GET['selected_id']; -} -elseif (isset($_POST['selected_id'])) -{ - $selected_id = $_POST['selected_id']; -} -else - $selected_id = ""; //--------------------------------------------------------------------------------------------- -function check_data() +function check_data($selected_id) { - if (!is_date($_POST['date_'])) + if (!is_date($_POST['date_'])) { display_error( _("The entered date is invalid.")); + set_focus('date_'); return false; } - if (!check_num('BuyRate', 0)) + if (input_num('BuyRate') <= 0) { - display_error( _("The exchange rate must be numeric and greater than zero.")); + display_error( _("The exchange rate cannot be zero or a negative number.")); + set_focus('BuyRate'); return false; } - if ($_POST['BuyRate'] <= 0) + if (!$selected_id && get_date_exchange_rate($_POST['curr_abrev'], $_POST['date_'])) { - display_error( _("The exchange rate cannot be zero or a negative number.")); + display_error( _("The exchange rate for the date is already there.")); + set_focus('date_'); return false; } - return true; } @@ -53,23 +55,24 @@ function handle_submit() { global $selected_id; - if (!check_data()) + if (!check_data($selected_id)) return false; - if ($selected_id != "") + if ($selected_id != "") { update_exchange_rate($_POST['curr_abrev'], $_POST['date_'], - input_num('BuyRate'), input_num('BuyRate')); - } - else + input_num('BuyRate'), input_num('BuyRate')); + } + else { add_exchange_rate($_POST['curr_abrev'], $_POST['date_'], input_num('BuyRate'), input_num('BuyRate')); } - return true; + $selected_id = ''; + clear_data(); } //--------------------------------------------------------------------------------------------- @@ -81,79 +84,67 @@ function handle_delete() if ($selected_id == "") return; delete_exchange_rate($selected_id); - - meta_forward($_SERVER['PHP_SELF']); + $selected_id = ''; + clear_data(); } //--------------------------------------------------------------------------------------------- - -function display_rates($curr_code) +function edit_link($row) { - global $table_style; - - $result = get_exchange_rates($curr_code); - - br(2); - start_table($table_style); - $th = array(_("Date to Use From"), _("Exchange Rate"), "", ""); - table_header($th); - - $k = 0; //row colour counter - - while ($myrow = db_fetch($result)) - { - - alt_table_row_color($k); - - label_cell(sql2date($myrow["date_"])); - label_cell(number_format2($myrow["rate_buy"], user_exrate_dec()), "nowrap align=right"); - edit_link_cell("selected_id=" . $myrow["id"]); - delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1"); + return button('Edit'.$row["id"], _("Edit"), true, ICON_EDIT); +} - end_row(); +function del_link($row) +{ + return button('Delete'.$row["id"], _("Delete"), true, ICON_DELETE); +} - } //END WHILE LIST LOOP +function display_rates($curr_code) +{ - end_table(); } //--------------------------------------------------------------------------------------------- function display_rate_edit() { - global $selected_id, $table_style2; + global $selected_id, $Ajax, $SysPrefs; + $xchg_rate_provider = ((isset($SysPrefs->xr_providers) && isset($SysPrefs->dflt_xr_provider)) + ? $SysPrefs->xr_providers[$SysPrefs->dflt_xr_provider] : 'ECB'); + start_table(TABLESTYLE2); - start_table($table_style2); - - if (isset($_POST['get_rate'])) - { - $_POST['BuyRate'] = exrate_format(get_ecb_rate($_POST['curr_abrev'])); - } - if ($selected_id != "") + if ($selected_id != "") { //editing an existing exchange rate $myrow = get_exchange_rate($selected_id); $_POST['date_'] = sql2date($myrow["date_"]); - $_POST['BuyRate'] = exrate_format($myrow["rate_buy"]); + $_POST['BuyRate'] = maxprec_format($myrow["rate_buy"]); hidden('selected_id', $selected_id); hidden('date_', $_POST['date_']); - hidden('curr_abrev', $_POST['curr_abrev']); label_row(_("Date to Use From:"), $_POST['date_']); - } - else + } + else { + $_POST['date_'] = Today(); + $_POST['BuyRate'] = ''; date_row(_("Date to Use From:"), 'date_'); } - small_amount_row(_("Exchange Rate:"), 'BuyRate', null, '', - submit('get_rate',_("Get")), user_exrate_dec()); + if (isset($_POST['get_rate'])) + { + $_POST['BuyRate'] = + maxprec_format(retrieve_exrate($_POST['curr_abrev'], $_POST['date_'])); + $Ajax->activate('BuyRate'); + } + amount_row(_("Exchange Rate:"), 'BuyRate', null, '', + submit('get_rate',_("Get"), false, _('Get current rate from') . ' ' . $xchg_rate_provider , true), 'max'); end_table(1); - submit_add_or_update_center($selected_id == ""); + submit_add_or_update_center($selected_id == '', '', 'both'); display_note(_("Exchange rates are entered against the company currency."), 1); } @@ -169,57 +160,61 @@ function clear_data() //--------------------------------------------------------------------------------------------- -if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) -{ - - if (handle_submit()) - { - meta_forward($_SERVER['PHP_SELF']); - } -} +if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') + handle_submit(); //--------------------------------------------------------------------------------------------- -if (isset($_GET['delete'])) -{ - +if ($Mode == 'Delete') handle_delete(); -} + //--------------------------------------------------------------------------------------------- -echo "