From cde0fe3bff4eb0bbfa8e042229c74988928fd586 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 6 Jul 2026 13:45:59 +0800 Subject: [PATCH] Allow HR users to view branch employees in My Attendance calendar --- app/Http/Controllers/AttendanceRecordController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AttendanceRecordController.php b/app/Http/Controllers/AttendanceRecordController.php index 234fc9b8b..b6f3f4c59 100644 --- a/app/Http/Controllers/AttendanceRecordController.php +++ b/app/Http/Controllers/AttendanceRecordController.php @@ -25,7 +25,8 @@ class AttendanceRecordController extends Controller $user = Auth::user(); // Employee self-service: redirect to calendar but pass their own records only - if ($user->type === 'employee' || $request->has('my_attendance')) { + $isStrictlyEmployee = $user->type === 'employee' && !$user->can('manage-attendance-records'); + if ($isStrictlyEmployee || ($request->has('my_attendance') && !$user->can('manage-attendance-records'))) { // For employees, show only their own attendance in calendar view if (!$request->routeIs('hr.attendance-records.calendar')) { return redirect()->route('hr.attendance-records.calendar', array_merge($request->all(), ['my_attendance' => 1])); @@ -958,7 +959,9 @@ class AttendanceRecordController extends Controller $user = Auth::user(); // Employee self-service: show only their own calendar - if ($user->type === 'employee' || $request->has('my_attendance')) { + // If they explicitly requested my_attendance but they are HR, we will show them their branch (as requested) + $isStrictlyEmployee = $user->type === 'employee' && !$user->can('manage-attendance-records'); + if ($isStrictlyEmployee || ($request->has('my_attendance') && !$user->can('manage-attendance-records'))) { $month = $request->input('month', date('n')); $year = $request->input('year', date('Y'));