Bugfixes in fixed assets editor.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 7 Dec 2015 13:17:16 +0000 (14:17 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 7 Dec 2015 13:17:48 +0000 (14:17 +0100)
includes/ui/ui_lists.inc
inventory/manage/items.php

index 910ad6534a853c40ed4cc0d10b5f4b3465385ca6..0149442508ed5d95404f9af2b151170373f3abdb 100644 (file)
@@ -1653,25 +1653,22 @@ function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=f
 //-----------------------------------------------------------------------------------------------
 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
 {
-       $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description), c.inactive FROM "
-               .TB_PREF."stock_fa_class c, "
-               .TB_PREF."stock_fa_class p 
-       WHERE c.parent_id=p.fa_class_id";
+       $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description) `class`, c.inactive FROM "
+               .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
 
        return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
                array('order'=>'c.fa_class_id',
                        'spec_option' => $spec_opt,
-                       'spec_id' => -1,
+                       'spec_id' => '-1',
                        'select_submit'=> $submit_on_change,
                        'async' => true,
                        'search_box' => true,
                        'search' => array("c.fa_class_id"),
                    'search_submit' => false,
-                   'spec_option' => '',
                    'spec_id' => '',
                    'size' => 3,
                    'max' => 3,
-                       'category' => 2,
+                       'category' => 'class',
                ));
 }
 
index ad65ee0fbadac2981e6c740121b82c05309fd96c..c69c485498115cb39bd331a30a533c57d6436cd1 100644 (file)
@@ -416,34 +416,36 @@ 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']);
+                       $_POST['depreciation_rate'] = get_post('depreciation_method') == 'N' ? ceil(100/$class_row['depreciation_rate'])
+                               : $class_row['depreciation_rate'];
+               }
 
-                       if ($_POST['depreciation_method'] == 'O')
-                       {
-                               hidden('depreciation_rate', 100);
-                               label_row(_("Depreciation Rate").':', "100 %");
-                       }
-                       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'])
-                               date_row(_("Depreciation Start").':', 'depreciation_start', null, null, 1 - date('j'));
-                       else {
-                               hidden('depreciation_start');
-                               label_row(_("Depreciation Start").':', $_POST['depreciation_start']);
-                               label_row(_("Last Depreciation").':', $_POST['depreciation_date']);
-                       }
-                       hidden('depreciation_date');
+               if ($_POST['depreciation_method'] == 'O')
+               {
+                       hidden('depreciation_rate', 100);
+                       label_row(_("Depreciation Rate").':', "100 %");
+               }
+               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'])
+                       date_row(_("Depreciation Start").':', 'depreciation_start', null, null, 1 - date('j'));
+               else {
+                       hidden('depreciation_start');
+                       label_row(_("Depreciation Start").':', $_POST['depreciation_start']);
+                       label_row(_("Last Depreciation").':', $_POST['depreciation_date']==$_POST['depreciation_start'] ? _("None") :  $_POST['depreciation_date']);
                }
+               hidden('depreciation_date');
        }
        table_section(2);