5 include($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
12 if (isset($_GET['selected_id']))
14 $selected_id = $_GET['selected_id'];
16 elseif(isset($_POST['selected_id']))
18 $selected_id = $_POST['selected_id'];
20 //-----------------------------------------------------------------------------------
22 function can_process()
24 if (strlen($_POST['name']) == 0)
26 display_error(_("The tax type name cannot be empty."));
29 elseif (!is_numeric($_POST['rate']))
31 display_error( _("The default tax rate must be numeric."));
34 elseif ($_POST['rate'] < 0)
36 display_error( _("The default tax rate cannot be less than zero."));
43 //-----------------------------------------------------------------------------------
45 if (isset($_POST['ADD_ITEM']) && can_process())
48 add_tax_type($_POST['name'], $_POST['sales_gl_code'],
49 $_POST['purchasing_gl_code'], $_POST['rate'], check_value('out'));
50 meta_forward($_SERVER['PHP_SELF']);
53 //-----------------------------------------------------------------------------------
55 if (isset($_POST['UPDATE_ITEM']) && can_process())
58 update_tax_type($selected_id, $_POST['name'],
59 $_POST['sales_gl_code'], $_POST['purchasing_gl_code'], $_POST['rate'], check_value('out'));
60 meta_forward($_SERVER['PHP_SELF']);
63 //-----------------------------------------------------------------------------------
65 function can_delete($selected_id)
67 $sql= "SELECT COUNT(*) FROM ".TB_PREF."tax_group_items WHERE tax_type_id=$selected_id";
68 $result = db_query($sql, "could not query tax groups");
69 $myrow = db_fetch_row($result);
72 display_error(_("Cannot delete this tax type because tax groups been created referring to it."));
80 //-----------------------------------------------------------------------------------
82 if (isset($_GET['delete']))
85 if (can_delete($selected_id))
87 delete_tax_type($selected_id);
88 meta_forward($_SERVER['PHP_SELF']);
92 //-----------------------------------------------------------------------------------
94 $result = get_all_tax_types();
96 start_table($table_style);
98 $th = array(_("Description"), _("Default Rate (%)"),
99 _("Sales GL Account"), _("Purchasing GL Account"), _("Outstanding"), "", "");
103 while ($myrow = db_fetch($result))
106 if ($myrow['out'] == 1)
110 alt_table_row_color($k);
112 label_cell($myrow["name"]);
113 label_cell(number_format2($myrow["rate"],user_percent_dec()), "align=right");
114 label_cell($myrow["sales_gl_code"] . " " . $myrow["SalesAccountName"]);
115 label_cell($myrow["purchasing_gl_code"] . " " . $myrow["PurchasingAccountName"]);
118 edit_link_cell("selected_id=".$myrow["id"]);
119 delete_link_cell("selected_id=".$myrow["id"]."&delete=1");
125 //-----------------------------------------------------------------------------------
127 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Tax Type"));
129 //-----------------------------------------------------------------------------------
133 start_table($table_style2);
135 if (isset($selected_id))
137 //editing an existing status code
139 $myrow = get_tax_type($selected_id);
141 $_POST['name'] = $myrow["name"];
142 $_POST['rate'] = $myrow["rate"];
143 $_POST['sales_gl_code'] = $myrow["sales_gl_code"];
144 $_POST['purchasing_gl_code'] = $myrow["purchasing_gl_code"];
145 $_POST['out'] = $myrow["out"];
147 hidden('selected_id', $selected_id);
149 text_row_ex(_("Description:"), 'name', 50);
150 text_row_ex(_("Default Rate:"), 'rate', 10, 10, "", "%");
152 gl_all_accounts_list_row(_("Sales GL Account:"), 'sales_gl_code', null);
153 gl_all_accounts_list_row(_("Purchasing GL Account:"), 'purchasing_gl_code', null);
155 check_row(_("Outstanding:"), 'out', null);
159 submit_add_or_update_center(!isset($selected_id));