5 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/banking.inc");
12 simple_page_mode(false);
14 //---------------------------------------------------------------------------------------------
18 if (strlen($_POST['Abbreviation']) == 0)
20 display_error( _("The currency abbreviation must be entered."));
21 set_focus('Abbreviation');
24 elseif (strlen($_POST['CurrencyName']) == 0)
26 display_error( _("The currency name must be entered."));
27 set_focus('CurrencyName');
30 elseif (strlen($_POST['Symbol']) == 0)
32 display_error( _("The currency symbol must be entered."));
36 elseif (strlen($_POST['hundreds_name']) == 0)
38 display_error( _("The hundredths name must be entered."));
39 set_focus('hundreds_name');
46 //---------------------------------------------------------------------------------------------
48 function handle_submit()
50 global $selected_id, $Mode;
55 if ($selected_id != "")
58 update_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
59 $_POST['country'], $_POST['hundreds_name']);
60 display_notification(_('Selected currency settings has been updated'));
65 add_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
66 $_POST['country'], $_POST['hundreds_name']);
67 display_notification(_('New currency has been added'));
72 //---------------------------------------------------------------------------------------------
74 function check_can_delete()
78 if ($selected_id == "")
80 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
81 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE curr_code = '$selected_id'";
82 $result = db_query($sql);
83 $myrow = db_fetch_row($result);
86 display_error(_("Cannot delete this currency, because customer accounts have been created referring to this currency."));
90 $sql= "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE curr_code = '$selected_id'";
91 $result = db_query($sql);
92 $myrow = db_fetch_row($result);
95 display_error(_("Cannot delete this currency, because supplier accounts have been created referring to this currency."));
99 $sql= "SELECT COUNT(*) FROM ".TB_PREF."company WHERE curr_default = '$selected_id'";
100 $result = db_query($sql);
101 $myrow = db_fetch_row($result);
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 $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_accounts WHERE bank_curr_code = '$selected_id'";
110 $result = db_query($sql);
111 $myrow = db_fetch_row($result);
114 display_error(_("Cannot delete this currency, because thre are bank accounts that use this currency."));
121 //---------------------------------------------------------------------------------------------
123 function handle_delete()
125 global $selected_id, $Mode;
126 if (check_can_delete()) {
127 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
128 delete_currency($selected_id);
129 display_notification(_('Selected currency has been deleted'));
134 //---------------------------------------------------------------------------------------------
136 function display_currencies()
140 $company_currency = get_company_currency();
142 $result = get_currencies();
144 start_table($table_style);
145 $th = array(_("Abbreviation"), _("Symbol"), _("Currency Name"),
146 _("Hundredths name"), _("Country"), "", "");
149 $k = 0; //row colour counter
151 while ($myrow = db_fetch($result))
154 if ($myrow[1] == $company_currency)
156 start_row("class='currencybg'");
159 alt_table_row_color($k);
161 label_cell($myrow["curr_abrev"]);
162 label_cell($myrow["curr_symbol"]);
163 label_cell($myrow["currency"]);
164 label_cell($myrow["hundreds_name"]);
165 label_cell($myrow["country"]);
166 edit_button_cell("Edit".$myrow["curr_abrev"], _("Edit"));
167 if ($myrow["curr_abrev"] != $company_currency)
168 edit_button_cell("Delete".$myrow["curr_abrev"], _("Delete"));
173 } //END WHILE LIST LOOP
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)
184 global $table_style2, $Mode;
187 start_table($table_style2);
189 if ($selected_id != '')
191 if ($Mode == 'Edit') {
192 //editing an existing currency
193 $myrow = get_currency($selected_id);
195 $_POST['Abbreviation'] = $myrow["curr_abrev"];
196 $_POST['Symbol'] = $myrow["curr_symbol"];
197 $_POST['CurrencyName'] = $myrow["currency"];
198 $_POST['country'] = $myrow["country"];
199 $_POST['hundreds_name'] = $myrow["hundreds_name"];
201 hidden('Abbreviation');
202 hidden('selected_id', $selected_id);
203 label_row(_("Currency Abbreviation:"), $_POST['Abbreviation']);
207 text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);
210 text_row_ex(_("Currency Symbol:"), 'Symbol', 10);
211 text_row_ex(_("Currency Name:"), 'CurrencyName', 20);
212 text_row_ex(_("Hundredths Name:"), 'hundreds_name', 15);
213 text_row_ex(_("Country:"), 'country', 40);
217 submit_add_or_update_center($selected_id == '', '', true);
222 //---------------------------------------------------------------------------------------------
224 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
227 //---------------------------------------------------------------------------------------------
229 if ($Mode == 'Delete')
232 //---------------------------------------------------------------------------------------------
233 if ($Mode == 'RESET')
236 $_POST['Abbreviation'] = $_POST['Symbol'] = '';
237 $_POST['CurrencyName'] = $_POST['country'] = '';
238 $_POST['hundreds_name'] = '';
241 display_currencies();
243 display_currency_edit($selected_id);
245 //---------------------------------------------------------------------------------------------