{% extends 'layout.twig' %}

{% block body %}
    <div class="contenu clearfix"  id="smouveme">
        <h1>
            {{ 'Visualisation des mouvements' | trad }}
            {{ Button(
                'Export' | trad,
                false,
                '',
                'ajaxPopup(\'' ~ path('Stock.Mouvement.popupExport') ~ '\', \'' ~ 'Export Mouvements' | trad ~ '\', \'\', \'\', \'\', \'modal_export \')',
                [],
                true,
                'mr-0'
            ) }}
        </h1>

        {{ ariane() }}

        {% set formFilterName = "filtres_mouvement"  %}
        <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">
                            <div class="row">
                                {{ inputAdvance('ZOOMADVANCE', {
                                    'titre': 'Société' | trad,
                                    'name' : 'filter_egal_SM#point#CODE_STE',
                                    'value' : post['filter_egal_SM#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_SM#point#CODE_STE'
                                    },
                                }) }}
                            </div>
                        </div>
                        <div class="filtre">
                            <div class="row">
                                {{ inputAdvance('ZOOMADVANCE', {
                                    'titre': 'Sous-famille' | trad,
                                    'name' : 'filter_egal_SM#point#SSFAM',
                                    'value' : post['filter_egal_SM#point#SSFAM'],
                                    'pahtZoom' : path('Ajax.liste.sousFamilles'),
                                    'entity' : 'SousFamille',
                                    'titleZoom' : 'Liste des sous-familles' | trad,
                                    'pathConvert' : path('Ajax.outil.convertLibelle'),
                                    'convertLibelle' : 'convertLibelleGlobal',
                                    'codeBDD': 'CODE_SFA',
                                    'libelleBDD': 'DESIGNAT',
                                    'widthPopup': 'modal_large',
                                    'bulle' :  'true',
                                    'faceAttr': {
                                        'data-zoomLink': 'input_filter_egal_SM#point#SSFAM'
                                    },
                                }) }}
                            </div>
                        </div>
                        <div class="filtre">
                            <div class="row">
                                {{ include('@Stock/Composant/ZoomAdvance/_section_imputation.twig', {
                                    name: 'filter_egal_SM#point#SECTIMP',
                                    configAxeImp: configAxeImp,
                                    siObligatoire: false,
                                    codeSteInputId: 'input_filter_egal_SM#point#CODE_STE',
                                    value: post['filter_egal_SM#point#SECTIMP'],
                                    bulle: 'true',
                                    faceAttr: { 'data-zoomLink': 'input_filter_egal_SM#point#SECTIMP' },
                                }) }}
                            </div>
                        </div>
                        <div class="filtre">
                            {% if is_cg_active() %}
                            <div class="row">
                                {{ inputAdvance('TREEVIEW', {
                                    'titre' : 'Code gestion' | trad,
                                    'name' : 'filter_egal_SM#point#CODGES',
                                    'pathTreeview' : path('Ajax.Treeview.codeGestion'),
                                    'paramsTreeview' : "{'CODE_SI': $('#'+CSS.escape('input_filter_egal_SM#point#SECTIMP')).val(), 'cg_valide': 'on', 'CODE_STE': $('#'+CSS.escape('input_filter_egal_SM#point#CODE_STE')).val(), 'inputCG' : 'filter_egal_SM#point#CODGES', 'affichageLibelle' : 1 }",
                                    'titleTreeview' : 'Code gestion' | trad,
                                    'value': post['filter_egal_SM#point#CODGES'],
                                    'convertLibelle' : 'cgTrad',
                                    '_pathConvert' : path('Ajax.outil.convertLibelle'),
                                    'entity' : 'Codgest',
                                    'codeBDD' : 'CODGES',
                                    'libelleBDD' : 'CODE_AFF',
                                    'codeSte' : "$('#input'+CSS.escape('filter_egal_SM#point#CODE_STE')).val()",
                                    'siLink': 'input_filter_egal_SM#point#SECTIMP',
                                    'codeAffCG' : post['text_filter_egal_SM#point#CODGES'],
                                    'codeSteCG': post['filter_egal_SM#point#CODE_STE'].form,
                                    'sectimpu': post['filter_egal_SM#point#SECTIMP'],
                                    'myFunction' : 'convertLibelleCodeGestion',
                                    'bulle' :  'true',
                                    'myParams' : '["'~path('Ajax.outil.convertLibelleCodeGestion')~'", this, "CODGES", "CODE_AFF", "input_filter_egal_SM#point#CODGES", "text_filter_egal_SM#point#CODGES", "' ~ post['filter_egal_SM#point#CODGES'] ~ '", "1", "", "input_filter_egal_SM#point#SECTIMP", 1, ]',
                                    'faceAttr': {
                                        'data-zoomLink': 'input_filter_egal_SM#point#CODGES'
                                    },
                                }) }}
                            </div>
                            {% endif %}
                        </div>
                        <div class="filtre">
                            <div class="row">
                                {{ include('@Stock/Composant/ZoomAdvance/_code_complementaire.twig', {
                                    name: 'filter_egal_SM#point#CODE_COMP',
                                    configAxeImp: configAxeImp,
                                    cdcObligatoire: false,
                                    codeSteInputId: 'input_filter_egal_SM#point#CODE_STE',
                                    value: post['filter_egal_SM#point#CODE_COMP'],
                                    bulle: 'true',
                                    faceAttr: { 'data-zoomLink': 'input_filter_egal_SM#point#CODE_COMP' },
                                }) }}
                            </div>
                        </div>
                        <div class="filtre mb-base">
                            <div class="row">
                                {{ include('@Stock/Composant/ZoomAdvance/_sous_compte_analyse.twig', {
                                    name: 'filter_egal_SM#point#SSCPTEANA',
                                    configAxeImp: configAxeImp,
                                    scaObligatoire: false,
                                    codeSteInputId: 'input_filter_egal_SM#point#CODE_STE',
                                    value: post['filter_egal_SM#point#SSCPTEANA'],
                                    bulle: 'true',
                                    faceAttr: { 'data-zoomLink': 'input_filter_egal_SM#point#SSCPTEANA' },
                                }) }}
                            </div>
                        </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_SM#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="100px">
                                {{ triTable('DTE_MVT', post.tri_DTE_MVT,'Date de mouvement' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="70px">
                                {{ triTable('NO_MVT', post.tri_NO_MVT, 'N° Mouvement' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('TYPE_MVT', post.tri_TYPE_MVT, 'Type de mouvement' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('CODE_ART', post.tri_CODE_ART, 'Code article' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="300px">
                                {{ triTable('DESIGN', post.tri_DESIGN, 'Désignation' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="150px">
                                {{ triTable('QTE_MVT', post.tri_QTE_MVT, 'Quantité mouvementée' | trad, '', '', formFilterName) }}
                            </th>
                            {% if is_prix_visible() %}
                                <th scope="col" width="150px">
                                    {{ triTable('VAL_UNIT', post.tri_VAL_UNIT, 'Prix unitaire' | trad, '', '', formFilterName) }}
                                </th>
                            {% endif %}
                            <th scope="col" width="100px">
                                {{ triTable('CODE_STE', post.tri_CODE_STE, 'Code société' | trad, '', '', formFilterName) }}
                            </th>
                            <th scope="col" width="250px">
                                {{ triTable('SITE', post.tri_SITE, 'Site du mouvement' | trad, '', '', formFilterName) }}
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="recherche">
                            <td>
                                {{ filterTable('date_SM#point#DTE_MVT', post['filter_date_SM#point#DTE_MVT'], '', '', '',formFilterName, 'datepicker', 'Date de mouvement' | trad) }}
                            </td>
                            <td>
                                {{ filterTable('egal_SM#point#NO_MVT', post['filter_egal_SM#point#NO_MVT'], '', '', '',formFilterName, '', 'N° de mouvement' | trad) }}
                            </td>
                            <td>
                                {{ filterSelect(
                                    'egal_SM#point#TYPE_MVT',
                                    post['filter_egal_SM#point#TYPE_MVT'],
                                    listeChoixTypesMvt,
                                    formFilterName, '', '', '', '', 'Type' | trad, false, {}, false
                                ) }}
                            </td>
                            <td>
                                {{ zoomFilter("egal_SM#point#CODE_ART", post['filter_egal_SM#point#CODE_ART'], "", formFilterName, path('Ajax.liste.stockArticles'), 'Article tiers' | trad, '','','','','','Article tiers') }}
                            </td>
                            <td>
                                {{ filterTable('SM#point#DESIGN',post['filter_SM#point#DESIGN'],'', '', '',formFilterName, '','Désignation' | trad) }}
                            </td>
                            <td>
                                {{ filterTable('egal_SM#point#QTE_MVT',post['filter_egal_SM#point#QTE_MVT'],'', '', '',formFilterName, '','Quantité' | trad) }}
                            </td>
                            {% if is_prix_visible() %}
                                <td>
                                    {{ filterTable('egal_SM#point#VAL_UNIT', post['filter_egal_SM#point#VAL_UNIT'], '', '', '',formFilterName, '', 'Valeur unitaire' | trad) }}
                                </td>
                            {% endif %}
                            <td>
                                {{ filterTable(
                                    'egal_SM#point#CODE_STE',
                                    post['filter_egal_SM#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>
                                {{ zoomFilter("egal_SM#point#SITE", post['filter_egal_SM#point#SITE'], "", formFilterName, path('Ajax.liste.siteStockAccessible'), 'Code site' | trad, '','','','','','Code site', '', '', '', "{'hasOpenedOnlyFilter': true}") }}
                            </td>
                        </tr>

                        {% for mouvement in mouvements %}
                            <tr id="smouveme{{ mouvement.NO_MVT }}" class="{% if loop.index is divisible by(2) %}even{% else %}odd{% endif %}">
                                <td
                                        class="code toggleSlide"
                                        onclick="toggleSlide('{{ path('Stock.Mouvement.ligne', { noMvt: mouvement.NO_MVT }) }}','smouveme{{ mouvement.NO_MVT }}detail', {id : {{ mouvement.NO_MVT }}});"
                                >
                                    {{ mouvement.DTE_MVT | dateTrad }}
                                </td>
                                <td class="text-right">{{ mouvement.NO_MVT }}</td>
                                <td>{{ listeChoixTypesMvt[mouvement.TYPE_MVT] }}</td>
                                <td>{{ mouvement.CODE_ART }}</td>
                                <td>{{ mouvement.DESIGN }}</td>
                                <td class="text-right">{{ mouvement.QTE_MVT | qte ~ ' ' ~ mouvement.UNITE_STK }}</td>
                                {% if is_prix_visible() %}
                                    <td class="text-right">
                                        {{ mouvement.VAL_UNIT | prixUnitaire ~ ' ' ~ mouvement.DEVISE }}
                                    </td>
                                {% endif %}
                                <td>{{ mouvement.CODE_STE }}</td>
                                <td>{{ (mouvement.STO_DESIGN ~ ' (' ~ mouvement.SITE ~ ')')|visualise }}</td>
                            </tr>
                            <tr class="detail_ligne hide_detail" id="smouveme{{ mouvement.NO_MVT }}detail"></tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    {{ paginations(
                        path('Stock.Mouvement.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/zoomAdvanceReinitialiser.js') }}"></script>
{% endblock %}