{# Template For PG Students In STTHOMAS College #}
<style>
     td, th { padding: 5px; }
     body{
        font-family: \"Times New Roman\", Times, serif; 
    }
    .border-0{
        border:1px solid #fff !important;
    }
    .border-trl-0{
        border-top:1px solid #fff !important;
        border-left:1px solid #fff !important;
        border-right:1px solid #fff !important;
    }
    .border-rl-0{
        border-left:1px solid #fff !important;
        border-right:1px solid #fff !important;
    }
    .border-b-0{
        border-bottom:1px solid #fff !important;
        border-top:1px solid #000 !important;
    }
    .border-t-0{
        border-top:1px solid #fff !important;
        border-bottom:1px solid #000 !important;
    }
    .noborder-r-0{
       border-right-style: none;
    }
    .border-bt-0{
        border-bottom:1px solid #fff !important;
        border-top:1px solid #fff !important;
    }
    .markTab{
        width:100%;
        margin:20px auto;
        font-size: 18px;
        padding:0;
        text-align:center;
        border-collapse: collapse;
    }
    .markTab td{
        margin: 0;
        font-size: 18px;
        padding:11px 5px;
        height: 45px;
        color: #000;
        text-align: center;
        border-collapse: collapse;
    }
    .markTab thead th[rowspan="4"] {
        height: 130px;
        vertical-align: middle;
        text-align: center;
    }
    thead { display: table-header-group; }
    tfoot { display: table-footer-group; }
    tr { page-break-inside: avoid; }
    .celldiv{
        width:100%;
        height: auto;
        float: none;
        margin: 0px auto;
        text-align: center;
        /*border: 1px solid #000;*/
        border-collapse: collapse;
        display: block;
    }
    .cellspan_left{
        float: left;
    }
    .cellspan_right{
        float: left;
    }
    .cellspan_left, .cellspan_right{
        width:50%;
        height: auto;				
        /*border:1px solid #000;*/
        padding: 5px 0;				
        border-collapse: collapse;
        display: block;
    }
    #subjectHeader {
        width: 100% !important;
    }
    #subjectHeader td {
        padding: 2mm;
        line-height: 15px !important;
        height: 4mm !important;
        vertical-align: middle !important;
        text-align: center !important;
    }
    .header-details-table {
        width: 100% !important;
        border-collapse: collapse;
        table-layout: auto;
    }
    .header-details-table td {
        padding: 2px !important;
        text-align: left !important;
        vertical-align: top;
        font-size: 22px;
    }
    .header-details-label {
        width: 1%;
        font-weight: bold;
        white-space: nowrap;
    }
    .header-details-colon {
        width: 1%;
        font-weight: bold;
        text-align: left !important;
        padding-left: 0 !important;
        padding-right: 4px !important;
    }
    .header-details-value {
        width: auto;
        padding-left: 0 !important;
        font-weight: bold;
    }
    
</style>
    <div class="page" style="width:100%;">

    <table id="subjectHeader">
        <tr style="padding-top:300px!important">
            <td><img src="{{data.collegeData.collegeHeader}}" class="college-header" style="height:40mm; width:auto;"></td>
        </tr>
        <tr>
            <td><b style="font-size: 22px;">{{data.examRegistrationData.name}}</br></td>
        </tr>
        <tr>
            <td><b style="font-size: 22px;">TABULATION REGISTER</br></td>
        </tr>
    </table>
    <table style="width:100%!important; table-layout:fixed;">
        <tr style="vertical-align: top;">
            <td style="width:70%; padding: 2px !important; vertical-align: top;">
                <table class="header-details-table">
                    <tr>
                        <td class="header-details-label">Programme</td>
                        <td class="header-details-colon">:</td>
                        <td class="header-details-value">{{data.examRegistrationData.programName| raw}}</td>
                    </tr>
                    <tr>
                        <td class="header-details-label">Month & Year</td>
                        <td class="header-details-colon">:</td>
                        <td class="header-details-value">{{data.examRegistrationData.examMonthName}} {{data.examRegistrationData.examYear}}</td>
                    </tr>
                    <tr>
                        <td class="header-details-label">Board Meeting Held on</td>
                        <td class="header-details-colon">:</td>
                        <td class="header-details-value">{{data.examRegistrationData.boardMeatingDate| raw}}</td>
                    </tr>
                    <tr>
                        <td class="header-details-label">Moderation</td>
                        <td class="header-details-colon">:</td>
                        <td class="header-details-value">{{data.examRegistrationData.moderation}}</td>
                    </tr>
                    <tr>
                        <td class="header-details-label">Date of Publication of Result</td>
                        <td class="header-details-colon">:</td>
                        <td class="header-details-value">{{data.examRegistrationData.resultPublishDate}}</td>
                    </tr>
                </table>
            </td>
            <td style="width:30%; padding: 2px !important; vertical-align: top;">
                <table class="markTab" border="1" cellpadding="0" cellspacing="0" style="width:100%; margin:0;">
                    <tr>
                        <th style="text-align:center !important" class="tabular-table-border">Credit Point Calculation</th>
                        <th style="text-align:center !important" class="tabular-table-border">Abbreviations</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border">EWGPA = EWGP/30</th>
                        <th style="text-align:left !important" class="tabular-table-border">IWGPA = Internal Grade Point Average</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border">WGPA = (EWGPA*4 + IWGPA)/5</th>
                        <th style="text-align:left !important" class="tabular-table-border">IGrade = Internal Grade</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border">Cr:Pt = WGPA * Credit</th>
                        <th style="text-align:left !important" class="tabular-table-border">EWGP = External Weighted Grade Point</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border">Minimum WGPA for pass = 2.00</th>
                        <th style="text-align:left !important" class="tabular-table-border">EWGPA = External Weighted Grade Point Avg</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border">Minimum SGPA for pass = 2.00</th>
                        <th style="text-align:left !important" class="tabular-table-border">WGPA = Weighted Grade Point Average</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border"></th>
                        <th style="text-align:left !important" class="tabular-table-border">Cr Pt = Credit Point</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border"></th>
                        <th style="text-align:left !important" class="tabular-table-border">SGPA = Semester Grade Point Average</th>
                    </tr>
                    <tr>
                        <th style="text-align:left !important" class="tabular-table-border"></th>
                        <th style="text-align:left !important" class="tabular-table-border">CGPA = Cumulative Grade Point Average</th>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    {# Group elective baskets like the UG/Regular template: collapse each basket to one column. #}
    {% set subjectGroupList = [] %}
    {% for grpChunk in data.examRegistrationData.subjectGroups %}
        {% set subjectGroupList = subjectGroupList|merge(grpChunk) %}
    {% endfor %}
    {% if subjectGroupList is empty %}
        {% set subjectGroupList = data.examRegistrationData.subjects %}
    {% endif %}
    {% set subjectLen =  subjectGroupList|length   %}
    {% set widthtr =  80 / subjectLen %}

    {% for chunk in data.studentDataChunks %}
    <div style="{{ not loop.first ? 'page-break-before: always;' : '' }}">
    <table class="markTab" border="1" cellpadding="0" cellspacing="0" style = "">
        <thead>
            <tr>
                <th rowspan="3" class='text-center bold ' data-a-h='center' data-a-v='middle'>Sl.No</th>
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>Reg. No & Name</th>
                {% for subject in subjectGroupList %}
                    <th colspan="9" width='{{widthtr}}'  class='text-center' data-a-h='center' data-a-v='middle'>{% if subject.isGrouped is defined and subject.isGrouped %}{{subject.name|raw}}{% else %}{{subject.code}} <br> {{subject.name}}{% endif %}</th>
                {% endfor %}
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>Total</br>Credit</br>Points</th>
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                    <svg width="40" height="160"><text x="20" y="155" transform="rotate(-90, 20, 155)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">SGPA {{data.examRegistrationData.semInSemNumber}} with Grade</text></svg>
                </th>
                {% for semester in data.examRegistrationData.semesters %}
                    <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                        <svg width="40" height="160"><text x="20" y="155" transform="rotate(-90, 20, 155)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">SGPA {{semester.semInSemNumber}} with Grade</text></svg>
                    </th>
                {% endfor %}
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                    <svg width="40" height="160"><text x="20" y="155" transform="rotate(-90, 20, 155)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">CGPA with Grade</text></svg>
                </th>
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                    <svg width="40" height="120"><text x="20" y="115" transform="rotate(-90, 20, 115)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">Folio No.</text></svg>
                </th>
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                    <svg width="40" height="120"><text x="20" y="115" transform="rotate(-90, 20, 115)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">PC Folio No.</text></svg>
                </th>
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                    <svg width="40" height="120"><text x="20" y="115" transform="rotate(-90, 20, 115)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">DC Folio No.</text></svg>
                </th>
                <th rowspan="3" class='text-center bold' data-a-h='center' data-a-v='middle'>
                    <svg width="40" height="120"><text x="20" y="115" transform="rotate(-90, 20, 115)" font-size="16" font-family="Times New Roman, Times, serif" text-anchor="start" font-weight="bold">Remark</text></svg>
                </th>
            </tr>
            <tr>
                {% for subject in subjectGroupList %}
                    <th colspan="9" class='text-center ' data-a-h='center' data-a-v='middle'>
                        <table style="width:100%; border:none; margin:0;"><tr>
                            <td style="border:none; text-align:left; padding:0; width:70%; font-size:15px;">IWGPA max: {{subject.internalMaxMark}}<br>EWGP max: {{subject.externalMaxMark}}</td>
                            <td style="border:none; text-align:right; padding:0; width:30%; font-size:15px; vertical-align:top;">Credit : {{subject.credit}}</td>
                        </tr></table>
                    </th>
                {% endfor %}
            </tr>
            <tr>
                {% for subject in subjectGroupList %}
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>IWGPA</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>IGrade</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>EWGP</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>EWGPA</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>EGrade</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>WGPA</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>Grade</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>Cr Pt</text>
                        </svg>
                    </th>
                    <th class='text-center ' data-a-h='center' data-a-v='middle'>
                        <svg width='5mm' height='30mm'>
                            <text transform='rotate(180)' y='-50%' x='-50%' style='writing-mode: tb;text-anchor: middle;'>Status</text>
                        </svg>
                    </th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
             {% set slno = loop.first ? 0 : ((data.firstPageCount|default(15)) + (loop.index0 - 1) * (data.otherPageCount|default(15))) %}
            {% for student in chunk %}
            {% for academicTerm in student.academicTerms %}
                {% set slno = slno + 1 %}
                <tr>
                    <td class="align-middle text-center " rowspan="2">{{slno}}</td>
                    <td style="text-align:left;padding: 4px; " rowspan="2">{{student.registerNo}}</br>{{student.name}} </td>
                    {# Row 1: the subject the student actually took in each (possibly grouped) column #}
                    {% for subject in subjectGroupList %}
                        {% set isEnteredCode = false %}
                        {% for studentSubject in academicTerm.subjects %}
                            {% set matchedCode = (subject.academicPaperSubjectIds is defined and studentSubject.id in subject.academicPaperSubjectIds) or (subject.academicPaperSubjectIds is not defined and studentSubject.id == subject.id) %}
                            {% if matchedCode and isEnteredCode == false %}
                                {% set isEnteredCode = true %}
                                <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}" colspan="9">{{studentSubject.code}}</td>
                            {% endif %}
                        {% endfor %}
                        {% if isEnteredCode == false %}
                            <td class="text-center" colspan="9"></td>
                        {% endif %}
                    {% endfor %}
                    {# Trailing aggregate columns span both rows #}
                    {% if academicTerm.failedStatus == 'PASSED' %}
                        <td class="align-middle text-center" rowspan="2">{{academicTerm.semesterCreditGradePoint}}</td>
                        <td class="align-middle text-center" rowspan="2">{{academicTerm.semesterSgpa}} / {{academicTerm.semesterGrade}}</td>
                    {% else %}
                        <td rowspan="2"> - </td>
                        <td rowspan="2"> - </td>
                    {% endif %}
                    {% for semester in data.examRegistrationData.semesters %}
                        {% set isEntered = false %}
                        {% for otherAcademicTerm in student.otherAcademicTerms %}
                            {% if otherAcademicTerm.id == semester.id %}
                                <td class="text-center noborder-r-0" rowspan="2">
                                    {% if otherAcademicTerm.failedStatus == "PASSED" %}
                                        {{ otherAcademicTerm.semesterSgpa }} / {{ otherAcademicTerm.semesterGrade }} <br> {{ otherAcademicTerm.latestExamMonth }}/{{ otherAcademicTerm.latestExamYear }}
                                    {% else %}
                                        <span > -- <br> {{ otherAcademicTerm.latestExamMonth }}/{{ otherAcademicTerm.latestExamYear }}</span>
                                    {% endif %}
                                </td>
                                {% set isEntered = true %}
                            {% endif %}
                        {% endfor %}
                        {% if isEntered == false %}
                            <td class="text-center" rowspan="2"> - </td>
                        {% endif %}
                    {% endfor %}
                    {% if student.failedStatus == 'PASSED' %}
                        <td class="align-middle text-center" rowspan="2">{{student.cgpa}} / {{student.grade}}</td>
                    {% else %}
                        <td rowspan="2"> - </td>
                    {% endif %}
                        <td rowspan="2" class="align-middle text-center"><span style="display:inline-block; -webkit-transform: rotate(-90deg); transform: rotate(-90deg); white-space: nowrap;">{{student.folioNumber}}</span></td> {#  For Folio Number #}
                        <td rowspan="2">  </td> {#  For PC Folio Number #}
                        <td rowspan="2">  </td> {#  For DC Folio Number #}
                        <td rowspan="2">  </td> {#  For Remark #}
                </tr>
                <tr>
                    {# Row 2: marks for the subject the student took #}
                    {% for subject in subjectGroupList %}
                        {% set isEntered = false %}
                        {% set isEnteredGroup = false %}
                        {% for studentSubject in academicTerm.subjects %}
                            {% set matched = (subject.academicPaperSubjectIds is defined and studentSubject.id in subject.academicPaperSubjectIds) or (subject.academicPaperSubjectIds is not defined and studentSubject.id == subject.id) %}
                            {% if matched and isEnteredGroup == false %}
                                {% set isEnteredGroup = true %}
                                {% if studentSubject.isInternal %}
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">{{ studentSubject.internalGradePoint == 0 ? '-' : (studentSubject.internalGradePoint|number_format(2, '.')) }}</td>
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">{{ studentSubject.internalGrade }}</td>
                                {% else %}
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">-</td>
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">-</td>
                                {% endif %}
                                {% if studentSubject.isExternal %}
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}} noborder-r-0">
                                        {% if studentSubject.attendanceStatus == "PRESENT" %}
                                            {{  studentSubject.externalGradePoint == 0 ? '-' : (studentSubject.externalGradePoint|number_format(2, '.')) }}
                                        {% elseif studentSubject.attendanceStatus == "MALPRACTICE" %}
                                            <span style="color:red;">MAL </span>
                                        {% else %}
                                            <span style="color:red;"> AB </span>
                                        {% endif %}
                                    </td>
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}} noborder-r-0">
                                        {% if studentSubject.attendanceStatus == "PRESENT" %}
                                            {{  studentSubject.externalMark == 0 ? '-' : (studentSubject.externalMark|round(2)) }}
                                        {% elseif studentSubject.attendanceStatus == "MALPRACTICE" %}
                                            <span style="color:red;">MAL </span>
                                        {% else %}
                                            <span style="color:red;"> AB </span>
                                        {% endif %}
                                    </td>
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}} noborder-r-0">{{ studentSubject.externalGrade }}</td>
                                {% else %}
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">-</td>
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">-</td>
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">-</td>
                                {% endif %}
                                <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}} ">{{ studentSubject.wgpa|number_format(2, '.') }}</td>
                                <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}} ">{{ studentSubject.grade }}</td>
                                <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">{{ studentSubject.creditGradePoint }}</td>
                                {% if studentSubject.failedStatus == 'PASSED' %}
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">P</td>
                                {% else %}
                                    <td class="text-center {{ studentSubject.failedStatus == "PASSED" ? '' : 'failed'}}">F</td>
                                {% endif %}
                                {% set isEntered = true %}
                            {% endif %}
                        {% endfor %}
                        {% if isEntered == false %}
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                            <td class="text-center"> * </td>
                        {% endif %}
                    {% endfor %}
                </tr>
            {% endfor %}
            {% endfor %}
        </tbody>
    </table>
    </div>
    {% endfor %}
    <div style="margin: 100px 0 0 0; width: 100%; font-size: 16px">
        <div style = "width:16%;margin:0 auto; text-align:center;float:left;"><b>Clerk</b></div>
        <div style = "width:16%;margin:0 auto; text-align:center;float:left;"><b>Chairman</b></div>
        <div style = "width:16%;margin:0 auto; text-align:center;float:left;"><b>Seal</b></div>
        <div style = "width:16%;margin:0 auto; text-align:center;float:left;"><b>ACE</b></div>
        <div style = "width:16%;margin:0 auto; text-align:center;float:left;" class="small">
            <b>CE</b>
        </div>
        <div style = "width:16%;margin:0 auto; text-align:center;float:left;" class="small">
            <b>Principal</b>
        </div>
    </div>
</div>
