2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 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/gpl-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 (input_num('BuyRate') <= 0)
39 display_error( _("The exchange rate cannot be zero or a negative number."));
47 //---------------------------------------------------------------------------------------------
49 function handle_submit()
56 if ($selected_id != "")
59 update_exchange_rate($_POST['curr_abrev'], $_POST['date_'],
60 input_num('BuyRate'), input_num('BuyRate'));
65 add_exchange_rate($_POST['curr_abrev'], $_POST['date_'],
66 input_num('BuyRate'), input_num('BuyRate'));
72 //---------------------------------------------------------------------------------------------
74 function handle_delete()
78 if ($selected_id == "")
80 delete_exchange_rate($selected_id);
84 //---------------------------------------------------------------------------------------------
85 function edit_link($row)
87 return button('Edit'.$row["id"], _("Edit"), true, ICON_EDIT);
90 function del_link($row)
92 return button('Delete'.$row["id"], _("Delete"), true, ICON_DELETE);
95 function display_rates($curr_code)
101 //---------------------------------------------------------------------------------------------
103 function display_rate_edit()
105 global $selected_id, $table_style2, $Ajax;
107 start_table($table_style2);
109 if ($selected_id != "")
111 //editing an existing exchange rate
113 $myrow = get_exchange_rate($selected_id);
115 $_POST['date_'] = sql2date($myrow["date_"]);
116 $_POST['BuyRate'] = exrate_format($myrow["rate_buy"]);
118 hidden('selected_id', $selected_id);
119 hidden('date_', $_POST['date_']);
121 label_row(_("Date to Use From:"), $_POST['date_']);
125 $_POST['date_'] = Today();
126 $_POST['BuyRate'] = '';
127 date_row(_("Date to Use From:"), 'date_');
129 if (isset($_POST['get_rate']))
131 $_POST['BuyRate'] = exrate_format(get_ecb_rate($_POST['curr_abrev']));
132 $Ajax->activate('BuyRate');
134 small_amount_row(_("Exchange Rate:"), 'BuyRate', null, '',
135 submit('get_rate',_("Get"), false, _('Get current ECB rate') , true),
140 submit_add_or_update_center($selected_id == '', '', true);
142 display_note(_("Exchange rates are entered against the company currency."), 1);
145 //---------------------------------------------------------------------------------------------
147 function clear_data()
149 unset($_POST['selected_id']);
150 unset($_POST['date_']);
151 unset($_POST['BuyRate']);
154 //---------------------------------------------------------------------------------------------
156 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
159 //---------------------------------------------------------------------------------------------
161 if ($Mode == 'Delete')
165 //---------------------------------------------------------------------------------------------
167 start_form(false, true);
169 if (!isset($_POST['curr_abrev']))
170 $_POST['curr_abrev'] = get_global_curr_code();
173 echo _("Select a currency :") . " ";
174 currencies_list('curr_abrev', null, true);
177 // if currency sel has changed, clear the form
178 if ($_POST['curr_abrev'] != get_global_curr_code())
184 set_global_curr_code($_POST['curr_abrev']);
186 $sql = "SELECT date_, rate_buy, id FROM "
187 .TB_PREF."exchange_rates "
188 ."WHERE curr_code='".$_POST['curr_abrev']."'
189 ORDER BY date_ DESC";
192 _("Date to Use From") => 'date',
193 _("Exchange Rate") => 'rate',
194 array('insert'=>true, 'fun'=>'edit_link'),
195 array('insert'=>true, 'fun'=>'del_link'),
197 $table =& new_db_pager('orders_tbl', $sql, $cols);
199 if (is_company_currency($_POST['curr_abrev']))
202 display_note(_("The selected currency is the company currency."), 2);
203 display_note(_("The company currency is the base currency so exchange rates cannot be set for it."), 1);
209 if (list_updated('curr_abrev')) {
210 $table->set_sql($sql);
211 $table->set_columns($cols);
213 $table->width = "40%";
214 display_db_pager($table);