{# Consolidated Tabulation Register - SFCHYD PG - issue #127047
   A3 landscape. Same layout as UG (index + page-per-student, all sems, NON-CGPA, summary) but PG marks table
   has 14 cols per group: C M1 M2 M3 AVG GM MD TTL GR FIN-RES SES TTL C.PT PEXAM (3 valuations for PG).
   ponytail: SKELETON — known fields (C/GR/FIN-RES/grand TTL/C.PT/PEXAM) wired; PG-specifics
   (M1/M2/M3/AVG/GM/MD/external-TTL/SES) placeholdered '-', to wire after we sit on the valuation data. #}
<style>
    .tr36 { color: #000; min-width: 1100px; }
    .tr36 table { border-collapse: collapse; width: 100%; }
    .tr36 .page { page-break-after: always; }
    .tr36 .page:last-child { page-break-after: auto; }
    .tr36 .marks th, .tr36 .marks td { border: 1px solid #000; padding: 2px 4px; }
    .tr36 .marks th { text-align: center; white-space: nowrap;line-height: 1!important; }
    .tr36 .center { text-align: center; }
    .tr36 .college-header { text-align: center; margin-bottom: 6px; }
    .tr36 .title { text-align: center; font-weight: bold; margin: 4px 0; }

    .tr36 .index-page { font-family: 'Times New Roman', serif; font-size: 29px; }
    .tr36 .index-page table { font-size: 29px; }
    .tr36 .index-page .title { font-size: 30px; line-height:1!important;}

    {# PG sheet is very wide (31 cols) -> smaller font than UG #}
    .tr36 .student-page { font-family: 'Helvetica', Arial, sans-serif; font-size: 12px; position: relative; min-height: 1300px; padding-right: 20mm; }
    .tr36 .student-page table { font-size: 12px; }
    .tr36 .student-page .title { font-size: 20px; }

    .tr36 .stud-info td { padding: 1px 4px; }
    .tr36 .stud-info .lbl { font-weight: bold; white-space: nowrap; width: 1%; padding-right: 8px; }
    .tr36 .rule { border: none; border-top: 1px solid #000; margin: 2px 0 6px; }

    .tr36 .sheet { width: 100%; }
    .tr36 .sheet th { text-align: center; padding: 0 2px; font-weight: bold; }
    .tr36 .sheet td { padding: 0 2px; vertical-align: top; }
    .tr36 .sheet .subj { text-align: left; }
    {# #6 2cm gap between SUBJECT NAME and the credit (C) column (PG has no SUB CAT column) #}
    .tr36 .sheet .subname { padding-right: 20mm; }
    {# #4 SEMESTER headings indented a further 2cm to the right #}
    .tr36 .sheet .sem td { font-weight: bold; padding: 8px 0 2px 36mm; }
    .tr36 .sheet .sgpa-row .subj { padding-left: 60px; }
    {# #7 CGPA / RESULT / GRADE summary line dropped 1cm #}
    .tr36 .totals { margin-top: 10mm; }
    .tr36 .totals td { padding-top: 6px; }
    .tr36 .totals b { font-weight: bold; }

    .tr36 .footer { position: absolute; left: 0; bottom: 0; width: 100%; margin: 0; table-layout: fixed; }
    .tr36 .footer td { width: 25%; text-align: center; font-size: 19px; font-weight: bold; white-space: nowrap; }
    .tr36 td,th { color: #000!important; }
</style>

<div class="tr36">

    {# ---------- INDEX PAGE ---------- #}
    <div class="page index-page">
        <div class="college-header"><img src="{{ data.collegeData.collegeHeader }}" style="width:15%; height:auto;"></div>
        <div class="title">Student Academic Report (Consolidated)</div>
        <br>
        <table class="marks" style="width:80%;margin:0 auto;">
            <thead>
                <tr>
                    <th style="width:8%">S.No</th>
                    <th style="width:22%">Roll Number</th>
                    <th>Student Name</th>
                    <th style="width:14%">CGPA</th>
                    <th style="width:12%">Page No.</th>
                </tr>
            </thead>
            <tbody>
                {% for student in data.studentData %}
                    <tr>
                        <td class="center">{{ loop.index }}</td>
                        <td>{{ student.rollNo }}</td>
                        <td>{{ student.name }}</td>
                        <td class="center">{{ student.failedStatus == 'PASSED' ? student.cgpa : '-' }}</td>
                        <td class="center">{% if student.pageNo is not null %}{{ student.pageNo }}{% endif %}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {# ---------- ONE PAGE PER STUDENT (all semesters) ---------- #}
    {% for student in data.studentData %}
        <div class="page student-page">
            <div style="text-align:right; font-weight:bold; margin-bottom:2px;">Page No.{% if student.pageNo is not null %} {{ student.pageNo }}{% endif %}</div>
            <div class="college-header"><img src="{{ data.collegeData.collegeHeader }}" style="width:15%; height:auto;"></div>
            <div class="title">TABULATION RECORD</div>
            <div class="title">{{ student.programName }}</div>

            <table class="stud-info" style="width:100%;">
                <tr>
                    <td class="lbl">ROLL NO :</td><td style="width:38%">{{ student.rollNo }}</td>
                    <td class="lbl">NAME :</td><td>{{ student.name }}</td>
                </tr>
                <tr>
                    <td class="lbl">MEDIUM :</td><td>ENGLISH</td>
                    <td class="lbl">FATHER NAME :</td><td>{{ student.fatherName }}</td>
                </tr>
                <tr>
                    <td class="lbl">DATE :</td><td>{{ student.lastExamPublishDate }}</td>
                    <td class="lbl">MOTHER NAME :</td><td>{{ student.motherName }}</td>
                </tr>
            </table>
            <hr class="rule">

            <table class="sheet" style="width:100%;">
                <thead>
                    <tr>
                        <th rowspan="2" class="subj subname" style="width:18%">SUBJECT NAME</th>
                        <th colspan="14">THEORY</th>
                        <th colspan="14">PRACTICAL</th>
                    </tr>
                    <tr>
                        <th>C</th><th>M1</th><th>M2</th><th>M3</th><th>AVG</th><th>GM</th><th>MD</th><th>TTL</th><th>GR</th><th>FIN RES</th><th>SES</th><th>TTL</th><th>C.PT</th><th>PEXAM</th>
                        <th>C</th><th>M1</th><th>M2</th><th>M3</th><th>AVG</th><th>GM</th><th>MD</th><th>TTL</th><th>GR</th><th>FIN RES</th><th>SES</th><th>TTL</th><th>C.PT</th><th>PEXAM</th>
                    </tr>
                </thead>
                <tbody>
                    {% for term in student.academicTerms %}
                        <tr class="sem"><td colspan="29">SEMESTER {{ term.romanNumber }}</td></tr>
                        {% for subject in term.subjects %}
                            {% set isTheory = subject.classType == 'THEORY' %}
                            {% set res = subject.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' %}
                            <tr>
                                <td class="subj subname">{{ subject.name | raw }}</td>
                                {# THEORY — M1/M2/M3/AVG wired; GM/MD/SES not in consolidated data (placeholdered) #}
                                <td class="center">{{ isTheory ? subject.markDetails.credit : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.firstValuationMark : '-' }}</td>{# M1 #}
                                <td class="center">{{ isTheory ? subject.secondValuationMark : '-' }}</td>{# M2 #}
                                <td class="center">{{ isTheory ? subject.thirdValuationMark : '-' }}</td>{# M3 #}
                                <td class="center">{{ isTheory ? subject.markDetails.externalMark|round : '-' }}</td>{# AVG = externalMark #}
                                <td class="center">{{ isTheory ? subject.graceMark : '-' }}</td>{# GM #}
                                <td class="center">{{ isTheory ? subject.moderationMark : '-' }}</td>{# MD #}
                                <td class="center">{{ isTheory ? subject.markDetails.externalMark|round : '-' }}</td>{# TTL ext = externalMark #}
                                <td class="center">{{ isTheory ? subject.grade : '-' }}</td>
                                <td class="center">{{ isTheory ? res : '-' }}</td>
                                <td class="center">{{ isTheory ? (subject.markDetails.isInternal ? subject.markDetails.internalMark : '-') : '-' }}</td>{# SES #}
                                <td class="center">{{ isTheory ? subject.totalMarkObtained|round : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.creditPoint|round : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.examMonthYear : '-' }}</td>
                                {# PRACTICAL #}
                                <td class="center">{{ isTheory ? '-' : subject.markDetails.credit }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.firstValuationMark }}</td>{# M1 #}
                                <td class="center">{{ isTheory ? '-' : subject.secondValuationMark }}</td>{# M2 #}
                                <td class="center">{{ isTheory ? '-' : subject.thirdValuationMark }}</td>{# M3 #}
                                <td class="center">{{ isTheory ? '-' : subject.markDetails.externalMark|round }}</td>{# AVG = externalMark #}
                                <td class="center">{{ isTheory ? '-' : subject.graceMark }}</td>{# GM #}
                                <td class="center">{{ isTheory ? '-' : subject.moderationMark }}</td>{# MD #}
                                <td class="center">{{ isTheory ? '-' : subject.markDetails.externalMark|round }}</td>{# TTL ext = externalMark #}
                                <td class="center">{{ isTheory ? '-' : subject.grade }}</td>
                                <td class="center">{{ isTheory ? '-' : res }}</td>
                                <td class="center">{{ isTheory ? '-' : (subject.markDetails.isInternal ? subject.markDetails.internalMark : '-') }}</td>{# SES #}
                                <td class="center">{{ isTheory ? '-' : subject.totalMarkObtained|round }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.creditPoint|round }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.examMonthYear }}</td>
                            </tr>
                        {% endfor %}
                        {# SGPA + per-sem totals (sum of credits, grand TTL, C.PT) — matches PG sample #}
                        <tr class="sgpa-row">
                            <td class="subj"><b>SGPA : {{ term.failedStatus == 'PASSED' ? term.sgpa : '-' }}</b></td>
                            <td class="center"><b>{{ term.sumCredit }}</b></td>
                            <td colspan="10"></td>
                            <td class="center"><b>{{ term.sumTtl|round }}</b></td>
                            <td class="center"><b>{{ term.sumCpt|round }}</b></td>
                            <td colspan="15"></td>
                        </tr>
                    {% endfor %}
                    {# NON-CGPA COURSES #}
                    {% if student.auditCources|length > 0 %}
                        <tr class="sem"><td colspan="29">NON-CGPA COURSES</td></tr>
                        {% for subject in student.auditCources %}
                            {% set isTheory = subject.classType == 'THEORY' %}
                            {% set res = subject.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' %}
                            <tr>
                                <td class="subj subname">{{ subject.name | raw }}</td>
                                {# THEORY #}
                                <td class="center">{{ isTheory ? subject.markDetails.credit : '-' }}</td>
                                <td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td>
                                <td class="center">{{ isTheory ? subject.grade : '-' }}</td>
                                <td class="center">{{ isTheory ? res : '-' }}</td>
                                <td class="center">-</td>
                                <td class="center">{{ isTheory ? subject.totalMarkObtained|round : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.creditPoint|round : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.examMonthYear : '-' }}</td>
                                {# PRACTICAL #}
                                <td class="center">{{ isTheory ? '-' : subject.markDetails.credit }}</td>
                                <td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td><td class="center">-</td>
                                <td class="center">{{ isTheory ? '-' : subject.grade }}</td>
                                <td class="center">{{ isTheory ? '-' : res }}</td>
                                <td class="center">-</td>
                                <td class="center">{{ isTheory ? '-' : subject.totalMarkObtained|round }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.creditPoint|round }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.examMonthYear }}</td>
                            </tr>
                        {% endfor %}
                    {% endif %}
                </tbody>
            </table>

            {# Summary — same as UG: CGPA above GRAND TOTAL, C.F left, RESULT/GRADE right; indented 20%, GRADE right-edge #}
            <table class="totals" style="width:80%; margin-left:20%;">
                <tr>
                    <td style="width:25%"></td>
                    <td style="width:25%"><b>CGPA : {{ student.failedStatus == 'PASSED' ? student.cgpa : '-' }}</b></td>
                    <td style="width:25%"><b>RESULT :</b> {{ student.failedStatus == 'PASSED' ? 'PASS' : 'FAIL' }}</td>
                    <td style="width:25%; text-align:right;"><b>GRADE :</b> {{ student.grade }}</td>
                </tr>
                <tr>
                    <td><b>C.F :</b> {{ student.conversionFactor }}</td>
                    <td><b>GRAND TOTAL :</b> {{ student.markDetails.markObtained }} / {{ student.markDetails.totalMarks }}</td>
                    <td></td>
                    <td></td>
                </tr>
            </table>

            <table class="footer" style="width:100%; table-layout:fixed;">
                <tr>
                    <td style="width:25%">PRINCIPAL</td>
                    <td style="width:25%">C.O.E</td>
                    <td style="width:25%">P.C. NO.</td>
                    <td style="width:25%">D.C. NO.</td>
                </tr>
            </table>
        </div>
    {% endfor %}

</div>
