# Hostiva v6 — Hotel + STR Unified

This release upgrades Hostiva from a pure short-term-rental (STR) platform into a unified property suite that handles **both STR units and full hotels** in a single workspace.

## What's new in v6

### Hotel mode features (additive — STR keeps working unchanged)
- **Property modes** — each property is flagged `str` or `hotel`
- **Room Types** — categorise rooms (Standard, Deluxe, Suite…) with bed type, occupancy, base rate
- **Rooms** — individual physical room inventory with housekeeping + occupancy status
- **Front Desk Dashboard** — live room grid, arrivals, departures, ADR / RevPAR / occupancy KPIs
- **Housekeeping** — assignable cleaning tasks, status workflow (pending → in-progress → completed)
- **Folio** — in-stay charges (food, beverage, minibar, laundry, etc.) with void support
- **Rate Plans** — optional plans for BAR, corporate, group, advance-purchase rates
- **Corporate Accounts & Group Bookings** — for hotels handling negotiated business
- **Night Audit** — daily snapshot table (room nights, ADR, RevPAR, revenue)

### UI refresh
- Single design system in `assets/css/hostiva.css` (Outfit font, modern blue+dark sidebar, rounded cards)
- New shared `assets/js/layout.js` builds the sidebar + topbar on every admin page
- Sidebar mode toggle (STR / Hotel / Both) hides/shows menu items per mode — persists in localStorage
- All admin pages share the same chrome — no more per-page sidebars

### Performance
- Bookings list now paginated (`?page=N&per_page=25`) — was unbounded `LIMIT 500`
- Critical indexes added (run `patch_performance.php` once)
- Static asset caching + gzip already enabled via `.htaccess`

## Upgrade steps (from existing v5 install)

### 1. Back up your database first
```bash
mysqldump -u youruser -p hostiva > hostiva-pre-v6.sql
```

### 2. Replace the files
Upload the new v6 files over your existing install. Skip `config/` so your DB credentials stay intact.

### 3. Run the v6 migration
```bash
mysql -u youruser -p hostiva < database/migrations_005_v6_hotel_mode.sql
```
This is **additive** — it adds new columns and tables without touching existing STR data.

### 4. Run the perf patch (one-time)
```bash
php patch_performance.php
```
Adds critical indexes on bookings/payments/calendar tables.

### 5. Enable hotel mode on a property
In the database (or via `properties.html` once you build the form):
```sql
UPDATE properties SET property_mode = 'hotel' WHERE id = 1;
```
Then visit **Room Types** in the sidebar to set up categories, **Rooms** to add inventory.

## New API routes (added in v6)
| Route | Purpose |
|---|---|
| `room_types` | CRUD room types (GET, POST, PUT, DELETE) |
| `rooms` | CRUD rooms (+ `?action=bulk_create`, `?action=status`) |
| `housekeeping` | Tasks (+ `?action=today`, `?action=start`, `?action=complete`) |
| `folio` | Charges (+ `?action=summary` for full folio, `?action=void`) |
| `front_desk` | Aggregated dashboard: KPIs + arrivals + departures + room grid |

All v5 routes are unchanged.

## File map

```
hostiva/
├── api/
│   ├── controllers/
│   │   ├── room_types.php          [NEW v6]
│   │   ├── rooms.php               [NEW v6]
│   │   ├── housekeeping.php        [NEW v6]
│   │   ├── folio.php               [NEW v6]
│   │   ├── front_desk.php          [NEW v6]
│   │   └── bookings.php            [PATCHED — pagination]
│   └── index.php                   [PATCHED — new routes]
├── assets/
│   ├── css/hostiva.css             [REWRITTEN — full design system]
│   └── js/
│       ├── hostiva.js              [REWRITTEN — API client]
│       └── layout.js               [REWRITTEN — sidebar + topbar]
├── database/
│   └── migrations_005_v6_hotel_mode.sql   [NEW v6 — run once]
├── pages/
│   ├── dashboard.html              [REBUILT]
│   ├── login.html                  [REBUILT]
│   ├── front-desk.html             [NEW]
│   ├── room-types.html             [NEW]
│   ├── rooms.html                  [NEW]
│   ├── housekeeping.html           [NEW]
│   └── (all other pages styled by new CSS/layout.js)
└── README_V6.md                    [this file]
```

## Testing checklist before going live

- [ ] Run migration on a backup copy first
- [ ] Verify existing STR bookings still load on `bookings.html`
- [ ] Verify dashboard loads KPIs correctly
- [ ] Create a test property with `property_mode='hotel'`
- [ ] Add a room type, then bulk-create 5 rooms
- [ ] Front Desk page shows the rooms
- [ ] Create a test housekeeping task — start it, complete it
- [ ] Verify room status changed to "clean" after completing a clean task
- [ ] Switch the sidebar mode toggle (STR / Hotel / Both) — menu items show/hide

## Known limitations in this build

- The new layout.js wraps existing pages — some older pages (calendar, ota, etc.) may need their internal markup refined for the new style. They work, but spacing/typography may need polish.
- Rate Plans table is in the schema but the management UI is pending — use SQL or the API directly until the UI ships.
- Night Audit is in the schema but auto-run cron is pending.
- Folio UI is wired through the API; a dedicated folio.html page is pending.
- Corporate Accounts and Group Bookings: schema only, UI pending.

These are scoped for the next iteration. The existing flows (bookings, payments, properties, reports, finance, channels) all continue to work as before.
