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_once($path_to_root . "/includes/session.inc");
16 page(_("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']);
69 display_notification(_('Selected currency settings has been updated'));
74 add_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
75 $_POST['country'], $_POST['hundreds_name']);
76 display_notification(_('New currency has been added'));
81 //---------------------------------------------------------------------------------------------
83 function check_can_delete()
87 if ($selected_id == "")
89 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
90 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE curr_code = '$selected_id'";
91 $result = db_query($sql);
92 $myrow = db_fetch_row($result);
95 display_error(_("Cannot delete this currency, because customer accounts have been created referring to this currency."));
99 $sql= "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE curr_code = '$selected_id'";
100 $result = db_query($sql);
101 $myrow = db_fetch_row($result);
104 display_error(_("Cannot delete this currency, because supplier accounts have been created referring to this currency."));
108 $sql= "SELECT COUNT(*) FROM ".TB_PREF."company WHERE curr_default = '$selected_id'";
109 $result = db_query($sql);
110 $myrow = db_fetch_row($result);
113 display_error(_("Cannot delete this currency, because the company preferences uses this currency."));
117 // see if there are any bank accounts that use this currency
118 $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_accounts WHERE bank_curr_code = '$selected_id'";
119 $result = db_query($sql);
120 $myrow = db_fetch_row($result);
123 display_error(_("Cannot delete this currency, because thre are bank accounts that use this currency."));
130 //---------------------------------------------------------------------------------------------
132 function handle_delete()
134 global $selected_id, $Mode;
135 if (check_can_delete()) {
136 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
137 delete_currency($selected_id);
138 display_notification(_('Selected currency has been deleted'));
143 //---------------------------------------------------------------------------------------------
145 function display_currencies()
149 $company_currency = get_company_currency();
151 $result = get_currencies(check_value('show_inactive'));
152 start_table($table_style);
153 $th = array(_("Abbreviation"), _("Symbol"), _("Currency Name"),
154 _("Hundredths name"), _("Country"), "", "");
155 inactive_control_column($th);
158 $k = 0; //row colour counter
160 while ($myrow = db_fetch($result))
163 if ($myrow[1] == $company_currency)
165 start_row("class='currencybg'");
168 alt_table_row_color($k);
170 label_cell($myrow["curr_abrev"]);
171 label_cell($myrow["curr_symbol"]);
172 label_cell($myrow["currency"]);
173 label_cell($myrow["hundreds_name"]);
174 label_cell($myrow["country"]);
175 inactive_control_cell($myrow["curr_abrev"], $myrow["inactive"], 'currencies', 'curr_abrev');
176 edit_button_cell("Edit".$myrow["curr_abrev"], _("Edit"));
177 if ($myrow["curr_abrev"] != $company_currency)
178 delete_button_cell("Delete".$myrow["curr_abrev"], _("Delete"));
183 } //END WHILE LIST LOOP
185 inactive_control_row($th);
187 display_note(_("The marked currency is the home currency which cannot be deleted."), 0, 0, "class='currentfg'");
190 //---------------------------------------------------------------------------------------------
192 function display_currency_edit($selected_id)
194 global $table_style2, $Mode;
196 start_table($table_style2);
198 if ($selected_id != '')
200 if ($Mode == 'Edit') {
201 //editing an existing currency
202 $myrow = get_currency($selected_id);
204 $_POST['Abbreviation'] = $myrow["curr_abrev"];
205 $_POST['Symbol'] = $myrow["curr_symbol"];
206 $_POST['CurrencyName'] = $myrow["currency"];
207 $_POST['country'] = $myrow["country"];
208 $_POST['hundreds_name'] = $myrow["hundreds_name"];
210 hidden('Abbreviation');
211 hidden('selected_id', $selected_id);
212 label_row(_("Currency Abbreviation:"), $_POST['Abbreviation']);
216 text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);
219 text_row_ex(_("Currency Symbol:"), 'Symbol', 10);
220 text_row_ex(_("Currency Name:"), 'CurrencyName', 20);
221 text_row_ex(_("Hundredths Name:"), 'hundreds_name', 15);
222 text_row_ex(_("Country:"), 'country', 40);
226 submit_add_or_update_center($selected_id == '', '', 'both');
229 //---------------------------------------------------------------------------------------------
231 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
234 //---------------------------------------------------------------------------------------------
236 if ($Mode == 'Delete')
239 //---------------------------------------------------------------------------------------------
240 if ($Mode == 'RESET')
243 $_POST['Abbreviation'] = $_POST['Symbol'] = '';
244 $_POST['CurrencyName'] = $_POST['country'] = '';
245 $_POST['hundreds_name'] = '';
249 display_currencies();
251 display_currency_edit($selected_id);
253 //---------------------------------------------------------------------------------------------