6 include($path_to_root . "/includes/session.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
11 include_once($path_to_root . "/includes/ui.inc");
13 include_once($path_to_root . "/taxes/db/tax_groups_db.inc");
14 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
16 simple_page_mode(true);
18 check_db_has_tax_types(_("There are no tax types defined. Define tax types before defining tax groups."));
20 //-----------------------------------------------------------------------------------
22 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
25 //initialise no input errors assumed initially before we test
28 if (strlen($_POST['name']) == 0)
31 display_error(_("The tax group name cannot be empty."));
36 // make sure any entered rates are valid
37 for ($i = 0; $i < 5; $i++)
39 if (isset($_POST['tax_type_id' . $i]) &&
40 $_POST['tax_type_id' . $i] != reserved_words::get_all_numeric() &&
41 !check_num('rate' . $i, 0))
43 display_error( _("An entered tax rate is invalid or less than zero."));
51 if ($input_error != 1)
54 // create an array of the taxes and array of rates
58 for ($i = 0; $i < 5; $i++)
60 if (isset($_POST['tax_type_id' . $i]) &&
61 $_POST['tax_type_id' . $i] != reserved_words::get_any_numeric())
63 $taxes[] = $_POST['tax_type_id' . $i];
64 $rates[] = input_num('rate' . $i);
68 if ($selected_id != -1)
70 update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes,
72 display_notification(_('Selected tax group has been updated'));
76 add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates);
77 display_notification(_('New tax group has been added'));
84 //-----------------------------------------------------------------------------------
86 function can_delete($selected_id)
88 if ($selected_id == -1)
90 $sql = "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE tax_group_id=$selected_id";
91 $result = db_query($sql, "could not query customers");
92 $myrow = db_fetch_row($result);
95 display_note(_("Cannot delete this tax group because customer branches been created referring to it."));
99 $sql = "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE tax_group_id=$selected_id";
100 $result = db_query($sql, "could not query suppliers");
101 $myrow = db_fetch_row($result);
104 display_note(_("Cannot delete this tax group because suppliers been created referring to it."));
113 //-----------------------------------------------------------------------------------
115 if ($Mode == 'Delete')
118 if (can_delete($selected_id))
120 delete_tax_group($selected_id);
121 display_notification(_('Selected tax group has been deleted'));
126 if ($Mode == 'RESET')
131 //-----------------------------------------------------------------------------------
133 $result = get_all_tax_groups();
136 start_table($table_style);
137 $th = array(_("Description"), _("Tax Shipping"), "", "");
141 while ($myrow = db_fetch($result))
144 alt_table_row_color($k);
146 label_cell($myrow["name"]);
147 if ($myrow["tax_shipping"])
148 label_cell(_("Yes"));
152 /*for ($i=0; $i< 5; $i++)
153 if ($myrow["type" . $i] != reserved_words::get_all_numeric())
154 echo "<td>" . $myrow["type" . $i] . "</td>";*/
156 edit_button_cell("Edit".$myrow["id"], _("Edit"));
157 edit_button_cell("Delete".$myrow["id"], _("Delete"));
165 //-----------------------------------------------------------------------------------
169 start_table($table_style2);
171 if ($selected_id != -1)
173 //editing an existing status code
175 if ($Mode == 'Edit') {
176 $group = get_tax_group($selected_id);
178 $_POST['name'] = $group["name"];
179 $_POST['tax_shipping'] = $group["tax_shipping"];
181 $items = get_tax_group_items($selected_id);
184 while ($tax_item = db_fetch($items))
186 $_POST['tax_type_id' . $i] = $tax_item["tax_type_id"];
187 $_POST['rate' . $i] = percent_format($tax_item["rate"]);
192 hidden('selected_id', $selected_id);
194 text_row_ex(_("Description:"), 'name', 40);
195 yesno_list_row(_("Tax Shipping:"), 'tax_shipping', null, "", "", true);
199 display_note(_("Select the taxes that are included in this group."), 1);
201 start_table($table_style2);
202 $th = array(_("Tax"), _("Default Rate (%)"), _("Rate (%)"));
204 for ($i = 0; $i < 5; $i++)
207 if (!isset($_POST['tax_type_id' . $i]))
208 $_POST['tax_type_id' . $i] = 0;
209 tax_types_list_cells(null, 'tax_type_id' . $i, $_POST['tax_type_id' . $i], _("None"), true);
211 if ($_POST['tax_type_id' . $i] != 0 && $_POST['tax_type_id' . $i] != reserved_words::get_all_numeric())
214 $default_rate = get_tax_type_default_rate($_POST['tax_type_id' . $i]);
215 label_cell(percent_format($default_rate), "nowrap align=right");
217 if (!isset($_POST['rate' . $i]) || $_POST['rate' . $i] == "")
218 $_POST['rate' . $i] = percent_format($default_rate);
219 small_amount_cells(null, 'rate' . $i, $_POST['rate' . $i], null, null,
227 submit_add_or_update_center($selected_id == -1, '', true);
231 //------------------------------------------------------------------------------------