{% extends 'layout.twig' %}

{% block body %}
    <div class="contenu clearfix"  id="tiers">
    <h1>
        {{ 'Gestion des tiers' | trad }}
        {% if hasCreateEditAccessRights %}
            <a href="{{ path('Stock.Tiers.nouveauForm') }}" class="button principal ajout mr-0">
                {{ 'Nouveau' | trad }}
            </a>
        {% endif %}
    </h1>
    {{ ariane() }}
    <div class="tab-content" id="tab-content">
        <p></p>
        {% set formName = "filtres_tiers" %}
        <form method="post" name="{{ formName }}" id="{{ formName }}">
            <div class="tab-content">
                <div id="filtre" class="tab-pane active in clearfix box-form">
                    <div class="filtre">
                        {{ inputAdvance('TEXT', {
                            'titre' : 'Nom destinataire' | trad,
                            'name' : 'filter_RS',
                            'value' : post.filter_RS,
                            'bulle': 'true',
                            'inputAttr': {
                                'data-multifilter': 'form_RS',
                                'data-multifilter-twin': 'table_RS'
                            },
                        }) }}
                    </div>
                    <div class="filtre">
                        {{ inputAdvance('ZOOMADVANCE',{
                            'titre' : 'Pays' | trad,
                            'name' : 'filter_PAYS',
                            'value': post['filter_PAYS'],
                            'pahtZoom' : path('Ajax.liste.pays'),
                            'entity' : 'Pays',
                            'titleZoom' : 'Liste des pays' | trad,
                            'pathConvert' : path('Ajax.outil.convertLibelle'),
                            'convertLibelle' : 'convertLibelleGlobal',
                            'inputAttr': {
                                'data-multifilter': 'form_PAYS',
                                'data-multifilter-twin': 'table_PAYS'
                            },
                            'faceAttr': {
                                'data-zoomLink': 'input_filter_PAYS'
                            },
                            'bulle': true
                        }) }}
                        {{ include('@Stock/Composant/ZoomAdvance/_empty_code_tiers.twig') }}
                    </div>
                    <button type="submit" class="principal button btn_filtre button_right last">
                        {{ 'Filtrer' | trad }}
                    </button>
                    <button class="secondaire button button_right" id="buttonCollapseFA"  id="buttonCollapseFA"  data-toggle="collapse" href="#filtre_avances">
                        {{  'Filtres avancés' | trad }}
                    </button>
                </div>
            </div>

            <div id="filtre_avances" class="collapse clearfix">
                {{ filtreAvance(post, filtreAvance, initFiltreAvance) }}
            </div>
            <div class="resultat_filtre">
                {{ bullFiltre(post, formName) }}
            </div>

            <div id='refreshTable'>
                <table class="table table-hover">
                    <thead class="thead-dark" >
                    <tr>
                        <th scope="col" width="150px">
                            {{ triTable('CODE',post.tri_CODE,'Code' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="200px">
                            {{ triTable('RS',post.tri_RS,'Nom destinataire' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="350px">
                            {{ triTable('ADR',post.tri_ADR,'Adresse' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="150px">
                            {{ triTable('CPOSTAL',post.tri_CPOSTAL,'Code postal' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="150px">
                            {{ triTable('VILLE1',post.tri_VILLE1,'Ville' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="100px">
                            {{ triTable('PAYS',post.tri_PAYS,'Pays' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="150px">
                            {{ triTable('DTE_OUV',post.tri_DTE_OUV,'Date ouverture' | trad, '', '', formName) }}
                        </th>
                        <th scope="col" width="150px">
                            {{ triTable('DTE_FER',post.tri_DTE_FER,'Date fermeture' | trad, '', '', formName) }}
                        </th>
                        {% if hasCreateEditAccessRights %}
                            <th scope="col" width="90px">{{ 'Actions' | trad }}</th>
                        {% endif %}
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="recherche">
                        <td>
                            {% set exclude_empty_code = is_blanc_interdit_tiers() ? 'true': 'false' %}
                            {{ zoomFilter(
                                "egal_CODE", post['filter_egal_CODE'], "", formName, path('Ajax.liste.tiers'),
                                'Code' | trad, '','','','','','Code', null, null, null,
                                "{'exclude_empty_code': " ~ exclude_empty_code ~ "}"
                            ) }}
                        </td>
                        <td>
                            {{ filterTable(
                                'RS',
                                post['filter_RS'],
                                '', '', '',formName, '',
                                'Nom destinataire' | trad, false, false, 'readonly', null, null, null,
                                {
                                    'data-multifilter': 'table_RS',
                                    'data-multifilter-twin': 'form_RS'
                                }
                            ) }}
                        </td>
                        <td>
                            {{ filterTable('ADR', post.filter_ADR, '', '', '',formName, '', 'Adresse' | trad) }}
                        </td>
                        <td>
                            {{ filterTable('egal_CPOSTAL', post.filter_egal_CPOSTAL, '', '', '',formName, '', 'Code postal' | trad) }}
                        </td>
                        <td>
                            {{ filterTable('VILLE1', post.filter_VILLE1, '', '', '',formName, '', 'Ville' | trad) }}
                        </td>
                        <td>
                            {{ filterTable(
                                'PAYS',
                                post['filter_PAYS'],
                                '', '', '',formName, '',
                                'Pays' | trad, false, false, 'readonly', null, null, null,
                                {
                                    'data-multifilter': 'table_PAYS',
                                    'data-multifilter-twin': 'form_PAYS'
                                }
                            ) }}
                        </td>
                        <td>
                            {{ filterTable('date_DTE_OUV', post.filter_date_DTE_OUV, '', '', '', formName, 'datepicker', 'Date d\'ouverture' | trad) }}
                        </td>
                        <td>
                            {{ filterTable('date_DTE_FER', post.filter_date_DTE_FER, '', '', '', formName, 'datepicker', 'Date de fermeture' | trad) }}
                        </td>
                        {% if hasCreateEditAccessRights %}
                            <td></td>
                        {% endif %}
                    </tr>

                    {% for tiers in tiersResults %}
                        <tr id="tiers{{ tiers.CODE }}" class="{% if loop.index is divisible by(2) %}even{% else %}odd{% endif %}">
                            <td>{{ tiers.CODE | visualise }}</td>
                            <td>{{ tiers.RS | visualise }}</td>
                            <td>{{ tiers.ADR | visualise }}</td>
                            <td>{{ tiers.CPOSTAL | visualise }}</td>
                            <td>{{ tiers.VILLE1 | visualise }}</td>
                            <td>{{ tiers.PAYS | visualise }}</td>
                            <td>{{ tiers.DTE_OUV | dateTrad | visualise }}</td>
                            <td>{{ tiers.DTE_FER | dateTrad | visualise }}</td>
                            {% if hasCreateEditAccessRights %}
                                <td>
                                    <a href="{{ path('Stock.Tiers.modifierForm', { code: tiers.CODE == '' ? emptyParam: tiers.CODE }) }}">
                                        <span class="modifier_v2"></span>
                                    </a>
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
                {{ paginations(path('Stock.Tiers.gestion'),infoPagination.nombreDePage,infoPagination.page,infoPagination.post) }}
            </div>
        </form>
    </div>
    <script type="text/javascript" src="{{ baseUrl('js/Modules/Stock/multiForm.js') }}"></script>
    <script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/zoomAdvanceReinitialiser.js') }}"></script>
{% endblock %}