diff --git a/api/app/Models/Shift.php b/api/app/Models/Shift.php index 334709d7..5388d4af 100644 --- a/api/app/Models/Shift.php +++ b/api/app/Models/Shift.php @@ -111,7 +111,7 @@ final class Shift extends Model return 0; } - return round($this->filled_slots / $this->slots_total, 2); + return (int) round(($this->filled_slots / $this->slots_total) * 100); }); } diff --git a/api/database/seeders/DevSeeder.php b/api/database/seeders/DevSeeder.php index edea6b8f..52e5f16e 100644 --- a/api/database/seeders/DevSeeder.php +++ b/api/database/seeders/DevSeeder.php @@ -328,14 +328,13 @@ class DevSeeder extends Seeder // EHBO: 6 shifts across volunteer time slots foreach (['vr_early', 'vr_avond', 'za_dag', 'za_avond', 'zo_dag', 'zo_avond'] as $key) { - $isFull = $key === 'za_dag'; $shift = Shift::create([ 'festival_section_id' => $ehbo->id, 'time_slot_id' => $ts[$key]->id, 'title' => 'EHBO Post', - 'slots_total' => $isFull ? 4 : 3, - 'slots_open_for_claiming' => $isFull ? 0 : 2, - 'status' => $isFull ? 'full' : 'open', + 'slots_total' => $key === 'za_dag' ? 4 : 3, + 'slots_open_for_claiming' => $key === 'za_dag' ? 0 : 2, + 'status' => 'open', ]); $allShifts[] = $shift; $s["ehbo_{$key}"] = $shift; @@ -669,7 +668,7 @@ class DevSeeder extends Seeder ->where('status', 'approved') ->get(); - $openShifts = collect($allShifts)->filter(fn (Shift $shift) => $shift->status === 'open'); + $openShifts = collect($allShifts)->filter(fn (Shift $shift) => $shift->status === 'open' && $shift->slots_open_for_claiming > 0); $statusPool = array_merge( array_fill(0, 75, ShiftAssignmentStatus::APPROVED), @@ -724,6 +723,18 @@ class DevSeeder extends Seeder $assignmentCount = ShiftAssignment::whereIn('shift_id', collect($allShifts)->pluck('id'))->count(); $this->command->info(" {$assignmentCount} shift assignments created"); + // Auto-correct shift statuses based on actual fill + foreach ($allShifts as $shift) { + $filled = ShiftAssignment::where('shift_id', $shift->id) + ->whereIn('status', [ShiftAssignmentStatus::APPROVED, ShiftAssignmentStatus::COMPLETED]) + ->count(); + + $correctStatus = $filled >= $shift->slots_total ? 'full' : 'open'; + if ($shift->status !== $correctStatus) { + $shift->update(['status' => $correctStatus]); + } + } + // ── Volunteer availabilities (~70) ── $volSlotKeys = ['vr_early', 'vr_avond', 'za_dag', 'za_avond', 'zo_dag', 'zo_avond']; @@ -978,7 +989,7 @@ class DevSeeder extends Seeder // ── Shift assignments (~80) ── - $openShifts = collect($allShifts)->filter(fn (Shift $shift) => $shift->status === 'open'); + $openShifts = collect($allShifts)->filter(fn (Shift $shift) => $shift->status === 'open' && $shift->slots_open_for_claiming > 0); $draftShifts = collect($allShifts)->filter(fn (Shift $shift) => $shift->status === 'draft'); $allApproved = $approvedVol->merge($approvedCrew);