[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / fixed_assets / fixed_asset_classes.php
1 <?php
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';
13 $path_to_root = "..";
14 include($path_to_root . "/includes/session.inc");
15
16 include_once($path_to_root . "/includes/ui.inc");
17
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");
20
21 page(_($help_context = "Fixed asset classes"));
22
23 simple_page_mode(true);
24
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
26 {
27
28         //initialise no input errors assumed initially before we test
29         $input_error = 0;
30
31         /* actions to take once the user has clicked the submit button
32         ie the page has called itself with some user input */
33
34         if ($input_error != 1) 
35         {
36         if ($selected_id != -1) 
37         {
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'));
41         } 
42         else 
43         {
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'));
47         }
48
49                 $Mode = 'RESET';
50         }
51
52
53 function can_delete($selected_id)
54 {
55         if (key_in_foreign_table($selected_id, 'stock_master', 'fa_class_id'))
56         {
57                 display_error(_("Cannot delete this class because it is used by some fixed asset items."));
58                 return false;
59         }
60         return true;
61 }
62
63 //----------------------------------------------------------------------------------
64
65 if ($Mode == 'Delete')
66 {
67
68         if (can_delete($selected_id)) 
69         {
70                 delete_fixed_asset_class($selected_id);
71                 display_notification(_('Selected fixed asset class has been deleted'));
72         } //end if Delete Location
73         $Mode = 'RESET';
74 }
75
76 if ($Mode == 'RESET')
77 {
78         $selected_id = -1;
79   unset($_POST);
80 }
81
82 $result = get_fixed_asset_classes();
83
84 start_form();
85 start_table(TABLESTYLE);
86 $th = array(_("Fixed asset class"), _("Description"), _("Basic Depreciation Rate"), "", "");
87 inactive_control_column($th);
88 table_header($th);
89 $k = 0; //row colour counter
90 while ($myrow = db_fetch($result)) 
91 {
92         alt_table_row_color($k);
93         
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"));
100         end_row();
101 }
102 inactive_control_row($th);
103 end_table(1);
104
105 echo '<br>';
106
107 start_form(true);
108 div_start('par_tbl');
109 start_table(TABLESTYLE2);
110
111 if ($selected_id != -1) 
112 {
113         if ($Mode == 'Edit') {
114                 $myrow = get_fixed_asset_class($selected_id);
115
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"];
121         }
122         hidden("selected_id", $selected_id);
123         hidden("fa_class_id");
124   hidden('parent_id');
125   label_row(_("Parent class:"), $_POST['parent_id']);
126   label_row(_("Fixed asset class:"), $_POST['fa_class_id']);
127
128 else 
129 {
130   text_row(_("Parent class:"), 'parent_id', null, 3, 3);
131   text_row(_("Fixed asset class:"), 'fa_class_id', null, 3, 3);
132 }
133
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);
138
139 end_table(1);
140 div_end();
141 //if ($selected_id != -1) 
142 submit_add_or_update_center($selected_id == -1, '', 'both');
143
144 end_form();
145
146 end_page();