# Resort booking module

## Existing components reused

Laravel 12.64 / PHP 8.2, the existing Blade admin layout and route-name permissions, React 19 / React Router / Vite website, `Vendor`, `Destination`, customer bearer authentication and customer gate, `ImageOptimizer`, public storage, settings, notification templates/queues, `PaymentTransaction`, payment gateway manager and verified callbacks. Supplier settlements use the existing Vendor Payment and accounting voucher service. Existing accommodation and hotel booking routes remain available.

## Important new files

- `database/migrations/2026_09_24_000001_create_resort_module.php`
- `database/migrations/2026_09_24_000002_add_resort_navigation.php`
- `database/migrations/2026_09_24_000003_link_resort_supplier_payments.php`
- `app/Models/Resort*.php`
- `app/Services/Resort/`: availability, pricing, booking, status, inventory, payment, money and public presenters.
- `app/Http/Controllers/Admin/ResortController.php`, `ResortBookingController.php`, and `app/Http/Controllers/Api/ResortController.php`
- `app/Http/Requests/Resort*.php`, `routes/resorts.php`
- `app/Console/Commands/ExpireResortHolds.php`
- `resources/views/admin/resorts/`
- `tests/Feature/ResortBookingTest.php`, `ResortConcurrencyTest.php`
- Website: `src/pages/ResortsPage.tsx`, `ResortDetailPage.tsx`, `ResortBookingsPage.tsx` and `scripts/test-resort-browser.cjs`.

## Important modified files

Backend routes, console schedule, payment callback/applier, Vendor fields/forms/validation, Payment model and vendor-payment accounting integration, admin menu seeder, sitemap controller, and the sidebar expectation test. `bootstrap/app.php` now preserves HTTP 429 and retry headers for partner throttling; the existing rate-limit regression test exposed its previous conversion to HTTP 500.

Website `App.tsx`, API client, customer booking navigation and SEO prerender script register the new module.

## Database changes

New tables: `resorts`, `resort_rooms`, `resort_facilities`, `resort_facility`, `resort_room_facility`, `resort_inventory`, `resort_rates`, `resort_blocks`, `resort_bookings`, `resort_booking_rooms`, `resort_booking_histories`, `resort_payment_applications`.

Vendor gains `company_name` and `payment_terms`. Existing `payments` gains nullable `resort_booking_id` for supplier settlements. New permissions/menu entries are additive. Resort/room masters are soft deleted; historical bookings restrict physical deletion of their room, resort and supplier references.

Individual room guest allocations and nightly snapshots are JSON arrays on each booking-room row. Facilities use relational pivots. Money uses decimal columns and integer minor-unit calculations; supplier prices never enter public DTOs.

## Admin features

- Own/partner resort management, vendor integration, destinations, descriptions, SEO, galleries, facilities, rules and policies.
- Resort-specific room types, capacity, default/allocated inventory, extra guest/bed charges and protected cost prices.
- Date overrides, stop-sell, room blocks and prioritized seasonal/weekend/special/promotional rates.
- Manual multi-room booking using the same services as public booking; existing customer selection or guest contact snapshots.
- Pending request amendments, authorized price/cost overrides, approval/rejection, audited status changes, check-in/out and cancellation.
- Offline receipts, partial payments, verified online payments, and recording completed offline refunds.
- Booking filters, revenue, collections, due balances, supplier payables, profit and occupancy reports.

## Website features

`/resorts` supports destination, dates, rooms, adults, children, name, price, facility, featured and direct-booking filters. `/resorts/{slug}` shows resort and room galleries, facilities, policies, dates, availability, multiple room types, individual guest allocations/child ages and nightly server quotes. `/account/resort-bookings` shows signed-in customers their own reservations and approved requests awaiting payment. Header/footer/theme and gateway selection are reused. Resort URLs are included in the backend sitemap and website prerender build.

## Business rules and operational defaults

- Own inventory and guaranteed partner allocations reserve nightly capacity. On-request or REQUEST-mode bookings always start `PENDING_REQUEST`; they cannot use online checkout until approved.
- Every occupied night is checked; checkout day is excluded. Capacity for a stay is its minimum nightly availability. Blocks and active holds reduce capacity, stop-sell prevents sales, and cancellation releases capacity without deleting history.
- Every inventory-changing operation locks the resort row first. SQLite uses the same transaction's parent UPDATE as a write lock; MySQL/PostgreSQL use the row lock. Independent resorts can proceed concurrently on row-locking databases. Transactions retry deadlocks up to five times.
- Holds default to 15 minutes and are configurable per resort. Availability ignores expired holds even if the scheduler is delayed. `resorts:expire-holds` cancels expired unpaid reservations and flags partial payments for review.
- Full payment is required for confirmation. Offline partial receipts are supported. A verified late payment rechecks capacity; unavailable inventory, cancelled bookings and overpayments require staff review/refund. Duplicate callbacks apply money once.
- Quote tokens prevent booking an unreviewed changed rate. Client amounts are not authoritative. Highest rate priority wins; equal priorities use the most recently created rule. Date-range ends are exclusive; weekday numbers are Sunday 0 through Saturday 6.
- Extras are charged per physical room per occupied night. Tax basis points apply to room charges plus extras minus discount plus the per-booking service charge. Gross profit is grand total minus tax minus snapshotted cost; losses are retained.
- Maximum stay is 90 nights. Each room allocation requires an adult and an age for every child. Extra beds do not bypass guest capacity.
- Guest details are snapshots, not new accounts. Signed-in customers retain the existing customer relationship. Existing configured notifications are sent for linked customers; guest requests are handled through their supplied contact information.
- Cancellation policy text guides staff decisions. Cancellation requires a recorded reason; refund execution remains with the existing provider/bank, and staff record the completed refund and reference. No automatic gateway refund API is assumed.
- Financial reports use check-in dates, excluding pending requests/cancelled/rejected bookings from revenue. Collection totals cover payments on the filtered bookings. Supplier payable is confirmed booking cost less linked vendor settlements. Existing unlinked vendor payments are not guessed or reassigned.
- Occupancy = confirmed/check-in/check-out/no-show room nights divided by default/date-override room nights minus blocked nights. Holds are excluded from sold nights. Stop-sell does not remove physical rooms. On-request resorts are excluded.
- Once a resort has bookings, its source and inventory mode cannot change. Supplier, resort name, room names, costs, rates and financial snapshots on existing bookings remain unchanged by master edits.

## Permissions

Permissions follow the existing `admin.<route>` convention. Super-admin retains access. Assign staff the relevant route permissions. Sensitive additional permissions are `admin.resorts.cost`, `admin.resorts.profit`, `admin.resorts.price-override`, `admin.resorts.rates`, `admin.resorts.confirm`, `admin.resorts.cancel`, `admin.resorts.checkin`, and `admin.resorts.checkout`. A status-change operator needs the transition route permission plus the specific action permission. Inventory mutations need their route permission and inventory/rates permission.

## Verification

Completed locally: full regression run **476 tests / 2,074 assertions**, final focused resort run **33 tests / 109 assertions** (including the subsequently added mixed-room search case), website TypeScript check, website build/SEO prerender, admin asset build, and the browser smoke test. No test failures remained in these runs.

Business tests cover own inventory, partner allocations/on-request approval, multiple types and individual allocations, adult/child/total capacities, overlap and back-to-back stays, blocks, stop-sell, overrides, weekend/nightly rates, extras, discount/tax/service charge, costs/profit including losses, snapshots, cancellation/release, expired holds, late payments, duplicate callbacks/submissions, invalid transitions, public cost privacy, ownership, admin views and quote changes.

`ResortConcurrencyTest` starts two independent PHP processes against a disposable SQLite database and asserts exactly one confirmed last-room booking. Repeat equivalent load testing on the production database engine during staging acceptance.

The optional Playwright smoke test uses `tests/Support/resort-browser-fixture.php` with a disposable database whose name contains `resort-browser-`. It verifies listing → dates → three rooms across two room types → per-room child age → quote → guest reservation → existing admin login → booking details, plus a 390px viewport overflow check. It requires Playwright and Chrome; no live payments are made.

## Safe deployment

Run from your existing release directories with the production `.env` already configured. Do not generate a replacement application key. Take your normal database backup before migrations. Deploy backend before building/prerendering the website so `/api/resorts` is available.

```bash
cd lets_tour_admin
composer install --no-dev --prefer-dist --optimize-autoloader
php artisan migrate --force
npm ci
npm run build
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan queue:restart

cd ../lets_tour_web
npm ci
VITE_API_URL=https://admin.<your-domain>/api npm run build
```

Publish `lets_tour_web/dist` through the existing website deployment process. Keep the existing storage link and scheduler cron running (`php artisan schedule:run` every minute); the new expiry job is registered automatically. No database reset or global reseeding is required. Verify your actual API hostname if the deployment differs from the repository's existing production hostname.

For local/staging verification with development dependencies installed:

```bash
cd lets_tour_admin
php vendor/phpunit/phpunit/phpunit
php vendor/phpunit/phpunit/phpunit --filter=Resort
cd ../lets_tour_web
npm run lint
npm run build
```

The local workspace has no backend `.env`; verification supplied a temporary test-process `APP_KEY` and `APP_NAME="Let's Go Tours and Travels"`. Real online gateway credentials and production database concurrency were not exercised locally. Migrations were applied only to disposable test databases during implementation.

The browser-test servers were stopped and the disposable fixture database `%TEMP%/resort-browser-tms.sqlite` has been removed.
