{# Template For MPES CHRIST Collage  #}
<style>
    @media print {
        #printBtnDiv { display : none !important; }
    }
	.primary-table {
		border-collapse: collapse !important;
		page-break-inside: auto;
		width: 100% !important;
	}

	.primary-table th {
		text-align: center;
		background: none !important;
		height: 4mm !important;
		border: 1px solid #000 !important;
		padding: 1mm !important;
	}
	.primary-table td {
		padding: 3px;
		line-height: 20px !important;
		height: 4mm !important;
		height: 4mm !important;
		border: 1px solid #000;
		text-align: center;
		vertical-align: middle !important;
	}
	#succesRateReportHeader {
		width: 100% !important;
		height: 4mm !important;
	}

	#succesRateReportHeader td {
		padding: 2mm;
		line-height: 15px !important;
		height: 4mm !important;
		border: 1px solid #000;
		vertical-align: middle !important;
	}
	#subjectHeader {
		width: 100% !important;
	}
	#subjectHeader td {
		padding: 2mm;
		line-height: 15px !important;
		height: 4mm !important;
		vertical-align: middle !important;
		text-align: center !important;
	}
	.no-border {
		border-left: 1px solid #fff !important;
		border-right: 1px solid #fff !important;
		border-top: 1px solid #fff !important;
        border-bottom: 1px solid #fff !important;
	}
	.college-header {
		height: 35mm;
		width: auto;
		margin: 0 10%;
	}
    .text-left{
        text-align:left!important;
    }
    .text-center{
        text-align:center!important;
    }
    .text-right{
        text-align:right!important;
    }
    .p-t-20{
        padding-top:10px!important;
    }
	.p-t-50{
        padding-top:50px!important;
    }
	
    .p-b-10{
        padding-bottom:10px!important;
    }
    .p-20{
        padding:20px!important;
    }
    .outer-border {
        border: 1px solid black;
        border-collapse: collapse;
    }
    .center {
        margin-left: auto;
        margin-right: auto;
    }
    .abbr-table td{
        padding: 2mm 10mm 2mm 10mm;
		line-height: 14px !important;
		margin-top:5mm;
    }
	.removeTdBorder{
		border-left:1px solid #fff !important;
		border-right:1px solid #fff !important;
		border-bottom:1px solid #fff !important;
		border-top:1px solid #fff !important;
	}
	.tabular-table {
		border-collapse: collapse !important;
		page-break-inside: auto;
		/* page-break-after:always; */
		width: 100% !important;
		border: 1px solid #000 !important;
	}

	.tabular-table th {
		text-align: center;
		background: none !important;
		height: 3mm !important;
		/* border: 1px solid #000 !important; */
		padding: 1mm !important;
		font-size:12px;
	}
	.tabular-table-border{
		border: 1px solid #000 !important;
	}
	.tabular-table td {
		padding: 8px 2px;
		line-height: 18px !important;
		height: 8mm !important;
		border: 1px solid #000;
		text-align: center;
		vertical-align: middle !important;
		/* page-break-after:always; */
	}
	.tabular-table tr{
		/* page-break-after:always; */
		height: 8mm !important;
	}
	.tabular-table tbody tr:last-child td {
		border-bottom: 1px solid #000 !important;
	}
	.small-font{
		font-weight: normal !important;
		font-size: 15px !important;
	}
	.failed{
		background-color:#c0c0c0 !important; 
	}
	@media screen {
	.sticky-column {
		position: sticky;
		left: 0;
		background-color: white !important;
		z-index: 3; 
		border: 1px solid #000 !important;

	}

	/* 2. Specific column adjustments */
	.sticky-column-1 { 
		left: 0;
		min-width: 40px;
		max-width: 40px;
	}
	.sticky-column-2 { 
		left: 40px;
		min-width: 50px;
		max-width: 50px;
	}
	.sticky-column-3 { 
		left: 90px;
		min-width: 140px;
		max-width: 140px;
	}
	.sticky-column-4 { 
		left: 230px;
		min-width: 200px;
		max-width: 200px;
	}
	.tabular-table {
		border-collapse: separate !important;
		border-spacing: 0 !important;
	}
	.tabular-table td {
		border-bottom: 1px solid #000 !important;
	}

	.tabular-table thead th.sticky-header {
		position: sticky;
		top: 0;
		z-index: 4; 
		background-color: white !important;
		border: 1px solid #000 !important;
		box-shadow: 0 1px 0 #000;
		}
	}
	
    .stud-row td{
		font-size: 18px !important;
	}
</style>
<div class="page" style="width:100%;" id="sem-wise-result-sheet" data-cols-width="10,40">
    {% set columnCount = (data.examRegistrationData.subjects|length * 8) + 1 %}
    {% set catHeadCount = (data.examRegistrationData.headerCategories|length) + 1 %}
    {% set totalColumnCount = columnCount + catHeadCount + 3 %}
{# TABLUTION REGISTER STARTS #}
	{% macro render_table_header(data, pageCategories, isLastCategoryPage, forcePageBreak) %}
	<table id="subjectHeader" style="width:100%!important;{% if forcePageBreak %}page-break-before: always{% endif %}">
		{% if data.isPrint == 1 %}
		<tr style="padding-top:300px!important" data-exclude="true">
			<td data-f-bold='true' colspan="3"><img src="{{data.collegeData.collegeHeader}}" class="college-header"></td>
		</tr>
		{% endif %}
        <tr>
			<td colspan="15" data-f-bold='true' data-a-h='center'><b style="font-size: 18px;" >{{data.examRegistrationData.name}}</br></td>
		</tr>
        <tr>
			<td colspan="15" data-f-bold='true' data-a-h='center'><b style="font-size: 18px;" >TABULATION REGISTER</br></td>
		</tr> 
    </table>
    <table style="width:100%!important;">
        <tr>
            <th colspan="2" data-f-bold='true' class="text-left">Programme : {{data.examRegistrationData.actualProgramName| raw}}</th>
            <th data-f-bold='true' class="text-right">&nbsp;</th>
        </tr>
        <tr>
            <th colspan="2" data-f-bold='true' class="text-left">Academic Year :  {{data.examRegistrationData.academicExamYear}} </th>
            <th data-f-bold='true' class="text-right">Semester : {{data.examRegistrationData.academicTermName}}</th>
        </tr>
        
    </table>
    <table class="tabular-table" id="tabulationRegisterReportExcel">
    <thead>
		<tr>
		    {% if data.isPrint == 0 %}
                <th data-f-bold='true' data-exclude="true" class="tabular-table-border sticky-column sticky-column-1 sticky-header" style="width:2%" rowspan="3">#</th>
            {% endif %}
            <th data-f-bold='true' class="tabular-table-border sticky-column sticky-column-2 sticky-header" style="width:2%" rowspan="3">Sl No</th>
			<th data-f-bold='true' class="tabular-table-border sticky-column sticky-column-3 sticky-header" style="width:16%" rowspan="3">Register Number</th>
			<th data-f-bold='true' class="tabular-table-border sticky-column sticky-column-4 sticky-header" style="width:20%; padding-left:15px !important; padding-right:15px !important" rowspan="3">Name of the Student</th>
            {% set mpesSubCols = 6 %}
            {% if data.displayContentOptions.rules.showModerationMark %}{% set mpesSubCols = mpesSubCols + 1 %}{% endif %}
            {% if data.displayContentOptions.rules.showGraceMark %}{% set mpesSubCols = mpesSubCols + 1 %}{% endif %}
            {% for category in pageCategories %}
				<th data-f-bold='true' data-a-h="center"  class="tabular-table-border text-center" colspan="{{(category.subjects|length) * mpesSubCols }}" style="width:20%"> {{category.name|raw}}</th> 
		    {% endfor %}
			{% if isLastCategoryPage %}
            	<th data-f-bold='true' data-a-h="center"  class="tabular-table-border text-center" style="width:2%" rowspan="3">Total</th>
				<th data-f-bold='true' data-a-h="center"  class="tabular-table-border text-center" style="width:2%" rowspan="3">SGPA</th>
				<th data-f-bold='true' data-a-h="center"  class="tabular-table-border text-center" style="width:2%" rowspan="3">Grade</th>
			{% endif %}
		</tr>
		<tr>
            {% for category in pageCategories %}
				{% for subject in category.subjects %}
					<th data-f-bold='true' data-a-h="center"  class="tabular-table-border text-center" colspan="{{mpesSubCols}}" style="width:18%">
						{{subject.code | raw}}
						</br>
						<div>CREDIT - {{subject.credit}}</div>
						<div style="float: left; width: 50%;text-align:left;">IA Max - {{subject.isInternal == 1 ? subject.internalMaxMark : '0'}}</div>
						<div style="float: right; width: 50%;text-align:right;">ESE MAX - {{subject.isExternal == 1 ? subject.externalMaxMark : '0'}}</div>
					</th>
				{% endfor %}
			{% endfor %}
        </tr>
        <tr>
			{% for category in pageCategories %}
				{% for subject in category.subjects %}
					{% if data.displayContentOptions.rules.showModerationMark %}
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">MDN</th>
					{% endif %}
					{% if data.displayContentOptions.rules.showGraceMark %}
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">GRM</th>
					{% endif %}
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">IA</span></th>
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">ESE</span></th>
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">TOT</span></th>
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">Credit</span></th>
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">Grade</span></th>
					<th data-f-bold='true' class="tabular-table-border text-center" style="font-size:10px; width:2%"><span style="padding-left:7px;padding-right:7px;">GP</span></th>

            	{% endfor %}
            {% endfor %}
        </tr>
    </thead>
	<tbody class="text-center">
	{% endmacro %}

	{% set studentsPerPage = 17 %}
	{% set categoriesPerPage = 1 %}
	{% set totalHeaderCategories = data.examRegistrationData.headerCategories|length %}
	{% set categoryPageCount = totalHeaderCategories > 0 ? (totalHeaderCategories / categoriesPerPage)|round(0, 'ceil') : 1 %}

	{% for categoryPageIndex in 0..(categoryPageCount - 1) %}
		{% set categoryStart = categoryPageIndex * categoriesPerPage %}
		{% set pageCategories = data.examRegistrationData.headerCategories|slice(categoryStart, categoriesPerPage) %}
		{% set isLastCategoryPage = categoryPageIndex == (categoryPageCount - 1) %}

		{% for student in data.studentData %}
			{% if loop.index0 % studentsPerPage == 0 %}
				{% if loop.index0 > 0 %}
					</tbody>
					</table>
					{% if data.isPrint == 1 %}
						<table style="width:100%!important; page-break:before: avoid !important" class="footer-table">
							<tr>
								<td colspan="100" class="no-border p-t-50" style="font-weight: bold !important; padding-top:85px !important">
									<span style="float:left!important; width:33.33%; text-align:left!important;">Checked by</span>
									<span style="float:left!important; width:33.33%; text-align:center!important;">Controller of Examinations</span>
									<span style="float:left!important; width:33.33%; text-align:right!important;">Principal</span>
								</td>
							</tr>
						</table>
					{% endif %}
				{% endif %}
				{{ _self.render_table_header(data, pageCategories, isLastCategoryPage, not (categoryPageIndex == 0 and loop.index0 == 0)) }}
			{% endif %}
            <tr class="stud-row">
                {% set academicTerm = student.academicTerms |first %}
                {% if data.isPrint == false %}
                    <td data-exclude="true" class="text-center tabular-table-border sticky-column sticky-column-1"><input type="checkbox" class="studentName" value='{{student.id}}'/></td>
                {% endif %}
                <td class="text-center sticky-column sticky-column-2">{{loop.index}}</td>
				<td class="text-center sticky-column sticky-column-3" style="font-size: 18px;">{{student.registerNo}}</td>
				<td class="text-left sticky-column sticky-column-4">{{student.name}}</td>
				{% for category in pageCategories %}
					{% for subject in category.subjects %}
						{% set isEntered = false %}
						{% for studentSubject in academicTerm.subjects %}
							{% if studentSubject.id == subject.id %}
								{% set displayHeadCount = displayHeadCount + 1 %}
								{% if studentSubject.attendanceStatus == "ABSENT" %}
									{% if data.displayContentOptions.rules.showModerationMark %}<td class="failed">{{studentSubject.moderationMark ? studentSubject.moderationMark : 0}}</td>{% endif %}
									{% if data.displayContentOptions.rules.showGraceMark %}<td class="failed">{{studentSubject.graceMark ? studentSubject.graceMark : 0}}</td>{% endif %}
									<td class="failed">{{studentSubject.isInternal == 1 ? studentSubject.internalAttendanceStatus == 'ABSENT' ? 'AB' : studentSubject.internalMark : "-"}}</td>
									<td class="failed">AB</td>
									<td class="failed b-r-t">-</td>
									<td class="failed b-r-t">-</td>
									<td class="failed b-r-t">-</td>
									<td class="failed b-r-t">-</td>
								{% elseif studentSubject.attendanceStatus == "MALPRACTICE" %}
									{% if data.displayContentOptions.rules.showModerationMark %}<td class="failed">{{studentSubject.moderationMark ? studentSubject.moderationMark : 0}}</td>{% endif %}
									{% if data.displayContentOptions.rules.showGraceMark %}<td class="failed">{{studentSubject.graceMark ? studentSubject.graceMark : 0}}</td>{% endif %}
									<td class="failed">{{studentSubject.isInternal == 1 ? studentSubject.internalAttendanceStatus == 'ABSENT' ? 'AB' : studentSubject.internalMark : "-"}}</td>
									<td class="failed">MAL</td>
									<td class="failed b-r-t">-</td>
									<td class="failed b-r-t">-</td>
									<td class="failed b-r-t">-</td>
									<td class="failed b-r-t">-</td>
								{% else %}
									{% if data.displayContentOptions.rules.showModerationMark %}<td>{{studentSubject.moderationMark ? studentSubject.moderationMark : 0}}</td>{% endif %}
									{% if data.displayContentOptions.rules.showGraceMark %}<td>{{studentSubject.graceMark ? studentSubject.graceMark : 0}}</td>{% endif %}
									{% if studentSubject.isInternal== 1 %}
										<td >{{studentSubject.internalAttendanceStatus == 'ABSENT' ? 'AB' : studentSubject.internalMark}}</td>
									{% else %}
										<td class="failed">-</td>
									{% endif %}
									{% if studentSubject.isExternal== 1 %}
										<td>{{studentSubject.externalMark|round}}</td>
									{% else %}
										<td class="failed">-</td>
									{% endif %}
									<td class="b-r-t">{{studentSubject.markObtained}}</td>
									<td class="b-r-t">{{studentSubject.credit}}</td>
									<td class="b-r-t">{{studentSubject.grade}}</td>
									<td class="b-r-t">{{studentSubject.gradePoint}}</td>
								{% endif %}
								{% set isEntered = true %}
							{% endif %}
						{% endfor %}
						{% if isEntered == false %}
							{% if data.displayContentOptions.rules.showModerationMark %}<td></td>{% endif %}
							{% if data.displayContentOptions.rules.showGraceMark %}<td></td>{% endif %}
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td class="b-r-t"></td>
						{% endif %}
					{% endfor %}
				{% endfor %}
				{% if isLastCategoryPage %}
                	<td >{{academicTerm.failedStatus == 'PASSED' ? academicTerm.semesterMarkObtained : '-'}}</td>
					<td >{{academicTerm.failedStatus == 'PASSED' ? academicTerm.semesterSgpa : '-'}}</td>
                	<td >{{academicTerm.failedStatus == 'PASSED' ? academicTerm.semesterGrade : '-'}}</td>
				{% endif %}

            </tr>
		{% endfor %}
	</tbody>
	</table>
	{% if data.isPrint == 1 %}
		<table style="width:100%!important; page-break:before: avoid !important" class="footer-table">
			<tr>
				<td colspan="100" class="no-border p-t-50" style="font-weight: bold !important; padding-top:85px !important">
					<span style="float:left!important; width:33.33%; text-align:left!important;">Checked by</span>
					<span style="float:left!important; width:33.33%; text-align:center!important;">Controller of Examinations</span>
					<span style="float:left!important; width:33.33%; text-align:right!important;">Principal</span>
				</td>
			</tr>
		</table>
	{% endif %}
	{% endfor %}
</div>
