En16931Calculator
in package
implements
TotalsCalculator
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.
Tags
Table of Contents
Interfaces
- TotalsCalculator
- Calculates line amounts, allowances and charges, the VAT breakdown and totals.
Methods
- __construct() : mixed
- calculate() : InvoiceData
- policy() : CalculationPolicy
- The policy of this calculator.
- withPolicy() : self
- The same calculator with another policy.
Methods
__construct()
public
__construct([LineCalculator $lineCalculator = new LineCalculator() ][, GrossPriceConverter $grossPriceConverter = new GrossPriceConverter() ][, CalculationPolicy $policy = new CalculationPolicy() ]) : mixed
Parameters
- $lineCalculator : LineCalculator = new LineCalculator()
- $grossPriceConverter : GrossPriceConverter = new GrossPriceConverter()
- $policy : CalculationPolicy = new CalculationPolicy()
calculate()
public
calculate(InvoiceData $invoice) : InvoiceData
Parameters
- $invoice : InvoiceData
Return values
InvoiceDatapolicy()
The policy of this calculator.
public
policy() : CalculationPolicy
Return values
CalculationPolicywithPolicy()
The same calculator with another policy.
public
withPolicy(CalculationPolicy $policy) : self
Parameters
- $policy : CalculationPolicy