5 include($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/ui.inc");
9 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
11 simple_page_mode(true);
12 //-----------------------------------------------------------------------------------
14 function can_process()
16 if (strlen($_POST['name']) == 0)
18 display_error(_("The tax type name cannot be empty."));
22 elseif (!check_num('rate', 0))
24 display_error( _("The default tax rate must be numeric and not less than zero."));
32 //-----------------------------------------------------------------------------------
34 if ($Mode=='ADD_ITEM' && can_process())
37 add_tax_type($_POST['name'], $_POST['sales_gl_code'],
38 $_POST['purchasing_gl_code'], input_num('rate'));
39 display_notification(_('New tax type has been added'));
43 //-----------------------------------------------------------------------------------
45 if ($Mode=='UPDATE_ITEM' && can_process())
48 update_tax_type($selected_id, $_POST['name'],
49 $_POST['sales_gl_code'], $_POST['purchasing_gl_code'], input_num('rate'));
50 display_notification(_('Selected tax type has been updated'));
54 //-----------------------------------------------------------------------------------
56 function can_delete($selected_id)
58 $sql= "SELECT COUNT(*) FROM ".TB_PREF."tax_group_items WHERE tax_type_id=$selected_id";
59 $result = db_query($sql, "could not query tax groups");
60 $myrow = db_fetch_row($result);
63 display_error(_("Cannot delete this tax type because tax groups been created referring to it."));
72 //-----------------------------------------------------------------------------------
74 if ($Mode == 'Delete')
77 if (can_delete($selected_id))
79 delete_tax_type($selected_id);
80 display_notification(_('Selected tax type has been deleted'));
90 //-----------------------------------------------------------------------------------
92 $result = get_all_tax_types();
95 start_table($table_style);
97 $th = array(_("Description"), _("Default Rate (%)"),
98 _("Sales GL Account"), _("Purchasing GL Account"), "", "");
102 while ($myrow = db_fetch($result))
105 alt_table_row_color($k);
107 label_cell($myrow["name"]);
108 label_cell(percent_format($myrow["rate"]), "align=right");
109 label_cell($myrow["sales_gl_code"] . " " . $myrow["SalesAccountName"]);
110 label_cell($myrow["purchasing_gl_code"] . " " . $myrow["PurchasingAccountName"]);
112 edit_button_cell("Edit".$myrow["id"], _("Edit"));
113 edit_button_cell("Delete".$myrow["id"], _("Delete"));
123 //-----------------------------------------------------------------------------------
127 start_table($table_style2);
129 if ($selected_id != -1)
131 if ($Mode == 'Edit') {
132 //editing an existing status code
134 $myrow = get_tax_type($selected_id);
136 $_POST['name'] = $myrow["name"];
137 $_POST['rate'] = percent_format($myrow["rate"]);
138 $_POST['sales_gl_code'] = $myrow["sales_gl_code"];
139 $_POST['purchasing_gl_code'] = $myrow["purchasing_gl_code"];
141 hidden('selected_id', $selected_id);
143 text_row_ex(_("Description:"), 'name', 50);
144 small_amount_row(_("Default Rate:"), 'rate', '', "", "%", user_percent_dec());
146 gl_all_accounts_list_row(_("Sales GL Account:"), 'sales_gl_code', null);
147 gl_all_accounts_list_row(_("Purchasing GL Account:"), 'purchasing_gl_code', null);
151 submit_add_or_update_center($selected_id == -1, '', true);