Fixed Assets: Added sum-of-the-year digits method, fixed declining balance method...
[fa-stable.git] / inventory / manage / items.php
index c4ab903ff147164e75e4d27fe4f4ee2b76302bb2..ad65ee0fbadac2981e6c740121b82c05309fd96c 100644 (file)
@@ -155,6 +155,7 @@ function clear_data()
        unset($_POST['no_purchase']);
        unset($_POST['depreciation_method']);
        unset($_POST['depreciation_rate']);
+       unset($_POST['depreciation_factor']);
        unset($_POST['depreciation_start']);
 }
 
@@ -226,7 +227,7 @@ if (isset($_POST['addupdate']))
                                $_POST['adjustment_account'], $_POST['assembly_account'], 
                                $_POST['dimension_id'], $_POST['dimension2_id'],
                                check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
-                               get_post('depreciation_method'), get_post('depreciation_rate'), get_post('depreciation_start'),
+                               get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start'),
                                get_post('fa_class_id'));
 
                        update_record_status($_POST['NewStockID'], $_POST['inactive'],
@@ -247,7 +248,7 @@ if (isset($_POST['addupdate']))
                                $_POST['adjustment_account'], $_POST['assembly_account'], 
                                $_POST['dimension_id'], $_POST['dimension2_id'],
                                check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
-                               get_post('depreciation_method'), get_post('depreciation_rate'), get_post('depreciation_start'),
+                               get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start'),
                                get_post('fa_class_id'));
 
                        display_notification(_("A new item has been added."));
@@ -335,7 +336,8 @@ function item_settings(&$stock_id, $new_item)
                        $_POST['mb_flag']  = $myrow["mb_flag"];
 
                        $_POST['depreciation_method'] = $myrow['depreciation_method'];
-                       $_POST['depreciation_rate'] = $myrow['depreciation_rate'];
+                       $_POST['depreciation_rate'] = number_format2($myrow['depreciation_rate'], 1);
+                       $_POST['depreciation_factor'] = number_format2($myrow['depreciation_factor'], 1);
                        $_POST['depreciation_start'] = sql2date($myrow['depreciation_start']);
                        $_POST['depreciation_date'] = sql2date($myrow['depreciation_date']);
                        $_POST['fa_class_id'] = $myrow['fa_class_id'];
@@ -415,24 +417,22 @@ function item_settings(&$stock_id, $new_item)
                if (!isset($_POST['depreciation_rate']) || (list_updated('fa_class_id') || list_updated('depreciation_method'))) {
                        $class_row = get_fixed_asset_class($_POST['fa_class_id']);
 
-                       if ($_POST['depreciation_method'] == 'S')
-                               $_POST['depreciation_rate'] = $class_row['depreciation_period'];
-                       else
-                               $_POST['depreciation_rate'] = $class_row['depreciation_rate'];
+                       if ($_POST['depreciation_method'] == 'O')
+                       {
+                               hidden('depreciation_rate', 100);
+                               label_row(_("Depreciation Rate").':', "100 %");
                        }
-
-                       switch ($_POST['depreciation_method']) {
-                               case 'D':
-                                       small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
-                                       break;
-                               case 'S':
-                                       text_row_ex(_("Depreciation Period").':', 'depreciation_rate', 3, 3, '', null, null, _("years"));
-                                       break;
-                               case 'O':
-                                       hidden('depreciation_rate', 100);
-                                       label_row(_("Depreciation Rate").':', "100 %");
-                                       break;
+                       elseif ($_POST['depreciation_method'] == 'N')
+                       {
+                               small_amount_row(_("Depreciation Years").':', 'depreciation_rate', null, null, _('years'), 0);
                        }
+                       elseif ($_POST['depreciation_method'] == 'D')
+                               small_amount_row(_("Base Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
+                       else
+                               small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
+
+                       if ($_POST['depreciation_method'] == 'D')
+                               small_amount_row(_("Rate multiplier").':', 'depreciation_factor', null, null, '', 2);
 
                        // do not allow to change the depreciation start after this item has been depreciated
                        if ($new_item || $_POST['depreciation_start'] == $_POST['depreciation_date'])
@@ -443,7 +443,7 @@ function item_settings(&$stock_id, $new_item)
                                label_row(_("Last Depreciation").':', $_POST['depreciation_date']);
                        }
                        hidden('depreciation_date');
-
+               }
        }
        table_section(2);