5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/includes/ui.inc");
9 include_once($path_to_root . "/includes/banking.inc");
13 $js .= get_js_date_picker();
14 page(_("Exchange Rates"), false, false, "", $js);
16 //---------------------------------------------------------------------------------------------
18 if (isset($_GET['selected_id']))
20 $selected_id = $_GET['selected_id'];
22 elseif (isset($_POST['selected_id']))
24 $selected_id = $_POST['selected_id'];
28 //---------------------------------------------------------------------------------------------
31 if (!is_date($_POST['date_']))
33 display_error( _("The entered date is invalid."));
36 if (!check_num('BuyRate', 0))
38 display_error( _("The exchange rate must be numeric and greater than zero."));
41 if ($_POST['BuyRate'] <= 0)
43 display_error( _("The exchange rate cannot be zero or a negative number."));
50 //---------------------------------------------------------------------------------------------
52 function handle_submit()
59 if ($selected_id != "")
62 update_exchange_rate($_POST['curr_abrev'], $_POST['date_'],
63 input_num('BuyRate'), input_num('BuyRate'));
68 add_exchange_rate($_POST['curr_abrev'], $_POST['date_'],
69 input_num('BuyRate'), input_num('BuyRate'));
75 //---------------------------------------------------------------------------------------------
77 function handle_delete()
81 if ($selected_id == "")
83 delete_exchange_rate($selected_id);
85 meta_forward($_SERVER['PHP_SELF']);
88 //---------------------------------------------------------------------------------------------
90 function display_rates($curr_code)
94 $result = get_exchange_rates($curr_code);
97 start_table($table_style);
98 $th = array(_("Date to Use From"), _("Exchange Rate"), "", "");
101 $k = 0; //row colour counter
103 while ($myrow = db_fetch($result))
106 alt_table_row_color($k);
108 label_cell(sql2date($myrow["date_"]));
109 label_cell(number_format2($myrow["rate_buy"], user_exrate_dec()), "nowrap align=right");
110 edit_link_cell("selected_id=" . $myrow["id"]);
111 delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
115 } //END WHILE LIST LOOP
120 //---------------------------------------------------------------------------------------------
122 function display_rate_edit()
124 global $selected_id, $table_style2;
126 start_table($table_style2);
128 if (isset($_POST['get_rate']))
130 $_POST['BuyRate'] = exrate_format(get_ecb_rate($_POST['curr_abrev']));
132 if ($selected_id != "")
134 //editing an existing exchange rate
136 $myrow = get_exchange_rate($selected_id);
138 $_POST['date_'] = sql2date($myrow["date_"]);
139 $_POST['BuyRate'] = exrate_format($myrow["rate_buy"]);
141 hidden('selected_id', $selected_id);
142 hidden('date_', $_POST['date_']);
143 hidden('curr_abrev', $_POST['curr_abrev']);
145 label_row(_("Date to Use From:"), $_POST['date_']);
149 date_row(_("Date to Use From:"), 'date_');
151 small_amount_row(_("Exchange Rate:"), 'BuyRate', null, '', submit('get_rate',_("Get"), false));
155 submit_add_or_update_center($selected_id == "");
157 display_note(_("Exchange rates are entered against the company currency."), 1);
160 //---------------------------------------------------------------------------------------------
162 function clear_data()
164 unset($_POST['selected_id']);
165 unset($_POST['date_']);
166 unset($_POST['BuyRate']);
169 //---------------------------------------------------------------------------------------------
171 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
176 meta_forward($_SERVER['PHP_SELF']);
180 //---------------------------------------------------------------------------------------------
182 if (isset($_GET['delete']))
188 //---------------------------------------------------------------------------------------------
191 start_form(false, true);
193 if (!isset($_POST['curr_abrev']))
194 $_POST['curr_abrev'] = get_global_curr_code();
196 echo _("Select a currency :") . " ";
197 currencies_list('curr_abrev', $_POST['curr_abrev'], true);
199 // if currency sel has changed, clear the form
200 if ($_POST['curr_abrev'] != get_global_curr_code())
206 set_global_curr_code($_POST['curr_abrev']);
208 if (is_company_currency($_POST['curr_abrev']))
211 display_note(_("The selected currency is the company currency."), 2);
212 display_note(_("The company currency is the base currency so exchange rates cannot be set for it."), 1);
217 display_rates($_POST['curr_abrev']);
219 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter a New Exchange Rate"));