6 include($path_to_root . "/includes/session.inc");
8 page(_("Item Tax Types"));
10 include_once($path_to_root . "/taxes/db/item_tax_types_db.inc");
11 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
13 include($path_to_root . "/includes/ui.inc");
15 if (isset($_GET['selected_id']))
17 $selected_id = $_GET['selected_id'];
19 elseif(isset($_POST['selected_id']))
21 $selected_id = $_POST['selected_id'];
24 //-----------------------------------------------------------------------------------
26 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
31 if (strlen($_POST['name']) == 0)
34 display_error(_("The item tax type description cannot be empty."));
37 if ($input_error != 1)
40 // create an array of the exemptions
41 $exempt_from = array();
43 $tax_types = get_all_tax_types_simple();
46 while ($myrow = db_fetch($tax_types))
48 if (check_value('ExemptTax' . $myrow["id"]))
50 $exempt_from[$i] = $myrow["id"];
55 if (isset($selected_id))
58 update_item_tax_type($selected_id, $_POST['name'], $_POST['exempt'], $exempt_from);
63 add_item_tax_type($_POST['name'], $_POST['exempt'], $exempt_from);
65 meta_forward($_SERVER['PHP_SELF']);
69 //-----------------------------------------------------------------------------------
71 function can_delete($selected_id)
73 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE tax_type_id=$selected_id";
74 $result = db_query($sql, "could not query stock master");
75 $myrow = db_fetch_row($result);
78 display_error(_("Cannot delete this item tax type because items have been created referring to it."));
86 //-----------------------------------------------------------------------------------
88 if (isset($_GET['delete']))
91 if (can_delete($selected_id))
93 delete_item_tax_type($selected_id);
94 meta_forward($_SERVER['PHP_SELF']);
98 //-----------------------------------------------------------------------------------
101 $result2 = $result = get_all_item_tax_types();
102 start_table("$table_style width=30%");
103 $th = array(_("Name"), _("Tax exempt"),'','');
108 while ($myrow = db_fetch($result2))
111 alt_table_row_color($k);
113 if ($myrow["exempt"] == 0)
115 $disallow_text = _("No");
119 $disallow_text = _("Yes");
122 label_cell($myrow["name"]);
123 label_cell($disallow_text);
124 edit_link_cell("selected_id=" . $myrow["id"]);
125 delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
131 //-----------------------------------------------------------------------------------
133 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Tax type"));
137 start_table($table_style2);
139 if (isset($selected_id))
142 if (!isset($_POST['name']))
144 $myrow = get_item_tax_type($selected_id);
146 $_POST['name'] = $myrow["name"];
147 $_POST['exempt'] = $myrow["exempt"];
149 // read the exemptions and check the ones that are on
150 $exemptions = get_item_tax_type_exemptions($selected_id);
152 if (db_num_rows($exemptions) > 0)
154 while ($exmp = db_fetch($exemptions))
156 $_POST['ExemptTax' . $exmp["tax_type_id"]] = 1;
161 hidden('selected_id', $selected_id);
164 text_row_ex(_("Description:"), 'name', 50);
166 yesno_list_row(_("Is Fully Tax-exempt:"), 'exempt', null, "", "", true);
170 if (!isset($_POST['exempt']) || $_POST['exempt'] == 0)
173 display_note(_("Select which taxes this item tax type is exempt from."), 0, 1);
175 start_table($table_style2);
176 $th = array(_("Tax Name"), _("Rate"), _("Is exempt"));
179 $tax_types = get_all_tax_types_simple();
181 while ($myrow = db_fetch($tax_types))
184 alt_table_row_color($k);
186 label_cell($myrow["name"]);
187 label_cell(percent_format($myrow["rate"])." %", "nowrap align=right");
188 check_cells("", 'ExemptTax' . $myrow["id"], null);
195 submit_add_or_update_center(!isset($selected_id));
199 //------------------------------------------------------------------------------------