fix: attendance stats count based on unique students, not records per lesson-hour

This commit is contained in:
Bro
2026-07-22 23:56:57 +07:00
parent 31ef9c0b0b
commit e4fef817b0
2 changed files with 49 additions and 27 deletions
+36 -1
View File
@@ -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