{% extends 'layout.twig' %}

{% block body %}
    <div class="contenu clearfix"  id="ssitesto">
        <h1>
            {{ 'Gestion des sites' | trad }}

            {% if canCreateSite %}
                <a href="{{ path('Stock.SiteStock.nouveauForm') }}" class="button principal ajout mr-0">
                    {{ 'Nouveau' | trad }}
                </a>
            {% endif %}
        </h1>
        {{ ariane() }}

        {% set formFilterName = "filtres_site_stock"  %}
        <div class="tab-content" id="tab-content">
            <form method="post" name="{{ formFilterName }}" id="{{ formFilterName }}">
                <p></p>
                <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('SELECT', {
                                'titre' : 'Etat' | trad,
                                'name' : 'ETAT',
                                'value' : post.ETAT,
                                'listeValue' : listeFiltreEtat,
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'Société' | trad,
                                'name' : 'filter_egal_STO#point#CODE_STE',
                                'value' : post['filter_egal_STO#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',
                                'inputAttr': {
                                    'data-multifilter': 'form_CODE_STE',
                                    'data-multifilter-twin': 'table_CODE_STE'
                                },
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_STO#point#CODE_STE'
                                },
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ include('@Stock/Composant/ZoomAdvance/_section_imputation.twig', {
                                name: 'filter_egal_STO#point#SI',
                                configAxeImp: configAxeImp,
                                siObligatoire: false,
                                codeSteInputId: 'input_filter_egal_STO#point#CODE_STE',
                                value: post['filter_egal_STO#point#SI'],
                                bulle: 'true',
                                inputAttr: {
                                    'data-multifilter': 'form_SI',
                                    'data-multifilter-twin': 'table_SI'
                                },
                                faceAttr: { 'data-zoomLink': 'input_filter_egal_STO#point#SI' },
                            }) }}
                        </div>
                        {% if is_cg_active() %}
                        <div class="filtre mb-base">
                            {{ inputAdvance('TREEVIEW', {
                                'titre' : 'Code gestion' | trad,
                                'name' : 'filter_egal_STO#point#CODGES',
                                'pathTreeview' : path('Ajax.Treeview.codeGestion'),
                                'paramsTreeview' : "{'CODE_SI': $('#'+CSS.escape('input_filter_egal_STO#point#SI')).val(),  'cg_valide': 'on', 'CODE_STE': $('#'+CSS.escape('input_filter_egal_STO#point#CODE_STE')).val(), 'inputCG' : 'filter_egal_STO#point#CODGES', 'affichageLibelle' : 1 }",
                                'titleTreeview' : 'Code gestion' | trad,
                                'value': post['filter_egal_STO#point#CODGES'],
                                'convertLibelle' : 'cgTrad',
                                'pathValidator' : path('Ajax.validator.codeGestion'),
                                'paramsValidator' : "{'nomChamp' : '"~ ('Code gestion' | trad |e('js')|raw)~"', 'null' : true, 'CODE_SI': $('#'+CSS.escape('input_filter_egal_STO#point#SI')).val() }",
                                '_pathConvert' : path('Ajax.outil.convertLibelle'),
                                'entity' : 'Codgest',
                                'codeBDD' : 'CODE_GES',
                                'libelleBDD' : 'CODE_AFF',
                                'codeSte' : "$('#input_'+CSS.escape('filter_egal_STO#point#CODE_STE')).val()",
                                'siLink': 'input_filter_egal_STO#point#SI',
                                'codeAffCG' : post['text_filter_egal_STO#point#CODGES'],
                                'codeSteCG': post['filter_egal_STO#point#CODE_STE'].form,
                                'sectimpu': post['filter_egal_STO#point#SI'],
                                'myFunction' : 'convertLibelleCodeGestion',
                                'bulle' :  'true',
                                'myParams' : '["'~path('Ajax.outil.convertLibelleCodeGestion')~'", this, "CODE_GES", "CODE_AFF", "input_filter_egal_STO#point#CODGES", "text_filter_egal_STO#point#CODGES", "' ~ post['filter_egal_STO#point#CODGES'] ~ '", "1", "", "input_filter_egal_STO#point#SI", 1, ]',
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_STO#point#CODGES'
                                },
                            }) }}
                        </div>
                        {% endif %}
                        <div class="filtre">
                            {{ include('@Stock/Composant/ZoomAdvance/_code_complementaire.twig', {
                                name: 'filter_egal_STO#point#CDC',
                                configAxeImp: configAxeImp,
                                cdcObligatoire: false,
                                codeSteInputId: 'input_filter_egal_STO#point#CODE_STE',
                                value: post['filter_egal_STO#point#CDC'],
                                bulle: 'true',
                                inputAttr: {
                                    'data-multifilter': 'form_CDC',
                                    'data-multifilter-twin': 'table_CDC'
                                },
                                faceAttr: { 'data-zoomLink': 'input_filter_egal_STO#point#CDC' },
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ include('@Stock/Composant/ZoomAdvance/_sous_compte_analyse.twig', {
                                name: 'filter_egal_STO#point#SCA',
                                configAxeImp: configAxeImp,
                                scaObligatoire: false,
                                codeSteInputId: 'input_filter_egal_STO#point#CODE_STE',
                                value: post['filter_egal_STO#point#SCA'],
                                bulle: 'true',
                                inputAttr: {
                                    'data-multifilter': 'form_SCA',
                                    'data-multifilter-twin': 'table_SCA'
                                },
                                faceAttr: { 'data-zoomLink': 'input_filter_egal_STO#point#SCA' },
                            }) }}
                        </div>
                        <div class="filtreBtn">
                            <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>
                            <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_STO#point#CODE_STE');">
                                {{ 'Vider les champs (sauf société)' | trad }}
                            </button>
                            <button type="button" class="secondaire button button_right" onClick="resetWithSession('{{ formFilterName }}', '{{ sessionFilters }}');">
                                {{ 'Réinitialiser avec la session' | trad }}
                            </button>
                        </div>
                    </div>
                </div>

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

                <div id='refreshTable'>
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th scope="col" width="110px">
                                {{ triTable('SITE',post.tri_SITE,'Code' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('DESIGN',post.tri_DESIGN,'Désignation' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('CODE_STE',post.tri_CODE_STE,'Société' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('SI',post.tri_SI,'Section d\'imputation' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('CDC',post.tri_CDC,'Code complémentaire' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('SCA',post.tri_SCA,'Sous-Compte d\'analyse' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="40px">{{ 'Actions' | trad }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="recherche">
                            <td>
                                {{ filterTable('egal_STO#point#SITE', post['filter_egal_STO#point#SITE'], '', '', '',formFilterName, '','Code' | trad) }}
                            </td>
                            <td>
                                {{ filterTable('STO#point#DESIGN', post['filter_STO#point#DESIGN'], '', '', '',formFilterName, '', 'Désignation' | trad) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_STO#point#CODE_STE',
                                    post['filter_egal_STO#point#CODE_STE'],
                                    '', '', '',formFilterName, '',
                                    'Société' | trad, false, false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_CODE_STE',
                                        'data-multifilter-twin': 'form_CODE_STE'
                                    }
                                ) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_STO#point#SI',
                                    post['filter_egal_STO#point#SI'],
                                    '', '', '', formFilterName,'',
                                    'Section d\'imputation' | trad, false, false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_SI',
                                        'data-multifilter-twin': 'form_SI'
                                    }
                                ) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_STO#point#CDC',
                                    post['filter_egal_STO#point#CDC'],
                                    '', '', '', formFilterName,'',
                                    'Code complémentaire' | trad, false, false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_CDC',
                                        'data-multifilter-twin': 'form_CDC'
                                    }
                                ) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_STO#point#SCA',
                                    post['filter_egal_STO#point#SCA'],
                                    '', '', '', formFilterName,'',
                                    'Sous-Compte d\'analyse' | trad, false, false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_SCA',
                                        'data-multifilter-twin': 'form_SCA'
                                    }
                                ) }}
                            </td>
                            <td></td>
                        </tr>

                        {% for siteStock in sitesStock %}
                            <tr id="ssitesto{{ siteStock.SITE }}" class="{% if loop.index is divisible by(2) %}even{% else %}odd{% endif %}">
                                <td
                                        class="code toggleSlide"
                                        onclick="toggleSlide('{{ path('Stock.SiteStock.ligne', { site: siteStock.SITE, codeSte: siteStock.CODE_STE }) }}','siteStock{{ siteStock.SITE }}{{ siteStock.CODE_STE }}detail', {id : '{{ siteStock.SITE }}{{ siteStock.CODE_STE }}'});"
                                >
                                    {{ siteStock.SITE }}
                                </td>
                                <td>{{ siteStock.DESIGN }}</td>
                                <td>{{ siteStock.CODE_STE }}</td>
                                <td>{{ (siteStock.SI_LIBELLE ~ ' (' ~ siteStock.SI ~ ')')|visualise }}</td>
                                <td>{{ (siteStock.CDC_LIBELLE ~ ' (' ~ siteStock.CDC ~ ')')|visualise }}</td>
                                <td>{{ (siteStock.SCA_LIBELLE ~ ' (' ~ siteStock.SCA ~ ')')|visualise }}</td>
                                <td class="parametrage">
                                    {{ menuContextuel('ssitesto' ~ siteStock.SITE, false, siteStock.menuContextuel, 10) }}
                                </td>
                            </tr>
                            <tr class="detail_ligne hide_detail" id="siteStock{{ siteStock.SITE }}{{ siteStock.CODE_STE }}detail"></tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    {{ paginations(
                        path('Stock.SiteStock.gestion'),
                        infoPagination.nombreDePage,
                        infoPagination.page,
                        infoPagination.post,
                        formFilterName
                    ) }}
                </div>
            </form>
        </div>
        <form name="sstocklos" id="sstocklos" action="{{ path('Stock.StockLocal.gestion') }}" class="d-none" method="POST">
            <input type="hidden" name="niveau" value="1">
            <input type="hidden" name="filter_egal_STO#point#SITE" value="" id="sstocklos_filter_egal_STO#point#SITE">
            <input type="hidden" name="filter_egal_SI#point#CODE_STE" value="" id="sstocklos_filter_egal_SI#point#CODE_STE">
            <input type="hidden" name="ariane_title" value="Stock local">
        </form>
    </div>
    <script type="text/javascript" src="{{ baseUrl('js/Modules/Stock/multiForm.js') }}"></script>
    <script type="text/javascript" src="{{ baseUrl('js/Modules/Stock/resetFormFilters.js') }}"></script>
    <script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/zoomAdvanceReinitialiser.js') }}"></script>
    <script type="application/javascript">
        function voirStockLocal (site, codeSte) {
            $('#' + CSS.escape('sstocklos_filter_egal_STO#point#SITE')).val(site);
            $('#' + CSS.escape('sstocklos_filter_egal_SI#point#CODE_STE')).val(codeSte);
            $('#sstocklos').submit();
        }
    </script>
{% endblock %}