Provided: Calendar Day, Selected Client, Client Only, Selected Start, Session Choice, Use Planned Duration, Actual Minutes, Session Notes, Added Bookings, Added Logs
Outputs: Appointments, Session Log, Daily Calendar, Client History

# Personal training planner

Plan sessions for three fictional clients, then record what each client did. This browser saves your bookings and session logs for your next visit.

Calendar Day = 30 November 2026
Selected Client = "Maya Reed"
Client Only = false
Selected Start = "11:00"
Session Choice = "Strength circuit"
Use Planned Duration = true
Actual Minutes = 45
Session Notes = ""

Client Directory = table(["Client"], [["Maya Reed"], ["Ellis Park"], ["Jo Silva"]])
Client List = Client Directory.Client
Hourly Slots = table(["Start"], [["07:00"], ["08:00"], ["09:00"], ["10:00"], ["11:00"], ["12:00"], ["13:00"], ["14:00"], ["15:00"], ["16:00"], ["17:00"], ["18:00"]])

Example Bookings = table(["Day", "Start", "Client", "Session", "Minutes"], [[23 November 2026, "09:00", "Maya Reed", "Strength circuit", 45], [24 November 2026, "10:00", "Ellis Park", "Steady cardio", 30], [25 November 2026, "14:00", "Jo Silva", "Mixed conditioning", 50], [30 November 2026, "09:00", "Maya Reed", "Strength circuit", 45], [30 November 2026, "10:00", "Ellis Park", "Steady cardio", 30], [30 November 2026, "14:00", "Jo Silva", "Mixed conditioning", 50], [1 December 2026, "08:00", "Jo Silva", "Steady cardio", 30], [1 December 2026, "12:00", "Maya Reed", "Mixed conditioning", 50], [2 December 2026, "10:00", "Ellis Park", "Strength circuit", 45]])
Example Logs = table(["Day", "Start", "Client", "Session", "Minutes", "Notes"], [[23 November 2026, "09:00", "Maya Reed", "Strength circuit", 42, "Completed three rounds. Try the longer carry next time."], [24 November 2026, "10:00", "Ellis Park", "Steady cardio", 30, "Chose the bike for the steady block."], [25 November 2026, "14:00", "Jo Silva", "Mixed conditioning", 48, "Finished four rounds. Keep the same rowing pace."]])
Added Bookings = table(["Day", "Start", "Client", "Session", "Minutes"], [])
Added Logs = table(["Day", "Start", "Client", "Session", "Minutes", "Notes"], [])
Appointments = append(Example Bookings, Added Bookings)
Session Log = append(Example Logs, Added Logs)

## Client calendar

='''Try the open **11:00** slot on **30 November 2026**, or choose Maya’s **09:00** booking to log a session.''' if Calendar Day == 30 November 2026 and Selected Client == "Maya Reed" and count(Added Bookings) == 0 and count(Added Logs) == 0

field "Calendar date" sets Calendar Day

choice "Client" sets Selected Client from Client List

checkbox "Show only this client’s appointments" sets Client Only

Day Book = select * from Appointments where Day = Calendar Day

~~~tiles
function calendar_slot(slot)
    Booked = select * from Day Book where Start = slot.Start
    return [slot.Start, Booked[1].Client, Booked[1].Session, Booked[1].Minutes] if count(Booked) > 0 else [slot.Start, null, null, null]
end
~~~

Ordered Slots = table(["Start", "Client", "Session", "Minutes"], map_rows(Hourly Slots, calendar_slot))
Day Calendar = select * from Ordered Slots where Client != null
Client Calendar = select * from Day Calendar where Client = Selected Client
Daily Calendar = Client Calendar if Client Only else Day Calendar

### =Calendar Day

='''
=(Daily Calendar)
''' if count(Daily Calendar) > 0 else '''No appointments for **=Selected Client** on this date.''' if Client Only else '''The calendar is open for this date.'''

## Session desk

[View the session library](training-sessions.lmd) as Library

Available Sessions = if_error(Library.Sessions, table(["Session", "Focus"], []))
Session List = Available Sessions.Session
Session Blocks = if_error(Library.Blocks, table(["Session", "Block", "Activity", "Minutes"], []))

choice "Start time" sets Selected Start from Hourly Slots

At This Time = select * from Day Book where Start = Selected Start
Slot Is Free = count(At This Time) == 0
Booked Client = At This Time[1].Client if not Slot Is Free
Booked Minutes = At This Time[1].Minutes if not Slot Is Free
Own Booking = not Slot Is Free and Booked Client == Selected Client
Active Session = At This Time[1].Session if not Slot Is Free else Session Choice
Session Focus = Focus from Available Sessions where Session = Active Session
Session Plan = select Block, Activity, Minutes from Session Blocks where Session = Active Session
Planned Minutes = sum(Session Plan.Minutes) if count(Session Plan) > 0 else 0
Available Slot = select * from Hourly Slots where Start = Selected Start
Known Clients = select * from Client Directory where Client = Selected Client
Can Book = Slot Is Free and count(Available Slot) == 1 and count(Known Clients) == 1 and not is_null(Session Focus) and is_int(Planned Minutes) and Planned Minutes >= 1 and Planned Minutes <= 60
Booking Row = [Calendar Day, Selected Start, Selected Client, Session Choice, Planned Minutes]

='''
**=Selected Start** is open. Choose a session for **=Selected Client**.

choice "Session" sets Session Choice from Session List
''' if Slot Is Free and count(Available Sessions) > 0 else '''The linked session library has no sessions to book.''' if Slot Is Free else '''**=Selected Client** is booked at **=Selected Start**.''' if Own Booking else '''**=Booked Client** is booked at **=Selected Start**. Choose another time for **=Selected Client**.'''

='''
### =Active Session · =Planned Minutes minutes

=Session Focus

=(Session Plan)
''' if (Slot Is Free and_or Own Booking) and count(Session Plan) > 0 else '''The **=Active Session** booking is for **=Booked Minutes minutes**. Its plan is no longer in the session library.''' if Own Booking

='''
button "Book session" calls Book Session using (Booking Row) if Can Book else alerts "Choose a client, an open time and a session that fits the one-hour slot."
''' if Slot Is Free and count(Available Sessions) > 0

Logged Slot = select * from Session Log where Day = Calendar Day and Start = Selected Start
Already Logged = count(Logged Slot) > 0
Recorded Minutes = Booked Minutes if Use Planned Duration else Actual Minutes
Valid Minutes = is_int(Recorded Minutes) and Recorded Minutes >= 1 and Recorded Minutes <= 180
Can Log = Own Booking and not Already Logged and Valid Minutes
Log Row = [Calendar Day, Selected Start, Selected Client, Active Session, Recorded Minutes, Session Notes]

='''
### Record the session

checkbox "Use booked duration" sets Use Planned Duration
''' if Own Booking and not Already Logged

='''Recording **=Booked Minutes minutes**.''' if Own Booking and not Already Logged and Use Planned Duration

='''
field "Actual minutes" sets Actual Minutes
''' if Own Booking and not Already Logged and not Use Planned Duration

='''
field "Session notes" sets Session Notes

button "Log session" calls Log Session using (Log Row) if Can Log else alerts "Enter a whole number of minutes from 1 to 180."
''' if Own Booking and not Already Logged else '''This session is in the log below.''' if Own Booking and Already Logged

## Session log for =Selected Client

Client History = select Day, Start, Session, Minutes, Notes from Session Log where Client = Selected Client
Completed Count = count(Client History)
Completed Minutes = sum(Client History.Minutes) if Completed Count > 0 else 0
Session Word = "session" if Completed Count == 1 else "sessions"

='''
**=Completed Count =Session Word**, **=Completed Minutes minutes** recorded across all dates.

=(Client History)
''' if Completed Count > 0 else '''The first completed session for **=Selected Client** will appear here.'''
