Quittio 0.3 API

CancellationHistory
in package

Read onlyYes
FinalYes

What the earlier partial cancellations of an invoice cancelled per VAT group (category and rate), so that the VAT of the next partial cancellation is rounded cumulatively.

VAT is rounded per document and VAT group (BR-CO-17). Rounded per partial cancellation on its own, the cancellations together can differ from the original by a cent per earlier part (e.g. 9.67 + 9.67 + 9.66 net at 19 %: 3 × 1.84 = 5.52 against 5.51). With a history, per group:

S = taxable amount of the earlier cancellations + taxable amount of this one target = round2(S × rate / 100), half up like the calculator; the original's VAT (BT-117) when this cancellation closes the group (all its lines are then cancelled completely) VAT = target − VAT of the earlier cancellations

After every cancellation the VAT cancelled so far is that of the taxable amount cancelled so far, and once all lines are cancelled exactly the original's VAT (1.84, 1.83, 1.84 = 5.51 in the example). For an original whose VAT another system rounded (BT-117 ≠ round2(BT-116 × rate)), the target is round2(S × BT-117 / BT-116): its rounding difference is spread over the parts in proportion to their taxable amounts instead of falling on the part that closes the group.

In gross price mode the taxable amount follows the same way from the gross amount G of the lines: N = round2(G cancelled so far / (1 + rate / 100)) as for the original (GrossPriceConverter), the original's BT-116 when the group closes, minus the taxable amount already cancelled. The taxable amounts of all cancellations then add up exactly to the original's, and so do the rounding amounts (BT-114).

Every cancellation therefore differs from round2(own taxable amount × rate) (or × the original's effective rate) by at most 0.01, which BR-CO-17 tolerates, and its VAT keeps the sign of its taxable amount (0.00 on 0.00); assertFits() rejects a history for which this would not hold. The VAT total in accounting currency (BT-111) follows the same way: round2(VAT cancelled so far × exchange rate), and the original's BT-111 when the cancellation closes all groups.

Amounts are signed in the original's direction: a credit note that cancels an invoice and the invoice that cancels a credit note count with their amounts, a negative invoice (strategy negative_invoice) with its amounts negated.

Table of Contents

Properties

$closes  : array<string|int, mixed>
$groups  : array<string|int, mixed>

Methods

__construct()  : mixed
align()  : BigDecimal}
The VAT of a calculated partial cancellation of $original aligned with this history: per VAT group the target minus the VAT already cancelled, and BT-111 the same way. In gross price mode the taxable amount of a group is aligned as well (the net amount of the gross amount cancelled so far minus the taxable amount already cancelled), unless that differs by more than 0.01 from the net amount of the cancellation's own gross amount (a history that does not match): then it keeps its own. Otherwise its taxable amounts stay as they are. Amounts are signed like the cancellation.
assertFits()  : void
Rejects a history that does not fit $original, checked with the calculated partial cancellation $cancellation and its aligned VAT breakdown $aligned (align()):
closes()  : bool
entries()  : array<int, BigDecimal}>
The VAT groups of an issued (calculated) cancellation of $original in the original's direction, with their share of BT-111 (distributed in proportion to their VAT; null without BT-111) and, in gross price mode, the gross amount of their lines (null otherwise).
gross()  : BigDecimal|null
Gross amount of the earlier cancellations of a group in gross price mode; null if unknown.
matches()  : bool
Whether an issued cancellation of $original carries the VAT this history gives it; false e.g.
tax()  : BigDecimal
taxable()  : BigDecimal
taxInTaxCurrency()  : BigDecimal|null
BT-111 of the earlier cancellations together; null if a share is unknown.
withCancellation()  : self
The history after an issued (calculated) cancellation of $original, e.g. to keep it without the Managed layer; $closes as in the constructor, for the next cancellation.

Properties

Methods

__construct()

public __construct([array<string, BigDecimal}> $groups = [] ][, array<int, string> $closes = [] ]) : mixed
Parameters
$groups : array<string, BigDecimal}> = []

per VAT group (key: DeclaredAmounts::breakdownKey()) the taxable amount (BT-116) and VAT (BT-117) of the earlier cancellations together, their share of BT-111 (null if unknown) and, in gross price mode, the gross amount of their lines (Σ quantity × price including VAT; null or missing if unknown), in the original's direction

$closes : array<int, string> = []

keys of the VAT groups whose lines are all cancelled completely once this cancellation is issued, including groups closed earlier

align()

The VAT of a calculated partial cancellation of $original aligned with this history: per VAT group the target minus the VAT already cancelled, and BT-111 the same way. In gross price mode the taxable amount of a group is aligned as well (the net amount of the gross amount cancelled so far minus the taxable amount already cancelled), unless that differs by more than 0.01 from the net amount of the cancellation's own gross amount (a history that does not match): then it keeps its own. Otherwise its taxable amounts stay as they are. Amounts are signed like the cancellation.

public align(InvoiceData $original, InvoiceData $cancellation) : BigDecimal}
Parameters
$original : InvoiceData
$cancellation : InvoiceData
Return values
BigDecimal} —

taxInTaxCurrency is null without VAT accounting currency (BT-6), exchange rate or known BT-111 of the earlier cancellations

assertFits()

Rejects a history that does not fit $original, checked with the calculated partial cancellation $cancellation and its aligned VAT breakdown $aligned (align()):

public assertFits(InvoiceData $original, InvoiceData $cancellation, array<int, VatBreakdown> $aligned) : void
  • every VAT group of the history and every group it closes must exist in the original,
  • the taxable amount cancelled so far (before and including this cancellation) must not exceed per group the sum of the magnitudes of the original's line net amounts,
  • every aligned VAT amount must differ by at most 0.01 from round2(own taxable amount × rate) (for an original whose VAT another system rounded, × its effective rate BT-117 / BT-116) and keep the sign of its taxable amount (0.00 on a taxable amount of 0.00).

A history built from the earlier cancellations as issued (withCancellation(), the Managed ledger) always fits.

Parameters
$original : InvoiceData
$cancellation : InvoiceData
$aligned : array<int, VatBreakdown>
Tags
throws
InvalidArgumentException

closes()

public closes(string $key) : bool
Parameters
$key : string
Return values
bool

entries()

The VAT groups of an issued (calculated) cancellation of $original in the original's direction, with their share of BT-111 (distributed in proportion to their VAT; null without BT-111) and, in gross price mode, the gross amount of their lines (null otherwise).

public static entries(InvoiceData $original, InvoiceData $cancellation) : array<int, BigDecimal}>
Parameters
$original : InvoiceData
$cancellation : InvoiceData
Return values
array<int, BigDecimal}>

gross()

Gross amount of the earlier cancellations of a group in gross price mode; null if unknown.

public gross(string $key) : BigDecimal|null
Parameters
$key : string
Return values
BigDecimal|null

matches()

Whether an issued cancellation of $original carries the VAT this history gives it; false e.g.

public matches(InvoiceData $original, InvoiceData $cancellation) : bool

after another partial cancellation was issued meanwhile.

Parameters
$original : InvoiceData
$cancellation : InvoiceData
Return values
bool

tax()

public tax(string $key) : BigDecimal
Parameters
$key : string
Return values
BigDecimal

taxable()

public taxable(string $key) : BigDecimal
Parameters
$key : string
Return values
BigDecimal

taxInTaxCurrency()

BT-111 of the earlier cancellations together; null if a share is unknown.

public taxInTaxCurrency() : BigDecimal|null
Return values
BigDecimal|null

withCancellation()

The history after an issued (calculated) cancellation of $original, e.g. to keep it without the Managed layer; $closes as in the constructor, for the next cancellation.

public withCancellation(InvoiceData $original, InvoiceData $cancellation[, array<int, string> $closes = [] ]) : self
Parameters
$original : InvoiceData
$cancellation : InvoiceData
$closes : array<int, string> = []
Return values
self
On this page

Search results