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");
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()
26 if (strlen($_POST['name']) == 0)
28 display_error(_("The tax type name cannot be empty."));
32 elseif (!check_num('rate', 0))
34 display_error( _("The default tax rate must be numeric and not less than zero."));
42 //-----------------------------------------------------------------------------------
44 if ($Mode=='ADD_ITEM' && can_process())
47 add_tax_type($_POST['name'], $_POST['sales_gl_code'],
48 $_POST['purchasing_gl_code'], input_num('rate'));
49 display_notification(_('New tax type has been added'));
53 //-----------------------------------------------------------------------------------
55 if ($Mode=='UPDATE_ITEM' && can_process())
58 update_tax_type($selected_id, $_POST['name'],
59 $_POST['sales_gl_code'], $_POST['purchasing_gl_code'], input_num('rate'));
60 display_notification(_('Selected tax type has been updated'));
64 //-----------------------------------------------------------------------------------
66 function can_delete($selected_id)
68 $sql= "SELECT COUNT(*) FROM ".TB_PREF."tax_group_items WHERE tax_type_id=$selected_id";
69 $result = db_query($sql, "could not query tax groups");
70 $myrow = db_fetch_row($result);
73 display_error(_("Cannot delete this tax type because tax groups been created referring to it."));
82 //-----------------------------------------------------------------------------------
84 if ($Mode == 'Delete')
87 if (can_delete($selected_id))
89 delete_tax_type($selected_id);
90 display_notification(_('Selected tax type has been deleted'));
100 //-----------------------------------------------------------------------------------
102 $result = get_all_tax_types();
105 start_table($table_style);
107 $th = array(_("Description"), _("Default Rate (%)"),
108 _("Sales GL Account"), _("Purchasing GL Account"), "", "");
112 while ($myrow = db_fetch($result))
115 alt_table_row_color($k);
117 label_cell($myrow["name"]);
118 label_cell(percent_format($myrow["rate"]), "align=right");
119 label_cell($myrow["sales_gl_code"] . " " . $myrow["SalesAccountName"]);
120 label_cell($myrow["purchasing_gl_code"] . " " . $myrow["PurchasingAccountName"]);
122 edit_button_cell("Edit".$myrow["id"], _("Edit"));
123 delete_button_cell("Delete".$myrow["id"], _("Delete"));
133 //-----------------------------------------------------------------------------------
137 start_table($table_style2);
139 if ($selected_id != -1)
141 if ($Mode == 'Edit') {
142 //editing an existing status code
144 $myrow = get_tax_type($selected_id);
146 $_POST['name'] = $myrow["name"];
147 $_POST['rate'] = percent_format($myrow["rate"]);
148 $_POST['sales_gl_code'] = $myrow["sales_gl_code"];
149 $_POST['purchasing_gl_code'] = $myrow["purchasing_gl_code"];
151 hidden('selected_id', $selected_id);
153 text_row_ex(_("Description:"), 'name', 50);
154 small_amount_row(_("Default Rate:"), 'rate', '', "", "%", user_percent_dec());
156 gl_all_accounts_list_row(_("Sales GL Account:"), 'sales_gl_code', null);
157 gl_all_accounts_list_row(_("Purchasing GL Account:"), 'purchasing_gl_code', null);
161 submit_add_or_update_center($selected_id == -1, '', 'both');