@php $watermarkPath = public_path('vendor/adminlte/dist/img/MEMA.png'); $watermark = base64_encode(file_get_contents($watermarkPath)); @endphp Watermark
@php $logoLeftPath = public_path('vendor/adminlte/dist/img/MEMA.png'); $logoRightPath = public_path('vendor/adminlte/dist/img/MEMA.webp'); $logoLeft = base64_encode(file_get_contents($logoLeftPath)); $logoRight = base64_encode(file_get_contents($logoRightPath)); @endphp School Logo School Logo

MEMA ASEP Learning Centre

{{ strtoupper($exam->name ?? 'EXAMINATION') }} RESULTS

Class: {{ $class->name ?? 'N/A' }} | Academic Session: {{ $academicSession->name ?? 'N/A' }} | Total Students: {{ count($studentsData) }}
Address: Kisarawe, Pwani | Phone: +255 342 546 | Email: info@mema.ac.tz | Website: www.mema.ac.tz
@php $gradeColors = ['A'=>'#d4edda','B'=>'#d1ecf1','C'=>'#fff3cd','D'=>'#ffe5b4','F'=>'#f8d7da']; // Division counts $divisionCounts = collect($studentsData)->groupBy('division')->map->count(); // Subject averages $allSubjects = collect($studentsData)->flatMap(fn($s) => $s['subjectsData'])->groupBy('subject'); $subjectAverages = $allSubjects->map(fn($subs, $name) => [ 'average_mark' => number_format(collect($subs)->avg(fn($x)=>is_numeric($x['mark'])?$x['mark']:0), 2), 'average_gpa' => number_format(collect($subs)->avg(fn($x)=>floatval($x['point'])), 2), 'type' => $subs->first()['type'] ?? '—' ])->sortKeys(); $bestSubject = $subjectAverages->sortByDesc('average_mark')->keys()->first(); $worstSubject = $subjectAverages->sortBy('average_mark')->keys()->first(); @endphp {{-- ================= Division Summary ================= --}}

Division Summary

DivisionNumber of Students
I{{ $divisionCounts['I'] ?? 0 }}
II{{ $divisionCounts['II'] ?? 0 }}
III{{ $divisionCounts['III'] ?? 0 }}
IV{{ $divisionCounts['IV'] ?? 0 }}
0{{ $divisionCounts['0'] ?? 0 }}
{{-- ================= Student Results Table ================= --}} @foreach($subjects as $subject) @endforeach @foreach(collect($studentsData)->sortBy(fn($d) => $d['student']->full_name)->values() as $i => $data) @php $marksCollection = collect($data['subjectsData']); // Separate core and elective subjects, only numeric marks $coreSubjects = $marksCollection->where('type','core') ->filter(fn($s)=>is_numeric($s['mark'])) ->sortByDesc(fn($s)=>floatval($s['mark'])); $electives = $marksCollection->where('type','elective') ->filter(fn($s)=>is_numeric($s['mark'])) ->sortByDesc(fn($s)=>floatval($s['mark'])); // Take Best 7: core first, then electives $bestSubjects = $coreSubjects->take(7); if($bestSubjects->count() < 7){ $bestSubjects = $bestSubjects->merge($electives->take(7 - $bestSubjects->count())); } $totalMarks = $bestSubjects->sum(fn($s)=>floatval($s['mark'])); $average = $bestSubjects->count() ? number_format($totalMarks/$bestSubjects->count(),2) : '0.00'; $totalPoints = $bestSubjects->sum(fn($s)=>floatval($s['point'])); @endphp @foreach($subjects as $subject) @php $sub = $data['subjectsData'][$subject->id] ?? ['mark'=>'-','grade'=>'-','point'=>0]; $bg = $gradeColors[$sub['grade']] ?? '#fff'; @endphp @endforeach @endforeach
# Student Name{{ $subject->name }}Total Marks (Best 7) Average (Best 7) Total Points GPA Division Position
{{ $i+1 }} {{ $data['student']->full_name }} {{ is_numeric($sub['mark']) ? floatval($sub['mark']) : '-' }} ({{ $sub['grade'] }}) {{ $totalMarks }} {{ $average }} {{ $totalPoints }} {{ number_format($data['gpa'] ?? 0,2) }} {{ $data['division'] ?? 'Unknown' }} {{ $data['position'] ?? ($i+1) }}/{{ count($studentsData) }}