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 ***********************************************************************/
12 $page_security = 'SA_CURRENCY';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
16 page(_($help_context = "Currencies"));
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/banking.inc");
21 simple_page_mode(false);
23 //---------------------------------------------------------------------------------------------
27 if (strlen($_POST['Abbreviation']) == 0)
29 display_error( _("The currency abbreviation must be entered."));
30 set_focus('Abbreviation');
33 elseif (strlen($_POST['CurrencyName']) == 0)
35 display_error( _("The currency name must be entered."));
36 set_focus('CurrencyName');
39 elseif (strlen($_POST['Symbol']) == 0)
41 display_error( _("The currency symbol must be entered."));
45 elseif (strlen($_POST['hundreds_name']) == 0)
47 display_error( _("The hundredths name must be entered."));
48 set_focus('hundreds_name');
55 //---------------------------------------------------------------------------------------------
57 function handle_submit()
59 global $selected_id, $Mode;
64 if ($selected_id != "")
67 update_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
68 $_POST['country'], $_POST['hundreds_name'], check_value('auto_update'));
69 display_notification(_('Selected currency settings has been updated'));
74 add_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
75 $_POST['country'], $_POST['hundreds_name'], check_value('auto_update'));
76 display_notification(_('New currency has been added'));
81 //---------------------------------------------------------------------------------------------
83 function check_can_delete($curr)
89 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
90 if (key_in_foreign_table($curr, 'debtors_master', 'curr_code'))
92 display_error(_("Cannot delete this currency, because customer accounts have been created referring to this currency."));
96 if (key_in_foreign_table($curr, 'suppliers', 'curr_code'))
98 display_error(_("Cannot delete this currency, because supplier accounts have been created referring to this currency."));
102 if ($curr == get_company_pref('curr_default'))
104 display_error(_("Cannot delete this currency, because the company preferences uses this currency."));
108 // see if there are any bank accounts that use this currency
109 if (key_in_foreign_table($curr, 'bank_accounts', 'bank_curr_code'))
111 display_error(_("Cannot delete this currency, because thre are bank accounts that use this currency."));
118 //---------------------------------------------------------------------------------------------
120 function handle_delete()
122 global $selected_id, $Mode;
123 if (check_can_delete($selected_id)) {
124 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
125 delete_currency($selected_id);
126 display_notification(_('Selected currency has been deleted'));
131 //---------------------------------------------------------------------------------------------
133 function display_currencies()
135 $company_currency = get_company_currency();
137 $result = get_currencies(check_value('show_inactive'));
138 start_table(TABLESTYLE);
139 $th = array(_("Abbreviation"), _("Symbol"), _("Currency Name"),
140 _("Hundredths name"), _("Country"), _("Auto update"), "", "");
141 inactive_control_column($th);
144 $k = 0; //row colour counter
146 while ($myrow = db_fetch($result))
149 if ($myrow[1] == $company_currency)
151 start_row("class='currencybg'");
154 alt_table_row_color($k);
156 label_cell($myrow["curr_abrev"]);
157 label_cell($myrow["curr_symbol"]);
158 label_cell($myrow["currency"]);
159 label_cell($myrow["hundreds_name"]);
160 label_cell($myrow["country"]);
161 label_cell( $myrow[1] == $company_currency ? '-' :
162 ($myrow["auto_update"] ? _('Yes') :_('No')), "align='center'");
163 inactive_control_cell($myrow["curr_abrev"], $myrow["inactive"], 'currencies', 'curr_abrev');
164 edit_button_cell("Edit".$myrow["curr_abrev"], _("Edit"));
165 if ($myrow["curr_abrev"] != $company_currency)
166 delete_button_cell("Delete".$myrow["curr_abrev"], _("Delete"));
171 } //END WHILE LIST LOOP
173 inactive_control_row($th);
175 display_note(_("The marked currency is the home currency which cannot be deleted."), 0, 0, "class='currentfg'");
178 //---------------------------------------------------------------------------------------------
180 function display_currency_edit($selected_id)
184 start_table(TABLESTYLE2);
186 if ($selected_id != '')
188 if ($Mode == 'Edit') {
189 //editing an existing currency
190 $myrow = get_currency($selected_id);
192 $_POST['Abbreviation'] = $myrow["curr_abrev"];
193 $_POST['Symbol'] = $myrow["curr_symbol"];
194 $_POST['CurrencyName'] = $myrow["currency"];
195 $_POST['country'] = $myrow["country"];
196 $_POST['hundreds_name'] = $myrow["hundreds_name"];
197 $_POST['auto_update'] = $myrow["auto_update"];
199 hidden('Abbreviation');
200 hidden('selected_id', $selected_id);
201 label_row(_("Currency Abbreviation:"), $_POST['Abbreviation']);
205 $_POST['auto_update'] = 1;
206 text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);
209 text_row_ex(_("Currency Symbol:"), 'Symbol', 10);
210 text_row_ex(_("Currency Name:"), 'CurrencyName', 20);
211 text_row_ex(_("Hundredths Name:"), 'hundreds_name', 15);
212 text_row_ex(_("Country:"), 'country', 40);
213 check_row(_("Automatic exchange rate update:"), 'auto_update', get_post('auto_update'));
216 submit_add_or_update_center($selected_id == '', '', 'both');
219 //---------------------------------------------------------------------------------------------
221 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
224 //---------------------------------------------------------------------------------------------
226 if ($Mode == 'Delete')
229 //---------------------------------------------------------------------------------------------
230 if ($Mode == 'RESET')
233 $_POST['Abbreviation'] = $_POST['Symbol'] = '';
234 $_POST['CurrencyName'] = $_POST['country'] = '';
235 $_POST['hundreds_name'] = '';
239 display_currencies();
241 display_currency_edit($selected_id);
243 //---------------------------------------------------------------------------------------------