Skip to main content

getOccupancyReport

Generates a comprehensive occupancy report for a specific date, including total rooms, occupied/available breakdown, and statistics by room type.

Function Signature

function getOccupancyReport(hotel, date)

Parameters

hotel
object
required
The hotel object to generate the report for
date
string
required
The date to check occupancy for in ISO format (e.g., ‘2026-03-22’). Can be past, present, or future.

How It Works

  1. Combines Data: Creates a clone of both active reservations and historical reservations (main.js:242-245)
  2. Filters by Date: Uses isDateInRange() to find all reservations where the specified date falls within check-in and check-out dates (main.js:250, validation.js:32-40)
  3. Gets Room Details: Maps reservation room numbers to full room objects (main.js:251)
  4. Calculates Metrics: Computes total, occupied, available counts and percentage
  5. Breaks Down by Type: Groups statistics by room type (single, double, suite)

Return Value

report
object
Detailed occupancy report object

Example

const occupancyReport = getOccupancyReport(hotel, '2026-03-22')
console.log(occupancyReport)

Expected Output

{
  date: '2026-03-22',
  total: 20,
  occupied: 12,
  available: 8,
  percentage: 60,  // Math.floor((12 / 20) * 100)
  byType: {
    single: {
      total: 8,
      occupied: 5
    },
    double: {
      total: 8,
      occupied: 5
    },
    suite: {
      total: 4,
      occupied: 2
    }
  }
}
The report includes both active reservations and historical data, making it accurate for past, present, and future dates.
The percentage is calculated using Math.floor(), so 60.8% becomes 60%.
  • isDateInRange() - Checks if date falls within reservation dates (validation.js:32-40)
  • getRoomByNumber() - Gets room details (utils.js:18-21)
  • getRoomsByType() - Filters rooms by type (utils.js:33-35)

getRevenueReport

Calculates total revenue for a date range, including room charges and extras, with reservation count.

Function Signature

function getRevenueReport(hotel, startDate, endDate)

Parameters

hotel
object
required
The hotel object to generate the revenue report for
startDate
string
required
Start date of the reporting period in ISO format (e.g., ‘2026-01-01’)
endDate
string
required
End date of the reporting period in ISO format (e.g., ‘2026-03-22’)

How Revenue is Calculated

  1. Combines Data: Gets all reservations + history using getReservationsPlusHistory() (main.js:283, utils.js:207-209)
  2. Filters by Range: Uses isRangeInRange() to find reservations where BOTH check-in and check-out fall within the specified date range (main.js:288-290, validation.js:42-51)
  3. Excludes Cancelled: Filters out reservations with status 'cancelled' (main.js:294)
  4. Calculates Extras: Sums all extras using getExtrasPrice() for each reservation (main.js:306-308, utils.js:122-127)
  5. Calculates Total: Sums all totalPrice values from valid reservations (main.js:309-311)

Return Value

report
object
Revenue report with financial breakdown

Example

const revenueReport = getRevenueReport(hotel, '2026-01-01', '2026-03-22')
console.log(revenueReport)

Expected Output

{
  period: '2026-01-01 to 2026-03-22',
  rooms: 20,
  extras: 450,      // Sum of all extras from reservations in range
  total: 5450,      // Total revenue (room charges + extras)
  reservations: 15  // Number of completed reservations
}

Revenue Breakdown Example

// Reservations in period:
// 1. RES-001: €500 (room) + €50 (extras) = €550, status: 'checked_out'
// 2. RES-002: €800 (room) + €100 (extras) = €900, status: 'checked_out'
// 3. RES-003: €600 (room) + €0 (extras) = €600, status: 'cancelled' ❌ Excluded

// Calculation:
extras = 50 + 100 =150
total = 550 + 900 =1450  // Note: totalPrice already includes extras
reservations = 2  // Cancelled not counted
The total field in the report represents the sum of all reservation totalPrice values, which already include extras. The separate extras field shows extras revenue for analytical purposes.
Only reservations where BOTH check-in AND check-out dates fall within the specified range are included. Cancelled reservations are excluded from all calculations.
  • getReservationsPlusHistory() - Combines active and historical reservations (utils.js:207-209)
  • isRangeInRange() - Validates date ranges overlap (validation.js:42-51)
  • getExtrasPrice() - Calculates extras total (utils.js:122-127)

getGuestHistory

Retrieves complete reservation history and spending summary for a specific guest by email.

Function Signature

function getGuestHistory(hotel, guestEmail)

Parameters

hotel
object
required
The hotel object to search within
guestEmail
string
required
The email address of the guest (used as unique identifier)

How It Works

  1. Get All Reservations: Retrieves combined reservations and history (main.js:320)
  2. Filter by Email: Finds all reservations matching guest.email (main.js:322-324)
  3. Extract Guest Data: Gets guest info from the first matching reservation (main.js:326-328)
  4. Calculate Total Spent: Sums all totalPrice values (main.js:330-332)
  5. Calculate Total Extras: Sums all extras charges separately (main.js:334-336)
  6. Map Reservations: Creates simplified reservation list (main.js:343-350)

Return Value

guestHistory
object
Complete guest profile with reservation history

Example

const guestHistory = getGuestHistory(hotel, '[email protected]')
console.log(guestHistory)

Expected Output

{
  guestEmail: '[email protected]',
  guestName: 'Ana García',
  totalReservations: 3,
  totalSpent: 1825,  // Sum of totalPrice + sum of all extras
  reservations: [
    {
      id: 'RES-001',
      checkIn: '2026-04-10',
      checkOut: '2026-04-15',
      status: 'checked_out',
      totalPrice: 625
    },
    {
      id: 'RES-005',
      checkIn: '2026-05-01',
      checkOut: '2026-05-05',
      status: 'checked_out',
      totalPrice: 500
    },
    {
      id: 'RES-012',
      checkIn: '2026-06-20',
      checkOut: '2026-06-25',
      status: 'confirmed',
      totalPrice: 700
    }
  ]
}

Total Spent Calculation

// Reservation totals from database:
// RES-001: totalPrice = €625 (includes €125 extras)
// RES-005: totalPrice = €500 (no extras)
// RES-012: totalPrice = €700 (includes €50 extras)

totalFromReservations = 625 + 500 + 700 =1825
totalExtras = 125 + 0 + 50 =175

// Final totalSpent calculation (main.js:342):
totalSpent = totalFromReservations + totalExtras =1825 +175 =2000
The totalSpent calculation adds extras twice: once from the reservation totalPrice (which already includes extras) and again from the separate extras calculation. This appears to be a calculation error in the source code (main.js:342).
  • The function searches across both active reservations and historical data
  • All reservation statuses are included (confirmed, checked_in, checked_out, cancelled)
  • Guest data (name, phone, dni) is extracted from the reservation records

Use Cases

  • Guest Loyalty Programs: Track total spending for rewards
  • Customer Service: View complete reservation history
  • Analytics: Identify repeat customers and their preferences
  • Billing Inquiries: Verify past charges and reservations
  • getReservationsPlusHistory() - Combines all reservation data (utils.js:207-209)
  • getExtrasPrice() - Calculates extras total (utils.js:122-127)

Build docs developers (and LLMs) love