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(true);
23 //-----------------------------------------------------------------------------------
25 function can_process()
31 display_error( _("The account id must be an integer and cannot be empty."));
35 if (strlen($_POST['name']) == 0)
37 display_error( _("The account group name cannot be empty."));
42 if (isset($selected_id) && ($selected_id == $_POST['parent']))
44 display_error(_("You cannot set an account group to be a subgroup of itself."));
51 //-----------------------------------------------------------------------------------
53 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
59 if ($selected_id != -1)
61 if (update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']))
62 display_notification(_('Selected account type has been updated'));
66 if (add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'])) {
67 display_notification(_('New account type has been added'));
74 //-----------------------------------------------------------------------------------
76 function can_delete($selected_id)
78 if ($selected_id == -1)
80 $type = db_escape($selected_id);
82 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_master
83 WHERE account_type=$type";
84 $result = db_query($sql, "could not query chart master");
85 $myrow = db_fetch_row($result);
88 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
92 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
94 $result = db_query($sql, "could not query chart types");
95 $myrow = db_fetch_row($result);
98 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
106 //-----------------------------------------------------------------------------------
108 if ($Mode == 'Delete')
111 if (can_delete($selected_id))
113 delete_account_type($selected_id);
114 display_notification(_('Selected account group has been deleted'));
118 if ($Mode == 'RESET')
121 $_POST['id'] = $_POST['name'] = '';
122 unset($_POST['parent']);
123 unset($_POST['class_id']);
125 //-----------------------------------------------------------------------------------
127 $result = get_account_types(check_value('show_inactive'));
130 start_table($table_style);
131 $th = array(_("ID"), _("Name"), _("Subgroup Of"), _("Class Type"), "", "");
132 inactive_control_column($th);
136 while ($myrow = db_fetch($result))
139 alt_table_row_color($k);
141 $bs_text = get_account_class_name($myrow["class_id"]);
143 if ($myrow["parent"] == ANY_NUMERIC)
149 $parent_text = get_account_type_name($myrow["parent"]);
152 label_cell($myrow["id"]);
153 label_cell($myrow["name"]);
154 label_cell($parent_text);
155 label_cell($bs_text);
156 inactive_control_cell($myrow["id"], $myrow["inactive"], 'chart_types', 'id');
157 edit_button_cell("Edit".$myrow["id"], _("Edit"));
158 delete_button_cell("Delete".$myrow["id"], _("Delete"));
162 inactive_control_row($th);
164 //-----------------------------------------------------------------------------------
166 start_table($table_style2);
168 if ($selected_id != -1)
172 //editing an existing status code
173 $myrow = get_account_type($selected_id);
175 $_POST['id'] = $myrow["id"];
176 $_POST['name'] = $myrow["name"];
177 $_POST['parent'] = $myrow["parent"];
178 $_POST['class_id'] = $myrow["class_id"];
179 hidden('selected_id', $selected_id);
182 label_row(_("ID:"), $_POST['id']);
185 text_row_ex(_("ID:"), 'id', 10);
186 text_row_ex(_("Name:"), 'name', 50);
188 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, _("None"), true);
190 class_list_row(_("Class Type:"), 'class_id', null);
194 submit_add_or_update_center($selected_id == -1, '', 'both');
198 //------------------------------------------------------------------------------------