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_ITEMTAXTYPE';
15 include($path_to_root . "/includes/session.inc");
17 page(_($help_context = "Item Tax Types"));
19 include_once($path_to_root . "/taxes/db/item_tax_types_db.inc");
20 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
22 include($path_to_root . "/includes/ui.inc");
24 simple_page_mode(true);
25 //-----------------------------------------------------------------------------------
27 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
32 if (strlen($_POST['name']) == 0)
35 display_error(_("The item tax type description cannot be empty."));
39 if ($input_error != 1)
42 // create an array of the exemptions
43 $exempt_from = array();
45 $tax_types = get_all_tax_types_simple();
48 while ($myrow = db_fetch($tax_types))
50 if (check_value('ExemptTax' . $myrow["id"]))
52 $exempt_from[$i] = $myrow["id"];
57 if ($selected_id != -1)
59 update_item_tax_type($selected_id, $_POST['name'], $_POST['exempt'], $exempt_from);
60 display_notification(_('Selected item tax type has been updated'));
64 add_item_tax_type($_POST['name'], $_POST['exempt'], $exempt_from);
65 display_notification(_('New item tax type has been added'));
71 //-----------------------------------------------------------------------------------
73 function can_delete($selected_id)
75 if (key_in_foreign_table($selected_id, 'stock_master', 'tax_type_id'))
77 display_error(_("Cannot delete this item tax type because items have been created referring to it."));
80 if (key_in_foreign_table($selected_id, 'stock_category', 'dflt_tax_type'))
82 display_error(_("Cannot delete this item tax type because item categories have been created referring to it."));
90 //-----------------------------------------------------------------------------------
92 if ($Mode == 'Delete')
95 if (can_delete($selected_id))
97 delete_item_tax_type($selected_id);
98 display_notification(_('Selected item tax type has been deleted'));
103 if ($Mode == 'RESET')
106 $sav = get_post('show_inactive');
108 $_POST['show_inactive'] = $sav;
110 //-----------------------------------------------------------------------------------
113 $result2 = $result = get_all_item_tax_types(check_value('show_inactive'));
116 start_table(TABLESTYLE, "width='30%'");
117 $th = array(_("Name"), _("Tax exempt"),'','');
118 inactive_control_column($th);
122 while ($myrow = db_fetch($result2))
125 alt_table_row_color($k);
127 if ($myrow["exempt"] == 0)
129 $disallow_text = _("No");
133 $disallow_text = _("Yes");
136 label_cell($myrow["name"]);
137 label_cell($disallow_text);
138 inactive_control_cell($myrow["id"], $myrow["inactive"], 'item_tax_types', 'id');
139 edit_button_cell("Edit".$myrow["id"], _("Edit"));
140 delete_button_cell("Delete".$myrow["id"], _("Delete"));
144 inactive_control_row($th);
146 //-----------------------------------------------------------------------------------
148 start_table(TABLESTYLE2);
150 if ($selected_id != -1)
152 if ($Mode == 'Edit') {
153 $myrow = get_item_tax_type($selected_id);
154 unset($_POST); // clear exemption checkboxes
155 $_POST['name'] = $myrow["name"];
156 $_POST['exempt'] = $myrow["exempt"];
158 // read the exemptions and check the ones that are on
159 $exemptions = get_item_tax_type_exemptions($selected_id);
161 if (db_num_rows($exemptions) > 0)
163 while ($exmp = db_fetch($exemptions))
165 $_POST['ExemptTax' . $exmp["tax_type_id"]] = 1;
170 hidden('selected_id', $selected_id);
173 text_row_ex(_("Description:"), 'name', 50);
175 yesno_list_row(_("Is Fully Tax-exempt:"), 'exempt', null, "", "", true);
179 if (!isset($_POST['exempt']) || $_POST['exempt'] == 0)
182 display_note(_("Select which taxes this item tax type is exempt from."), 0, 1);
184 start_table(TABLESTYLE2);
185 $th = array(_("Tax Name"), _("Rate"), _("Is exempt"));
188 $tax_types = get_all_tax_types_simple();
190 while ($myrow = db_fetch($tax_types))
193 alt_table_row_color($k);
195 label_cell($myrow["name"]);
196 label_cell(percent_format($myrow["rate"])." %", "nowrap align=right");
197 check_cells("", 'ExemptTax' . $myrow["id"], null);
204 submit_add_or_update_center($selected_id == -1, '', 'both');
208 //------------------------------------------------------------------------------------