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()
27 if (!is_numeric($_POST['id']))
29 display_error( _("The account class ID must be numeric."));
33 if (strlen($_POST['name']) == 0)
35 display_error( _("The account class name cannot be empty."));
43 //-----------------------------------------------------------------------------------
45 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
51 if ($selected_id != -1)
53 update_account_class($selected_id, $_POST['name'], $_POST['Balance']);
54 display_notification(_('Selected account class settings has been updated'));
58 add_account_class($_POST['id'], $_POST['name'], $_POST['Balance']);
59 display_notification(_('New account class has been added'));
65 //-----------------------------------------------------------------------------------
67 function can_delete($selected_id)
69 if ($selected_id == -1)
71 $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
72 WHERE class_id=$selected_id";
73 $result = db_query($sql, "could not query chart master");
74 $myrow = db_fetch_row($result);
77 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
85 //-----------------------------------------------------------------------------------
87 if ($Mode == 'Delete')
90 if (can_delete($selected_id))
92 delete_account_class($selected_id);
93 display_notification(_('Selected account class has been deleted'));
98 //-----------------------------------------------------------------------------------
102 $_POST['id'] = $_POST['name'] = $_POST['Balance'] = '';
104 //-----------------------------------------------------------------------------------
106 $result = get_account_classes();
108 start_table($table_style);
109 $th = array(_("Class ID"), _("Class Name"), _("Balance Sheet"), "", "");
113 while ($myrow = db_fetch($result))
116 alt_table_row_color($k);
118 if ($myrow["balance_sheet"] == 0)
126 label_cell($myrow["cid"]);
127 label_cell($myrow['class_name']);
128 label_cell($bs_text);
129 edit_button_cell("Edit".$myrow["cid"], _("Edit"));
130 delete_button_cell("Delete".$myrow["cid"], _("Delete"));
137 //-----------------------------------------------------------------------------------
141 start_table($table_style2);
143 if ($selected_id != -1)
145 if ($Mode == 'Edit') {
146 //editing an existing status code
147 $myrow = get_account_class($selected_id);
149 $_POST['id'] = $myrow["cid"];
150 $_POST['name'] = $myrow["class_name"];
151 $_POST['Balance'] = $myrow["balance_sheet"];
152 hidden('selected_id', $selected_id);
155 label_row(_("Class ID:"), $_POST['id']);
161 text_row_ex(_("Class ID:"), 'id', 3);
164 text_row_ex(_("Class Name:"), 'name', 50, 60);
166 yesno_list_row(_("Balance Sheet:"), 'Balance', null, "", "", false);
170 submit_add_or_update_center($selected_id == -1, '', true);
174 //------------------------------------------------------------------------------------