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_TAXGROUPS';
15 include($path_to_root . "/includes/session.inc");
17 page(_("Tax Groups"));
19 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/includes/ui.inc");
22 include_once($path_to_root . "/taxes/db/tax_groups_db.inc");
23 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
25 simple_page_mode(true);
27 check_db_has_tax_types(_("There are no tax types defined. Define tax types before defining tax groups."));
29 //-----------------------------------------------------------------------------------
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
34 //initialise no input errors assumed initially before we test
37 if (strlen($_POST['name']) == 0)
40 display_error(_("The tax group name cannot be empty."));
43 /* Editable rate has been removed 090920 Joe Hunt
46 // make sure any entered rates are valid
47 for ($i = 0; $i < 5; $i++)
49 if (isset($_POST['tax_type_id' . $i]) &&
50 $_POST['tax_type_id' . $i] != ALL_NUMERIC &&
51 !check_num('rate' . $i, 0))
53 display_error( _("An entered tax rate is invalid or less than zero."));
61 if ($input_error != 1)
64 // create an array of the taxes and array of rates
68 for ($i = 0; $i < 5; $i++)
70 if (isset($_POST['tax_type_id' . $i]) &&
71 $_POST['tax_type_id' . $i] != ANY_NUMERIC)
73 $taxes[] = $_POST['tax_type_id' . $i];
74 $rates[] = get_tax_type_default_rate($_POST['tax_type_id' . $i]);
75 //Editable rate has been removed 090920 Joe Hunt
76 //$rates[] = input_num('rate' . $i);
80 if ($selected_id != -1)
82 update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes,
84 display_notification(_('Selected tax group has been updated'));
88 add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates);
89 display_notification(_('New tax group has been added'));
96 //-----------------------------------------------------------------------------------
98 function can_delete($selected_id)
100 if ($selected_id == -1)
102 $sql = "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE tax_group_id=".db_escape($selected_id);
103 $result = db_query($sql, "could not query customers");
104 $myrow = db_fetch_row($result);
107 display_note(_("Cannot delete this tax group because customer branches been created referring to it."));
111 $sql = "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE tax_group_id=".db_escape($selected_id);
112 $result = db_query($sql, "could not query suppliers");
113 $myrow = db_fetch_row($result);
116 display_note(_("Cannot delete this tax group because suppliers been created referring to it."));
125 //-----------------------------------------------------------------------------------
127 if ($Mode == 'Delete')
130 if (can_delete($selected_id))
132 delete_tax_group($selected_id);
133 display_notification(_('Selected tax group has been deleted'));
138 if ($Mode == 'RESET')
141 $sav = get_post('show_inactive');
143 $_POST['show_inactive'] = $sav;
145 //-----------------------------------------------------------------------------------
147 $result = get_all_tax_groups(check_value('show_inactive'));
150 start_table($table_style);
151 $th = array(_("Description"), _("Tax Shipping"), "", "");
152 inactive_control_column($th);
156 while ($myrow = db_fetch($result))
159 alt_table_row_color($k);
161 label_cell($myrow["name"]);
162 if ($myrow["tax_shipping"])
163 label_cell(_("Yes"));
167 /*for ($i=0; $i< 5; $i++)
168 if ($myrow["type" . $i] != ALL_NUMERIC)
169 echo "<td>" . $myrow["type" . $i] . "</td>";*/
171 inactive_control_cell($myrow["id"], $myrow["inactive"], 'tax_groups', 'id');
172 edit_button_cell("Edit".$myrow["id"], _("Edit"));
173 delete_button_cell("Delete".$myrow["id"], _("Delete"));
177 inactive_control_row($th);
180 //-----------------------------------------------------------------------------------
182 start_table($table_style2);
184 if ($selected_id != -1)
186 //editing an existing status code
188 if ($Mode == 'Edit') {
189 $group = get_tax_group($selected_id);
191 $_POST['name'] = $group["name"];
192 $_POST['tax_shipping'] = $group["tax_shipping"];
194 $items = get_tax_group_items($selected_id);
197 while ($tax_item = db_fetch($items))
199 $_POST['tax_type_id' . $i] = $tax_item["tax_type_id"];
200 $_POST['rate' . $i] = percent_format($tax_item["rate"]);
203 while($i<5) unset($_POST['tax_type_id'.$i++]);
206 hidden('selected_id', $selected_id);
208 text_row_ex(_("Description:"), 'name', 40);
209 yesno_list_row(_("Tax Shipping:"), 'tax_shipping', null, "", "", true);
213 display_note(_("Select the taxes that are included in this group."), 1);
215 start_table($table_style2);
216 //$th = array(_("Tax"), _("Default Rate (%)"), _("Rate (%)"));
217 //Editable rate has been removed 090920 Joe Hunt
218 $th = array(_("Tax"), _("Rate (%)"));
220 for ($i = 0; $i < 5; $i++)
223 if (!isset($_POST['tax_type_id' . $i]))
224 $_POST['tax_type_id' . $i] = 0;
225 tax_types_list_cells(null, 'tax_type_id' . $i, $_POST['tax_type_id' . $i], _("None"), true);
227 if ($_POST['tax_type_id' . $i] != 0 && $_POST['tax_type_id' . $i] != ALL_NUMERIC)
229 $default_rate = get_tax_type_default_rate($_POST['tax_type_id' . $i]);
230 label_cell(percent_format($default_rate), "nowrap align=right");
232 //Editable rate has been removed 090920 Joe Hunt
233 //if (!isset($_POST['rate' . $i]) || $_POST['rate' . $i] == "")
234 // $_POST['rate' . $i] = percent_format($default_rate);
235 //small_amount_cells(null, 'rate' . $i, $_POST['rate' . $i], null, null,
236 // user_percent_dec());
243 submit_add_or_update_center($selected_id == -1, '', 'both');
247 //------------------------------------------------------------------------------------