var rulingCode = getQuery("ruling");
$(document).ready(function () {
    $(' [data-mask="price"]').blur(function () {
        var amount = 0 ;
        $(' [data-mask="price"]').each(function () {
            amount = numberNonCommas($(this).val()) + amount;
        });
        $('#divSumAfter').html(numberWithCommas(amount));
        $('#spanletterAmount').text(wordifyfa(amount, 0));
    });
    var sumAmount = numberNonCommas($("#divSumAfter").text());
    $('#spanletterAmount').text(wordifyfa(sumAmount, 0));
});
async function getEventLookupCombo($combo, search, code) {
    var id = $combo.attr('id');
    var url = "";
    var data = null;
    switch (id) {
        case "cboWorkshop":
            url = "SalaryApi/GetWorkShops";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboEducation":
            url = "SalaryApi/GetEducations";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboContractType":
            url = "SalaryApi/GetContractTypes";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboCostCenter":
            url = "SalaryApi/GetCostCenters";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboPosition":
            url = "SalaryApi/GetOrganizationPositions";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboJob":
            url = "SalaryApi/GetInsuranceJobs";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
    }
    if (url)
        await ajax({
            url: url,
            data: data,
            success: function (resValue) {
                $combo.lookupBuilder().bindData(resValue);
            }
        });
}
function save() {
    var exceprionText = checkValidation("");
    if (exceprionText) {
        showMsgModal(0, exceprionText);
        return;
    }
    if (Number($("[data-id='BaseAmount']").val()) === 0) {
        showMsgModal(0, "مقدار مزد مبنا را وارد کنید");
        return;
    }
    var data = getJsonValue("");
    data["PersonnelCode"] = getQuery("personnel");
    if (rulingCode)
        data["Code"] = rulingCode;
    ajax({
        url: "SalaryApi/" + (rulingCode ? "UpdateWageRuling" : "InsertWageRuling"),
        data: data,
        success: function (result) {
            refreshParent('loadGrid()');
            showMsgModal(2, window.top.savedSuccessfully);
            closeTopModal();
        }
    });
}
