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 ***********************************************************************/
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."));
45 // make sure any entered rates are valid
46 for ($i = 0; $i < 5; $i++)
48 if (isset($_POST['tax_type_id' . $i]) &&
49 $_POST['tax_type_id' . $i] != reserved_words::get_all_numeric() &&
50 !check_num('rate' . $i, 0))
52 display_error( _("An entered tax rate is invalid or less than zero."));
60 if ($input_error != 1)
63 // create an array of the taxes and array of rates
67 for ($i = 0; $i < 5; $i++)
69 if (isset($_POST['tax_type_id' . $i]) &&
70 $_POST['tax_type_id' . $i] != reserved_words::get_any_numeric())
72 $taxes[] = $_POST['tax_type_id' . $i];
73 $rates[] = input_num('rate' . $i);
77 if ($selected_id != -1)
79 update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes,
81 display_notification(_('Selected tax group has been updated'));
85 add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates);
86 display_notification(_('New tax group has been added'));
93 //-----------------------------------------------------------------------------------
95 function can_delete($selected_id)
97 if ($selected_id == -1)
99 $sql = "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE tax_group_id=$selected_id";
100 $result = db_query($sql, "could not query customers");
101 $myrow = db_fetch_row($result);
104 display_note(_("Cannot delete this tax group because customer branches been created referring to it."));
108 $sql = "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE tax_group_id=$selected_id";
109 $result = db_query($sql, "could not query suppliers");
110 $myrow = db_fetch_row($result);
113 display_note(_("Cannot delete this tax group because suppliers been created referring to it."));
122 //-----------------------------------------------------------------------------------
124 if ($Mode == 'Delete')
127 if (can_delete($selected_id))
129 delete_tax_group($selected_id);
130 display_notification(_('Selected tax group has been deleted'));
135 if ($Mode == 'RESET')
140 //-----------------------------------------------------------------------------------
142 $result = get_all_tax_groups();
145 start_table($table_style);
146 $th = array(_("Description"), _("Tax Shipping"), "", "");
150 while ($myrow = db_fetch($result))
153 alt_table_row_color($k);
155 label_cell($myrow["name"]);
156 if ($myrow["tax_shipping"])
157 label_cell(_("Yes"));
161 /*for ($i=0; $i< 5; $i++)
162 if ($myrow["type" . $i] != reserved_words::get_all_numeric())
163 echo "<td>" . $myrow["type" . $i] . "</td>";*/
165 edit_button_cell("Edit".$myrow["id"], _("Edit"));
166 delete_button_cell("Delete".$myrow["id"], _("Delete"));
174 //-----------------------------------------------------------------------------------
178 start_table($table_style2);
180 if ($selected_id != -1)
182 //editing an existing status code
184 if ($Mode == 'Edit') {
185 $group = get_tax_group($selected_id);
187 $_POST['name'] = $group["name"];
188 $_POST['tax_shipping'] = $group["tax_shipping"];
190 $items = get_tax_group_items($selected_id);
193 while ($tax_item = db_fetch($items))
195 $_POST['tax_type_id' . $i] = $tax_item["tax_type_id"];
196 $_POST['rate' . $i] = percent_format($tax_item["rate"]);
201 hidden('selected_id', $selected_id);
203 text_row_ex(_("Description:"), 'name', 40);
204 yesno_list_row(_("Tax Shipping:"), 'tax_shipping', null, "", "", true);
208 display_note(_("Select the taxes that are included in this group."), 1);
210 start_table($table_style2);
211 $th = array(_("Tax"), _("Default Rate (%)"), _("Rate (%)"));
213 for ($i = 0; $i < 5; $i++)
216 if (!isset($_POST['tax_type_id' . $i]))
217 $_POST['tax_type_id' . $i] = 0;
218 tax_types_list_cells(null, 'tax_type_id' . $i, $_POST['tax_type_id' . $i], _("None"), true);
220 if ($_POST['tax_type_id' . $i] != 0 && $_POST['tax_type_id' . $i] != reserved_words::get_all_numeric())
223 $default_rate = get_tax_type_default_rate($_POST['tax_type_id' . $i]);
224 label_cell(percent_format($default_rate), "nowrap align=right");
226 if (!isset($_POST['rate' . $i]) || $_POST['rate' . $i] == "")
227 $_POST['rate' . $i] = percent_format($default_rate);
228 small_amount_cells(null, 'rate' . $i, $_POST['rate' . $i], null, null,
236 submit_add_or_update_center($selected_id == -1, '', true);
240 //------------------------------------------------------------------------------------