diff --git a/app/Services/Admin/HR/AttendanceService.php b/app/Services/Admin/HR/AttendanceService.php index d722c3e..9cdf722 100644 --- a/app/Services/Admin/HR/AttendanceService.php +++ b/app/Services/Admin/HR/AttendanceService.php @@ -37,7 +37,7 @@ public function getIndexData(int $year, int $month): array return [ 'attendances' => $this->getByMonth($year, $month, $employeeId), 'leaves' => $this->getLeavesByMonth($year, $month, $employeeId), - 'employees' => $isAdmin ? $this->employeeService->getAll() : [], + 'employees' => $isAdmin ? $this->getEmployeesWithAttendancePermission() : [], 'todayAttendance' => $isAdmin ? null : $this->getToday(), 'currentYear' => $year, 'currentMonth' => $month, @@ -79,7 +79,7 @@ public function getByMonthData(int $year, int $month): array return [ 'attendances' => $this->getByMonth($year, $month, $employeeId), 'leaves' => $this->getLeavesByMonth($year, $month, $employeeId), - 'employees' => $this->employeeService->getAll(), + 'employees' => $this->getEmployeesWithAttendancePermission(), 'monthStats' => $this->getMonthStats($year, $month, $employeeId), ]; } @@ -341,4 +341,16 @@ private function formatAttendance(Attendance $attendance): array return $toArray; } + + private function getEmployeesWithAttendancePermission(): Collection + { + return Employee::with(['user.userProfile', 'user.roles']) + ->whereHas('user', fn ($q) => $q->where('is_active', true) + ->whereHas('roles', fn ($rq) => $rq->whereHas('permissions', fn ($pq) => $pq->where('name', 'attendances.view')))) + ->get() + ->map(fn (Employee $employee) => [ + 'id' => $employee->id, + 'name' => $employee->user?->userProfile?->full_name ?? '-', + ]); + } } diff --git a/resources/js/pages/admin/hr/attendance/index.tsx b/resources/js/pages/admin/hr/attendance/index.tsx index 64d4d39..9c87896 100644 --- a/resources/js/pages/admin/hr/attendance/index.tsx +++ b/resources/js/pages/admin/hr/attendance/index.tsx @@ -452,6 +452,7 @@ export default function AttendanceIndex({
Hadir Terlambat + Belum Pulang Cuti
)} @@ -608,6 +609,11 @@ export default function AttendanceIndex({ ? 'Terlambat' : 'Hadir'} + {!att.check_out_at && ( + + Belum Pulang + + )} Masuk :{' '} {formatTime( @@ -616,9 +622,9 @@ export default function AttendanceIndex({ Pulang :{' '} - {formatTime( - att.check_out_at, - )} + {att.check_out_at + ? formatTime(att.check_out_at) + : '-'} {late && (