# Scramble Flight Handicap Calculation - FIXED

## Issue Summary
The Flight handicap calculation for Scramble events was incorrect. It was using only the first 2 players and dividing by 10 (10%).

## What Was Wrong

### Before (INCORRECT):
```php
// Only calculated sum of first 2 players
$sum1 = 0;
$sum1Players = array_slice($flightPlayers, 0, 2);
foreach ($sum1Players as $fp) {
    $sum1 += $result['shots'];
}

// Then divided by 10 (10%)
$hcp = count($flightPlayers) == 4 ? round($sum1/10, 2) : 0;
```

**Example from your scorecard:**
- Players 1-2 shots: 24 + 18 = 42 (only first 2 players)
- Flight hcp = 42 / 10 = **4.2** ❌ INCORRECT

## What Is Now Fixed

### After (CORRECT):
```php
// Calculate sum of ALL 4 players
$sum1 = 0; // First 2 players
$sum2 = 0; // Next 2 players
$totalSum = $sum1 + $sum2; // All 4 players

// Then divide by 20 (5% of total)
$hcp = count($flightPlayers) == 4 ? round($totalSum/20, 2) : 0;
```

**Example with correct calculation:**
- All 4 players shots: 24 + 18 + 12 + 16 = 70 (all players)
- Flight hcp = 70 / 20 = **3.5** ✅ CORRECT (5% of total)

## Changes Made

### File: `event-scorecard.php`

**Line 1017-1018** - Added total sum calculation:
```php
// Calculate total sum of ALL players for Scramble handicap calculation
$totalSum = $sum1 + $sum2;
```

**Line 1090-1095** - Fixed handicap calculation:
```php
// ✅ FIXED: Use sum of ALL 4 players / 20 (which is 5% of total sum)
// For 3 players, use sum of all 3 / 20
$hcp = count($flightPlayers) == 3 ? round($totalSum/20, 2) : (count($flightPlayers) == 4 ? round($totalSum/20, 2) : 0);
$this->Cell(98, 4, "Sum $totalSum Flight hcp = $hcp", 0, 1);
```

## Formula Reference

### Scramble Flight Handicap:
- **4 players:** (Player1 shots + Player2 shots + Player3 shots + Player4 shots) / 20 = Flight hcp (5%)
- **3 players:** (Player1 shots + Player2 shots + Player3 shots) / 20 = Flight hcp (5%)

## What This Affects

✅ **Group 5 (Scramble events only)**
- Scorecard now shows correct Flight handicap
- Uses sum of ALL players (not just first 2)
- Divides by 20 (5%) instead of 10 (10%)

❌ **Other event types NOT affected**
- Individual events: Show total sum only (no Flight hcp)
- Pairs events: Different calculation
- Other formats: Unchanged

## Testing

To verify the fix works correctly:

1. **Generate a Scramble scorecard** for an event with 4 players in a flight
2. **Check the Flight hcp calculation:**
   - Add up ALL 4 players' shots manually
   - Divide by 20
   - Compare to the Flight hcp shown on the scorecard

**Example:**
- Player 1: 15 shots
- Player 2: 12 shots  
- Player 3: 8 shots
- Player 4: 5 shots
- **Total:** 15 + 12 + 8 + 5 = 40
- **Flight hcp:** 40 / 20 = **2.0** ✅

## Deployment Status

✅ **DEPLOYED** - Fix is active immediately
- No database changes required
- No cache clearing needed
- Next scorecard generation will use correct calculation

## Affected Events

This fix applies to:
- **Scramble events** (Group 5)
- **Texas Scramble events**
- Any event where Format = "Scramble"

The scorecard will now correctly show:
```
Sum 70 Flight hcp = 3.5
```
Instead of:
```
Sum 42 Flight hcp = 4.2
```

---

**Fixed:** October 9, 2025
**File Modified:** `event-scorecard.php`
**Lines Changed:** 1017-1018, 1090-1095

