Fix week nav anchor, timesheet sync range, and in-progress clock entries

- Week Prev/Next/Today now anchor to this Monday instead of today, so
  navigation stays week-aligned
- Timesheet sync no longer pulls into the future — capped at today
  while shift-fetching still covers the full displayed week
- Roster pivot skips entries that are still clocked in with no
  clock-out yet, instead of showing them as 0 hours

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-08-06 14:11:40 +00:00
parent 36ca4e1996
commit 47bd54afec
3 changed files with 18 additions and 9 deletions

View file

@ -7,6 +7,12 @@ function todayStr() {
const d = new Date();
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
function thisMonday() {
const d = new Date();
const diff = (d.getDay() + 6) % 7; // days since Monday (Mon=0 … Sun=6)
d.setDate(d.getDate() - diff);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
function offsetDate(s, days) {
const [y, m, d] = s.split('-').map(Number);
const dt = new Date(y, m - 1, d);
@ -137,7 +143,7 @@ export function Planner() {
setLoading(true);
setError('');
const today = todayStr();
const ws = weekStartRef.current || today;
const ws = weekStartRef.current || thisMonday();
const wsEnd = offsetDate(ws, 6);
const lv = lvArg !== undefined ? (lvArg || offsetDate(today, -1)) : (lastViewed || savedLastReviewed || offsetDate(today, -1));
try {
@ -199,8 +205,7 @@ export function Planner() {
return () => window.removeEventListener('beforeunload', onUnload);
}, [staff, pickup, adjustments]);
function handleWeekOffset(days) {
const today = todayStr();
const newStart = offsetDate(weekStartRef.current || today, days);
const newStart = offsetDate(weekStartRef.current || thisMonday(), days);
weekStartRef.current = newStart;
setWeekStart(newStart);
stampLastReviewed();
@ -272,11 +277,13 @@ export function Planner() {
if (!bookings)
return;
const start = bookings.dates[0];
const end = bookings.dates[bookings.dates.length - 1];
const today = todayStr();
const end = bookings.dates[bookings.dates.length - 1] > today ? today : bookings.dates[bookings.dates.length - 1];
setTimesheetSyncing(true);
try {
await syncTimesheets(start, end);
const shifts = await getWorkforceShifts(start, end);
const wsEnd = bookings.dates[bookings.dates.length - 1];
const shifts = await getWorkforceShifts(start, wsEnd);
setWfShifts(shifts);
flash('Timesheets pulled from Workforce');
}
@ -303,8 +310,7 @@ export function Planner() {
// ── Required hours (memoised on state changes) ────────────────────────────
const required = bookings ? calcRequired(bookings, timeReqs, pickup, generalTasks, adjustments) : null;
// ── Render ──────────────────────────────────────────────────────────────────
const today = todayStr();
const displayWeekStart = weekStart || today;
const displayWeekStart = weekStart || thisMonday();
return (_jsxs("div", { style: { padding: '1.5rem', maxWidth: '1600px' }, children: [_jsxs("div", { style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '0.75rem', marginBottom: '1.25rem' }, children: [_jsxs("div", { children: [_jsx("h1", { style: { fontSize: '1.15rem', fontWeight: 700, color: 'var(--text-dark)' }, children: "Housekeeping Planner" }), bookings && (_jsxs("p", { style: { fontSize: '0.8rem', color: 'var(--text-mid)', marginTop: '0.1rem' }, children: [fmtDate(bookings.dates[0]), " \u2013 ", fmtDate(bookings.dates[bookings.dates.length - 1])] }))] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '0.4rem', marginLeft: 'auto', flexWrap: 'wrap' }, children: [_jsx(CtrlBtn, { onClick: () => handleWeekOffset(-7), children: "\u2039 Prev" }), _jsx(CtrlBtn, { onClick: handleWeekToday, primary: true, children: "Today" }), _jsx(CtrlBtn, { onClick: () => handleWeekOffset(7), children: "Next \u203A" }), _jsx("input", { type: "date", value: displayWeekStart, onChange: e => { if (e.target.value) {
const v = e.target.value;
weekStartRef.current = v;
@ -458,6 +464,9 @@ function pivotWfShifts(wfShifts, dates) {
if (!day)
continue;
for (const s of day.staff) {
// Skip in-progress timesheet entries — clocked in but no clock-out time yet
if (s.times === '?' && s.hours === 0)
continue;
if (!members[s.id])
members[s.id] = { id: s.id, name: s.name, days: {} };
members[s.id].days[date] = { hours: s.hours, times: s.times, status: s.status };