Zum Inhalt springen

API reference / Quittio \ Core \ Calculation

GrossPriceConverter

final class in quittio/core

Quittio\Core\Calculation\GrossPriceConverter · Source

Gross price mode for B2C and shops.

Shops calculate with prices including VAT, EN 16931 calculates net. Per VAT group:

  1. G = Σ g_i with g_i = round2(quantity × price incl. VAT)
  2. N = round2(G / (1 + rate / 100)); a partial cancellation aligned with the earlier ones declares its N (Corrections\CancellationHistory), which is used within 0.01
  3. T = round2(N × rate / 100) (BR-CO-17)
  4. Every line gets n_i = round2(g_i / (1 + rate / 100)); the few cents N − Σ n_i are added to the lines with the largest rounding remainders. Each line keeps the sign of its gross amount (returns and vouchers stay negative). Net prices are derived with the precision needed so that the line formula yields the line amount.
  5. G − (N + T) is returned as rounding amount for BT-114, so that the amount due equals the gross amount the customer saw. The calculator takes BT-114 from the total G and the amounts it finally uses, so that it also holds when declared amounts are kept (e.g. the aligned VAT of a partial cancellation).

Limits: all lines must use gross prices, and gross lines must not have line or document allowances or charges. Model shipping costs and discounts as lines; a discount line needs a negative quantity, because prices must not be negative (BR-27).

Methods#

MethodDescription
->appliesTo()
->convert()
::netOf()N = round2(G / (1 + rate / 100)), step 2.

appliesTo()#

public function appliesTo(InvoiceData $invoice): bool
ParameterTypeDescription
$invoiceInvoiceData
Returns
bool

convert()#

public function convert(
    InvoiceData $invoice,
    array<string, BigDecimal> $nets = [],
): array{lines: list<InvoiceLine>, rounding: BigDecimal, gross: BigDecimal}
ParameterTypeDescription
$invoiceInvoiceData
$netsarray<string, Brick\Math\BigDecimal> = []declared net amounts N per VAT group (key: DeclaredAmounts::breakdownKey()), e.g. of a partial cancellation aligned with the earlier ones (Corrections\CancellationHistory); used instead of step 2 within 0.01
Returns
array{lines: list<InvoiceLine>, rounding: Brick\Math\BigDecimal, gross: Brick\Math\BigDecimal} – gross: G of all groups

netOf()#

public static function netOf(BigDecimal $gross, BigDecimal $rate): BigDecimal

static

N = round2(G / (1 + rate / 100)), step 2.

ParameterTypeDescription
$grossBrick\Math\BigDecimal
$rateBrick\Math\BigDecimal
Returns
Brick\Math\BigDecimal

Die Open-Core-Pakete stehen unter der MIT-Lizenz. Die rechtlichen Formulierungen der Länderpakete sind mit einer Steuerberatung abzustimmen.