Allow HR users to view branch employees in My Attendance calendar

This commit is contained in:
2026-07-06 13:45:59 +08:00
parent 436dd731d4
commit cde0fe3bff

View File

@@ -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'));