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(_("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 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE tax_type_id=$selected_id";
76 $result = db_query($sql, "could not query stock master");
77 $myrow = db_fetch_row($result);
80 display_error(_("Cannot delete this item tax type because items have been created referring to it."));
88 //-----------------------------------------------------------------------------------
90 if ($Mode == 'Delete')
93 if (can_delete($selected_id))
95 delete_item_tax_type($selected_id);
96 display_notification(_('Selected item tax type has been deleted'));
101 if ($Mode == 'RESET')
104 $sav = get_post('show_inactive');
106 $_POST['show_inactive'] = $sav;
108 //-----------------------------------------------------------------------------------
111 $result2 = $result = get_all_item_tax_types(check_value('show_inactive'));
114 start_table("$table_style width=30%");
115 $th = array(_("Name"), _("Tax exempt"),'','');
116 inactive_control_column($th);
120 while ($myrow = db_fetch($result2))
123 alt_table_row_color($k);
125 if ($myrow["exempt"] == 0)
127 $disallow_text = _("No");
131 $disallow_text = _("Yes");
134 label_cell($myrow["name"]);
135 label_cell($disallow_text);
136 inactive_control_cell($myrow["id"], $myrow["inactive"], 'item_tax_types', 'id');
137 edit_button_cell("Edit".$myrow["id"], _("Edit"));
138 delete_button_cell("Delete".$myrow["id"], _("Delete"));
142 inactive_control_row($th);
144 //-----------------------------------------------------------------------------------
146 start_table($table_style2);
148 if ($selected_id != -1)
150 if ($Mode == 'Edit') {
151 $myrow = get_item_tax_type($selected_id);
153 $_POST['name'] = $myrow["name"];
154 $_POST['exempt'] = $myrow["exempt"];
156 // read the exemptions and check the ones that are on
157 $exemptions = get_item_tax_type_exemptions($selected_id);
159 if (db_num_rows($exemptions) > 0)
161 while ($exmp = db_fetch($exemptions))
163 $_POST['ExemptTax' . $exmp["tax_type_id"]] = 1;
168 hidden('selected_id', $selected_id);
171 text_row_ex(_("Description:"), 'name', 50);
173 yesno_list_row(_("Is Fully Tax-exempt:"), 'exempt', null, "", "", true);
177 if (!isset($_POST['exempt']) || $_POST['exempt'] == 0)
180 display_note(_("Select which taxes this item tax type is exempt from."), 0, 1);
182 start_table($table_style2);
183 $th = array(_("Tax Name"), _("Rate"), _("Is exempt"));
186 $tax_types = get_all_tax_types_simple();
188 while ($myrow = db_fetch($tax_types))
191 alt_table_row_color($k);
193 label_cell($myrow["name"]);
194 label_cell(percent_format($myrow["rate"])." %", "nowrap align=right");
195 check_cells("", 'ExemptTax' . $myrow["id"], null);
202 submit_add_or_update_center($selected_id == -1, '', 'both');
206 //------------------------------------------------------------------------------------