| 1 | package Finance::Tax::Aruba::Role::BBO::TaxYear; | ||||||||||||
| 2 | 8 | our $VERSION = '0.014'; | |||||||||||
| 3 | 8 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | # ABSTRACT: A role that implements BBO (turnover tax) logic | ||||||||||||
| 6 | |||||||||||||
| 7 | 8 | requires qw( | |||||||||||
| 8 | is_year | ||||||||||||
| 9 | ); | ||||||||||||
| 10 | |||||||||||||
| 11 | # The BBO rate for this tax year, as a decimal (e.g. 0.07 for 7%). Every | ||||||||||||
| 12 | # year class MUST override this via `has '+rate' => (default => ...)` -- | ||||||||||||
| 13 | # there's no sane cross-year default to fall back on. | ||||||||||||
| 14 | 8 | has rate => ( | |||||||||||
| 15 | is => 'ro', | ||||||||||||
| 16 | isa => 'Num', | ||||||||||||
| 17 | required => 1, | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | |||||||||||||
| 20 | # Whether import BBO (paid to Customs at the border) is creditable | ||||||||||||
| 21 | # against domestic BBO owed for this tax year -- see net_payable. This | ||||||||||||
| 22 | # distinction changed at some point (the rule and/or the rate for | ||||||||||||
| 23 | # imports specifically), which is the whole reason this is a per-year | ||||||||||||
| 24 | # plugin the same as Income:: is, rather than one flat rate. Each year | ||||||||||||
| 25 | # class overrides this via `has '+bbo_at_border' => (default => ...)`. | ||||||||||||
| 26 | 8 | has bbo_at_border => ( | |||||||||||
| 27 | is => 'ro', | ||||||||||||
| 28 | isa => 'Bool', | ||||||||||||
| 29 | default => 0, | ||||||||||||
| 30 | ); | ||||||||||||
| 31 | |||||||||||||
| 32 | # Unlike VAT/BTW, BBO isn't added on top of a price -- the amount you | ||||||||||||
| 33 | # bill a domestic customer already contains the tax you owe on it, so | ||||||||||||
| 34 | # the tax owed is simply the billed amount times the rate. | ||||||||||||
| 35 | 11 | ▶ | sub domestic_tax { | ||||||||||
|
Subroutine
domestic_tax: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 36 | 11 | my ($self, $amount) = @_; | |||||||||||
| 37 | 11 | return $self->_round($amount * $self->rate); | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | # What you actually keep from a domestic sale once BBO is set aside. | ||||||||||||
| 41 | 1 | ▶ | sub domestic_net { | ||||||||||
|
Subroutine
domestic_net: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 42 | 1 | my ($self, $amount) = @_; | |||||||||||
| 43 | 1 | return $self->_round($amount - $self->domestic_tax($amount)); | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | # BBO paid to Customs on an imported good, at the border, at the same | ||||||||||||
| 47 | # rate as a domestic sale. | ||||||||||||
| 48 | 2 | ▶ | sub import_tax { | ||||||||||
|
Subroutine
import_tax: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 49 | 2 | my ($self, $amount) = @_; | |||||||||||
| 50 | 2 | return $self->_round($amount * $self->rate); | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | # A service billed to a client outside Aruba is zero-rated: BBO is a | ||||||||||||
| 54 | # tax on local turnover, so it doesn't apply "across the border" the | ||||||||||||
| 55 | # other way either. Kept as its own method (rather than just always | ||||||||||||
| 56 | # being 0 inline at the call site) so the exemption is a documented, | ||||||||||||
| 57 | # named rule instead of an implicit absence. | ||||||||||||
| 58 | 2 | ▶ | sub export_tax { | ||||||||||
|
Subroutine
export_tax: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 59 | 2 | return 0; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | # Customs invoices the BBO on an import separately. The seller or the | ||||||||||||
| 63 | # importer pays it. It only offsets domestic BBO when the invoice is held | ||||||||||||
| 64 | # by the importer (held => 1), e.g. the seller paid and forwarded it. | ||||||||||||
| 65 | 8 | ▶ | sub customs_offset { | ||||||||||
|
Subroutine
customs_offset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 66 | 8 | my ($self, $invoices) = @_; | |||||||||||
| 67 | 8 | return $self->_round($self->_customs_sum($invoices, 1)); | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 1 | ▶ | sub customs_not_forwarded { | ||||||||||
|
Subroutine
customs_not_forwarded: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 71 | 1 | my ($self, $invoices) = @_; | |||||||||||
| 72 | 1 | return $self->_round($self->_customs_sum($invoices, 0)); | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 9 | ▶ | sub _customs_sum { | ||||||||||
|
Subroutine
_customs_sum: called CC=4 SCAR=13.9
| |||||||||||||
| 76 | 9 | my ($self, $invoices, $held) = @_; | |||||||||||
| 77 | 9 | my $sum = 0; | |||||||||||
| 78 | 9 | ▶ | foreach (@{ $invoices // [] }) { | ||||||||||
|
Condition100%2/2
$invoices // []
MC/DC100%1/1
$invoices // []
$invoices
Truth table100%2/2
A
A= $invoices
| |||||||||||||
| 79 | 10 | ▶ | $sum += $_->{amount} if !!$_->{held} == !!$held; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | } | ||||||||||||
| 81 | 9 | return $sum; | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | # A negative result is a credit carried forward, not an error. Customs | ||||||||||||
| 85 | # invoices only offset for a tax year where bbo_at_border is true. | ||||||||||||
| 86 | 8 | ▶ | sub net_payable { | ||||||||||
|
Subroutine
net_payable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 87 | 8 | my ($self, %args) = @_; | |||||||||||
| 88 | 8 | ▶ | my $domestic = $args{domestic} // 0; | ||||||||||
|
Condition100%2/2
$args{"domestic"} // 0
MC/DC100%1/1
$args{"domestic"} // 0
$args{"domestic"}
Truth table100%2/2
A
A= $args{"domestic"}
| |||||||||||||
| 89 | |||||||||||||
| 90 | 8 | my $domestic_tax = $self->domestic_tax($domestic); | |||||||||||
| 91 | 8 | ▶ | return $domestic_tax unless $self->bbo_at_border; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | |||||||||||||
| 93 | 7 | return $self->_round($domestic_tax - $self->customs_offset($args{customs})); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 30 | ▶ | sub _round { | ||||||||||
|
Subroutine
_round: called CC=1 SCAR=0.0
| |||||||||||||
| 97 | 30 | my ($self, $amount) = @_; | |||||||||||
| 98 | 30 | return sprintf('%.2f', $amount) + 0; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 8 | 1; | |||||||||||
| 102 | |||||||||||||
| 103 | __END__ | ||||||||||||