Draft a site's invoices
A site with Payments keeps its owner’s invoices: who each is for, its lines, its tax and terms, and what was paid against it. You read them, write drafts, save the owner’s details and make the templates invoices are drawn with. The owner issues, voids and marks invoices as paid on the Payments screen, so no command does those, and nothing you write is sent to anybody.
The Payments commands run inside bash, like every other site command.
Every one of them needs the connection to have been allowed to see
invoices, since an invoice holds the client’s contact details and the
owner’s bank details; a connection that was not is told so, and the owner
connects the agent again to allow it. Drafting and saving also need the
connection to have been allowed to change the site.
1. What an invoice is
Section titled “1. What an invoice is”- A draft has no number and goes nowhere. The owner reads it, changes what they like and issues it.
- An issued invoice has its number, the day it was issued and who it is
from, and cannot be changed. Its status is
unpaid,overdueonce its terms have run out,part_paidorpaid. - A void invoice was taken back by the owner, who may copy it into a new draft to put it right.
list_invoices names each by number, which is what get_invoice and
update_invoice_draft take. code is the number printed on an issued
invoice, such as RJ-2026-015.
Money is per currency and never added across currencies. A line’s amount is
its qty times its price; a line with no unit is a fixed price.
2. Drafting one
Section titled “2. Drafting one”- Read
list_invoicesfor the client: a past client’s invoice has their company, address and VAT number already, and itsget_invoicehas them whole. draft_invoicewith the client and the lines. What you leave out is the owner’s default: the currency, the days to pay, the tax and the note.issued_onis the day it is dated, where the owner names one; left out, it is dated the day the owner issues it. Its number is given when it is issued, so never write one.- Tell the owner the draft is ready on the Payments screen, its total, and what you guessed.
A client in the EU with a VAT number is billed with reverse charge unless
you send tax. Ask the owner rather than guess a price: their earlier
invoices to the same client are the best guide.
list_invoices --q northwind "lines": [{"description": "Audit", "qty": 2, "unit": "day", "price": 450}]}'3. Changing a draft
Section titled “3. Changing a draft”update_invoice_draft changes the fields you send and keeps the rest.
lines is the whole list in order: read the draft with get_invoice, change
the lines you mean to and send every one back, since a line left out is
dropped. An issued invoice is refused; say so to the owner, who may void it
and copy it.
4. The owner’s details
Section titled “4. The owner’s details”update_invoice_details saves what every invoice prints and each new one
starts from: who invoices are from (name, email, address, reg,
vat), how clients pay (account, bank, iban, bic, pay_link),
what a new invoice starts with (currency, terms, tax, vat_rate,
note), the numbering (prefix, next_number) and the default
template. It saves the fields you send and keeps the rest, and sets
invoices up first on a site that has not. An issued invoice keeps the
details it was issued with, so a change reaches the next one only.
- From an invoice the owner gave you, take each value as it is written
there. The number gives the numbering, so the next one reads like it:
INV-2026-014isprefixINV-{year}-({year}is the year each is issued, all four digits) andnext_number15, the count following in three digits at least. A count with fewer digits, or one that isn’t last, goes where{number}stands, as it is:INV-6isINV-{number}and 7,14/2026is{number}/{year}and 15. Where neither fits (INV-26-014), save the closest and tell the owner how their next number will read. - A value the invoice shows that has no field of its own: what follows
from the invoice (a title from its first line, a service period from
the day it’s dated) is worked out in the template’s script, and what
is the owner’s alone (a correspondent bank’s code) goes on a line of
its own in the closest field (
bank), for the template to print from there. Tell the owner what you put where. - From the site, take its name, address, registration and VAT number.
- Never guess a bank detail. Leave out what you could not read, and ask.
5. An invoice template
Section titled “5. An invoice template”A template is an artifact of kind template that reads the invoice and
invoice_items sources: the one invoice it is drawn with, whose fields
list_artifacts names under sources. The Payments screen, an invoice’s
link and its PDF all draw the invoice with one. Read the
making-artifacts guide for the files and the commands.
-
Read the starter,
get_artifact --slug invoice, where the site has it: it prints every field, and its look is in inline styles, so the link and the PDF look the same. -
Take the look of what the owner asked for or gave you: the layout, the type, the colours, the labels and their language.
-
Print every value from the sources, and never type one in: the number, the dates, the client, the lines, the sums, who it is from and how to pay. Then each invoice only needs its own client, lines and date. Text that is the same on every invoice and is none of those (a line of terms, a thank-you) may be written into the template.
-
Make it, and open its
preview_urlto look before you say it is done:Terminal window create_artifact --slug invoice-classic --title "Classic" --kind template \--reads invoice --reads invoice_items --note "make a template like my invoice" --text '…' -
With an example invoice, unless the owner says otherwise: save their details from it (
update_invoice_details), withtemplateset to the new template so new invoices are drawn with it, and draft the next invoice for the same client and lines (draft_invoice, noissued_on), so the owner only changes its date and amounts and issues it. Say what you read and what you could not.
6. Reminders
Section titled “6. Reminders”A reminder is your reply, not a command. Read the invoice with
get_invoice: its client, code, amount_due, due_on and how to pay
(pay). Write it short and polite, in the owner’s voice, and leave it for
the owner to send from their own mail.
7. When a command refuses
Section titled “7. When a command refuses”- Invoices are not set up: save the owner’s details with
update_invoice_details, which sets them up, or the owner sets them up on the Payments screen. - The plan does not include Payments: the owner can change plans.
- The invoice is issued: only a draft changes here.
- A value is refused, such as a currency the site does not take: the sentence names it; send it again without it or with what it names.