line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::Engine::Function::DDB; |
2
|
|
|
|
|
|
|
|
3
|
28
|
|
|
28
|
|
151
|
use strict; |
|
28
|
|
|
|
|
62
|
|
|
28
|
|
|
|
|
906
|
|
4
|
28
|
|
|
28
|
|
145
|
use warnings; |
|
28
|
|
|
|
|
58
|
|
|
28
|
|
|
|
|
881
|
|
5
|
|
|
|
|
|
|
|
6
|
28
|
|
|
28
|
|
142
|
use base 'Spreadsheet::Engine::Fn::depreciation'; |
|
28
|
|
|
|
|
58
|
|
|
28
|
|
|
|
|
6891
|
|
7
|
28
|
|
|
28
|
|
182
|
use List::Util 'min'; |
|
28
|
|
|
|
|
56
|
|
|
28
|
|
|
|
|
7457
|
|
8
|
|
|
|
|
|
|
|
9
|
81
|
|
|
81
|
1
|
225
|
sub argument_count { -4 => 5 } |
10
|
81
|
|
|
81
|
1
|
325
|
sub signature { 'n', 'n', '>=1', 'n', 'n' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub calculate { |
13
|
81
|
|
|
81
|
1
|
3379
|
my ($self, $cost, $salvage, $lifetime, $period, $method) = @_; |
14
|
81
|
|
100
|
|
|
279
|
$method ||= 2; |
15
|
|
|
|
|
|
|
|
16
|
81
|
|
|
|
|
113
|
my $depreciation = 0; # calculated for each period |
17
|
81
|
|
|
|
|
99
|
my $accumulated = 0; # accumulated by adding each period's |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# calculate for each period based on net from previous |
20
|
81
|
|
|
|
|
358
|
for my $i (1 .. min($period, $lifetime)) { |
21
|
240
|
|
|
|
|
380
|
$depreciation = ($cost - $accumulated) * ($method / $lifetime); |
22
|
|
|
|
|
|
|
{ # don't go lower than salvage value |
23
|
240
|
|
|
|
|
248
|
my $bottom = $cost - $salvage - $accumulated; |
|
240
|
|
|
|
|
328
|
|
24
|
240
|
100
|
|
|
|
522
|
$depreciation = $bottom if $bottom < $depreciation; |
25
|
|
|
|
|
|
|
} |
26
|
240
|
|
|
|
|
350
|
$accumulated += $depreciation; |
27
|
|
|
|
|
|
|
} |
28
|
81
|
|
|
|
|
1920
|
return $depreciation; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |