5 include($path_to_root . "/includes/session.inc");
7 page(_("GL Account Groups"));
9 include($path_to_root . "/gl/includes/gl_db.inc");
11 include($path_to_root . "/includes/ui.inc");
13 simple_page_mode(false);
14 //-----------------------------------------------------------------------------------
16 function can_process()
20 if (strlen($_POST['name']) == 0)
22 display_error( _("The account group name cannot be empty."));
27 if (isset($selected_id) && ($selected_id == $_POST['parent']))
29 display_error(_("You cannot set an account group to be a subgroup of itself."));
36 //-----------------------------------------------------------------------------------
38 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
44 if ($selected_id != "")
46 update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']);
47 display_notification(_('Selected account type has been updated'));
51 add_account_type($_POST['name'], $_POST['class_id'], $_POST['parent']);
52 display_notification(_('New account type has been added'));
58 //-----------------------------------------------------------------------------------
60 function can_delete($selected_id)
62 if ($selected_id == "")
64 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_master
65 WHERE account_type=$selected_id";
66 $result = db_query($sql, "could not query chart master");
67 $myrow = db_fetch_row($result);
70 display_error(_("Cannot delete this account group because GL accounts have been created referring to it."));
74 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
75 WHERE parent=$selected_id";
76 $result = db_query($sql, "could not query chart types");
77 $myrow = db_fetch_row($result);
80 display_error(_("Cannot delete this account group because GL account groups have been created referring to it."));
88 //-----------------------------------------------------------------------------------
90 if ($Mode == 'Delete')
93 if (can_delete($selected_id))
95 delete_account_type($selected_id);
96 display_notification(_('Selected currency has been deleted'));
100 if ($Mode == 'RESET')
104 unset($_POST['parent']);
105 unset($_POST['class_id']);
107 //-----------------------------------------------------------------------------------
109 $result = get_account_types();
111 start_table($table_style);
112 $th = array(_("Name"), _("Subgroup Of"), _("Class Type"), "", "");
116 while ($myrow = db_fetch($result))
119 alt_table_row_color($k);
121 $bs_text = get_account_class_name($myrow["class_id"]);
123 if ($myrow["parent"] == reserved_words::get_any_numeric())
129 $parent_text = get_account_type_name($myrow["parent"]);
132 label_cell($myrow["name"]);
133 label_cell($parent_text);
134 label_cell($bs_text);
135 edit_button_cell("Edit".$myrow["id"], _("Edit"));
136 edit_button_cell("Delete".$myrow["id"], _("Delete"));
143 //-----------------------------------------------------------------------------------
147 start_table($table_style2);
151 //editing an existing status code
152 $myrow = get_account_type($selected_id);
154 $_POST['name'] = $myrow["name"];
155 $_POST['parent'] = $myrow["parent"];
156 $_POST['class_id'] = $myrow["class_id"];
158 hidden('selected_id', $selected_id);
160 text_row_ex(_("Name:"), 'name', 50);
162 gl_account_types_list_row(_("Subgroup Of:"), 'parent', null, _("None"), true);
164 class_list_row(_("Class Type:"), 'class_id', null);
168 submit_add_or_update_center($selected_id == '', '', true);
172 //------------------------------------------------------------------------------------