Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[fa-stable.git] / taxes / tax_types.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_TAXRATES';
13 $path_to_root = "..";
14
15 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "Tax Types"));
17
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/taxes/db/tax_types_db.inc");
20
21 simple_page_mode(true);
22 //-----------------------------------------------------------------------------------
23
24 function can_process()
25 {
26         global $selected_id;
27         
28         if (strlen($_POST['name']) == 0)
29         {
30                 display_error(_("The tax type name cannot be empty."));
31                 set_focus('name');
32                 return false;
33         }
34         elseif (!check_num('rate', 0))
35         {
36                 display_error( _("The default tax rate must be numeric and not less than zero."));
37                 set_focus('rate');
38                 return false;
39         }
40
41         if (!is_tax_gl_unique(get_post('sales_gl_code'), get_post('purchasing_gl_code'), $selected_id)) {
42                 display_error( _("Selected GL Accounts cannot be used by another tax type."));
43                 set_focus('sales_gl_code');
44                 return false;
45         }
46         return true;
47 }
48
49 //-----------------------------------------------------------------------------------
50
51 if ($Mode=='ADD_ITEM' && can_process())
52 {
53
54         add_tax_type($_POST['name'], $_POST['sales_gl_code'],
55                 $_POST['purchasing_gl_code'], input_num('rate', 0));
56         display_notification(_('New tax type has been added'));
57         $Mode = 'RESET';
58 }
59
60 //-----------------------------------------------------------------------------------
61
62 if ($Mode=='UPDATE_ITEM' && can_process())
63 {
64
65         update_tax_type($selected_id, $_POST['name'],
66         $_POST['sales_gl_code'], $_POST['purchasing_gl_code'], input_num('rate'));
67         display_notification(_('Selected tax type has been updated'));
68         $Mode = 'RESET';
69 }
70
71 //-----------------------------------------------------------------------------------
72
73 function can_delete($selected_id)
74 {
75         if (key_in_foreign_table($selected_id, 'tax_group_items', 'tax_type_id'))
76         {
77                 display_error(_("Cannot delete this tax type because tax groups been created referring to it."));
78
79                 return false;
80         }
81
82         return true;
83 }
84
85
86 //-----------------------------------------------------------------------------------
87
88 if ($Mode == 'Delete')
89 {
90
91         if (can_delete($selected_id))
92         {
93                 delete_tax_type($selected_id);
94                 display_notification(_('Selected tax type has been deleted'));
95         }
96         $Mode = 'RESET';
97 }
98
99 if ($Mode == 'RESET')
100 {
101         $selected_id = -1;
102         $sav = get_post('show_inactive');
103         unset($_POST);
104         $_POST['show_inactive'] = $sav;
105 }
106 //-----------------------------------------------------------------------------------
107
108 $result = get_all_tax_types(check_value('show_inactive'));
109
110 start_form();
111
112 display_note(_("To avoid problems with manual journal entry all tax types should have unique Sales/Purchasing GL accounts."), 0, 1);
113 start_table(TABLESTYLE);
114
115 $th = array(_("Description"), _("Default Rate (%)"),
116         _("Sales GL Account"), _("Purchasing GL Account"), "", "");
117 inactive_control_column($th);
118 table_header($th);
119
120 $k = 0;
121 while ($myrow = db_fetch($result))
122 {
123
124         alt_table_row_color($k);
125
126         label_cell($myrow["name"]);
127         label_cell(percent_format($myrow["rate"]), "align=right");
128         label_cell($myrow["sales_gl_code"] . "&nbsp;" . $myrow["SalesAccountName"]);
129         label_cell($myrow["purchasing_gl_code"] . "&nbsp;" . $myrow["PurchasingAccountName"]);
130
131         inactive_control_cell($myrow["id"], $myrow["inactive"], 'tax_types', 'id');
132         edit_button_cell("Edit".$myrow["id"], _("Edit"));
133         delete_button_cell("Delete".$myrow["id"], _("Delete"));
134
135         end_row();
136 }
137
138 inactive_control_row($th);
139 end_table(1);
140 //-----------------------------------------------------------------------------------
141
142 start_table(TABLESTYLE2);
143
144 if ($selected_id != -1) 
145 {
146         if ($Mode == 'Edit') {
147                 //editing an existing status code
148
149                 $myrow = get_tax_type($selected_id);
150
151                 $_POST['name']  = $myrow["name"];
152                 $_POST['rate']  = percent_format($myrow["rate"]);
153                 $_POST['sales_gl_code']  = $myrow["sales_gl_code"];
154                 $_POST['purchasing_gl_code']  = $myrow["purchasing_gl_code"];
155         }
156         hidden('selected_id', $selected_id);
157 }
158 text_row_ex(_("Description:"), 'name', 50);
159 small_amount_row(_("Default Rate:"), 'rate', '', "", "%", user_percent_dec());
160
161 gl_all_accounts_list_row(_("Sales GL Account:"), 'sales_gl_code', null);
162 gl_all_accounts_list_row(_("Purchasing GL Account:"), 'purchasing_gl_code', null);
163
164 end_table(1);
165
166 submit_add_or_update_center($selected_id == -1, '', 'both');
167
168 end_form();
169
170 end_page();
171