user(); $employee = $user?->employee; $isManager = $user?->hasAnyRole([Role::OWNER->value, Role::DEVELOPER->value, Role::DIREKTUR->value]) ?? false; $scopedEmployeeId = $isManager ? null : $employee?->id; $hasScopedAccess = $isManager || $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, 'isOnLeave' => $employee ? $this->attendanceService->isOnLeaveToday($employee) : false, 'canCheckIn' => ($user?->can(Permission::ATTENDANCES_CREATE->value) ?? false) && $employee !== null, 'canManageAll' => $isManager, 'calendarRange' => [ 'start' => $start->toDateString(), 'end' => $end->toDateString(), ], ]); } public function checkIn(CheckInRequest $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(CheckOutRequest $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('Presensi'); return redirect()->route('admin.hr.attendances.index'); } }