{% set path = path(path ?? 'Ajax.liste.demandeAchat') %}

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

{% block body %}
    <div id="genetableau">
        <center>
            <div>
                <form method="POST" id='formDemandeAchat'>
                    <input type="hidden" name="divCode" value="{{ post.divCode }}" />
                    <input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
                    <table class="table" id="tableau">
                        <thead class="thead-dark">
                        <tr>
                            <th>
                                {{ triTable(
                                    'NO_DA',
                                    infoPagination.filter.tri_NO_DA,
                                    'DA N°' | trad,
                                    'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ triTable(
                                    'NO_DEM',
                                    infoPagination.filter.tri_NO_DEM,
                                    'Demandeur' | trad,
                                    'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ triTable(
                                    'CODE_STE',
                                    infoPagination.filter.tri_CODE_STE,
                                    'Société' | trad,
                                    'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ triTable(
                                    'DTE_VAL',
                                    infoPagination.filter.tri_DTE_VAL,
                                    'Date de validation' | trad,
                                    'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ triTable(
                                    'CTR_LIV',
                                    infoPagination.filter.tri_CTR_LIV,
                                    'Centre de livraison' | trad,
                                    'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ triTable(
                                    'STATUT',
                                    infoPagination.filter.tri_STATUT,
                                    'Statut' | trad,
                                    'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th>
                                {{ filterTable(
                                    'egal_NO_DA',
                                    infoPagination.filter.filter_egal_NO_DA,
                                    '', 'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ filterTable(
                                    'NO_DEM',
                                    infoPagination.filter.filter_NO_DEM, '', 'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ filterTable(
                                    'CODE_STE',
                                    infoPagination.filter.filter_CODE_STE, '', 'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ filterTable(
                                    'date_DTE_VAL',
                                    infoPagination.filter.filter_date_DTE_VAL, '', 'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ filterTable(
                                    'CTR_LIV',
                                    infoPagination.filter.filter_CTR_LIV, '', 'genetableau',
                                    path,
                                    'formDemandeAchat'
                                ) }}
                            </th>
                            <th>
                                {{ filterSelect(
                                    'STATUT',
                                    infoPagination.filter.filter_STATUT,
                                    listeChoixStatut,
                                    'formDemandeAchat',
                                    '',
                                    'genetableau',
                                    path
                                ) }}
                            </th>
                        </tr>
                        {% for demandeAchat in demandesAchat %}
                            {% set onClick=attrJs('changeCodeLibelleDa', [
                                post.divCode,
                                demandeAchat.NO_DA,
                                post.divLibelle,
                                demandeAchat.NO_DEM~' ('~demandeAchat.NO_DA~')',
                                demandeAchat.ca_modenum is defined ?
                                {ca_modenum: societe.ca_modenum} : {}
                            ])  %}

                            <tr onclick="{{ onClick | raw }}">
                                <td id ="{{demandeAchat.NO_DA}}">{{ demandeAchat.NO_DA   | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                                <td>{{ demandeAchat.NO_DEM  | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                                <td>{{ demandeAchat.CODE_STE  | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                                <td>{{ demandeAchat.DTE_VAL  | dateTrad }}</td>
                                <td>{{ demandeAchat.CTR_LIV  | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                                <td>{{ listeChoixStatut[demandeAchat.STATUT] }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>

                </form>
                {{ paginations(
                    path,
                    infoPagination.nombreDePage,
                    infoPagination.page,
                    infoPagination.post,
                    'genetableau'
                ) }}
            </div>
        </center>
    </div>

    <script>
        function changeCodeLibelleDa(inputId, codeValue, divLibelle, libelleValue, mapAttr)
        {
            let target = document.getElementById(inputId);
            for (let key in mapAttr) {
                target.setAttribute('data-'+key, mapAttr[key]);
            }

            changeCodeLibelle(inputId, codeValue, divLibelle, libelleValue);
            desactivePopup();
        }
    </script>
{% endblock %}
