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."));
38 if ($input_error != 1)
41 // create an array of the exemptions
42 $exempt_from = array();
44 $tax_types = get_all_tax_types_simple();
47 while ($myrow = db_fetch($tax_types))
49 if (check_value('ExemptTax' . $myrow["id"]))
51 $exempt_from[$i] = $myrow["id"];
56 if (isset($selected_id))
59 update_item_tax_type($selected_id, $_POST['name'], $_POST['exempt'], $exempt_from);
64 add_item_tax_type($_POST['name'], $_POST['exempt'], $exempt_from);
66 meta_forward($_SERVER['PHP_SELF']);
70 //-----------------------------------------------------------------------------------
72 function can_delete($selected_id)
74 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE tax_type_id=$selected_id";
75 $result = db_query($sql, "could not query stock master");
76 $myrow = db_fetch_row($result);
79 display_error(_("Cannot delete this item tax type because items have been created referring to it."));
87 //-----------------------------------------------------------------------------------
89 if (isset($_GET['delete']))
92 if (can_delete($selected_id))
94 delete_item_tax_type($selected_id);
95 meta_forward($_SERVER['PHP_SELF']);
99 //-----------------------------------------------------------------------------------
102 $result2 = $result = get_all_item_tax_types();
103 start_table("$table_style width=30%");
104 $th = array(_("Name"), _("Tax exempt"),'','');
109 while ($myrow = db_fetch($result2))
112 alt_table_row_color($k);
114 if ($myrow["exempt"] == 0)
116 $disallow_text = _("No");
120 $disallow_text = _("Yes");
123 label_cell($myrow["name"]);
124 label_cell($disallow_text);
125 edit_link_cell("selected_id=" . $myrow["id"]);
126 delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
132 //-----------------------------------------------------------------------------------
134 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Tax type"));
138 start_table($table_style2);
140 if (isset($selected_id))
143 if (!isset($_POST['name']))
145 $myrow = get_item_tax_type($selected_id);
147 $_POST['name'] = $myrow["name"];
148 $_POST['exempt'] = $myrow["exempt"];
150 // read the exemptions and check the ones that are on
151 $exemptions = get_item_tax_type_exemptions($selected_id);
153 if (db_num_rows($exemptions) > 0)
155 while ($exmp = db_fetch($exemptions))
157 $_POST['ExemptTax' . $exmp["tax_type_id"]] = 1;
162 hidden('selected_id', $selected_id);
165 text_row_ex(_("Description:"), 'name', 50);
167 yesno_list_row(_("Is Fully Tax-exempt:"), 'exempt', null, "", "", true);
171 if (!isset($_POST['exempt']) || $_POST['exempt'] == 0)
174 display_note(_("Select which taxes this item tax type is exempt from."), 0, 1);
176 start_table($table_style2);
177 $th = array(_("Tax Name"), _("Rate"), _("Is exempt"));
180 $tax_types = get_all_tax_types_simple();
182 while ($myrow = db_fetch($tax_types))
185 alt_table_row_color($k);
187 label_cell($myrow["name"]);
188 label_cell(percent_format($myrow["rate"])." %", "nowrap align=right");
189 check_cells("", 'ExemptTax' . $myrow["id"], null);
196 submit_add_or_update_center(!isset($selected_id));
200 //------------------------------------------------------------------------------------