user(); $employee = $user?->employee; $canManageAll = $user?->can(Permission::ATTENDANCES_MANAGE->value) ?? false; $scopedEmployeeId = $canManageAll ? null : $employee?->id; $hasScopedAccess = $canManageAll || $employee !== null; $start = $request->date('start') ?? now()->startOfMonth(); $end = $request->date('end') ?? now()->endOfMonth(); return Inertia::render('admin/hr/attendances/Index', [ 'attendances' => $this->attendanceService->listForCalendar( $start, $end, $scopedEmployeeId, $hasScopedAccess, ), 'todayAttendance' => $employee ? $this->attendanceService->todayAttendanceForEmployee($employee) : null, 'canCheckIn' => ($user?->can(Permission::ATTENDANCES_CREATE->value) ?? false) && $employee !== null, 'canManageAll' => $canManageAll, 'calendarRange' => [ 'start' => $start->toDateString(), 'end' => $end->toDateString(), ], ]); } public function checkIn(AttendanceCheckInRequest $request): RedirectResponse { $this->attendanceService->checkIn($request->validated(), $request->user()); $this->flashSuccess('Presensi masuk berhasil dicatat.'); return redirect()->route('admin.hr.attendances.index'); } public function checkOut(AttendanceCheckOutRequest $request): RedirectResponse { $this->attendanceService->checkOut($request->validated(), $request->user()); $this->flashSuccess('Presensi pulang berhasil dicatat.'); return redirect()->route('admin.hr.attendances.index'); } public function destroy(Attendance $attendance): RedirectResponse { $this->attendanceService->delete($attendance); $this->flashDeleted('Data presensi'); return redirect()->route('admin.hr.attendances.index'); } }