@composable-os/pack-bookings 0.1.0-beta.10 → 0.1.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- // Bookings (stage 31a, build step 3: the spine; ADR 0504): a gym's or studio's timetable and the
1
+ // Bookings (stage 31a; ADRs 0504, 0520 and 0553): a gym's or studio's timetable and the
2
2
  // bookings members make on it. Staff set a weekly timetable once (series), the host makes each
3
3
  // week's classes from it, and members book and cancel them on the web and in the app.
4
4
  //
5
5
  // Everything that is a rule is the host's, declared here as behaviours (ADR 0404):
6
6
  // - a series makes its classes ahead in local time across clock changes (`recurring`, ADR 0500),
7
7
  // never less far ahead than the longest booking window a class type sets (`horizonAtLeast`),
8
- // never on a closure's dates, and never over a class staff changed by hand;
8
+ // never on a closure's dates, and never over what staff changed by hand on a class (a coach
9
+ // swapped stays swapped while the series' new room or time still reaches it, ADR 0620);
9
10
  // - a class has places (`capacity`), and a booking holds one by its state (`claims`, ADR 0501),
10
11
  // refused by the database past the places, for every actor;
11
12
  // - one live booking per Person per class (`unique`, ADR 0502);
@@ -18,10 +19,53 @@
18
19
  // - a booking entering `booked` spends a use of its Person's membership or pass and an in-time
19
20
  // cancel gives it back (`allowance`, ADRs 0493 and 0494), unless staff booked it paid at the
20
21
  // desk (`waived`, ADR 0506). The holders are the Memberships pack's (stage 32b);
21
- // - members read the timetable and how many places are left, never who is booked (decision 13).
22
- // The tools in tools.ts compose the host's operations and add no rules of their own.
22
+ // - a member joins a full class's waitlist, spending nothing; a place given back before the
23
+ // class type's "waitlist stops" time goes to the waitlist in the same batch, and the host
24
+ // moves the first waiter in, spending their use then, or passes them over when nothing they
25
+ // hold can pay (`claims.waitlist`, ADR 0520; step 5);
26
+ // - a visitor, or a member with nothing to spend, pays for one class on the web (a drop-in,
27
+ // decision 8): the host makes the booking held while its order is unpaid, priced from the
28
+ // class type's drop-in price or the organisation's, booked when the payment is verified and
29
+ // released when the order expires; a paid drop-in cancelled in time or by the gym owes the
30
+ // money back, which a person approves (`sellable.moves`, ADR 0560; step 8);
31
+ // - members read the timetable and how many places are left, never who is booked (decision 13);
32
+ // - a coach ticks names from an hour before the class (a window that binds staff, ADR 0551);
33
+ // of two ticks at once one is made (ADR 0437); 30 minutes after a class ends, the host makes
34
+ // its still-booked bookings no-shows, only if someone on it was ticked (`states.after`,
35
+ // ADR 0550). A no-show keeps its use;
36
+ // - staff move a booking to another class by making the new one (`movedFrom`): the old one is
37
+ // moved, its place given back and its use spent again on the new one, in one batch, refused
38
+ // whole when the new class is full or the use cannot be spent (ADRs 0493 and 0551);
39
+ // - staff cancel a class (a person's act, or a person approves an AI's request, ADR 0552), and
40
+ // every booked, waiting and held booking of it is cancelled in the same batch (ADR 0507);
41
+ // - the coach role (`roles`, ADR 0436): the day's classes, their lists, and ticking names;
42
+ // - a class is its coach's shift (`staffed`, stage 45, ADR 0621): one staff account is never
43
+ // on two overlapping shifts, refused by the database for every writer, and a write of a
44
+ // class answers its warnings (the coach away or not qualified, a class with no coach).
45
+ // - a class takes its room while it is on, when the room takes one booking at a time
46
+ // (`occupies`, stage 49, ADR 0765): a second class in it at an overlapping time is refused by
47
+ // the database for every writer; a series' date that would clash is made with no room.
48
+ // - appointments (stage 49 step 5, ADR 0764): one-to-one sessions of a service with a coach,
49
+ // booked by staff for a client. An appointment is its coach's shift (`staffed`), so a coach is
50
+ // never on a class, a duty and an appointment at once, the service's buffer kept free around
51
+ // it (claim margins, ADR 0760), and it must have a coach with a staff account (ADR 0760). It
52
+ // takes a private room the service needs (`occupies`, ADR 0765): the first free one, chosen
53
+ // by the host when staff name none. Its client is kept off the roster and the feed (ADR 0761).
54
+ // Booked, it spends a use of a pass or membership that covers the service, unless staff mark
55
+ // it paid at the desk (`allowance`, `waived`, ADR 0506); a cancel before the service's "late
56
+ // from" gives it back; a late cancel and a no-show keep it, with no fee (decision 1), until a
57
+ // person excuses it. 30 minutes after it ends, the host marks one nobody marked as attended.
58
+ // The tools in tools.ts compose the host's operations and add no rules of their own. The messages
59
+ // in automations.ts (step 9, ADR 0572) email members and their guardians through the email-send
60
+ // gatekeeper on what the host did: booked, moved in, passed over, a place free after the cut-off,
61
+ // a class changed or cancelled by the gym, the reminder before a class (a date-relative trigger
62
+ // in minutes, ADR 0570) with an add-to-calendar file (ADR 0571), a drop-in's refund made; and
63
+ // tell staff of a class whose list was not taken. They write nothing.
23
64
  import { defineExtension } from "@composable-os/sdk";
24
- import { book, bookFor, cancel, cancelFor, classGet, classList, day, findPeople, mine, returnUse, timetable, } from "./tools.js";
65
+ import { bookingsAutomations } from "./automations.js";
66
+ import { bookingsDashboards } from "./dashboards.js";
67
+ import { bookingsRoutineMail } from "./routine-mail.js";
68
+ import { book, bookAppointment, bookFor, buy, cancel, cancelAppointment, cancelAppointmentByUs, cancelClass, cancelFor, classGet, classList, coachDay, day, excuseAppointment, family, findPeople, leaveWaitlist, markAll, markAppointment, markAttended, markNoShow, mine, move, moveAppointment, reassignAppointment, returnUse, roster, timetable, undoAttended, } from "./tools.js";
25
69
  /** Weekday values a series' `weekdays` uses (ADR 0500). */
26
70
  const WEEKDAYS = [
27
71
  { value: "mon", label: "Monday" },
@@ -32,7 +76,7 @@ const WEEKDAYS = [
32
76
  { value: "sat", label: "Saturday" },
33
77
  { value: "sun", label: "Sunday" },
34
78
  ];
35
- /** A booking's states (spec 31, "Booking states"). Only some are reachable at this step. */
79
+ /** A booking's states (spec 31, "Booking states"). */
36
80
  const BOOKING_STATES = [
37
81
  { value: "booked", label: "Booked" },
38
82
  { value: "pending", label: "Held while paying" },
@@ -47,7 +91,9 @@ const BOOKING_STATES = [
47
91
  { value: "moved", label: "Moved" },
48
92
  { value: "expired", label: "Expired" },
49
93
  ];
50
- /** A booking that holds or takes a place, and so counts as the Person's one for its class. */
94
+ /** Cancelled with a class the gym cancels: each booking holding a place or a use, or waiting. */
95
+ const FOLLOW_CANCEL = ["booked", "waiting", "pending", "attended", "no_show", "late_cancelled"];
96
+ /** A booking that holds or waits for a place, and so counts as the Person's one for its class. */
51
97
  const ACTIVE = ["pending", "booked", "waiting", "attended", "no_show"];
52
98
  /** When a customer may book, and when a cancel is late, from the class type or the org. */
53
99
  const opens = {
@@ -63,6 +109,57 @@ const lateFrom = {
63
109
  at: "class.startsAt",
64
110
  minutesBefore: { field: "class.classType.lateMinutes", setting: "lateMinutes" },
65
111
  };
112
+ /** A class's list opens for ticking an hour before it starts (guess: people arrive early). */
113
+ const listOpens = { at: "class.startsAt", minutesBefore: 60 };
114
+ /** An appointment's states (stage 49, "Appointment states"). */
115
+ const APPOINTMENT_STATES = [
116
+ { value: "booked", label: "Booked" },
117
+ { value: "pending", label: "Held while paying" },
118
+ { value: "unpaid", label: "Not paid yet" },
119
+ { value: "cancelled", label: "Cancelled" },
120
+ { value: "late_cancelled", label: "Cancelled late" },
121
+ { value: "excused", label: "Cancelled, session given back" },
122
+ { value: "attended", label: "Attended" },
123
+ { value: "no_show", label: "No-show" },
124
+ { value: "cancelled_by_us", label: "Cancelled by the business" },
125
+ { value: "moved", label: "Moved" },
126
+ { value: "expired", label: "Expired" },
127
+ ];
128
+ /**
129
+ * An appointment takes its coach's time and its room in these states: held while paying, not paid
130
+ * yet, booked, and after it (a coach who waited for a no-show was there, and pay counts it).
131
+ */
132
+ const APPOINTMENT_LIVE = ["pending", "unpaid", "booked", "attended", "no_show"];
133
+ /** When a customer may book an appointment, and when a cancel is late, from the service or org. */
134
+ const appointmentOpens = {
135
+ at: "startsAt",
136
+ daysBefore: { field: "service.opensDays", setting: "appointmentOpensDays" },
137
+ zone: "timezone",
138
+ };
139
+ const appointmentCloses = {
140
+ at: "startsAt",
141
+ minutesBefore: { field: "service.closesMinutes", setting: "appointmentClosesMinutes" },
142
+ };
143
+ // Counted from the appointment's anchor (ADR 0764): its own start, or, once moved, the start of the
144
+ // one it replaced, so a move never makes a late cancel in time again.
145
+ const appointmentLateFrom = {
146
+ at: "lateAnchor",
147
+ minutesBefore: { field: "service.lateMinutes", setting: "appointmentLateMinutes" },
148
+ };
149
+ /** Attended and no-show may be corrected, one into the other, for 7 days after the end. */
150
+ const correctable = { at: "endsAt", minutesBefore: -10_080 };
151
+ /** What a customer reads of a class: on the public timetable, and of a class they booked. */
152
+ const CLASS_READ = [
153
+ "title",
154
+ "classType",
155
+ "startsAt",
156
+ "endsAt",
157
+ "timezone",
158
+ "room",
159
+ "coach",
160
+ "notes",
161
+ "state",
162
+ ];
66
163
  // A booking rule is a person's to change (spec 31: "Change the booking rules: a person only"):
67
164
  // set by the assistant, an MCP client, an automation or extension code, it waits for a person's
68
165
  // approval (`personApproves`, ADR 0507).
@@ -85,15 +182,45 @@ export default defineExtension({
85
182
  // The class type is Programs' (spec 31): the host installs Bookings only beside Programs.
86
183
  requires: ["programs"],
87
184
  permissions: {
88
- // person.get / person.create: a booking's person on a class list, and a walk-in staff book.
185
+ // person.get / person.createWith: a booking's person on a class list, and a walk-in staff book.
89
186
  // programs.classtype: a class type's name and booking rules on staff's day view.
90
187
  read: ["person", "programs.classtype"],
91
188
  write: ["person"],
92
189
  // record.*, my.* and state.resolve are not listed: they are granted by object (Bookings'
93
190
  // own, and the read and write lists above), and a listed one would reach every object.
94
191
  // duplicate.check: a walk-in is checked against the People on file before one is made.
95
- operations: ["public.list", "public.get", "capacity.get", "duplicate.check"],
96
- modules: ["ops"],
192
+ // waitlist.position: where a waiter stands in the queue (a member: their own only).
193
+ // me.family: the member's own id, and the children staff linked to them (ADR 0540).
194
+ // order.startHeld: a drop-in, the booking made with its order by the host (ADR 0560).
195
+ // The messages (automations.ts): order.get (whether a drop-in was paid), extensionSettings.list
196
+ // (the waiting list's cut-off), notification.send (staff told of a class whose list was not
197
+ // taken); person.link.list, a child's live guardians on staff's screens. routine-mail, the
198
+ // members' email (routine-mail.ts, ADR 0590: the host decides who it goes to and what it
199
+ // says), sent from the email-send connection a person binds to each automation; storage,
200
+ // which class changes are still to be told (several edits within two minutes make one email).
201
+ // staffing.free: who is free for a service at a time, for "any coach" when staff book an
202
+ // appointment (stage 49, ADR 0763); staffing.week: a coach's duties beside their classes and
203
+ // appointments on the coach's day (ADR 0626), as the roster shows them to the reader.
204
+ // agreement.listHealthNotes: the "health note" mark beside a name on a class list (stage 44,
205
+ // decision 18), a yes or no per Person on the class's bookings (the host reads them) and
206
+ // nothing of the form; the host gives it only when a person called the tool themselves.
207
+ operations: [
208
+ "order.startHeld",
209
+ "public.list",
210
+ "public.get",
211
+ "capacity.get",
212
+ "duplicate.check",
213
+ "waitlist.position",
214
+ "me.family",
215
+ "person.link.list",
216
+ "order.get",
217
+ "extensionSettings.list",
218
+ "notification.send",
219
+ "agreement.listHealthNotes",
220
+ "staffing.free",
221
+ "staffing.week",
222
+ ],
223
+ modules: ["ops", "routine-mail", "email-send", "storage"],
97
224
  },
98
225
  // Bookings' fields on Programs' class type: how it shows, and its booking rules when they
99
226
  // differ from the organisation's (Settings → Extensions → Bookings). Empty: the organisation's.
@@ -118,16 +245,52 @@ export default defineExtension({
118
245
  "Empty: the organisation's setting."),
119
246
  lateMinutes: minutes("Late cancel from (minutes before)", "A cancel this close to the start or closer is late and keeps the class it used. Empty: " +
120
247
  "the organisation's setting."),
121
- promotionMinutes: minutes("Waitlist stops (minutes before)", "Nobody is moved in from the waitlist after this. Empty: the organisation's setting. " +
122
- "(The waitlist comes in a later release.)"),
123
- reminderMinutes: minutes("Reminder (minutes before)", "When members are reminded of a class. Empty: the organisation's setting. (Reminders " +
124
- "come in a later release.)"),
248
+ promotionMinutes: minutes("Waitlist stops (minutes before)", "Nobody is moved in from the waitlist after this: a place freed later goes to whoever " +
249
+ "books first. Empty: the organisation's setting."),
250
+ reminderMinutes: {
251
+ ...minutes("Reminder (minutes before)", "When members booked into a class are emailed a reminder, at most two days before. " +
252
+ "Empty: the organisation's setting."),
253
+ // At most two days: the reminder's minute scan reads the classes this far ahead (ADR 0570).
254
+ max: 2_880,
255
+ },
256
+ dropInPrice: {
257
+ type: "number",
258
+ label: "Drop-in price",
259
+ description: "What one class costs someone paying for it on the website, in the organisation's " +
260
+ "currency. Empty: the organisation's setting; empty there too, no drop-ins.",
261
+ min: 0,
262
+ max: 100_000,
263
+ step: 0.01,
264
+ personApproves: true,
265
+ },
125
266
  staffOnly: {
126
267
  type: "boolean",
127
268
  label: "Booked by staff only",
128
269
  description: "Members cannot book its classes themselves; staff book them in.",
129
270
  personApproves: true,
130
271
  },
272
+ // Preparation and pack-down (stage 45 decision 19, ADR 0627): minutes added to the coach's
273
+ // pay hours for each class of this type. Pay only: they never make two classes clash.
274
+ rosterBeforeMinutes: {
275
+ type: "number",
276
+ label: "Set-up minutes (pay)",
277
+ description: "Minutes before each class counted in its coach's pay hours (set-up). Empty: none. " +
278
+ "They never stop a coach taking the class before.",
279
+ min: 0,
280
+ max: 240,
281
+ step: 1,
282
+ personApproves: true,
283
+ },
284
+ rosterAfterMinutes: {
285
+ type: "number",
286
+ label: "Pack-down minutes (pay)",
287
+ description: "Minutes after each class counted in its coach's pay hours (pack-down). Empty: none. " +
288
+ "They never stop a coach taking the class after.",
289
+ min: 0,
290
+ max: 240,
291
+ step: 1,
292
+ personApproves: true,
293
+ },
131
294
  },
132
295
  },
133
296
  objects: {
@@ -147,6 +310,15 @@ export default defineExtension({
147
310
  min: 0,
148
311
  step: 1,
149
312
  },
313
+ // A private room (stage 49, ADR 0765): one class at a time in it, refused by the host for
314
+ // every writer. Off for a shared floor many classes use at once.
315
+ exclusive: {
316
+ type: "boolean",
317
+ label: "One booking at a time",
318
+ description: "Nothing else can be booked in this room while a class is in it. Turning it on is " +
319
+ "refused while two classes still to come overlap in it.",
320
+ default: false,
321
+ },
150
322
  notes: { type: "longText", label: "Notes" },
151
323
  },
152
324
  public: { read: ["name"] },
@@ -169,6 +341,9 @@ export default defineExtension({
169
341
  },
170
342
  active: { type: "boolean", label: "Active", default: true },
171
343
  },
344
+ // One coach profile per staff account (stage 45, ADR 0621): the host writes the right
345
+ // profile when a shift changes hands, and an account's classes are its profile's.
346
+ unique: [{ fields: ["user"] }],
172
347
  public: { read: ["name", "photo", "bio"] },
173
348
  },
174
349
  series: {
@@ -205,7 +380,9 @@ export default defineExtension({
205
380
  step: 1,
206
381
  },
207
382
  room: { type: "relation", label: "Room", to: "bookings.room" },
208
- coach: { type: "relation", label: "Coach", to: "bookings.coach" },
383
+ // Who coaches is a person's to change (stage 45 step 4, ADR 0626): the assistant, an MCP
384
+ // client or code may ask, and a person applies it. It changes someone's working week.
385
+ coach: { type: "relation", label: "Coach", to: "bookings.coach", personApproves: true },
209
386
  places: { type: "number", label: "Places", required: true, min: 0, step: 1 },
210
387
  firstDate: { type: "date", label: "First date", required: true },
211
388
  lastDate: { type: "date", label: "Last date", description: "Empty: ongoing." },
@@ -281,11 +458,13 @@ export default defineExtension({
281
458
  required: true,
282
459
  },
283
460
  startsAt: { type: "datetime", label: "Starts", required: true },
284
- endsAt: { type: "datetime", label: "Ends" },
461
+ // Required (step 7): no-shows are written after it, and a class is cancelled only before.
462
+ endsAt: { type: "datetime", label: "Ends", required: true },
285
463
  // Left empty, the organisation's zone (ADR 0460): a class always has one.
286
464
  timezone: { type: "timezone", label: "Time zone", required: true },
287
465
  room: { type: "relation", label: "Room", to: "bookings.room" },
288
- coach: { type: "relation", label: "Coach", to: "bookings.coach" },
466
+ // A person's to change (ADR 0626), as the series' coach: an AI's swap waits for a person.
467
+ coach: { type: "relation", label: "Coach", to: "bookings.coach", personApproves: true },
289
468
  // Required: a class is never unlimited by leaving its places empty.
290
469
  places: { type: "number", label: "Places", required: true, min: 0, step: 1 },
291
470
  notes: { type: "longText", label: "Notes for members" },
@@ -303,7 +482,15 @@ export default defineExtension({
303
482
  type: "boolean",
304
483
  label: "Changed from its series",
305
484
  readOnly: true,
306
- description: "Edited by hand: its series no longer changes it.",
485
+ description: "Moved, or its state changed, by hand: its series no longer changes it. A field " +
486
+ "changed by hand alone (another coach that day) stays this class's own, and later " +
487
+ "changes to its series still reach the rest.",
488
+ },
489
+ cancelledReason: {
490
+ type: "longText",
491
+ label: "Why it was cancelled",
492
+ readOnly: true,
493
+ description: "The reason staff gave when they cancelled the class.",
307
494
  },
308
495
  // A class that is not scheduled cannot be booked by a member (the booking's create rule).
309
496
  closed: {
@@ -316,46 +503,74 @@ export default defineExtension({
316
503
  field: "state",
317
504
  initial: "scheduled",
318
505
  moves: [
319
- // Only the host cancels a class at this step (a closure, a series ended, each confirmed
320
- // by a person, ADR 0500). Staff cancelling a class, with its bookings cancelled in the
321
- // same batch, is step 7's cascade.
322
- { from: "scheduled", to: "cancelled", by: ["host"], final: true },
506
+ // The host cancels a class (a closure, a series ended, each confirmed by a person, ADR
507
+ // 0500), and so does cancelClass: a person's act, or an AI's request a person approves
508
+ // (ADR 0552). No other staff write cancels one. Its bookings follow in the same batch.
509
+ // Only until the class ends (binding the tool's staff write; the host is not bound): a
510
+ // class that happened is not cancelled afterwards, so no-shows never sit on one.
511
+ {
512
+ from: "scheduled",
513
+ to: "cancelled",
514
+ by: ["host"],
515
+ tools: ["cancelClass"],
516
+ window: { until: "endsAt" },
517
+ bindsStaff: true,
518
+ final: true,
519
+ },
323
520
  { from: "scheduled", to: "done", by: ["staff", "host"], final: true },
324
521
  ],
325
522
  },
326
523
  // Members see how many places are left (decision 13), never who has them.
327
524
  capacity: { places: "places", show: "exact" },
525
+ // A class is a shift its coach works (stage 45, ADR 0621): the host refuses one staff
526
+ // account on two overlapping shifts (two classes, a class and a duty), for every writer, and
527
+ // answers a write with its warnings (the coach away or not qualified, a class with no
528
+ // coach). A coach profile with no account (a visiting coach) covers the class for members
529
+ // and claims nobody's time. A class done still counts (pay reads it); a cancelled one not.
530
+ staffed: {
531
+ who: { field: "coach", account: "user" },
532
+ starts: "startsAt",
533
+ ends: "endsAt",
534
+ zone: "timezone",
535
+ kind: "classType",
536
+ live: ["scheduled", "done"],
537
+ place: "room.name",
538
+ pattern: { link: "series", who: "coach" },
539
+ // Pay only (ADR 0627): the class type's set-up and pack-down minutes, and the evidence a
540
+ // class was run: its bookings, ticked by whoever took the list.
541
+ payBefore: { field: "classType.rosterBeforeMinutes" },
542
+ payAfter: { field: "classType.rosterAfterMinutes" },
543
+ evidence: { object: "booking", link: "class", by: "markedBy" },
544
+ },
545
+ // A class takes its room while it is on, when the room takes one booking at a time (stage
546
+ // 49, ADR 0765): the host refuses a second class (or, later, an appointment) in it at an
547
+ // overlapping time, for every writer. A shared room is never claimed. The room calendar
548
+ // shows it by its title (stage 57, ADR 0844).
549
+ occupies: {
550
+ thing: "room",
551
+ starts: "startsAt",
552
+ ends: "endsAt",
553
+ live: ["scheduled", "done"],
554
+ only: "exclusive",
555
+ title: "title",
556
+ },
328
557
  public: {
329
- read: [
330
- "title",
331
- "classType",
332
- "startsAt",
333
- "endsAt",
334
- "timezone",
335
- "room",
336
- "coach",
337
- "notes",
338
- "state",
339
- ],
558
+ read: CLASS_READ,
340
559
  when: { field: "state", in: ["scheduled"] },
341
560
  },
342
561
  // A booking's member reads their class whatever its state (a cancelled one says so).
343
562
  customerVia: {
344
563
  from: "bookings.booking",
345
564
  field: "class",
346
- read: [
347
- "title",
348
- "classType",
349
- "startsAt",
350
- "endsAt",
351
- "timezone",
352
- "room",
353
- "coach",
354
- "notes",
355
- "state",
356
- ],
565
+ read: CLASS_READ,
357
566
  },
358
- indexes: [["startsAt"], ["state", "startsAt"], ["series"], ["classType", "startsAt"]],
567
+ indexes: [
568
+ ["startsAt"],
569
+ ["state", "startsAt"],
570
+ ["series"],
571
+ ["classType", "startsAt"],
572
+ ["endsAt"],
573
+ ],
359
574
  },
360
575
  closure: {
361
576
  label: "Closure",
@@ -383,7 +598,9 @@ export default defineExtension({
383
598
  fields: {
384
599
  title: { type: "text", label: "Title" },
385
600
  class: { type: "relation", label: "Class", to: "bookings.class", required: true },
386
- person: { type: "relation", label: "Person", to: "person", required: true },
601
+ // Set on every booking but a guest's drop-in held while unpaid, which is nobody's until the
602
+ // payment is verified (`sellable.moves.guest`: the host keeps it set in every other state).
603
+ person: { type: "relation", label: "Person", to: "person" },
387
604
  state: { type: "select", label: "State", track: "timeline", options: BOOKING_STATES },
388
605
  holder: {
389
606
  type: "text",
@@ -412,17 +629,38 @@ export default defineExtension({
412
629
  },
413
630
  paidOtherwise: {
414
631
  type: "boolean",
415
- label: "Paid at the desk",
632
+ label: "Paid another way",
416
633
  readOnly: true,
417
- description: "Booked by staff for someone who paid another way (a walk-in at the desk): it " +
634
+ description: "Paid at the desk (a walk-in staff booked) or as a drop-in on the website: it " +
418
635
  "spends no use. Set when it is made.",
419
636
  },
637
+ // A drop-in (ADR 0560): what it cost and its order, written by the host at the buy.
638
+ dropInPrice: {
639
+ type: "number",
640
+ label: "Drop-in paid",
641
+ readOnly: true,
642
+ description: "What the drop-in cost, set by the host when it was bought.",
643
+ },
644
+ dropInOrder: {
645
+ type: "text",
646
+ label: "Drop-in order",
647
+ readOnly: true,
648
+ description: "The order that pays for this drop-in, set by the host.",
649
+ },
420
650
  bookedBy: {
421
651
  type: "user",
422
652
  label: "Booked by",
423
653
  readOnly: true,
424
654
  description: "The staff account that booked it. Empty when the member booked.",
425
655
  },
656
+ madeBy: {
657
+ type: "relation",
658
+ label: "Booked by (member)",
659
+ to: "person",
660
+ readOnly: true,
661
+ description: "The member who made it, set by the host: the person themselves, or the parent or " +
662
+ "guardian who booked for them. Empty when staff booked. Nobody edits it.",
663
+ },
426
664
  movedFrom: {
427
665
  type: "relation",
428
666
  label: "Moved from",
@@ -431,33 +669,81 @@ export default defineExtension({
431
669
  description: "The booking this one replaced when staff moved it to this class.",
432
670
  },
433
671
  note: { type: "longText", label: "Staff note" },
672
+ // Who ticked the name (or marked a no-show), and when (step 7): the coach who was first.
673
+ markedAt: {
674
+ type: "datetime",
675
+ label: "Attendance marked",
676
+ readOnly: true,
677
+ description: "When a coach ticked them as come, or marked them as not come.",
678
+ },
679
+ markedBy: {
680
+ type: "user",
681
+ label: "Marked by",
682
+ readOnly: true,
683
+ description: "The staff account that marked their attendance.",
684
+ },
685
+ markedByName: {
686
+ type: "text",
687
+ label: "Marked by (name)",
688
+ readOnly: true,
689
+ description: "That staff member's name as it was then.",
690
+ },
691
+ // The waitlist's record of what the host did (ADR 0520), for the class list and messages.
692
+ promotedAt: {
693
+ type: "datetime",
694
+ label: "Moved in from the waitlist",
695
+ readOnly: true,
696
+ description: "When the host moved them in from the waitlist.",
697
+ },
698
+ passedOverAt: {
699
+ type: "datetime",
700
+ label: "Passed over",
701
+ readOnly: true,
702
+ description: "When a place was free but nothing they hold could pay for it: they stay waiting.",
703
+ },
704
+ passedOverReason: {
705
+ type: "text",
706
+ label: "Why passed over",
707
+ readOnly: true,
708
+ description: "The host's reason (no_uses_left, ended, not_live, not_covered…).",
709
+ },
434
710
  },
435
711
  states: {
436
712
  field: "state",
437
713
  initial: "booked",
438
714
  create: {
439
- // Waiting (step 5) and held while paying (step 8) are not reachable by anyone but the
440
- // host yet: nothing a customer does lands a booking in them.
441
- in: { waiting: ["host"], pending: ["host"] },
715
+ // A member or staff join a full class's waitlist (ADR 0520: only while it is full,
716
+ // before the cut-off). Held while paying (step 8) is the host's alone.
717
+ in: { waiting: ["staff", "customer", "host"], pending: ["host"] },
442
718
  window: { from: opens, until: closes },
443
719
  // A class type booked by staff only (staff may book it).
444
720
  staffOnly: "class.classType.staffOnly",
445
721
  // A class that is not scheduled (cancelled or done): nobody books it, staff included.
446
722
  closed: "class.closed",
447
723
  },
448
- // A class the host cancels (a closure, a series changed, ended or trashed) cancels its
449
- // live bookings in the same batch: places released, uses given back (ADR 0507).
724
+ // A class the gym cancels (cancelClass, a closure, a series changed, ended or trashed)
725
+ // cancels every booking that holds a place or a use in the same batch: booked, ticked,
726
+ // marked not come and cancelled late included, each use given back once (ADRs 0507, 0553).
450
727
  follows: {
451
728
  relation: "class",
452
729
  when: { cancelled: "cancelled_by_us" },
453
- from: ["booked", "waiting", "pending"],
730
+ from: FOLLOW_CANCEL,
454
731
  },
455
732
  // A member asks to cancel; the host picks in time or late by its clock (ADR 0503).
456
733
  requests: { cancel: ["cancelled", "late_cancelled"] },
457
734
  moves: [
458
735
  { from: "pending", to: "booked", by: ["host"] },
459
736
  { from: "pending", to: "expired", by: ["host"], final: true },
460
- { from: "waiting", to: "booked", by: ["host"] },
737
+ // The host promotes (taking the waitlist's hold); a member waiting on a class with a
738
+ // free place (after the cut-off, say) takes it themselves, inside the booking window
739
+ // and the staff-only rule, never a place held for the queue (ADR 0520).
740
+ {
741
+ from: "waiting",
742
+ to: "booked",
743
+ by: ["host", "customer"],
744
+ window: { from: opens, until: closes },
745
+ staffOnly: "class.classType.staffOnly",
746
+ },
461
747
  { from: "waiting", to: "left", by: ["staff", "customer"], final: true },
462
748
  {
463
749
  from: "booked",
@@ -469,32 +755,132 @@ export default defineExtension({
469
755
  // person's own act, the move below.
470
756
  bindsStaff: true,
471
757
  },
758
+ // Not final: a class the gym cancels afterwards gives the kept use back (ADR 0553).
472
759
  {
473
760
  from: "booked",
474
761
  to: "late_cancelled",
475
762
  by: ["staff", "customer"],
476
- final: true,
477
763
  window: { from: lateFrom, until: "class.startsAt" },
478
764
  },
479
765
  // A person on the staff gives the use back whatever the time, with a reason, through
480
766
  // returnUse alone (ADR 0513's `tools`: humanOnly, with its permission).
481
767
  { from: "booked", to: "excused", by: ["host"], tools: ["returnUse"], final: true },
482
- { from: "booked", to: "attended", by: ["staff"] },
768
+ // A coach ticks a name from an hour before the class, and any time after it (a late
769
+ // correction), never days ahead (a window that binds staff, ADR 0551). Unticked, it is
770
+ // booked again; a no-show ticked is attended. Each keeps the use.
771
+ {
772
+ from: "booked",
773
+ to: "attended",
774
+ by: ["staff"],
775
+ window: { from: listOpens },
776
+ bindsStaff: true,
777
+ },
483
778
  { from: "attended", to: "booked", by: ["staff"] },
484
- { from: "booked", to: "no_show", by: ["staff", "host"] },
779
+ // Marked by a coach once the class has started; by the host after it (states.after).
780
+ {
781
+ from: "booked",
782
+ to: "no_show",
783
+ by: ["staff", "host"],
784
+ window: { from: "class.startsAt" },
785
+ bindsStaff: true,
786
+ },
485
787
  { from: "no_show", to: "attended", by: ["staff"] },
788
+ { from: FOLLOW_CANCEL, to: "cancelled_by_us", by: ["host"], final: true },
789
+ // A move to another class: made only by making the new booking (`movedFrom`), in its
790
+ // batch (ADR 0551), and only before the class starts; after it, giving the use back is a
791
+ // person's act (returnUse).
486
792
  {
487
- from: ["booked", "waiting", "pending"],
488
- to: "cancelled_by_us",
489
- by: ["host"],
793
+ from: "booked",
794
+ to: "moved",
795
+ by: ["staff"],
490
796
  final: true,
797
+ window: { until: "class.startsAt" },
798
+ bindsStaff: true,
491
799
  },
492
- { from: "booked", to: "moved", by: ["staff"], final: true },
493
800
  ],
801
+ // 30 minutes after a class ends, a booking still booked is a no-show, only when someone
802
+ // on the class was marked (its list was taken): a forgotten list makes nobody a no-show
803
+ // (spec 31, decision 11; ADR 0550).
804
+ after: [
805
+ {
806
+ from: "booked",
807
+ to: "no_show",
808
+ at: "class.endsAt",
809
+ minutesAfter: 30,
810
+ ifAnyIn: ["attended", "no_show"],
811
+ },
812
+ ],
813
+ },
814
+ // A class's bookings are the list its coach reads (stage 44, ADR 0643): the host may mark a
815
+ // health note beside each Person on it, asked for by the class's id only.
816
+ healthNotes: { list: "class", person: "person" },
817
+ // Before a booking (stage 44, ADRs 0641 and 0644): checked when a caller makes one booked
818
+ // or waiting, or a waiter takes a free place, for the booking's Person; a drop-in at its
819
+ // order. The host's own moves (promotion, a paid drop-in) are not.
820
+ agreements: {
821
+ point: "booking",
822
+ label: "Before a booking",
823
+ suggests: ["waiver", "health", "guardian"],
824
+ enter: ["booked", "waiting"],
825
+ person: "person",
826
+ // The timetable and drop-in blocks show what is due and let a person agree (step 5).
827
+ inlineStep: true,
494
828
  },
495
829
  // A place on the class while held, booked, attended or a no-show (ADR 0501).
496
- claims: { on: "class", held: ["pending"], confirmed: ["booked", "attended", "no_show"] },
830
+ // Its waitlist (ADR 0520): a place given back before the class type's "waitlist stops"
831
+ // time (else the organisation's) goes to the first waiter, whom the host moves in.
832
+ claims: {
833
+ on: "class",
834
+ held: ["pending"],
835
+ confirmed: ["booked", "attended", "no_show"],
836
+ waitlist: {
837
+ state: "waiting",
838
+ promote: "booked",
839
+ until: {
840
+ at: "class.startsAt",
841
+ minutesBefore: {
842
+ field: "class.classType.promotionMinutes",
843
+ setting: "promotionMinutes",
844
+ },
845
+ },
846
+ promotedAt: "promotedAt",
847
+ passedOverAt: "passedOverAt",
848
+ passedOverReason: "passedOverReason",
849
+ },
850
+ },
497
851
  unique: [{ fields: ["person", "class"], states: ACTIVE }],
852
+ // A drop-in (decision 8, ADR 0560): x.bookings.buy has the host make the booking held
853
+ // (`pending`, a place claimed) with its order, priced from the class type's drop-in price,
854
+ // else the organisation's. A verified payment books it; the order expiring or cancelled
855
+ // releases it (`expired`). A paid one cancelled in time, given back by a person, or
856
+ // cancelled by the gym owes its money back, which a person with orders:refund approves
857
+ // (decision 15). A late cancel and a no-show keep it (no fee, no refund).
858
+ sellable: {
859
+ price: "dropInPrice",
860
+ // Stripe's "Fee for Personal Training/Fitness Classes" (in-person group classes); a human
861
+ // admin may override it in Settings -> Orders.
862
+ tax: { code: "txcd_50021003" },
863
+ moves: {
864
+ held: "pending",
865
+ paid: "booked",
866
+ expired: "expired",
867
+ refund: ["cancelled", "excused", "cancelled_by_us"],
868
+ price: { field: "class.classType.dropInPrice", setting: "dropInPrice" },
869
+ title: "class.title",
870
+ order: "dropInOrder",
871
+ // A visitor is matched to no Person until they have paid (ADR 0560): their hold is
872
+ // nobody's, blocks nobody's own booking and says nothing about who has the address.
873
+ guest: true,
874
+ // How much of a class unpaid guest holds may take at once.
875
+ holdCap: { setting: "dropInHoldPercent" },
876
+ },
877
+ // In the finance reports (ADR 0792): earned when the class starts.
878
+ finance: {
879
+ category: { key: "drop_ins", label: "Drop-ins" },
880
+ earned: "at_date",
881
+ at: "class.startsAt",
882
+ },
883
+ },
498
884
  // A spender of the Memberships pack's holders (stage 32b's ids, spec 32): booked spends,
499
885
  // an in-time cancel, a class the gym cancels and a move give back; a late cancel and a
500
886
  // no-show keep it. The period is the class's, and its type and local time are what a
@@ -511,19 +897,441 @@ export default defineExtension({
511
897
  movedFrom: { field: "movedFrom", state: "moved" },
512
898
  paidBy: ["memberships.membership", "memberships.pass"],
513
899
  waived: "paidOtherwise",
900
+ // A membership ended by its payer's cooling off (stage 44 step 7, ADR 0647): its
901
+ // bookings for classes not yet started are cancelled as the gym's, their places freed
902
+ // for the waiting list and their uses given back.
903
+ released: "cancelled_by_us",
514
904
  },
515
905
  },
516
- // A member reads and changes only their own bookings; never anyone else's (decision 13).
906
+ // A member reads and changes only their own bookings, and a parent or guardian staff linked
907
+ // to a child the child's too (ADR 0540); never anyone else's (decision 13).
517
908
  customer: {
518
909
  field: "person",
519
- read: ["class", "state", "holder", "classType"],
910
+ read: [
911
+ "person",
912
+ "class",
913
+ "state",
914
+ "holder",
915
+ "classType",
916
+ "promotedAt",
917
+ "passedOverAt",
918
+ "passedOverReason",
919
+ "paidOtherwise",
920
+ "dropInPrice",
921
+ "dropInOrder",
922
+ ],
520
923
  write: ["class", "state", "holder"],
521
924
  // Which class and which holder are chosen when it is made, never after (ADR 0507).
522
925
  createOnly: ["class", "holder"],
926
+ // A guardian books, cancels and joins waitlists for a live dependant, under the same
927
+ // windows and rules, and reads their bookings (ADR 0540). The use is the child's: the
928
+ // allowance spends the booking's Person's holders only.
929
+ guardians: { write: true, madeBy: "madeBy" },
523
930
  },
524
931
  timelineLinks: ["person"],
525
932
  indexes: [["class", "state"], ["person", "state"], ["state"]],
526
933
  },
934
+ service: {
935
+ label: "Service",
936
+ plural: "Services",
937
+ icon: "user-check",
938
+ titleField: "title",
939
+ description: "A kind of one-to-one session the business offers (personal training, 60 minutes): its " +
940
+ "length, buffers, the rooms it may use and its booking rules. Who gives it is a " +
941
+ "qualification, not a list here.",
942
+ navigation: "settings",
943
+ fields: {
944
+ title: { type: "text", label: "Title", required: true },
945
+ description: { type: "longText", label: "Description" },
946
+ length: {
947
+ type: "number",
948
+ label: "Length (minutes)",
949
+ required: true,
950
+ min: 5,
951
+ max: 480,
952
+ step: 5,
953
+ },
954
+ // The buffer (stage 49, ADR 0760): minutes kept free in the coach's time and the room,
955
+ // never part of the appointment's own times or its pay.
956
+ bufferBefore: {
957
+ type: "number",
958
+ label: "Buffer before (minutes)",
959
+ description: "Minutes kept free before each session, for the coach and the room.",
960
+ min: 0,
961
+ max: 240,
962
+ step: 5,
963
+ },
964
+ bufferAfter: {
965
+ type: "number",
966
+ label: "Buffer after (minutes)",
967
+ description: "Minutes kept free after each session, for the coach and the room.",
968
+ min: 0,
969
+ max: 240,
970
+ step: 5,
971
+ },
972
+ price: {
973
+ type: "currency",
974
+ label: "Price per session",
975
+ description: "What one session costs when paid for on its own. Empty: not sold per session.",
976
+ personApproves: true,
977
+ },
978
+ rooms: {
979
+ type: "relation",
980
+ label: "Rooms it may use",
981
+ to: "bookings.room",
982
+ many: true,
983
+ description: "In the order they are offered: an appointment takes the first one free. Empty: it " +
984
+ "needs no room.",
985
+ },
986
+ step: {
987
+ type: "number",
988
+ label: "Start times every (minutes)",
989
+ description: "15, 30 or 60: start times on the hour and every this many minutes. Empty: 30.",
990
+ min: 15,
991
+ max: 60,
992
+ step: 15,
993
+ },
994
+ opensDays: {
995
+ type: "number",
996
+ label: "Booking opens (days before)",
997
+ description: "Clients may book this many days ahead. Empty: the organisation's setting.",
998
+ min: 0,
999
+ max: 365,
1000
+ step: 1,
1001
+ personApproves: true,
1002
+ },
1003
+ closesMinutes: minutes("Booking closes (minutes before)", "Clients may book until this many minutes before a session. Empty: the organisation's " +
1004
+ "setting."),
1005
+ lateMinutes: minutes("Late cancel from (minutes before)", "A cancel this close to the start or closer is late and keeps the session it used. " +
1006
+ "Empty: the organisation's setting."),
1007
+ whoBooks: {
1008
+ type: "select",
1009
+ label: "Who books it",
1010
+ default: "members_visitors",
1011
+ options: [
1012
+ { value: "members_visitors", label: "Members and visitors" },
1013
+ { value: "members", label: "Members only" },
1014
+ { value: "staff", label: "Staff only" },
1015
+ ],
1016
+ personApproves: true,
1017
+ },
1018
+ active: { type: "boolean", label: "Offered", default: true },
1019
+ // Booked by staff only: a customer cannot book it themselves (the create rule).
1020
+ staffOnly: {
1021
+ type: "formula",
1022
+ label: "Booked by staff only",
1023
+ expression: 'coalesce(whoBooks, "members_visitors") = "staff"',
1024
+ },
1025
+ // A service no longer offered: nobody books it, staff included (the create rule).
1026
+ closed: {
1027
+ type: "formula",
1028
+ label: "Not offered",
1029
+ expression: "not coalesce(active, true)",
1030
+ },
1031
+ },
1032
+ indexes: [["active"]],
1033
+ },
1034
+ appointment: {
1035
+ label: "Appointment",
1036
+ plural: "Appointments",
1037
+ icon: "calendar-heart",
1038
+ titleField: "title",
1039
+ titleDefault: { from: ["service", "person"] },
1040
+ description: "One booked one-to-one session: a client, a coach, a service, a start and an end, and " +
1041
+ "the room it takes.",
1042
+ navigation: "main",
1043
+ navigationOrder: 33,
1044
+ fields: {
1045
+ title: { type: "text", label: "Title" },
1046
+ service: { type: "relation", label: "Service", to: "bookings.service", required: true },
1047
+ // Required when it is made (states.create.requires); not `required`, so erasing the client
1048
+ // keeps the appointment for pay and the business's books with the client cleared.
1049
+ person: { type: "relation", label: "Client", to: "person" },
1050
+ // Who gives it: a coach profile holding a staff account (account required, ADR 0760).
1051
+ // Empty only once a coach has left (uncovered): a manager gives it to another coach
1052
+ // (reassignAppointment, which an AI may only ask a person to do).
1053
+ coach: { type: "relation", label: "Coach", to: "bookings.coach" },
1054
+ room: {
1055
+ type: "relation",
1056
+ label: "Room",
1057
+ to: "bookings.room",
1058
+ description: "Left empty, the host gives it the first of the service's rooms free then.",
1059
+ },
1060
+ // Its times and service change only by a move (a new appointment, ADR 0764).
1061
+ startsAt: { type: "datetime", label: "Starts", required: true },
1062
+ endsAt: { type: "datetime", label: "Ends", required: true },
1063
+ timezone: { type: "timezone", label: "Time zone", required: true },
1064
+ lateAnchor: {
1065
+ type: "datetime",
1066
+ label: "Late cancel counted from",
1067
+ readOnly: true,
1068
+ description: "Set by the host: its start, or, when it was moved, the start of the appointment it " +
1069
+ "replaced. The late-cancel point is counted back from it.",
1070
+ },
1071
+ state: {
1072
+ type: "select",
1073
+ label: "State",
1074
+ track: "timeline",
1075
+ options: APPOINTMENT_STATES,
1076
+ },
1077
+ holder: {
1078
+ type: "text",
1079
+ label: "Paid from",
1080
+ description: "The pass or membership the appointment spent a session of (its id). Left empty, the " +
1081
+ "host chooses the one whose session would lapse first.",
1082
+ },
1083
+ // What a pass's or a membership's services and limits read, filled by the host.
1084
+ serviceId: {
1085
+ type: "text",
1086
+ label: "Service (for passes)",
1087
+ readOnly: true,
1088
+ description: "The service, copied by the host: what a pass's services are compared with.",
1089
+ },
1090
+ weekday: {
1091
+ type: "number",
1092
+ label: "Weekday",
1093
+ readOnly: true,
1094
+ description: "The local weekday (1 Monday to 7 Sunday), set by the host.",
1095
+ },
1096
+ minute: {
1097
+ type: "number",
1098
+ label: "Local minute",
1099
+ readOnly: true,
1100
+ description: "The local start, in minutes after midnight, set by the host.",
1101
+ },
1102
+ paidOtherwise: {
1103
+ type: "boolean",
1104
+ label: "Paid at the desk",
1105
+ readOnly: true,
1106
+ description: "Paid at the desk or another way: it spends no session. Set when it is made.",
1107
+ },
1108
+ bookedBy: {
1109
+ type: "user",
1110
+ label: "Booked by",
1111
+ readOnly: true,
1112
+ description: "The staff account that booked it.",
1113
+ },
1114
+ movedFrom: {
1115
+ type: "relation",
1116
+ label: "Moved from",
1117
+ to: "bookings.appointment",
1118
+ readOnly: true,
1119
+ description: "The appointment this one replaced when it was moved to another time.",
1120
+ },
1121
+ note: { type: "longText", label: "Staff note" },
1122
+ markedAt: {
1123
+ type: "datetime",
1124
+ label: "Attendance marked",
1125
+ readOnly: true,
1126
+ description: "When it was marked attended or not come.",
1127
+ },
1128
+ markedBy: {
1129
+ type: "user",
1130
+ label: "Marked by",
1131
+ readOnly: true,
1132
+ description: "The staff account that marked it. Empty when the host marked it attended.",
1133
+ },
1134
+ markedByName: {
1135
+ type: "text",
1136
+ label: "Marked by (name)",
1137
+ readOnly: true,
1138
+ description: "That staff member's name as it was then.",
1139
+ },
1140
+ cancelledReason: {
1141
+ type: "longText",
1142
+ label: "Why it was cancelled or given back",
1143
+ readOnly: true,
1144
+ },
1145
+ },
1146
+ states: {
1147
+ field: "state",
1148
+ initial: "booked",
1149
+ create: {
1150
+ // Held while paying (stage 49 step 8) and not paid yet (a standing series' date, step 9)
1151
+ // are the host's alone.
1152
+ in: { pending: ["host"], unpaid: ["host"] },
1153
+ window: { from: appointmentOpens, until: appointmentCloses },
1154
+ staffOnly: "service.staffOnly",
1155
+ // A service no longer offered: nobody books it, staff included.
1156
+ closed: "service.closed",
1157
+ // Made for a client, by everyone, the host included.
1158
+ requires: ["person"],
1159
+ },
1160
+ // A cancel is in time or late by the host's clock, for every caller (ADR 0503).
1161
+ requests: { cancel: ["cancelled", "late_cancelled"] },
1162
+ moves: [
1163
+ { from: "pending", to: "booked", by: ["host"] },
1164
+ { from: "pending", to: "expired", by: ["host"], final: true },
1165
+ // Not paid yet: staff book it (a session spent, or paid at the desk).
1166
+ { from: "unpaid", to: "booked", by: ["staff"] },
1167
+ // In time, for everyone, staff included (ADR 0507): giving a session back later is a
1168
+ // person's own act (excuseAppointment), never a cancel's.
1169
+ {
1170
+ from: "booked",
1171
+ to: "cancelled",
1172
+ by: ["staff", "customer"],
1173
+ final: true,
1174
+ window: { until: appointmentLateFrom },
1175
+ bindsStaff: true,
1176
+ },
1177
+ // Late: the session is used, with no fee (decision 1). Not final: a person may excuse it.
1178
+ {
1179
+ from: "booked",
1180
+ to: "late_cancelled",
1181
+ by: ["staff", "customer"],
1182
+ window: { from: appointmentLateFrom, until: "startsAt" },
1183
+ },
1184
+ // A move to another time or coach: made only by making the new appointment
1185
+ // (`movedFrom`), in its batch (ADR 0551), before it starts; the session moves with it.
1186
+ {
1187
+ from: "booked",
1188
+ to: "moved",
1189
+ by: ["staff"],
1190
+ final: true,
1191
+ window: { until: "startsAt" },
1192
+ bindsStaff: true,
1193
+ },
1194
+ // Marked once it has started, by the coach or staff; attended by the host 30 minutes
1195
+ // after the end when nobody marked it (`after`). Each keeps the session.
1196
+ {
1197
+ from: "booked",
1198
+ to: "attended",
1199
+ by: ["staff", "host"],
1200
+ window: { from: "startsAt" },
1201
+ bindsStaff: true,
1202
+ },
1203
+ {
1204
+ from: "booked",
1205
+ to: "no_show",
1206
+ by: ["staff", "host"],
1207
+ window: { from: "startsAt" },
1208
+ bindsStaff: true,
1209
+ },
1210
+ // A correction, one into the other, within 7 days of the end.
1211
+ {
1212
+ from: "attended",
1213
+ to: "no_show",
1214
+ by: ["staff"],
1215
+ window: { until: correctable },
1216
+ bindsStaff: true,
1217
+ },
1218
+ {
1219
+ from: "no_show",
1220
+ to: "attended",
1221
+ by: ["staff"],
1222
+ window: { until: correctable },
1223
+ bindsStaff: true,
1224
+ },
1225
+ // A person on the staff gives the session back (decision 1), with a reason, through
1226
+ // excuseAppointment alone (ADR 0513).
1227
+ {
1228
+ from: ["late_cancelled", "no_show"],
1229
+ to: "excused",
1230
+ by: ["host"],
1231
+ tools: ["excuseAppointment"],
1232
+ final: true,
1233
+ },
1234
+ // The business cancels it, the session given back: the host (a membership cooled off;
1235
+ // later a closure or a provider leaving), and a person through cancelAppointmentByUs.
1236
+ {
1237
+ from: ["pending", "unpaid", "booked"],
1238
+ to: "cancelled_by_us",
1239
+ by: ["host"],
1240
+ tools: ["cancelAppointmentByUs"],
1241
+ final: true,
1242
+ },
1243
+ ],
1244
+ // Nobody marked it: attended, 30 minutes after it ends (the spec's decision 9). The
1245
+ // session is kept either way, so this changes only reporting. Never one whose coach left
1246
+ // (no coach): nobody gave it.
1247
+ after: [
1248
+ { from: "booked", to: "attended", at: "endsAt", minutesAfter: 30, ifSet: ["coach"] },
1249
+ ],
1250
+ },
1251
+ // The coach's shift (stage 45, ADR 0621): one staff account is never on a class, a duty and
1252
+ // an appointment at once, the service's buffer included (ADR 0760), refused by the database
1253
+ // for every writer. A coach profile with no account cannot be booked (`account`). Its title
1254
+ // names the client, so the roster and the feed show it as its service (ADR 0761). Booked at
1255
+ // free times (ADRs 0762, 0763): the coach's open hours, the service's length, step and
1256
+ // rooms, the client's own appointments, the closures; staff are warned outside them.
1257
+ staffed: {
1258
+ who: { field: "coach", account: "user" },
1259
+ starts: "startsAt",
1260
+ ends: "endsAt",
1261
+ zone: "timezone",
1262
+ kind: "service",
1263
+ live: APPOINTMENT_LIVE,
1264
+ place: "room.name",
1265
+ claimBefore: { field: "service.bufferBefore" },
1266
+ claimAfter: { field: "service.bufferAfter" },
1267
+ account: "required",
1268
+ private: true,
1269
+ open: {
1270
+ length: { field: "service.length" },
1271
+ step: { field: "service.step" },
1272
+ rooms: { field: "service.rooms" },
1273
+ client: "person",
1274
+ closedBy: { object: "closure", from: "fromDate", until: "untilDate" },
1275
+ customer: true,
1276
+ },
1277
+ },
1278
+ // Its room while it is on, when the room takes one booking at a time (ADR 0765), the
1279
+ // service's buffer kept free in it too. The room calendar shows the service, not the client.
1280
+ occupies: {
1281
+ thing: "room",
1282
+ starts: "startsAt",
1283
+ ends: "endsAt",
1284
+ live: APPOINTMENT_LIVE,
1285
+ before: { field: "service.bufferBefore" },
1286
+ after: { field: "service.bufferAfter" },
1287
+ only: "exclusive",
1288
+ },
1289
+ // A spender of the Memberships pack's holders, as a class booking is: booked spends one
1290
+ // session of a pass or membership that covers the service; an in-time cancel, a move, an
1291
+ // excuse and the business's cancel give it back; a late cancel and a no-show keep it, with
1292
+ // no fee (decision 1). Staff may book it paid at the desk (`waived`, ADR 0506).
1293
+ allowance: {
1294
+ spends: {
1295
+ person: "person",
1296
+ holder: "holder",
1297
+ spendIn: ["booked"],
1298
+ returnIn: ["cancelled", "excused", "cancelled_by_us", "moved"],
1299
+ at: "startsAt",
1300
+ copy: { serviceId: "service.id" },
1301
+ local: { weekday: "weekday", minute: "minute", zone: "timezone" },
1302
+ // Its times and service change only by a move, and a moved one keeps the late point of
1303
+ // the one it replaced (ADR 0764): a used session never comes back by a change of time.
1304
+ movedFrom: {
1305
+ field: "movedFrom",
1306
+ state: "moved",
1307
+ fixed: ["startsAt", "endsAt", "service"],
1308
+ anchor: { field: "lateAnchor", from: "startsAt" },
1309
+ },
1310
+ paidBy: ["memberships.membership", "memberships.pass"],
1311
+ waived: "paidOtherwise",
1312
+ released: "cancelled_by_us",
1313
+ },
1314
+ },
1315
+ // Before an appointment (stage 44, ADRs 0641 and 0644): what the business attaches here is
1316
+ // due before the client's appointment is booked.
1317
+ agreements: {
1318
+ point: "appointment",
1319
+ label: "Before an appointment",
1320
+ suggests: ["waiver", "health", "guardian"],
1321
+ enter: ["booked"],
1322
+ person: "person",
1323
+ inlineStep: true,
1324
+ },
1325
+ timelineLinks: ["person"],
1326
+ indexes: [
1327
+ ["startsAt"],
1328
+ ["coach", "startsAt"],
1329
+ ["person", "startsAt"],
1330
+ ["state", "startsAt"],
1331
+ ["service"],
1332
+ ["endsAt"],
1333
+ ],
1334
+ },
527
1335
  },
528
1336
  views: {
529
1337
  todaysClasses: {
@@ -557,6 +1365,13 @@ export default defineExtension({
557
1365
  sort: { field: "time", direction: "asc" },
558
1366
  columns: ["title", "weekdays", "time", "length", "coach", "room", "places", "firstDate"],
559
1367
  },
1368
+ waitlists: {
1369
+ label: "Waiting",
1370
+ object: "bookings.booking",
1371
+ filter: { field: "state", op: "eq", value: "waiting" },
1372
+ sort: { field: "createdAt", direction: "asc" },
1373
+ columns: ["title", "class", "person", "createdAt", "passedOverAt", "passedOverReason"],
1374
+ },
560
1375
  lateCancels: {
561
1376
  label: "Late cancels",
562
1377
  object: "bookings.booking",
@@ -564,6 +1379,31 @@ export default defineExtension({
564
1379
  sort: { field: "updatedAt", direction: "desc" },
565
1380
  columns: ["title", "class", "person", "updatedAt"],
566
1381
  },
1382
+ // Step 9's saved views: this month's, by when the booking last changed (became one).
1383
+ noShowsThisMonth: {
1384
+ label: "No-shows this month",
1385
+ object: "bookings.booking",
1386
+ filter: {
1387
+ and: [
1388
+ { field: "state", op: "eq", value: "no_show" },
1389
+ { field: "updatedAt", op: "gte", value: { $relative: "startOfMonth" } },
1390
+ ],
1391
+ },
1392
+ sort: { field: "updatedAt", direction: "desc" },
1393
+ columns: ["title", "class", "person", "markedByName", "updatedAt"],
1394
+ },
1395
+ lateCancelsThisMonth: {
1396
+ label: "Late cancels this month",
1397
+ object: "bookings.booking",
1398
+ filter: {
1399
+ and: [
1400
+ { field: "state", op: "eq", value: "late_cancelled" },
1401
+ { field: "updatedAt", op: "gte", value: { $relative: "startOfMonth" } },
1402
+ ],
1403
+ },
1404
+ sort: { field: "updatedAt", direction: "desc" },
1405
+ columns: ["title", "class", "person", "updatedAt"],
1406
+ },
567
1407
  },
568
1408
  recordTabs: {
569
1409
  // A class's list: who is booked, on its record page.
@@ -574,7 +1414,19 @@ export default defineExtension({
574
1414
  type: "table",
575
1415
  object: "bookings.booking",
576
1416
  relation: "class",
577
- columns: ["person", "state", "holder", "paidOtherwise", "bookedBy", "createdAt"],
1417
+ columns: [
1418
+ "person",
1419
+ "state",
1420
+ "holder",
1421
+ "paidOtherwise",
1422
+ "dropInPrice",
1423
+ "bookedBy",
1424
+ "promotedAt",
1425
+ "passedOverReason",
1426
+ "markedAt",
1427
+ "markedByName",
1428
+ "createdAt",
1429
+ ],
578
1430
  sort: { field: "createdAt", direction: "asc" },
579
1431
  },
580
1432
  order: 10,
@@ -603,6 +1455,51 @@ export default defineExtension({
603
1455
  },
604
1456
  order: 35,
605
1457
  },
1458
+ // A client's appointments (stage 49), soonest last.
1459
+ personAppointments: {
1460
+ label: "Appointments",
1461
+ on: "person",
1462
+ view: {
1463
+ type: "table",
1464
+ object: "bookings.appointment",
1465
+ relation: "person",
1466
+ columns: ["service", "startsAt", "coach", "room", "state", "holder", "paidOtherwise"],
1467
+ sort: { field: "startsAt", direction: "desc" },
1468
+ },
1469
+ order: 36,
1470
+ },
1471
+ serviceAppointments: {
1472
+ label: "Appointments",
1473
+ on: "bookings.service",
1474
+ view: {
1475
+ type: "table",
1476
+ object: "bookings.appointment",
1477
+ relation: "service",
1478
+ columns: ["startsAt", "person", "coach", "room", "state"],
1479
+ sort: { field: "startsAt", direction: "desc" },
1480
+ },
1481
+ order: 10,
1482
+ },
1483
+ },
1484
+ // The members' email (ADR 0590): routine mail the host sends without a person's approval.
1485
+ routineMail: bookingsRoutineMail,
1486
+ // What a journey can start or stop on (stage 53, ADR 0802): the host records the last time each
1487
+ // person had each, in the write's batch. "Not seen for two weeks" is no `attended` for 14 days.
1488
+ // A tick taken back (attended to booked) is not a new booking.
1489
+ journeySignals: {
1490
+ booked: {
1491
+ label: "Class booked",
1492
+ description: "A place in a class is booked: made, taken from the waitlist, or paid for.",
1493
+ object: "booking",
1494
+ enters: ["booked"],
1495
+ from: ["pending", "waiting"],
1496
+ },
1497
+ attended: {
1498
+ label: "Class attended",
1499
+ description: "A coach ticks the person's name on a class's list.",
1500
+ object: "booking",
1501
+ enters: ["attended"],
1502
+ },
606
1503
  },
607
1504
  // The organisation's booking rules, which a class type's own values override. Changed by a
608
1505
  // person with the extensions permission (Settings → Extensions → Bookings).
@@ -638,27 +1535,144 @@ export default defineExtension({
638
1535
  promotionMinutes: {
639
1536
  type: "number",
640
1537
  label: "Waitlist stops (minutes before)",
641
- description: "Nobody is moved in from the waitlist after this (a later release).",
1538
+ description: "Nobody is moved in from the waitlist after this: a place freed later goes to whoever " +
1539
+ "books first.",
642
1540
  default: 120,
643
1541
  min: 0,
644
1542
  max: 10_080,
645
1543
  personApproves: true,
646
1544
  },
1545
+ dropInPrice: {
1546
+ type: "number",
1547
+ label: "Drop-in price",
1548
+ description: "What one class costs someone paying for it on the website, in the organisation's " +
1549
+ "currency, unless its class type sets its own. Empty: no drop-ins.",
1550
+ min: 0,
1551
+ max: 100_000,
1552
+ personApproves: true,
1553
+ },
1554
+ dropInHoldPercent: {
1555
+ type: "number",
1556
+ label: "Places held for unpaid drop-ins (percent)",
1557
+ description: "At most this share of a class's places (at least one) may be held at once for visitors " +
1558
+ "who have not paid yet. More are told to try again shortly.",
1559
+ default: 50,
1560
+ min: 0,
1561
+ max: 100,
1562
+ personApproves: true,
1563
+ },
647
1564
  reminderMinutes: {
648
1565
  type: "number",
649
1566
  label: "Reminder (minutes before)",
650
- description: "When members are reminded of a class (a later release).",
1567
+ description: "When members booked into a class are emailed a reminder, unless its class type sets " +
1568
+ "its own: at most two days (2,880 minutes) before.",
651
1569
  default: 180,
652
1570
  min: 0,
1571
+ max: 2_880,
1572
+ personApproves: true,
1573
+ },
1574
+ // Appointments' booking rules (stage 49), which a service's own values override.
1575
+ appointmentOpensDays: {
1576
+ type: "number",
1577
+ label: "Appointments: booking opens (days before)",
1578
+ description: "Clients may book a one-to-one session this many days ahead.",
1579
+ default: 28,
1580
+ min: 0,
1581
+ max: 365,
1582
+ personApproves: true,
1583
+ },
1584
+ appointmentClosesMinutes: {
1585
+ type: "number",
1586
+ label: "Appointments: booking closes (minutes before)",
1587
+ description: "Clients may book a session until this many minutes before it (720: 12 hours).",
1588
+ default: 720,
1589
+ min: 0,
653
1590
  max: 10_080,
654
1591
  personApproves: true,
655
1592
  },
1593
+ appointmentLateMinutes: {
1594
+ type: "number",
1595
+ label: "Appointments: late cancel from (minutes before)",
1596
+ description: "A cancel this close to a session's start is late: the session is used, with no fee " +
1597
+ "(1,440: 24 hours). Staff can give it back.",
1598
+ default: 1_440,
1599
+ min: 0,
1600
+ max: 10_080,
1601
+ personApproves: true,
1602
+ },
1603
+ bookingsUrl: {
1604
+ type: "text",
1605
+ label: "Where members see their bookings",
1606
+ description: "The page on your site where a signed-in member sees their bookings (https), linked from " +
1607
+ "every booking email, when it is on your site (Settings → Routine email). Empty: the emails " +
1608
+ "say to sign in.",
1609
+ // The link every member email carries: a person's to change, as the booking rules are.
1610
+ personApproves: true,
1611
+ },
1612
+ // Feedback after a class (stage 29 step 5, decision 4; ADR 0723): which Forms form members
1613
+ // are asked to answer, and when. Who is asked and what they are sent is a person's choice.
1614
+ feedbackForm: {
1615
+ type: "text",
1616
+ label: "Feedback form (its address)",
1617
+ description: "The address of a Forms form answered by personal link (open, published, Who may answer: " +
1618
+ "By personal link) that members are asked to " +
1619
+ "answer after a class they came to, with a link that works once and for a week; at most " +
1620
+ "once a month each, a child's to their parent or guardian. Empty: nobody is asked.",
1621
+ personApproves: true,
1622
+ },
1623
+ feedbackMinutes: {
1624
+ type: "number",
1625
+ label: "Feedback asked (minutes after the tick)",
1626
+ description: "How long after a member is ticked as come the feedback email goes.",
1627
+ default: 180,
1628
+ min: 0,
1629
+ max: 2_880,
1630
+ personApproves: true,
1631
+ },
1632
+ },
1633
+ // The coach role (spec 31, decision 10; ADR 0436): the day's classes and their lists, and ticking
1634
+ // names. Nothing else: no money (no holders, no desk payments, no orders), no people beyond the
1635
+ // names on a list, no bookings made or cancelled, no settings.
1636
+ roles: {
1637
+ coach: {
1638
+ label: "Coach",
1639
+ description: "Sees the day's classes and each class's list, and ticks who came (or marks who did " +
1640
+ "not). Nothing else: no money, no other people, no booking or cancelling, no settings.",
1641
+ permissions: ["bookings:coach"],
1642
+ read: ["bookings.class"],
1643
+ // Today's classes and lists only (spec 31: "read today's classes and their lists"): a class
1644
+ // starting today in its own zone, or running now (past midnight until it ends). Another
1645
+ // day's corrections are the desk's.
1646
+ today: {
1647
+ "bookings.class": { at: "startsAt", until: "endsAt", zone: "timezone" },
1648
+ "bookings.booking": { at: "class.startsAt", until: "class.endsAt", zone: "class.timezone" },
1649
+ },
1650
+ },
1651
+ },
1652
+ // The front desk's tools (ADR 0600): find people, book anyone (a walk-in too) into any class,
1653
+ // cancel for them, move them, give a use back, a class's full list and any day's classes. Any
1654
+ // member of staff holds them; an admin grants them to a coach, whose coach role they add to:
1655
+ // the coach's own list and ticks stay today's. Not cancelling a class (its own permission, and
1656
+ // a person's), not refunds (orders:refund), not people, orders, passes or memberships.
1657
+ // Appointments (stage 49, ADR 0764): `bookings:appointments` books, moves, cancels, marks and
1658
+ // reassigns one-to-one sessions, and reads any coach's day. Any member of staff holds it; an
1659
+ // admin grants it to a coach (a manager of the coaches).
1660
+ grantable: ["bookings:desk", "bookings:appointments"],
1661
+ grantableLabels: {
1662
+ "bookings:desk": "Front desk: find people; book, cancel and move classes and one-to-one sessions for " +
1663
+ "anyone; give a use back; mark sessions; see any day's classes and lists and every " +
1664
+ "coach's day with its clients. For a coach who also works the desk.",
1665
+ "bookings:appointments": "Appointments: book one-to-one sessions for clients, move, cancel and mark them, give a " +
1666
+ "session back, give a session to another coach, and see any coach's day. For a coach who " +
1667
+ "manages the others' sessions.",
656
1668
  },
657
1669
  tools: {
658
1670
  timetable,
659
1671
  classGet,
660
1672
  book,
1673
+ buy,
661
1674
  cancel,
1675
+ leaveWaitlist,
662
1676
  mine,
663
1677
  findPeople,
664
1678
  bookFor,
@@ -666,5 +1680,56 @@ export default defineExtension({
666
1680
  returnUse,
667
1681
  day,
668
1682
  classList,
1683
+ roster,
1684
+ markAttended,
1685
+ undoAttended,
1686
+ markNoShow,
1687
+ markAll,
1688
+ move,
1689
+ cancelClass,
1690
+ family,
1691
+ bookAppointment,
1692
+ moveAppointment,
1693
+ cancelAppointment,
1694
+ cancelAppointmentByUs,
1695
+ markAppointment,
1696
+ excuseAppointment,
1697
+ reassignAppointment,
1698
+ coachDay,
1699
+ },
1700
+ automations: bookingsAutomations,
1701
+ dashboards: bookingsDashboards,
1702
+ // Staff screens in the product's admin (stage 47, ADR 0660): the front desk, and a class's list
1703
+ // (a tab on the class, and in the navigation for a coach, who opens today's classes there). Each
1704
+ // is gated by the tools that decide who may work it (its main read and the write it is for; the
1705
+ // host refuses the rest): the desk, any member of staff or a coach granted `bookings:desk`; the
1706
+ // list, the coach role or any member (a viewer cannot tick). Never a customer's tool.
1707
+ screens: {
1708
+ desk: {
1709
+ label: "Front desk",
1710
+ block: "bookings-desk",
1711
+ export: "FrontDesk",
1712
+ nav: { group: "Bookings", order: 10 },
1713
+ opens: ["findPeople", "bookFor"],
1714
+ },
1715
+ classList: {
1716
+ label: "Class list",
1717
+ block: "bookings-class-list",
1718
+ export: "TodayClassList",
1719
+ nav: { group: "Bookings", order: 20 },
1720
+ opens: ["roster", "markAttended"],
1721
+ record: { object: "bookings.class", as: "classId" },
1722
+ },
1723
+ },
1724
+ // Its section of My account (stage 48, ADR 0710): shown to a member with a booking, or whose child
1725
+ // linked to them has one (a booking opens to guardians), the timetable with their bookings.
1726
+ portal: {
1727
+ bookings: {
1728
+ label: "Bookings",
1729
+ web: { block: "bookings-timetable", export: "Timetable" },
1730
+ native: { block: "bookings-native-timetable", export: "TimetableScreen" },
1731
+ order: 10,
1732
+ has: ["bookings.booking"],
1733
+ },
669
1734
  },
670
1735
  });