{% extends 'layout.twig' %}

{% block body %}
    <div class="contenu clearfix">
        <h1>
            {{ 'Inventaires' | trad }}
            <a href="{{ path('Stock.Inventaire.nouveauForm') }}" class="button principal ajout button_right mr-0">
                {{ 'Nouveau' | trad }}
            </a>
            {{ Button(
                'Export' | trad,
                false,
                '',
                'ajaxPopup(\''~path('Stock.Inventaire.popupExport')~'\', \''~'Export Inventaires' | trad~'\', \'\', \'\', \'\', \'modal_export \')', ''
            ) }}
        </h1>

        {{ ariane() }}

        {% set formFilterName = "filtres_inventaires"  %}
        <div class="tab-content" id="tab-content">
            <p></p>
            <form method="post" name="{{ formFilterName }}" id="{{ formFilterName }}">
                <div class="tab-content">
                    <div id="filtre" class="tab-pane active in clearfix bg_form padding_form border_form filtre_facture">
                        <div class="filtre">
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'Magasinier' | trad,
                                'name' : 'filter_egal_SI#point#MAG',
                                'value' : post['filter_egal_SI#point#MAG'],
                                'pahtZoom' : path('Ajax.liste.magasiniers'),
                                'entity' : 'HASTUTIL',
                                'titleZoom' : 'Liste des magasiniers' | trad,
                                'pathConvert' : path('Ajax.outil.convertLibelle'),
                                'convertLibelle' : 'convertLibelleGlobal',
                                'pathValidator' : path('Ajax.validator.zoom'),
                                'paramsValidator' : "{'entity' : 'HASTUTIL','nomChamp' : '"~ 'Magasinier' | trad ~"', 'null' : true}",
                                'bulle' :  'true',
                                'faceAttr': {
                                    'data-zoomLink': 'input_egal_SI#point#MAG'
                                },
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'Société' | trad,
                                'name' : 'filter_egal_SI#point#CODE_STE',
                                'value' : post['filter_egal_SI#point#CODE_STE'],
                                'pahtZoom' : path('Ajax.liste.societe'),
                                'entity' : 'Societe',
                                'titleZoom' : 'Liste des sociétés' | trad,
                                'pathConvert' : path('Ajax.outil.convertLibelle'),
                                'convertLibelle' : 'convertLibelleGlobal',
                                'bulle' :  'true',
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_SI#point#CODE_STE'
                                },
                            }) }}
                        </div>
                        <button type="submit" class="principal button btn_filtre button_right last">
                            {{ 'Filtrer' | trad }}
                        </button>
                        <button type="button" class="secondaire button button_right" onClick="resetFormFilters('{{ formFilterName }}');">
                            {{ 'Vider les champs' | trad }}
                        </button>
                        <button type="button" class="secondaire button button_right" onClick="resetFormFilters('{{ formFilterName }}', 'filter_egal_SI#point#CODE_STE');">
                            {{ 'Vider les champs (sauf société)' | trad }}
                        </button>
                    </div>
                </div>

                <div class="resultat_filtre">
                    {{ bullFiltre(post, formFilterName) }}
                </div>

                <div id='refreshTable'>
                    <table class="table table-hover">
                        <thead class="thead-dark" >
                        <tr>
                            <th scope="col" width="110px">
                                {{ triTable('NO_INV',post.tri_NO_INV, 'N°Inv' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="500px">
                                {{ triTable('DESIGN',post.tri_DESIGN,'Désignation' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('DTE_CREAT',post.tri_DTE_CREAT,'Date création' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('DTE_PREV',post.tri_DTE_PREV,'Prévision' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ 'Statut' | trad }}
                            </th>
                            <th scope="col" width="40px">{{ 'Actions' | trad }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="recherche">
                            <td>{{ filterTable('egal_SI#point#NO_INV',post['filter_egal_SI#point#NO_INV'],'', '', '',formFilterName, '','N° Inv' | trad) }}</td>
                            <td>{{ filterTable('SI#point#DESIGN',post['filter_SI#point#DESIGN'],'', '', '',formFilterName, '','Désignation' | trad) }}</td>
                            <td>{{ filterTable('date_SI#point#DTE_CREAT',post['filter_date_SI#point#DTE_CREAT'],'', '', '', formFilterName,'datepicker','Date création' | trad) }}</td>
                            <td>{{ filterTable('date_SI#point#DTE_PREV',post['filter_date_SI#point#DTE_PREV'],'', '', '', formFilterName,'datepicker','Prévision' | trad) }}</td>
                            <td>{{ filterSelect('STATUT', post.STATUT, listeFiltreStatut, formFilterName, '', '','', true, 'Statut' | trad) }}</td>
                            <td></td>
                        </tr>

                        {% for inventaire in inventaires %}
                            <tr id="sinventa{{ inventaire.NO_INV }}" class="{% if loop.index is divisible by(2) %}even{% else %}odd{% endif %}">
                                <td
                                        class="code montant toggleSlide"
                                        onclick="toggleSlide('{{ path('Stock.Inventaire.ligne', { noInv: inventaire.NO_INV }) }}','inventaire{{ inventaire.NO_INV }}detail', {id : {{ inventaire.NO_INV }}});"
                                >
                                    {{ inventaire.NO_INV }}
                                </td>
                                <td>{{ inventaire.DESIGN | visualise }}</td>
                                <td>{{ inventaire.DTE_CREAT | dateTrad }}</td>
                                <td>{{ inventaire.DTE_PREV | dateTrad | visualise }}</td>
                                <td>
                                    {% if inventaire.DTE_PRET == '00000000' and inventaire.DTE_VAL == '00000000' %}
                                        {{ listeFiltreStatut['C'] }}
                                    {% endif %}

                                    {% if inventaire.DTE_VAL == '00000000' and inventaire.DTE_PRET != '00000000' %}
                                        {{ listeFiltreStatut['A'] }}
                                    {% endif %}

                                    {% if inventaire.DTE_VAL != '00000000' and inventaire.DTE_PRET != '00000000' %}
                                        {{ listeFiltreStatut['V'] }}
                                    {% endif %}
                                </td>
                                <td class="parametrage">
                                    {{ menuContextuel('sinventa' ~ inventaire.NO_INV, false, inventaire.menuContextuel, 10) }}
                                </td>
                            </tr>
                            <tr class="detail_ligne hide_detail" id="inventaire{{ inventaire.NO_INV }}detail"></tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    {{ paginations(
                        path('Stock.Inventaire.gestion'),
                        infoPagination.nombreDePage,
                        infoPagination.page,
                        infoPagination.post,
                        formFilterName
                    ) }}
                </div>
            </form>
            <div class="d-none">
                {% for inventaire in inventaires %}
                    {% if inventaire.UNIQUE_SITE != "" %}
                        <form id="inv{{ inventaire.NO_INV }}" method="POST">
                            <input name="SITE" type="hidden" value="{{ inventaire.UNIQUE_SITE }}">
                        </form>
                    {% endif %}
                {% endfor %}
            </div>
        </div>
    </div>
    <script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/zoomAdvanceReinitialiser.js') }}"></script>
    <script type="text/javascript" src="{{ baseUrl('js/Modules/Stock/resetFormFilters.js') }}"></script>
    <script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/validerEntete.js') }}"></script>
    <script type="text/javascript" src="{{ baseUrl('js/Modules/Stock/multiForm.js') }}"></script>
    <script type="text/javascript" src="{{ baseUrl('js/Modules/Stock/exportDoc.js') }}"></script>
    <script type="text/javascript">
        function executeInventaireAction (action, formAction, noInv, exportPath) {
            const formId = '#inv' + noInv;

            if (action !== 'exporter') {
                const form = $(formId);

                form.attr('action', formAction);
                form.submit();
            } else {
                exportStockDoc(
                    exportPath,
                    formId,
                    '{{ path('Ajax.Erreur.popupInformation') }}',
                    '{{ path('Ajax.Outil.appelAsync') }}',
                    '{{ 'Informations' | trad }}',
                    '{{ 'Votre document est en cours de téléchargement, vous allez recevoir un mail contenant votre document.' | trad }}'
                );
            }
        }
    </script>
{% endblock %}