{% extends 'scolarite/ags_base.html' %}
{% load static %}
{% load custom_tag %}
{% load custom_tag_obj %}
{% block head %}{% endblock head %}
{% block page_title %}<!--({{ue.code}}) : {{ue.libelle}}--> {% endblock page_title %}
{% block content %}
<div class="card mb-3">
    <div class="card-header">
        <i class="fas fa-table"></i>
        LISTE DES DEMANDES
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <h4 style="color: #1f96d7; margin-bottom:-9px;">Génerer un document</h4><hr/>
            <form method="post" action="#">
            {% csrf_token %}
            <div class="row">
                <div class="col-md-3">
                    <label>Matricule</label>
                    <input class="form-control" style="text-transform:uppercase;" name="nce" placeholder="Numéro Carte Etudiant" required />
                </div>
                <div class="col-md-2">
                    <label>Années</label>
                    <select class="form-control" name="annee">
                        {% for annee in annees %}
                        <option value="{{annee.id}}">{{annee}}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-3">
                    <label>Type de demande</label>
                    <select class="form-control" name="typedem">
                        {% for typeDemande in typeDemandes %}
                        <option value="{{typeDemande.id}}">{{typeDemande.libelle}}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-3">
                    <button style="margin-top:30px;" name="generer" class="btn btn-primary"><i class="fa fa-file"></i>&nbsp; Générer le document</button>
                </div>

            </div><br/>
            </form>
            <table class="table table-bordered table-striped" {% if hide_form %}hidden{% endif %}>
                <thead>
                    <tr>
                        <th>ANNEE</th>
                        <th>NOM & PRENOMS</th>
                        <th>ETABLISSEMENT</th>
                        <th>TYPE</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td width="100">{{an}}</td>
                        <td>
                            <strong>{{etudiant.nce}}</strong><br/>
                            {{etudiant}}
                        </td>
                        <td width="70">{{etudiant.ufr.code}}</td>
                        <td>{{typedem}}</td>
                        <td width="150">
                            {% if an and sem and typedem.libelle == 'Relevé de notes' %}
                            <a style="margin-top:3px;" href="{% url 'Scolarite:releve_de_note_semestre' etudiant.id an.id sem.0.id %}" target="_blank" class="btn btn-success btn-sm"><i class="fa fa-download"></i>&nbsp; S1</a>
                            <a style="margin-top:3px;" href="{% url 'Scolarite:releve_de_note_semestre' etudiant.id an.id sem.1.id %}" target="_blank" class="btn btn-success btn-sm"><i class="fa fa-download"></i>&nbsp; S2</a>
                            <a style="margin-top:3px;" href="{% url 'Scolarite:releve_de_note' etudiant.id an.id %}" target="_blank" class="btn btn-success btn-sm"><i class="fa fa-download"></i>&nbsp; Annuel</a>
                            {% elif an and sem and typedem.libelle == 'Certificat de scolarité'  %}
                            <a style="margin-top:3px;" href="{% url 'Scolarite:certificat_scolarite' etudiant.id an.id %}" target="_blank" class="btn btn-success btn-sm"><i class="fa fa-download"></i>&nbsp; Télécharger</a>
                            {% endif %}
                        </td>
                    </tr>


                </tbody>
            </table><br/>
            <h4 style="color: #1f96d7; margin-bottom:-9px;">Liste de demandes</h4><hr/>
            {% for tp in typeDemandes %}{{tp.libelle}} (<span style="color:#1f96d7;">{{tp|get_demande_by_type:'length'}}</span>) | {% endfor %}
            <hr/>
            <br/>
            <table class="table table-bordered table-striped" id="dataTable" width="100%" cellspacing="0">
                <thead>
                <tr>
                    <th>Date</th>
                    <th>Apprenant</th>
                    <th>Type</th>
                    <th></th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th>Date</th>
                    <th>Apprenant</th>
                    <th>Type</th>
                    <th></th>
                </tr>
                </tfoot>
                <tbody>
                {% for demande in demandes %}
                <tr>
                    <td width="80">{{demande.created|date:'d-m-Y à H:m:s'}}</td>
                    <td>
                        <strong>{{demande.etudiant.nce}}</strong><br/>
                        {{demande.etudiant}}
                    </td>
                    <!--<td>{{pv.ufr.libelle}}</td> -->
                    <td>{{demande.type_demande}}</td>
                    <td width="100">
                        {% if demande.id|check_reponse_by_demande %}
                        <button data-toggle="modal" data-target="#dem{{demande.id}}" class="btn btn-success btn-sm"><i class="fa fa-paper-plane"></i>&nbsp; Renvoyer</button>
                        {% else %}
                        <button data-toggle="modal" data-target="#dem{{demande.id}}" class="btn btn-primary btn-sm"><i class="fa fa-paper-plane"></i>&nbsp; Envoyer</button>
                        {% endif %}
                        <!--<img src="{% static 'inscription/assets/img/done.png' %}" width="30" height="30"> -->
                    </td>
                </tr>
                {% include 'scolarite/modal_demande_done.html' %}
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock content %}

{% block custom_js %}
<script src="{% static 'js/custom-js/save_note.js'%} "></script>
 <script src="{% static 'js/custom-js/note.js' %}"></script>
<script>
    var elements = rootElement.getElementsByClassName('delib')
</script>
{% endblock custom_js %}