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 ***********************************************************************/
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'], $_POST['convert']);
54 display_notification(_('Selected account class settings has been updated'));
58 add_account_class($_POST['id'], $_POST['name'], $_POST['Balance'], $_POST['convert']);
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'] = $_POST['sign_convert'] = '';
104 //-----------------------------------------------------------------------------------
106 $result = get_account_classes(check_value('show_inactive'));
109 start_table($table_style);
110 $th = array(_("Class ID"), _("Class Name"), _("Balance Sheet"), _("Sign Convert"), "", "");
111 inactive_control_column($th);
115 while ($myrow = db_fetch($result))
118 alt_table_row_color($k);
120 if ($myrow["balance_sheet"] == 0)
128 if ($myrow["sign_convert"] == 0)
136 label_cell($myrow["cid"]);
137 label_cell($myrow['class_name']);
138 label_cell($bs_text);
139 label_cell($sc_text);
140 inactive_control_cell($myrow["cid"], $myrow["inactive"], 'chart_class', 'cid');
141 edit_button_cell("Edit".$myrow["cid"], _("Edit"));
142 delete_button_cell("Delete".$myrow["cid"], _("Delete"));
145 inactive_control_row($th);
147 //-----------------------------------------------------------------------------------
149 start_table($table_style2);
151 if ($selected_id != -1)
153 if ($Mode == 'Edit') {
154 //editing an existing status code
155 $myrow = get_account_class($selected_id);
157 $_POST['id'] = $myrow["cid"];
158 $_POST['name'] = $myrow["class_name"];
159 $_POST['Balance'] = $myrow["balance_sheet"];
160 $_POST['convert'] = $myrow["sign_convert"];
161 hidden('selected_id', $selected_id);
164 label_row(_("Class ID:"), $_POST['id']);
170 text_row_ex(_("Class ID:"), 'id', 3);
173 text_row_ex(_("Class Name:"), 'name', 50, 60);
175 yesno_list_row(_("Balance Sheet:"), 'Balance', null, "", "", false);
177 yesno_list_row(_("Sign Convert (Balance Sheet/PL statement):"), 'convert', null, "", "", false);
181 submit_add_or_update_center($selected_id == -1, '', 'both');
185 //------------------------------------------------------------------------------------