var code = getQuery("code");
var gridBuilder;
$(document).ready(function () {
    gridBuilder = $(".grid").gridBuilder();
    initial();
});
async function initial() {
    if (code) {
        await getTaxRateDetail(code);
    } else
        gridBuilder.addNewRow();
    $("#divMain").show();
    closeLoading();
}
async function getTaxRateDetail(code) {
    await ajax({
        url: "SalaryApi/GetTaxRatesDetail",
        data: { code: code },
        success: function (result) {
            gridBuilder.loadData(result);
        }
    });
}
function save() {
    var error = checkValidation("");
    if (error === "") {
        var data = getJsonValue("");
        var artikls = gridBuilder.getDataArray()["data"];
        data["StartYearMonth"] = $("#txtFromYear").val() + $("#cboFromMonth").val();
        data["EndYearMonth"] = $("#txtToYear").val() + $("#cboToMonth").val();
        if (code) 
            data["Code"] = code;
        ajax({
            url: "SalaryApi/" + (code ? "UpdateTaxRate" : "InsertTaxRate"),
            data: { taxRate: data, taxRateDetails: artikls },
            success: function (result) {
                refreshParent("loadGrid('grdTaxList')");
                showMsgModal(2, result.FinalMessage);
                closeTopModal();
            }
        });
    }
    else {
        showMsgModal(0, error, error);
    }
}
