{% extends 'layout.twig' %}

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

        {{ ariane() }}

        {% set formFilterName = "filtres_bon_sortie"  %}
        <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_SE#point#MAG',
                                'value' : post['filter_egal_SE#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',
                                'inputAttr': {
                                    'data-multifilter': 'form_MAG',
                                    'data-multifilter-twin': 'table_MAG'
                                },
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_SE#point#MAG'
                                },
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'Société' | trad,
                                'name' : 'filter_egal_SE#point#CODE_STE',
                                'value' : post['filter_egal_SE#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_SE#point#CODE_STE'
                                },
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ include('@Stock/Composant/ZoomAdvance/_section_imputation.twig', {
                                name: 'filter_egal_SL#point#SECTIMP',
                                configAxeImp: configAxeImp,
                                siObligatoire: false,
                                codeSteInputId: 'input_filter_egal_SE#point#CODE_STE',
                                value: post['filter_egal_SL#point#SECTIMP'],
                                bulle: 'true',
                                faceAttr: { 'data-zoomLink': 'input_filter_egal_SL#point#SECTIMP' },
                            }) }}
                        </div>
                        {% if is_cg_active() %}
                        <div class="filtre">
                            {{ inputAdvance('TREEVIEW', {
                                'titre' : 'Code gestion' | trad,
                                'name' : 'filter_egal_SL#point#CODGES',
                                'pathTreeview' : path('Ajax.Treeview.codeGestion'),
                                'paramsTreeview' : "{'CODE_SI': $('#'+CSS.escape('input_filter_egal_SL#point#SECTIMP')).val(), 'cg_valide': 'on', 'CODE_STE': $('#'+CSS.escape('input_filter_egal_SE#point#CODE_STE[form]')).val(), 'inputCG' : 'filter_egal_SL#point#CODGES', 'affichageLibelle' : 1 }",
                                'titleTreeview' : 'Code gestion' | trad,
                                'value': post['filter_egal_SL#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_SL#point#SECTIMP')).val() }",
                                '_pathConvert' : path('Ajax.outil.convertLibelle'),
                                'entity' : 'Codgest',
                                'codeBDD' : 'CODE_GES',
                                'libelleBDD' : 'CODE_AFF',
                                'codeSte' : "$('#input_'+CSS.escape('filter_egal_SE#point#CODE_STE[form]')).val()",
                                'siLink': 'input_filter_egal_SL#point#SECTIMP',
                                'codeAffCG' : post['text_filter_egal_SL#point#CODGES'],
                                'codeSteCG': post['filter_egal_SE#point#CODE_STE'].form,
                                'sectimpu': post['filter_egal_SL#point#SECTIMP'],
                                'myFunction' : 'convertLibelleCodeGestion',
                                'bulle' :  'true',
                                'myParams' : '["'~path('Ajax.outil.convertLibelleCodeGestion')~'", this, "CODE_GES", "CODE_AFF", "input_filter_egal_SL#point#CODGES", "text_filter_egal_SL#point#CODGES", "' ~ post['filter_egal_SL#point#CODGES'] ~ '", "1", "", "input_filter_egal_SL#point#SECTIMP", 1, ]',
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_SL#point#CODGES'
                                },
                            }) }}
                        </div>
                        {% endif %}
                        <div class="filtre">
                            {{ include('@Stock/Composant/ZoomAdvance/_code_complementaire.twig', {
                                name: 'filter_egal_SL#point#CODE_COMP',
                                configAxeImp: configAxeImp,
                                cdcObligatoire: false,
                                codeSteInputId: 'input_filter_egal_SE#point#CODE_STE',
                                value: post['filter_egal_SL#point#CODE_COMP'],
                                bulle: 'true',
                                faceAttr: { 'data-zoomLink': 'input_filter_egal_SL#point#CODE_COMP' }
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ include('@Stock/Composant/ZoomAdvance/_sous_compte_analyse.twig', {
                                name: 'filter_egal_SL#point#SSCPTEANA',
                                configAxeImp: configAxeImp,
                                scaObligatoire: false,
                                codeSteInputId: 'input_filter_egal_SE#point#CODE_STE',
                                value: post['filter_egal_SL#point#SSCPTEANA'],
                                bulle: 'true',
                                faceAttr: { 'data-zoomLink': 'input_filter_egal_SL#point#SSCPTEANA' },
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('SELECT', {
                                'titre' : 'Etat' | trad,
                                'name' : 'ETAT',
                                'value' : post.ETAT,
                                'listeValue' : listeFiltreEtat,
                                'bulle' :  'true',
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'N° de DS' | trad,
                                'name' : 'filter_egal_SL#point#NO_DS',
                                'value' : post['filter_egal_SL#point#NO_DS'],
                                'pahtZoom' : path('Ajax.liste.demandesServices'),
                                'paramZoom' : "{'filter_SE#point#SOLDE_DS': 'E' }",
                                'entity' : 'DemandeService',
                                'titleZoom' : 'Liste des demandes de service à satisfaire' | trad,
                                'pathConvert' : path('Ajax.outil.convertLibelle'),
                                'convertLibelle' : '',
                                'bulle' :  'true',
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_SL#point#NO_DS'
                                }
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('TEXT', {
                                'titre' : 'Mots Clés' | trad,
                                'name' : 'MOTCLE',
                                'value' : post.MOTCLE,
                                'bulle' :  'true',
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('SWITCH', {
                                'titre' : 'Tous les mots ?' | trad,
                                'name' : 'TOUS_LES_MOTS',
                                'value' : post.TOUS_LES_MOTS,
                            }) }}
                        </div>
                        <div class="filtre">
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'Site' | trad,
                                'name' : 'filter_egal_SE#point#SITE',
                                'value' : post['filter_egal_SE#point#SITE'],
                                'pahtZoom' : path('Ajax.liste.siteStockAccessible'),
                                'paramZoom' : "{'opened_only': true }",
                                'entity' : 'SSiteSto',
                                'titleZoom' : 'Liste des sites de stockage' | trad,
                                'pathConvert' : path('Ajax.outil.convertLibelle'),
                                'convertLibelle' : 'convertLibelleGlobal',
                                'bulle' :  'true',
                                'inputAttr': {
                                    'data-multifilter': 'form_SITE',
                                    'data-multifilter-twin': 'table_SITE'
                                },
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_SE#point#SITE'
                                }
                            }) }}
                        </div>
                        <div class="filtre mb-base">
                            {% set exclude_empty_code = is_blanc_interdit_tiers() ? 'true': 'false' %}
                            {{ inputAdvance('ZOOMADVANCE', {
                                'titre': 'Destinataire' | trad,
                                'name' : 'filter_egal_SE#point#DEST',
                                'value' : post['filter_egal_SE#point#DEST'],
                                'pahtZoom' : path('Ajax.liste.tiers'),
                                'paramZoom': "{'exclude_empty_code': " ~ exclude_empty_code ~ "}",
                                'entity' : 'SSiteSto',
                                'titleZoom' : 'Liste des sites de stockage' | trad,
                                'pathConvert' : path('Ajax.outil.convertLibelle'),
                                'convertLibelle' : 'convertLibelleGlobal',
                                'bulle' :  'true',
                                'faceAttr': {
                                    'data-zoomLink': 'input_filter_egal_SE#point#DEST'
                                },
                            }) }}
                            {{ 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>
                        <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_SE#point#CODE_STE');">
                            {{ 'Vider les champs (sauf société)' | trad }}
                        </button>
                    </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 class="thead-dark" >
                        <tr>
                            <th scope="col" width="70px">
                                {{ triTable('NO_BS',post.tri_NO_BS,'N° BS' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="100px">
                                {{ triTable('CODE_STE',post.tri_CODE_STE,'Code société' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="100px">
                                {{ triTable('DTE_CREAT',post.tri_DTE_CREAT,'Date création' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="100px">
                                {{ triTable('DTE_VALID',post.tri_DTE_VALID,'Date validation' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="250px">
                                {{ triTable('MAG',post.tri_MAG,'Magasinier' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="250px">
                                {{ triTable('SITE',post.tri_SITE,'Site' | trad, '', '', formFilterName) }}
                            </th>
                            {% if is_prix_visible() %}
                                <th scope="col" width="100px">
                                    {{ triTable('TOT_BS',post.tri_TOT_BS,'Total' | trad, '', '', formFilterName) }}
                                </th>
                            {% endif %}
                            <th scope="col" width="40px">{{ 'Actions' | trad }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="recherche">
                            <td>
                                {{ filterTable('egal_SE#point#NO_BS',post['filter_egal_SE#point#NO_BS'],'', '', '',formFilterName, '','N° BS' | trad) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_SE#point#CODE_STE',
                                    post['filter_egal_SE#point#CODE_STE'],
                                    '', '', '',formFilterName, '',
                                    'Code société' | trad, '', false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_CODE_STE',
                                        'data-multifilter-twin': 'form_CODE_STE'
                                    }
                                ) }}
                            </td>
                            <td>
                                {{ filterTable('date_SE#point#DTE_CREAT',post['filter_date_SE#point#DTE_CREAT'],'', '', '', formFilterName,'datepicker','Date création' | trad) }}
                            </td>
                            <td>
                                {{ filterTable('date_SE#point#DTE_VALID',post['filter_date_SE#point#DTE_VALID'],'', '', '', formFilterName,'datepicker','Date de validation' | trad) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_SE#point#MAG',
                                    post['filter_egal_SE#point#MAG'],
                                    '', '', '',formFilterName, '',
                                    'Magasinier' | trad, '', false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_MAG',
                                        'data-multifilter-twin': 'form_MAG'
                                    }
                                ) }}
                            </td>
                            <td>
                                {{ filterTable(
                                    'egal_SE#point#SITE',
                                    post['filter_egal_SE#point#SITE'],
                                    '', '', '',formFilterName, '',
                                    'Site' | trad, '', false, 'readonly', null, null, null,
                                    {
                                        'data-multifilter': 'table_SITE',
                                        'data-multifilter-twin': 'form_SITE'
                                    }
                                ) }}
                            </td>
                            {% if is_prix_visible() %}
                                <td>
                                    {{ filterTable('montant_SE#point#TOT_BS',post['filter_montant_SE#point#TOT_BS'],'', '', '',formFilterName, '','Total' | trad) }}
                                </td>
                            {% endif %}
                            <td></td>
                        </tr>

                        {% for bonSortie in bonsSortie %}
                            <tr id="sbsEnte{{ bonSortie.NO_BS }}" class="{% if loop.index is divisible by(2) %}even{% else %}odd{% endif %}">
                                <td
                                        class="code montant toggleSlide"
                                        onclick="toggleSlide('{{ path('Stock.BonSortie.ligne', { noBs: bonSortie.NO_BS }) }}','bonSortie{{ bonSortie.NO_BS }}detail', {id : {{ bonSortie.NO_BS }}});"
                                >
                                    {{ bonSortie.NO_BS }}
                                </td>
                                <td>{{ bonSortie.CODE_STE }}</td>
                                <td>{{ bonSortie.DTE_CREAT | dateTrad }}</td>
                                <td>{{ bonSortie.DTE_VALID | dateTrad | visualise }}</td>
                                <td>{{ (bonSortie.MAG_LIBELLE ~ ' (' ~ bonSortie.MAG ~ ')')|visualise }}</td>
                                <td>{{ (bonSortie.SITE_DESIGN ~ ' (' ~ bonSortie.SITE~ ')')|visualise }}</td>
                                {% if is_prix_visible() %}
                                    <td class="text-right">
                                        {% if bonSortie.DTE_VALID != '00000000' %}
                                            {{ bonSortie.TOT_BS | prix ~ ' ' ~ bonSortie.DEVISE }}
                                        {% else %}
                                            {{ 'BS non validé' | trad }}
                                        {% endif %}
                                    </td>
                                {% endif %}
                                <td class="parametrage">
                                    {% if bonSortie.NB_DOC > 0 %}
                                        {{ include('@Stock/Composant/Bouton/_doc_att_button.twig', { module: 'BonSortie', id: bonSortie.NO_BS, enteLabel: 'bon de sortie' }) }}
                                    {% endif %}
                                    {{ menuContextuel('sbsEnte' ~ bonSortie.NO_BS,false, bonSortie.menuContextuel,10) }}
                                </td>
                            </tr>
                            <tr class="detail_ligne hide_detail" id="bonSortie{{ bonSortie.NO_BS }}detail"></tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    {{ paginations(
                        path('Stock.BonSortie.gestion'),
                        infoPagination.nombreDePage,
                        infoPagination.page,
                        infoPagination.post,
                        formFilterName
                    ) }}
                </div>
            </form>
        </div>
    </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/validerEntete.js') }}"></script>
    <script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/zoomAdvanceReinitialiser.js') }}"></script>
{% endblock %}