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 //---------------------------------------------------------------------------------------------
14 if (isset($_GET['selected_id']))
16 $selected_id = $_GET['selected_id'];
18 elseif (isset($_POST['selected_id']))
20 $selected_id = $_POST['selected_id'];
24 //---------------------------------------------------------------------------------------------
28 if (strlen($_POST['Abbreviation']) == 0)
30 display_error( _("The currency abbreviation must be entered."));
33 elseif (strlen($_POST['CurrencyName']) == 0)
35 display_error( _("The currency name must be entered."));
38 elseif (strlen($_POST['Symbol']) == 0)
40 display_error( _("The currency symbol must be entered."));
43 elseif (strlen($_POST['hundreds_name']) == 0)
45 display_error( _("The hundredths name must be entered."));
52 //---------------------------------------------------------------------------------------------
54 function handle_submit()
61 if ($selected_id != "")
64 update_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
65 $_POST['country'], $_POST['hundreds_name']);
70 add_currency($_POST['Abbreviation'], $_POST['Symbol'], $_POST['CurrencyName'],
71 $_POST['country'], $_POST['hundreds_name']);
77 //---------------------------------------------------------------------------------------------
79 function check_can_delete()
83 if ($selected_id == "")
85 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
86 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE curr_code = '$selected_id'";
87 $result = db_query($sql);
88 $myrow = db_fetch_row($result);
91 display_error(_("Cannot delete this currency, because customer accounts have been created referring to this currency."));
95 $sql= "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE curr_code = '$selected_id'";
96 $result = db_query($sql);
97 $myrow = db_fetch_row($result);
100 display_error(_("Cannot delete this currency, because supplier accounts have been created referring to this currency."));
104 $sql= "SELECT COUNT(*) FROM ".TB_PREF."company WHERE curr_default = '$selected_id'";
105 $result = db_query($sql);
106 $myrow = db_fetch_row($result);
109 display_error(_("Cannot delete this currency, because the company preferences uses this currency."));
113 // see if there are any bank accounts that use this currency
114 $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_accounts WHERE bank_curr_code = '$selected_id'";
115 $result = db_query($sql);
116 $myrow = db_fetch_row($result);
119 display_error(_("Cannot delete this currency, because thre are bank accounts that use this currency."));
126 //---------------------------------------------------------------------------------------------
128 function handle_delete()
131 if (!check_can_delete())
133 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
135 delete_currency($selected_id);
137 meta_forward($_SERVER['PHP_SELF']);
140 //---------------------------------------------------------------------------------------------
142 function display_currencies()
146 $company_currency = get_company_currency();
148 $result = get_currencies();
150 start_table($table_style);
151 $th = array(_("Abbreviation"), _("Symbol"), _("Currency Name"),
152 _("Hundredths name"), _("Country"), "", "");
155 $k = 0; //row colour counter
157 while ($myrow = db_fetch($result))
160 if ($myrow[1] == $company_currency)
162 start_row("class='currencybg'");
165 alt_table_row_color($k);
167 label_cell($myrow["curr_abrev"]);
168 label_cell($myrow["curr_symbol"]);
169 label_cell($myrow["currency"]);
170 label_cell($myrow["hundreds_name"]);
171 label_cell($myrow["country"]);
172 edit_link_cell("selected_id=" . $myrow["curr_abrev"]);
173 if ($myrow["curr_abrev"] != $company_currency)
174 delete_link_cell("selected_id=" . $myrow["curr_abrev"]. "&delete=1");
178 } //END WHILE LIST LOOP
182 display_note(_("The marked currency is the home currency which cannot be deleted."), 0, 0, "class='currentfg'");
185 //---------------------------------------------------------------------------------------------
187 function display_currency_edit($selected_id)
189 global $table_style2;
192 start_table($table_style2);
194 if ($selected_id != "")
196 //editing an existing currency
197 $myrow = get_currency($selected_id);
199 $_POST['Abbreviation'] = $myrow["curr_abrev"];
200 $_POST['Symbol'] = $myrow["curr_symbol"];
201 $_POST['CurrencyName'] = $myrow["currency"];
202 $_POST['country'] = $myrow["country"];
203 $_POST['hundreds_name'] = $myrow["hundreds_name"];
205 hidden('selected_id', $selected_id);
206 hidden('Abbreviation', $_POST['Abbreviation']);
207 label_row(_("Currency Abbreviation:"), $_POST['Abbreviation']);
211 text_row_ex(_("Currency Abbreviation:"), 'Abbreviation', 4, 3);
214 text_row_ex(_("Currency Symbol:"), 'Symbol', 10);
215 text_row_ex(_("Currency Name:"), 'CurrencyName', 20);
216 text_row_ex(_("Hundredths Name:"), 'hundreds_name', 15);
217 text_row_ex(_("Country:"), 'country', 40);
221 submit_add_or_update_center($selected_id == "");
226 //---------------------------------------------------------------------------------------------
228 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
233 meta_forward($_SERVER['PHP_SELF']);
237 //---------------------------------------------------------------------------------------------
239 if (isset($_GET['delete']))
245 //---------------------------------------------------------------------------------------------
247 display_currencies();
249 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter a New Currency"));
251 display_currency_edit($selected_id);
253 //---------------------------------------------------------------------------------------------