{# Regular Tabulation Register - SFCHYD UG - issue #127047
   A3 landscape (page size set in Template36RegularTabulationRegisterGenerator render options).
   Layout: 1 index page (student -> page no) + 1 page per student.
   ponytail: skeleton grounded in the real data shape; column widths / header text tuned against live output. #}
<style>
    {# ponytail: wkhtmltopdf (old WebKit) renders at ~120dpi -> 0.6pt per CSS px, and tables do NOT
       inherit font-size, so size MUST be set on the table too. px = target_pt / 0.6.
       index: 20.4pt->34px / 17.2pt->29px ; student: 13pt->22px / 10pt->17px / 9pt->15px. #}
    .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; }

    /* Index page -> matches TR format (1).pdf : Times New Roman, 20.4pt title / 17.2pt body */
    .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;}

    /* Student page -> matches UG - TR (1).pdf : Helvetica, 13pt title / 10pt headings / 9pt body */
    {# ponytail: page = A3 420x297mm, 9mm top/bottom margins -> ~279mm content ~= 1300px @0.6pt/px.
       min-height + absolute footer pins signatures to page bottom. Assumes 1 page/student (true for SFCHYD). #}
    .tr36 .student-page { font-family: 'Helvetica', Arial, sans-serif; font-size: 13px; position: relative; min-height: 1300px; padding-right: 20mm; }
    .tr36 .student-page table { font-size: 13px; }
    .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; }

    /* Borderless columnar marks sheet -> matches UG - TR (1).pdf */
    .tr36 .sheet { width: 100%; }
    .tr36 .sheet th { text-align: center; padding: 0 4px; font-weight: bold; }
    .tr36 .sheet td { padding: 0 4px; vertical-align: top; }
    .tr36 .sheet .subj { text-align: left; }
    {# #5 SUB CAT column collapses to content, 1cm gap before SUBJECT NAME #}
    .tr36 .sheet .subcat { width: 1%; white-space: nowrap; padding-right: 10mm; }
    {# #6 2cm gap between SUBJECT NAME and the credit (C) 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; }
    {# #7 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: 13px; 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>

            <table class="stud-info" style="width:100%;">
                <tr>
                    <td class="lbl">COURSE :</td><td style="width:38%">{{ data.examRegistrationData.programName }}</td>
                    <td class="lbl">NAME :</td><td>{{ student.name }}</td>
                </tr>
                <tr>
                    <td class="lbl">ROLL NO :</td><td>{{ student.rollNo }}</td>
                    <td class="lbl">FATHER NAME :</td><td>{{ student.fatherName }}</td>
                </tr>
                <tr>
                    <td class="lbl">MEDIUM :</td><td>ENGLISH</td>
                    <td class="lbl">MOTHER NAME :</td><td>{{ student.motherName }}</td>
                </tr>
                <tr>
                    <td class="lbl">DATE :</td><td>{{ data.printDate }}</td>
                    <td class="lbl"></td><td></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'} %}
            {# One continuous borderless sheet: all semesters stacked, SGPA per sem at right.
               Single sem here just leaves the rest of the page empty — same as the sample's spare space. #}
            <table class="sheet" style="width:100%;">
                <thead>
                    <tr>
                        <th rowspan="2" class="subj subcat">SUB<br>CAT</th>
                        <th rowspan="2" class="subj subname" style="width:24%">SUBJECT NAME</th>
                        <th colspan="8">THEORY</th>
                        <th colspan="8">PRACTICAL</th>
                        <th rowspan="2">SGPA</th>
                    </tr>
                    <tr>
                        <th>C</th><th>MAX</th><th>MIN</th><th>SEC</th><th>GR</th><th>RES</th><th>C.PT</th><th>PEXAM</th>
                        <th>C</th><th>MAX</th><th>MIN</th><th>SEC</th><th>GR</th><th>RES</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="19">SEMESTER {{ academicTerm.semInRomanLetter }}</td></tr>
                        {% for subject in academicTerm.subjects %}
                            {# SFCHYD model (per Template36FCMC): each subject is THEORY or PRACTICAL by classType;
                               it fills its own column group and dashes the other. #}
                            {% set isTheory = subject.classType == 'THEORY' %}
                            {% set isAbsent = subject.isExternal and subject.attendanceStatus != 'PRESENT' %}
                            {% set secured = subject.attendanceStatus == 'MALPRACTICE' ? 'MAL' : (isAbsent ? 'AB' : subject.markObtained|round) %}
                            {% set maxMark = (subject.isExternal ? subject.externalMaxMark : 0) + (subject.isInternal ? subject.internalMaxMark : 0) %}
                            {# MIN = minimum marks to pass = MAX x aggregate pass% / 100 (per Template36IndividualResultGenerator) #}
                            {% set minMark = subject.aggregatePassPercentage ? (maxMark * subject.aggregatePassPercentage / 100)|round : '-' %}
                            {% set res = subject.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' %}
                            <tr>
                                <td class="subj subcat">{{ subject.subjectTypeCode }}</td>
                                <td class="subj subname">{{ subject.name | raw }}</td>
                                {# THEORY #}
                                <td class="center">{{ isTheory ? subject.credit : '-' }}</td>
                                <td class="center">{{ isTheory ? maxMark : '-' }}</td>
                                <td class="center">{{ isTheory ? minMark : '-' }}</td>
                                <td class="center">{{ isTheory ? secured : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.grade : '-' }}</td>
                                <td class="center">{{ isTheory ? res : '-' }}</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 ? '-' : maxMark }}</td>
                                <td class="center">{{ isTheory ? '-' : minMark }}</td>
                                <td class="center">{{ isTheory ? '-' : secured }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.grade }}</td>
                                <td class="center">{{ isTheory ? '-' : res }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.creditGradePoint|round }}</td>
                                <td class="center">{{ isTheory ? '-' : pexam }}</td>
                                <td class="center"><b>{{ loop.last ? (academicTerm.failedStatus == 'PASSED' ? academicTerm.semesterSgpa : '-') : '' }}</b></td>
                            </tr>
                        {% endfor %}
                    {% 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="19">NON-CGPA COURSES</td></tr>
                        {% for subject in student.auditCources %}
                            {% set isTheory = subject.classType == 'THEORY' %}
                            {% set isAbsent = subject.isExternal and subject.attendanceStatus != 'PRESENT' %}
                            {% set secured = subject.attendanceStatus == 'MALPRACTICE' ? 'MAL' : (isAbsent ? 'AB' : subject.markObtained|round) %}
                            {% set maxMark = (subject.isExternal ? subject.externalMaxMark : 0) + (subject.isInternal ? subject.internalMaxMark : 0) %}
                            {% set minMark = subject.aggregatePassPercentage ? (maxMark * subject.aggregatePassPercentage / 100)|round : '-' %}
                            {% set res = subject.failedStatus == 'FAILED' ? 'FAIL' : 'PASS' %}
                            <tr>
                                <td class="subj subcat">{{ subject.subjectTypeCode }}</td>
                                <td class="subj subname">{{ subject.name | raw }}</td>
                                {# THEORY #}
                                <td class="center">{{ isTheory ? subject.credit : '-' }}</td>
                                <td class="center">{{ isTheory ? maxMark : '-' }}</td>
                                <td class="center">{{ isTheory ? minMark : '-' }}</td>
                                <td class="center">{{ isTheory ? secured : '-' }}</td>
                                <td class="center">{{ isTheory ? subject.grade : '-' }}</td>
                                <td class="center">{{ isTheory ? res : '-' }}</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 ? '-' : maxMark }}</td>
                                <td class="center">{{ isTheory ? '-' : minMark }}</td>
                                <td class="center">{{ isTheory ? '-' : secured }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.grade }}</td>
                                <td class="center">{{ isTheory ? '-' : res }}</td>
                                <td class="center">{{ isTheory ? '-' : subject.creditGradePoint|round }}</td>
                                <td class="center">{{ isTheory ? '-' : auditPexam }}</td>
                                <td class="center"></td>
                            </tr>
                        {% endfor %}
                    {% endif %}
                </tbody>
            </table>

            {# Whole-card summary (regular = single sem, so no CGPA — GRAND TOTAL / RESULT / GRADE only).
               Indented ~20% from left, spans to right edge; GRADE at the far right (matches consolidated). #}
            {% 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>PRINCIPAL (S.F.C)</td>
                    <td>C.O.E (S.F.C)</td>
                    <td>P.C. NO</td>
                    <td>D.C. NO</td>
                </tr>
            </table>
        </div>
    {% endfor %}

</div>
