Functional contract
Billing and finance
Clinic AR: invoices issued from sales orders, record-only payments, deposits, credit notes, a per–Legal Entity client ledger, tips, and commissions are built. Cash-up, live processors, PDF, and reports remain intended. Invoices are hybrid: the legal header comes from the Location’s Legal Entity; the sale is attributed to the Location. For TaskPaws platform subscriptions (plans, credits, Stripe), see SaaS billing.
Invoices
Clinic → Invoices (invoices.*). One invoice per open sales order (1:1); lines and totals are immutable. Do not confuse with Settings → Billing / billing.* / BillingInvoice (SaaS).
- Header: Legal Entity snapshot (legal name, tax ID, currency; fiscal address still intended); number per Legal Entity
INV-000123; bill-to = payer; ship-to = a parent from the order's payer candidates; optional notes frozen at issue. - Lines: frozen copies of the order lines at their snapshotted unit price (including patient group prices for the line's patient), line discount, and share of the order discount. Revenue and providers are attributed to the Location.
- Taxes: each line uses the item's tax group effective at the order's Location and the tax rates effective (inherited from Organization / Location group, or overridden) there on the issue date. A disabled tax or tax group applies nothing. Tax rows snapshot name, code, group, percent, inclusive / compound, base, and amount.
- Preview:
GET /app/checkout/:id/preview_invoiceshows lines, taxes, platform fee, and totals before issue.
Issue (POST /app/checkout/:id/invoice, invoices.manage):
- Lock the open order (rejected if not open, already invoiced, or empty); resolve ship-to and notes.
- Assign the number; create invoice, lines, and taxes; append the platform fee line when the org charges clients (usage credits are spent here).
- Calculate staff commissions.
- Release stock reserved for the order and consume inventory (bundle lines consume their components); mark the order
invoiced. - Post
invoice_issuedto the ledger, save tips, apply linked deposit credit.
Statuses: issued → partially_paid → paid, or credited when credit notes cover the whole total. Historical invoices do not change if the Location later moves to another Legal Entity.
Payments
Record-only collection on issued invoices: multi-tender, partial, optional payor shares, per-tender receipts (RCP-), and audit history. No processor webhooks yet.
- Tenders: cash (stores change due), card, debit, bank transfer, QR, payment link, financing; non-cash may carry an external reference.
- Client credit tender is not a payment: it allocates paid deposit credit (order-linked first, then oldest) and then unallocated payments of the bill-to. No receipt or ledger entry.
- Partial: any amount up to the balance; overpay is rejected.
- Payor shares: must sum to
net_total + tip_total; clients must be payer candidates; locked after the first payment. Multi-payor before invoice uses split at checkout. - Unallocate removes a payment from an invoice (balance due rises, client balance unchanged); the money stays as the payment's open amount.
- Refunds (
RFD-): from the open amount first, else the newest application; own tender (not client credit); can reopen a paid invoice. Never returns SaaS usage credits. A refunded payment cannot be voided. - Void restores invoice and share balances and stamps the receipt voided.
| Concern | Level | Behavior |
|---|---|---|
| Merchant account (e.g. Stripe Connect, intended) | Legal Entity | Locations sharing an entity settle to its bank; a Location with its own entity settles separately |
| Card terminal | Location | Hardware and “which desk took the payment” are site-local |
| Cash / check | Location | Counted in that site’s drawer |
| Payment application | Location + Legal Entity | Applied to that entity’s invoices only; never silently pays another entity’s AR |
Deposits
A Deposit (DEP-000123) is a prepayment request linked to an appointment, visit, and/or sales order. Requesting posts nothing; paying posts payment_received (client goes into credit). Not SaaS CreditAccount.
| Status | Meaning | Blocks check-in |
|---|---|---|
pending | Nothing paid | Yes |
partially_paid | Some paid | Yes |
paid | Fully paid | No |
waived | Staff waived collection (paid part stays credit) | No |
voided | Cancelled; only with nothing paid or applied | No |
- Created automatically when an appointment's type has a deposit (amount, refundable default from the type), or manually from the client, schedule popover, or sales order.
- Collect: same tenders as invoices (no client credit). When the org charges clients the platform fee, it is added to the tender as a surcharge; deposit credit is the pre-fee amount.
- Check-in links live deposits to the visit and its open order; undo check-in clears those links.
- Checkout lists applied and available deposits; staff apply / unapply. Issue applies the bill-to's applied deposits up to the invoice total (allocation only). Merge moves deposits to the target; split keeps them on the original; void unlinks them.
- Refunds only for refundable deposits; applied credit is shrunk newest first and those invoices reopen.
- Cancel / no-show with paid credit: Invoice fee (fee order with "No-show fee" / "Cancellation fee", paid by the deposit), Keep as credit (default), or Refund. Appointments with a live deposit cannot be deleted.
Credit notes
Always tied to one invoice (CN-000001 per Legal Entity; drafts show CN-DRAFT-<id>). Draft is editable and touches nothing; issued is immutable (correct with another credit note). Clinic → Credit notes.
- Invoice lines: up to the remaining creditable quantity; net, order-discount share, and taxes prorate by quantity, the last unit takes the exact remainder. Platform fee lines cannot be credited.
- New lines: description, optional catalog item, price, quantity, optional patient, tax group (default = the item's tax group effective at the invoice's Location), taxed at the rates effective at that Location.
total = Σ(net − order_discount_share) + exclusive taxes; capped atinvoice.total − amount_creditedon save and on issue. Tips are never credited.
On issue: amount_credited rises (so net_total and balance_due = net_total + tip_total − amount_paid drop); ledger credit_note_issued (−total); if now overpaid, newest allocations shrink (payments become open amount, deposits regain available credit); flagged lines restock (batch items to the sold lots, bundles return stocked components); staff commissions are reversed; invoice becomes credited at zero net. Payor shares must still sum to net_total + tip_total.
credited, payment open amount 100. Refund it (balance 0) or use it as client credit later.
Client ledger
One account per client per Legal Entity with a cached balance (negative = in credit). Entries are append-only and post to the bill-to only; who handed the tender is "paid by" metadata. Allocations (payment or deposit to invoice) never post.
| Entry | Amount |
|---|---|
invoice_issued | + invoice total |
credit_note_issued | − credit note total |
payment_received / payment_voided | − / + (amount − platform fee surcharge) |
refund_issued | + refund amount |
tip_added / tip_voided | + / − tip amount |
Shown on the client page (balance due / in favor, running entries, unallocated payments, deposits with credit), invoice show, receipts, and deposits. Multi–Legal Entity balances stay separate.
Tips and commissions
- Clinic tips: non-taxable staff tips entered at issue, at collect, or later; they raise the amount due without touching frozen totals and are never credited.
- Clinic commissions: per-item percent from the provider's commission group, calculated on issue, reversed by credit notes, paid out or voided in bulk.
Permissions
| Role | Invoices / credit notes | Payments / deposits |
|---|---|---|
| Organization administrator | Read, manage | Read, manage |
| Location administrator | Read, manage | Read, manage |
| Receptionist | Read, manage | Read, manage |
| Veterinarian | Read | Read |
invoices.read / .manage cover invoices, credit notes, and the client ledger section; payments.read / .manage cover payments, shares, receipts, refunds, and deposits. Plan feature invoices (Business + Elite, wherever checkout is). SaaS billing.* alone cannot issue clinic invoices. Records at another Location or Organization return 404.
Cross-site balances Intended
If a client owes Location C and presents at Location A:
- Show an alert naming the other Location with the outstanding balance.
- Do not add, net, or auto-collect C’s balance on A’s invoice.
- Collect C’s balance in C’s context (or by an Organization admin using C’s Legal Entity), so money and tax stay on the correct EIN.
Default for v1: always collect in the originating Location’s context, identical for same-EIN and split-EIN groups.
Daily close and reports Intended
Each Location runs its own cash-up (expected vs counted, card totals, discrepancies). Accounting export (QuickBooks, Xero, or file) groups by Legal Entity, with Location as a line dimension.
| Report context | Question it answers |
|---|---|
| Organization | Group performance across every site |
| Legal Entity | Books and tax for one EIN |
| Location | Site profitability: appointments, sales by room, inventory, drawer |
Filters must not leak Locations the User is not granted (Staff access).
Acceptance
- Issuing from an open order creates
INV-000001, freezes totals, discounts, and taxes, and locks the order asinvoiced; empty, closed, or second issue is rejected. - An invoice from Location A shows Legal Entity 1’s EIN; one from Location C shows Legal Entity 2’s.
- Multi-tender collect that sums to the balance marks the invoice
paidwith oneRCP-per tender; partial leavespartially_paid; overpay is rejected. - A pays B's invoice: B's balance drops, A's is unchanged.
- Booking a type with a deposit blocks check-in until paid or waived; issuing applies linked deposit credit.
- Crediting a paid invoice makes the client balance negative; refunding the released payment returns it to zero.
- Receptionist can issue and collect; veterinarian can only read.
- Intended Location A’s daily close excludes Location B’s cash; a Legal Entity export contains only its Locations; checkout at A with an unpaid invoice at C alerts without pulling C’s balance.
Out of scope: processor onboarding (Stripe Connect / Terminal), live payment links, financing, invoice and statement PDF, invoice void and post-issue line edits, tax-engine choice, payment plans, chart of accounts, mobile API. Full contracts: docs/functional/billing-and-finance.md, clinic-invoices.md, clinic-payments.md, clinic-deposits.md, clinic-credit-notes.md, clinic-client-ledger.md.
Related: Appointment to invoice, Clinic tips, Clinic commissions, SaaS billing, Inventory.