async function getEventLookupCombo($combo, search, code) {
    var id = $combo.attr('id');
    var url = "";
    var data = null;
    var level = Number($combo.parent().attr("data-level"));
    if (code && code.toString().indexOf("|") > 0)
        code = code.split("|")[0];
    switch (id) {
        case "cboMoainFrom": case "cboMoainTo":
            url = "AccountingApi/GetMoainList";
            data = { checkActive: true, search: search, selectedCode: code, pageNo: 1 };
            break;
        case "cboTafzilFrom": case "cboMarkazHazineFrom": case "cboProjectFrom":
            url = "AccountingApi/GetTafsilList";
            data = { moainCode: $("#cboMoainFrom").lookupBuilder().getSelectedValue().split("|")[0] || null, level: level, search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboTafzilTo": case "cboMarkazHazineTo": case "cboProjectTo":
            url = "AccountingApi/GetTafsilList";
            data = { moainCode: $("#cboMoainTo").lookupBuilder().getSelectedValue().split("|")[0] || null, level: level, search: search, pageNo: 1, selectedCode: code };
            break;
    }
    await ajax({
        url: url,
        data: data,
        success: function (result) {
            switch (id) {
                case "cboTafzilFrom": case "cboTafzilTo": case "cboMarkazHazineFrom": case "cboMarkazHazineTo": case "cboProjectFrom": case "cboProjectTo":
                    $.each(result, function () {
                        this.Code = this.Id;
                    });
                    var newResult = [{ Name: window.top.allItemsOne, Code: "-1" }];
                    result = newResult.concat(result);
                    break;
                case "cboMoainFrom": case "cboMoainTo":
                    $.each(result, function () {
                        this.Code = this.Code + "|" + this.ChildCount + "|" + this.ChildCountM + "|" + this.ChildCountP;
                    });
                    break;
            }

            $combo.lookupBuilder().bindData(result);
        }
    });
}
function cboMoainSelectedIndexChange(s) {
    var mode = s.substr(8);
    var selectedMoain = $("#" + s).lookupBuilder().getSelectedValue().split("|");

    $("#cboTafzil" + mode).lookupBuilder().setEnabled(Number(selectedMoain[1]) > 0);
    if (Number(selectedMoain[1]) === 0) 
        $("#cboTafzil" + mode).lookupBuilder().setSelectedValue("");

    $("#cboMarkazHazine" + mode).lookupBuilder().setEnabled(Number(selectedMoain[2]) > 0);
    if (Number(selectedMoain[2]) === 0) 
        $("#cboMarkazHazine" + mode).lookupBuilder().setSelectedValue("");

    $("#cboProject" + mode).lookupBuilder().setEnabled(Number(selectedMoain[3]) > 0);
    if (Number(selectedMoain[3]) === 0) 
        $("#cboProject" + mode).lookupBuilder().setSelectedValue("");
    
    GetArticleCount(s, mode);
}
function GetArticleCount(s, mode) {
    if (!mode)
        mode = s.indexOf("From") > 1 ? "From" : "To";
    var moain = $("#cboMoain" + mode).lookupBuilder().getSelectedValue().split("|")[0];
    var tafsil = $("#cboTafzil" + mode).lookupBuilder().getSelectedValue() || null;
    var markazHazine = $("#cboMarkazHazine" + mode).lookupBuilder().getSelectedValue() || null;
    var project = $("#cboProject" + mode).lookupBuilder().getSelectedValue() || null;
    ajax({
        loading: true,
        url: "AccountingApi/GetArticleCount",
        data: {
            moainCode: moain,
            tafsilId: tafsil,
            costCenterId: markazHazine,
            projectId: project
        },
        success: function (retValue) {
            $("#lblArtikelCount" + mode).text(retValue);
        }
    });
}
function transfer() {
    var moainFrom = $("#cboMoainFrom").lookupBuilder().getSelectedValue().split("|")[0];
    var moainTo = $("#cboMoainTo").lookupBuilder().getSelectedValue().split("|")[0];
    var fromTafsilText = $("#cboTafzilFrom").lookupBuilder().getSelectedText();
    var toTafsilText = $("#cboTafzilTo").lookupBuilder().getSelectedText();
    var fromCostCenterText = $("#cboMarkazHazineFrom").lookupBuilder().getSelectedText();
    var toCostCenterText = $("#cboMarkazHazineto").lookupBuilder().getSelectedText();
    var fromProjectText = $("#cboProjectFrom").lookupBuilder().getSelectedText();
    var toProjectText = $("#cboProjectTo").lookupBuilder().getSelectedText();
    if (moainFrom === null)
        showMsgModal(0, window.top.moainSource);
    else if (moainTo === null)
        showMsgModal(0, window.top.moainDestination);
    else {
        var txtFrom = $("#cboMoainFrom").lookupBuilder().getSelectedText() + (fromTafsilText.length > 0 ? "/" + fromTafsilText : "") + (fromCostCenterText.length > 0 ? "/" + fromCostCenterText : "") + (fromProjectText.length > 0 ? "/" + fromProjectText : "");
        var txtTo = $("#cboMoainTo").lookupBuilder().getSelectedText() + (toTafsilText.length > 0 ? "/" + toTafsilText : "") + (toCostCenterText.length > 0 ? "/" + toCostCenterText : "") + (toProjectText.length > 0 ? "/" + toProjectText : "");
        if (confirm(window.top.transferAllDocument + ": " + txtFrom + " " + window.top.toAccount + ": " + txtTo + " " + window.top.areSure))
            ajax({
                loading: true,
                url: "AccountingApi/TransferAccount",
                data: {
                    fromMoainCode: moainFrom,
                    fromTafsilId: $("#cboTafzilFrom").lookupBuilder().getSelectedValue() || null,
                    fromCostCenterId: $("#cboMarkazHazineFrom").lookupBuilder().getSelectedValue() || null,
                    fromProjectId: $("#cboProjectFrom").lookupBuilder().getSelectedValue() || null,
                    toMoainCode: moainTo, ToTafsilId: $("#cboTafzilTo").lookupBuilder().getSelectedValue() || null,
                    toCostCenterId: $("#cboMarkazHazineTo").lookupBuilder().getSelectedValue() || null,
                    toProjectId: $("#cboProjectTo").lookupBuilder().getSelectedValue() || null
                },
                success: function (retValue) {
                    showMsgModal(2, window.top.aboveAccountAccounting);
                    closeTopModal();
                }
            });
    }
}












