<form method="post" name="SBT_LIGN" id="{{ formId }}" action="{{ formAction }}">
    <h3 class="mb-base">
        &nbsp&nbsp
        <button type="submit" class="button principal button_right last" id="validateLignForm">
            {{ 'Enregistrer' | trad }}
        </button>
        <button type="button" class="button secondaire listeLigns">
            {{ 'Annuler' | trad }}
        </button>
    </h3>
    <div class="tab-pane active in clearfix padding_form bg_form border_form">
        <div class="clearfix">
            <div class="colonne2">
                <input type="hidden" name="SBT_LIGN[NO_LIG]" value="{{ noLigne }}">
                <input type="hidden" name="SBT_LIGN[NO_DS]" value="{{ ligneBonTransfert.NO_DS ?? 0 }}">
                <input type="hidden" name="SBT_LIGN[NO_LIG_DS]" value="{{ ligneBonTransfert.NO_LIG_DS ?? 0 }}">
                <div class="row">
                    {{ inputAdvance('ZOOMADVANCE',{
                        titre: 'Code article' | trad,
                        name: 'SBT_LIGN[CODE_ART]',
                        value: ligneBonTransfert.CODE_ART ?? '',
                        pahtZoom: path('Ajax.liste.stockLocal'),
                        entity: 'Sarticle',
                        titleZoom : strBuild('@1@ : liste des articles' | trad, [siteStock.DESIGN ~ ' (' ~ siteStock.SITE ~ ')']),
                        paramZoom: "{'filter_egal_STO#point#SITE' : '" ~ bonTransfert.SITE ~ "', 'divPrix': 'input_SBT_LIGN[PRIX]', 'divQte': 'input_SBT_LIGN[QTE_TRF]', 'qteLabelText': '" ~ 'Quantité transférée' | trad ~ "' }",
                        pathConvert: path('Ajax.outil.convertLibelle'),
                        convertLibelle: 'convertLibelleGlobal',
                        obligatoire: true,
                        libelleBDD: 'DESIGN',
                        pathValidator : path('Ajax.validator.zoomStockLocal'),
                        paramsValidator : "{'null' : false, 'site' : '" ~ bonTransfert.SITE ~ "' }",
                        option: ligneBonTransfert.NO_DS ? 'readonly': ''
                    }) }}
                </div>
            </div>
            <div class="colonne2 last">
                <div class="row">
                    {% set maxVal = maxQteTrf ? "'max':" ~ maxQteTrf: '' %}

                    {{ inputAdvance('TEXT', {
                        titre: strBuild('Quantité transférée @1@' | trad, [uniteStk ? '(' ~ uniteStk ~ ')': '']),
                        name: 'SBT_LIGN[QTE_TRF]',
                        obligatoire: true,
                        value: ligneBonTransfert.QTE_TRF ? ligneBonTransfert.QTE_TRF | qte: '',
                        pathValidator: path('Ajax.validator.float'),
                        paramsValidator: "{'min' : '0', 'obligatoire': true, 'format': " ~ format_qte() ~ ", " ~ maxVal ~ "}",
                        addClass: 'text-right'
                    }) }}
                </div>
                <div class="row" {% if not is_prix_visible() %}style="display:none;"{% endif %}>
                    {{ inputAdvance('TEXT', {
                        titre: strBuild('Prix (@1@)' | trad,[bonTransfert.DEVISE]),
                        name: 'SBT_LIGN[PRIX]',
                        value: ligneBonTransfert.PRIX ? ligneBonTransfert.PRIX | prixUnitaire: '',
                        pathValidator: path('Ajax.validator.float'),
                        paramsValidator: "{'min' : '0', 'format': " ~ format_pu() ~ "}",
                        addClass: 'text-right',
                        option: not has_droit_modification_prix() ? 'readonly': ''
                    }) }}
                </div>
            </div>
        </div>
        <div class="clearfix" id="cs">
            {% if CSExist('SBT_LIGN') %}
                <hr>
                {{ inputCSAdvance({
                    'post' : post,
                    'codTab' : 'SBT_LIGN',
                    'colonneActif' : true,
                    'ModeModif' : modeModif,
                    'codeEnr' : autoCompletCodeEnr(noBt, noLigne)
                }) }}
            {% endif %}
        </div>
        <fieldset class="scheduler-border {% if stockArticle is not defined or stockArticle.TRACABLE != '54' %}d-none{% endif %} mb-0" id="lots">
            <legend class="scheduler-border">{{ 'Répartition par lots' | trad }}</legend>
            <div id="collection">
                {% if ligneBonTransfert is defined and stockArticle.TRACABLE == '54' %}
                    {% if ligneBonTransfert.SBT_LOTS|length > 0 %}
                        {% for key, lotBonTransfert in ligneBonTransfert.SBT_LOTS %}
                            {{ include('@Stock/LigneBonTransfert/Composant/_lot.twig', { key: key, lotBonTransfert: lotBonTransfert, ligneBonTransfert: ligneBonTransfert }) }}
                        {% endfor %}
                    {% else %}
                        {{ include('@Stock/LigneBonTransfert/Composant/_lot.twig', { key: 0, ligneBonTransfert: ligneBonTransfert }) }}
                    {% endif %}
                {% endif %}
            </div>
            <div class="bs-col-1">
                <button type="button" class="principal addItem">
                    + Ajouter
                </button>
            </div>
        </fieldset>
    </div>
</form>
<div class="d-none">
    {{ include('@Stock/LigneBonTransfert/Composant/_lot.twig', { key: '%i%', ligneBonTransfert: ligneBonTransfert, model: true }) }}
    {{ include('@Stock/LigneBonTransfert/Composant/_lot.twig', { key: 0, ligneBonTransfert: ligneBonTransfert }) }}
</div>
<script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/csInitializer.js') }}"></script>
<script type="application/javascript">
    $('#' + CSS.escape('input_SBT_LIGN[CODE_ART]')).on('change', (event) => {
        const codeArt = $(event.target).val();
        const site =  $('#input_SBT_ENTE_SITE').val();

        showLotsFieldSet('{{ path('Stock.StockLocal.getInformation') }}', site, codeArt);

        if (!'{{ modeModif }}') {
            initializeCs(
                '{{ path('Ajax.InitChampController.initializeCs') }}',
                '{{ formId }}',
                $('#'+CSS.escape('input_SBT_ENTE_CODE_STE')).val(),
                '{{ autoCompletCodeEnr(noBt, noLigne) }}',
                'SBT_LIGN',
                [['SARTICLE', codeArt], ['SSTOCKLO', site + codeArt]]
            );
        }
    });
</script>