diff --git a/app/Http/Controllers/ShiftController.php b/app/Http/Controllers/ShiftController.php index 644951e04..680ac41d9 100644 --- a/app/Http/Controllers/ShiftController.php +++ b/app/Http/Controllers/ShiftController.php @@ -247,6 +247,7 @@ class ShiftController extends Controller 'attendance_records.employee_id as user_id', 'attendance_records.date', 'attendance_records.is_rest_day', + 'attendance_records.shift_id', 'shifts.name as shift_name' ) ->get() @@ -268,22 +269,31 @@ class ShiftController extends Controller // If attendance record specifically marks it as a globally tracked Rest Day if ($record->is_rest_day) { $status = 'RD'; + $shiftName = 'Rest Day'; + $shiftId = null; } else if ($record->shift_name) { // Extract shift safely $status = strtoupper(substr($record->shift_name, 0, 1)); + $shiftName = $record->shift_name; + $shiftId = $record->shift_id; } else if ($user->employee && $user->employee->shift) { // Record exists, but shift mapping is blank. Fallback to employee profile shift. $status = strtoupper(substr($user->employee->shift->name, 0, 1)); + $shiftName = $user->employee->shift->name; + $shiftId = $user->employee->shift->id; } } else if ($user->employee && $user->employee->shift) { // Completely blank record; safely map to their default assigned Employee Shift! // Removed hardcoded Sat/Sun filters because `attendance_records` strictly dictates actual weekend behavior now! $status = strtoupper(substr($user->employee->shift->name, 0, 1)); + $shiftName = $user->employee->shift->name; + $shiftId = $user->employee->shift->id; } $grid[$dateKey] = [ 'status' => $status, - 'shift_name' => $shiftName + 'shift_name' => $shiftName, + 'shift_id' => $shiftId ?? '' ]; }