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(_($help_context = "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."));
44 if ($input_error != 1)
47 // create an array of the taxes and array of rates
51 while (($id = find_submit('tax_type_id'))!=-1)
54 $rates[] = get_tax_type_default_rate($id);
55 unset($_POST['tax_type_id' . $id]);
57 if ($selected_id != -1)
59 update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes,
61 display_notification(_('Selected tax group has been updated'));
65 add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates);
66 display_notification(_('New tax group has been added'));
73 //-----------------------------------------------------------------------------------
75 function can_delete($selected_id)
77 if ($selected_id == -1)
79 if (key_in_foreign_table($selected_id, 'cust_branch', 'tax_group_id'))
81 display_error(_("Cannot delete this tax group because customer branches been created referring to it."));
85 if (key_in_foreign_table($selected_id, 'suppliers', 'tax_group_id'))
87 display_error(_("Cannot delete this tax group because suppliers been created referring to it."));
96 //-----------------------------------------------------------------------------------
98 if ($Mode == 'Delete')
101 if (can_delete($selected_id))
103 delete_tax_group($selected_id);
104 display_notification(_('Selected tax group has been deleted'));
109 if ($Mode == 'RESET')
112 $sav = get_post('show_inactive');
115 $_POST['show_inactive'] = $sav;
117 //-----------------------------------------------------------------------------------
119 $result = get_all_tax_groups(check_value('show_inactive'));
123 start_table(TABLESTYLE);
124 $th = array(_("Description"), _("Shipping Tax"), "", "");
125 inactive_control_column($th);
130 while ($myrow = db_fetch($result))
133 alt_table_row_color($k);
135 label_cell($myrow["name"]);
136 if ($myrow["tax_shipping"])
137 label_cell(_("Yes"));
141 inactive_control_cell($myrow["id"], $myrow["inactive"], 'tax_groups', 'id');
142 edit_button_cell("Edit".$myrow["id"], _("Edit"));
143 delete_button_cell("Delete".$myrow["id"], _("Delete"));
147 inactive_control_row($th);
150 //-----------------------------------------------------------------------------------
152 start_table(TABLESTYLE2);
154 if ($selected_id != -1)
156 //editing an existing status code
158 if ($Mode == 'Edit') {
159 $group = get_tax_group($selected_id);
161 $_POST['name'] = $group["name"];
162 $_POST['tax_shipping'] = $group["tax_shipping"];
165 hidden('selected_id', $selected_id);
167 text_row_ex(_("Description:"), 'name', 40);
168 yesno_list_row(_("Tax applied to Shipping:"), 'tax_shipping', null, "", "", true);
172 display_note(_("Select the taxes that are included in this group."), 1, 1);
174 // null means transport tax group, but for new we do not use real rates
175 $items = get_tax_group_rates($selected_id!=-1 ? $selected_id : null);
177 $th = array(_("Tax"), "");
179 start_table(TABLESTYLE2);
182 while($item = db_fetch_assoc($items))
184 check_row($item['tax_type_name'], 'tax_type_id' . $item['tax_type_id'],
185 $selected_id!=-1 && isset($item['rate']), "align='center'");
190 submit_add_or_update_center($selected_id == -1, '', 'both');
194 //------------------------------------------------------------------------------------