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.
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
item
hours
rate
amount
Patient leaflet design
6
£65
£390.00
Waiting-room posters (set of four)
9
£65
£585.00
Appointment cards
2.5
£65
£162.50
Print-ready files and proofs
1.5
£65
£97.50
Total
£1,235.00
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.
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.
number
client
issued
due
amount
paid
INV-034
Northfield Dental
£1,235
INV-033
Bluebell Florist
£720
INV-032
Kestrel Physio
£1,105
INV-031
Greenway Bakery
£960
Waiting to be paid
number
client
due
amount
INV-032
Kestrel Physio
£1,105
INV-034
Northfield Dental
£1,235
Total
£2,340
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.
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
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.
Switch on paid for INV-032. It leaves "Waiting to be paid", and that total drops by 1105.00.
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.
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.
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 dataset title Invoices# Amounts show in pounds. A rate is often not money, so `with rate` says this one is.set currency £ with rateset page A4 margins normalset font DM Sansset heading-font DM Sans# ---- Colours, each with its shade for dark pages ----------------------------------------palette ink#1c2230dark#e6e9f0 brand#3b3fb6dark#a9acff paper#ffffffdark#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.studiosplit"|" 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-studioclassstudio > span:last-child { font-size: 0.62em; font-weight: 600; letter-spacing: 0.24em; text-transform: uppercase; color: var(--brand) }classstudio > span:first-child::before { content: "◆ "; color: var(--brand) }line address _->div.addresssplit"|" 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-addressline 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-payline thanks _->p.thankssplit"|" 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 ... ``` ->factsverbatim~~~::: invoicestudio Larkfield Studio | Invoiceaddress 4 Mill Lane, Hebden Bridge HX7 8AD | hello@larkfield.example | 01422 845 210```factsacrossBill to: Northfield Dental | Dr Maya Lund, 12 Station Road, Ilkley LS29 8HBInvoice: INV-034Issued: 20 November 2026Due: 20 December 2026 | 30 days```view: lines as table plain columns item, hours, rate, amount filter invoice = INV-034 sum amountpay **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 ledgerEvery 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 -> rednumber, client:choice(from clients.name), issued:date, due:date = issued + 30d, amount = sum(lines.amount), paid:toggleINV-031, Greenway Bakery, 2026-09-14, yesINV-032, Kestrel Physio, 2026-10-02, noINV-033, Bluebell Florist, 2026-10-19, yesINV-034, Northfield Dental, 2026-11-20, no```### Waiting to be paidview: invoices as table plain columns number, client, due, amount filter not paid sum amount## LinesOne 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 amountinvoice:choice(from invoices.number), item, hours:number, rate:number, amount = hours * rateINV-031, Menu board design, 6, 60.00INV-031, Price cards for the counter, 10, 60.00INV-032, Booking page, 14, 65.00INV-032, Print files for leaflets, 3, 65.00INV-033, Logo refresh, 8, 60.00INV-033, Shop window lettering, 4, 60.00INV-034, Patient leaflet design, 6, 65.00INV-034, Waiting-room posters (set of four), 9, 65.00INV-034, Appointment cards, 2.5, 65.00INV-034, Print-ready files and proofs, 1.5, 65.00```## Clients```data clients as cardsname, contact, address, email:urlGreenway Bakery, Priya Shah, "3 Market Street, Todmorden OL14 5AJ", mailto:priya@greenway.exampleKestrel Physio, Tom Reid, "Unit 2, Calder Works, Halifax HX1 1XZ", mailto:tom@kestrel.exampleBluebell Florist, Sam Okoro, "18 Crown Street, Hebden Bridge HX7 8EH", mailto:sam@bluebell.exampleNorthfield 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 yourself1. 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.