{% extends 'menu_left.html.twig' %}

{% block title %}Echeances globales{% endblock %}

{% block main %}



    <div class="container-fluid">

        <div id="echeancier-global-intro" class="row plr-16 ptb-24">
            <!-- INTRO-->
            <div class="col-xs-12 p-0">
                <div class="bloc-base p-16">
                    <p><a href="{{ path('participations_list') }}" class="button-rond-xs align-middle mr-8"><i class="fas fa-arrow-left"></i></a>Participations financières</p>
                </div>
            </div>
        </div>
        <br/>
        <div class="row plr-16 ptb-24">
            <div align="left">
            {% if app.session.has('interlocuteurSelectedEcheances') %}
                {% set interlocuteurSelected = app.session.get('interlocuteurSelectedEcheances') %}
            {% else %}
                {% set interlocuteurSelected = null %}
            {% endif %}
            <select id="inter" name="inter" class="selectpicker">
                <option value="-1" {% if interlocuteurSelected is null %}selected{% endif %}>Tous les interlocuteurs</option>
                {% for inter in interlocuteurs %}
                    <option value="{{ inter.siret }}" {% if inter.siret == interlocuteurSelected %} selected {% endif %}>{{ inter.siret }} - {{ inter.raisonSociale }}</option>
                {% endfor %}
            </select>
        </div>
        <div id="echeancier-global-tableau" class="row plr-16 ptb-24">
            <!-- TABLEAU-->
            <div class="col-xs-12 p-0">
                <div class="bloc-base p-16">
                    <div class="bloc-title mb-16">
                        <div class="row m-0">
                            <div class="col-xs-6 p-0">
                                <h2 class="align-middle">Année {{ annee }}</h2>
                            </div>
                            <div class="col-xs-6 p-0 text-align-r">
                                <a id="year-previous" title="Année précédente" href="?annee={{ annee-1 }}" class="button-rond-xs align-middle"><i class="fas fa-arrow-left"></i></a> <a id="year-next" title="Année suivante" href="?annee={{ annee+1 }}" class="button-rond-xs align-middle"><i class="fas fa-arrow-right"></i></a>
                            </div>
                        </div>
                    </div>
                    <div class="row m-0">
                        <div class="col-xs-12 p-16 background-white">
                            <div class="table-responsive">
                                <table id="myTable" class="display">
                                    <thead class="background-blue">
                                    <tr>
                                        <th style="width:  10%;" class="pl-8 pr-16 ptb-16"><a class="popover-aide" href="#" data-content="Libellé d’aide à la compréhension" data-placement="bottom">N° de convention ou acte d'attrib.</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide" href="#" data-content="Libellé d’aide à la compréhension" data-placement="bottom">Interlocuteur</a></th>
                                        <th style="width:  30%;" class="pl-8 pr-16 ptb-16"><a class="popover-aide" href="#" data-content="Libellé d’aide à la compréhension" data-placement="bottom">Objet</a></th>
                                        <th style="width:  30%;" class="pl-8 pr-16 ptb-16"><a class="popover-aide" href="#" data-content="Libellé d’aide à la compréhension" data-placement="bottom">Localisation</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide" href="#" data-content="Libellé d’aide à la compréhension" data-placement="bottom">Echéance</a></th>
                                        <th style="width:  16%;" class="pl-8 pr-16 ptb-16"><a class="popover-aide" href="#" data-content="Libellé d’aide à la compréhension" data-placement="bottom">Montant</a></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for e in echeances %}
                                        <tr>
                                            <td class="plr-8 ptb-24"><a href="{{ path('echeance_dossier',{dossierID : e.dossier_aide_numero})}}" class="table-lien">{{ e.dossier_aide_numero }}</a></td>
                                            <td class="plr-8 ptb-24">{{ e.interlocuteurSiret }}</td>
                                            <td class="plr-8 ptb-24">{{ e.objet }}</td>
                                            <td class="plr-8 ptb-24">{{ e.localisation }}</td>
                                            {% if '30/11/-0001' not in e.date_echeance|date('d/m/Y') and e.date_echeance is not null %}
                                                <td class="plr-8 ptb-24">{{e.date_echeance ? e.date_echeance|date('d/m/Y') }}</td>
                                            {% else %}
                                                <td class="plr-8 ptb-24"></td>
                                            {% endif %}
                                            <td class="plr-8 ptb-24">{{ e.montant|number_format(2,',',' ') }}€</td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th class="plr-8 ptb-24" colspan="5">Total des montants de l'année :</th>
                                        <th class="plr-8 ptb-24">{{ total|number_format(2,',',' ') }} €</th>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

    </div>

{% endblock %}
{% block javascript %}
    {{ parent() }}

    <script type="text/javascript">
       $('#myTable').dataTable({
                "aoColumns": [
                    null,
                    null,
                    null,
                    null,
                    { "sType": "date-uk" },
                    { "sType": "currency" },
                ]
            });    
    </script>

{% endblock %}
{% block javascript_inline %}
<script>
    $('#year-previous #year-next').tooltip({});
    $(document).ready(function() {
        $('#inter').change(function(){
            let siret = $( this ).val();
            if(siret == -1)
                document.location.href= Routing.generate('global_echeances');
            else
                document.location.href= Routing.generate('global_echeances', {'inter' : siret });
        });
        
    });
</script>
{% endblock %}

