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