# Invoices

The 5 tools for invoices. Before an agent first makes one, it reads guide topic invoices.

## create_invoice

Make an invoice in a space: who it is from and to, its number (given for you), the day issued and the day due, price lines with quantities and unit prices (Artifacts adds up the subtotal, discount, tax and total), how to pay (bank details) and a note. The client reads it on its published page; when the money arrives, update_invoice with paid marks it paid. When the space lists its invoices in a sheet or database (list_invoices_in), its row is written there. Read guide topic "invoices" first; check it with render_invoice; publish_item gives the link to send.

Parameters:
- `space_id` (string, required)
- `title` (string, required): What people find it by: "Invoice: Redfern Logistics, November".
- `number` (string): Its number; a new invoice is numbered for you (INV-0001, INV-0002… per space).
- `from` (object): Who it is from (you). A new invoice starts with the space's last one.
- `client` (object): Who pays it.
- `issued` (string): The day it is issued (YYYY-MM-DD; default today).
- `due` (string): The day it is due (YYYY-MM-DD; default 30 days after issued).
- `lines` (object[])
- `currency` (string): ISO code: "USD" (default), "EUR", "GBP".
- `discount_percent` (number): A discount on the subtotal, in percent.
- `tax_percent` (number): Tax on the subtotal after the discount, in percent.
- `payment` (string): How to pay, in Markdown: bank, account and routing numbers, the reference to quote. A new invoice starts with the space's last one.
- `notes` (string): A closing note, in Markdown: thanks, late-payment terms.

## read_invoice

An invoice as it is now: its status (draft, sent, overdue, paid), number, who it is from and to, the days issued and due, its price lines with their ids (what update_invoice and comment take), the totals, how to pay, the note, when it was paid (the day, the amount, who marked it), where the space lists its invoices, its published link and whether that page shows the latest version, and checks: what to fix.

Parameters:
- `item_id` (string, required)

## update_invoice

Change an invoice: the title, number, who it is from and to, the days issued and due, currency, discount, tax, how to pay and the note; add price lines (after a given id, or at the end), change them (only the parts given; null or "" clears one), remove them (only when the person asked), order them (every id once). paid marks it paid when the person says the money arrived (the day, default today, and a note such as the transfer reference): its terms then stop changing. paid: null undoes it (a mistake). Its row in the space's invoice list follows. A published invoice's page keeps the version published last: after a change, the client sees it only once it is published again (publish_item, when the person asks).

Parameters:
- `item_id` (string, required)
- `title` (string)
- `number` (string): Its number; a new invoice is numbered for you (INV-0001, INV-0002… per space).
- `from` (object)
- `client` (object)
- `issued` (string): The day it is issued (YYYY-MM-DD; default today).
- `due` (string): The day it is due (YYYY-MM-DD; default 30 days after issued).
- `currency` (string): ISO code: "USD" (default), "EUR", "GBP".
- `discount_percent` (number | null)
- `tax_percent` (number | null)
- `payment` (string | null)
- `notes` (string | null)
- `add_lines` (object[])
- `change_lines` (object[])
- `remove_lines` (string[])
- `order_lines` (string[]): Every line id once, in the new order.
- `paid` (object | null): Mark it paid, only when the person says the money arrived; null undoes it.

## list_invoices_in

Where a space lists its invoices, one row each — Number, Client, Amount, Due, Status (Draft, Sent, Paid) — kept up to date as invoices change, are published and are marked paid. Give nothing for a new database named Invoices; sheet for a spreadsheet of the space (its Invoices tab, made if missing); or database (and table) for a database of the space (the table given gets the missing fields; without table, a new Invoices table). Every invoice of the space is written there at once. off: true stops listing (the rows stay). Only when the person asks where invoices should be listed.

Parameters:
- `space_id` (string, required)
- `sheet` (string): A spreadsheet item of the space.
- `database` (string): A database item of the space.
- `table` (string): The database's table, by name or id.
- `off` (boolean): Stop listing invoices.

## render_invoice

See an invoice as people do: a screenshot of the page (its sender, client, dates, lines, totals and how to pay), plus checks — no sender, client or payment details, no price lines, a total of 0, overdue, an invoice list that cannot be written, not published yet or changed since — and errors the page hit.

Parameters:
- `item_id` (string, required)
