Functional contract
Clinic commissions
Staff earn a commission on the invoice lines they provide. The percent comes from the staff member's commission group on the invoice's issue date, per catalog item. Commissions are calculated when the invoice is issued, reversed by credit notes, and tracked as pending payout, paid out, or voided like tips (no transfers).
Concepts
| Term | Meaning |
|---|---|
| Commission group | CommissionGroup: name, code, description, enabled, and an owner — the Organization, a Location group, or a Location. Holds one rate per catalog item. It may only rate items available in its scope, and its scope cannot change while staff are assigned |
| Rate | CommissionGroupRate: catalog item, percent (0–100), and before_discounts. An item without a rate in one group falls back to the provider's next group; with no rate anywhere it earns nothing. Each group can rate the same item differently |
| Overrides | Group enabled and rate percent / before discounts are overridable per Location and Location group, with lock levels (see below) |
| Membership | StaffCommissionMembership: staff, group, starts_on, ends_on (inclusive, blank = ongoing). At most one group per scope (Organization, each Location group, each Location) on any date; periods in a scope never overlap |
| Commission | InvoiceCommission (Location): one per invoice line and provider, or a negative reversal from a credit note |
| Base | Per rate. Default (after discounts): net − order_discount_share, before tax. before_discounts on: gross |
Calculation (on issue)
Sales::CommissionCalculator.for_invoice! runs inside invoice issue, after the lines are created.
- Only lines with a provider and a catalog item count; the platform fee line never does.
- Candidate groups come from the provider's memberships covering the issue date (Location time zone), limited to groups available at the invoice's Location, ranked most specific first: Location → Location group → Organization.
- Per line item, the first ranked group that is enabled at the Location and rates the item applies (
Commissions::Resolution). A disabled group or one without a rate for the item falls back to the next. - The rate's percent and base resolve at the invoice's Location: lock, Location override, group override, master.
amount = round(base × percent / 100, 2); zero amounts are skipped.- The row stores group, percent, base kind, and base amount, so later edits to groups, rates, or memberships never change it.
Location and group overrides
Commission groups and rates follow the shared inherit-or-override model.
- Overridable: group
enabled; ratepercentandbefore_discounts. - Locks:
lock_enabled,lock_percent,lock_before_discounts—none,locations(“Only location groups can override”), oreverywhere. A group row may also lock a field for its own Locations. - Scope: only records owned above the override's scope, and rates only where the item is granted.
- Disabled is a hard off: a disabled group never applies, even where an override says enabled.
- Override or scoped group? Override when the same group pays a different percent at a site; create a Location- or group-owned group when the site has its own scheme. The group's override drawer offers both.
- Screens: summary line per group and rate with Change (override drawer), plus an All sites tab (Editing overrides).
Commission lookup
Staff record → Commission lookup: pick an item and a Location to see, for today, each ranked group's outcome (applies, skipped because disabled, skipped for no rate, not reached), the resulting percent and base, a Fallback badge when a more specific group was skipped, and the rate's source badges and level trails. It uses the same Commissions::Resolution as the calculation.
Credit notes
Issuing a credit note runs Sales::CommissionReversal, which creates negative, pending rows linked to the original commission and the credit note.
- Line from the invoice: each commission on that line is reversed by
amount × credited qty / invoice qty. The last creditable quantity takes the exact remainder: $10.00 on 3 units credited one at a time → −$3.33, −$3.33, −$3.34. - New lines (not tied to an invoice line):
ratio = their pre-tax amount / invoice pre-tax base(platform fee excluded, capped at 1). Every commission on the invoice is reversed byamount × ratio; rounding drift goes to the largest. $15.00 and $2.50 on a $200 invoice with a $50 goodwill credit → −$3.75 and −$0.63. - A commission is never reversed below zero.
Memberships
Settings → Staff → edit → Commission group: current group per scope, a change form (scope, group, effective date, default today), and the period history with who made each change.
- Changing the group closes the latest period in that scope the day before the new start and opens a new one. "No commission group" only closes that scope's period.
- The new start must be after the latest period's start. Existing commissions are not recalculated.
- Only enabled groups can be assigned. Disabling a group keeps its memberships and commissions.
commissiongroups.manageassigns groups in any scope; a Location group administrator (locationgroups.manage) only assigns groups owned by their Location group.
Payout status
| From | To |
|---|---|
| Pending payout | Paid out, Voided |
| Paid out | Pending payout, Voided |
| Voided | Pending payout |
Set in bulk on the Commissions list with an optional reference or reason. Each change records who and when; restoring to pending clears the stamps. A voided row must go back to pending before it can be paid out. Reversal rows follow the same rules.
Screens
| Screen | Path | What you see |
|---|---|---|
| Settings → Commission groups | /app/commission_groups (list, show, new, edit, delete) | Groups with per-item rates. A Location workspace lists only groups available there. A group with memberships or commissions cannot be deleted; disable it instead |
| Staff record → Commission group | POST /app/staffs/:staff_id/commission_membership | Assign or end a group from a date |
| Clinic → Commissions | GET /app/commissions, PATCH /app/commissions/payout | Filters (status, default Pending payout; staff; From / To on invoice issue date), totals, per-staff summary; rows with issue date, invoice ("Reversed by CN-…"), staff, item, group, base, percent, status, amount; bulk status update |
| Settings → Staff → edit | — | Commissions section per readable Location: pending / paid-out / voided totals, the 10 most recent rows, link to the filtered list |
Permissions
| Role | commissions.read | commissions.manage (payout) | commissiongroups.manage |
|---|---|---|---|
| Organization administrator | Yes | Yes | Yes |
| Location group administrator | Group's Locations | Group's Locations | No (own group's groups via locationgroups.manage) |
| Location administrator | Yes | Yes | No |
| Receptionist | Yes | No | No |
| Veterinarian | No | No | No |
commissions.read / .manage are Location-scoped; commissiongroups.manage is Organization-scoped. Commission groups are readable with commissiongroups.manage or any commissions.read; editable with commissiongroups.manage, or locationgroups.manage for groups owned by that Location group. Plan features commissions and settings.commission_groups are on wherever invoices are (Business + Elite).
For developers
| Concern | Where |
|---|---|
| Models | CommissionGroup, CommissionGroupRate, StaffCommissionMembership, InvoiceCommission, Staff#assign_commission_group! / #ranked_commission_groups_at / #commission_group_on |
| Overrides | Commissions::EffectiveGroup, Commissions::EffectiveRate (on Hierarchy::EffectiveRecord), Commissions::Policy (on Hierarchy::Policy) |
| Calculation | Sales::CommissionCalculator (called by Sales::InvoiceIssuer), Commissions::Resolution (shared with Commission lookup) |
| Credit note reversal | Sales::CommissionReversal (called by CreditNotes::Issuer) |
| Payout | Sales::CommissionPayout |
| Controllers | App::CommissionGroupsController, App::CommissionsController, App::StaffCommissionMembershipsController, App::StaffsController#load_staff_commissions |
| Routes | /app/commission_groups, /app/commissions, /app/commissions/payout, /app/staffs/:staff_id/commission_membership |
Full contract: docs/functional/clinic-commissions.md.
Acceptance
- A $150 consult with a 10% line discount and a 10% after-discounts rate gives a $13.50 commission to the provider.
- The same item earns per each group's percent and base (before vs after discounts).
- A Location-owned group beats a Location group's, which beats the Organization's, for the same staff on the same date; an item the specific group does not rate, or a group disabled there, falls back to the next group.
- A Location rate override changes the percent and base only at that Location; a disabled group earns nothing even with an "enabled" override.
- Changing a group or rate after issue leaves existing commissions unchanged.
- Crediting a line reverses its commissions by quantity; a goodwill credit reverses all commissions by its share of the pre-tax base; never below zero.
- Paid out and voided follow the status table; voided must be restored before paying out.
- Receptionist can view but not change payout status; veterinarian cannot open the Commissions list.
Out of scope: recalculating after back-dated membership, rate, or override changes, commissions on tips or deposits, payroll export, mobile API.
Related: Clinic tips, Billing and finance, Appointment to invoice, RBAC, Staff access.