API reference / Quittio \ Core \ Corrections
Cancellation
final class in quittio/core
Quittio\Core\Corrections\Cancellation · Source
Full cancellation of an issued invoice: a new invoice with its own number that reverses the original and refers to it (BG-3).
Sign strategies (17.2):
- credit_note: type code 381, amounts positive; UBL writes a CreditNote document,
- negative_invoice: type code 380, quantities and allowance/charge amounts negated.
The cancellation of a credit note is an invoice (380) with the same positive amounts in both strategies.
Self-billed documents stay self-billed (issued by the buyer, labelled "Gutschrift" by the kept regulatory note): a self-billed invoice (389) or debit note (527) is cancelled by a self-billed credit note (261) or a negative self-billed invoice (389), a self-billed credit note by a self-billed invoice (389) with positive amounts.
Both are permitted in Germany; apart from self-billing the document must not be called "Gutschrift". The original data is never changed.
Declared amounts (Meta::FLAG_DECLARED_AMOUNTS): a full cancellation reverses the declared line net amounts (BT-131) and the declared VAT breakdown (BT-116, BT-117) of the original, also if another system rounded differently (BT-131 within 0.02, PEPPOL-EN16931-R120; BT-117 within the tolerance of BR-CO-17), so that the totals BT-106 to BT-115 are reversed exactly. A partial cancellation keeps the declared amounts of whole cancelled lines; quantities and amounts of a line are recalculated. Its VAT is that of the cancelled part, round2(taxable amount × rate) per VAT group, unless a CancellationHistory of the earlier partial cancellations is given: then the VAT is rounded cumulatively per group and declared (Meta::FLAG_CANCELLATION_VAT_ALIGNED), so that all cancellations together reverse exactly the taxable amount (BT-116) and the VAT (BT-117) of every group and BT-111 in accounting currency. In gross price mode the net amounts follow cumulatively from the gross amounts cancelled so far (round2(G / (1 + rate)) like the original) and the rounding amount (BT-114) from the amounts used, so that the amount due stays the gross amount of the cancelled lines. Every cancellation then differs by at most 0.01 from round2(own taxable amount × rate), with the sign of its taxable amount (QUITTIO-CANCELLATION-VAT-ALIGNED, mentioned in the cancellation note); for an original whose VAT another system rounded, from round2(own taxable amount × the original's BT-117 / BT-116), which spreads that rounding over the parts. A history that does not fit the original (CancellationHistory::assertFits()) is rejected.
Constants#
| Constant | Value | Description |
|---|---|---|
STRATEGIES | [\Quittio\Core\Countries\CorrectionPolicy::CANCELLATION_CREDIT_NOTE, \Quittio\Core\Countries\CorrectionPolicy::CANCELLATION_NEGATIVE_INVOICE] |
Methods#
| Method | Description |
|---|---|
::of() |
of()#
public static function of(
InvoiceData $original,
string $number,
string $strategy = \Quittio\Core\Countries\CorrectionPolicy::CANCELLATION_CREDIT_NOTE,
?string $reason = null,
?Date $issueDate = null,
?string $locale = null,
string|null $title = null,
list<array{line: string, quantity?: BigDecimal|int|string, Amount?: string}>|null $lines = null,
?CorrectionPolicy $policy = null,
CancellationHistory|null $history = null,
TotalsCalculator $calculator = new \Quittio\Core\Calculation\En16931Calculator(),
): InvoiceBuilder| Parameter | Type | Description |
|---|---|---|
$original | InvoiceData | |
$number | string | |
$strategy | string = \Quittio\Core\Countries\CorrectionPolicy::CANCELLATION_CREDIT_NOTE | |
$reason | ?string = null | |
$issueDate | ?Date = null | |
$locale | ?string = null | |
$title | string|null = null | document title in the PDF, e.g. "Stornorechnung"; without it the title comes from $policy ("cancellation_self_billed" for self-billed originals) |
$lines | list<array{line: string, Quittio\Core\Corrections\quantity?: Brick\Math\BigDecimal|int|string, Amount?: string}>|null = null | partial cancellation: whole lines, a quantity of a line or an amount of a line (e.g. a price reduction); null cancels the whole invoice. Quantities and amounts are magnitudes, negative lines keep their sign. For lines with a price including VAT (gross price mode) the amount includes VAT |
$policy | ?CorrectionPolicy = null | |
$history | CancellationHistory|null = null | partial cancellations: what the earlier partial cancellations of the original cancelled per VAT group, and which groups this one closes, for the cumulative rounding of the VAT (see CancellationHistory); without it the VAT is rounded per document |
$calculator | TotalsCalculator = new \Quittio\Core\Calculation\En16931Calculator() | calculator of the VAT alignment with $history, e.g. the one of the Quittio instance |
- Returns
InvoiceBuilder- Throws
InvalidArgumentException– e.g. for a history that does not fit the original