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
31 /* actions to take once the user has clicked the submit button
32 ie the page has called itself with some user input */
34 if ($input_error != 1)
36 if ($selected_id != -1)
38 update_fixed_asset_class($selected_id, $_POST['parent_id'], $_POST['description'], $_POST['long_description'],
39 $_POST['depreciation_rate']);
40 display_notification(_('Selected fixed asset class has been updated'));
44 add_fixed_asset_class($_POST['fa_class_id'], $_POST['parent_id'], $_POST['description'], $_POST['long_description'],
45 $_POST['depreciation_rate']);
46 display_notification(_('New fixed asset class has been added'));
53 function can_delete($selected_id)
55 if (key_in_foreign_table($selected_id, 'stock_master', 'fa_class_id'))
57 display_error(_("Cannot delete this class because it is used by some fixed asset items."));
63 //----------------------------------------------------------------------------------
65 if ($Mode == 'Delete')
68 if (can_delete($selected_id))
70 delete_fixed_asset_class($selected_id);
71 display_notification(_('Selected fixed asset class has been deleted'));
72 } //end if Delete Location
82 $result = get_fixed_asset_classes();
85 start_table(TABLESTYLE);
86 $th = array(_("Fixed asset class"), _("Description"), _("Basic Depreciation Rate"), "", "");
87 inactive_control_column($th);
89 $k = 0; //row colour counter
90 while ($myrow = db_fetch($result))
92 alt_table_row_color($k);
94 label_cell($myrow["fa_class_id"]);
95 label_cell($myrow["description"]);
96 label_cell($myrow["depreciation_rate"].'%');
97 inactive_control_cell($myrow["fa_class_id"], $myrow["inactive"], 'stock_fa_classes', 'fa_class_id');
98 edit_button_cell("Edit".$myrow["fa_class_id"], _("Edit"));
99 delete_button_cell("Delete".$myrow["fa_class_id"], _("Delete"));
102 inactive_control_row($th);
108 div_start('par_tbl');
109 start_table(TABLESTYLE2);
111 if ($selected_id != -1)
113 if ($Mode == 'Edit') {
114 $myrow = get_fixed_asset_class($selected_id);
116 $_POST['fa_class_id'] = $myrow["fa_class_id"];
117 $_POST['parent_id'] = $myrow["parent_id"];
118 $_POST['description'] = $myrow["description"];
119 $_POST['long_description'] = $myrow["long_description"];
120 $_POST['depreciation_rate'] = $myrow["depreciation_rate"];
122 hidden("selected_id", $selected_id);
123 hidden("fa_class_id");
125 label_row(_("Parent class:"), $_POST['parent_id']);
126 label_row(_("Fixed asset class:"), $_POST['fa_class_id']);
130 text_row(_("Parent class:"), 'parent_id', null, 3, 3);
131 text_row(_("Fixed asset class:"), 'fa_class_id', null, 3, 3);
134 text_row(_("Description:"), 'description', null, 42, 200);
135 textarea_row(_('Long description:'), 'long_description', null, 42, 3);
136 small_amount_row(_("Basic Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
137 //text_row(_("Parent id:"), 'parent_id', null, 3, 3);
141 //if ($selected_id != -1)
142 submit_add_or_update_center($selected_id == -1, '', 'both');