a = false;

$(document).ready(function () {
    $("#btn_savee").click(function () {
        if (a == false) {
            saveperform();
        }
    });
});

function saveperform() {
    // Quill editor cha content hidden input madhe sync kara submit chya aadhi
    $('#terms_condition').val(quillTerms.root.innerHTML);
    $('#bank_details').val(quillBank.root.innerHTML);
    $('#signature').val(quillSign.root.innerHTML);

    var report_header_name = $('#report_header_name').val();
    var id = $('#id').val();

    if (report_header_name == "") {
        showProAlert('error', 'Error', 'Please Select Report Header Name');
        return;
    }

    if (id > 0) {
        a = true;
        var formData = new FormData($("#Form")[0]);
        $.ajax({
            url: base_path + "report_header/updatedata",
            type: "POST",
            data: formData,
            processData: false,
            contentType: false,
            beforeSend: function () {
                $('#btn_savee').prop('disabled', true).html('<i class="fa fa-spinner"></i> Loading');
            },
            success: function () {
                $('#btn_savee').html('<i class="fa fa-check-circle"></i> Save').prop('disabled', false);
                showProAlert('success', 'Success', 'Data Updated Successfully').then(function () {
                    window.location.href = base_path + "report_header/index";
                });
            }
        });
    } else {
        a = true;
        var formData = new FormData($("#Form")[0]);

        $.ajax({
            url: base_path + "report_header/insert",
            type: "POST",
            data: formData,
            processData: false,
            contentType: false,

            beforeSend: function () {
                $('#btn_savee')
                    .prop('disabled', true)
                    .html('<i class="fa fa-spinner"></i> Loading');
            },

            success: function (response) {
                showProAlert('success', 'Success', 'Data Submitted Successfully').then(function () {
                    window.location.href = base_path + "report_header";
                });
            }
        });
    }
}
