Undefined 'no_zeroes' in rep115 line 235. Fixed.
[fa-stable.git] / taxes / tax_groups.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_TAXGROUPS';
13 $path_to_root = "..";
14
15 include($path_to_root . "/includes/session.inc");
16
17 page(_($help_context = "Tax Groups"));
18
19 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21
22 include_once($path_to_root . "/taxes/db/tax_groups_db.inc");
23 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
24
25 simple_page_mode(true);
26         
27 check_db_has_tax_types(_("There are no tax types defined. Define tax types before defining tax groups."));
28
29 //-----------------------------------------------------------------------------------
30
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
32 {
33
34         //initialise no input errors assumed initially before we test
35         $input_error = 0;
36
37         if (strlen($_POST['name']) == 0) 
38         {
39                 $input_error = 1;
40                 display_error(_("The tax group name cannot be empty."));
41                 set_focus('name');
42         } 
43         if ($input_error != 1) 
44         {
45
46                 // create an array of the taxes and array of rates
47         $taxes = array();
48
49                 while (($id = find_submit('tax_type_id'))!=-1)
50                 {
51                         if (check_value('tax_type_id'.$id) != 0)
52                         {
53                         $taxes[] = $id;
54                         }       
55                         unset($_POST['tax_type_id' . $id]);
56                 }
57         if ($selected_id != -1) 
58         {
59                         update_tax_group($selected_id, $_POST['name'], $taxes, get_post('tax_area'));
60                         display_notification(_('Selected tax group has been updated'));
61         } 
62         else 
63         {
64                         add_tax_group($_POST['name'], $taxes, get_post('tax_area'));
65                         display_notification(_('New tax group has been added'));
66         }
67
68                 $Mode = 'RESET';
69         }
70 }
71
72 //-----------------------------------------------------------------------------------
73
74 function can_delete($selected_id)
75 {
76         if ($selected_id == -1)
77                 return false;
78         if (key_in_foreign_table($selected_id, 'cust_branch', 'tax_group_id'))  
79         {
80                 display_error(_("Cannot delete this tax group because customer branches been created referring to it."));
81                 return false;
82         }
83
84         if (key_in_foreign_table($selected_id, 'suppliers', 'tax_group_id'))
85         {
86                 display_error(_("Cannot delete this tax group because suppliers been created referring to it."));
87                 return false;
88         }
89
90
91         return true;
92 }
93
94
95 //-----------------------------------------------------------------------------------
96
97 if ($Mode == 'Delete')
98 {
99
100         if (can_delete($selected_id))
101         {
102                 delete_tax_group($selected_id);
103                 display_notification(_('Selected tax group has been deleted'));
104         }
105         $Mode = 'RESET';
106 }
107
108 if ($Mode == 'RESET')
109 {
110         $selected_id = -1;
111         $sav = get_post('show_inactive');
112         unset($_POST);
113         if ($sav)
114                 $_POST['show_inactive'] = $sav;
115 }
116 //-----------------------------------------------------------------------------------
117
118 $result = get_all_tax_groups(check_value('show_inactive'));
119
120 start_form();
121
122 start_table(TABLESTYLE);
123 $th = array(_("Description"), _("Tax Area Type"), "", "");
124 inactive_control_column($th);
125
126 table_header($th);
127
128 $k = 0;
129 while ($myrow = db_fetch($result)) 
130 {
131
132         alt_table_row_color($k);
133
134         label_cell($myrow["name"]);
135         label_cell($tax_area_types[$myrow['tax_area']]);
136
137         inactive_control_cell($myrow["id"], $myrow["inactive"], 'tax_groups', 'id');
138         edit_button_cell("Edit".$myrow["id"], _("Edit"));
139         delete_button_cell("Delete".$myrow["id"], _("Delete"));
140         end_row();
141 }
142
143 inactive_control_row($th);
144 end_table(1);
145
146 //-----------------------------------------------------------------------------------
147
148 start_table(TABLESTYLE2);
149
150 if ($selected_id != -1) 
151 {
152         //editing an existing status code
153
154         if ($Mode == 'Edit') {
155         $group = get_tax_group($selected_id);
156
157         $_POST['name']  = $group["name"];
158         $_POST['tax_area']  = $group["tax_area"];
159
160         }
161         hidden('selected_id', $selected_id);
162
163 }
164 text_row_ex(_("Description:"), 'name', 40);
165 vat_areas_list_row(_("Tax Area Type:"), 'tax_area');
166
167 end_table();
168
169 display_note(_("Select the taxes that are included in this group."), 1, 1);
170
171 $items = get_tax_group_rates($selected_id!=-1 ? $selected_id : null);
172
173 start_table(TABLESTYLE2);
174 $th = array(_("Tax"), "");
175 table_header($th);
176
177 while($item = db_fetch($items)) 
178 {
179         start_row();
180         if ($selected_id != -1)
181         {
182                 check_cells($item['tax_type_name'], 'tax_type_id' . $item['tax_type_id'], 
183                         isset($item['rate']), true, false, "align='center'");
184         }
185         else
186         {
187                 check_cells($item['tax_type_name'], 'tax_type_id' . $item['tax_type_id'], 
188                         null, true, false, "align='center'");
189                 if (get_post('_tax_type_id' . $item['tax_type_id'].'_update'))  
190                 {
191                         //$_POST['_tax_type_id' . $item['tax_type_id'].'_update'] = 0;
192                         $Ajax->activate('_page_body');
193                 }
194         }               
195         end_row();      
196         
197 }
198
199 end_table(1);
200
201 submit_add_or_update_center($selected_id == -1, '', 'both');
202
203 end_form();
204
205 //------------------------------------------------------------------------------------
206
207 end_page();
208