{% extends 'layout.twig' %}

{% block body %}
    <div class="contenu clearfix"  id="articles">
        <h1>{{ 'Articles' | trad }}</h1>

        {{ ariane() }}

        {% set formFilterName = "filtres_sites"  %}
        <div class="tab-content" id="tab-content">
            <form method="post" name="{{ formFilterName }}" id="{{ formFilterName }}">
                <h3 class="mb-base">
                    {{ strBuild('Liste des sites de stock de l\'article N° @1@ - @2@' | trad, [codeArt, design]) }}
                    {{ Button(
                        'Ajouter à un site' | trad,
                        true,
                        '',
                        'ajaxPopup(\''~ path('Stock.StockArticle.popupAjoutStockLocal', { codeArt: codeArt }) ~'\', \'' ~ strBuild('Ajout article N°@1@ à un site - @2@' | trad, [codeArt, design]) ~ '\', \'\', \'\', \'\', \'modal_export \')', '',
                        true,
                        'ajout mr-0'
                    ) }}
                </h3>
                <div class="tab-content">
                    <div class="tab-pane active in clearfix">
                        <div id='refreshTable'>
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th scope="col" width="90px">
                                        {{ triTable('SITE', post.tri_SITE, 'Site' | trad, '', '', formFilterName) }}
                                    </th>
                                    <th scope="col" width="600px">
                                        {{ triTable('SITE_DESIGN', post.tri_SITE_DESIGN, 'Désignation' | trad, '', '', formFilterName) }}
                                    </th>
                                    <th scope="col" width="600px">
                                        {{ triTable('CODE_STE', post.tri_CODE_STE, 'Société' | trad, '', '', formFilterName) }}
                                    </th>
                                    <th scope="col" width="600px">
                                        {{ triTable('QTE_PHYS', post.tri_QTE_PHYS, 'Quantité disponible' | trad, '', '', formFilterName) }}
                                    </th>
                                    <th scope="col" width="600px">
                                        {{ triTable('QTE_INDIS', post.tri_QTE_INDIS, 'Quantité indisponible' | trad, '', '', formFilterName) }}
                                    </th>
                                    <th scope="col" width="600px">
                                        {{ triTable('UNITE_STK', post.tri_UNITE_STK, 'Unité stockée' | trad, '', '', formFilterName) }}
                                    </th>
                                    <th scope="col" width="20px">{{ 'Visualiser' | trad }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for stockLocal in stockLocaux %}
                                    <tr class="{% if loop.index is divisible by(2) %}even{% else %}odd{% endif %}">
                                        <td>{{ stockLocal.SITE }}</td>
                                        <td>{{ stockLocal.SITE_DESIGN }}</td>
                                        <td>{{ stockLocal.RAIS_SOC ~ ' (' ~ stockLocal.CODE_STE ~ ')' }}</td>
                                        <td class="text-right">{{ stockLocal.QTE_DISPO | qte }}</td>
                                        <td class="text-right">{{ stockLocal.QTE_INDIS | qte }}</td>
                                        <td>{{ stockLocal.UNITE_STK }}</td>
                                        <td class="parametrage">
                                            <span class="visualiser_v2" onclick="voirStockLocal('{{ path('Stock.StockLocal.visualiser', { codeArt: stockLocal.CODE_ART, site: stockLocal.SITE }) }}')"></span>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                            {{ paginations(
                                path('Stock.StockArticle.stockArticleParSite', { codeArt: codeArt }),
                                infoPagination.nombreDePage,
                                infoPagination.page,
                                infoPagination.post
                            ) }}
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <form method="post" class="d-none" id="voirStockLocal">
        <input type="hidden" name="ariane" value="2">
    </form>
    <script type="application/javascript">
        function voirStockLocal (path) {
            const voirStockLocalForm = $('#voirStockLocal');

            voirStockLocalForm.prop('action', path);
            voirStockLocalForm.submit();
        }
    </script>
{% endblock %}