X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=fixed_assets%2Fincludes%2Fdepreciation.inc;h=b63ad1a8eb527a5869db59a96d1d3864eefa9472;hb=5189bc26f377d678d0a3d88a2b623d69c0e1a278;hp=dda99f96639fbb8dffd30dac01377647fe309920;hpb=fd069bba86276f15311ff6ab10b22d4a06a55513;p=fa-stable.git diff --git a/fixed_assets/includes/depreciation.inc b/fixed_assets/includes/depreciation.inc index dda99f96..b63ad1a8 100644 --- a/fixed_assets/includes/depreciation.inc +++ b/fixed_assets/includes/depreciation.inc @@ -62,20 +62,28 @@ function compute_gl_rows_for_depreciation($item, $no_months, $period) { $y = date('Y', strtotime($year['end'])); switch ($item['depreciation_method']) { - case 'D': - $value = $item['material_cost'] * $item['depreciation_rate'] / 100 / 12; - break; - - case 'S': - // depreciation_rate is the period here. - $done_months = months_between_dates($item['depreciation_start'], $item['depreciation_date']); - $remaining_months = $item['depreciation_rate'] * 12 - $done_months; - $value = $item['material_cost'] / $remaining_months; - break; + case 'D': + $line_value = $item['purchase_cost']*$item['depreciation_rate']/100/12; + $value = $item['material_cost'] * $item['depreciation_rate'] * $item['depreciation_factor']/100/12; + if ($value < $line_value) + $value = $line_value; + break; + + case 'S': // purchase_cost stores start cost of item + $done_months = months_between_dates($item['depreciation_start'], $item['depreciation_date']); + $remaining_months = 12.0 * 100.0/$item['depreciation_rate'] - $done_months; + $value = $item['purchase_cost']*$item['depreciation_rate']/100/12; + break; + + case 'N': + $N = $item['depreciation_rate']; + $done_years = months_between_dates($item['depreciation_start'], $item['depreciation_date'])/12; + $value = $item['purchase_cost']* ($N-$done_years)/($N*($N+1)/2)/12; + break; case 'O': - $value = $item['material_cost']; - break; + $value = $item['material_cost']; + break; } $next = next_depreciation_date($item['depreciation_date']); @@ -84,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; @@ -103,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; }