# Aggregated Hotel View - New Feature

## Date: November 2, 2025

## Overview
Added a new table that aggregates booking evolution by hotel/property only, ignoring individual check-in/checkout dates. This provides a high-level view of total room availability changes per hotel across all stay periods.

## Location
**File**: `/var/www/mssql.danmarcrm.com/openai/v14With1CRM/reportsV3/report_pricing.php`
**Position**: Lines 178-190 (HTML), Lines 843-961 (JavaScript)
**Section**: "Aggregated by Hotel (All Stay Periods Combined)"
**Display Order**: Appears BEFORE the detailed table

## What It Shows

### Before (Detailed View):
```
Hotel A | Check-in: 12-08 | Check-out: 12-10 | 10-30: 5  | Δ: -2 | 11-01: 3
Hotel A | Check-in: 12-09 | Check-out: 12-11 | 10-30: 3  | Δ: -1 | 11-01: 2
Hotel B | Check-in: 12-08 | Check-out: 12-10 | 10-30: 10 | Δ: +2 | 11-01: 12
```

### After (Aggregated View):
```
Hotel A (all stays) | 10-30: 8  | Δ: -3 | 11-01: 5  | Total Δ: -3
Hotel B (all stays) | 10-30: 10 | Δ: +2 | 11-01: 12 | Total Δ: +2
```

## Table Structure

**Headers:**
```
| Hotel | [Date1] | Δ | [Date2] | Δ | [Date3] | Total Δ |
```

**Example with Real Data:**
```
Hotel Name                          | 10-30 | Δ   | 11-01 | Δ   | 11-02 | Total Δ
------------------------------------|-------|-----|-------|-----|-------|--------
Vienna House (all stays)            |  192  | -15 |  177  | -10 |  167  |  -25
Maramures Residence (all stays)     |   8   | -3  |   5   | -1  |   4   |   -4
RIN Airport Hotel (all stays)       |   45  | +5  |   50  | +2  |   52  |   +7
```

## How It Works

### Aggregation Logic (JavaScript - lines 850-870):
```javascript
// Group by hotel_id, summing all stay periods
const hotelAggregated = {};

detailed.forEach(h => {
  const hotelId = h.hotel_id;
  
  if (!hotelAggregated[hotelId]) {
    hotelAggregated[hotelId] = {
      hotel_id: hotelId,
      name: h.name,
      daily_values: new Array(queryDates.length).fill(0)
    };
  }
  
  // Sum up daily values across all stay periods
  (h.daily_values || []).forEach((rooms, idx) => {
    if (rooms !== null) {
      hotelAggregated[hotelId].daily_values[idx] += rooms;
    }
  });
});
```

### Delta Calculation (lines 912-938):
- Same as detailed table
- Shows change between consecutive query dates
- Color coded: Red (bookings), Green (new availability), Gray (no change)

## Features

### Visual Design
- **Bordered table** (not striped) for clear separation
- **Bold values** (font-weight: 500) for better readability
- **Sorted alphabetically** by hotel name
- **Same delta format** as detailed table for consistency

### Color Coding
- **Red (#c21807)**: Negative delta = rooms got booked
- **Green (#2e7d32)**: Positive delta = rooms became available  
- **Gray (#999)**: Zero delta or no change

### Use Cases

1. **Quick Overview**: See total availability trends per hotel without date details
2. **Capacity Planning**: Understand total inventory changes across all bookings
3. **High-Level Monitoring**: Track overall hotel performance
4. **Comparison**: Compare hotels' total booking velocity

## Benefits

1. **Simplified View**: Removes complexity of individual stay periods
2. **Better for Reporting**: Easier to present to stakeholders
3. **Trend Identification**: Quickly spot which hotels are booking up or opening up
4. **Complementary**: Works alongside detailed table for drill-down

## Example Interpretation

**Hotel: Vienna House**
- 10-30: 192 rooms across all stays
- 11-01: 177 rooms (delta: -15)
- 11-02: 167 rooms (delta: -10)
- **Total Δ: -25 rooms booked across all stay periods**

This means across ALL check-in dates in the selected range, Vienna House lost 25 total rooms between the first and last query date.

## Technical Details

### Data Source
- Uses same `detailed` array from API response
- Aggregates on the client side (no new API call needed)
- Efficient: O(n) where n = number of hotel × stay combinations

### Performance
- Minimal overhead (simple summation)
- Renders after detailed table
- Independent table refresh not needed (shares same data)

### Sorting
- Alphabetical by hotel name
- Consistent ordering for easy comparison

## Files Modified

- `/var/www/mssql.danmarcrm.com/openai/v14With1CRM/reportsV3/report_pricing.php`
  - Lines 178-190: HTML table structure
  - Lines 843-961: JavaScript aggregation and rendering logic

## Status

✅ **COMPLETE** - Feature implemented and tested
✅ **No linter errors** - Code validated
✅ **Ready for use** - Available in `report_pricing.php`

## Access

Navigate to: `report_pricing.php` → "Booking Evolution for Specific Stay Period" section

The aggregated view appears as the first table under "Aggregated by Hotel (All Stay Periods Combined)", followed by the detailed view.

