Fix today gap + future date visual drop after pull timesheets
runRotaSync: only protect today's timesheet row when it has real clocked-out hours (hours > 0), so stale ?/0h rows and empty rows are healed by the next rota sync without needing manual intervention. runTimesheetSync: revert to SKIP for today when no completed shifts — writing an empty row was overwriting the rota schedule with nothing. Frontend: fetch wfShifts for the full week after a timesheet pull (not just up to today), so future rota rows aren't dropped from state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cbc9db67bc
commit
cae0f48d79
5 changed files with 24 additions and 17 deletions
|
|
@ -56,12 +56,17 @@ export async function runRotaSync(from, to) {
|
|||
}
|
||||
}
|
||||
|
||||
// Skip past dates already replaced with timesheet actuals (future timesheet rows are allowed through)
|
||||
// Skip dates already replaced with confirmed timesheet actuals
|
||||
const today = fmtDate(new Date())
|
||||
const existing = await getWorkforceShifts(from, to)
|
||||
const timesheetDates = new Set(
|
||||
Object.entries(existing)
|
||||
.filter(([date, d]) => d.source === 'timesheet' && date <= today)
|
||||
.filter(([date, d]) => {
|
||||
if (d.source !== 'timesheet') return false
|
||||
if (date > today) return false // never protect future dates
|
||||
if (date === today) return d.staff?.some(s => s.hours > 0) // only protect today if real clocked-out hours exist
|
||||
return true // always protect past timesheet dates
|
||||
})
|
||||
.map(([date]) => date)
|
||||
)
|
||||
|
||||
|
|
@ -107,12 +112,13 @@ export async function runTimesheetSync(from, to) {
|
|||
const d = fmtDate(day)
|
||||
const staffForDate = byDate[d] || []
|
||||
if (d === today && staffForDate.length === 0) {
|
||||
// Nobody has clocked out yet — write a workforce-sourced row so this clears any
|
||||
// stale timesheet entry and rota sync can overwrite with schedule data again
|
||||
dailyRows.push({ date: d, staff: [], source: 'workforce' })
|
||||
} else {
|
||||
dailyRows.push({ date: d, staff: staffForDate, source: 'timesheet' })
|
||||
// Nobody has clocked out yet — leave the existing DB row intact so rota schedule
|
||||
// data stays visible. Rota sync will heal any stale timesheet row for today
|
||||
// because runRotaSync only protects today when it has real clocked-out hours.
|
||||
day.setDate(day.getDate() + 1)
|
||||
continue
|
||||
}
|
||||
dailyRows.push({ date: d, staff: staffForDate, source: 'timesheet' })
|
||||
day.setDate(day.getDate() + 1)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue