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_GLACCOUNTCLASS';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "GL Account Classes"));
18 include($path_to_root . "/gl/includes/gl_db.inc");
20 include($path_to_root . "/includes/ui.inc");
22 simple_page_mode(true);
23 //-----------------------------------------------------------------------------------
25 function can_process()
27 global $use_oldstyle_convert;
28 if (!is_numeric($_POST['id']))
30 display_error( _("The account class ID must be numeric."));
34 if (strlen($_POST['name']) == 0)
36 display_error( _("The account class name cannot be empty."));
40 if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
41 $_POST['Balance'] = check_value('Balance');
45 //-----------------------------------------------------------------------------------
47 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
53 if ($selected_id != -1)
55 if(update_account_class($selected_id, $_POST['name'], $_POST['ctype']))
56 display_notification(_('Selected account class settings has been updated'));
60 if(add_account_class($_POST['id'], $_POST['name'], $_POST['ctype'])) {
61 display_notification(_('New account class has been added'));
68 //-----------------------------------------------------------------------------------
70 function can_delete($selected_id)
72 if ($selected_id == -1)
74 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
75 WHERE class_id=$selected_id";
76 $result = db_query($sql, "could not query chart master");
77 $myrow = db_fetch_row($result);
80 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
88 //-----------------------------------------------------------------------------------
90 if ($Mode == 'Delete')
93 if (can_delete($selected_id))
95 delete_account_class($selected_id);
96 display_notification(_('Selected account class has been deleted'));
101 //-----------------------------------------------------------------------------------
102 if ($Mode == 'RESET')
105 $_POST['id'] = $_POST['name'] = $_POST['ctype'] = '';
107 //-----------------------------------------------------------------------------------
109 $result = get_account_classes(check_value('show_inactive'));
112 start_table($table_style);
113 $th = array(_("Class ID"), _("Class Name"), _("Class Type"), "", "");
114 if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
115 $th[2] = _("Balance Sheet");
116 inactive_control_column($th);
120 while ($myrow = db_fetch($result))
123 alt_table_row_color($k);
125 label_cell($myrow["cid"]);
126 label_cell($myrow['class_name']);
127 if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
129 $myrow['ctype'] = ($myrow["ctype"] >= CL_ASSETS && $myrow["ctype"] < CL_INCOME ? 1 : 0);
130 label_cell(($myrow['ctype'] == 1 ? _("Yes") : _("No")));
133 label_cell($class_types[$myrow["ctype"]]);
134 inactive_control_cell($myrow["cid"], $myrow["inactive"], 'chart_class', 'cid');
135 edit_button_cell("Edit".$myrow["cid"], _("Edit"));
136 delete_button_cell("Delete".$myrow["cid"], _("Delete"));
139 inactive_control_row($th);
141 //-----------------------------------------------------------------------------------
143 start_table($table_style2);
145 if ($selected_id != -1)
147 if ($Mode == 'Edit') {
148 //editing an existing status code
149 $myrow = get_account_class($selected_id);
151 $_POST['id'] = $myrow["cid"];
152 $_POST['name'] = $myrow["class_name"];
153 if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
154 $_POST['ctype'] = ($myrow["ctype"] >= CL_ASSETS && $myrow["ctype"] < CL_INCOME ? 1 : 0);
156 $_POST['ctype'] = $myrow["ctype"];
157 hidden('selected_id', $selected_id);
160 label_row(_("Class ID:"), $_POST['id']);
166 text_row_ex(_("Class ID:"), 'id', 3);
169 text_row_ex(_("Class Name:"), 'name', 50, 60);
171 if (isset($use_oldstyle_convert) && $use_oldstyle_convert == 1)
172 check_row(_("Balance Sheet"), 'ctype', null);
174 class_types_list_row(_("Class Type:"), 'ctype', null);
178 submit_add_or_update_center($selected_id == -1, '', 'both');
182 //------------------------------------------------------------------------------------