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_ASSETCLASS';
14 include($path_to_root . "/includes/session.inc");
16 include_once($path_to_root . "/includes/ui.inc");
18 include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc");
19 include_once($path_to_root . "/fixed_assets/includes/fa_classes_db.inc");
21 page(_($help_context = "Fixed asset classes"));
23 simple_page_mode(true);
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 //initialise no input errors assumed initially before we test
30 if (input_num('depreciation_rate') > 100) {
31 display_error(_("The depreciation rate can't be greater than 100%"));
35 /* actions to take once the user has clicked the submit button
36 ie the page has called itself with some user input */
38 if ($input_error != 1)
40 if ($selected_id != -1)
42 update_fixed_asset_class($selected_id, $_POST['parent_id'], $_POST['description'], $_POST['long_description'],
43 input_num('depreciation_rate'));
44 display_notification(_('Selected fixed asset class has been updated'));
48 add_fixed_asset_class($_POST['fa_class_id'], $_POST['parent_id'], $_POST['description'], $_POST['long_description'], input_num('depreciation_rate'));
49 display_notification(_('New fixed asset class has been added'));
56 function can_delete($selected_id)
58 if (key_in_foreign_table($selected_id, 'stock_master', 'fa_class_id'))
60 display_error(_("Cannot delete this class because it is used by some fixed asset items."));
66 //----------------------------------------------------------------------------------
68 if ($Mode == 'Delete')
71 if (can_delete($selected_id))
73 delete_fixed_asset_class($selected_id);
74 display_notification(_('Selected fixed asset class has been deleted'));
75 } //end if Delete Location
85 $result = get_fixed_asset_classes();
88 start_table(TABLESTYLE);
89 $th = array(_("Fixed asset class"), _("Description"), _("Basic Depreciation Rate"), "", "");
90 inactive_control_column($th);
92 $k = 0; //row colour counter
93 while ($myrow = db_fetch($result))
95 alt_table_row_color($k);
97 label_cell($myrow["fa_class_id"]);
98 label_cell($myrow["description"]);
99 label_cell($myrow["depreciation_rate"].'%');
100 inactive_control_cell($myrow["fa_class_id"], $myrow["inactive"], 'stock_fa_classes', 'fa_class_id');
101 edit_button_cell("Edit".$myrow["fa_class_id"], _("Edit"));
102 delete_button_cell("Delete".$myrow["fa_class_id"], _("Delete"));
105 inactive_control_row($th);
111 div_start('par_tbl');
112 start_table(TABLESTYLE2);
114 if ($selected_id != -1)
116 if ($Mode == 'Edit') {
117 $myrow = get_fixed_asset_class($selected_id);
119 $_POST['fa_class_id'] = $myrow["fa_class_id"];
120 $_POST['parent_id'] = $myrow["parent_id"];
121 $_POST['description'] = $myrow["description"];
122 $_POST['long_description'] = $myrow["long_description"];
123 $_POST['depreciation_rate'] = $myrow["depreciation_rate"];
125 hidden("selected_id", $selected_id);
126 hidden("fa_class_id");
128 label_row(_("Parent class:"), $_POST['parent_id']);
129 label_row(_("Fixed asset class:"), $_POST['fa_class_id']);
133 text_row(_("Parent class:"), 'parent_id', null, 3, 3);
134 text_row(_("Fixed asset class:"), 'fa_class_id', null, 3, 3);
137 text_row(_("Description:"), 'description', null, 42, 200);
138 textarea_row(_('Long description:'), 'long_description', null, 42, 3);
139 small_amount_row(_("Basic Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
140 //text_row(_("Parent id:"), 'parent_id', null, 3, 3);
144 //if ($selected_id != -1)
145 submit_add_or_update_center($selected_id == -1, '', 'both');