
Training invoicing and purchase orders for B2B training: system design
Training invoicing works for corporate buyers when every invoice is a frozen document tied to a booking, a purchase order (PO) and agreed terms. Model the PO as a spending limit, issue invoices only against what is left, fix mistakes with credit notes, and sync finished documents to accounting from a queue.
Card checkout ends with a receipt. A corporate booking ends when the buyer’s accounts payable team pays, often weeks later, and only if the invoice carries the right PO number. This post covers that billing side. The seat hold, payment states and webhooks are in our registration workflow and payment state machine article, so we do not repeat them.
Key takeaways
- Capture the PO at booking and treat it as a limit with a number, currency, validity dates and a status.
- Store five invoice states and derive overdue and part-paid from dates and payment allocations.
- Never edit an issued invoice. Use a credit note that names the original, or a replacement invoice.
- Copy buyer details, tax values and terms onto the invoice at issue.
- Send documents to accounting through an outbox with idempotency keys, so an outage never blocks a booking.
Which records does a training invoicing data model need?
You need seven kinds of record: buyer account, bill-to contact, purchase order, booking line, invoice with lines, credit note, and payment with allocations. Dunning events and sync records support the automation. Booking lines hang off the enrollments in your TMS data model.
| Record | Holds | Rule that matters |
|---|---|---|
| Buyer account | Legal name, tax ID, default terms, “PO required” flag | Behavior is a setting, not a code branch |
| Bill-to contact | Accounts payable email, address, e-invoice address | Never the delegate or booker by default |
| Purchase order | Number, currency, net limit, validity dates, status | Unique per account; a budget envelope |
| Booking line | Seat, price at booking, PO reference | Price copied at booking, not read live |
| Invoice and lines | Number, status, dates, net and tax totals | Frozen once issued |
| Credit note | Original invoice, reason, amounts | Always names the invoice it amends |
| Payment and allocation | Amount, date, reference, split by invoice | One payment can settle several invoices |
Store money as exact decimals with a currency on every document, and never convert silently between currencies.
How should you capture, validate and match a purchase order?
Capture the PO at booking, not at invoice time, as a spending limit with a number, currency, validity dates and an open or closed status. At issue, run a two-way match: same account and currency, PO open and in date, and invoice net no larger than what remains.
Buyers publish what they reject. One university purchasing office lists “missing PO number,” “invalid PO number (closed or not in system)” and “multiple invoices in a single file attachment” among its rejected invoice reasons (page last modified June 2026). Each is preventable in your data. Buyers often book before procurement raises the PO, so allow “PO pending” with a chase date and block only the invoice.
Pro tip: Put the PO number on the booking. If the PO lives only on the invoice, a regenerated or split invoice can lose it. Carry it on every booking line and let the invoice copy it, so bookings under different POs can never merge into one document.
Remaining balance is the limit minus issued invoices plus credit notes. Lock the PO row while issuing, so two invoices cannot both claim the last of it. This schema is our own design, not a standard. It compares net amounts, so add a flag if your buyers state limits including tax. Drafts do not reserve balance. The accounts table (with name, vat_id, terms_days and po_required) and a one-row-per-series number_series counter are omitted here.
CREATE TABLE purchase_orders (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
account_id bigint NOT NULL REFERENCES accounts,
po_number text NOT NULL, currency char(3) NOT NULL,
net_limit numeric(12,2) NOT NULL CHECK (net_limit > 0),
valid_from date NOT NULL, valid_to date NOT NULL,
status text NOT NULL DEFAULT 'open' CHECK (status IN ('open','closed')),
UNIQUE (account_id, po_number), CHECK (valid_to >= valid_from)
);
CREATE TABLE invoices (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
account_id bigint NOT NULL REFERENCES accounts,
po_id bigint REFERENCES purchase_orders,
invoice_number text UNIQUE, -- NULL while draft
status text NOT NULL DEFAULT 'draft'
CHECK (status IN ('draft','issued','paid','void','written_off')),
currency char(3) NOT NULL,
issue_date date, due_date date,
buyer_vat_id text, -- snapshot taken at issue
net_total numeric(12,2) NOT NULL DEFAULT 0,
tax_total numeric(12,2) NOT NULL DEFAULT 0,
CHECK (status = 'draft' OR (invoice_number IS NOT NULL
AND issue_date IS NOT NULL AND due_date IS NOT NULL))
);
CREATE TABLE credit_notes (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
invoice_id bigint NOT NULL REFERENCES invoices, -- names the original
credit_number text NOT NULL UNIQUE, reason text NOT NULL,
net_total numeric(12,2) NOT NULL CHECK (net_total > 0),
tax_total numeric(12,2) NOT NULL DEFAULT 0
);
-- Net amount still available on each PO
CREATE VIEW po_balance AS
SELECT po.id AS po_id, po.po_number, po.net_limit,
po.net_limit
- COALESCE(SUM(i.net_total) FILTER (WHERE i.status IN ('issued','paid','written_off')), 0)
+ COALESCE(SUM(cn.credited) FILTER (WHERE i.status IN ('issued','paid','written_off')), 0)
AS net_remaining
FROM purchase_orders po
LEFT JOIN invoices i ON i.po_id = po.id
LEFT JOIN (SELECT invoice_id, SUM(net_total) AS credited
FROM credit_notes GROUP BY invoice_id) cn ON cn.invoice_id = i.id
GROUP BY po.id;
CREATE FUNCTION issue_invoice(p_invoice bigint) RETURNS text
LANGUAGE plpgsql AS $$
DECLARE
inv invoices%ROWTYPE; acct accounts%ROWTYPE; p purchase_orders%ROWTYPE;
po po_balance%ROWTYPE; n int;
BEGIN
SELECT * INTO inv FROM invoices WHERE id = p_invoice FOR UPDATE;
IF inv.status <> 'draft' THEN
RAISE EXCEPTION 'invoice % is %, only drafts can be issued', p_invoice, inv.status;
END IF;
SELECT * INTO acct FROM accounts WHERE id = inv.account_id;
IF acct.po_required AND inv.po_id IS NULL THEN
RAISE EXCEPTION 'account % requires a PO on every invoice', acct.name;
END IF;
IF inv.po_id IS NOT NULL THEN
SELECT * INTO p FROM purchase_orders WHERE id = inv.po_id FOR UPDATE; -- one invoice at a time per PO
IF p.account_id <> inv.account_id OR p.currency <> inv.currency OR p.status <> 'open'
OR current_date NOT BETWEEN p.valid_from AND p.valid_to THEN
RAISE EXCEPTION 'PO % cannot take this invoice (account, currency, status or dates)', p.po_number;
END IF;
SELECT * INTO po FROM po_balance WHERE po_id = inv.po_id;
IF po.net_remaining < inv.net_total THEN
RAISE EXCEPTION 'PO % has % left, invoice needs %', po.po_number, po.net_remaining, inv.net_total;
END IF;
END IF;
UPDATE number_series SET last_no = last_no + 1 WHERE series = 'INV' RETURNING last_no INTO n;
UPDATE invoices
SET status = 'issued', invoice_number = 'INV-' || lpad(n::text, 6, '0'),
issue_date = current_date, due_date = current_date + acct.terms_days,
buyer_vat_id = acct.vat_id
WHERE id = p_invoice;
RETURN 'INV-' || lpad(n::text, 6, '0');
END $$;
We ran both scripts on PostgreSQL 16.15 with illustrative amounts. An 1,800 invoice issued against a 3,000 PO, and a second for 1,500 was refused with 1,200 left. A 600 credit note lifted the balance to 1,800, and the second then issued. Closed, expired and wrong-currency POs were refused. In a race for a 1,000 PO, the second session waited, then was refused.
Which invoice states does a training business need?
Five stored states cover most B2B training: draft, issued, paid, void and written off. Overdue and part-paid are derived from the due date and payment allocations, never stored. Once issued, an invoice is frozen, and changes go through a credit note or a replacement invoice.
| State | Meaning | Editable? | Leaves by |
|---|---|---|---|
| Draft | Assembled from bookings, no number | Yes | Issue or delete |
| Issued | Numbered, sent, awaiting payment | No | Payment, void, write-off |
| Paid | Allocations cover the total | No | Payment reversal only |
| Void | Cancelled, number kept for the audit trail | No | Nothing |
| Written off | Judged unlikely to be paid | No | Payment or void |
This mirrors Stripe’s invoice lifecycle: draft, open, paid, void and uncollectible. Stripe’s documentation says most details of a finalized invoice can no longer be changed, and that a voided invoice keeps a paper trail and counts as zero-value in reporting. It also shows “Past due” as a dashboard label on an open invoice, not a status.
Find overdue invoices with status = 'issued' AND due_date < current_date. In our test, an invoice whose due date we moved 12 days back came back as 12 days overdue, with no extra state.
How do credit notes handle cancellations and substitutions?
A credit note reduces what a buyer owes without rewriting the original invoice. Issue one for cancellations, sessions you cancel and price corrections. A delegate substitution needs none, because only a name changes on the booking. Every credit note must name the invoice it amends.
| Situation | Document | PO balance |
|---|---|---|
| Cancellation before cut-off, unpaid | Credit note for the seat price | Restored |
| Late cancellation with a fee | Credit note for price minus fee | Partly restored |
| Colleague replaces delegate | None; edit the booking | Unchanged |
| You cancel the session, paid | Credit note, then refund or account credit | Restored |
| Wrong price after issue | Credit note, plus new invoice if needed | Adjusted |
Stripe describes the same split: a credit note on an open invoice reduces the amount due, and on a paid invoice the credit can be refunded, held as customer balance or handled outside the system. Fee rules are commercial terms; the system just applies them consistently.
Which tax fields does training invoicing need to store on every invoice?
Store what the invoice must show, as values frozen at issue: both parties’ names and addresses, the buyer’s tax ID, line descriptions and quantities, tax-exclusive unit prices, the rate and amount by rate, and any exemption or reverse-charge wording. Finance or a tax engine picks the rates; the database records the result.
The European Commission’s VAT invoicing page, read in November 2026, lists these for a full invoice: date of issue, a unique sequential number, supplier and customer details, the customer’s VAT ID where the customer owes the tax, description and quantity, unit price excluding tax, the transaction or payment date if different, and the VAT rate and amount with a breakdown by rate or exemption. It adds case-specific wording such as “reverse charge.” For documents that amend a simplified invoice it asks for a reference to the original, so store one on every credit note.
On numbering, the same page asks for a unique sequential number. In our test, a rolled-back nextval() call on a PostgreSQL sequence was not reused, so a number was skipped. The counter table above reissued the number after a rollback. Whether you need gapless numbers is a question for finance. The counter is the safe default and only serializes issuing within one series.
E-invoicing is moving. The Commission says electronic invoices equal paper ones subject to the recipient’s acceptance, and that public bodies must accept structured e-invoices. Its VAT in the Digital Age page says the package was adopted on 11 March 2025 and entered into force on 14 April 2025, that digital reporting requirements affect cross-border B2B from 1 July 2030, and that Member States may introduce mandatory e-invoicing under specific conditions. Keep invoice lines as structured data and treat the PDF as one rendering. This is system design, not tax advice, so have finance check the field list for every country you sell in.
Pro tip: Snapshot, do not join. Copy the buyer’s legal name, address, tax ID, tax rates and payment terms onto the invoice at issue. If the CRM record changes next year, a reprint of an old invoice must still match the document the buyer received and your accountant booked.
How should payment terms and dunning work for corporate accounts?
Keep terms on the buyer account, copy the resulting due date onto each invoice at issue, and let a PO or contract override it. Dunning is then a schedule of reminders keyed to that due date, sent to the bill-to contact and paused while a dispute or PO problem is open.
Decide in writing whether the clock starts at the invoice date or at the buyer’s approval, because the two give different due dates. Decide when you invoice too: at booking, which starts the clock early but creates credit notes on cancellation, or after delivery, which delays cash while a PO may expire. Make it a per-account policy. Late-payment interest rules vary by country, so ask finance first.
Store dunning as data, one row per invoice and step, so each reminder goes out once. This cadence is illustrative; tune it with finance. Offsets are relative to the due date:
- Minus 3 days: a courtesy note with invoice number, PO number and payment details.
- Plus 7 days: a reminder to accounts payable, copying the booker.
- Plus 21 days: an escalation task for the account manager.
- Plus 35 days: a human decision on credit hold, write-off or collection.
Stop all steps when allocations cover the invoice, pause them when a dispute flag is set, and never send reminders to delegates.
How do you sync invoices to the accounting system safely?
Treat the accounting system as the ledger and your platform as the source of bookings and invoice documents. Write each issued invoice, credit note and payment to an outbox table, send it from a worker with an idempotency key, and pull payment status back. An outage should delay sync, never block a booking.
Give each document a sync record with a target system, external ID and a status such as pending, sent, confirmed or failed. Sync only frozen documents, and send a credit note with the external ID of its invoice. Make the key stable per document and version, so a retry after a timeout cannot duplicate it.
Pick one numbering authority, and have the other system accept it. Then run a nightly reconciliation of counts and totals per day on both sides, and list mismatches for a person to review.
What should you do next?
Sketch the records against your current system, then write the tests first: an invoice over the PO limit, a credit note restoring balance, two invoices racing for one PO, a rolled-back issue, and a retried sync.
Then ask finance three questions: which countries need which tax fields, whether numbering must be gapless, and who owns the ledger. If you would rather buy than build, SimpliTrain’s payment gateway and invoicing page says it supports invoice and purchase order based payment workflows for corporate clients, with an exportable transaction log. It does not state tax handling, credit notes or accounting sync, so raise those in a demo request.
Frequently asked questions
What is a purchase order in B2B training?
A purchase order is the buyer’s formal commitment to spend a stated amount with you, issued before the work and identified by a number. In a training system it works as a budget envelope: invoices draw it down, credit notes restore it, and the number appears on every related invoice.
Is a purchase order the same as an invoice?
No. The buyer issues the purchase order to authorize spending, and you issue the invoice to request payment. One PO can cover several invoices, such as separate sessions or staged billing, so it needs its own record with a remaining balance.
Can you invoice before the training takes place?
Often yes. Invoicing at booking confirms the seat and starts the payment clock early, at the cost of more credit notes when delegates cancel. Tax timing rules differ by country, so ask finance when the tax point falls before you invoice in advance.
When should you issue a credit note instead of voiding an invoice?
Use a credit note when the original invoice was valid but the amount owed has changed, such as after a cancellation. Voiding fits an invoice that should never have existed. Stripe’s documentation advises checking local rules on amending or voiding invoices.
Do I need e-invoicing for B2B training invoices?
It depends on the buyer’s country and whether the buyer is a public body. The European Commission says electronic invoices are allowed subject to the recipient’s acceptance, and that public bodies must accept structured e-invoices. Confirm each country with finance.
