Booking — Data & external links
A database view and the external concepts Booking references. Convention: 📖 READ, ✏️ WRITE (insert/update).
Related external concepts
Booking does not own these — it links to them.
| Concept | What | Role in Booking | Owning domain |
|---|---|---|---|
| Term / TermProduct | Term & its products/sessions. | Source of available sessions, capacity, price. | Program/Term |
| Subscription / Enrollment | Long-term package and enrollment runtime. | Subscription Booking provides the pattern/schedule; the Enrichment charge remains owned by Booking. | Subscription |
| TermProgramSet | Group of products/courses. | Unit for applying discounts & grouping lines. | Program |
| ProgramCategory | Program grouping. | Holds CombinedBookingOptionId, DiscountRuleType. | Program |
| ActionLog | A record of one action. | ActionLogId groups bookings for combined edit. | Platform |
| Account / Attendee | Parent / child. | Target account & attendee of the booking. | Account |
| Billing | A booking's financial ledger. | Submit creates Billing; attaches invoices. | Finance/Billing |
| Invoice / CreditNote | Invoice & credit note. | Confirm generates invoices; cancel → credit note. | Finance/Billing |
| TermAttendance | Session roll call. | Confirm creates; cancel/remove → deactivate. | Attendance |
| Discount | Discount rule. | Auto-applied during pricing (see Discount rule). | Discount |
📌 Domains outside the wiki scope (Finance/Xero, detailed discount pricing) see Documentation scope.
Data tables — grouped by aggregate
| Aggregate | Main tables | Purpose |
|---|---|---|
| TermBookingOrder (request) | TermBookingOrder | Booking request: account, type, status, ActionLogId. |
TermBookingOrderLine | Session rows (date/time/product/price, discount slots). | |
TermBookingOrderExtra | Order-level add-ons. | |
TermBookingOrderDiscount | Order-level applied discounts. | |
| TermBooking (confirmed) | TermBooking | Confirmed booking: status, ProgramCategoryId, LockTypeId. |
TermBookingLine / TermBookingExtra / TermBookingDiscount | Confirmed session / add-on / discount rows. | |
| Discount | Discount, TermProgramSetDiscount, ProfileDiscount | Definition & apply config. |
DiscountApplication, DiscountApplicationAllocation | Records & allocates discount. |
Data tables per flow
Flow 1 — Create order
| Action | Tables | Purpose |
|---|---|---|
| Get sessions/capacity | TermProduct, TermProgramSetCapacity 📖 READ | Available sessions + capacity. |
| Create order | TermBookingOrder, TermBookingOrderLine ✏️ WRITE | Cart (status Created). |
Flow 2 — Submit
| Action | Tables | Purpose |
|---|---|---|
| Apply discounts | TermProgramSetDiscount, Discount 📖 READ; TermBookingOrderDiscount ✏️ WRITE | Automatic discounts. |
| Overlap guard | TermBookingOrder, TermBooking 📖 READ | Conflict check (excludes Subscription/WaitingList). |
| Create finance | Billing ✏️ WRITE | The order's financial ledger. |
Flow 3 — Billing Difference preview
| Action | Tables / data | Purpose |
|---|---|---|
| Build projection | TermBookingOrder, TermBooking, Billing, Invoice, CreditNote, Discount, settings 📖 READ | Calculate projected financial state from current data. |
| Return preview | BillingDifferencePreviewModel 📖 READ | Return transaction collections, Summary, AttendeeBreakdowns, DebugInfo and PreviewSnapshotToken; write no tables. |
Summary.Difference is backend-calculated as new invoices − new credit notes − scheduled-delete invoices. Preview also returns current billing-record totals: Summary.TotalOriginalAmountPaid (the sum of Invoice.AmountPaid) and Summary.TotalOriginalAmountDue (the sum of Invoice.AmountDue). These fields describe the current state, not paid/due projected after the edit, and must not be divided across attendees. Projected transaction numbers are opaque display codes such as INV-PRV-2642, not real invoices and not freshness checks.
The UI decision summary uses the same source:
| Display | Formula / source |
|---|---|
Current net billed | Summary.TotalOriginalAmount |
Paid to date | Summary.TotalOriginalAmountPaid |
Open invoice balance | Summary.TotalOriginalAmountDue (before credits) |
Projected net billed | Current net billed + Summary.Difference |
Net billing change | Summary.Difference |
These are whole-billing-record totals; the transaction list and attendee breakdown are secondary details, hidden by default and opened with a text control.
AttendeeBreakdowns is an allocation from the same billing calculation as Summary, not an independent billing calculation per attendee. Each attendee belonging to a submitted order gets one row; activity from another booking group sharing the same BillingId goes into Other booking groups (IsOutsideSelectedScope = true), while uncertain attribution goes into Shared / Unallocated (IsShared = true). The rows must add up to the corresponding totals in Summary; Other booking groups is not counted in the selected-attendee count.
Key fields for each breakdown row:
| Field | Meaning |
|---|---|
AttendeeId, AttendeeName | Attendee identity; a grouped row may not have an AttendeeId. |
IsShared | true when the row is Shared / Unallocated. |
IsOutsideSelectedScope | true when the row is Other booking groups. |
TotalOriginalAmount | Persisted current net amount. |
TotalNewAmount | Total projected new invoices. |
TotalCreditNoteAmount | Projected new credit notes, stored as a positive magnitude. |
TotalScheduledToDeleteAmount | Generated invoices to deactivate, stored as a positive magnitude. |
Difference | TotalNewAmount − TotalCreditNoteAmount − TotalScheduledToDeleteAmount. |
ScheduledToDeleteCount, NewInvoiceCount, NewCreditNoteCount | Counts of the corresponding work items in the row. |
Flow 3b — Booking Manager bulk Confirm
| Action | Tables / data | Purpose |
|---|---|---|
| Queue new bookings | TermBookingOrder, BookingScheduler ✏️ WRITE | Queue bulk Confirm_Booking as in the existing flow. |
| Edit/mixed guard | TermBookingOrder 📖 READ | Reject the entire batch before locks/schedulers with PREVIEW_BILLING_DIFF_BATCH_EDIT_NOT_SUPPORTED. |
| Queue attendance | TermBookingOrder, BookingScheduler ✏️ WRITE | Keep bulk Confirm_Attendance; it does not go through Billing Difference. |
Flow 4 — Confirm / Quote
| Action | Tables | Purpose |
|---|---|---|
| Create booking | TermBooking, TermBookingLine/Extra/Discount ✏️ WRITE | Copied from the order. |
| Roll call | TermAttendance ✏️ WRITE | One record per session. |
| Keep roll call on edit | TermAttendance, RollCallHistory ✏️ WRITE | Replacing attendance still copies the old roll call (invariant INV-BOOK-27). |
| Invoice | Invoice, InvoiceLine ✏️ WRITE (via Finance) | Generated on confirm. |
| Allocate discount | DiscountApplication, DiscountApplicationAllocation ✏️ WRITE | Billing audit. |
Flow 4b — Subscription Enrichment generation
| Action | Tables | Purpose |
|---|---|---|
| Resolve occurrence | Subscription, EnrollmentPattern, TermProduct, schedule 📖 READ | Determine date, scope, authoritative rate, and accounting item. |
| Create charge | TermBooking, TermBookingLine, TermAttendance ✏️ WRITE | One active line + attendance for each TermBookingId + TermProductId + Date. |
| Booking reconciliation | Billing, Invoice, InvoiceLine, TermBookingInvoiceLog ✏️ WRITE | Invoice the Booking line under the correct owner; retries do not duplicate it. |
| Subscription Billing exclusion | EnrollmentBillingSchedule, SubscriptionTermBillingSchedule, EnrollmentInvoiceLog 📖 READ | Do not take the amount from the Enrichment Booking line. |
Flow 5 — Cancel
| Action | Tables | Purpose |
|---|---|---|
| Cancel booking | TermBooking ✏️ UPDATE (→ Canceled) | Cancelled state. |
| Reverse invoice | CreditNote ✏️ WRITE | Credit note for issued invoices. |
| Remove roll call | TermAttendance ✏️ UPDATE (IsActive=false) | Deactivate (even lines that left Approved). |
Flow 6 — Booking Reconciliation
| Action | Tables | Purpose |
|---|---|---|
| Read candidates | TermAttendance, BookingReconciliationRule 📖 READ | Attendance Unreconciled and signed out + fee/refund rules. |
| Ignore | TermAttendance ✏️ UPDATE (ReconciliationStatusId=Ignored) | Skip without generating documents. |
| Generate fee/refund | Invoice/CreditNote, InvoiceLine/CreditNoteLine ✏️ WRITE | TypeId BookingReconciliation (3), per split rule. |
| Update attendance | TermAttendance ✏️ UPDATE (ReconciliationStatusId=Invoiced/Credited, ReconciliationAmount) | Mark as processed. |
| Link booking | TermBookingInvoiceLog / TermBookingCreditNoteLog ✏️ WRITE | Resolve Booking ID on FinanceTransaction. |
| Scheduler | InvoiceScheduler / CreditNoteScheduler, EntityEventScheduler ✏️ WRITE | Send mail/sync, refresh booking numbers. |
Flow 7 — Manage Enrichments
| Action | Tables | Purpose |
|---|---|---|
| Load state | TermBookingLine, TermProduct, invoice/credit/attendance/lock 📖 READ | Show selected, amount, editable, and lock reason. |
| Save selection | TermBookingLine, TermAttendance ✏️ WRITE | Atomically add/deactivate future unlocked occurrences. |
| Refresh totals | TermBooking ✏️ UPDATE; Booking Billing service | Recalculate the Booking total; do not write Invoice/CreditNote directly from the popup. |
Schema references
docs/DB_SCHEMA_DESIGN/AZURE_SQL_GLOSSARY.md— term → table.docs/ONBOARD/flows/booking.md— booking flow with READ/WRITE tables.- Related: Architecture & data, Discount rule, Booking Reconciliation.