$(document).ready(function () {
    $("#cboYear").lookupBuilder().onChanged(function () {
        loadGrid();
    });
    $("#cboMonth").lookupBuilder().onChanged(function () {
        loadGrid();
    });
    $("#cboType").lookupBuilder().onChanged(function () {
        loadGrid();
    });
    $("#cboWorkShop").lookupBuilder().onChanged(function () {
        loadGrid();
    });
    loadGrid();
});
function loadGrid(gridId, objectParameter) {
    gridId = "grdFunctionList";
    var gridBuilder = $("#" + gridId).gridBuilder();
    var isExportExcel = objectParameter && objectParameter.exportExcel ? true : false;
    ajax({
        loading: true,
        url: "SalaryApi/GetRevenueList",
        data: {
            workshopCode: Number($("#cboWorkShop").lookupBuilder().getSelectedValue()),
            typeCode: Number($("#cboType").lookupBuilder().getSelectedValue()),
            year: $("#cboYear").lookupBuilder().getSelectedValue() || 0,
            month: $("#cboMonth").lookupBuilder().getSelectedValue() || 0,
            filter: gridBuilder.getFilter(),
            sort: gridBuilder.getSortFields(),
            pageNo: isExportExcel ? -1 : gridBuilder.getCurrentPageNumber()
        },
        success: function (data) {
            if (isExportExcel) {
                exportExcel(data, gridBuilder.getColumns(), gridBuilder.getColumnsCaption());
            }
            else
                gridBuilder.loadData(data);
        }
    });
}
function DeleteRevenue() {
    if (!confirm("آیا مایل به حذف این کارکرد می باشید ؟")) return;
    var gridBuilder = $("#grdFunctionList").gridBuilder();
    var rowIndex = gridBuilder.getActiveRowIndex();
    var Code = gridBuilder.getCellValue(rowIndex, "Code");
    if (Number(Code) > 0)
        ajax({
            loading: true,
            url: "SalaryApi/DeleteRevenue",
            data: Code,
            success: function (data) {
                loadGrid();
            }
        });
}
function openModalManual() {
    openInModal('', 'Salary/FunctionManualSave', 'ثبت دستی کارکرد', '780', '366')
}
function openModalAuto() {
    openInModal('', 'Salary/FunctionAutoSave', 'ثبت اتوماتیک کارکرد', '860', '456')
}
function openModalInput() {
    openInModal('', 'Salary/FunctionInputFile', 'ورود اطلاعات از فایل', '510', '260')
}
function openModalRevenueEdit() {
    var gridBuilder = $("#grdFunctionList").gridBuilder();
    var rowIndex = gridBuilder.getActiveRowIndex();
    var Code = gridBuilder.getCellValue(rowIndex, "Code");
    if (Number(Code) > 0)
        openInModal('', 'Salary/FunctionManualSave?Code=' + Code, 'ویرایش کارکرد', '780', '366')
}