user()->employee; if (!$employee) { return Inertia::render('employee/index', [ 'stats' => null, ]); } $currentMonth = Carbon::now()->month; $currentYear = Carbon::now()->year; $attendances = Attendance::where('employee_id', $employee->id) ->whereMonth('date', $currentMonth) ->whereYear('date', $currentYear) ->get(); $presentCount = $attendances->where('status', 'present')->count(); $leaveCount = $attendances->where('status', 'leave')->count(); $dispensationCount = $attendances->where('status', 'dispensation')->count(); // Batas telat 08:00 $onTimeCount = $attendances->where('status', 'present')->filter(function ($att) { return $att->check_in && $att->check_in <= '08:00:00'; })->count(); $lateCount = $attendances->where('status', 'present')->filter(function ($att) { return $att->check_in && $att->check_in > '08:00:00'; })->count(); return Inertia::render('employee/index', [ 'stats' => [ 'present' => $presentCount, 'leave' => $leaveCount, 'dispensation' => $dispensationCount, 'on_time' => $onTimeCount, 'late' => $lateCount, ], 'employee' => $employee, ]); } }