$(document).ready(function () {
    $("#btnImport").on("click", function () {
        $("#btnBrowse").click();
    });
});
function getSampleFile() {
    var wageFactors = [];
    $(".checkbox-control:checked").each(function () {
        wageFactors.push($(this).parent().attr("data-value"));
    });
    ajax({
        url: "SalaryApi/GetRevenueSampleFile",
        data: { wageFactors: wageFactors },
        success: function (result) {
            var link = document.createElement("a");
            link.download = "export.xlsx";
            link.href = result;
            link.click();
            $(link).remove();
        }
    });
}
function onFileChange(sender, event) {
    if (sender.files.length == 0) return;
    var file = event.target.files[0];
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function () {
        ajax({
            url: "SalaryApi/ImportRevenueList",
            data: reader.result,
            success: function (result) {
                dararecs = result;
                var gridBuilder = $("#grdList").gridBuilder();
                gridBuilder.loadData(result);
            }
        });
    };
}
function saveFileData(ignorelast) {
    for (var i = 0; i < dararecs.length; i++)
        dararecs[i].YearMonth = $("#cboYear").lookupBuilder().getSelectedValue() + ($("#cboMonth").lookupBuilder().getSelectedValue()).padStart(2, 0);

    ajax({
        loading:true,
        url: "SalaryApi/SaveRevenueList",
        data: { Revenues: dararecs, IgnoreLast: ignorelast },
        success: function (result) {
            if (result.Result)
                showMsgModal(2, window.top.savedSuccessfully);
            else
                showMsgModal(0, result.ErrorMessage);
        }
    });
}
