From 16c70f5ba423a47c7c10e0a463c6a88a08062083 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Thu, 6 Aug 2026 14:11:40 +0000 Subject: [PATCH] Fix past-departure room cards incorrectly merging with prior night MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A past-departure record only marks that a checkout happened on the viewed date — it never occupied the night before, so it must not merge with the previous card the way a booking still actively occupying viewDate would. Co-Authored-By: Claude Sonnet 5 --- backend/src/lib/booking-flow.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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,