Fix timesheet sync overwriting future rota dates with empty data

Pull timesheets was writing source='timesheet' rows for future dates
(no clock-in data yet), giving ? / 0.00h and preventing rota sync
from ever healing those dates.

Three-part fix:
- Backend runTimesheetSync: cap end date to today before looping
- Frontend syncTimesheetData: cap end date to today before calling API
- Backend runRotaSync: only skip timesheet-sourced dates that are <= today,
  so any future dates accidentally marked as timesheet are self-healed
  next time rota sync runs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-23 12:08:36 +00:00
parent ffefa1914f
commit c19460ecb3
5 changed files with 34 additions and 26 deletions

View file

@ -56,10 +56,13 @@ export async function runRotaSync(from, to) {
}
}
// Skip dates already replaced with timesheet actuals
// Skip past dates already replaced with timesheet actuals (future timesheet rows are allowed through)
const today = fmtDate(new Date())
const existing = await getWorkforceShifts(from, to)
const timesheetDates = new Set(
Object.entries(existing).filter(([, d]) => d.source === 'timesheet').map(([date]) => date)
Object.entries(existing)
.filter(([date, d]) => d.source === 'timesheet' && date <= today)
.map(([date]) => date)
)
const dailyRows = []
@ -81,6 +84,10 @@ export async function runTimesheetSync(from, to) {
if (!from || !to) ({ from, to } = defaultTimesheetWindow())
// Never write timesheet rows for future dates — actual hours don't exist yet
const today = fmtDate(new Date())
if (to > today) to = today
const fromDate = new Date(from + 'T00:00:00')
const toDate = new Date(to + 'T00:00:00')