File Coverage

blib/lib/Business/RO/TaxDeduction/Table.pm
Criterion Covered Total %
statement 20 22 90.9
branch 2 2 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 32 34 94.1


line stmt bran cond sub pod time code
1             package Business::RO::TaxDeduction::Table;
2             $Business::RO::TaxDeduction::Table::VERSION = '0.012';
3             # ABSTRACT: Deduction table by year
4              
5 3     3   95659 use 5.010001;
  3         18  
6 3     3   474 use utf8;
  3         14  
  3         14  
7 3     3   466 use Moo;
  3         9323  
  3         13  
8 3     3   2176 use MooX::HandlesVia;
  3         7472  
  3         18  
9 3         20 use Business::RO::TaxDeduction::Types qw(
10             Int
11             HashRef
12             TaxPersons
13 3     3   665 );
  3         6  
14              
15             with qw(Business::RO::TaxDeduction::Role::Utils);
16              
17             has vbl => (
18             is => 'ro',
19             isa => Int,
20             required => 1,
21             );
22              
23             has '_deduction_table_2018_0' => (
24             is => 'ro',
25             isa => HashRef,
26             lazy => 1,
27             default => sub {
28             return {
29             510 => [ 1, 1950 ],
30             495 => [ 1951, 2000 ],
31             480 => [ 2001, 2050 ],
32             465 => [ 2051, 2100 ],
33             450 => [ 2101, 2150 ],
34             435 => [ 2151, 2200 ],
35             420 => [ 2201, 2250 ],
36             405 => [ 2251, 2300 ],
37             390 => [ 2301, 2350 ],
38             375 => [ 2351, 2400 ],
39             360 => [ 2401, 2450 ],
40             345 => [ 2451, 2500 ],
41             330 => [ 2501, 2550 ],
42             315 => [ 2551, 2600 ],
43             300 => [ 2601, 2650 ],
44             285 => [ 2651, 2700 ],
45             270 => [ 2701, 2750 ],
46             255 => [ 2751, 2800 ],
47             240 => [ 2801, 2850 ],
48             225 => [ 2851, 2900 ],
49             210 => [ 2901, 2950 ],
50             195 => [ 2951, 3000 ],
51             180 => [ 3001, 3050 ],
52             165 => [ 3051, 3100 ],
53             150 => [ 3101, 3150 ],
54             135 => [ 3151, 3200 ],
55             120 => [ 3201, 3250 ],
56             105 => [ 3251, 3300 ],
57             90 => [ 3301, 3350 ],
58             75 => [ 3351, 3400 ],
59             60 => [ 3401, 3450 ],
60             45 => [ 3451, 3500 ],
61             30 => [ 3501, 3550 ],
62             15 => [ 3551, 3600 ],
63             0 => [ 3601, 999999 ],
64             };
65             },
66             );
67              
68             has '_deduction_table_2018_1' => (
69             is => 'ro',
70             isa => HashRef,
71             lazy => 1,
72             default => sub {
73             return {
74             670 => [ 1, 1950 ],
75             655 => [ 1951, 2000 ],
76             640 => [ 2001, 2050 ],
77             625 => [ 2051, 2100 ],
78             610 => [ 2101, 2150 ],
79             595 => [ 2151, 2200 ],
80             580 => [ 2201, 2250 ],
81             565 => [ 2251, 2300 ],
82             550 => [ 2301, 2350 ],
83             535 => [ 2351, 2400 ],
84             520 => [ 2401, 2450 ],
85             505 => [ 2451, 2500 ],
86             490 => [ 2501, 2550 ],
87             475 => [ 2551, 2600 ],
88             460 => [ 2601, 2650 ],
89             445 => [ 2651, 2700 ],
90             430 => [ 2701, 2750 ],
91             415 => [ 2751, 2800 ],
92             400 => [ 2801, 2850 ],
93             385 => [ 2851, 2900 ],
94             370 => [ 2901, 2950 ],
95             355 => [ 2951, 3000 ],
96             340 => [ 3001, 3050 ],
97             325 => [ 3051, 3100 ],
98             310 => [ 3101, 3150 ],
99             295 => [ 3151, 3200 ],
100             280 => [ 3201, 3250 ],
101             265 => [ 3251, 3300 ],
102             250 => [ 3301, 3350 ],
103             235 => [ 3351, 3400 ],
104             220 => [ 3401, 3450 ],
105             205 => [ 3451, 3500 ],
106             190 => [ 3501, 3550 ],
107             175 => [ 3551, 3600 ],
108             0 => [ 3601, 999999 ],
109             };
110             },
111             );
112              
113             has '_deduction_table_2018_2' => (
114             is => 'ro',
115             isa => HashRef,
116             lazy => 1,
117             default => sub {
118             return {
119             830 => [ 1, 1950 ],
120             815 => [ 1951, 2000 ],
121             800 => [ 2001, 2050 ],
122             785 => [ 2051, 2100 ],
123             770 => [ 2101, 2150 ],
124             755 => [ 2151, 2200 ],
125             740 => [ 2201, 2250 ],
126             725 => [ 2251, 2300 ],
127             710 => [ 2301, 2350 ],
128             695 => [ 2351, 2400 ],
129             680 => [ 2401, 2450 ],
130             665 => [ 2451, 2500 ],
131             650 => [ 2501, 2550 ],
132             635 => [ 2551, 2600 ],
133             620 => [ 2601, 2650 ],
134             605 => [ 2651, 2700 ],
135             590 => [ 2701, 2750 ],
136             575 => [ 2751, 2800 ],
137             560 => [ 2801, 2850 ],
138             545 => [ 2851, 2900 ],
139             530 => [ 2901, 2950 ],
140             515 => [ 2951, 3000 ],
141             500 => [ 3001, 3050 ],
142             485 => [ 3051, 3100 ],
143             470 => [ 3101, 3150 ],
144             455 => [ 3151, 3200 ],
145             440 => [ 3201, 3250 ],
146             425 => [ 3251, 3300 ],
147             410 => [ 3301, 3350 ],
148             395 => [ 3351, 3400 ],
149             380 => [ 3401, 3450 ],
150             365 => [ 3451, 3500 ],
151             350 => [ 3501, 3550 ],
152             335 => [ 3551, 3600 ],
153             0 => [ 3601, 999999 ],
154             };
155             },
156             );
157              
158             has '_deduction_table_2018_3' => (
159             is => 'ro',
160             isa => HashRef,
161             lazy => 1,
162             default => sub {
163             return {
164             990 => [ 1, 1950 ],
165             975 => [ 1951, 2000 ],
166             960 => [ 2001, 2050 ],
167             945 => [ 2051, 2100 ],
168             930 => [ 2101, 2150 ],
169             915 => [ 2151, 2200 ],
170             900 => [ 2201, 2250 ],
171             885 => [ 2251, 2300 ],
172             870 => [ 2301, 2350 ],
173             855 => [ 2351, 2400 ],
174             840 => [ 2401, 2450 ],
175             825 => [ 2451, 2500 ],
176             810 => [ 2501, 2550 ],
177             795 => [ 2551, 2600 ],
178             780 => [ 2601, 2650 ],
179             765 => [ 2651, 2700 ],
180             750 => [ 2701, 2750 ],
181             735 => [ 2751, 2800 ],
182             720 => [ 2801, 2850 ],
183             705 => [ 2851, 2900 ],
184             690 => [ 2901, 2950 ],
185             675 => [ 2951, 3000 ],
186             660 => [ 3001, 3050 ],
187             645 => [ 3051, 3100 ],
188             630 => [ 3101, 3150 ],
189             615 => [ 3151, 3200 ],
190             600 => [ 3201, 3250 ],
191             585 => [ 3251, 3300 ],
192             570 => [ 3301, 3350 ],
193             555 => [ 3351, 3400 ],
194             540 => [ 3401, 3450 ],
195             525 => [ 3451, 3500 ],
196             510 => [ 3501, 3550 ],
197             495 => [ 3551, 3600 ],
198             0 => [ 3601, 999999 ],
199             };
200             },
201             );
202              
203             has '_deduction_table_2018_4' => (
204             is => 'ro',
205             isa => HashRef,
206             lazy => 1,
207             default => sub {
208             return {
209             1310 => [ 1, 1950 ],
210             1295 => [ 1951, 2000 ],
211             1280 => [ 2001, 2050 ],
212             1265 => [ 2051, 2100 ],
213             1250 => [ 2101, 2150 ],
214             1235 => [ 2151, 2200 ],
215             1220 => [ 2201, 2250 ],
216             1205 => [ 2251, 2300 ],
217             1190 => [ 2301, 2350 ],
218             1175 => [ 2351, 2400 ],
219             1160 => [ 2401, 2450 ],
220             1145 => [ 2451, 2500 ],
221             1130 => [ 2501, 2550 ],
222             1115 => [ 2551, 2600 ],
223             1100 => [ 2601, 2650 ],
224             1085 => [ 2651, 2700 ],
225             1070 => [ 2701, 2750 ],
226             1055 => [ 2751, 2800 ],
227             1040 => [ 2801, 2850 ],
228             1025 => [ 2851, 2900 ],
229             1010 => [ 2901, 2950 ],
230             995 => [ 2951, 3000 ],
231             980 => [ 3001, 3050 ],
232             965 => [ 3051, 3100 ],
233             950 => [ 3101, 3150 ],
234             935 => [ 3151, 3200 ],
235             920 => [ 3201, 3250 ],
236             905 => [ 3251, 3300 ],
237             890 => [ 3301, 3350 ],
238             875 => [ 3351, 3400 ],
239             860 => [ 3401, 3450 ],
240             845 => [ 3451, 3500 ],
241             830 => [ 3501, 3550 ],
242             815 => [ 3551, 3600 ],
243             0 => [ 3601, 999999 ],
244             };
245             },
246             );
247              
248             has '_deduction_map' => (
249             is => 'ro',
250             handles_via => 'Hash',
251             lazy => 1,
252             default => sub {
253             my $self = shift;
254             my $year = $self->base_year;
255             my $pers = $self->persons;
256             my $meth = "_deduction_table_${year}_${pers}";
257             return $self->$meth;
258             },
259             handles => {
260             _get_amounts => 'keys',
261             _get_range => 'get',
262             },
263             );
264              
265             sub deduction {
266 357     357 1 2555 my $self = shift;
267 357         677 my $vbl = $self->vbl;
268 357         4834 foreach my $amount ( $self->_get_amounts ) {
269 6551         100176 my $range = $self->_get_range($amount);
270 6551 100 100     437159 if ( ( $vbl >= $range->[0] )
271             && ( $vbl <= $range->[1] ) )
272             {
273 357         4592 return $amount;
274             }
275             }
276 0           my $msg = "vbl=$vbl, persons=" . $self->persons;
277 0           die "Something went wrong for $msg";
278             }
279              
280             1;
281              
282             __END__