Fixed numeric fields to accept user native number format.
[fa-stable.git] / taxes / item_tax_types.php
1 <?php
2
3 $path_to_root = "..";
4 $page_security = 3;
5
6 include($path_to_root . "/includes/session.inc");
7
8 page(_("Item Tax Types")); 
9
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");
12
13 include($path_to_root . "/includes/ui.inc");
14
15 if (isset($_GET['selected_id']))
16 {
17         $selected_id = $_GET['selected_id'];
18
19 elseif(isset($_POST['selected_id']))
20 {
21         $selected_id = $_POST['selected_id'];
22 }
23
24 //-----------------------------------------------------------------------------------
25
26 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
27 {
28
29         $input_error = 0;
30
31         if (strlen($_POST['name']) == 0) 
32         {
33                 $input_error = 1;
34                 display_error(_("The item tax type description cannot be empty."));
35         }
36
37         if ($input_error != 1) 
38         {
39                 
40                 // create an array of the exemptions
41         $exempt_from = array();
42         
43         $tax_types = get_all_tax_types_simple();
44         $i = 0;         
45         
46         while ($myrow = db_fetch($tax_types)) 
47         {
48                 if (check_value('ExemptTax' . $myrow["id"]))
49                 {
50                         $exempt_from[$i] = $myrow["id"];
51                         $i++;
52                 }
53         }  
54         
55         if (isset($selected_id)) 
56         {
57                 
58                 update_item_tax_type($selected_id, $_POST['name'], $_POST['exempt'], $exempt_from);
59         } 
60         else 
61         {
62     
63                 add_item_tax_type($_POST['name'], $_POST['exempt'], $exempt_from);
64         }
65                 meta_forward($_SERVER['PHP_SELF']);             
66         }
67
68
69 //-----------------------------------------------------------------------------------
70
71 function can_delete($selected_id)
72 {
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);
76         if ($myrow[0] > 0) 
77         {
78                 display_error(_("Cannot delete this item tax type because items have been created referring to it."));
79                 return false;
80         }
81         
82         return true;
83 }
84
85
86 //-----------------------------------------------------------------------------------
87
88 if (isset($_GET['delete'])) 
89 {
90
91         if (can_delete($selected_id))
92         {
93                 delete_item_tax_type($selected_id);
94                 meta_forward($_SERVER['PHP_SELF']);             
95         }
96 }
97
98 //-----------------------------------------------------------------------------------
99
100
101 $result2 = $result = get_all_item_tax_types();
102 start_table("$table_style width=30%");
103 $th = array(_("Name"), _("Tax exempt"),'','');
104
105 table_header($th);
106
107 $k = 0;
108 while ($myrow = db_fetch($result2)) 
109 {
110         
111         alt_table_row_color($k);        
112
113         if ($myrow["exempt"] == 0) 
114         {
115                 $disallow_text = _("No");
116         } 
117         else 
118         {
119                 $disallow_text = _("Yes");
120         }
121         
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");
126         end_row();
127 }
128
129 end_table();
130
131 //-----------------------------------------------------------------------------------
132
133 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Tax type"));
134
135 start_form();
136
137 start_table($table_style2);
138
139 if (isset($selected_id)) 
140 {
141         
142         if (!isset($_POST['name'])) 
143         {
144         $myrow = get_item_tax_type($selected_id);
145     
146         $_POST['name']  = $myrow["name"];
147         $_POST['exempt']  = $myrow["exempt"];
148         
149         // read the exemptions and check the ones that are on
150         $exemptions = get_item_tax_type_exemptions($selected_id);
151         
152         if (db_num_rows($exemptions) > 0)
153         {
154                 while ($exmp = db_fetch($exemptions)) 
155                 {
156                         $_POST['ExemptTax' . $exmp["tax_type_id"]] = 1;
157                 }
158         }       
159         }
160
161         hidden('selected_id', $selected_id);
162
163
164 text_row_ex(_("Description:"), 'name', 50);
165
166 yesno_list_row(_("Is Fully Tax-exempt:"), 'exempt', null, "", "", true);
167
168 end_table(1);
169
170 if (!isset($_POST['exempt']) || $_POST['exempt'] == 0) 
171 {
172
173     display_note(_("Select which taxes this item tax type is exempt from."), 0, 1);
174     
175     start_table($table_style2);
176     $th = array(_("Tax Name"), _("Rate"), _("Is exempt"));
177     table_header($th);
178         
179     $tax_types = get_all_tax_types_simple();            
180     
181     while ($myrow = db_fetch($tax_types)) 
182     {
183         
184         alt_table_row_color($k);        
185     
186         label_cell($myrow["name"]);
187         label_cell(percent_format($myrow["rate"])." %", "nowrap align=right");
188         check_cells("", 'ExemptTax' . $myrow["id"], null);
189         end_row();
190     }
191     
192     end_table(1);
193 }
194
195 submit_add_or_update_center(!isset($selected_id));
196
197 end_form();
198
199 //------------------------------------------------------------------------------------
200
201 end_page();
202
203 ?>