{# Regular Tabulation Register - SFCHYD PG - issue #127047
   A3 landscape. Same layout as UG regular, 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: regular TR data has externalMark/internalMark/graceMark/moderationMark, so GM/MD/TTL-ext/SES
   ARE wired; only M1/M2/M3/AVG (valuation marks) placeholdered '-' until we wire oe_student_total_mark. #}
<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: 10px; position: relative; min-height: 1300px; padding-right: 20mm; }
    .tr36 .student-page table { font-size: 10px; }
    .tr36 .student-page .title { font-size: 18px; }

    .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: 17px; font-weight: bold; white-space: nowrap; }
</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 For {{ data.examRegistrationData.programName }}</div>
        <div class="title">SEMESTER {{ data.examRegistrationData.semInRomanLetter }} - {{ data.examRegistrationData.examMonthName }} {{ data.examRegistrationData.examYear }}</div>
        <br>
        <table class="marks index-table" 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%">SGPA</th>
                    <th style="width:12%">Page No.</th>
                </tr>
            </thead>
            <tbody>
                {% for student in data.studentData %}
                    {% set firstTerm = student.academicTerms|first %}
                    <tr>
                        <td class="center">{{ loop.index }}</td>
                        <td>{{ student.rollNo }}</td>
                        <td>{{ student.name }}</td>
                        <td class="center">{{ firstTerm.failedStatus == 'PASSED' ? firstTerm.semesterSgpa : '-' }}</td>
                        <td class="center">{{ (loop.index + 1) < 10 ? '0' ~ (loop.index + 1) : (loop.index + 1) }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {# ---------- ONE PAGE PER STUDENT ---------- #}
    {% for student in data.studentData %}
        <div class="page student-page">
            <div style="text-align:right; font-weight:bold; margin-bottom:2px;">Page No.</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">{{ data.examRegistrationData.programName|upper }}</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>{{ data.printDate }}</td>
                    <td class="lbl">MOTHER NAME :</td><td>{{ student.motherName }}</td>
                </tr>
            </table>
            <hr class="rule">

            {% set monthShort = {1:'Jan',2:'Feb',3:'Mar',4:'Apr',5:'May',6:'Jun',7:'Jul',8:'Aug',9:'Sep',10:'Oct',11:'Nov',12:'Dec'} %}
            <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 academicTerm in student.academicTerms %}
                        {% set pexam = monthShort[academicTerm.examMonth + 0] ~ (academicTerm.examYear ? academicTerm.examYear|slice(-2) : '') %}
                        <tr class="sem"><td colspan="29">SEMESTER {{ academicTerm.semInRomanLetter }}</td></tr>
                        {% for subject in academicTerm.subjects %}
                            {% set isTheory = subject.classType == 'THEORY' %}
                            {% set isAbsent = subject.isExternal and subject.attendanceStatus != 'PRESENT' %}
                            {% set mal = subject.attendanceStatus == 'MALPRACTICE' %}
                            {% set secured = mal ? 'MAL' : (isAbsent ? 'AB' : subject.markObtained|round) %}
                            {% set extTtl = mal ? 'MAL' : (isAbsent ? 'AB' : subject.externalMark|round) %}
                            {% set res = subject.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' %}
                            <tr>
                                <td class="subj subname">{{ subject.name | raw }}</td>
                                {# THEORY — M1/M2/M3/AVG placeholdered; rest wired #}
                                <td class="center">{{ isTheory ? subject.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 ? extTtl : '-' }}</td>{# AVG = TTL #}
                                <td class="center">{{ isTheory ? subject.valuationGraceMark : '-' }}</td>{# GM #}
                                <td class="center">{{ isTheory ? subject.valuationModerationMark : '-' }}</td>{# MD #}
                                <td class="center">{{ isTheory ? extTtl : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.grade : '-' }}</td>
                                <td class="center">{{ isTheory ? res : '-' }}</td>
                                <td class="center">{{ isTheory ? (subject.isInternal ? subject.internalMark : '-') : '-' }}</td>
                                <td class="center">{{ isTheory ? secured : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.creditGradePoint|round : '-' }}</td>
                                <td class="center">{{ isTheory ? pexam : '-' }}</td>
                                {# PRACTICAL #}
                                <td class="center">{{ isTheory ? '-' : subject.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 ? '-' : extTtl }}</td>{# AVG = TTL #}
                                <td class="center">{{ isTheory ? '-' : subject.valuationGraceMark }}</td>{# GM #}
                                <td class="center">{{ isTheory ? '-' : subject.valuationModerationMark }}</td>{# MD #}
                                <td class="center">{{ isTheory ? '-' : extTtl }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.grade }}</td>
                                <td class="center">{{ isTheory ? '-' : res }}</td>
                                <td class="center">{{ isTheory ? '-' : (subject.isInternal ? subject.internalMark : '-') }}</td>
                                <td class="center">{{ isTheory ? '-' : secured }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.creditGradePoint|round }}</td>
                                <td class="center">{{ isTheory ? '-' : pexam }}</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 : {{ academicTerm.failedStatus == 'PASSED' ? academicTerm.semesterSgpa : '-' }}</b></td>
                            <td class="center"><b>{{ academicTerm.sumCredit }}</b></td>
                            <td colspan="10"></td>
                            <td class="center"><b>{{ academicTerm.sumTtl|round }}</b></td>
                            <td class="center"><b>{{ academicTerm.sumCpt|round }}</b></td>
                            <td colspan="15"></td>
                        </tr>
                    {% endfor %}
                    {# NON-CGPA COURSES (audit) — shown separately, not counted in SGPA (same as consolidated TR) #}
                    {% if student.auditCources|length > 0 %}
                        {% set auditTerm = student.academicTerms|first %}
                        {% set auditPexam = monthShort[auditTerm.examMonth + 0] ~ (auditTerm.examYear ? auditTerm.examYear|slice(-2) : '') %}
                        <tr class="sem"><td colspan="29">NON-CGPA COURSES</td></tr>
                        {% for subject in student.auditCources %}
                            {% set isTheory = subject.classType == 'THEORY' %}
                            {% set isAbsent = subject.isExternal and subject.attendanceStatus != 'PRESENT' %}
                            {% set mal = subject.attendanceStatus == 'MALPRACTICE' %}
                            {% set secured = mal ? 'MAL' : (isAbsent ? 'AB' : subject.markObtained|round) %}
                            {% set extTtl = mal ? 'MAL' : (isAbsent ? 'AB' : subject.externalMark + 0) %}
                            {% set res = subject.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' %}
                            <tr>
                                <td class="subj subname">{{ subject.name | raw }}</td>
                                {# THEORY #}
                                <td class="center">{{ isTheory ? subject.credit : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.firstValuationMark : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.secondValuationMark : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.thirdValuationMark : '-' }}</td>
                                <td class="center">{{ isTheory ? extTtl : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.valuationGraceMark : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.valuationModerationMark : '-' }}</td>
                                <td class="center">{{ isTheory ? extTtl : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.grade : '-' }}</td>
                                <td class="center">{{ isTheory ? res : '-' }}</td>
                                <td class="center">{{ isTheory ? (subject.isInternal ? subject.internalMark : '-') : '-' }}</td>
                                <td class="center">{{ isTheory ? secured : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.creditGradePoint|round : '-' }}</td>
                                <td class="center">{{ isTheory ? auditPexam : '-' }}</td>
                                {# PRACTICAL #}
                                <td class="center">{{ isTheory ? '-' : subject.credit }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.firstValuationMark }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.secondValuationMark }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.thirdValuationMark }}</td>
                                <td class="center">{{ isTheory ? '-' : extTtl }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.valuationGraceMark }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.valuationModerationMark }}</td>
                                <td class="center">{{ isTheory ? '-' : extTtl }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.grade }}</td>
                                <td class="center">{{ isTheory ? '-' : res }}</td>
                                <td class="center">{{ isTheory ? '-' : (subject.isInternal ? subject.internalMark : '-') }}</td>
                                <td class="center">{{ isTheory ? '-' : secured }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.creditGradePoint|round }}</td>
                                <td class="center">{{ isTheory ? '-' : auditPexam }}</td>
                            </tr>
                        {% endfor %}
                    {% endif %}
                </tbody>
            </table>

            {# Summary (regular = single sem, no CGPA). Indented 20%, GRADE right edge. #}
            {% set summary = student.academicTerms|last %}
            <table class="totals" style="width:80%; margin-left:20%;">
                <tr>
                                        <td style="width:50%"><b>RESULT :</b> {{ summary.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' }}</td>
                    <td style="width:50%; text-align:right;"><b>GRADE :</b> {{ summary.semesterGrade }}</td>
                    <td style="width:50%; text-align:right;"><b>
                </tr>
            </table>

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

</div>
