diff --git a/backend/src/lib/syncJobs.js b/backend/src/lib/syncJobs.js index d5802a0..4b477af 100644 --- a/backend/src/lib/syncJobs.js +++ b/backend/src/lib/syncJobs.js @@ -105,7 +105,14 @@ export async function runTimesheetSync(from, to) { const day = new Date(fromDate) while (day <= toDate) { const d = fmtDate(day) - dailyRows.push({ date: d, staff: byDate[d] || [], source: 'timesheet' }) + const staffForDate = byDate[d] || [] + // For today: only write a timesheet row if at least one shift has clocked out. + // An empty row would overwrite rota data with nothing while staff are still working. + if (d === today && staffForDate.length === 0) { + day.setDate(day.getDate() + 1) + continue + } + dailyRows.push({ date: d, staff: staffForDate, source: 'timesheet' }) day.setDate(day.getDate() + 1) } diff --git a/backend/src/lib/workforce.js b/backend/src/lib/workforce.js index 8faf987..19575d2 100644 --- a/backend/src/lib/workforce.js +++ b/backend/src/lib/workforce.js @@ -85,11 +85,17 @@ export async function fetchTimesheetShifts(from, to, deptIds) { const filtered = shifts.filter(s => deptIds.includes(String(s.department_id))) + const todayISO = new Date().toLocaleDateString('en-CA', { timeZone: 'Europe/London' }) + const byUser = {} for (const s of filtered) { const uid = String(s.user_id) if (!nameMap[uid]) continue const date = s.date // already 'YYYY-MM-DD' + + // Skip today's shifts with no finish time — still clocked in, hours unknown + if (date === todayISO && !s.finish) continue + const hrs = (s.finish && s.start) ? Math.max(0, (s.finish - s.start) / 3600 - (s.break_length || 0) / 60) : 0