diff --git a/app/Http/Controllers/AttendanceController.php b/app/Http/Controllers/AttendanceController.php index e2b5957..8f6cc27 100644 --- a/app/Http/Controllers/AttendanceController.php +++ b/app/Http/Controllers/AttendanceController.php @@ -21,7 +21,42 @@ class AttendanceController extends Controller public function index(Request $request): View { - return view('attendances.index'); + $today = now()->toDateString(); + $thisMonth = now()->month; + $thisYear = now()->year; + + // Hitung berdasarkan jumlah siswa unik, bukan total record per jam + $todayStudents = \App\Models\Attendance::where('date', $today) + ->distinct('student_id') + ->count('student_id'); + + $todayAlphaStudents = \App\Models\Attendance::where('date', $today) + ->where('status', 'alpha') + ->distinct('student_id') + ->count('student_id'); + + $monthStudents = \App\Models\Attendance::whereMonth('date', $thisMonth) + ->whereYear('date', $thisYear) + ->distinct('student_id') + ->count('student_id'); + + $monthAlphaStudents = \App\Models\Attendance::whereMonth('date', $thisMonth) + ->whereYear('date', $thisYear) + ->where('status', 'alpha') + ->distinct('student_id') + ->count('student_id'); + + $recentDates = \App\Models\Attendance::select('date') + ->distinct() + ->orderByDesc('date') + ->take(10) + ->get(); + + return view('attendances.index', compact( + 'todayStudents', 'todayAlphaStudents', + 'monthStudents', 'monthAlphaStudents', + 'recentDates' + )); } public function create(Request $request): View diff --git a/resources/views/attendances/index.blade.php b/resources/views/attendances/index.blade.php index 7b5dd4e..1f01229 100644 --- a/resources/views/attendances/index.blade.php +++ b/resources/views/attendances/index.blade.php @@ -25,50 +25,37 @@ {{-- Quick Stats --}} - @php - $today = now()->toDateString(); - $todayAlpha = \App\Models\Attendance::where('date', $today)->where('status', 'alpha')->count(); - $todayTotal = \App\Models\Attendance::where('date', $today)->count(); - $monthTotal = \App\Models\Attendance::whereMonth('date', now()->month)->whereYear('date', now()->year)->count(); - $monthAlpha = \App\Models\Attendance::whereMonth('date', now()->month)->whereYear('date', now()->year)->where('status', 'alpha')->count(); - $recentDates = \App\Models\Attendance::select('date') - ->distinct() - ->orderByDesc('date') - ->take(10) - ->get(); - @endphp -
-

Presensi Hari Ini

-

{{ $todayTotal }}

-

data tercatat

+

Siswa Dipresensi Hari Ini

+

{{ $todayStudents }}

+

siswa tercatat

-

Alpha Hari Ini

-

{{ $todayAlpha }}

-

tanpa keterangan

+

Siswa Alpha Hari Ini

+

{{ $todayAlphaStudents }}

+

siswa tanpa keterangan

-
+
-

Bulan Ini

-

{{ $monthTotal }}

-

total presensi

+

Siswa Bulan Ini

+

{{ $monthStudents }}

+

pernah dipresensi

-

Alpha Bulan Ini

-

{{ $monthAlpha }}

-

pelanggaran

+

Siswa Alpha Bulan Ini

+

{{ $monthAlphaStudents }}

+

pernah alpha