
{% extends '@ajax-layout/layout.twig' %}

{% block body %}
    <div id="genetableau">
        <center>
            <div>
                {% set formName = 'formulaireListeSlotloc' %}
                <form method="POST" id='{{ formName }}' name="{{ formName }}">
                    <input type="hidden" name="divCode" value="{{ post.divCode }}" />
                    <input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
                    <input type="hidden" name="filter_egal_SL#point#CODE_ART" value="{{ post['filter_egal_SL#point#CODE_ART'] }}" />
                    <input type="hidden" name="filter_egal_SL#point#SITE" value="{{ post['filter_egal_SL#point#SITE'] }}" />
                    <input type="hidden" name="slotinvr" value="{{ post.slotinvr }}" />
                    <input type="hidden" name="site" value="{{ post.site }}" />
                    <input type="hidden" name="noInv" value="{{ post.noInv }}" />
                    <input type="hidden" name="divDtePerem" value="{{ post.divDtePerem }}" />
                    <input type="hidden" name="divPrix" value="{{ post.divPrix }}" />
                    <input type="hidden" name="QTE_LOC_GT_0" value="{{ post['QTE_LOC_GT_0'] }}" />
                    <table class="table" id="tableau">
                        <thead class="thead-dark">
                        <tr>
                            <th>{{ triTable('NO_LOT',  post.tri_NO_LOT, 'N° Lot' | trad, 'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ triTable('QTE_LOC',  post.tri_QTE_LOC, 'Quantité locale' | trad,'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ triTable('QTE_INDIS',  post.tri_QTE_INDIS, 'Quantité indisponible' | trad,'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ triTable('QTE_TRF',  post.tri_QTE_TRF, 'Quantité transférée' | trad,'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ triTable('DTE_PEREM',  post.tri_DTE_PEREM, 'Date de péremption' | trad,'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th>{{ filterTable('egal_SL#point#NO_LOT', post['filter_egal_SL#point#NO_LOT'], '', 'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ filterTable('egal_SL#point#QTE_LOC', post['filter_egal_SL#point#QTE_LOC'], '', 'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ filterTable('egal_SL#point#QTE_INDIS', post['filter_egal_SL#point#QTE_INDIS'], '', 'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ filterTable('egal_SL#point#QTE_TRF', post['filter_egal_SL#point#QTE_TRF'], '', 'genetableau', path('Ajax.liste.stockLotLocal'), formName) }}</th>
                            <th>{{ filterTable('date_SG#point#DTE_PEREM', post['filter_date_SG#point#DTE_PEREM'], '', 'genetableau', path('Ajax.liste.stockLotLocal'), formName, 'datepicker') }}</th>
                        </tr>
                        {% for lotLocal in stockLotsLocaux %}
                            <tr onclick="{{ attrJs('changeValue', [post.divCode, post.divLibelle, lotLocal.NO_LOT, lotLocal.DTE_PEREM, lotLocal.PRIX]) }}">
                                <td>{{ lotLocal.NO_LOT  }}</td>
                                <td class="text-right">{{ lotLocal.QTE_LOC | qte ~ ' ' ~ lotLocal.UNITE_STK }}</td>
                                <td class="text-right">{{ lotLocal.QTE_INDIS | qte ~ ' ' ~ lotLocal.UNITE_STK }}</td>
                                <td class="text-right">{{ lotLocal.QTE_TRF | qte ~ ' ' ~ lotLocal.UNITE_STK }}</td>
                                <td>{{ lotLocal.DTE_PEREM | dateTrad  }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </form>
                {{ paginations(path('Ajax.liste.stockLotLocal'), infoPagination.nombreDePage, infoPagination.page, infoPagination.post, 'modal-body') }}
            </div>
        </center>
        <script>
            function changeValue (divCode, divLibelle, noLot, dtePerem, prix) {
                const input = $('#' + CSS.escape(divLibelle));
                const hiddenInput = $('#' + CSS.escape(divCode));

                input.val(noLot);
                input.trigger('change');
                hiddenInput.val(noLot);

                if ('{{ post.divDtePerem }}') {
                    const divDtePerem = $('#' + CSS.escape('{{ post.divDtePerem }}'));

                    divDtePerem.val(dtePerem);
                    divDtePerem.addClass('white-tooltip');
                    divDtePerem.attr('data-original-title', '{{ 'Valeur d\'origine' | trad }} : ' + dtePerem);
                }

                if ('{{ post.divPrix }}') {
                    $('#' + CSS.escape('{{ post.divPrix }}')).val(prix);
                }

                desactivePopup();
            }
        </script>
    </div>

{% endblock %}