2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
13 $path_to_root="../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/banking.inc");
23 $js .= get_js_date_picker();
24 page(_("Exchange Rates"), false, false, "", $js);
26 simple_page_mode(false);
28 //---------------------------------------------------------------------------------------------
31 if (!is_date($_POST['date_']))
33 display_error( _("The entered date is invalid."));
37 if (!check_num('BuyRate', 0))
39 display_error( _("The exchange rate must be numeric and greater than zero."));
43 if ($_POST['BuyRate'] <= 0)
45 display_error( _("The exchange rate cannot be zero or a negative number."));
53 //---------------------------------------------------------------------------------------------
55 function handle_submit()
62 if ($selected_id != "")
65 update_exchange_rate($_POST['curr_abrev'], $_POST['date_'],
66 input_num('BuyRate'), input_num('BuyRate'));
71 add_exchange_rate($_POST['curr_abrev'], $_POST['date_'],
72 input_num('BuyRate'), input_num('BuyRate'));
78 //---------------------------------------------------------------------------------------------
80 function handle_delete()
84 if ($selected_id == "")
86 delete_exchange_rate($selected_id);
90 //---------------------------------------------------------------------------------------------
91 function edit_link($row)
93 return button('Edit'.$row["id"], _("Edit"), true, ICON_EDIT);
96 function del_link($row)
98 return button('Delete'.$row["id"], _("Delete"), true, ICON_DELETE);
101 function display_rates($curr_code)
107 //---------------------------------------------------------------------------------------------
109 function display_rate_edit()
111 global $selected_id, $table_style2, $Ajax;
113 start_table($table_style2);
115 if ($selected_id != "")
117 //editing an existing exchange rate
119 $myrow = get_exchange_rate($selected_id);
121 $_POST['date_'] = sql2date($myrow["date_"]);
122 $_POST['BuyRate'] = exrate_format($myrow["rate_buy"]);
124 hidden('selected_id', $selected_id);
125 hidden('date_', $_POST['date_']);
127 label_row(_("Date to Use From:"), $_POST['date_']);
131 $_POST['date_'] = Today();
132 $_POST['BuyRate'] = '';
133 date_row(_("Date to Use From:"), 'date_');
135 if (isset($_POST['get_rate']))
137 $_POST['BuyRate'] = exrate_format(get_ecb_rate($_POST['curr_abrev']));
138 if ($_POST['BuyRate'] == 0) {
139 display_error(_('This currency is not listed by ECB. Enter exchange rate manually.'));
141 $Ajax->activate('BuyRate');
143 small_amount_row(_("Exchange Rate:"), 'BuyRate', null, '',
144 submit('get_rate',_("Get"), false, _('Get current ECB rate') , true),
149 submit_add_or_update_center($selected_id == '', '', true);
151 display_note(_("Exchange rates are entered against the company currency."), 1);
154 //---------------------------------------------------------------------------------------------
156 function clear_data()
158 unset($_POST['selected_id']);
159 unset($_POST['date_']);
160 unset($_POST['BuyRate']);
163 //---------------------------------------------------------------------------------------------
165 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
168 //---------------------------------------------------------------------------------------------
170 if ($Mode == 'Delete')
174 //---------------------------------------------------------------------------------------------
176 start_form(false, true);
178 if (!isset($_POST['curr_abrev']))
179 $_POST['curr_abrev'] = get_global_curr_code();
182 echo _("Select a currency :") . " ";
183 currencies_list('curr_abrev', null, true);
186 // if currency sel has changed, clear the form
187 if ($_POST['curr_abrev'] != get_global_curr_code())
193 set_global_curr_code($_POST['curr_abrev']);
195 $sql = "SELECT date_, rate_buy, id FROM "
196 .TB_PREF."exchange_rates "
197 ."WHERE curr_code='".$_POST['curr_abrev']."'
198 ORDER BY date_ DESC";
201 _("Date to Use From") => 'date',
202 _("Exchange Rate") => 'rate',
203 array('insert'=>true, 'fun'=>'edit_link'),
204 array('insert'=>true, 'fun'=>'del_link'),
206 $table =& new_db_pager('orders_tbl', $sql, $cols);
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);
218 if (list_updated('curr_abrev')) {
219 $table->set_sql($sql);
220 $table->set_columns($cols);
222 $table->width = "40%";
223 display_db_pager($table);