. ***********************************************************************/ $page_security = 3; $path_to_root=".."; include($path_to_root . "/includes/session.inc"); page(_("Tax Groups")); include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/taxes/db/tax_groups_db.inc"); include_once($path_to_root . "/taxes/db/tax_types_db.inc"); simple_page_mode(true); check_db_has_tax_types(_("There are no tax types defined. Define tax types before defining tax groups.")); //----------------------------------------------------------------------------------- if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { //initialise no input errors assumed initially before we test $input_error = 0; if (strlen($_POST['name']) == 0) { $input_error = 1; display_error(_("The tax group name cannot be empty.")); set_focus('name'); } else { // make sure any entered rates are valid for ($i = 0; $i < 5; $i++) { if (isset($_POST['tax_type_id' . $i]) && $_POST['tax_type_id' . $i] != reserved_words::get_all_numeric() && !check_num('rate' . $i, 0)) { display_error( _("An entered tax rate is invalid or less than zero.")); $input_error = 1; set_focus('rate'); break; } } } if ($input_error != 1) { // create an array of the taxes and array of rates $taxes = array(); $rates = array(); for ($i = 0; $i < 5; $i++) { if (isset($_POST['tax_type_id' . $i]) && $_POST['tax_type_id' . $i] != reserved_words::get_any_numeric()) { $taxes[] = $_POST['tax_type_id' . $i]; $rates[] = input_num('rate' . $i); } } if ($selected_id != -1) { update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes, $rates); display_notification(_('Selected tax group has been updated')); } else { add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates); display_notification(_('New tax group has been added')); } $Mode = 'RESET'; } } //----------------------------------------------------------------------------------- function can_delete($selected_id) { if ($selected_id == -1) return false; $sql = "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE tax_group_id=$selected_id"; $result = db_query($sql, "could not query customers"); $myrow = db_fetch_row($result); if ($myrow[0] > 0) { display_note(_("Cannot delete this tax group because customer branches been created referring to it.")); return false; } $sql = "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE tax_group_id=$selected_id"; $result = db_query($sql, "could not query suppliers"); $myrow = db_fetch_row($result); if ($myrow[0] > 0) { display_note(_("Cannot delete this tax group because suppliers been created referring to it.")); return false; } return true; } //----------------------------------------------------------------------------------- if ($Mode == 'Delete') { if (can_delete($selected_id)) { delete_tax_group($selected_id); display_notification(_('Selected tax group has been deleted')); } $Mode = 'RESET'; } if ($Mode == 'RESET') { $selected_id = -1; unset($_POST); } //----------------------------------------------------------------------------------- $result = get_all_tax_groups(); start_form(); start_table($table_style); $th = array(_("Description"), _("Tax Shipping"), "", ""); table_header($th); $k = 0; while ($myrow = db_fetch($result)) { alt_table_row_color($k); label_cell($myrow["name"]); if ($myrow["tax_shipping"]) label_cell(_("Yes")); else label_cell(_("No")); /*for ($i=0; $i< 5; $i++) if ($myrow["type" . $i] != reserved_words::get_all_numeric()) echo "