Convert a Lead to a Family
Conversion is the bridge from the staging tables
to live data. It is reached from the Convert to Family… button on the
lead detail page (/admin/lead_convert.php?id=N), which disappears once the
lead is converted.
What the admin picks
The form opens with a preview table — a dry-run summary of what will happen: whether the parent will be created (“no login until invited”) or will adopt an existing account matched by email (“phone/address are filled in, nothing is overwritten with blanks”), what each student gets, and where a held payment will land.
Then, per lead student (already-converted students render as “Already converted — nothing more to choose here”):
- Instrument — a select over the real instrument catalog, preselected from the lead. When the family chose the wizard’s combined “Cello/Bass” option, the label says so and the admin picks which; inquiry students default to their first interest that maps to a real instrument (Bass → Double Bass, Guitar Ensemble → Guitar), or none.
- Date of birth — optional; the label notes the family-supplied “Class of” year if there is one.
- A reservation placement — a “Choose a time…” button opens the schedule
picker: the semester’s weekly grid with occupied cells unclickable, a
client-side fit check (“That would run into the next booking…”), and a
server-side advisory re-check (
schedule_slot_check.php). Placement is optional — “convert now and place them from the Schedule later” is always available, and is the only option when the semester has no location-teacher columns yet. The duration defaults to the lead’s lesson length (30 for inquiry students). - Payment target — shown only when the lead holds a payment: which student’s ledger the payment should land on.
An inquiry lead has no semester of its own, so placement uses the admin’s currently selected semester.
What the system does, in order
The eval (lead_convert_eval.php) runs conflict checks before anything is
written — deliberately, because conversion creates people before it books
slots, and a clash discovered mid-way would leave half-made records:
- Sibling vs. sibling — two students in this submission booked into the same teacher at overlapping times (each looks free on its own).
- Against the schedule — each pick is checked against existing reservations and hold blocks, with a specific message (“This teacher already has Name’s weekly slot at 10:00–10:30 am…”).
Then LeadManagement::convertLead runs, step by step:
- Parent — adopt-or-create by email. Adoption restores a soft-deleted
account if that’s what the email matches, and fills in only empty
fields — an existing account’s data is never blanked. Creation makes a
user with no password (
password_hash = '') and sends no email. - Students — for each lead student not yet converted: a user with no
email and no login, a student profile (DOB, class-of), instruments,
and the
parenthoodlink. Each student’sconverted_student_user_idis written immediately, so progress is durable. - Reservations — the slot is re-checked at booking time, then:
- the lead has paid (in full, or the first installment): the
reservation is created
confirmed, its lessons are generated and the semester charges are posted (plus the installment fee when the family chose the plan; the registration fee once per family); - the lead has not paid: it is created
pending_confirmation. No lessons are generated and nothing is charged; that happens when the reservation is later confirmed on the schedule.
- the lead has paid (in full, or the first installment): the
reservation is created
- Payment — if the lead holds a Stripe payment, it is recorded as
paymentcredits: each student confirmed in step 3 is credited up to what they now owe. Anything left over (or the whole payment, when no time was chosen) stays with an only child as their credit; in a family with more than one child it becomes the parent’s parent credit, which is used automatically whenever one of their children is charged. There is no student to pick. So a family that paid in full lands at a zero balance, and an installment family lands confirmed with the rest owing. A check on the Stripe reference guarantees one payment can never be recorded twice; if it is already on a ledger, the admin sees “This payment is already on a ledger — not recorded again.” - Mark converted — the lead gets
status='converted',converted_parent_user_id, andconverted_at(preserved on re-entry).
The success flash summarizes it: “Converted! Created the parent account · 2 students · 1 reservation placed in Spring 2027 (confirmed — charges posted and the payment applied) · payment recorded on the ledger.” For an unpaid lead it reads “(pending confirmation)”.
Re-entry and failure behavior
Conversion deliberately runs without one big transaction — each step commits as it goes — precisely so it is safe to run again:
- Already-converted students are skipped; the parent adoption is an upsert; profile writes never overwrite with nulls; instruments and parent links are insert-ignore; the payment insert is unique-guarded.
- If a slot conflict slips past the pre-flight (someone books it between check and commit), the people are already created but the lead is not marked converted — so the Convert button stays available and re-running continues where it left off.
- The sharp edge: if student 1’s reservation was created and student 2’s then failed, resubmitting with student 1’s pick still filled will conflict with the reservation it just created. Clear student 1’s pick before resubmitting. (Instrument/DOB choices for already-converted students are ignored on re-entry — fix those on the student record instead.)
After conversion: invite the family
Conversion creates accounts but no logins and no emails. Giving the family portal access is a separate, manual step: the Send Account Invite button on the lead detail page (only rendered while the parent has an email and no password). Forgetting it leaves a family that exists in the system but cannot sign in — see Process Leads for how the invite works.
