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

{% block title %}Opérations comptables{% endblock %}

{% block main %}



    <div class="container-fluid">


    {% if not entete is null and not entete.texte==''%}
        <div class="col-xs-12 p-0">
            <div class="bloc-base p-16">
                {{ entete.texte|raw }}
            </div>
        </div>
    {% endif %}

    <br/>
    <div align="left">

        {% if app.session.has('interlocuteurSelected') %}
            {% set interlocuteurSelected = app.session.get('interlocuteurSelected') %}
        {% else %}
            {% set interlocuteurSelected = null %}
        {% endif %}
        <select id="inter" name="inter" class="selectpicker">
            <option value="tous" {% 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 id="operations-comptables-tableau" class="row plr-16 ptb-24">
            <!-- TABLEAU-->
            <div class="col-xs-12 p-0">
                <div class="bloc-base p-16">
                    <div class="row m-0">
                        <div class="col-xs-12 p-0 mb-24">
                            <ul id="content-nav-tabs" class="nav divider-grey-b">
                                <li class="pr-24 nav-item">
                                    <a class="plr-0 pt-0 pb-24 nav-link" href="{{ path('encaissements_usager') }}">Mes encaissements</a>
                                </li>
                                <li class="plr-24 nav-item active">
                                    <a class="plr-0 pt-0 pb-24 nav-link" href="{{ path('decaissements_usager') }}">Mes décaissements</a>
                                </li>
                            </ul>
                        </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 class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Objet</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Nature</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Montant</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Emis le</a></th>
                                        <th style="display: none;"></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Exigible le</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Recouvré le</a></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for d in decaissements %}
                                        <tr>
                                            <td class="plr-8 ptb-24">{{ d.objet }}</td>
                                            <td class="plr-8 ptb-24">{{ d.nature }}</td>
                                            <td class="plr-8 ptb-24">{{ d.montant|number_format(2,',',' ') }} €</td>

                                            {% if '30/11/-0001' not in d.dateDemande|date('d/m/Y') and d.dateDemande is not null %}
                                                <td class="plr-8 ptb-24"><span class="hidden">{{d.dateDemande ? d.dateDemande|date('Y/m/d H:i:s') }}</span>{{d.dateDemande ? d.dateDemande|date('d/m/Y') }}</td>
                                            {% else %}
                                                <td class="plr-8 ptb-24"><span class="hidden">{{d.dateDemande ? d.dateDemande|date('Y/m/d H:i:s') }}</span></td>
                                            {% endif %}

                                            {% if '30/11/-0001' not in d.dateDemande|date('d/m/Y') and d.dateDemande is not null %}
                                                <td style="display: none;"><span class="hidden">{{d.dateDemande ? d.dateDemande|date('Y/m/d H:i:s') }}</span> {{d.dateDemande ? d.dateDemande|date('d/m/Y') }}</td>
                                            {% else %}
                                                <td style="display: none;"><span class="hidden">{{d.dateDemande ? d.dateDemande|date('Y/m/d H:i:s') }}</span>
                                            {% endif %}

                                            {% if '30/11/-0001' not in d.dateLimite|date('d/m/Y') and d.dateLimite is not null %}
                                                <td class="plr-8 ptb-24"><span class="hidden">{{d.dateLimite ? d.dateLimite|date('Y/m/d H:i:s') }}</span>{{d.dateLimite ? d.dateLimite|date('d/m/Y') }}</td>
                                            {% else %}
                                                <td class="plr-8 ptb-24"><span class="hidden">{{d.dateLimite ? d.dateLimite|date('Y/m/d H:i:s') }}</span></td>
                                            {% endif %}

                                            {% if '30/11/-0001' not in d.dateRecouvrementTotal|date('d/m/Y') and d.dateRecouvrementTotal is not null %}
                                                <td class="plr-8 ptb-24"><span class="hidden">{{d.dateRecouvrementTotal ? d.dateRecouvrementTotal|date('Y/m/d H:i:s') }}</span>{{d.dateRecouvrementTotal ? d.dateRecouvrementTotal|date('d/m/Y') }}</td>
                                            {% else %}
                                                <td class="plr-8 ptb-24"><span class="hidden">{{d.dateRecouvrementTotal ? d.dateRecouvrementTotal|date('Y/m/d H:i:s') }}</span></td>
                                            {% endif %}
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

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

    </div>


    {% if not allDecaissements is defined or allDecaissements==false %}
    <div align="center">
        <span class="font-color-blue"> <strong>VOIR TOUS MES DECAISSEMENTS </strong></span><br/>
        <a  href="?all=1" class="button-rond-xs align-middle"><i class="fas fa-arrow-down"></i></a>
    </div>
    {% endif %}

    {% if allDecaissements is defined and allDecaissements==true %}
    <div align="center">
        <span class="font-color-blue"> <strong>VOIR LES 5 PLUS RÉCENTS </strong></span><br/>
        <a  href="{{path('decaissements_usager')}}" class="button-rond-xs align-middle"><i class="fas fa-arrow-up"></i></a>
    </div>
    {% endif %}

{% endblock %}

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

    <script type="text/javascript">
        $(document).ready(function() {
            $('#inter').change(function(){
                let siret = $( this ).val();
                if(siret == -1)
                    document.location.href= Routing.generate('decaissements_usager');
                else
                    document.location.href= Routing.generate('decaissements_usager', {'inter' : siret });
            });    
        });
    </script>

    <script type="text/javascript">
    $(document).ready(function() {

        $('#myTable').dataTable({
            destroy: true,
            "aaSorting": []
        });
    });
    </script>

{% endblock %}

