SelfscribeDownloadOpen the app

Client statements

One statement per client, worked out from your job log and printed in one run.

Document · Advanced · uses mail merge, totals, print

Edit it in the playgroundRead the file

What it shows

Send each client a statement worked out from your jobs.

What you learn

Totals per client from a log of jobs, values looked up in another table, fields a merge fills, a view that lists one client's rows, text that changes with a value, text only the template shows.

Try this

  • Step through the clients with ‹ › over the page, then press Merge… for one PDF with a statement each.
  • Mark "Shop front signwriting" paid in the jobs block, and Greenway Bakery's statement drops by 1080.00.
  • Change Kestrel Physio's rate from 65.00 to 50.00, and its statement no longer offers two parts.
examples/statements.self · 136 lines
~~~ selfscribe
# Lesson: Send each client a statement worked out from your jobs.
# You learn: totals per client from a log of jobs, values looked up in another table, fields a merge fills, a view that lists one client's rows, text that changes with a value, text only the template shows.
# Try this: step through the clients with ‹ › over the page, then press Merge… for one PDF with a statement each.
# Try this: mark "Shop front signwriting" paid in the jobs block, and Greenway Bakery's statement drops by 1080.00.
# Try this: change Kestrel Physio's rate from 65.00 to 50.00, and its statement no longer offers two parts.
# summary: One statement per client, worked out from your job log and printed in one run.
# category: money
# tags: document, advanced, work
# uses: mail merge, totals, print
use data
set title Client statements
# Amounts show in pounds; hours stay plain numbers.
set currency £
set page A4 margins normal
set style paper
set font DM Sans
set heading-font DM Sans
# keep: each line break you type stays a line break, as an address needs.
set linebreaks keep

# ---- Mail merge: one statement per row of `bill`, the totals near the end -----------------
# `bill` has a row for each client with jobs still to pay. A file works the same way
# (`set merge clients.csv`), and so does a table of a database.
set merge bill
# What the fields show outside a merge, as in the gallery: the first client's statement.
set client  Greenway Bakery
set contact Priya Shah
set street  3 Market Street
set town    Todmorden OL14 5AJ
set rate    60.00
set sum_hours 32
set owed    1920.00
# A name in double braces is a field. With #if, else and /if in braces, the page chooses
# between two texts.
inline {{_}}                 -> var

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

# ---- The letterhead: "studio Name | Kind of paper", then "address a | b | c" ---------------
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; color: var(--ink) }  as stm-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 2em; padding-bottom: 1.1em; border-bottom: 1px solid var(--line); font: 0.8em/1.5 var(--doc-font-ui); opacity: 0.75 }  as stm-address

# ---- ":::: head": who it is for ("::: to") beside what they owe ("::: owed") -------------
block  :::: head ... ::::    -> div.billto    { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1.2em 2em; margin: 0 0 1.4em }  as stm-billto
block  ::: to ... :::        -> address.to    { font-style: normal; line-height: 1.5 }  as stm-to
block  ::: owed ... :::      -> div.owed      { min-width: 14em; padding: 0.9em 1.3em; border-radius: 12px; background: var(--tint); text-align: right; font: 0.85em/1.5 var(--doc-font-ui); color: var(--ink) }  as stm-owed
class  owed strong           { font-size: 2.3em; line-height: 1.3; letter-spacing: -0.01em; color: var(--brand) }
line   dated _               -> div.dated     split "|" span  { display: flex; flex-wrap: wrap; gap: 0.2em 2em; margin: 0 0 1.4em; padding: 0.6em 0; border-block: 1px solid var(--line); font: 0.85em/1.4 var(--doc-font-ui); opacity: 0.85 }  as stm-dated

# ---- "small ..." the fine print at the foot ------------------------------------------------
line   small _               -> p.small       { margin-top: 2em; padding-top: 0.8em; border-top: 1px solid var(--line); font-size: 0.8em; opacity: 0.7 }  as stm-small
~~~
studio Larkfield Studio | Statement
address 4 Mill Lane, Hebden Bridge HX7 8AD | hello@larkfield.example | 01422 845 210

:::: head
::: to
**{{client}}**
{{contact}}
{{street}}
{{town}}
:::
::: owed
Amount due
**£{{owed}}**
{{#if owed > 2000}}in two parts, as agreed{{else}}by 14 December 2026{{/if}}
:::
::::

dated Statement date: 30 November 2026 | Your rate: £{{rate}} an hour | Hours not yet paid: {{sum_hours}}

These jobs are finished and invoiced, and not yet paid. Thank you for your work with us this autumn.

view: jobs as table plain columns job, finished, hours, amount filter client = "{{client}}" and not paid sum hours, amount

{{#if owed > 2000}}As agreed, you can pay this in two parts: half by 14 December, and the rest by 14 January.{{else}}Please pay by 14 December 2026.{{/if}}

small Pay by bank transfer to Larkfield Studio, with your name as the reference. Anything here you do not recognise? Write to hello@larkfield.example and we will look at it the same day.

{{#unless records}}
## Who gets a statement

Every client with a job still to pay, worked out from the job log. The table is the merge's list, so no statement prints it.
{{/unless}}

```data bill from jobs where not paid per client sum hours, amount count as table title "Who gets a statement" columns client, contact, town, records, sum_hours, owed
% client, contact = client.contact, street = client.street, town = client.town, rate = client.rate, owed = sum_amount
```

```data clients as hidden
name, contact, street, town, rate:number
Greenway Bakery, Priya Shah, 3 Market Street, Todmorden OL14 5AJ, 60.00
Kestrel Physio, Tom Reid, "Unit 2, Calder Works", Halifax HX1 1XZ, 65.00
Bluebell Florist, Sam Okoro, 18 Crown Street, Hebden Bridge HX7 8EH, 60.00
Northfield Dental, Dr Maya Lund, 12 Station Road, Ilkley LS29 8HB, 65.00
```

```data jobs as hidden
job, client:choice(from clients.name), finished:date, hours:number, paid:bool, amount = hours * client.rate
Price cards, Greenway Bakery, 2026-09-04, 10, yes
Autumn menu boards, Greenway Bakery, 2026-09-18, 8, no
Shop window lettering, Bluebell Florist, 2026-09-28, 4, yes
Booking page, Kestrel Physio, 2026-10-02, 22, no
Leaflet print files, Kestrel Physio, 2026-10-16, 3, no
Wedding brochure, Bluebell Florist, 2026-10-23, 9, no
Christmas order cards, Greenway Bakery, 2026-10-29, 6, no
Logo for the new clinic, Kestrel Physio, 2026-11-06, 12, no
Shop front signwriting, Greenway Bakery, 2026-11-12, 18, no
Waiting-room posters, Northfield Dental, 2026-11-14, 9, yes
```

{{#unless records}}
## How it's made

- `set merge bill` makes one statement for each row of `bill`. The page above is the template, and each `{{client}}` or `{{owed}}` in it is a field that the row fills.
- `bill` reads the job log: `from jobs where not paid per client sum hours, amount count` adds up each client's open jobs. Its `%` line looks up the client's address and rate in `clients`.
- The table of jobs is `view: jobs … filter client = "{{client}}" and not paid`, so each statement lists that client's jobs only.
- An `#if owed > 2000` marker in double braces chooses between two texts, in the box and under the table. This part sits between `#unless records` and `/unless` markers: every client in the merge has open jobs, so no statement prints it.

## Try it yourself

1. Step through the clients with ‹ › over the page. Bluebell Florist's statement has one job, and Northfield Dental gets none: everything is paid.
2. In Source, find "Shop front signwriting" in the `jobs` block and change its `no` to `yes`. Greenway Bakery's statement drops by 1080.00.
3. In the `clients` block, change Kestrel Physio's rate from 65.00 to 50.00. Its total falls under 2000, and the line about two parts gives way to "Please pay by 14 December 2026."
4. Add a job `Gift vouchers, Northfield Dental, 2026-11-25, 3, no` to the `jobs` block. Northfield Dental gets a statement too.

Next: *Invoices* keeps the line items of each job. *Certificates* merges straight from a table.
{{/unless}}