Billing tools
Billing is for the people who plan a project’s invoicing. Today it holds the invoice plan: the planned invoices of each project, with their dates and amounts. It can answer “what is still to be invoiced on Riverside Clinic this year?” or “plan the rest of the fee as one invoice at the end of March”, and make the change.
A planned invoice is a forecast of a future invoice. It is not an invoice, and these tools never make or send one.
The toolset also has:
search_records. Search for the project to get its id. There is noplanned_invoicekind: uselist_planned_invoicesto find planned invoices.delete_recordwith kindplanned_invoice. It deletes one pending planned invoice for good. There is norestore_recordin this toolset.list_projectsandget_project.
An account admin gets 8 tools. Drum offers the toolset to anyone who can read, create, change or delete the planned invoices of some project.
The same operations run the web planned invoice form and the REST endpoints under Planned invoices, so a change is refused or saved for the same reasons everywhere.
What the tools cannot do
- Make, send or change an invoice. The invoice and progress claim tools come later.
- Change or delete an invoiced or paid planned invoice. It is the record of its invoice (
planned_invoice_not_pending). Change the invoice in Drum instead. - Generate a default invoice schedule, delete all pending planned invoices, or bulk delete. These stay in Drum for now, as does the project’s switch that limits its plan to its budget.
How the tools fit together
- Find the project.
search_recordsorlist_projectsgives theproject_id. - Read the plan.
list_planned_invoiceswithproject_idgives the project’s planned invoices by planned date. Addstatus: "pending"for the part that is not invoiced yet. - Change it.
create_planned_invoiceadds one,update_planned_invoicechanges a pending one, anddelete_recordwith kindplanned_invoicedeletes a pending one.
Fixed amount or percentage
Each planned invoice has a billing_type:
fixed_amount(the default): sendamount_cents. That amount is the plan.percentage: sendpercentage(0 to 100 of the project’s invoicing budget), orpercentage_of_remaining_budget(more than 0 and up to 100 of the budget that no other pending planned invoice holds yet). Drum sets the amount, and keeps it up to date when the budget changes.
To plan everything that is not planned yet, send percentage_of_remaining_budget: 100 rather than an amount you work out. When the project limits its plan to its budget, a plan above the remaining budget is refused with validation_failed.
Stale changes
Send the updated_at of your read as expected_updated_at on update_planned_invoice. If the planned invoice changed since, by an edit or a recalculation of the project’s plan, the call answers conflict with reason stale_state and changes nothing. An update that sends only planned_date or description keeps the stored amount and percentage.
Who sees what
The view, create, update and delete rights are separate, as in Drum. A member with a write right and no view right can still make that change, but does not see the planned invoice in the list, and the write answers only {id, status}, so the amount and the linked invoice stay hidden.
create_planned_invoice takes an idempotency_key, so a retry after a timeout does not add a second planned invoice.
Errors
| Reason | When |
|---|---|
planned_invoice_not_found, project_not_found |
Missing, deleted, in another account, or not readable by the user |
planned_invoice_not_pending |
The planned invoice is invoiced or paid |
stale_state |
It changed since the expected_updated_at read |
validation_failed |
The project’s budget limit refused the plan |
missing_input, invalid_input |
A field is missing or does not parse. field names it |
list_planned_invoices
List the planned invoices (the invoice plan) of the projects that the user can see, by planned date. A planned invoice forecasts a future invoice. It is not an invoice. Send project_id for the plan of one project, and status pending for the part that is not invoiced yet. Use get_planned_invoice to read one by id. Use the ids with update_planned_invoice, or with delete_record kind planned_invoice.
| Title | List planned invoices |
| Toolsets | Billing |
| Kind | Read only, Idempotent |
| Needs | api_read, and read_invoices or a project role that can view planned invoices. The rows are the planned invoices the user can read |
| Returns | planned_invoices, count, limit, offset, has_more |
| Input | Type | Required | Description |
|---|---|---|---|
project_id |
integer | From search_records or list_projects. | |
status |
string | pending: not invoiced yet. invoiced and paid: linked to an invoice. One of pending, invoiced, paid. |
|
planned_date_from |
string | Planned on or after, yyyy-mm-dd. | |
planned_date_to |
string | Planned on or before, yyyy-mm-dd. | |
limit |
integer | Maximum rows to return. Default 25, maximum 100. | |
offset |
integer | Number of rows to skip. Default 0. |
get_planned_invoice
Read one planned invoice by id: its project, planned date, amount, status and linked invoice. A planned invoice forecasts a future invoice. It is not an invoice. Use list_planned_invoices to find the ids, or to read the plan of a project. updated_at is the expected_updated_at of update_planned_invoice.
| Title | Get planned invoice |
| Toolsets | Billing |
| Kind | Read only, Idempotent |
| Needs | api_read, and the read right on that planned invoice, as for list_planned_invoices |
| Returns | planned_invoice |
| Input | Type | Required | Description |
|---|---|---|---|
planned_invoice_id |
integer | Yes | From list_planned_invoices. |
create_planned_invoice
Add a planned invoice to the invoice plan of a project, as Add Planned Invoice in Drum does. It forecasts revenue, and does not make or send an invoice. billing_type fixed_amount (the default) needs amount_cents. billing_type percentage needs percentage or percentage_of_remaining_budget, and Drum sets the amount from it. To plan what is not planned yet, send percentage_of_remaining_budget (100 for all of it), not an amount that you calculate. When the project limits its plan to its budget, a plan above the remaining budget is refused (validation_failed).
| Title | Create planned invoice |
| Toolsets | Billing |
| Kind | Writes data |
| Needs | api_create, and create_invoices or a project role that can create planned invoices on the project |
| Returns | planned_invoice, replayed |
| Input | Type | Required | Description |
|---|---|---|---|
project_id |
integer | Yes | From search_records or list_projects. |
billing_type |
string | fixed_amount (default on a create): amount_cents is the plan. percentage: the amount follows a percentage of the project budget. One of fixed_amount, percentage. |
|
planned_date |
string | Yes | yyyy-mm-dd. |
amount_cents |
integer | Integer cents, tax exclusive. fixed_amount only. | |
percentage |
number | 0 to 100 of the project’s invoicing budget. percentage only. | |
percentage_of_remaining_budget |
number | More than 0 to 100 of the budget that no other pending planned invoice holds. percentage only, not with percentage. | |
description |
string | 255 characters or fewer. | |
idempotency_key |
string | 255 characters or fewer. |
update_planned_invoice
Change one pending planned invoice. Omit a field to keep it, or send null to clear description. Send the updated_at of your read as expected_updated_at, and a change made since then answers stale_state. An invoiced or paid planned invoice is the record of its invoice and cannot change (planned_invoice_not_pending). For billing_type percentage, Drum sets the amount from the percentage, so do not send amount_cents. Use delete_record with kind planned_invoice to delete one.
| Title | Update planned invoice |
| Toolsets | Billing |
| Kind | Writes data, Idempotent |
| Needs | api_update, and update_invoices or a project role that can update planned invoices on the project |
| Returns | planned_invoice, replayed |
| Input | Type | Required | Description |
|---|---|---|---|
planned_invoice_id |
integer | Yes | From list_planned_invoices or get_planned_invoice. |
billing_type |
string | fixed_amount (default on a create): amount_cents is the plan. percentage: the amount follows a percentage of the project budget. One of fixed_amount, percentage. |
|
planned_date |
string | yyyy-mm-dd. | |
amount_cents |
integer | Integer cents, tax exclusive. fixed_amount only. | |
percentage |
number | 0 to 100 of the project’s invoicing budget. percentage only. | |
percentage_of_remaining_budget |
number | More than 0 to 100 of the budget that no other pending planned invoice holds. percentage only, not with percentage. | |
description |
string or null | 255 characters or fewer. null clears it. | |
expected_updated_at |
string | updated_at from your read, unchanged. |