# Hotel Management System - Support Engineer Documentation

## System Overview

This is a comprehensive hotel and restaurant management system built with PHP, MySQL, CSS, and JavaScript. The system handles guest bookings, room management, point-of-sale operations, restaurant pre-orders, invoicing, VAT reporting, and staff timesheets.

**Technology Stack:**
- Backend: PHP 7+ with PDO for database operations
- Database: MySQL
- Frontend: Bootstrap 4/5, jQuery, HTML5, CSS3
- Additional: mPDF for invoice generation, PHPMailer for email functionality

## System Architecture

### Core Files & Purpose

| File | Purpose | Key Features |
|------|---------|--------------|
| `config.php` | Database configuration and system settings | Database connection, VAT rates, timezone settings |
| `login.php` | User authentication | Password hashing, session management |
| `checklogin.php` | Session validation | Included in protected pages |
| `portal.php` | Main dashboard | Room status overview, navigation hub |

## Database Structure

### Key Tables

#### Customer Management
- **`customer`** - Guest information, billing addresses, marketing preferences
- **`booking`** - Main booking records with status tracking
- **`booking_items`** - Individual room bookings with dates and pricing

#### Room & Inventory
- **`room`** - Room details (name, type, facilities, category)
- **`room_rate`** - Pricing structure by season and category
- **`sales_item`** - POS items (food, drinks, misc) with pricing and VAT

#### Restaurant System
- **`meal_preorders`** - Restaurant pre-order bookings
- **`meal_preorders_items`** - Individual items within pre-orders
- **`category`** - Revenue categories for reporting

#### Financial
- **`sales`** - POS transactions
- **`packages`** - Special rate packages
- **`system`** - System-wide settings including VAT rates

#### Staff Management
- **`user`** - Staff accounts with roles and authentication
- **`timesheet`** - Staff clock-in/out records

## Core Modules

### 1. Booking Management

#### Files:
- `booking.php` - Main booking interface
- `post_booking.php` - Booking form processor
- `pop_room_allocator.php` - Room allocation modal
- `moveguest.php` - Guest relocation

#### Key Features:
- Multi-room bookings
- Seasonal pricing (High/Low season)
- Package rates
- Custom pricing overrides
- Booking status tracking: `allocated` → `Checked In` → `Checked Out`

#### Common Issues:
- **Booking conflicts**: Check `booking_items` table for overlapping dates
- **Missing rates**: Verify `room_rate` table has entries for the season/category
- **Custom rates not saving**: Check `booking_items.custom_rate` field

### 2. Guest Management

#### Files:
- `guest.php` - Guest information form
- `guest_details.php` - View/edit guest details
- `find_guest.php` / `find_guest2.php` - Guest search
- `post_guest.php` - Guest data processor

#### Key Features:
- Complete contact information
- Separate billing addresses
- Marketing consent tracking
- Booking history display

### 3. Point of Sale (POS)

#### Files:
- `sales.php` - Main POS interface
- `charges.php` - Item management
- `post_sales.php` - Sales transaction processor

#### Key Features:
- Categorized items (Beer, Spirits, Wine, Food, Misc)
- VAT rate handling (Standard, Discount, Exempt)
- Revenue category tracking
- Menu position for restaurant items

#### Menu Position Values:
- `None` - Not shown on restaurant menu
- `Starter` - Appetizer section
- `Main` - Main course section
- `Dessert` - Dessert section

### 4. Restaurant Pre-Order System

#### Files:
- `restaurant-menu-preorder.html` - Customer-facing menu
- `menu.js` - Frontend menu functionality
- `menuitems.php` - API endpoint for menu items
- `submitOrder.php` - Process pre-orders
- `get_meal_bookings.php` / `get_meal_bookings2.php` - View bookings
- `menu_setup.php` - Menu item descriptions

#### Key Features:
- Online pre-ordering with date/time selection
- Item categorization by menu position
- Email confirmations
- Admin booking management

### 5. Financial Management

#### Invoicing:
- `invoice.php` - Generate invoices
- `create_invoice.php` - Invoice creation logic
- `email_invoice.php` - Email invoice to guest
- `meal_only_invoice.php` - Restaurant-only invoices

#### VAT Reporting:
- `vat_report.php` - Standard VAT report
- `vat_report_restaurant.php` - Restaurant VAT
- `setvat.php` / `setvat_new.php` - VAT rate management

#### Revenue Reports:
- `revenue_sales.php` - Sales revenue analysis
- `revenue_accommodation.php` - Room revenue
- `revenue_sales_by_category.php` - Category breakdown

### 6. Room Management

#### Files:
- `room_details.php` - Room configuration
- `room.php` - Room selection interfaces
- `addroomtype.php` - Room type management

#### Room Categories:
- **Premium** - Higher-tier rooms
- **Standard** - Standard accommodations
- Custom categories can be added

#### Room Types:
- Double
- Twin
- Double & Single

### 7. Staff Management

#### Files:
- `user_admin.php` - User account management
- `createuser.php` - New user creation
- `timesheet_login.php` - Timesheet access
- `timesheet.php` - Clock in/out interface
- `timesheet_report.php` - Timesheet reporting

#### User Roles:
- **Administrator** - Full system access
- **Standard User** - Limited access

## Common Support Scenarios

### 1. Database Connection Issues

**Symptoms:**
- "An error occurred trying to connect to the database"
- Pages loading with errors

**Troubleshooting:**
1. Check `config.php` database credentials
2. Verify MySQL service is running
3. Test network connectivity to database host
4. Check database user permissions

**Configuration Details:**
```php
$dbhost = "100.26.229.26";
$dbdatabase = "hotel";
$dbuser = "slave";
$dbpassword = "Hopeimok2012!";
```

### 2. Login Problems

**Symptoms:**
- "Invalid user name / password"
- Redirects to login page repeatedly

**Troubleshooting:**
1. Verify username exists in `user` table
2. Check password hash in database
3. Verify session configuration
4. Clear browser cookies/session data

### 3. VAT Calculation Issues

**VAT Rates (from `system` table):**
- Standard VAT (`VAT` field)
- Discount VAT (`VAT2` field)
- Exempt (0%)

**Calculation Variables:**
- `$INCLUDING_VAT` = 1 + VAT rate
- `$TAX_FROM_GROSS` = Tax portion of gross amount

### 4. Room Allocation Problems

**Common Issues:**
- Overbooking
- Incorrect room status
- Missing availability

**Resolution Steps:**
1. Check `booking_items` for date conflicts
2. Verify `booking_status` values
3. Review room allocation in `portal.php`

### 5. Restaurant Menu Issues

**Menu Item Status:**
- `sales_item_status` = 'Live' (active)
- `sales_item_status` = 'Deleted' (inactive)

**Menu Position Issues:**
- Items must have `menu_position` ≠ 'None' to appear
- Check `menuitems.php` API endpoint

### 6. Email Functionality

**Email Configuration:**
- Uses PHPMailer (`includes/phpmailer.php`)
- From address: `info@beaconhotel.co.uk`
- Check email templates in relevant files

### 7. Invoice Generation

**Common Issues:**
- Missing invoice data
- PDF generation errors
- Email delivery failures

**Key Files:**
- `create_invoice.php` - Main invoice logic
- `invoice_pdf.php` - PDF generation
- mPDF library location: `$mpdf_location = '../';`

## System Configuration

### Important Settings

#### Timezone:
```php
date_default_timezone_set('Europe/London');
```

#### File Locations:
- Invoices: `$invoice_location = '../invoices/';`
- Assets: `/assets/` directory

#### Session Management:
- Authentication required for most pages
- Session variables: `$_SESSION['loggedin']`, `$_SESSION['admin']`

### Security Considerations

1. **Password Hashing**: Uses PHP `password_hash()` with BCRYPT
2. **SQL Injection Protection**: PDO prepared statements
3. **Session Security**: Login checks on protected pages
4. **Access Control**: Admin flag for privileged operations

## Troubleshooting Checklist

### Database Issues:
- [ ] Database server accessible
- [ ] Credentials correct
- [ ] User permissions adequate
- [ ] Required tables exist

### Application Issues:
- [ ] PHP version compatible (7+)
- [ ] Required extensions loaded (PDO, MySQL)
- [ ] File permissions correct
- [ ] Error logging enabled

### User Issues:
- [ ] Account exists and active
- [ ] Password recently changed
- [ ] Session cookies enabled
- [ ] Browser cache cleared

### Data Issues:
- [ ] Required records exist
- [ ] Foreign key relationships intact
- [ ] Enum values match expected options
- [ ] Date formats consistent

## Emergency Procedures

### System Down:
1. Check database connectivity
2. Verify web server status
3. Review error logs
4. Contact system administrator

### Data Corruption:
1. Stop affected processes
2. Assess damage scope
3. Restore from backup if necessary
4. Document incident

### Security Breach:
1. Change all system passwords
2. Review access logs
3. Update security measures
4. Notify management

## Maintenance Tasks

### Daily:
- Monitor system performance
- Check error logs
- Verify backup completion

### Weekly:
- Review user accounts
- Clean temporary files
- Update system documentation

### Monthly:
- Database optimization
- Security review
- Performance analysis

---

**Contact Information:**
- Primary Admin: Ashley
- Secondary Contact: Gareth
- Database Host: 100.26.229.26
- System URL: https://focust.solutions/

*Last Updated: August 2025*
