var code = getQuery("code");
$(document).ready(function () {
    initial();
});
async function initial() {
    if (code !== "")
        await getTax(code);
    else {
        $("#divMain").show();
        closeLoading();
    }
}
async function getTax() {
    await ajax({
        url: "SaleApi/GetValueAddedDetail",
        data: { code: code},
        success: function (result) {
            loadData(result);
        }
    });
}
async function loadData(result) {
    await setJsonValue(result);
    closeLoading();
    $("#divMain").show();
}
async function getEventLookupCombo($combo, search, code) {
    var id = $combo.attr('id');
    var url = "";
    var data = null;

    switch (id) {
        case "cboYear":
            url = "GeneralApi/GetYearList";
            data = { search: search, pageNo: 1, selectedCode: code };
            break;
        case "cboDocumentType":
            url = "SaleApi/GetDocumentTypeList";
            data = { state: 1, search: search, pageNo: 1, selectedCode: code };
            break;
    }
    await ajax({
        url: url,
        data: data,
        success: function (result) {
            var newResult = [{ Name: window.top.all, Code: -1 }];
            result = newResult.concat(result);
            $combo.lookupBuilder().bindData(result);
        }
    });
}
function save() {
    var data = getJsonValue("");
    data['Type'] = $('#cboType').val();
    data['Name'] = $("#cboType option:selected").text();
    if (code)
        data['Code'] = code;
    var exceprionText = checkValidation('');
    if (exceprionText === '') {
        ajax({
            loading: true,
            url: "SaleApi/" + (code === "" ? "InsertValueAdded" : "UpdateValueAdded"),
            data: { valueAdded: data },
            success: function (result) {
                showMsgModal(2, code === "" ? window.top.savedSuccessfully : window.top.editedSuccessfully);
                refreshParent('refresh(1)');
                closeTopModal();
            }
        });
    }
    else {
        showMsgModal(0, exceprionText, exceprionText, '0');
    }
}
