var code = getQuery("code");
$(document).ready(function () {
    initial();
});
async function initial() {
    if (code)
        await getContractType(code);
    closeLoading();
    $("#divMain").show();
}
async function getContractType(code) {
    await ajax({
        url: "SalaryApi/GetContractType",
        data: { code: code },
        success: function (result) {
            $("#Name").val(result.Name);
        }
    });
}
function save() {
    if (code)
        edit();
    else
        insert();
}
function insert() {
    var data = getJsonValue("");
    var error = checkValidation("");
    if (error === "") {
        ajax({
            url: "SalaryApi/InsertContractType",
            data: data,
            success: function (result) {
                refreshParent("refresh()");
                showMsgModal(2, result.FinalMessage);
                closeTopModal();
            }
        });
    }
    else {
        showMsgModal(0, error, error);
    }
}
function edit() {
    var data = getJsonValue("");
    data["Code"] = code;
    var error = checkValidation("");
    if (error === "") {
        ajax({
            url: "SalaryApi/UpdateContractType",
            data: data,
            success: function (result) {
                refreshParent("refresh(" + code + ")");
                showMsgModal(2, result.FinalMessage);
                closeTopModal();
            }
        });
    }
    else {
        showMsgModal(0, error, error);
    }
}