Add DOW-aligned LY toggle to directors forecast worksheet and report
Checkbox in the header switches between 364-day same-weekday comparison and same calendar-date last year. Default remains DOW-aligned. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2e8a908f05
commit
9530125509
4 changed files with 33 additions and 20 deletions
|
|
@ -41,12 +41,13 @@ async function getSessionAndOverrides(year, month) {
|
|||
return { session, overrideMap }
|
||||
}
|
||||
|
||||
async function fetchMonthFromApi(year, month, lastDayNum) {
|
||||
async function fetchMonthFromApi(year, month, lastDayNum, dowAlign = true) {
|
||||
const startDate = `${year}-${String(month).padStart(2, '0')}-01`
|
||||
const days = lastDayNum
|
||||
const da = `&dow_align=${dowAlign}`
|
||||
const [revData, roomsData] = await Promise.all([
|
||||
fcFetch(`/forecast/revenue?start_date=${startDate}&days=${days}&type=all`),
|
||||
fcFetch(`/forecast/rooms?start_date=${startDate}&days=${days}`),
|
||||
fcFetch(`/forecast/revenue?start_date=${startDate}&days=${days}&type=all${da}`),
|
||||
fcFetch(`/forecast/rooms?start_date=${startDate}&days=${days}${da}`),
|
||||
])
|
||||
const revMap = {}
|
||||
for (const d of revData.data) revMap[d.date] = d
|
||||
|
|
@ -65,6 +66,7 @@ export async function directorsForecastRoutes(fastify) {
|
|||
if (isNaN(year) || isNaN(month) || month < 1 || month > 12) {
|
||||
return reply.status(400).send({ error: 'Invalid year/month' })
|
||||
}
|
||||
const dowAlign = request.query.dow_align !== 'false'
|
||||
|
||||
const lastDayNum = new Date(year, month, 0).getDate()
|
||||
const today = new Date().toISOString().split('T')[0]
|
||||
|
|
@ -72,7 +74,7 @@ export async function directorsForecastRoutes(fastify) {
|
|||
|
||||
const [{ session, overrideMap }, { revMap, roomsMap }] = await Promise.all([
|
||||
getSessionAndOverrides(year, month),
|
||||
fetchMonthFromApi(year, month, lastDayNum),
|
||||
fetchMonthFromApi(year, month, lastDayNum, dowAlign),
|
||||
])
|
||||
|
||||
const rate = parseFloat(session.pickup_avg_rate || sessionRate)
|
||||
|
|
@ -186,10 +188,11 @@ export async function directorsForecastRoutes(fastify) {
|
|||
const year = parseInt(request.params.year)
|
||||
const month = parseInt(request.params.month)
|
||||
const lastDayNum = new Date(year, month, 0).getDate()
|
||||
const dowAlign = request.query.dow_align !== 'false'
|
||||
|
||||
const [{ session, overrideMap }, { revMap, roomsMap }] = await Promise.all([
|
||||
getSessionAndOverrides(year, month),
|
||||
fetchMonthFromApi(year, month, lastDayNum),
|
||||
fetchMonthFromApi(year, month, lastDayNum, dowAlign),
|
||||
])
|
||||
|
||||
const sessionRate = parseFloat(session.pickup_avg_rate || 135)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue