Commit graph

58 commits

Author SHA1 Message Date
b9fdd97330 Add PWA manifest support
Icons already existed in public/icons/ but nothing wired them up —
no manifest, no service worker, not installable.
2026-07-29 17:28:35 +00:00
4137813fc7 Use central Anthropic key for AI insights; add update-check banner
AI insights now fetches the Claude API key from the central settings
service instead of storing its own encrypted copy, so wages and other
apps can share the same key. Also wires up the update-available banner
using the existing version-check hook pattern.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 20:43:03 +00:00
72f607132c Tighten AI insight bullet constraints further — still truncating at 800 tokens
Live-tested again: 800 tokens still wasn't enough for Sonnet's bullet density
(6 dense bullets, cut off mid-sentence again). Capped bullet count to 4-5,
added a hard 35-word single-sentence limit per bullet, told it not to add a
closing summary, and raised the cap to 1200 for genuine headroom.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 19:48:05 +00:00
50ef00c336 Fix AI insight output truncation — bump token cap, enforce bullet brevity
Live-tested on the dev stack: with the more verbose Sonnet model, the old
550-token cap cut the last bullet off mid-sentence. Bumped to 800 and told
the model to keep each bullet to 1-2 sentences so it isn't relying on the
cap alone to stay in bounds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 19:39:26 +00:00
2a7ee1d6b8 Expand AI insight: fix broken competitor query, add continuity, 30-day horizon, holidays
- Fix gather_competitor_data() tier filter: it queried tier IN ('primary','secondary'),
  values that never exist (real values are 'own'/'competitor'/'market'), so the
  cheapest-competitor comparison has always silently returned nothing.
- Feed the previous insight back into the prompt so the model can note what's
  changed/resolved instead of repeating itself.
- Extend forecast horizon from 14 to 30 days; add a per-day revenue table
  alongside the existing occupancy table.
- Annotate the occupancy table with UK (England) bank holidays.
- Add a same-channel market-movement section (B.com vs B.com, rack vs rack)
  diffing rates against the last insight's snapshot, threshold £3.
- Add a parsed headline field + insight history list on the Dashboard,
  collapsed to headline/age and expandable to full content.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 18:03:31 +00:00
2f5349bd1c Fix session-expiry redirect breaking standalone PWA out of its shell
Same fix as kitchen/kds: AuthGate unconditionally hard-navigated
window.top to the central /login on session expiry, even when not
embedded in the portal iframe — dropping an installed/directly-opened
forecasting session into the portal's framed browser view instead of
staying in its own window.

Now only bounces to central login when actually embedded (passing
?from= so it returns here afterwards); standalone or directly-opened
tabs get an in-app login form and never navigate away. Also wired up
the inactivity auto-logout timer.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 17:07:15 +00:00
7007eb7020 Fix API keys list not showing — unwrap .keys from response
Backend returns { keys: [...] } but frontend was treating the whole
object as the array, so apiKeys.length was always falsy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 11:29:35 +00:00
d47e6dff40 Add name, email and sign out button to sidebar footer
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-22 11:10:09 +00:00
454f34d390 Add dow_align param to /forecast/revenue and /forecast/rooms
Allows callers to switch between 364-day DOW-aligned prior year
and same calendar-date prior year comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 18:28:55 +00:00
185b2ec163 Fall back to DOW averages for dry/wet when spend settings not configured
Covers model returns data (covers * spend) but if resos spend settings are
absent the result is zero, which previously bypassed the DOW fallback. Now
fall back to DOW when the covers-based dry or wet is zero.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 18:17:42 +00:00
ca75037e39 Cap pickup suggestion so OTB + pickup never exceeds bookable capacity
Rename ML± column to Pickup± (prior-year pace model, not ML)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 17:47:40 +00:00
1fae3ce60b Fix sync not updating arrival/departure dates on re-sync
ON CONFLICT clause was missing arrival_date, departure_date, nights, and
room_number — so early checkouts (where NewBook updates booking_departure
to the actual checkout date) never propagated to the DB columns. Reverts
the COUNT(DISTINCT) workaround since the root cause is now fixed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 17:23:09 +00:00
7ebc31756d Fix OTB overcounting by counting distinct rooms not booking rows
Multiple bookings per room (early-checkout Departed + new Arrived, or
NewBook double-bookings) caused COUNT(*) to exceed total room capacity.
Switch to COUNT(DISTINCT COALESCE(room_number, newbook_id)) so each
physical room counts once regardless of how many booking rows span it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 17:19:51 +00:00
2912745300 Fix current OTB overcounting Departed and Unconfirmed bookings
Guests who check out early keep their original departure_date in NewBook,
so Departed status with departure_date > stay_date were being counted as
live OTB — inflating room count above physical capacity. Unconfirmed
bookings are also provisional so excluded from live OTB.

Prior-year queries retain all statuses since historical bookings will
legitimately be in Departed state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 17:15:03 +00:00
455396c965 Fix cascading InFailedSQLTransactionError in covers forecast
When forecast_rooms_for_date throws inside covers_model, asyncpg aborts the
whole transaction. The exception was being caught with a warning but no rollback,
so every subsequent query in the same request failed. Added db.rollback() in
all three exception handlers (breakfast pickupv2, dinner pickupv2, per-day loop)
and moved public.py's rollback into a finally block so it always fires even
when covers_model returns normally with a corrupted transaction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 16:50:09 +00:00
4bad66c91a Fix revenue endpoint 500 — rollback SQLAlchemy session after caught exceptions
When forecast_covers_range or forecast_revenue_for_date throw DB exceptions,
the swallowed exception leaves the async session in an aborted transaction state.
Subsequent queries (DOW averages, per-date accom) then fail with
InFailedSQLTransactionError. Adding db.rollback() in the except blocks
resets the session so the fallback path can continue cleanly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 14:53:54 +00:00
71a385e670 Remove responsive breakpoint — sidebar always visible (desktop-forced via CSS)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-21 08:54:51 +00:00
f26141f258 Force desktop viewport (width=1280) — info-heavy display not suited to responsive layout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 23:15:55 +00:00
da8c27d0de Add DOW-average fallback for dry/wet forecast when covers data is zero
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 12:41:53 +00:00
f0d4fb3beb Use occupied_rooms from occupancy report for past-date OTB, excluding overflow
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 12:37:28 +00:00
d8ad753a62 Fix available_rooms to use is_included flag from room category settings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 12:32:45 +00:00
4e783bd508 Fix available_rooms query: use newbook_occupancy_report_data not daily_occupancy
The table is newbook_occupancy_report_data (per-category rows). Aggregate
SUM(available - maintenance) WHERE category_id != '5' to get the correct
available room count excluding overflow and maintenance.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 11:32:35 +00:00
e04ae18711 Fix /public/forecast/rooms to use available_rooms excluding overflow
Replace static system_config.total_rooms (80, includes overflow) with
per-day available_rooms from daily_occupancy table. This ensures
occupancy % is calculated against the correct base (non-overflow rooms)
consistent with how the rest of the app reports occupancy. Falls back
to system_config.total_rooms when daily_occupancy has no data for a date.
Also adds available_rooms per-day to the response payload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 10:51:51 +00:00
785e804414 Remove PWA nginx location blocks from forecasting
Stale manifest/sw/registerSW location blocks left after PWA plugin removal.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-14 08:45:33 +00:00
ba3351a8a3 Remove vite-plugin-pwa from forecasting frontend
registerSW.js was 404ing in the browser — the PWA plugin was a leftover
from the original port and this is an internal hotel app with no PWA requirement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-14 08:39:39 +00:00
5fbf155f62 Add weather sync job, API endpoints and settings UI
Fetches daily ERA5 weather from Open-Meteo (no API key).
Configurable location, timezone and sync time via Settings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 21:10:03 +00:00
fc15bc5d9a Remove old Resos sync path (resos_bookings table)
Consolidates to single sync path: resos_bookings_sync.py →
resos_bookings_data table. Removes sync_resos_data(), duplicate
load_resos_custom_field_mappings(), resos_api_key and
sync_resos_enabled seed rows, and the dead resos_sync scheduler job.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 21:07:47 +00:00
1a0b18f06e Fix group_exclude_field column type: BOOLEAN → TEXT
Stores Resos booking reference strings like "#35498,NOT-#56748".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 20:40:04 +00:00
018a73ed95 Remove local asyncio import shadowing module-level import
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 20:36:13 +00:00
ba386e316e Fix Resos sync interrupted by health check restart
Yield to event loop after each booking DB commit so FastAPI can
respond to Docker health checks during long syncs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 20:29:50 +00:00
0563ad7fc2 AI insights: UK dates, GBP, remove rate parity section
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 19:57:40 +00:00
9761e88e9b Add missing Resos tables to schema.sql
resos_custom_field_mapping, resos_opening_hours_mapping,
resos_manual_breakfast_periods, resos_bookings_data,
resos_bookings_stats, resos_booking_pace were never added to the
schema — they only existed in the original standalone Postgres instance.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 19:01:50 +00:00
7dfaa5a9fb Add bare /health location to nginx for management monitor compatibility
The management monitor checks http://{host}:{port}/health (no slug prefix).
Adds a location = /health alias alongside the existing /forecasting/health
so both the slug URL (browser/NPM) and the bare path (monitor) work.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 17:07:24 +00:00
1aa52c563e Add Resos connection status card to Settings — read-only, sourced from central Settings
Replaces the removed API key form with a status card showing whether the
Resos key is configured in the central Settings app, plus a Test Connection
button. Adds back the GET /settings/resos and POST /settings/resos/test
endpoints (now reading from central_settings rather than system_config).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 15:02:42 +00:00
3650c92175 Move Resos API key to central Settings service; add sidebar scrollbar styling
Removes the standalone resos_api_key from the forecasting app's own
system_config table. All credential fetches now go through
central_settings.get_resos_credentials() / get_resos_credentials_sync()
which pull from the Settings app (LXC 116) via the internal integration
endpoint — the same pattern already used for NewBook. The Resos API
Config section is removed from the forecasting Settings page; users
manage the key in the central Settings app instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 14:35:35 +00:00
9057d764fa Configurable inactivity timeout — disabled automatically in PWA/standalone mode 2026-07-13 12:29:01 +00:00
e4152b183b Add shared device inactivity timeout to AuthGate 2026-07-13 11:53:05 +00:00
dde41bc5d1 Escape HTML entities before rendering AI insight content
The renderContent() function used dangerouslySetInnerHTML without
first sanitizing the AI-generated text, allowing any HTML in the
model response to execute in the browser. Added escHtml() helper
and applied it before the bold-substitution regex.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-13 09:25:02 +00:00
fce9048902 Replace letter icons with Lucide PWA icons 2026-07-11 20:30:11 +00:00
1ee3f7919f Make forecasting installable as a PWA
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-11 11:27:00 +00:00
084555efdb Fix mid-session 401 redirecting iframe to wrong URL, causing portal EmbeddedFallback
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-10 11:43:58 +00:00
f3e02c3867 Fix expired session showing EmbeddedFallback in portal iframe
When the JWT expired, AuthGate redirected window.location to /auth/login
which loaded inside the portal iframe. The portal detected window.self !==
window.top and showed the EmbeddedFallback ("This app isn't available yet")
instead of the login page.

Redirect window.top instead so the portal itself navigates to /login.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-09 20:19:36 +00:00
76ed477c3a Remove bookability and competitor rates — moved to Rate Monitor app
Deletes bookability.py, competitor_rates.py, Bookability.tsx,
CompetitorRates.tsx. Removes their imports, router mounts, and nav items.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 12:14:26 +00:00
b14d3b414e schema: add forecast_runs, pickup_snapshots, pickup_curves tables
forecast_runs was missing, causing all manual/scheduled forecast jobs to
fail on startup. pickup_snapshots and pickup_curves are referenced by the
pickup model but were absent from schema.sql.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 11:17:02 +00:00
0e43841783 Clear stale sync_log 'running' entries on startup
After a container restart any in-progress jobs leave orphaned 'running' rows
with no completed_at. Added startup cleanup to mark them failed, so the UI
doesn't show a permanently stuck status.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 10:12:19 +00:00
1612468122 Bookability: run date refresh synchronously, update timestamp immediately
Backend now awaits the refresh in a thread executor instead of queuing a
background task, so the response returns only after data is written. Frontend
drops the 3s setTimeout and invalidates the cache immediately on success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 10:08:20 +00:00
7223ae9c30 Bookability: show last-updated timestamp per date column
Backend adds valid_from to DateRateInfo and computes date_last_updated dict
(max valid_from across categories per date). Frontend renders it as a small
timestamp below the date in each column header — time only if today, date+time
if older. Full ISO string in title tooltip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 10:03:17 +00:00
9e6801482f Fix Forecasts nav: useParams key was forecastId but route param is :page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 09:48:14 +00:00
effad0a4e2 Fix schema: add missing tables and correct forecast_snapshots structure
- Add booking_com_hotels and booking_com_rates (competitor rate scraper tables)
- Fix forecast_snapshots: was using old pivoted schema (snapshot_date,
  prophet_value etc.); code expects normalised rows (perception_date, model,
  forecast_value, actual_value). Add DO block migration to drop+recreate if
  old schema is detected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 09:28:52 +00:00
3c66e777e4 Patch fetch_room_categories and fetch_gl_accounts to use central NewBook creds
These two endpoints were missed in the central settings migration. They now try
the Settings service first and fall back to app-local system_config.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 09:26:49 +00:00