SelfscribeDownloadOpen the app

Invoices

Line items that add themselves up per invoice, laid out to print and send.

Document · Advanced · uses totals, print, table

Edit it in the playgroundRead the file

What it shows

Keep invoices as line items that total themselves.

What you learn

A table to pick from, a column worked out from others, an invoice drawn from its own lines, a ledger that adds each invoice up, a test that marks what is late.

Try this

  • Change the hours of "Waiting-room posters" from 9 to 11, and its line, the invoice's total and the ledger follow.
  • Switch on paid for INV-032, and "Waiting to be paid" drops by 1105.00.
  • Add INV-034, Delivery to the practice, 1, 65.00 to the lines, and it joins the sheet and its total.
examples/invoice.self · 122 lines
~~~ selfscribe
# Lesson: Keep invoices as line items that total themselves.
# You learn: a table to pick from, a column worked out from others, an invoice drawn from its own lines, a ledger that adds each invoice up, a test that marks what is late.
# Try this: change the hours of "Waiting-room posters" from 9 to 11, and its line, the invoice's total and the ledger follow.
# Try this: switch on paid for INV-032, and "Waiting to be paid" drops by 1105.00.
# Try this: add `INV-034, Delivery to the practice, 1, 65.00` to the lines, and it joins the sheet and its total.
# summary: Line items that add themselves up per invoice, laid out to print and send.
# category: money
# tags: document, advanced, work
# uses: totals, print, table
#
# ---- "```data NAME" ... "```": a table of rows, and "view: NAME ..." to show it again -------
# `use data` brings the Markdown rules plus data blocks and `view:` lines.
use data
set title Invoices
# Amounts show in pounds. A rate is often not money, so `with rate` says this one is.
set currency £ with rate
set page A4 margins normal
set font DM Sans
set heading-font DM Sans

# ---- Colours, each with its shade for dark pages ----------------------------------------
palette
  ink    #1c2230  dark #e6e9f0
  brand  #3b3fb6  dark #a9acff
  paper  #ffffff  dark #1c2029
  line   color-mix(in srgb, currentColor 13%, transparent)
  tint   color-mix(in srgb, var(--brand) 7%, transparent)

# ---- "::: invoice" ... ":::": the sheet that is printed and sent ---------------------------
block  ::: invoice ... :::   -> article.invoice  { margin: 0 0 2.4em; padding: 2em 2.2em 1.4em; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 48px -32px rgb(0 0 0 / 0.45) }  as inv-sheet

# ---- Lines of the sheet, each by the word it starts with -------------------------------
# "studio Name | Invoice": the name on the left, the kind of paper on the right.
line   studio _              -> div.studio    split "|" span  { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.4em 1em; font: 700 1.35em/1.2 var(--doc-font-heading); letter-spacing: -0.01em }  as inv-studio
class  studio > span:last-child  { font-size: 0.62em; font-weight: 600; letter-spacing: 0.24em; text-transform: uppercase; color: var(--brand) }
class  studio > span:first-child::before  { content: "◆ "; color: var(--brand) }
line   address _             -> div.address   split "|" span  { display: flex; flex-wrap: wrap; gap: 0.1em 1.2em; margin: 0.4em 0 1.4em; padding-bottom: 1.1em; border-bottom: 1px solid var(--line); font: 0.8em/1.5 var(--doc-font-ui); opacity: 0.75 }  as inv-address
line   pay _                 -> p.pay         { margin: 1.2em 0 0.3em; padding: 0.8em 1em; border-radius: 10px; background: var(--tint); font-size: 0.92em }  as inv-pay
line   thanks _              -> p.thanks      split "|" span  { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.2em 1em; margin: 0.8em 0 0; font-size: 0.85em; opacity: 0.7 }  as inv-thanks

# ---- "```facts" with `across`: the strip of who, which and when --------------------------
block  ``` facts ... ```     -> facts  verbatim
~~~
::: invoice
studio Larkfield Studio | Invoice
address 4 Mill Lane, Hebden Bridge HX7 8AD | hello@larkfield.example | 01422 845 210

```facts
across
Bill to: Northfield Dental | Dr Maya Lund, 12 Station Road, Ilkley LS29 8HB
Invoice: INV-034
Issued: 20 November 2026
Due: 20 December 2026 | 30 days
```

view: lines as table plain columns item, hours, rate, amount filter invoice = INV-034 sum amount

pay **Please pay by 20 December 2026**, in pounds, by bank transfer to Larkfield Studio, with INV-034 as the reference. No VAT is charged: the studio is not VAT registered.

thanks Thank you for the work, Maya. | Ana Ferreira, Larkfield Studio
:::

## The ledger

Every invoice, newest first. One that is unpaid after its due date turns red.

```data invoices as table sort issued desc when not paid and due < today -> red
number, client:choice(from clients.name), issued:date, due:date = issued + 30d, amount = sum(lines.amount), paid:toggle
INV-031, Greenway Bakery, 2026-09-14, yes
INV-032, Kestrel Physio, 2026-10-02, no
INV-033, Bluebell Florist, 2026-10-19, yes
INV-034, Northfield Dental, 2026-11-20, no
```

### Waiting to be paid

view: invoices as table plain columns number, client, due, amount filter not paid sum amount

## Lines

One line per piece of work. The invoice column puts it on its invoice, and **+ Add** on a group adds a line to that invoice.

```data lines as table columns item, hours, rate, amount group invoice sum amount
invoice:choice(from invoices.number), item, hours:number, rate:number, amount = hours * rate
INV-031, Menu board design, 6, 60.00
INV-031, Price cards for the counter, 10, 60.00
INV-032, Booking page, 14, 65.00
INV-032, Print files for leaflets, 3, 65.00
INV-033, Logo refresh, 8, 60.00
INV-033, Shop window lettering, 4, 60.00
INV-034, Patient leaflet design, 6, 65.00
INV-034, Waiting-room posters (set of four), 9, 65.00
INV-034, Appointment cards, 2.5, 65.00
INV-034, Print-ready files and proofs, 1.5, 65.00
```

## Clients

```data clients as cards
name, contact, address, email:url
Greenway Bakery, Priya Shah, "3 Market Street, Todmorden OL14 5AJ", mailto:priya@greenway.example
Kestrel Physio, Tom Reid, "Unit 2, Calder Works, Halifax HX1 1XZ", mailto:tom@kestrel.example
Bluebell Florist, Sam Okoro, "18 Crown Street, Hebden Bridge HX7 8EH", mailto:sam@bluebell.example
Northfield Dental, Dr Maya Lund, "12 Station Road, Ilkley LS29 8HB", mailto:reception@northfield.example
```

## How it's made

- The sheet at the top is a `::: invoice` block. Its letterhead is two lines of your own, `studio` and `address`, and the strip under them is a `facts` block with `across`.
- Its lines are `view: lines as table plain … filter invoice = INV-034 sum amount`. `plain` draws them as part of the page, with the total as a bare figure.
- In `lines`, `amount = hours * rate` is worked out for each line. In `invoices`, `amount = sum(lines.amount)` adds up the lines that name that invoice, and `due:date = issued + 30d` works out the date.
- `when not paid and due < today -> red` on the ledger marks an invoice that is late on the day you read it.

## Try it yourself

1. Change the hours of "Waiting-room posters" from 9 to 11. Its line, the sheet's total and INV-034 in the ledger all grow by 130.00.
2. Switch on paid for INV-032. It leaves "Waiting to be paid", and that total drops by 1105.00.
3. Press **+ Add** under INV-034 in the lines and write "Delivery to the practice", 1 hour at 65.00. The new line already says INV-034, and it joins the sheet.
4. Add `Moorside Primary, Ruth Clegg, "Moor Lane, Halifax HX2 0AB", mailto:office@moorside.example` to the clients. Moorside Primary can now be picked in the ledger's client column.

Next: *Client statements* turns jobs like these into a statement for each client. *Household budget* adds up bills.