{% extends 'layout.twig' %}

{% block body %}
    {% set typeImport = typeImport|default('mono') %}
    <div class="contenu clearfix" id="import_multiple_reporting">
        <h1>{{ 'Import reporting' | trad }}</h1>
        {{ ariane() }}

        <h2>
            {% if typeImport == 'multi' %}
                {{ 'Importation' | trad }}
            {% else %}
                {{ 'Fournisseur' | trad }} : {{ libelle_fournisseur??libelle }} ({{ code_fournisseur??id }})
            {% endif %}
        </h2>

        {{ flash.display|raw }}

        {{ arianeSub() }}

        <div id="importReporting" class="padding15">
            <form method="POST" id='formulaireGeneral' enctype="multipart/form-data" class="box-form clearfix" >
                <input type="hidden" value='' name='importSend'>
                {% if typeImport == 'mono' %}
                    <input type="hidden" value="{{ code_fournisseur }}" name="CODE_FOURNISSEUR">
                {% endif %}
                <input type="hidden" value="{{ typeImport }}" name="TYPE_IMPORT">
                <div class="single">
                    {{ inputAdvance('FILE', {'name' : 'Report', 'format' : 'excel'} ) }}
                </div>
                <center><h4>{{ "Déposez votre fichier d'import reporting ci-dessus (fichier supporté : xls, xlsx, csv)." | trad }}</h4></center>
                <hr>
                <button class="button principal button_right" type='button' onClick="ImportReporting('{{ path('Specifique155.importReporting.import', {type:typeImport}) }}');">{{ 'Importer' | trad }}</button>
                <a href="{{ urlDownloadPattern }}" class="button secondaire button_right">{{ 'Télécharger le patron'|trad }}</a>
            </form>
        </div>
    </div>

    <script>

        function ImportReporting(path)
        {
            jForm.append("importSend", $('[name="importSend"]').val());
            jForm.append("TYPE_IMPORT", $('[name="TYPE_IMPORT"]').val());
            if ($('[name="CODE_FOURNISSEUR"]').length > 0) {
                jForm.append("CODE_FOURNISSEUR", $('[name="CODE_FOURNISSEUR"]').val());
            }

            activeLoader();
            $.ajax({
                url : path ,
                data : jForm,
                type: 'POST',
                contentType: false,
                cache: false,
                processData: false,
                mimeType: "multipart/form-data",
                success: function (data) {
                    desactiveLoader();
                    $("#modal-content").addClass("modal_small");
                    $("#modal-body").html(data);
                    activePopup();
                },
                error: function (data){
                    var data = jQuery.parseJSON(data.responseText);
                    if(data.postGestion){
                        redirectJSWithPost(data.path, data.postGestion);
                    }
                    else{
                        window.location.href = data.path;
                    }
                }
            });
        };
    </script>
{% endblock %}