{% 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>

        <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 active">
                                    <a class="plr-0 pt-0 pb-24 nav-link" href="{{ path('encaissements_usager') }}">Mes encaissements</a>
                                </li>
                                <li class="plr-24 nav-item">
                                    <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">Demande du</a></th>
                                        <th style="display: none;" 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">Mandaté le</a></th>
                                        <th class="pl-8 pr-16 ptb-16"><a class="popover-aide"  data-placement="bottom">Payé le</a></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for e in encaissements %}
                                        <tr>
                                            <td class="plr-8 ptb-24">{{ e.objet }}</td>
                                            <td class="plr-8 ptb-24">{{ e.nature }}</td>
                                            <td class="plr-8 ptb-24">{{ e.montant|number_format(2,',',' ') }} €</td>

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

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

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

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

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

                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

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

    </div>

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

    {% if allEncaissements is defined and allEncaissements==true %}
    <div align="center">
        <span class="font-color-blue"> <strong>VOIR LES 5 PLUS RÉCENTS </strong></span><br/>
        <a  href="{{path('encaissements_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('encaissements_usager');
                else
                    document.location.href= Routing.generate('encaissements_usager', {'inter' : siret });
            });    
        });
    </script>

    <script type="text/javascript">
        $(document).ready(function() {
            $('#myTable').dataTable({
                destroy: true,
                "aaSorting": []
            });
        });
    </script>

{% endblock %}

