Files
FiscusPublic/docs/07_receipts.md
T
mnovak 507eb62216 [fiscus-capture] Receipts: the fields every Czech receipt shows, read from an OCR's words; payment.receipt_attached
fiscus_capture::receipt::read takes the OCR's lines (words with boxes and confidence in thousandths) and finds
the total, date and time, IČO (check digit), DIČ and the shop's name by their labels, never a shop's layout;
unsure words mark their field, the shop is always to check; bounded, control characters dropped, a proptest.
The phone's post takes a receipt (source receipt, ico, dic). The ledger gains payment.receipt_attached (the
payment keeps its merchant and key), known_shop and receipt_match (exactly one candidate or none).
docs/07_receipts.md; fixtures/receipts/ waits for redacted samples. v0.9.0.
2026-11-17 19:40:08 +01:00

3.2 KiB
Raw Permalink Blame History

07 · Receipts

A receipt becomes a payment, or fills in one you have. The image is read by an OCR outside the core (Lector, on the PC or the phone, in the app); the core gets its words and reads the fields, and keeps the result.

Reading (fiscus_capture::receipt)

Input: the OCR's lines of words, each word with its box (pixels of the upright image) and its confidence in thousandths (0–1000; the app converts, so no float enters the core). Output: a Receipt with the fields it found, each with its boxes and sure (every word read with confidence ≥ 800).

What every Czech receipt must show, found by its label, never by a shop's layout:

Field How
total the rightmost amount on a line labelled K úhradě, Částka k úhradě, Celkem k úhradě (best), Celkem, Celková částka, Celkem Kč (next), Suma, Total; or alone on the line after the label. A line with DPH, Základ, Sazba, Mezisoučet, Zaokrouhlení or Vráceno is never the total. Among equals, the larger. 1 284,90, 1284.90, groups split over words; read from text into haléře; over 10 000 000 Kč is refused whole, never read as its tail
date, time 16.11.2026, 16. 11. 2026, 16.11.26, 2026-11-16, 16/11/2026 (years 2000–2100); 14:32[:05]. A date with a time on its line first
IČO 8 digits after IČ/IČO, with the weighted mod-11 check digit (invoice::ico_ok); else from a company DIČ (CZ + the IČO)
DIČ CZ and 8–10 digits, in one word or two
shop the first line from the top with three letters or more, more letters than twice its digits, and no label (IČ, DIČ, Tel, a web or email address…), above the IČO's line (or among the first six). All capitals become Title Case. Always sure: false: you check it

Nothing found is an empty Receipt, not an error. Hostile input is bounded: at most 600 lines, 120 words a line, 80 characters a word (else TooLarge); control characters are dropped. A proptest feeds random text.

No shop templates. As with bank statements, no rule specific to one shop's receipts is written without real samples of them (fixtures/receipts/, none yet).

In the ledger

  • payment.receipt_attached { payment, receipt: { shop, ico, dic } } attaches it to any payment (captured, imported, added; on a confirmed pair it shows on the one payment). Checked: the shop 1–100 characters, trimmed, no control characters; a valid IČO and DIČ. A later one replaces it.
  • The payment keeps its merchant and merchant key, so the rules that bring a category stay as they are; the apps show the shop's name from the receipt.
  • State::known_shop(ico): your latest receipt with that IČO, its name and that payment's category. A shop you have confirmed once is named and categorised from then on.
  • State::receipt_match(total, date): the one outflow of exactly that amount within 3 days (MATCH_DAYS) that has no receipt yet. Two or more, or none: None, and the receipt is a payment of its own. Nothing is guessed.

From the phone

The Android app reads the receipt itself and posts only the fields, as the iPhone Shortcut's post with "source": "receipt" and optional ico and dic (docs/02_capture_sharing.md). The photo never leaves the phone.