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_GLACCOUNTGROUP';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "GL Account Groups"));
18 include($path_to_root . "/gl/includes/gl_db.inc");
20 include($path_to_root . "/includes/ui.inc");
22 simple_page_mode(false);
23 //-----------------------------------------------------------------------------------
25 function can_process($selected_id)
27 if (strlen(trim($_POST['id'])) == 0)
29 display_error( _("The account group id cannot be empty."));
33 if (strlen(trim($_POST['name'])) == 0)
35 display_error( _("The account group name cannot be empty."));
39 $type = get_account_type(trim($_POST['id']));
40 if ($type && ($type['id'] != $selected_id))
42 display_error( _("This account group id is already in use."));
47 //if (strcmp($_POST['id'], $_POST['parent']) == 0)
48 if ($_POST['id'] === $_POST['parent'])
50 display_error(_("You cannot set an account group to be a subgroup of itself."));
57 //-----------------------------------------------------------------------------------
59 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
62 if (can_process($selected_id))
65 if ($selected_id != "")
67 if (update_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'], $_POST['old_id']))
68 display_notification(_('Selected account type has been updated'));
72 if (add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'])) {
73 display_notification(_('New account type has been added'));
80 //-----------------------------------------------------------------------------------
82 function can_delete($type)
87 if (key_in_foreign_table($type, 'chart_master', 'account_type'))
89 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
93 if (key_in_foreign_table($type, 'chart_types', 'parent'))
95 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
103 //-----------------------------------------------------------------------------------
105 if ($Mode == 'Delete')
108 if (can_delete($selected_id))
110 delete_account_type($selected_id);
111 display_notification(_('Selected account group has been deleted'));
115 if ($Mode == 'RESET')
118 $_POST['id'] = $_POST['name'] = '';
119 unset($_POST['parent']);
120 unset($_POST['class_id']);
122 //-----------------------------------------------------------------------------------
124 $result = get_account_types(check_value('show_inactive'));
127 start_table(TABLESTYLE);
128 $th = array(_("Group ID"), _("Group Name"), _("Subgroup Of"), _("Class"), "", "");
129 inactive_control_column($th);
133 while ($myrow = db_fetch($result))
136 alt_table_row_color($k);
138 $bs_text = get_account_class_name($myrow["class_id"]);
140 if ($myrow["parent"] == '-1')
146 $parent_text = get_account_type_name($myrow["parent"]);
149 label_cell($myrow["id"]);
150 label_cell($myrow["name"]);
151 label_cell($parent_text);
152 label_cell($bs_text);
153 inactive_control_cell($myrow["id"], $myrow["inactive"], 'chart_types', 'id');
154 edit_button_cell("Edit".$myrow["id"], _("Edit"));
155 delete_button_cell("Delete".$myrow["id"], _("Delete"));
159 inactive_control_row($th);
161 //-----------------------------------------------------------------------------------
163 start_table(TABLESTYLE2);
165 if ($selected_id != "")
169 //editing an existing status code
170 $myrow = get_account_type($selected_id);
172 $_POST['id'] = $myrow["id"];
173 $_POST['name'] = $myrow["name"];
174 $_POST['parent'] = $myrow["parent"];
175 if ($_POST['parent'] == '-1')
176 $_POST['parent'] == "";
177 $_POST['class_id'] = $myrow["class_id"];
178 hidden('selected_id', $myrow['id']);
179 hidden('old_id', $myrow["id"]);
183 hidden('selected_id', $selected_id);
184 hidden('old_id', $_POST["old_id"]);
187 text_row_ex(_("ID:"), 'id', 10);
188 text_row_ex(_("Name:"), 'name', 50);
190 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, _("None"), true);
192 class_list_row(_("Class:"), 'class_id', null);
196 submit_add_or_update_center($selected_id == "", '', 'both');
200 //------------------------------------------------------------------------------------