{% extends '@Stock/Layout/parametrage_global_layout.twig' %}

{% block body_parametrage %}
    <form name="controle_budgets_form" id="controle_budgets_form" method="POST" action="{{ path('Stock.Vrac.controleBudgets') }}">
        <h2 class="mb-base">
            {{ 'Contrôle budgets' | trad }}
            <button type="submit" class="principal button last button_right">
                {{ 'Enregistrer' | trad }}
            </button>
        </h2>
        <div class="bg_form border_form pr-base pl-base">
            <fieldset class="scheduler-border">
                <legend class="scheduler-border">{{ 'Activation cumuls' | trad }}</legend>
                <div class="colonne2">
                    <div class="row">
                        {{ inputAdvance('SWITCH', {
                            'titre' : 'Activation des cumuls sur les bons de sortie' | trad,
                            'name' : 'PARAVRAC[BS_ACTIVATION_CUMULS][LIB01PARV]',
                            'value' : parametres.BS_ACTIVATION_CUMULS.LIB01PARV,
                        }) }}
                        <input type="hidden" name="PARAVRAC[BS_ACTIVATION_CUMULS][TYPEPARV]" value="PARAMGEN">
                        <input type="hidden" name="PARAVRAC[BS_ACTIVATION_CUMULS][CODEPARV]" value="BS_ACTIVATION_CUMULS">
                    </div>
                </div>
            </fieldset>
            <div id="form_SI_BC">
                <fieldset class="scheduler-border">
                    <legend class="scheduler-border">{{ 'Système simplifié' | trad }}</legend>
                    <fieldset class="scheduler-border" style="margin-top: 0 !important;">
                        <legend class="scheduler-border">{{ 'Section d\'imputation' | trad }}</legend>
                        <div class="colonne2">
                            <div class="row">
                                {{ inputAdvance('SELECT', {
                                    'titre' : 'Bons de sortie' | trad,
                                    'name' : 'PARAVRAC[VERBS_CTRLSI][LIB01PARV]',
                                    'value' : parametres.VERBS_CTRLSI.LIB01PARV,
                                    'listeValue' : listeChoixControleBonsDeSortie,
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERBS_CTRLSI][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERBS_CTRLSI][CODEPARV]" value="VERBS_CTRLSI">
                            </div>
                            <div class="row">
                                {{ inputAdvance('SELECT', {
                                    'titre' : 'Global / Période' | trad,
                                    'name' : 'PARAVRAC[VERIF_BUDGSI][LIB01PARV]',
                                    'value' : parametres.VERIF_BUDGSI.LIB01PARV,
                                    'listeValue' : listeChoixControleGlobal,
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERIF_BUDGSI][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERIF_BUDGSI][CODEPARV]" value="VERIF_BUDGSI">
                            </div>
                        </div>
                        <div class="colonne2 last">
                            <div class="row">
                                {{ inputAdvance('TEXT', {
                                    titre: 'Taux d\'avancement (%)' | trad,
                                    name: 'PARAVRAC[VERBS_TXAVSI][LIB01PARV]',
                                    value: parametres.VERBS_TXAVSI.LIB01PARV | prix,
                                    pathValidator: path('Ajax.validator.float'),
                                    paramsValidator: "{'min' : '0', 'max': '100', 'format': " ~ format_montant() ~ "}",
                                    addClass: 'text-right'
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERBS_TXAVSI][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERBS_TXAVSI][CODEPARV]" value="VERBS_TXAVSI">
                            </div>
                        </div>
                    </fieldset>
                    <fieldset class="scheduler-border">
                        <legend class="scheduler-border">{{ 'Code complémentaire' | trad }}</legend>
                        <div class="colonne2">
                            <div class="row">
                                {{ inputAdvance('SELECT', {
                                    'titre' : 'Bons de sortie' | trad,
                                    'name' : 'PARAVRAC[VERBS_CTLCDC][LIB01PARV]',
                                    'value' : parametres.VERBS_CTLCDC.LIB01PARV,
                                    'listeValue' : listeChoixControleBonsDeSortie,
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERBS_CTLCDC][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERBS_CTLCDC][CODEPARV]" value="VERBS_CTLCDC">
                            </div>
                            <div class="row">
                                {{ inputAdvance('SELECT', {
                                    'titre' : 'Global / Période' | trad,
                                    'name' : 'PARAVRAC[VERIF_BUDCDC][LIB01PARV]',
                                    'value' : parametres.VERIF_BUDCDC.LIB01PARV,
                                    'listeValue' : listeChoixControleGlobal,
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERIF_BUDCDC][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERIF_BUDCDC][CODEPARV]" value="VERIF_BUDCDC">
                            </div>
                        </div>
                        <div class="colonne2 last">
                            <div class="row">
                                {{ inputAdvance('TEXT', {
                                    titre: 'Taux d\'avancement (%)' | trad,
                                    name: 'PARAVRAC[VERBS_TXVCDC][LIB01PARV]',
                                    value: parametres.VERBS_TXVCDC.LIB01PARV | prix,
                                    pathValidator: path('Ajax.validator.float'),
                                    paramsValidator: "{'min' : '0', 'max': '100', 'format': " ~ format_montant() ~ "}",
                                    addClass: 'text-right'
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERBS_TXVCDC][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERBS_TXVCDC][CODEPARV]" value="VERBS_TXVCDC">
                            </div>
                        </div>
                    </fieldset>
                    <fieldset class="scheduler-border mb-0">
                        <legend class="scheduler-border">{{ 'Sous-compte d\'analyse' | trad }}</legend>
                        <div class="colonne2">
                            <div class="row">
                                {{ inputAdvance('SELECT', {
                                    'titre' : 'Bons de sortie' | trad,
                                    'name' : 'PARAVRAC[VERBS_CTLSCA][LIB01PARV]',
                                    'value' : parametres.VERBS_CTLSCA.LIB01PARV,
                                    'listeValue' : listeChoixControleBonsDeSortie,
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERBS_CTLSCA][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERBS_CTLSCA][CODEPARV]" value="VERBS_CTLSCA">
                            </div>
                            <div class="row">
                                {{ inputAdvance('SELECT', {
                                    'titre' : 'Global / Période' | trad,
                                    'name' : 'PARAVRAC[VERIF_BUDSCA][LIB01PARV]',
                                    'value' : parametres.VERIF_BUDSCA.LIB01PARV,
                                    'listeValue' : listeChoixControleGlobal,
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERIF_BUDSCA][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERIF_BUDSCA][CODEPARV]" value="VERIF_BUDSCA">
                            </div>
                        </div>
                        <div class="colonne2 last">
                            <div class="row">
                                {{ inputAdvance('TEXT', {
                                    titre: 'Taux d\'avancement (%)' | trad,
                                    name: 'PARAVRAC[VERBS_TXVSCA][LIB01PARV]',
                                    value: parametres.VERBS_TXVSCA.LIB01PARV | prix,
                                    pathValidator: path('Ajax.validator.float'),
                                    paramsValidator: "{'min' : '0', 'max': '100', 'format': " ~ format_montant() ~ "}",
                                    addClass: 'text-right'
                                }) }}
                                <input type="hidden" name="PARAVRAC[VERBS_TXVSCA][TYPEPARV]" value="PARAMGEN">
                                <input type="hidden" name="PARAVRAC[VERBS_TXVSCA][CODEPARV]" value="VERBS_TXVSCA">
                            </div>
                        </div>
                    </fieldset>
                </fieldset>
                <fieldset class="scheduler-border">
                    <legend class="scheduler-border">{{ 'Budget comptable' | trad }}</legend>
                    <div class="colonne2">
                        <div class="row">
                            {{ inputAdvance('SELECT', {
                                'titre' : 'Contrôle sur bons de sortie' | trad,
                                'name' : 'PARAVRAC[CTRLBUDCPTBS][LIB01PARV]',
                                'value' : parametres.CTRLBUDCPTBS.LIB01PARV,
                                'listeValue' : listeChoixControleGlobal,
                            }) }}
                            <input type="hidden" name="PARAVRAC[CTRLBUDCPTBS][TYPEPARV]" value="PARAMGEN">
                            <input type="hidden" name="PARAVRAC[CTRLBUDCPTBS][CODEPARV]" value="CTRLBUDCPTBS">
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>
    </form>
    <script type="application/javascript" src="{{ baseUrl('js/Modules/Stock/postAjaxForm.js') }}"></script>
    <script type="application/javascript">
        $('#controle_budgets_form').on('submit', (event) => {
            event.preventDefault();

            activeLoader();
            const form = $('#controle_budgets_form');

            submitForm(form, form.serializeArray());
        });

        $(window).on("load",  () => {
            toggleFields();
            $('#input_' + CSS.escape('PARAVRAC[BS_ACTIVATION_CUMULS][LIB01PARV]')).on('change', () => {
                toggleFields();
            })
        })

        function toggleFields() {
            const fields = $('#controle_budgets_form input, #controle_budgets_form select');
            const cumulsSurBSActive = $('#input_' + CSS.escape('PARAVRAC[BS_ACTIVATION_CUMULS][LIB01PARV]')).is(':checked');

            if (cumulsSurBSActive) {
                fields.each((key, element) => {
                    $(element).prop('readonly', false);
                    $(element).removeAttr('readonly');
                });
            } else {
                fields.each((key, element) => {
                    $(element).attr('readonly', 'true');
                });
            }
        }
    </script>
{% endblock %}