Room planner: fix bookings_list to use list_type=staying

The original WordPress plugin (class-hhdl-ajax.php line 409) uses
list_type='staying', which returns bookings whose stay *overlaps* the
date window (arrival <= period_to AND departure >= period_from).

Using list_type='all' was returning bookings filtered by booking-placed
date (or a flat dump), completely missing tomorrow-arriving bookings
that are needed for right-bracket display. Switching to 'staying' with
the original yesterday→tomorrow window gives 50 bookings vs 89 before,
and correctly includes adjacent-day arrivals.

Verified on dev: room 101 now shows confirmed right-bracket for July 5
arrival, room 102 now correctly classifies as back-to-back.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-04 12:18:26 +00:00
parent 3c4bdd9a1c
commit 89ad3811da
2 changed files with 11 additions and 12 deletions

View file

@ -58,13 +58,14 @@ export async function fetchSites() {
return res?.data ?? []
}
// Fetch bookings spanning a date range.
// list_type 'all' includes arrived, confirmed, unconfirmed, departed, blocked.
// Fetch bookings whose stay overlaps the date window.
// list_type 'staying' returns bookings where arrival <= period_to AND departure >= period_from,
// so a booking arriving on period_to is included. This matches the original plugin behaviour.
export async function fetchBookings(fromDate, toDate) {
const res = await callApi('bookings_list', {
period_from: `${fromDate} 00:00:00`,
period_to: `${toDate} 23:59:59`,
list_type: 'all',
list_type: 'staying',
})
return res?.data ?? []
}

View file

@ -54,13 +54,12 @@ export async function roomRoutes(app) {
const viewDate = req.query.date || new Date().toISOString().slice(0, 10)
const roomName = req.query.room
const yesterday = dateOffset(viewDate, -1)
const tomorrow = dateOffset(viewDate, +1)
const dayAfterTomorrow = dateOffset(viewDate, +2)
const yesterday = dateOffset(viewDate, -1)
const tomorrow = dateOffset(viewDate, +1)
const [sites, bookings] = await Promise.all([
fetchSites(),
fetchBookings(yesterday, dayAfterTomorrow),
fetchBookings(yesterday, tomorrow),
])
if (!roomName) {
@ -98,7 +97,7 @@ export async function roomRoutes(app) {
const classified = classifyRoom(site, bookings, viewDate, yesterday, tomorrow)
return {
view_date: viewDate, yesterday, tomorrow, day_after_tomorrow: dayAfterTomorrow,
view_date: viewDate, yesterday, tomorrow,
site: { id: siteId, name: site.site_name, fields: Object.keys(site) },
booking_id_fields: idFields,
total_bookings_fetched: bookings.length,
@ -151,12 +150,11 @@ export async function roomRoutes(app) {
// Fetch from NewBook in parallel
let sites, bookings, tasks
try {
// Fetch bookings one day beyond tomorrow so tomorrow-arriving bookings appear
// in nextBooking lookups (some NewBook regions exclude period_to-date arrivals).
const dayAfterTomorrow = dateOffset(viewDate, +2)
// list_type 'staying' includes bookings with arrival <= period_to,
// so fetching yesterday→tomorrow captures all adjacent-day brackets.
;[sites, bookings, tasks] = await Promise.all([
fetchSites(),
fetchBookings(yesterday, dayAfterTomorrow),
fetchBookings(yesterday, tomorrow),
fetchTasks(yesterday, tomorrow),
])
} catch (err) {