{% extends 'layout.twig' %}

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

        {{ flash.display|raw }}

        {{ arianeSub() }}

        <div id="transformCsvToXml" class="padding15">
            <form method="POST" id='formulaireGeneral' enctype="multipart/form-data" class="box-form clearfix" >
                <input type="hidden" value='' name='importSend'>
                <div class="single">
                    {{ inputAdvance('FILE', {'name' : 'DeclaratifCA', 'format' : 'excel'} ) }}
                </div>
                <center><h4>{{ "Déposer votre fichier de déclaratif CA fournisseurs ci-dessus (fichier supporté : xls, xlsx, csv)." | trad }}</h4></center>
                <hr>
                <button class="button principal button_right" type='button' onClick="ImportCA('{{ path('Specifique155.declaratif.index') }}')">{{ 'Importer' | trad }}</button>
            </form>
        </div>
    </div>

    <script>

        function ImportCA(path)
        {
            jForm.append("importSend", $('[name="importSend"]').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 %}