{% set carteraVencida = 0 %}
<table class="table table-bordered table-striped table-hover table-responsive table-condensed" style="font-size: small;">
    <thead>
        <tr>
            <th>#</th>
            <th>CVE ALUMNO</th>
            <th>NOMBRE DEL ALUMNO</th>
            <th>NIVEL</th>
            <th>GRADO</th>
        </tr>
    </thead>
    <tbody>
        {% for d in datos %}
            <tr>
                <td style="vertical-align: middle;">{{loop.index}}</td>
                <td style="vertical-align: middle;">{{d[0].cveCtl}}</td>
                <td style="vertical-align: middle;">{{d[0].apePat}} {{d[0].apeMat}} {{d[0].nomAlu}}</td>
                <td style="vertical-align: middle;">{{d[0].cveLic.nomLic}}</td>
                <td style="vertical-align: middle;">{{d[0].numero}}</td>

                {% set total = 0 %}
                {% set sumaTotal = 0 %}
                
                {% for x in d[1] %}
                    {% set total = 0 %}
                    <td style="font-size: smaller;padding-top: 0px;">
                        {% if x.numero == 0 %}
                            {% if x.semestre > 1 %}
                                {% if d[0].modalidad == 'SEMESTRAL' %}
                                    <span class="btn-circle btn-primary" style="padding: 0px;">{{loop.index}}</span><br> Reinscripcion: SEMESTRE <br> #{{ x.semestre }}
                                {% else %}
                                    <span class="btn-circle btn-primary" style="padding: 0px;">{{loop.index}}</span><br> Reinscripcion: CUATRIMESTRE <br> #{{ x.semestre }}
                                {% endif %}
                                <br>
                                <strong>${{ d[0].costoReinscripciones | number_format(2,".",",") }}</strong>
                                <hr>
                                {% set total = total + d[0].costoReinscripciones %}
                            {% else %}
                                {% if d[0].modalidad == 'SEMESTRAL' %}
                                    <span class="btn-circle btn-primary" style="padding: 0px;">{{loop.index}}</span><br> Inscripcion: SEMESTRE <br> #{{ x.semestre }}
                                {% else %}
                                    <span class="btn-circle btn-primary" style="padding: 0px;">{{loop.index}}</span><br> Inscripcion: CUATRIMESTRE <br> #{{ x.semestre }}
                                {% endif %}
                                <br>
                                <strong>${{ d[0].costoInscripcion | number_format(2,".",",") }}</strong>
                                <hr>
                                {% set total = total + d[0].costoInscripcion %}
                            {% endif %}
                            RECARGOS
                            <br>
                            <strong>$100.00</strong>
                            {% set total = total + 100 %}
                            <hr>
                            <p style="background-color: white;text-align: right;">
                                TOTAL:
                                <br>
                                <strong>${{total | number_format(2,".",",") }}</strong>
                            </p>
                        {% else %}
                            <span class="btn-circle btn-primary" style="padding: 0px;">{{loop.index}}</span><br> COLEGIATURA: <i>{{x.nomMes}}</i> <br> {{x.fecIni | date('Y')}}
                            <br>
                            <strong>${{d[0].costoMensualidad | number_format(2,".",",") }}</strong>
                            {% set total = total + d[0].costoMensualidad %}
                            <hr>
                            RECARGOS
                            <br>
                            <strong>$200.00</strong>
                            {% set total = total + 200 %}
                            <hr>
                            <p style="background-color: white;text-align: right;">
                                TOTAL:
                                <br>
                                <strong>${{total | number_format(2,".",",") }}</strong>
                            </p>
                        {% endif %}
                    </td>
                    {% set sumaTotal = sumaTotal + total %}
                {% else %}
                    <td style="background-color: red;">ESTO ES RARO, NO DEBERÍA DE VER ESTE MENSAJE</td>
                {% endfor %}

                <td style="vertical-align: middle;background-color: orange;">
                    ADEUDO TOTAL: 
                    <br>
                    <strong>${{sumaTotal | number_format(2,".",",") }}</strong>
                    {% set carteraVencida = carteraVencida + sumaTotal %}
                </td>
            </tr>
        {% else %}
            <tr class="text-center">
                <td colspan="5"> NO HAY ALUMNOS CON ADEUDOS ~(^.^)~</td>
            </tr>
        {% endfor %}
    </tbody>
</table>
<hr>
<table class="table table-responsive table-condensed table-hover table-striped">
    <thead>
        <tr>
            <th>GRAN TOTAL: </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                ${{carteraVencida | number_format(2,".",",") }}
            </td>
        </tr>
    </tbody>
</table>