@php $t = $ctx['settings']; $s = $ctx['student']; $school = $ctx['school']; $term = $ctx['term']; $row = $ctx['row'] ?? null; $sheet = $ctx['sheet'] ?? null; $pdf = $pdf ?? false; $flag = fn (string $k) => \App\Services\Academic\ResultTemplateService::flag($t, $k); $val = fn (string $k, $d = null) => $t[$k] ?? $d; $img = fn (?string $p) => result_asset($p, $pdf); $segment = $s->class?->name ?? ''; $arm = $s->class?->section ?? null; // Watermark positioning $wmPos = $val('watermark_position', 'center'); $wmStyle = 'left:50%; top:45%; transform:translate(-50%,-50%);'; if ($wmPos === 'top-left') { $wmStyle = 'left:6mm; top:6mm;'; } if ($wmPos === 'top-right') { $wmStyle = 'right:6mm; top:6mm;'; } if ($wmPos === 'bottom-left') { $wmStyle = 'left:6mm; bottom:6mm;'; } if ($wmPos === 'bottom-right'){ $wmStyle = 'right:6mm; bottom:6mm;'; } if ($flag('enable_watermark') && $val('watermark_type', 'logo') !== 'none' && $val('watermark_opacity', 0.08) > 0) { $wmOpacity = max(0, min(1, (float) $val('watermark_opacity', 0.08))); $wmSize = max(20, (int) $val('watermark_size', 230)); $wmType = $val('watermark_type', 'logo'); $wmLogo = $img($school->logo); } else { $wmType = 'none'; } @endphp
@if(($wmType ?? '') === 'logo' && !empty($wmLogo))
@elseif(($wmType ?? '') === 'name')
{{ $school->name }}
@endif
@foreach($ctx['sectionOrder'] as $section) @if($section === 'header') {{-- ===================== SCHOOL HEADER ===================== --}}
@if($flag('show_logo') && $img($school->logo)) @elseif($flag('show_logo'))   @endif

{{ $school->name }}

@if($flag('show_address') && ($school->address || $school->city || $school->state))

{{ trim(implode(', ', array_filter([ $school->address, $school->city, $school->state, $school->country ]))) }}

@endif @if($school->phone || $school->email)

@if($school->phone)Tel: {{ $school->phone }}@if($school->email)  |  @endif @endif @if($school->email){{ $school->email }} @endif

@endif @if($flag('show_motto') && $val('motto'))

“{{ $val('motto') }}”

@endif
@if($flag('show_national_emblem') && $img($val('emblem_image'))) National emblem @endif

{{ $val('result_title', 'STUDENT ACADEMIC PERFORMANCE REPORT') }}

@if($flag('show_session')){{ $term->academicYear?->name ?? '' }} @endif @if($flag('show_session') && $flag('show_term'))— @endif @if($flag('show_term')){{ $term->name }} @endif

@elseif($section === 'student') {{-- ===================== STUDENT INFORMATION ===================== --}} @php $photoSrc = $img($s->photo); $showPhoto = $flag('show_admission_no') || $flag('show_photo') ? ($img($s->photo) != null) : false; $showPhotoCell = false; // placeholder; photo block handled below $photoShape = $val('photo_shape', 'square'); $photoBorderRadius = $photoShape === 'circle' ? '50%' : ($photoShape === 'rounded' ? '6px' : '0'); $photoSize = max(50, (int) $val('photo_size', 96)); @endphp
Student Information @if($flag('show_photo') && $photoSrc) @elseif($flag('show_photo')) @endif @if($flag('show_admission_no')) @else @endif @if($flag('show_gender')) @else @endif @if($flag('show_arm') && $arm) @else @endif @if($flag('show_dob')) @else @endif @if($flag('show_age') && $s->age !== null) @else @endif
Name {{ $s->full_name }}
Student photo
{{ $s->initials }}
Admission No.{{ $s->admission_no ?? '—' }} Class{{ $segment ?: '—' }}Class{{ $segment ?: '—' }}
Gender{{ ucfirst($s->gender ?? '—') }}  Arm{{ $arm }}  
Date of Birth{{ $s->date_of_birth?->format('d M Y') ?? '—' }}  Age{{ $s->age }} yrs  
@elseif($section === 'academic' && $row) {{-- ===================== ACADEMIC PERFORMANCE ===================== --}} @php $columnCount = 1; @endphp
Academic Performance @if($flag('show_max_score'))@endif @if($flag('show_assessment_columns')) @foreach($ctx['types'] as $type) @endforeach @endif @if($flag('show_subject_total'))@endif @if($flag('show_subject_percentage'))@endif @if($flag('show_class_average'))@endif @if($flag('show_highest_lowest'))@endif @if($flag('show_subject_grade'))@endif @if($flag('show_subject_remark'))@endif @if($flag('show_subject_position'))@endif @foreach($ctx['subjects'] as $subject) @php $sr = $row['subjects'][$subject->id]; $subjectRemark = ($sr['grade'] ?? null) && isset($ctx['grades'][$sr['grade']]) ? $ctx['grades'][$sr['grade']]->remark : null; $subjPos = $ctx['subjectPositions'][$subject->id] ?? null; @endphp @if($flag('show_max_score'))@endif @if($flag('show_assessment_columns')) @foreach($ctx['types'] as $type) @endforeach @endif @if($flag('show_subject_total'))@endif @if($flag('show_subject_percentage'))@endif @if($flag('show_class_average')) @endif @if($flag('show_highest_lowest')) @endif @if($flag('show_subject_grade'))@endif @if($flag('show_subject_remark'))@endif @if($flag('show_subject_position')) @endif @endforeach @if($row) @if($flag('show_max_score'))@endif @if($flag('show_assessment_columns')) @endif @if($flag('show_subject_total'))@endif @if($flag('show_subject_percentage'))@endif @if($flag('show_class_average'))@endif @if($flag('show_highest_lowest'))@endif @if($flag('show_subject_grade'))@endif @if($flag('show_subject_remark'))@endif @if($flag('show_subject_position'))@endif @endif
SubjectMax.{{ $type->name }}
/{{ (float)$type->weight }}
Total%Class AvgHighLowGradeRemarkPos.
{{ $subject->name }}100{{ isset($sr['scores'][$type->id]['raw']) ? number_format((float)$sr['scores'][$type->id]['raw'],1) : '—' }}{{ $sr['total'] ?? '—' }}{{ $sr['total'] !== null ? round($sr['total'],1).'%' : '—' }}{{ $ctx['subjectAverages'][$subject->id] !== null ? number_format($ctx['subjectAverages'][$subject->id],1) : '—' }}{{ $ctx['subjectStats'][$subject->id]['highest'] ?? '—' }} {{ $ctx['subjectStats'][$subject->id]['lowest'] ?? '—' }}{{ $sr['grade'] ?? '—' }}{{ $subjectRemark ?? '' }}{{ $subjPos && $subjPos['position'] ? ordinal($subjPos['position']).'/'.$subjPos['in'] : '—' }}
Overall—{{ $row['total'] ?? '—' }}{{ $row['average'] !== null ? round($row['average'],1).'%' : '—' }}{{ $ctx['classAverage'] !== null ? number_format($ctx['classAverage'],1) : '—' }}{{ $row['grade'] ?? '—' }}
@elseif($section === 'summary' && $row && $flag('show_summary')) {{-- ===================== RESULT SUMMARY ===================== --}}
Result Summary @if($flag('show_subject_total')) @endif @if($flag('show_overall_percentage')) @endif @if($flag('show_overall_grade')) @endif @if($flag('show_gpa') && $ctx['gradePointsEnabled'] && $ctx['gpa'] !== null) @endif @if($flag('show_subject_total')) @endif @if($flag('show_overall_percentage')) @endif @if($flag('show_overall_grade')) @endif @if($flag('show_gpa') && $ctx['gradePointsEnabled'] && $ctx['gpa'] !== null) @endif
Total Score {{ $row['total'] ?? '—' }}Average {{ $row['average'] !== null ? round($row['average'],1).'%' : '—' }}Grade {{ $row['grade'] ?? '—' }}GPA {{ number_format((float)$ctx['gpa'],2) }}
Position @if($ctx['calculatePositions']) {{ ($ctx['position'] ?? null) ? ordinal($ctx['position']).' of '.($ctx['studentsInClass'] ?? '—') : '—' }} @else ______ @endif Students {{ $ctx['studentsInClass'] ?? '—' }}Subjects Offered {{ $ctx['subjectsOffered'] ?? '—' }}Next Term ______
@elseif($section === 'conduct' && ($flag('show_psychomotor') || $flag('show_affective'))) {{-- ===================== PSYCHOMOTOR / AFFECTIVE ===================== --}} @php $labels = ['affective' => 'Affective Domain', 'psychomotor' => 'Psychomotor Skills']; $shown = false; @endphp @foreach($labels as $category => $label) @if(($category === 'affective' && $flag('show_affective')) || ($category === 'psychomotor' && $flag('show_psychomotor'))) @if(($ctx['traits'][$category] ?? collect())->count()) @if(!$shown)
@php $shown = true; @endphp @endif {{ $label }} @foreach($ctx['traits'][$category] as $trait) @endforeach @foreach($ctx['traits'][$category] as $trait) @endforeach
{{ $trait->name }}
{{ $ctx['ratings'][$trait->id]->rating ?? '—' }}
@endif @endif @endforeach @if($shown)
@endif @elseif($section === 'attendance' && $flag('show_attendance')) {{-- ===================== ATTENDANCE ===================== --}}
{{ $val('attendance_title', 'ATTENDANCE SUMMARY') }}
School DaysPresentAbsentLateExcused/SickAttendance %
{{ $ctx['attendance']['days_recorded'] }} {{ $ctx['attendance']['present'] }} {{ $ctx['attendance']['absent'] }} {{ $ctx['attendance']['late'] }} {{ $ctx['attendance']['excused'] }} {{ $ctx['attendance']['percentage'] !== null ? $ctx['attendance']['percentage'].'%' : '—' }}
@elseif($section === 'grading' && $flag('show_grading_key') && $ctx['gradingRows']->count()) {{-- ===================== GRADING KEY ===================== --}}
Grading Key @foreach($ctx['gradingRows'] as $g) @endforeach
GradeMarks RangeRemark
{{ $g->grade_letter }} {{ number_format((float)$g->min_marks,0,',','.') }} – {{ number_format((float)$g->max_marks,0,',','.') }} {{ $g->remark }}
@elseif($section === 'chart' && $flag('show_performance_chart') && count($ctx['chart'])) {{-- ===================== PERFORMANCE CHART ===================== --}} @php $maxVal = max(array_column($ctx['chart'], 'value')) ?: 100; $barH = 40; // mm @endphp
Subject Performance @foreach($ctx['chart'] as $point) @php $h = $point['value'] !== null ? max(1, round(($point['value'] / $maxVal) * $barH)) : 0; @endphp @endforeach
{{ $point['label'] }}
{{ $point['value'] !== null ? round($point['value']) : '—' }}
@elseif($section === 'remarks') {{-- ===================== REMARKS ===================== --}}
Remarks @if($flag('show_teacher_remark')) @endif @if($flag('show_principal_remark')) @endif @if($flag('show_proprietor_remark')) @endif @if($sheet?->overall_remark) @endif
{{ $val('class_teacher_comment_title', "Class Teacher's Remark") }}: {{ $sheet?->class_teacher_remark ?: '________________________________________________________' }}
{{ $val('comment_title', "Principal's Remark") }}: {{ $sheet?->principal_remark ?: '________________________________________________________' }}
{{ $val('proprietor_comment_title', "Proprietor's Comment") }}: {{ $val('proprietor_remark') ?: '________________________________________________________' }}
Overall Remark: {{ $sheet->overall_remark }}
@elseif($section === 'signatures' && $ctx['signatures']->count()) {{-- ===================== SIGNATURES ===================== --}}
@foreach($ctx['signatures'] as $signature)
@if($img($signature->signature)) Signature @else
@endif
@if($signature->name)
{{ $signature->name }}
@endif
{{ $signature->title }}
@if($flag('show_signature_date'))
Date: {{ $ctx['reportDate']->format('d M Y') }}
@endif
@endforeach
@elseif($section === 'security') {{-- ===================== SECURITY / FOOTER ===================== --}} @endif @endforeach