@php /* |-------------------------------------------------------------------------- | IMAGE HELPER - STORAGE/PUBLIC IMAGE TO BASE64 |-------------------------------------------------------------------------- | | This makes border image and school logo reliable in both browser view | and print preview. It also handles paths saved with storage/ or public/. | */ $imageToDataUri = function ($path, $fallbackMime = 'image/png') { if (!$path) { return null; } $path = str_replace('\\', '/', trim((string) $path)); // Already a data URI if (str_starts_with($path, 'data:image/')) { return $path; } // External URL: keep as-is if ( str_starts_with($path, 'http://') || str_starts_with($path, 'https://') ) { return $path; } $normalized = ltrim($path, '/'); if (str_starts_with($normalized, 'storage/')) { $normalized = substr($normalized, strlen('storage/')); } if (str_starts_with($normalized, 'public/')) { $normalized = substr($normalized, strlen('public/')); } try { $disk = \Illuminate\Support\Facades\Storage::disk('public'); if ($disk->exists($normalized)) { $mime = $disk->mimeType($normalized) ?: $fallbackMime; $contents = $disk->get($normalized); return 'data:' . $mime . ';base64,' . base64_encode($contents); } } catch (\Throwable $e) { // Try public paths below. } $publicCandidates = [ public_path($normalized), public_path('storage/' . $normalized), public_path(ltrim($path, '/')), ]; foreach ($publicCandidates as $candidate) { if (is_file($candidate) && is_readable($candidate)) { $mime = function_exists('mime_content_type') ? (mime_content_type($candidate) ?: $fallbackMime) : $fallbackMime; return 'data:' . $mime . ';base64,' . base64_encode( file_get_contents($candidate) ); } } return null; }; /* Border image */ $borderImageSrc = $imageToDataUri('pattern1.png'); // Extra fallback in case pattern1.png is directly under public/storage. if (!$borderImageSrc) { $borderImageSrc = $imageToDataUri('storage/pattern1.png'); } @endphp Progress Reports - Overall Result {{-- ================================================================ PRINT BUTTON ================================================================ --}} @php /* |-------------------------------------------------------------------------- | GRADE SCALE |-------------------------------------------------------------------------- */ $mainGradeScales = \App\Models\GradeScale::orderBy( 'min_mark', 'asc' ) ->get([ 'grade', 'min_mark', 'max_mark', 'grade_point' ]); /* |-------------------------------------------------------------------------- | FORMAT MARK |-------------------------------------------------------------------------- */ $formatMark = function ($value) { if ( $value === null || $value === '' ) { return ''; } if (!is_numeric($value)) { return $value; } return rtrim( rtrim( number_format( (float) $value, 2, '.', '' ), '0' ), '.' ); }; /* |-------------------------------------------------------------------------- | FORMAT GRADE POINT |-------------------------------------------------------------------------- */ $formatPoint = function ($value) { if ( $value === null || $value === '' ) { return ''; } if (!is_numeric($value)) { return $value; } return number_format( (float) $value, 2 ); }; /* |-------------------------------------------------------------------------- | CALCULATE GRADE |-------------------------------------------------------------------------- */ $calculateGrade = function ( $obtained, $full, $forceFail = false ) use ($mainGradeScales) { if ($forceFail) { return [ 'grade' => 'F', 'point' => 0 ]; } if ( !is_numeric($obtained) || !is_numeric($full) || (float) $full <= 0 ) { return [ 'grade' => '', 'point' => null ]; } $percentage = ( (float) $obtained / (float) $full ) * 100; foreach ( $mainGradeScales as $scale ) { $minimum = (float) ( $scale->min_mark ?? 0 ); $maximum = (float) ( $scale->max_mark ?? 100 ); if ( $percentage >= $minimum && $percentage <= $maximum ) { return [ 'grade' => $scale->grade ?? '', 'point' => (float) ( $scale->grade_point ?? 0 ) ]; } } return [ 'grade' => '', 'point' => null ]; }; /* |-------------------------------------------------------------------------- | TERM EXAM GROUPS FOR PDF STYLE OVERALL REPORT |-------------------------------------------------------------------------- | | Only Exam Type = Term will be used as main groups. | Every Term exam is shown together with the MT/other exams merged with it | through exam_weightages. | | Example: | 1st Term (Mark/Obt) | 80% Marks of 1st Term | 1st M.T (20%) (Mark/Obt) | 1st Term Obtained Total | Letter Grade | Grade Point | */ $termGroups = collect(); $termExamsForReport = collect($examList) ->filter(function ($exam) { return strtolower( trim( (string) ( $exam->examType->name ?? '' ) ) ) === 'term'; }) ->values(); foreach ($termExamsForReport as $termExam) { $weightages = \App\Models\ExamWeightage::where( 'term_exam_id', $termExam->id ) ->with([ 'componentExam.examType' ]) ->orderBy('id', 'asc') ->get(); /* |-------------------------------------------------------------------------- | NO MERGE CONFIGURATION |-------------------------------------------------------------------------- | | If no weightage configuration exists, the Term exam itself is 100%. | */ if ($weightages->isEmpty()) { $ownWeight = new \App\Models\ExamWeightage([ 'term_exam_id' => $termExam->id, 'component_exam_id' => $termExam->id, 'weightage_percent' => 100, ]); $ownWeight->setRelation( 'componentExam', $termExam ); $weightages = collect([ $ownWeight ]); } /* |-------------------------------------------------------------------------- | MAKE SURE TERM EXAM ITSELF EXISTS IN WEIGHTAGE LIST |-------------------------------------------------------------------------- | | Example: | MT = 20% | Then remaining Term percentage = 80%. | */ $termWeightRow = $weightages ->first(function ($row) use ($termExam) { return (int) $row->component_exam_id === (int) $termExam->id; }); if (!$termWeightRow) { $otherPercentage = (float) $weightages ->sum('weightage_percent'); $remainingPercentage = max( 0, 100 - $otherPercentage ); /* * If configuration has only merged exams and their total * unexpectedly reaches 100, keep Term at 0 rather than * inventing an additional percentage. */ $termWeightRow = new \App\Models\ExamWeightage([ 'term_exam_id' => $termExam->id, 'component_exam_id' => $termExam->id, 'weightage_percent' => $remainingPercentage, ]); $termWeightRow->setRelation( 'componentExam', $termExam ); $weightages->prepend( $termWeightRow ); } /* |-------------------------------------------------------------------------- | TERM FIRST, MERGED EXAMS AFTER TERM |-------------------------------------------------------------------------- */ $weightages = $weightages ->sortBy(function ($row) use ($termExam) { return (int) $row->component_exam_id === (int) $termExam->id ? 0 : 1; }) ->values(); $termWeightRow = $weightages ->first(function ($row) use ($termExam) { return (int) $row->component_exam_id === (int) $termExam->id; }); $mergedComponents = $weightages ->filter(function ($row) use ($termExam) { return (int) $row->component_exam_id !== (int) $termExam->id && $row->componentExam; }) ->values(); $termWeightVal = (float) ( $termWeightRow->weightage_percent ?? 100 ); $termGroups->push([ 'term_exam' => $termExam, 'term_weightage' => $termWeightVal, 'components' => $weightages, 'merged_components' => $mergedComponents, 'has_merge' => $mergedComponents->isNotEmpty() && $termWeightVal < 100, ]); } /* |-------------------------------------------------------------------------- | DYNAMIC TABLE COLUMN COUNT |-------------------------------------------------------------------------- | | Base: | SL + Subject + Full Marks = 3 | | Per Term: | Term Mark/Obt = 2 | Weighted Term column = 1 (only when merge exists) | Every merged exam = 2 (Mark/Obt) | Term Obtained Total + Grade + Point = 3 | | Final: | Obtained Total + Average + Highest + Letter + Point = 5 | */ $globalClassCode = (int) ($class->class_code ?? -1); $isSecondaryClass = ($globalClassCode >= 9); $summaryColCount = $isSecondaryClass ? 3 : 2; $marksTableColumnCount = 3 + 5 + $summaryColCount; foreach ($termGroups as $group) { $mergedCount = $group['merged_components'] ->count(); $marksTableColumnCount += 2 + ( $group['has_merge'] ? 1 : 0 ) + ($mergedCount * 2) + 3; } @endphp @forelse($cards as $studentCard) @php /* |-------------------------------------------------------------------------- | CARD DATA FROM CONTROLLER |-------------------------------------------------------------------------- */ $registration = $studentCard['registration']; $student = $registration->student; $results = $studentCard['results'] ?? []; $merit = $studentCard['merit'] ?? null; $overallResult = $studentCard['overallResult'] ?? null; $classCode = (int) ( $registration->class_model?->class_code ?? $class->class_code ?? -1 ); $isSecondary = ($classCode >= 9); $totalSubjects = count($results); $pairedCount = collect($results) ->filter(fn($r) => !empty($r['is_paired'])) ->count(); $hasAdditional = collect($results) ->contains(fn($r) => !empty($r['is_fourth'])); $additionalRowCount = $hasAdditional ? 1 : 0; $grandTotalRowCount = 1; $rowspanCount = $totalSubjects + $pairedCount + $additionalRowCount + $grandTotalRowCount; $formatPosition = function ($pos) { if (!$pos) return '-'; $num = (int) $pos; if (!in_array(($num % 100), [11, 12, 13])) { switch ($num % 10) { case 1: return $num . 'st'; case 2: return $num . 'nd'; case 3: return $num . 'rd'; } } return $num . 'th'; }; $schoolInfo = $studentCard['schoolInfo'] ?? null; /* |-------------------------------------------------------------------------- | SCHOOL LOGO SOURCE |-------------------------------------------------------------------------- */ $schoolLogoSrc = null; if ( $schoolInfo && !empty($schoolInfo->school_logo) ) { $schoolLogoSrc = $imageToDataUri( $schoolInfo->school_logo ); } /* Default logo fallback */ if (!$schoolLogoSrc) { $schoolLogoSrc = $imageToDataUri( 'images/default-avatar.png' ); } /* Last fallback: normal public URL */ if (!$schoolLogoSrc) { $schoolLogoSrc = asset('images/default-avatar.png'); } $facultyComments = $studentCard['facultyComments'] ?? collect(); /* |-------------------------------------------------------------------------- | GRADE TABLE FULL MARK |-------------------------------------------------------------------------- */ $gradeTableFullMarks = (float) ( $summaryExam?->full_mark ?? $summaryExam?->full_marks ?? 100 ); if ($gradeTableFullMarks <= 0) { $gradeTableFullMarks = 100; } /* |-------------------------------------------------------------------------- | SORT SUBJECTS |-------------------------------------------------------------------------- | | Normal subjects first. | Additional subject last. | */ $regularSubjects = collect($results) ->filter(function ($result) { return empty( $result['is_fourth'] ); }); $additionalSubjects = collect($results) ->filter(function ($result) { return !empty( $result['is_fourth'] ); }); $orderedResults = $regularSubjects->concat( $additionalSubjects ); /* |-------------------------------------------------------------------------- | GRAND TOTAL VARIABLES |-------------------------------------------------------------------------- */ $grandFullMarks = 0; $examGrandFull = []; $examGrandObt = []; foreach ($examList as $exam) { $examGrandFull[$exam->id] = 0; $examGrandObt[$exam->id] = 0; } $additionalHeaderShown = false; @endphp
{{-- ======================================================== SCHOOL HEADER ========================================================= --}}
{{-- GRADE TABLE --}}
@forelse($mainGradeScales as $scale) @php $displayMin = ( $gradeTableFullMarks * (float) ( $scale->min_mark ?? 0 ) ) / 100; $displayMax = ( $gradeTableFullMarks * (float) ( $scale->max_mark ?? 100 ) ) / 100; @endphp @empty @endforelse
Interval Letter GPA
{{ $formatMark( $displayMin ) }} - {{ $formatMark( $displayMax ) }} {{ $scale->grade }} {{ number_format( $scale->grade_point ?? 0, 2 ) }}
0 - 100 N/A 0.00
{{-- SCHOOL NAME --}}

{{ $schoolInfo->school_name ?? '--' }}

{{ $schoolInfo->address ?? '--' }}

{{-- LOGO --}}
Progress Report
{{-- ======================================================== STUDENT INFORMATION ========================================================= --}}
Student's Name: {{ $student->student_name_english ?? 'N/A' }} Class: {{ $registration ->class_model ->name ?? 'N/A' }} Group: {{ $registration ->group ->name ?? 'N/A' }} Session: {{ $registration ->session ->name ?? 'N/A' }}
Section: {{ $registration ->section ->name ?? 'N/A' }} Roll: {{ $registration ->class_roll ?? 'N/A' }} Shift: {{ $registration ->shift ->name ?? 'N/A' }} Exam Name: Overall Result
{{-- ======================================================== TERM RESULT CACHE + GROUP VALUE HELPER ========================================================= --}} @php $termExamIds = $termGroups ->map(function ($group) { return $group['term_exam']->id; }) ->values(); /* |-------------------------------------------------------------------------- | TERM FINAL RESULTS |-------------------------------------------------------------------------- | | ExamResult of the Term exam already contains the final result after | the configured MT/other exam merge. Therefore the report displays | the real processed Term total/grade instead of guessing it again. | */ $termResultRows = \App\Models\ExamResult::where( 'student_id', $registration->student_id ) ->whereIn( 'exam_id', $termExamIds ) ->get() ->keyBy(function ($row) { return $row->exam_id . '_' . $row->subject_id; }); /* |-------------------------------------------------------------------------- | BUILD ONE TERM GROUP FOR ONE SUBJECT/PAPER |-------------------------------------------------------------------------- */ $buildGroupValue = function ( $examTotals, $subjectId, $group ) use ( $termResultRows, $calculateGrade ) { $termExam = $group['term_exam']; $termExamId = $termExam->id; $termRaw = $examTotals[$termExamId] ?? [ 'full' => 0, 'obt' => 0 ]; $termFull = is_numeric( $termRaw['full'] ?? null ) ? (float) $termRaw['full'] : 0; $termObt = $termRaw['obt'] ?? 0; $termWeightage = (float) ( $group['term_weightage'] ?? 100 ); /* |-------------------------------------------------------------------------- | PDF STYLE WEIGHTED TERM MARK |-------------------------------------------------------------------------- | | Example: | 1st Term full = 100 | weight = 80% | weighted full = 80 | | ICT: | full = 50 | weight = 80% | weighted full = 40 | */ $termWeightedFull = $group['has_merge'] ? ( $termFull * $termWeightage / 100 ) : $termFull; if (is_numeric($termObt)) { $termWeightedObt = $group['has_merge'] ? ( (float) $termObt * $termWeightage / 100 ) : (float) $termObt; } else { $termWeightedObt = $termObt; } $mergedValues = collect(); $mergedFullTotal = 0; $mergedObtTotal = 0; $hasAbsent = !is_numeric( $termObt ); foreach ( $group['merged_components'] as $weightRow ) { $componentExam = $weightRow->componentExam; if (!$componentExam) { continue; } $componentRaw = $examTotals[$componentExam->id] ?? [ 'full' => 0, 'obt' => 0 ]; $componentFull = is_numeric( $componentRaw['full'] ?? null ) ? (float) $componentRaw['full'] : 0; $componentObt = $componentRaw['obt'] ?? 0; $mergedFullTotal += $componentFull; if (is_numeric($componentObt)) { $mergedObtTotal += (float) $componentObt; } else { $hasAbsent = true; } $mergedValues->push([ 'exam' => $componentExam, 'weightage' => (float) ( $weightRow ->weightage_percent ?? 0 ), 'full' => $componentFull, 'obt' => $componentObt, ]); } /* |-------------------------------------------------------------------------- | FINAL FULL MARK OF THIS TERM |-------------------------------------------------------------------------- | | PDF logic: | | Term 100 × 80% = 80 | MT full = 20 | Final full = 100 | | ICT: | 50 × 80% = 40 | MT full = 10 | Final full = 50 | */ $finalFull = $termWeightedFull + $mergedFullTotal; $computedFinalObt = ( is_numeric( $termWeightedObt ) ? (float) $termWeightedObt : 0 ) + $mergedObtTotal; /* |-------------------------------------------------------------------------- | USE SAVED TERM RESULT AS SOURCE OF TRUTH |-------------------------------------------------------------------------- */ $termResultKey = $termExamId . '_' . $subjectId; $termResult = $termResultRows[ $termResultKey ] ?? null; if ($termResult) { $finalObt = $termResult->is_absent ? 'AB' : ( $termResult ->total_obtained ?? $computedFinalObt ); $grade = $termResult->grade ?? ''; $point = $termResult->grade_point ?? null; } else { $finalObt = $hasAbsent ? 'AB' : $computedFinalObt; $calculated = $calculateGrade( $computedFinalObt, $finalFull, $hasAbsent ); $grade = $calculated['grade']; $point = $calculated['point']; } return [ 'term_exam' => $termExam, 'term_full' => $termFull, 'term_obt' => $termObt, 'term_weightage' => $termWeightage, 'term_weighted_full' => $termWeightedFull, 'term_weighted_obt' => $termWeightedObt, 'merged' => $mergedValues, 'final_full' => $finalFull, 'final_obt' => $finalObt, 'grade' => $grade, 'point' => $point, ]; }; @endphp {{-- ======================================================== NO DATA ========================================================= --}} @if( $termGroups->isEmpty() || empty($results) )

No Term exam data available for this student.

@else {{-- ==================================================== TITLE ===================================================== --}} {{-- ==================================================== PDF STYLE MARKS TABLE ===================================================== --}}
@foreach( $termGroups as $group ) {{-- Term Mark / Obt --}} {{-- Weighted Term --}} @if( $group['has_merge'] ) @endif {{-- Merged Exam Mark / Obt --}} @foreach( $group['merged_components'] as $weightRow ) @endforeach {{-- Term Total / Grade / Point --}} @endforeach {{-- Overall final columns --}} {{-- Overall Summary columns --}} @if($isSecondary) @else @endif {{-- ============================================== HEADER =============================================== --}} @foreach( $termGroups as $group ) @php $termExam = $group['term_exam']; $termWeight = $group[ 'term_weightage' ]; @endphp {{-- TERM EXAM --}} {{-- WEIGHTED TERM COLUMN --}} @if( $group['has_merge'] ) @endif {{-- MERGED MT / OTHER EXAMS --}} @foreach( $group[ 'merged_components' ] as $weightRow ) @php $mergedExam = $weightRow ->componentExam; $mergedWeight = $weightRow ->weightage_percent ?? null; @endphp @endforeach {{-- TERM FINAL --}} @endforeach {{-- OVERALL FINAL --}} @if($isSecondary) @else @endif @foreach( $termGroups as $group ) {{-- TERM EXAM MARK / OBT --}} {{-- MERGED EXAM MARK / OBT --}} @foreach( $group[ 'merged_components' ] as $weightRow ) @endforeach @endforeach {{-- ============================================== BODY =============================================== --}} @php $sl = 1; $additionalHeaderShown = false; $grandFullMarks = 0; $grandObtainedTotal = 0; $grandGroupTotals = []; foreach ( $termGroups as $group ) { $termId = $group[ 'term_exam' ]->id; $grandGroupTotals[ $termId ] = [ 'term_full' => 0, 'term_obt' => 0, 'term_weighted_obt' => 0, 'merged' => [], 'final_obt' => 0, ]; foreach ( $group[ 'merged_components' ] as $weightRow ) { $componentId = $weightRow ->component_exam_id; $grandGroupTotals[ $termId ]['merged'][ $componentId ] = [ 'full' => 0, 'obt' => 0, ]; } } /* |-------------------------------------------------------------------------- | ACCUMULATE ONE DISPLAY ROW INTO GRAND TOTAL |-------------------------------------------------------------------------- */ $addRowToGrand = function ( $rowGroups, $rowFull, $rowObt ) use ( &$grandGroupTotals, &$grandFullMarks, &$grandObtainedTotal ) { $grandFullMarks += $rowFull; $grandObtainedTotal += $rowObt; foreach ( $rowGroups as $termId => $g ) { $grandGroupTotals[ $termId ]['term_full'] += is_numeric( $g['term_full'] ) ? (float) $g[ 'term_full' ] : 0; $grandGroupTotals[ $termId ]['term_obt'] += is_numeric( $g['term_obt'] ) ? (float) $g[ 'term_obt' ] : 0; $grandGroupTotals[ $termId ]['term_weighted_obt'] += is_numeric( $g[ 'term_weighted_obt' ] ) ? (float) $g[ 'term_weighted_obt' ] : 0; foreach ( $g['merged'] as $merged ) { $componentId = $merged[ 'exam' ]->id; $grandGroupTotals[ $termId ]['merged'][ $componentId ]['full'] += is_numeric( $merged[ 'full' ] ) ? (float) $merged[ 'full' ] : 0; $grandGroupTotals[ $termId ]['merged'][ $componentId ]['obt'] += is_numeric( $merged[ 'obt' ] ) ? (float) $merged[ 'obt' ] : 0; } $grandGroupTotals[ $termId ]['final_obt'] += is_numeric( $g[ 'final_obt' ] ) ? (float) $g[ 'final_obt' ] : 0; } }; @endphp @foreach( $orderedResults as $result ) {{-- ========================================== ADDITIONAL SUBJECT HEADER =========================================== --}} @if( !empty( $result['is_fourth'] ) && !$additionalHeaderShown ) @php $additionalHeaderShown = true; @endphp @endif {{-- ========================================== PAIRED SUBJECT =========================================== --}} @if( !empty( $result['is_paired'] ) ) @php $paper1 = $result['paper1'] ?? []; $paper2 = $result['paper2'] ?? []; $paper1Totals = $paper1[ 'exam_totals' ] ?? []; $paper2Totals = $paper2[ 'exam_totals' ] ?? []; $paper1SubjectId = $paper1[ 'subject_id' ] ?? null; $paper2SubjectId = $paper2[ 'subject_id' ] ?? null; /* |-------------------------------------------------------------------------- | PAPER 1 GROUPS |-------------------------------------------------------------------------- */ $paper1Groups = []; foreach ( $termGroups as $group ) { $termId = $group[ 'term_exam' ]->id; $paper1Groups[ $termId ] = $buildGroupValue( $paper1Totals, $paper1SubjectId, $group ); } /* |-------------------------------------------------------------------------- | PAPER 2 GROUPS |-------------------------------------------------------------------------- */ $paper2Groups = []; foreach ( $termGroups as $group ) { $termId = $group[ 'term_exam' ]->id; $paper2Groups[ $termId ] = $buildGroupValue( $paper2Totals, $paper2SubjectId, $group ); } /* |-------------------------------------------------------------------------- | PAPER TOTALS |-------------------------------------------------------------------------- */ $paper1FullTotal = collect( $paper1Groups ) ->sum( 'final_full' ); $paper2FullTotal = collect( $paper2Groups ) ->sum( 'final_full' ); $paper1ObtTotal = collect( $paper1Groups ) ->sum(function ($g) { return is_numeric( $g[ 'final_obt' ] ) ? (float) $g[ 'final_obt' ] : 0; }); $paper2ObtTotal = collect( $paper2Groups ) ->sum(function ($g) { return is_numeric( $g[ 'final_obt' ] ) ? (float) $g[ 'final_obt' ] : 0; }); $paper1ValidTerms = collect( $paper1Groups ) ->filter(function ($g) { return $g[ 'final_full' ] > 0; }) ->count(); $paper2ValidTerms = collect( $paper2Groups ) ->filter(function ($g) { return $g[ 'final_full' ] > 0; }) ->count(); $paper1Average = $paper1ValidTerms > 0 ? ( $paper1ObtTotal / $paper1ValidTerms ) : 0; $paper2Average = $paper2ValidTerms > 0 ? ( $paper2ObtTotal / $paper2ValidTerms ) : 0; /* |-------------------------------------------------------------------------- | COMBINED OVERALL GRADE |-------------------------------------------------------------------------- */ $pairFullTotal = $paper1FullTotal + $paper2FullTotal; $pairObtTotal = $paper1ObtTotal + $paper2ObtTotal; $pairHasTermFail = false; foreach ($termGroups as $group) { $termId = $group['term_exam']->id; $g1 = $paper1Groups[$termId] ?? null; $g2 = $paper2Groups[$termId] ?? null; $p1Full = is_numeric($g1['final_full'] ?? null) ? (float) $g1['final_full'] : 0; $p2Full = is_numeric($g2['final_full'] ?? null) ? (float) $g2['final_full'] : 0; $p1Obt = is_numeric($g1['final_obt'] ?? null) ? (float) $g1['final_obt'] : 0; $p2Obt = is_numeric($g2['final_obt'] ?? null) ? (float) $g2['final_obt'] : 0; $termCombFull = $p1Full + $p2Full; $termCombObt = $p1Obt + $p2Obt; $p1Absent = !is_numeric($g1['final_obt'] ?? null); $p2Absent = !is_numeric($g2['final_obt'] ?? null); if ($termCombFull > 0) { $termPct = ($termCombObt / $termCombFull) * 100; if ($termPct < 33.0 || ($p1Absent && $p2Absent)) { $pairHasTermFail = true; break; } } elseif ($p1Absent && $p2Absent) { $pairHasTermFail = true; break; } } $pairFail = $pairHasTermFail || ( $pairFullTotal > 0 && ( ( (float) $pairObtTotal / (float) $pairFullTotal ) * 100 ) < 33.0 ) || ($paper1FullTotal == 0 && $paper2FullTotal == 0); $pairGrade = $calculateGrade( $pairObtTotal, $pairFullTotal, $pairFail ); $pairHighest = $result['final'] ->highest_marks ?? 0; /* |-------------------------------------------------------------------------- | GRAND TOTAL |-------------------------------------------------------------------------- */ $addRowToGrand( $paper1Groups, $paper1FullTotal, $paper1ObtTotal ); $addRowToGrand( $paper2Groups, $paper2FullTotal, $paper2ObtTotal ); @endphp {{-- ====================================== PAPER 1 ROW ======================================= --}} @foreach( $termGroups as $group ) @php $termId = $group[ 'term_exam' ]->id; $g = $paper1Groups[ $termId ]; @endphp {{-- TERM MARK --}} {{-- TERM OBT --}} {{-- WEIGHTED TERM --}} @if( $group['has_merge'] ) @endif {{-- MERGED EXAMS --}} @foreach( $g['merged'] as $merged ) @endforeach {{-- TERM TOTAL --}} {{-- TERM LETTER --}} {{-- TERM POINT --}} @endforeach {{-- OVERALL TOTAL --}} {{-- AVERAGE --}} {{-- COMBINED HIGHEST --}} {{-- COMBINED LETTER --}} {{-- COMBINED POINT --}} @if ($loop->first) @if($isSecondary) @else @endif @endif {{-- ====================================== PAPER 2 ROW ======================================= --}} @foreach( $termGroups as $group ) @php $termId = $group[ 'term_exam' ]->id; $g = $paper2Groups[ $termId ]; @endphp @if( $group['has_merge'] ) @endif @foreach( $g['merged'] as $merged ) @endforeach @endforeach {{-- ========================================== NORMAL SUBJECT =========================================== --}} @else @php $examTotals = $result[ 'exam_totals' ] ?? []; $subjectId = $result[ 'subject_id' ] ?? null; $rowGroups = []; foreach ( $termGroups as $group ) { $termId = $group[ 'term_exam' ]->id; $rowGroups[ $termId ] = $buildGroupValue( $examTotals, $subjectId, $group ); } $subjectFullTotal = collect( $rowGroups ) ->sum( 'final_full' ); $subjectObtTotal = collect( $rowGroups ) ->sum(function ($g) { return is_numeric( $g[ 'final_obt' ] ) ? (float) $g[ 'final_obt' ] : 0; }); $subjectExamCount = collect( $rowGroups ) ->filter(function ($g) { return $g[ 'final_full' ] > 0; }) ->count(); $subjectAverage = $subjectExamCount > 0 ? ( $subjectObtTotal / $subjectExamCount ) : 0; $singleSubjectHasTermFail = collect($rowGroups) ->contains(function ($g) { return ($g['grade'] ?? '') === 'F' || (float) ($g['point'] ?? 0) <= 0 || !is_numeric($g['final_obt'] ?? null); }); $overallFail = $singleSubjectHasTermFail || ( $subjectFullTotal > 0 && ( ( (float) $subjectObtTotal / (float) $subjectFullTotal ) * 100 ) < 33.0 ) || ($subjectFullTotal == 0); $overallGrade = $calculateGrade( $subjectObtTotal, $subjectFullTotal, $overallFail ); $highestMarks = $result['final'] ->highest_marks ?? 0; $addRowToGrand( $rowGroups, $subjectFullTotal, $subjectObtTotal ); @endphp @foreach( $termGroups as $group ) @php $termId = $group[ 'term_exam' ]->id; $g = $rowGroups[ $termId ]; @endphp {{-- TERM MARK --}} {{-- TERM OBT --}} {{-- WEIGHTED TERM --}} @if( $group['has_merge'] ) @endif {{-- MERGED EXAMS --}} @foreach( $g['merged'] as $merged ) @endforeach {{-- TERM FINAL TOTAL --}} {{-- TERM LETTER --}} {{-- TERM POINT --}} @endforeach {{-- OVERALL OBTAINED TOTAL --}} {{-- AVERAGE --}} {{-- HIGHEST --}} {{-- OVERALL LETTER --}} {{-- OVERALL POINT --}} @if ($loop->first) @if($isSecondary) @else @endif @endif @endif @endforeach {{-- ============================================== GRAND TOTAL =============================================== --}} @php $validOverallTermCount = $termGroups ->count(); $grandAverage = $validOverallTermCount > 0 ? ( $grandObtainedTotal / $validOverallTermCount ) : 0; @endphp @foreach( $termGroups as $group ) @php $termId = $group[ 'term_exam' ]->id; $grandG = $grandGroupTotals[ $termId ]; @endphp {{-- TERM RAW TOTALS --}} {{-- WEIGHTED TERM TOTAL --}} @if( $group['has_merge'] ) @endif {{-- MERGED EXAM TOTALS --}} @foreach( $group[ 'merged_components' ] as $weightRow ) @php $componentId = $weightRow ->component_exam_id; $mergedGrand = $grandG[ 'merged' ][ $componentId ] ?? [ 'full' => 0, 'obt' => 0, ]; @endphp @endforeach {{-- TERM FINAL GRAND TOTAL --}} @endforeach {{-- OVERALL GRAND TOTAL --}}
SL Subjects Full
Marks
{{ $termExam->exam_name ?? 'Term' }} {{ $formatMark( $termWeight ) }}%
Marks
of
{{ $termExam->exam_name ?? 'Term' }}
{{ $mergedExam->exam_name ?? 'Merged Exam' }} @if( $mergedWeight !== null && (float) $mergedWeight < 100 ) ({{ $formatMark( $mergedWeight ) }}%) @endif {{ $termExam->exam_name ?? 'Term' }}
Obtained
Total
Letter
Grade
Grade
Point
Obtained
Total
Average
Obtained
Total
Highest
Marks
Letter
Grade
Grade
Point
Avg. GPA
(Without
4th subject)
Avg.
GPA
Position Avg.
GPA
Position
Mark Obt Mark Obt
Additional Subject:
{{ $sl++ }} {{ $result[ 'subject_name' ] ?? '—' }} {{ $formatMark( $paper1FullTotal ) }} {{ $formatMark( $g[ 'term_full' ] ) }} {{ $formatMark( $g[ 'term_obt' ] ) }} {{ $formatMark( $g[ 'term_weighted_obt' ] ) }} {{ $formatMark( $merged[ 'full' ] ) }} {{ $formatMark( $merged[ 'obt' ] ) }} {{ $formatMark( $g[ 'final_obt' ] ) }} {{ $g['grade'] }} {{ $formatPoint( $g['point'] ) }} {{ $formatMark( $paper1ObtTotal ) }} {{ $formatMark( $paper1Average ) }} {{ $formatMark( $pairHighest ) }} {{ $pairGrade[ 'grade' ] }} {{ $formatPoint( $pairGrade[ 'point' ] ) }} {{ $overallResult ? number_format($overallResult->gpa_without_4th ?? 0, 2) : '-' }} {{ $overallResult ? number_format($overallResult->gpa ?? 0, 2) : '-' }} {{ $overallResult && $overallResult->position ? $formatPosition($overallResult->position) : '-' }} {{ $overallResult ? number_format($overallResult->gpa ?? 0, 2) : '-' }} {{ $overallResult && $overallResult->position ? $formatPosition($overallResult->position) : '-' }}
{{ $formatMark( $paper2FullTotal ) }} {{ $formatMark( $g[ 'term_full' ] ) }} {{ $formatMark( $g[ 'term_obt' ] ) }} {{ $formatMark( $g[ 'term_weighted_obt' ] ) }} {{ $formatMark( $merged[ 'full' ] ) }} {{ $formatMark( $merged[ 'obt' ] ) }} {{ $formatMark( $g[ 'final_obt' ] ) }} {{ $g['grade'] }} {{ $formatPoint( $g['point'] ) }} {{ $formatMark( $paper2ObtTotal ) }} {{ $formatMark( $paper2Average ) }}
{{ $sl++ }} {{ $result[ 'subject_name' ] ?? '—' }} {{ $formatMark( $subjectFullTotal ) }} {{ $formatMark( $g[ 'term_full' ] ) }} {{ $formatMark( $g[ 'term_obt' ] ) }} {{ $formatMark( $g[ 'term_weighted_obt' ] ) }} {{ $formatMark( $merged[ 'full' ] ) }} {{ $formatMark( $merged[ 'obt' ] ) }} {{ $formatMark( $g[ 'final_obt' ] ) }} {{ $g['grade'] }} {{ $formatPoint( $g['point'] ) }} {{ $formatMark( $subjectObtTotal ) }} {{ $formatMark( $subjectAverage ) }} {{ $formatMark( $highestMarks ) }} {{ $overallGrade[ 'grade' ] }} {{ $formatPoint( $overallGrade[ 'point' ] ) }} {{ $overallResult ? number_format($overallResult->gpa_without_4th ?? 0, 2) : '-' }} {{ $overallResult ? number_format($overallResult->gpa ?? 0, 2) : '-' }} {{ $overallResult && $overallResult->position ? $formatPosition($overallResult->position) : '-' }} {{ $overallResult ? number_format($overallResult->gpa ?? 0, 2) : '-' }} {{ $overallResult && $overallResult->position ? $formatPosition($overallResult->position) : '-' }}
Grand Total {{ $formatMark( $grandFullMarks ) }} {{ $formatMark( $grandG[ 'term_full' ] ) }} {{ $formatMark( $grandG[ 'term_obt' ] ) }} {{ $formatMark( $grandG[ 'term_weighted_obt' ] ) }} {{ $formatMark( $mergedGrand[ 'full' ] ) }} {{ $formatMark( $mergedGrand[ 'obt' ] ) }} {{ $formatMark( $grandG[ 'final_obt' ] ) }} - - {{ $formatMark( $grandObtainedTotal ) }} {{ $formatMark( $grandAverage ) }} - - -
@endif {{-- ======================================================== PERFORMANCE / COMMENTS ========================================================= --}}
{{-- PERFORMANCE --}}
@php $perf = $summaryExam ? \App\Models\StudentPerformance::where( 'exam_id', $summaryExam->id ) ->where( 'student_id', $registration->student_id ) ->first() : null; @endphp
Categories Excellent Very Good Good Average
Behaviour {{ $perf && $perf->behaviour === 'Ex.' ? '✓' : '' }} {{ $perf && $perf->behaviour === 'V.G' ? '✓' : '' }} {{ $perf && $perf->behaviour === 'Good' ? '✓' : '' }} {{ $perf && $perf->behaviour === 'Avg.' ? '✓' : '' }}
Dress Up {{ $perf && $perf->dress_up === 'Ex.' ? '✓' : '' }} {{ $perf && $perf->dress_up === 'V.G' ? '✓' : '' }} {{ $perf && $perf->dress_up === 'Good' ? '✓' : '' }} {{ $perf && $perf->dress_up === 'Avg.' ? '✓' : '' }}
Performance {{ $perf && $perf->performance === 'Ex.' ? '✓' : '' }} {{ $perf && $perf->performance === 'V.G' ? '✓' : '' }} {{ $perf && $perf->performance === 'Good' ? '✓' : '' }} {{ $perf && $perf->performance === 'Avg.' ? '✓' : '' }}
Co-Curricular {{ $perf && $perf->co_curriculum === 'Ex.' ? '✓' : '' }} {{ $perf && $perf->co_curriculum === 'V.G' ? '✓' : '' }} {{ $perf && $perf->co_curriculum === 'Good' ? '✓' : '' }} {{ $perf && $perf->co_curriculum === 'Avg.' ? '✓' : '' }}
{{-- ==================================================== FACULTY COMMENTS ===================================================== --}}
@php $commentRoles = [ 'Form Teacher', 'Assistant Co-Ordinator', 'Co-Ordinator', 'Vice-Principal', ]; @endphp @foreach( $commentRoles as $role ) @php $comment = $facultyComments[$role][0] ->comment ?? '—'; @endphp @endforeach
Designation Comments
{{ $role }} {{ $comment }}
{{-- ==================================================== PRINCIPAL ===================================================== --}}
@php $principalComment = $facultyComments['Principal'][0] ->comment ?? '—'; @endphp
Remark Principal's Signature
{{ $principalComment }}  
@empty

No student data available for this class.

@endforelse {{-- ================================================================ BOTTOM PRINT BUTTON ================================================================ --}}