58 lines
3.5 KiB
Markdown
58 lines
3.5 KiB
Markdown
# 03 — Invoices and the tax reserve (v1.1)
|
||
|
||
`fiscus-ledger::invoice`: issuing invoices (faktury) from the ledger, finding them paid on a statement, and
|
||
setting a share of each paid one aside for tax. Pure like the rest: no clock, no randomness; dates and ids are
|
||
parameters.
|
||
|
||
## The supplier
|
||
`supplier.set` names who issues invoices: name, address (1–4 lines), IČO, DIČ, whether they are a VAT payer, a
|
||
registration line for the invoice, and the reserve: the thousandths of each paid invoice's amount without VAT
|
||
set aside for income tax and insurance (0–600, so 0–60 %). A VAT payer must have a DIČ. The latest
|
||
`supplier.set` counts from then on; an invoice keeps the supplier it was issued under, so changing the reserve
|
||
never changes an invoice issued before.
|
||
|
||
IČO: 8 digits, the last the weighted mod-11 check of the first seven. DIČ: `CZ` and 8–10 digits.
|
||
|
||
## An invoice
|
||
`invoice.issued` carries the whole invoice: id, number, issue and due dates, the taxable-supply date (DUZP, on a
|
||
VAT invoice only), the customer, 1–50 lines, and the budget its payment goes into (`None`: the default one).
|
||
|
||
- **Number = variable symbol.** `YYYYNNNN`: the year it was issued and its place in that year
|
||
(`State::next_invoice_number(year)`). A number is used once. The payment is matched by it.
|
||
- **A line:** text (1–200), quantity in thousandths (0,001–1 000 000), unit (≤ 10), unit price in haléře,
|
||
and on a VAT invoice a rate of 21, 12 or 0 %. Its amount is `quantity × price`, rounded half away from
|
||
zero to the haléř.
|
||
- **VAT:** per rate, from the base: the base of a rate is the sum of its lines, its VAT `base × rate / 100`
|
||
rounded once (§ 37 ZDPH). Not per line.
|
||
- **Total:** 0,01–9 999 999,99 CZK, what QR Platba carries. `State::invoice_spayd` gives the QR Platba of an
|
||
unpaid invoice: its total, `X-VS` its number, to the account set by `account.set`.
|
||
|
||
Every rule is checked when the event is applied; an invoice that breaks one is rejected and changes nothing.
|
||
|
||
## Paid
|
||
`invoice.paid { invoice, payment, on }`: `payment` is the statement line that paid it, or `None` for one marked
|
||
paid by hand. A line pays one invoice, only of the invoice's exact total, not before the invoice was issued.
|
||
|
||
`plan_invoice_payments(state, ids, at)` is what the app runs after an import. For each unpaid invoice, the
|
||
earliest statement line whose amount is its total and whose variable symbol is its number (leading zeros do
|
||
not count) pays it: `invoice.paid`, then `payment.categorised` → `income` (unless the person chose a category),
|
||
then `payment.assigned` → the invoice's budget. Nothing is guessed: a line of another amount, or without the
|
||
symbol, stays for the person to look at. Run twice, the second plan is empty.
|
||
|
||
## The reserve
|
||
When an invoice is paid, `reserve = VAT + round(net × reserve‰ / 1000)` is set aside: a VAT payer's VAT in full
|
||
(it is the state's), and the reserve share of the rest. `State::reserve_balance()` is everything set aside less
|
||
`reserve.withdrawn` (the tax or insurance paid from it), which can never take more than the reserve holds.
|
||
|
||
## Cancelling
|
||
`invoice.cancelled` cancels an unpaid invoice. A paid one stays; a credit note (opravný daňový doklad) is not
|
||
built yet.
|
||
|
||
| Event | Effect |
|
||
|:--|:--|
|
||
| `supplier.set` | the supplier from now on |
|
||
| `invoice.issued` | a new invoice, checked, with its totals |
|
||
| `invoice.paid` | paid by a statement line or by hand; the reserve set aside |
|
||
| `invoice.cancelled` | an unpaid invoice withdrawn |
|
||
| `reserve.withdrawn` | money out of the reserve, at most its balance |
|