diff --git a/backend/src/lib/booking-flow.js b/backend/src/lib/booking-flow.js index e02dd97..5f3b5b1 100644 --- a/backend/src/lib/booking-flow.js +++ b/backend/src/lib/booking-flow.js @@ -89,6 +89,10 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow, o // Determine flow type let flowType = 'vacant' + // True when primaryBooking is a historical depart-only record (set below) rather + // than a booking that actually occupies viewDate — the room was vacant that night. + let isPastDepartureRecord = false + if (primaryBooking) { const status = (primaryBooking.booking_status || '').toLowerCase() if (status === 'blocked') { @@ -113,6 +117,7 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow, o } else if (effectiveDeparting && opts.past) { primaryBooking = effectiveDeparting flowType = 'depart' + isPastDepartureRecord = true } const arrivalDate = primaryBooking ? toDateStr(primaryBooking.booking_arrival) : null @@ -158,7 +163,10 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow, o flow_type: flowType, booking: primaryBooking, - spans_previous: isVacantFlow + // A past-departure record only marks that a checkout happened on viewDate — it + // never occupied the night before viewDate, so it must not merge with the prior + // card the way a booking that's still actively occupying viewDate would. + spans_previous: (isVacantFlow || isPastDepartureRecord) ? prevVacant : !!primaryBooking && !!arrivalDate && arrivalDate < viewDate, spans_next: isVacantFlow ? nextVacant : spansNext,