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:
parent
3c4bdd9a1c
commit
89ad3811da
2 changed files with 11 additions and 12 deletions
|
|
@ -58,13 +58,14 @@ export async function fetchSites() {
|
||||||
return res?.data ?? []
|
return res?.data ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch bookings spanning a date range.
|
// Fetch bookings whose stay overlaps the date window.
|
||||||
// list_type 'all' includes arrived, confirmed, unconfirmed, departed, blocked.
|
// 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) {
|
export async function fetchBookings(fromDate, toDate) {
|
||||||
const res = await callApi('bookings_list', {
|
const res = await callApi('bookings_list', {
|
||||||
period_from: `${fromDate} 00:00:00`,
|
period_from: `${fromDate} 00:00:00`,
|
||||||
period_to: `${toDate} 23:59:59`,
|
period_to: `${toDate} 23:59:59`,
|
||||||
list_type: 'all',
|
list_type: 'staying',
|
||||||
})
|
})
|
||||||
return res?.data ?? []
|
return res?.data ?? []
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,10 @@ export async function roomRoutes(app) {
|
||||||
const roomName = req.query.room
|
const roomName = req.query.room
|
||||||
const yesterday = dateOffset(viewDate, -1)
|
const yesterday = dateOffset(viewDate, -1)
|
||||||
const tomorrow = dateOffset(viewDate, +1)
|
const tomorrow = dateOffset(viewDate, +1)
|
||||||
const dayAfterTomorrow = dateOffset(viewDate, +2)
|
|
||||||
|
|
||||||
const [sites, bookings] = await Promise.all([
|
const [sites, bookings] = await Promise.all([
|
||||||
fetchSites(),
|
fetchSites(),
|
||||||
fetchBookings(yesterday, dayAfterTomorrow),
|
fetchBookings(yesterday, tomorrow),
|
||||||
])
|
])
|
||||||
|
|
||||||
if (!roomName) {
|
if (!roomName) {
|
||||||
|
|
@ -98,7 +97,7 @@ export async function roomRoutes(app) {
|
||||||
const classified = classifyRoom(site, bookings, viewDate, yesterday, tomorrow)
|
const classified = classifyRoom(site, bookings, viewDate, yesterday, tomorrow)
|
||||||
|
|
||||||
return {
|
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) },
|
site: { id: siteId, name: site.site_name, fields: Object.keys(site) },
|
||||||
booking_id_fields: idFields,
|
booking_id_fields: idFields,
|
||||||
total_bookings_fetched: bookings.length,
|
total_bookings_fetched: bookings.length,
|
||||||
|
|
@ -151,12 +150,11 @@ export async function roomRoutes(app) {
|
||||||
// Fetch from NewBook in parallel
|
// Fetch from NewBook in parallel
|
||||||
let sites, bookings, tasks
|
let sites, bookings, tasks
|
||||||
try {
|
try {
|
||||||
// Fetch bookings one day beyond tomorrow so tomorrow-arriving bookings appear
|
// list_type 'staying' includes bookings with arrival <= period_to,
|
||||||
// in nextBooking lookups (some NewBook regions exclude period_to-date arrivals).
|
// so fetching yesterday→tomorrow captures all adjacent-day brackets.
|
||||||
const dayAfterTomorrow = dateOffset(viewDate, +2)
|
|
||||||
;[sites, bookings, tasks] = await Promise.all([
|
;[sites, bookings, tasks] = await Promise.all([
|
||||||
fetchSites(),
|
fetchSites(),
|
||||||
fetchBookings(yesterday, dayAfterTomorrow),
|
fetchBookings(yesterday, tomorrow),
|
||||||
fetchTasks(yesterday, tomorrow),
|
fetchTasks(yesterday, tomorrow),
|
||||||
])
|
])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue