Changed balance_sheet operation in class table to class type for sign convert in...
[fa-stable.git] / gl / manage / gl_account_classes.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 = 3;
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_("GL Account Classes"));
17
18 include($path_to_root . "/gl/includes/gl_db.inc");
19
20 include($path_to_root . "/includes/ui.inc");
21
22 simple_page_mode(true);
23 //-----------------------------------------------------------------------------------
24
25 function can_process() 
26 {
27         if (!is_numeric($_POST['id'])) 
28         {
29                 display_error( _("The account class ID must be numeric."));
30                 set_focus('id');
31                 return false;
32         }
33         if (strlen($_POST['name']) == 0) 
34         {
35                 display_error( _("The account class name cannot be empty."));
36                 set_focus('name');
37                 return false;
38         }
39
40         return true;
41 }
42
43 //-----------------------------------------------------------------------------------
44
45 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
46 {
47
48         if (can_process()) 
49         {
50
51         if ($selected_id != -1) 
52         {
53                 update_account_class($selected_id, $_POST['name'], $_POST['Balance']);
54                         display_notification(_('Selected account class settings has been updated'));
55         } 
56         else 
57         {
58                 add_account_class($_POST['id'], $_POST['name'], $_POST['Balance']);
59                         display_notification(_('New account class has been added'));
60         }
61                 $Mode = 'RESET';
62         }
63 }
64
65 //-----------------------------------------------------------------------------------
66
67 function can_delete($selected_id)
68 {
69         if ($selected_id == -1)
70                 return false;
71         $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
72                 WHERE class_id=$selected_id";
73         $result = db_query($sql, "could not query chart master");
74         $myrow = db_fetch_row($result);
75         if ($myrow[0] > 0) 
76         {
77                 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
78                 return false;
79         }
80
81         return true;
82 }
83
84
85 //-----------------------------------------------------------------------------------
86
87 if ($Mode == 'Delete')
88 {
89
90         if (can_delete($selected_id))
91         {
92                 delete_account_class($selected_id);
93                 display_notification(_('Selected account class has been deleted'));
94         }
95         $Mode = 'RESET';
96 }
97
98 //-----------------------------------------------------------------------------------
99 if ($Mode == 'RESET')
100 {
101         $selected_id = -1;
102         $_POST['id']  = $_POST['name']  = $_POST['Balance'] = '';
103 }
104 //-----------------------------------------------------------------------------------
105
106 $result = get_account_classes();
107 start_form();
108 start_table($table_style);
109 $th = array(_("Class ID"), _("Class Name"), _("Class Type"), "", "");
110 table_header($th);
111
112 $k = 0;
113 while ($myrow = db_fetch($result)) 
114 {
115
116         alt_table_row_color($k);
117
118         label_cell($myrow["cid"]);
119         label_cell($myrow['class_name']);
120         label_cell($class_types[$myrow["balance_sheet"]]);
121         edit_button_cell("Edit".$myrow["cid"], _("Edit"));
122         delete_button_cell("Delete".$myrow["cid"], _("Delete"));
123         end_row();
124 }
125
126 end_table();
127 end_form();
128 echo '<br>';
129 //-----------------------------------------------------------------------------------
130
131 start_form();
132
133 start_table($table_style2);
134
135 if ($selected_id != -1) 
136 {
137  if ($Mode == 'Edit') {
138         //editing an existing status code
139         $myrow = get_account_class($selected_id);
140
141         $_POST['id']  = $myrow["cid"];
142         $_POST['name']  = $myrow["class_name"];
143         $_POST['Balance']  = $myrow["balance_sheet"];
144         hidden('selected_id', $selected_id);
145  }
146         hidden('id');
147         label_row(_("Class ID:"), $_POST['id']);
148
149
150 else 
151 {
152
153         text_row_ex(_("Class ID:"), 'id', 3);
154 }
155
156 text_row_ex(_("Class Name:"), 'name', 50, 60);
157
158 class_types_list_row(_("Class Type:"), 'Balance', null);
159
160 end_table(1);
161
162 submit_add_or_update_center($selected_id == -1, '', true);
163
164 end_form();
165
166 //------------------------------------------------------------------------------------
167
168 end_page();
169
170 ?>