API reference / Quittio \ Core \ Calculation
En16931Calculator
final class in quittio/core · implements TotalsCalculator
Quittio\Core\Calculation\En16931Calculator · Source
Calculation according to EN 16931.
Amounts are rounded half up to two decimals at the defined points only. VAT is calculated per VAT group (category and rate), not per line (BR-CO-17).
With Meta::FLAG_DECLARED_AMOUNTS (cancellations and unchanged data of InvoiceBuilder::from() whose declared amounts another system rounded differently) and a matching fingerprint of the amount inputs (DeclaredAmounts), declared line net amounts (BT-131) within 0.02 of quantity × price ± allowances and charges (PEPPOL-EN16931-R120) and declared VAT category tax amounts (BT-117) less than one currency unit from the recalculation (BR-CO-17) are kept; otherwise the recalculated amounts are used and Meta::FLAG_DECLARED_AMOUNTS_RECALCULATED is set (QUITTIO-DECLARED-AMOUNTS). Data whose amount inputs changed after the amounts were declared (fingerprint mismatch, e.g. a change with with() or in stored JSON) is recalculated completely. A declared VAT total in accounting currency (BT-111, Meta::declaredVatInTaxCurrency()) is kept within 0.01 of round2(BT-110 × exchange rate), e.g. the BT-111 of a partial cancellation aligned with the earlier ones (Corrections\CancellationHistory). In gross price mode the rounding amount (BT-114) follows the amounts finally used, so that the amount due stays the gross amount of the lines. The CalculationPolicy decides whether declared amounts are kept, recalculated or rejected. The flags are read and written as DeclaredAmountsState.
Methods#
| Method | Description |
|---|---|
->__construct() | |
->calculate() | |
->policy() | The policy of this calculator. |
->withPolicy() | The same calculator with another policy. |
__construct()#
public function __construct(
LineCalculator $lineCalculator = new \Quittio\Core\Calculation\LineCalculator(),
GrossPriceConverter $grossPriceConverter = new \Quittio\Core\Calculation\GrossPriceConverter(),
CalculationPolicy $policy = new \Quittio\Core\Calculation\CalculationPolicy(),
)| Parameter | Type | Description |
|---|---|---|
$lineCalculator | LineCalculator = new \Quittio\Core\Calculation\LineCalculator() | |
$grossPriceConverter | GrossPriceConverter = new \Quittio\Core\Calculation\GrossPriceConverter() | |
$policy | CalculationPolicy = new \Quittio\Core\Calculation\CalculationPolicy() |
calculate()#
public function calculate(InvoiceData $invoice): InvoiceData| Parameter | Type | Description |
|---|---|---|
$invoice | InvoiceData |
- Returns
InvoiceData
policy()#
public function policy(): CalculationPolicyThe policy of this calculator.
- Returns
CalculationPolicy
withPolicy()#
public function withPolicy(CalculationPolicy $policy): selfThe same calculator with another policy.
| Parameter | Type | Description |
|---|---|---|
$policy | CalculationPolicy |
- Returns
self