Incorrect Journal Balance (sales invoice) when many decimals in tax and price.
[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   if (input_num('depreciation_rate') > 100) {
31     display_error(_("The depreciation rate can't be greater than 100%"));
32     $input_error = 1;
33   }
34         
35         /* actions to take once the user has clicked the submit button
36         ie the page has called itself with some user input */
37
38         if ($input_error != 1) 
39         {
40         if ($selected_id != -1) 
41         {
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'));
45         } 
46         else 
47         {
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'));
50         }
51
52                 $Mode = 'RESET';
53         }
54
55
56 function can_delete($selected_id)
57 {
58         if (key_in_foreign_table($selected_id, 'stock_master', 'fa_class_id'))
59         {
60                 display_error(_("Cannot delete this class because it is used by some fixed asset items."));
61                 return false;
62         }
63         return true;
64 }
65
66 //----------------------------------------------------------------------------------
67
68 if ($Mode == 'Delete')
69 {
70
71         if (can_delete($selected_id)) 
72         {
73                 delete_fixed_asset_class($selected_id);
74                 display_notification(_('Selected fixed asset class has been deleted'));
75         } //end if Delete Location
76         $Mode = 'RESET';
77 }
78
79 if ($Mode == 'RESET')
80 {
81         $selected_id = -1;
82   unset($_POST);
83 }
84
85 $result = get_fixed_asset_classes();
86
87 start_form();
88 start_table(TABLESTYLE);
89 $th = array(_("Fixed asset class"), _("Description"), _("Basic Depreciation Rate"), "", "");
90 inactive_control_column($th);
91 table_header($th);
92 $k = 0; //row colour counter
93 while ($myrow = db_fetch($result)) 
94 {
95         alt_table_row_color($k);
96         
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"));
103         end_row();
104 }
105 inactive_control_row($th);
106 end_table(1);
107
108 echo '<br>';
109
110 start_form(true);
111 div_start('par_tbl');
112 start_table(TABLESTYLE2);
113
114 if ($selected_id != -1) 
115 {
116         if ($Mode == 'Edit') {
117                 $myrow = get_fixed_asset_class($selected_id);
118
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"];
124         }
125         hidden("selected_id", $selected_id);
126         hidden("fa_class_id");
127   hidden('parent_id');
128   label_row(_("Parent class:"), $_POST['parent_id']);
129   label_row(_("Fixed asset class:"), $_POST['fa_class_id']);
130
131 else 
132 {
133   text_row(_("Parent class:"), 'parent_id', null, 3, 3);
134   text_row(_("Fixed asset class:"), 'fa_class_id', null, 3, 3);
135 }
136
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);
141
142 end_table(1);
143 div_end();
144 //if ($selected_id != -1) 
145 submit_add_or_update_center($selected_id == -1, '', 'both');
146
147 end_form();
148
149 end_page();