Fixed numeric fields to accept user native number format.
[fa-stable.git] / taxes / tax_types.php
1 <?php
2 $page_security = 3;
3 $path_to_root="..";
4
5 include($path_to_root . "/includes/session.inc");
6 page(_("Tax Types"));
7
8 include_once($path_to_root . "/includes/ui.inc");
9 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
10
11 if (isset($_GET['selected_id']))
12 {
13         $selected_id = $_GET['selected_id'];
14 }
15 elseif(isset($_POST['selected_id']))
16 {
17         $selected_id = $_POST['selected_id'];
18 }
19 //-----------------------------------------------------------------------------------
20
21 function can_process()
22 {
23         if (strlen($_POST['name']) == 0)
24         {
25                 display_error(_("The tax type name cannot be empty."));
26                 return false;
27         }
28         elseif (!check_num('rate', 0))
29         {
30                 display_error( _("The default tax rate must be numeric and not less than zero."));
31                 return false;
32         }
33
34         return true;
35 }
36
37 //-----------------------------------------------------------------------------------
38
39 if (isset($_POST['ADD_ITEM']) && can_process())
40 {
41
42         add_tax_type($_POST['name'], $_POST['sales_gl_code'],
43                 $_POST['purchasing_gl_code'], imput_num('rate'));
44         meta_forward($_SERVER['PHP_SELF']);
45 }
46
47 //-----------------------------------------------------------------------------------
48
49 if (isset($_POST['UPDATE_ITEM']) && can_process())
50 {
51
52         update_tax_type($selected_id, $_POST['name'],
53         $_POST['sales_gl_code'], $_POST['purchasing_gl_code'], input_num('rate'));
54         meta_forward($_SERVER['PHP_SELF']);
55 }
56
57 //-----------------------------------------------------------------------------------
58
59 function can_delete($selected_id)
60 {
61         $sql= "SELECT COUNT(*) FROM ".TB_PREF."tax_group_items  WHERE tax_type_id=$selected_id";
62         $result = db_query($sql, "could not query tax groups");
63         $myrow = db_fetch_row($result);
64         if ($myrow[0] > 0)
65         {
66                 display_error(_("Cannot delete this tax type because tax groups been created referring to it."));
67                 return false;
68         }
69
70         return true;
71 }
72
73
74 //-----------------------------------------------------------------------------------
75
76 if (isset($_GET['delete']))
77 {
78
79         if (can_delete($selected_id))
80         {
81                 delete_tax_type($selected_id);
82                 meta_forward($_SERVER['PHP_SELF']);
83         }
84 }
85
86 //-----------------------------------------------------------------------------------
87
88 $result = get_all_tax_types();
89
90 start_table($table_style);
91
92 $th = array(_("Description"), _("Default Rate (%)"),
93         _("Sales GL Account"), _("Purchasing GL Account"), "", "");
94 table_header($th);
95
96 $k = 0;
97 while ($myrow = db_fetch($result))
98 {
99
100         alt_table_row_color($k);
101
102         label_cell($myrow["name"]);
103         label_cell(percent_format($myrow["rate"]), "align=right");
104         label_cell($myrow["sales_gl_code"] . "&nbsp;" . $myrow["SalesAccountName"]);
105         label_cell($myrow["purchasing_gl_code"] . "&nbsp;" . $myrow["PurchasingAccountName"]);
106
107         edit_link_cell("selected_id=".$myrow["id"]);
108         delete_link_cell("selected_id=".$myrow["id"]."&delete=1");
109
110         end_row();
111 }
112
113 end_table();
114
115 //-----------------------------------------------------------------------------------
116
117 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Tax Type"));
118
119 //-----------------------------------------------------------------------------------
120
121 start_form();
122
123 start_table($table_style2);
124
125 if (isset($selected_id))
126 {
127         //editing an existing status code
128
129         $myrow = get_tax_type($selected_id);
130
131         $_POST['name']  = $myrow["name"];
132         $_POST['rate']  = percent_format($myrow["rate"]);
133         $_POST['sales_gl_code']  = $myrow["sales_gl_code"];
134         $_POST['purchasing_gl_code']  = $myrow["purchasing_gl_code"];
135
136         hidden('selected_id', $selected_id);
137 }
138 text_row_ex(_("Description:"), 'name', 50);
139 small_amount_row(_("Default Rate:"), 'rate', '', "", "%");
140
141 gl_all_accounts_list_row(_("Sales GL Account:"), 'sales_gl_code', null);
142 gl_all_accounts_list_row(_("Purchasing GL Account:"), 'purchasing_gl_code', null);
143
144 end_table(1);
145
146 submit_add_or_update_center(!isset($selected_id));
147
148 end_form();
149
150 end_page();
151
152 ?>