Fixed fixed assets stright line depreciation.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 23 Jan 2016 11:24:28 +0000 (12:24 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 23 Jan 2016 11:24:28 +0000 (12:24 +0100)
fixed_assets/includes/depreciation.inc

index 3bc72126cebb53c1fa10003720d5eebb388f3f57..e07a93de057b860602a9cb0e5d58dfec713a6dc3 100644 (file)
@@ -70,6 +70,8 @@ function compute_gl_rows_for_depreciation($item, $no_months, $period) {
                break;
 
     case 'S':  // purchase_cost stores start cost of item
+               $done_months = months_between_dates($item['depreciation_start'], $item['depreciation_date']);
+               $remaining_months = 100.0/$item['depreciation_rate'] - $done_months;
                $value = $item['purchase_cost']*$item['depreciation_rate']/100/12;
                break;
 
@@ -90,6 +92,12 @@ function compute_gl_rows_for_depreciation($item, $no_months, $period) {
   $total = 0;
   $cnt = 0;
   for ($i=$m; $i < $m + $no_months; $i++) {
+
+       if ($item['depreciation_method'] == 'S') {
+               if ($cnt >= $remaining_months)
+                       $value = 0;
+       }
+
     $date = sql2date(date("$y-$i-t", strtotime("$y-$i-1")));
 
     $total += $value;
@@ -109,15 +117,11 @@ function compute_gl_rows_for_depreciation($item, $no_months, $period) {
 
     $cnt++;
 
-    if ($item['depreciation_method'] == 'S') {
-      if ($cnt >= $remaining_months)
-        $value = 0;
-    }
-    elseif ($item['depreciation_method'] == 'O') {
-      // depreciate only in the first month
-      $value = 0;
-    }
-  }
+       if ($item['depreciation_method'] == 'O') {
+               // depreciate only in the first month
+               $value = 0;
+       }
+ }
 
   return $rows;
 }