script/bbo.pl untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 78 CC 1 SCAR 6.9
CC
1
Cov
0%
_p
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 use warnings;
3 use strict;
4  
5 # PODNAME: bbo.pl
6 # ABSTRACT: A BBO (Aruba turnover tax) calculator
7  
8 use DateTime;
9 use Finance::Tax::Aruba::BBO;
10 use Getopt::Long;
11 use Pod::Usage;
12 use Text::Table;
13  
14 my %opts = (
15 domestic => 0,
16 import => 0,
17 export => 0,
18 help => 0,
19 'customs-bbo-paid' => [],
20 'customs-bbo-seller' => [],
21 );
22  
23 {
24 local $SIG{__WARN__};
25 my $ok = eval {
26 GetOptions(\%opts, qw(
27 help
28 year=i
29 rate=f
30 domestic=f
31 import=f
32 export=f
33 customs-bbo-paid=f@
34 customs-bbo-seller=f@
35 ));
36 };
37 if (!$ok) {
38 die($@);
39 }
40 }
41  
42 pod2usage(0) if $opts{help};
43  
44 $opts{year} //= DateTime->now->year;
45  
46 my $calc = Finance::Tax::Aruba::BBO->tax_year(
47 $opts{year},
48 exists $opts{rate} ? (rate => $opts{rate}) : (),
49 );
50  
51 my @customs = (
52 (map { { amount => $_, held => 1 } } @{ $opts{'customs-bbo-paid'} }),
53 (map { { amount => $_, held => 0 } } @{ $opts{'customs-bbo-seller'} }),
54 );
55  
56 sub _p { return sprintf('%.2f', shift) }
57  
58 my @rows = (
59 ['Domestic sales', _p($opts{domestic})],
60 [sprintf('BBO (%s%%)', $calc->bbo_rate * 100), _p($calc->domestic_tax_bbo($opts{domestic}))],
61 [sprintf('BAZV (%s%%)', $calc->bazv_rate * 100), _p($calc->domestic_tax_bazv($opts{domestic}))],
62 ['Domestic BBO owed', _p($calc->domestic_tax($opts{domestic}))],
63 ['Domestic net (kept)', _p($calc->domestic_net($opts{domestic}))],
64 ['-', '-'],
65 ['Imports', _p($opts{import})],
66 ['Estimated customs BBO', _p($calc->import_tax($opts{import}))],
67 ['Customs BBO offset', _p($calc->customs_offset(\@customs))],
68 ['Customs BBO not forwarded', _p($calc->customs_not_forwarded(\@customs))],
69 ['-', '-'],
70 ['Exports (zero-rated)', _p($opts{export})],
71 ['BBO on exports', _p($calc->export_tax($opts{export}))],
72 ['-', '-'],
73 ['Net BBO payable', _p($calc->net_payable(domestic => $opts{domestic}, customs => \@customs))],
74 );
75  
76 my $tb = Text::Table->new('What', 'AWG');
77 $tb->load(@rows);
78 print $tb;
79  
80 __END__