{% extends "sco_page.j2" %}

{% block styles %}
    {{super()}}
    <link href="{{scu.STATIC_DIR}}/css/jury_but.css" rel="stylesheet" type="text/css" />
    <link href="{{scu.STATIC_DIR}}/css/cursus_but.css" rel="stylesheet" type="text/css" />
    <link href="{{scu.STATIC_DIR}}/css/bulletin_court.css" rel="stylesheet" type="text/css" />
{% endblock %}

{% macro table_modules(mod_type, title) -%}
<table class="resultats_modules">
    <thead>
        <tr class="titre_table">
            <th colspan="2"></th>
            <th colspan="{{ ues_acronyms|length }}">Unités d'enseignement</th>
        </tr>
        <tr class="titres_ues">
            <td colspan="2">{{title}}</td>
            {% for ue in ues_acronyms %}
                <td class="col_ue">{{ue}}</td>
            {% endfor %}
        </tr>
    </thead>       
    <tbody>
    {% for mod in bul[mod_type] %}
        <tr>
            <td>{{mod}}</td>
            <td>{{bul[mod_type][mod].titre}}</td>
            {% for ue in ues_acronyms %}
                <td>{{
                    bul.ues[ue][mod_type][mod].moyenne
                    if mod in bul.ues[ue][mod_type] else ""
                }}</td>
            {% endfor %}
        </tr>
    {% endfor %}
    </tbody>
</table>
{%- endmacro %}

{% block app_content %}
<p><a href="{{url_for(
        'notes.bulletin_but_pdf', scodoc_dept=g.scodoc_dept, etudid=etud.id, 
        formsemestre_id=formsemestre.id
    )}}" class="stdlink">version pdf {{scu.ICON_PDF|safe}}</a>
</p>

<div class="but_bul_court">
    <div id="infos_etudiant">
        <div class="nom">{{etud.nomprenom}}</div>
        <div class="formation">BUT {{formsemestre.formation.referentiel_competence.specialite}}</div>
        {% if formsemestre.etuds_inscriptions[etud.id].parcour %}
            <div class="parcours">Parcours {{formsemestre.etuds_inscriptions[etud.id].parcour.code}}</div>
        {% endif %}
        <div class="annee_scolaire">Année {{formsemestre.annee_scolaire_str()}}</div>
        <div class="semestre">Semestre {{formsemestre.semestre_id}}</div>
    </div>

    <div id="logo">
        {% if logo %}
            {{logo.html()|safe}}
        {% endif %}
    </div>

    {% if bul.options.show_abs %}
        <div id="assiduite">
            <div class="ligne-entete">Absences {{bul.semestre.absences.metrique}}</div>
            <div class="abs">Non justifiées</div>
            <div>{{bul.semestre.absences.injustifie}}</div>
            <div class="abs">Total</div>
            <div>{{bul.semestre.absences.total}}</div>
        </div>
    {% endif %}

    <div id="ues">
        <table>
        <thead>
            <tr class="titre_table">
                <th colspan="{{ 1 + bul.ues|length }}">Unités d'enseignement du semestre {{formsemestre.semestre_id}}</th>
            </tr>
            <tr class="titres_ues">
                <td></td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{ue}}</td>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Moyenne</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].moyenne.value}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>Bonus</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].bonus if bul.ues[ue].bonus != "00.00" else ""}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>Malus</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].malus if bul.ues[ue].malus != "00.00" else ""}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>Rang</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].moyenne.rang}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>Effectif</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].moyenne.total}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>ECTS</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{
                        "%g"|format(decision_ues[ue].ects) if ue in decision_ues else ""
                    }}</td>
                {% endfor %}
            </tr>
            <tr class="jury">
                <td>Jury</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{
                        decision_ues[ue].code if ue in decision_ues else ""
                    }}</td>
                {% endfor %}
            </tr>
        </tbody>
        </table>
    </div>

    <div id="ressources">
        {{ table_modules("ressources", "Ressources") }}
    </div>

    <div id="saes">
        {{ table_modules("saes", "Situations d'Apprentissage et d'Évaluation (SAÉ)") }}
    </div>

    <div id="row_situation">
        <div id="cursus_etud">
            {% include "but/cursus_etud.j2" %}
        </div>

        <div id="situation">
            <div>ECTS acquis : {{ects_total}}</div>
            <div class="descr_jury">
                {% if bul.semestre.decision_annee %}
                    Jury tenu le {{
                        datetime.datetime.fromisoformat(bul.semestre.decision_annee.date).strftime("%d/%m/%Y à %H:%M")
                    }},
                    année BUT {{bul.semestre.decision_annee.code}}.
                {% endif %}
                {% set virg = joiner(", ") %}
                {% for aut in bul.semestre.autorisation_inscription -%}
                    {% if loop.first %}
                        Autorisé à s'inscrire en
                    {% endif %}
                    {{- virg() }}S{{aut.semestre_id -}}
                    {%- if loop.last -%}
                    .
                    {%- endif -%}
                {%- endfor %}
            </div>
        </div>
    </div>

    <div id="footer">
    Bulletin généré par ScoDoc le {{time.strftime("%d/%m/%Y à %Hh%M")}}. Explication des codes sur 
        <a href="https://scodoc.org/CodesJuryBUT">https://scodoc.org/CodesJuryBUT</a>
    </div>
</div>

{% endblock %}
