<style>
    .bordered-table,
    .bordered-table th,
    .bordered-table td{
        border: 1px solid #000;
        border-collapse: collapse;
    }

    {# this table is only meant for excel export #}
    #failed-student-list{
        display: none;
    }

</style>


<div class="text-center" style="margin:10px;">
    <div class="text-center m-t-20">
        <table style="width:100% !important; page-break-inside:avoid;" class="bordered-table" id="failed-student-list-wkhtml">
            <thead>
                <tr>
                    <th data-a-h="center"  data-f-bold="true" colspan="{{(additionalInfo.totalSemester * 3) + 7}}" class="text-center" style="font-size:20px"> {{additionalInfo.collegeData.collegeName}}</th>
                </tr>
                <tr>
                    <th data-a-h="center"  data-f-bold="true" colspan="{{(additionalInfo.totalSemester * 3) + 7}}" class="text-center " style="font-size:17px"> Consolidated Report of Failed Students  </th>
                </tr>
                <tr>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:5%"> Sl No.  </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:10%"> Register Number</th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:20%"> Name of Student </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:20%"> Program </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:20%"> Batch </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" colspan="{{additionalInfo.totalSemester * 3}}" style="height:40px; padding:10px;">
                        Failed subject List {{additionalInfo.formattedBatchNames}}
                    </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;" data-a-wrap="true"> Total Number of Supplementary Courses</th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;"> Course</th>
                </tr>
                <tr>
                    {% for semester in additionalInfo.semesters %}
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" colspan="3" style="height:40px; padding:10px;  width:10%"> {{ semester.name }} </th>
                    {% endfor %}

                </tr>
                <tr>
                    {% for semester in additionalInfo.semesters %}
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" style="height:40px; padding:10px;  width:10%"> Count </th>
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" style="height:40px; padding:10px;  width:10%"> Code </th>
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" style="height:40px; padding:10px;  width:10%"> Course </th>
                    {% endfor %}

                </tr>
            </thead>
            <tbody>
                {% set sl = 0%}
                {% for student in subjects %}
                    {% set sl = sl + 1 %}
                    <tr>
                        <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px">{{sl}}</td>
                        <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px">{{student.regNo}}</td>
                        <td class="text-left" style="vertical-align:top !important; padding: 10px">{{student.name}}</td>
                        <td class="text-left" style="vertical-align:top !important; padding: 10px">{{student.program}}</td>
                        <td class="text-left" style="vertical-align:top !important; padding: 5px">{{student.batch}}</td>
                        {% for semester in additionalInfo.semesters %}
                            {% set found = 0%}
                            {% for academicTerm in student.academicTerms %}	
                                {% if semester.id == academicTerm.id %}
                                    <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" >{{academicTerm.failedCount }}</td>
                                    <td class="text-left" data-a-h="center"  style="vertical-align:top !important; padding-top:20px">
                                        <ul>
                                        {% for course in academicTerm.failedCourses %}	
                                            <li>{{course.subjectCode}}<br></li>
                                        {% endfor %}
                                        </ul>
                                    </td>
                                    <td class="text-left" data-a-h="center"  style="vertical-align:top !important; padding-top:20px">
                                        <ul>
                                        {% for course in academicTerm.failedCourses %}	
                                            <li>{{course.subjectName}}<br></li>
                                        {% endfor %}
                                        </ul>
                                    </td>
                                    {% set found = 1%}
                                {% endif %}
                            {% endfor %}
                            {% if found == 0 %}
                                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" >0</td>
                                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" ></td>
                                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" ></td>
                            {% endif %}
                        {% endfor %}
                        <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px">{{student.failedCount}}</td>
                        <td class="text-left" data-a-h="left" style="vertical-align:top !important; padding-top:20px">
                            <ul>
                                {% for course in student.course %}	
                                    <li>{{course}}<br></li>
                                {% endfor %}
                            </ul>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>

        </table>
    <div>
</div>

<div class="text-center" style="margin:10px;">
    <div class="text-center m-t-20">
        <table style="width:100% !important; page-break-inside:avoid;" class="bordered-table" id="failed-student-list" data-cols-width="{{additionalInfo.commaSeparatedColSpans}}"> {# column widths are directly substituted. it is created at the service #}
            <thead>
                <tr>
                    <th data-a-h="center"  data-f-bold="true" colspan="{{(additionalInfo.totalSemester * 3) + 7}}" class="text-center" style="font-size:20px"> {{additionalInfo.collegeData.collegeName}}</th>
                </tr>
                <tr>
                    <th data-a-h="center"  data-f-bold="true" colspan="{{(additionalInfo.totalSemester * 3) + 7}}" class="text-center " style="font-size:17px"> Consolidated Report of Failed Students  </th>
                </tr>
                <tr>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:5%"> Sl No.  </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:10%"> Register Number</th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:20%"> Name of Student </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:20%"> Program </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;  width:20%"> Batch </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" colspan="{{additionalInfo.totalSemester * 3}}" style="height:40px; padding:10px;">
                        Failed subject List {{additionalInfo.formattedBatchNames}}
                    </th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;" data-a-wrap="true"> Total Number of Supplementary Courses</th>
                    <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" rowspan="3" style="height:40px; padding:10px;"> Course</th>
                </tr>
                <tr>
                    {% for semester in additionalInfo.semesters %}
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" colspan="3" style="height:40px; padding:10px;  width:10%"> {{ semester.name }} </th>
                    {% endfor %}

                </tr>
                <tr>
                    {% for semester in additionalInfo.semesters %}
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" style="height:40px; padding:10px;  width:10%"> Count </th>
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" style="height:40px; padding:10px;  width:10%"> Code </th>
                        <th data-a-h="center"  data-f-bold="true" class="text-center fs-11" style="height:40px; padding:10px;  width:10%"> Course </th>
                    {% endfor %}

                </tr>
            </thead>
            <tbody>
                {{ _self.rowcreatorExcelExport(subjects, additionalInfo) }}
            </tbody>

        </table>
    <div>
</div>



{% macro rowcreatorExcelExport(subjects, additionalInfo) %}

{% set slno = 0 %}
{% for student in subjects %}
    {% set slno = slno + 1 %}
    {% for failedSubject in 1..student.failedCount %}
        {% set parentLoopIndex = loop.index %}
        <tr>
            {# only print student details for the first iteration #}
            {% if parentLoopIndex == 1 %}
                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" rowspan="{{ student.failedCount }}">{{ slno }}</td>
                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" rowspan="{{ student.failedCount }}">{{student.regNo}}</td>
                <td class="text-left" style="vertical-align:top !important; padding: 10px" rowspan="{{ student.failedCount }}">{{ student.name }}</td>
                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" rowspan="{{ student.failedCount }}">{{student.program}}</td>
                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" rowspan="{{ student.failedCount }}">{{student.batch}}</td>
            {% endif %}

            {# print subject details #}
            {% for semester in additionalInfo.semesters %}
                {% set obj = student.keyed[semester.id][parentLoopIndex - 1] %}
                {% if parentLoopIndex == 1 %}
                    <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" rowspan="{{ student.failedCount }}"> {{ obj.semesterFailCount ?? 0 }} </td>
                {% endif %}
                <td class="text-left" data-a-wrap="true" data-a-h="center"  style="vertical-align:top !important; padding-top:20px;"> {{ obj.subjectCode }} </td>
                <td class="text-left" data-a-wrap="true" data-a-h="center"  style="vertical-align:top !important; padding-top:20px;"> {{ obj.subjectName }} </td>
            {% endfor %}

            {# only print the total failed count once #}
            {% if parentLoopIndex == 1 %}
                <td class="text-center" data-a-h="center" style="vertical-align:top !important; padding-top:20px" rowspan="{{ student.failedCount }}">{{student.failedCount}}</td>
            {% endif %}

            <td data-a-wrap="true"> {{ student.course[parentLoopIndex - 1] }} </td>
        </tr>
    {% endfor %}
{% endfor %}

{% endmacro %}