2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("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()
28 if (strlen($_POST['name']) == 0)
30 display_error( _("The account class name cannot be empty."));
38 //-----------------------------------------------------------------------------------
40 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
46 if ($selected_id != -1)
48 update_account_class($selected_id, $_POST['name'], $_POST['Balance']);
49 display_notification(_('Selected account class settings has been updated'));
53 add_account_class($_POST['id'], $_POST['name'], $_POST['Balance']);
54 display_notification(_('New account class has been added'));
60 //-----------------------------------------------------------------------------------
62 function can_delete($selected_id)
64 if ($selected_id == -1)
66 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
67 WHERE class_id=$selected_id";
68 $result = db_query($sql, "could not query chart master");
69 $myrow = db_fetch_row($result);
72 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
80 //-----------------------------------------------------------------------------------
82 if ($Mode == 'Delete')
85 if (can_delete($selected_id))
87 delete_account_class($selected_id);
88 display_notification(_('Selected account class has been deleted'));
93 //-----------------------------------------------------------------------------------
97 $_POST['id'] = $_POST['name'] = $_POST['Balance'] = '';
99 //-----------------------------------------------------------------------------------
101 $result = get_account_classes();
103 start_table($table_style);
104 $th = array(_("Class ID"), _("Class Name"), _("Balance Sheet"), "", "");
108 while ($myrow = db_fetch($result))
111 alt_table_row_color($k);
113 if ($myrow["balance_sheet"] == 0)
121 label_cell($myrow["cid"]);
122 label_cell($myrow['class_name']);
123 label_cell($bs_text);
124 edit_button_cell("Edit".$myrow["cid"], _("Edit"));
125 delete_button_cell("Delete".$myrow["cid"], _("Delete"));
132 //-----------------------------------------------------------------------------------
136 start_table($table_style2);
138 if ($selected_id != -1)
140 if ($Mode == 'Edit') {
141 //editing an existing status code
142 $myrow = get_account_class($selected_id);
144 $_POST['id'] = $myrow["cid"];
145 $_POST['name'] = $myrow["class_name"];
146 $_POST['Balance'] = $myrow["balance_sheet"];
147 hidden('selected_id', $selected_id);
150 label_row(_("Class ID:"), $_POST['id']);
156 text_row_ex(_("Class ID:"), 'id', 3);
159 text_row_ex(_("Class Name:"), 'name', 50, 60);
161 yesno_list_row(_("Balance Sheet:"), 'Balance', null, "", "", false);
165 submit_add_or_update_center($selected_id == -1, '', true);
169 //------------------------------------------------------------------------------------