-
Notifications
You must be signed in to change notification settings - Fork 0
Attendance
The attendance module covers clock-in and clock-out, breaks, working from home, and pre-logged late arrivals. Everything is keyed on the user, the work date, and the user's timezone offset, so a clock-in at 09:00 local time is always 09:00 local time when it is shown back.
The dashboard shows a single big button: Clock In when the user is not yet at work, Clock Out when they are. A clock-in writes a new row to attendance with clock_in_at set to now() and work_date set to the user's local date. A clock-out updates the same row with clock_out_at and a computed total_hours. Breaks are stored as a JSON array of { started_at, ended_at } pairs on the same row.
While the user is clocked in, the dashboard shows a live Hh Mm Ss counter that ticks every second. The client computes the value from clock_in_at and the cumulative break time so the server is not hit every second. Reloading the page or switching device picks the same value up because the source of truth is the row in attendance.
A worker who knows they will be late can log it the night before from the dashboard. The form writes running_late = true, late_reason, and an optional expected_arrival_time to the attendance row for the target date, creating the row if it does not exist. The team calendar shows the entry in amber. An email goes to the admin notification address so the front desk knows in advance.
The dashboard has a Work From Home toggle. Switching it on writes is_wfh = true and a captured wfh_reason to the attendance row for today. The calendar shows WFH days, and an email is sent to the address in WFH_NOTIFY_EMAIL so reception knows not to expect the person at the door.
If a user clocks in after their work-schedule start time plus the grace period, the row is flagged as a late arrival. The flag drives the late-arrival report and the dashboard banner. A user who pre-logged running late is not double-flagged.
If an entry is wrong, the user opens the Corrections page and submits a request describing what needs to change. A manager approves or declines from the admin area, and the change is applied with an audit-log entry pointing at the original row.
The main table is attendance(user_id, work_date, clock_in_at, clock_out_at, total_hours, breaks JSONB, running_late BOOL, late_reason TEXT, expected_arrival_time TIME, is_wfh BOOL, wfh_reason TEXT, status TEXT). There is exactly one row per user per work date. Row Level Security ensures employees see only their own rows, while admin, accounts, and director can read across the team.