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()
87 if ($selected_id == "")
89 $curr = db_escape($selected_id);
91 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
92 if (key_in_foreign_table($curr, 'debtors_master', 'curr_code', true))
94 display_error(_("Cannot delete this currency, because customer accounts have been created referring to this currency."));
98 if (key_in_foreign_table($curr, 'suppliers', 'curr_code', true))
100 display_error(_("Cannot delete this currency, because supplier accounts have been created referring to this currency."));
104 if ($curr == get_company_pref('curr_default'))
106 display_error(_("Cannot delete this currency, because the company preferences uses this currency."));
110 // see if there are any bank accounts that use this currency
111 if (key_in_foreign_table($curr, 'bank_accounts', 'bank_curr_code', true))
113 display_error(_("Cannot delete this currency, because thre are bank accounts that use this currency."));
120 //---------------------------------------------------------------------------------------------
122 function handle_delete()
124 global $selected_id, $Mode;
125 if (check_can_delete()) {
126 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
127 delete_currency($selected_id);
128 display_notification(_('Selected currency has been deleted'));
133 //---------------------------------------------------------------------------------------------
135 function display_currencies()
137 $company_currency = get_company_currency();
139 $result = get_currencies(check_value('show_inactive'));
140 start_table(TABLESTYLE);
141 $th = array(_("Abbreviation"), _("Symbol"), _("Currency Name"),
142 _("Hundredths name"), _("Country"), _("Auto update"), "", "");
143 inactive_control_column($th);
146 $k = 0; //row colour counter
148 while ($myrow = db_fetch($result))
151 if ($myrow[1] == $company_currency)
153 start_row("class='currencybg'");
156 alt_table_row_color($k);
158 label_cell($myrow["curr_abrev"]);
159 label_cell($myrow["curr_symbol"]);
160 label_cell($myrow["currency"]);
161 label_cell($myrow["hundreds_name"]);
162 label_cell($myrow["country"]);
163 label_cell( $myrow[1] == $company_currency ? '-' :
164 ($myrow["auto_update"] ? _('Yes') :_('No')), "align='center'");
165 inactive_control_cell($myrow["curr_abrev"], $myrow["inactive"], 'currencies', 'curr_abrev');
166 edit_button_cell("Edit".$myrow["curr_abrev"], _("Edit"));
167 if ($myrow["curr_abrev"] != $company_currency)
168 delete_button_cell("Delete".$myrow["curr_abrev"], _("Delete"));
173 } //END WHILE LIST LOOP
175 inactive_control_row($th);
177 display_note(_("The marked currency is the home currency which cannot be deleted."), 0, 0, "class='currentfg'");
180 //---------------------------------------------------------------------------------------------
182 function display_currency_edit($selected_id)
186 start_table(TABLESTYLE2);
188 if ($selected_id != '')
190 if ($Mode == 'Edit') {
191 //editing an existing currency
192 $myrow = get_currency($selected_id);
194 $_POST['Abbreviation'] = $myrow["curr_abrev"];
195 $_POST['Symbol'] = $myrow["curr_symbol"];
196 $_POST['CurrencyName'] = $myrow["currency"];
197 $_POST['country'] = $myrow["country"];
198 $_POST['hundreds_name'] = $myrow["hundreds_name"];
199 $_POST['auto_update'] = $myrow["auto_update"];
201 hidden('Abbreviation');
202 hidden('selected_id', $selected_id);
203 label_row(_("Currency Abbreviation:"), $_POST['Abbreviation']);
207 $_POST['auto_update'] = 1;
208 text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);
211 text_row_ex(_("Currency Symbol:"), 'Symbol', 10);
212 text_row_ex(_("Currency Name:"), 'CurrencyName', 20);
213 text_row_ex(_("Hundredths Name:"), 'hundreds_name', 15);
214 text_row_ex(_("Country:"), 'country', 40);
215 check_row(_("Automatic exchange rate update:"), 'auto_update', get_post('auto_update'));
218 submit_add_or_update_center($selected_id == '', '', 'both');
221 //---------------------------------------------------------------------------------------------
223 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
226 //---------------------------------------------------------------------------------------------
228 if ($Mode == 'Delete')
231 //---------------------------------------------------------------------------------------------
232 if ($Mode == 'RESET')
235 $_POST['Abbreviation'] = $_POST['Symbol'] = '';
236 $_POST['CurrencyName'] = $_POST['country'] = '';
237 $_POST['hundreds_name'] = '';
241 display_currencies();
243 display_currency_edit($selected_id);
245 //---------------------------------------------------------------------------------------------