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_TAXRATES';
15 include($path_to_root . "/includes/session.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
21 simple_page_mode(true);
22 //-----------------------------------------------------------------------------------
24 function can_process()
28 if (strlen($_POST['name']) == 0)
30 display_error(_("The tax type name cannot be empty."));
34 elseif (!check_num('rate', 0))
36 display_error( _("The default tax rate must be numeric and not less than zero."));
41 if (!is_tax_gl_unique(get_post('sales_gl_code', 'purchasing_gl_code', $selected_id))) {
42 display_error( _("Selected GL Accounts cannot be used by another tax type."));
43 set_focus('sales_gl_code');
49 //-----------------------------------------------------------------------------------
51 if ($Mode=='ADD_ITEM' && can_process())
54 add_tax_type($_POST['name'], $_POST['sales_gl_code'],
55 $_POST['purchasing_gl_code'], input_num('rate', 0));
56 display_notification(_('New tax type has been added'));
60 //-----------------------------------------------------------------------------------
62 if ($Mode=='UPDATE_ITEM' && can_process())
65 update_tax_type($selected_id, $_POST['name'],
66 $_POST['sales_gl_code'], $_POST['purchasing_gl_code'], input_num('rate'));
67 display_notification(_('Selected tax type has been updated'));
71 //-----------------------------------------------------------------------------------
73 function can_delete($selected_id)
75 $sql= "SELECT COUNT(*) FROM ".TB_PREF."tax_group_items WHERE tax_type_id=".db_escape($selected_id);
76 $result = db_query($sql, "could not query tax groups");
77 $myrow = db_fetch_row($result);
80 display_error(_("Cannot delete this tax type because tax groups been created referring to it."));
89 //-----------------------------------------------------------------------------------
91 if ($Mode == 'Delete')
94 if (can_delete($selected_id))
96 delete_tax_type($selected_id);
97 display_notification(_('Selected tax type has been deleted'));
102 if ($Mode == 'RESET')
105 $sav = get_post('show_inactive');
107 $_POST['show_inactive'] = $sav;
109 //-----------------------------------------------------------------------------------
111 $result = get_all_tax_types(check_value('show_inactive'));
115 display_note(_("To avoid problems with manual journal entry all tax types should have unique Sales/Purchasing GL accounts."));
116 start_table($table_style);
118 $th = array(_("Description"), _("Default Rate (%)"),
119 _("Sales GL Account"), _("Purchasing GL Account"), "", "");
120 inactive_control_column($th);
124 while ($myrow = db_fetch($result))
127 alt_table_row_color($k);
129 label_cell($myrow["name"]);
130 label_cell(percent_format($myrow["rate"]), "align=right");
131 label_cell($myrow["sales_gl_code"] . " " . $myrow["SalesAccountName"]);
132 label_cell($myrow["purchasing_gl_code"] . " " . $myrow["PurchasingAccountName"]);
134 inactive_control_cell($myrow["id"], $myrow["inactive"], 'tax_types', 'id');
135 edit_button_cell("Edit".$myrow["id"], _("Edit"));
136 delete_button_cell("Delete".$myrow["id"], _("Delete"));
141 inactive_control_row($th);
143 //-----------------------------------------------------------------------------------
145 start_table($table_style2);
147 if ($selected_id != -1)
149 if ($Mode == 'Edit') {
150 //editing an existing status code
152 $myrow = get_tax_type($selected_id);
154 $_POST['name'] = $myrow["name"];
155 $_POST['rate'] = percent_format($myrow["rate"]);
156 $_POST['sales_gl_code'] = $myrow["sales_gl_code"];
157 $_POST['purchasing_gl_code'] = $myrow["purchasing_gl_code"];
159 hidden('selected_id', $selected_id);
161 text_row_ex(_("Description:"), 'name', 50);
162 small_amount_row(_("Default Rate:"), 'rate', '', "", "%", user_percent_dec());
164 gl_all_accounts_list_row(_("Sales GL Account:"), 'sales_gl_code', null);
165 gl_all_accounts_list_row(_("Purchasing GL Account:"), 'purchasing_gl_code', null);
169 submit_add_or_update_center($selected_id == -1, '', 'both');