Fix NewBook reports using invented bookings_list params and field names
Arrivals, departures, stayovers, and bookings-by-source were sending request params (arrival_date_from, departure_date_from, stayover_date_from) and reading response fields (arrival_date, booking_ref, no_nights) that don't exist in NewBook's API — causing API errors. Switched to the real bookings_list contract (period_from/period_to/list_type) and field names (booking_arrival, booking_departure, reference, booking_length, etc.) already proven working in room-planner, hvac, and kitchen's integrations. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
51b6142651
commit
d1c50c77d0
4 changed files with 61 additions and 37 deletions
|
|
@ -8,22 +8,28 @@ export default {
|
||||||
|
|
||||||
async run({ dateFrom, dateTo }, { newbook }) {
|
async run({ dateFrom, dateTo }, { newbook }) {
|
||||||
const data = await newbook.callApi('bookings_list', {
|
const data = await newbook.callApi('bookings_list', {
|
||||||
arrival_date_from: dateFrom,
|
period_from: `${dateFrom} 00:00:00`,
|
||||||
arrival_date_to: dateTo,
|
period_to: `${dateTo} 23:59:59`,
|
||||||
|
list_type: 'staying',
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = (data?.data ?? []).map(b => ({
|
const bookings = (data?.data ?? []).filter(b => {
|
||||||
ref: b.booking_ref ?? b.id,
|
const arrival = (b.booking_arrival ?? '').slice(0, 10)
|
||||||
|
return arrival >= dateFrom && arrival <= dateTo
|
||||||
|
})
|
||||||
|
|
||||||
|
const rows = bookings.map(b => ({
|
||||||
|
ref: b.reference ?? b.booking_reference ?? b.id,
|
||||||
guest: b.guest_name ?? `${b.first_name ?? ''} ${b.last_name ?? ''}`.trim(),
|
guest: b.guest_name ?? `${b.first_name ?? ''} ${b.last_name ?? ''}`.trim(),
|
||||||
arrival: b.arrival_date,
|
arrival: b.booking_arrival,
|
||||||
departure: b.departure_date,
|
departure: b.booking_departure,
|
||||||
nights: b.nights ?? b.no_nights,
|
nights: b.booking_length ?? b.nights,
|
||||||
room: b.site_name ?? b.room_name ?? b.site_id,
|
room: b.site_name ?? b.site_id,
|
||||||
adults: b.adults ?? b.no_adults,
|
adults: b.booking_adults ?? b.adults,
|
||||||
children: b.children ?? b.no_children ?? 0,
|
children: b.booking_children ?? b.children ?? 0,
|
||||||
source: b.booking_source ?? b.channel,
|
source: b.booking_source ?? b.channel,
|
||||||
status: b.booking_status ?? b.status,
|
status: b.status,
|
||||||
total: b.booking_total ?? b.total_price,
|
total: b.total,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,23 @@ export default {
|
||||||
|
|
||||||
async run({ dateFrom, dateTo }, { newbook }) {
|
async run({ dateFrom, dateTo }, { newbook }) {
|
||||||
const data = await newbook.callApi('bookings_list', {
|
const data = await newbook.callApi('bookings_list', {
|
||||||
arrival_date_from: dateFrom,
|
period_from: `${dateFrom} 00:00:00`,
|
||||||
arrival_date_to: dateTo,
|
period_to: `${dateTo} 23:59:59`,
|
||||||
|
list_type: 'staying',
|
||||||
})
|
})
|
||||||
|
|
||||||
const bookings = data?.data ?? []
|
const bookings = (data?.data ?? []).filter(b => {
|
||||||
|
const arrival = (b.booking_arrival ?? '').slice(0, 10)
|
||||||
|
return arrival >= dateFrom && arrival <= dateTo
|
||||||
|
})
|
||||||
const grouped = {}
|
const grouped = {}
|
||||||
|
|
||||||
for (const b of bookings) {
|
for (const b of bookings) {
|
||||||
const source = b.booking_source ?? b.channel ?? 'Unknown'
|
const source = b.booking_source ?? b.channel ?? 'Unknown'
|
||||||
if (!grouped[source]) grouped[source] = { bookings: 0, nights: 0, revenue: 0 }
|
if (!grouped[source]) grouped[source] = { bookings: 0, nights: 0, revenue: 0 }
|
||||||
grouped[source].bookings++
|
grouped[source].bookings++
|
||||||
grouped[source].nights += parseInt(b.nights ?? b.no_nights ?? 0) || 0
|
grouped[source].nights += parseInt(b.booking_length ?? b.nights ?? 0) || 0
|
||||||
grouped[source].revenue += parseFloat(b.booking_total ?? b.total_price ?? 0) || 0
|
grouped[source].revenue += parseFloat(b.total ?? 0) || 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const rows = Object.entries(grouped)
|
const rows = Object.entries(grouped)
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,26 @@ export default {
|
||||||
|
|
||||||
async run({ dateFrom, dateTo }, { newbook }) {
|
async run({ dateFrom, dateTo }, { newbook }) {
|
||||||
const data = await newbook.callApi('bookings_list', {
|
const data = await newbook.callApi('bookings_list', {
|
||||||
departure_date_from: dateFrom,
|
period_from: `${dateFrom} 00:00:00`,
|
||||||
departure_date_to: dateTo,
|
period_to: `${dateTo} 23:59:59`,
|
||||||
|
list_type: 'staying',
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = (data?.data ?? []).map(b => ({
|
const bookings = (data?.data ?? []).filter(b => {
|
||||||
ref: b.booking_ref ?? b.id,
|
const departure = (b.booking_departure ?? '').slice(0, 10)
|
||||||
|
return departure >= dateFrom && departure <= dateTo
|
||||||
|
})
|
||||||
|
|
||||||
|
const rows = bookings.map(b => ({
|
||||||
|
ref: b.reference ?? b.booking_reference ?? b.id,
|
||||||
guest: b.guest_name ?? `${b.first_name ?? ''} ${b.last_name ?? ''}`.trim(),
|
guest: b.guest_name ?? `${b.first_name ?? ''} ${b.last_name ?? ''}`.trim(),
|
||||||
arrival: b.arrival_date,
|
arrival: b.booking_arrival,
|
||||||
departure: b.departure_date,
|
departure: b.booking_departure,
|
||||||
nights: b.nights ?? b.no_nights,
|
nights: b.booking_length ?? b.nights,
|
||||||
room: b.site_name ?? b.room_name ?? b.site_id,
|
room: b.site_name ?? b.site_id,
|
||||||
source: b.booking_source ?? b.channel,
|
source: b.booking_source ?? b.channel,
|
||||||
status: b.booking_status ?? b.status,
|
status: b.status,
|
||||||
total: b.booking_total ?? b.total_price,
|
total: b.total,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,27 @@ export default {
|
||||||
|
|
||||||
async run({ dateFrom, dateTo }, { newbook }) {
|
async run({ dateFrom, dateTo }, { newbook }) {
|
||||||
const data = await newbook.callApi('bookings_list', {
|
const data = await newbook.callApi('bookings_list', {
|
||||||
stayover_date_from: dateFrom,
|
period_from: `${dateFrom} 00:00:00`,
|
||||||
stayover_date_to: dateTo,
|
period_to: `${dateTo} 23:59:59`,
|
||||||
|
list_type: 'staying',
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = (data?.data ?? []).map(b => ({
|
// In-house for the whole window — arrived before it started, still there after it ends.
|
||||||
ref: b.booking_ref ?? b.id,
|
const bookings = (data?.data ?? []).filter(b => {
|
||||||
|
const arrival = (b.booking_arrival ?? '').slice(0, 10)
|
||||||
|
const departure = (b.booking_departure ?? '').slice(0, 10)
|
||||||
|
return arrival < dateFrom && departure > dateTo
|
||||||
|
})
|
||||||
|
|
||||||
|
const rows = bookings.map(b => ({
|
||||||
|
ref: b.reference ?? b.booking_reference ?? b.id,
|
||||||
guest: b.guest_name ?? `${b.first_name ?? ''} ${b.last_name ?? ''}`.trim(),
|
guest: b.guest_name ?? `${b.first_name ?? ''} ${b.last_name ?? ''}`.trim(),
|
||||||
arrival: b.arrival_date,
|
arrival: b.booking_arrival,
|
||||||
departure: b.departure_date,
|
departure: b.booking_departure,
|
||||||
nights: b.nights ?? b.no_nights,
|
nights: b.booking_length ?? b.nights,
|
||||||
room: b.site_name ?? b.room_name ?? b.site_id,
|
room: b.site_name ?? b.site_id,
|
||||||
adults: b.adults ?? b.no_adults,
|
adults: b.booking_adults ?? b.adults,
|
||||||
status: b.booking_status ?? b.status,
|
status: b.status,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue