Let parents register once and book for their children

A parent registers once and manages lessons for one or more children, who
need no login of their own. A child is a real wp_users row with the student
role but no usable login — so student_id keeps meaning "a WordPress user"
on every table, and booking, credits, policies and enrolments work unchanged.
A us_guardians link table maps guardian to child.

The signup form gains a parent/guardian tick that reveals a block per child,
with the account-signup questions asked per child rather than per guardian
— they describe the student, not the account holder. Signup policies are
recorded once per child with the guardian as the acceptor, which is the
record that actually means something. A family that half-creates is rolled
back entirely rather than leaving a guardian who cannot re-register.

The booking and enrolment forms gain a "Who is this for?" picker listing
children first, so the default selection is never the parent — booking for
the wrong child is correctable, quietly billing a parent for their kid's
lesson is not. POST /bookings and POST /enrollments take an optional
student_id honoured only for that child's guardian; anything else is a 403.
That check is the authorisation boundary of the feature.

Payments and credits gain a payer: the charge names the child it was for and
the guardian who owes it, so per-child reporting is unchanged while notices,
receipts and the payment step reach the parent. Credit is held by the payer,
so one child's cancellation can settle a sibling's charge, and the daily
billing scan sends a guardian one notice covering every child.

Closes #132

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
2026-07-29 16:07:52 -03:00
co-authored by Claude Opus 5
parent c25260a367
commit b772e1811e
71 changed files with 4192 additions and 191 deletions
+28
View File
@@ -39,6 +39,13 @@ class Payment {
public readonly string $registrationType,
public readonly int $registrationId,
public readonly float $amount,
/**
* The account that owes this charge — a child's guardian, or 0 meaning
* "the student themselves". Zero rather than a copy of `studentId` so
* every payment written before guardian accounts existed reads back with
* its original meaning without a data migration.
*/
public readonly int $payerId = 0,
public readonly string $currency = 'CAD',
public readonly string $method = self::METHOD_ETRANSFER,
public readonly string $status = self::STATUS_PENDING,
@@ -64,6 +71,7 @@ class Payment {
registrationType: Val::string( $row->registration_type ),
registrationId: Val::int( $row->registration_id ),
amount: Val::float( $row->amount ),
payerId: Val::int( $row->payer_id ?? 0 ),
currency: Val::string( $row->currency ),
method: Val::string( $row->method ),
status: Val::string( $row->status ),
@@ -87,6 +95,25 @@ class Payment {
return self::STATUS_PAID === $this->status;
}
/**
* Who actually owes this charge: the recorded payer, falling back to the
* student. Every caller that needs a person to bill, receipt or credit goes
* through here rather than reading `payerId` directly, so the `0` default
* never leaks out as a user id.
*/
public function payerOrStudent(): int {
return $this->payerId > 0 ? $this->payerId : $this->studentId;
}
/**
* Whether someone other than the student is paying — a guardian. Drives the
* "paid by" line on admin screens, which is noise when they are the same
* person.
*/
public function hasSeparatePayer(): bool {
return $this->payerId > 0 && $this->payerId !== $this->studentId;
}
/**
* Whether this payment was generated by the daily billing scan (weekly /
* monthly) rather than taken at registration. Scheduled payments carry a due
@@ -134,6 +161,7 @@ class Payment {
return [
'id' => $this->id,
'student_id' => $this->studentId,
'payer_id' => $this->payerOrStudent(),
'instructor_id' => $this->instructorId,
'registration_type' => $this->registrationType,
'etransfer_email' => $this->etransferEmail,