TaxAmountCalculator
in package
The only arithmetic of the VAT engine — pure bcmath: - {@see splitGross()}: a final price → base `money(gross ÷ (1 + rate/100))` + VAT = difference, the gross amount itself never changes; - {@see allocate()}: an ancillary amount (gateway fee, shipping) split proportionally to group bases, each part rounded to 3 places, the rounding remainder goes to the largest group.
Intermediate results on WORK_SCALE = 12 like InvoiceCalculator; money on 3 places,
half away from zero (bcmath truncates, so ±0.0005 is added first — the same money() as there).
Table of Contents
Constants
- MONEY_SCALE : int = 3
- WORK_SCALE : int = 12
Methods
- allocate() : array<string|int, mixed>
- Splits `$amount` proportionally to `$weights` (group bases). Keys are preserved; the sum of the parts equals `money($amount)` exactly. Remainder → the largest weight (first on a tie). All weights zero → everything to the first group.
- money() : numeric-string
- splitGross() : array{base: numeric-string, vat: numeric-string}
Constants
MONEY_SCALE
private
int
MONEY_SCALE
= 3
WORK_SCALE
private
int
WORK_SCALE
= 12
Methods
allocate()
Splits `$amount` proportionally to `$weights` (group bases). Keys are preserved; the sum of the parts equals `money($amount)` exactly. Remainder → the largest weight (first on a tie). All weights zero → everything to the first group.
public
allocate(numeric-string $amount, array<string|int, mixed> $weights) : array<string|int, mixed>
Parameters
- $amount : numeric-string
- $weights : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>money()
public
money(numeric-string $value) : numeric-string
Parameters
- $value : numeric-string
Return values
numeric-stringsplitGross()
public
splitGross(numeric-string $gross, numeric-string $vatPercents) : array{base: numeric-string, vat: numeric-string}
Parameters
- $gross : numeric-string
- $vatPercents : numeric-string