var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var F01280;
(function (F01280) {
    var InterfaceRules = (function () {
        function InterfaceRules(document) {
            this._activeCorrection = 0;
            this._document = document;
        }
        InterfaceRules.prototype.GetRelRowTotalFormula = function (row, column, relRowCount) {
            var result = new SheetCalcResult(BaseFormulas.SUM);
            for (var i = 1; i < relRowCount; i++) {
                result.AddCoordinates(new CellCoordinate(row - i, column));
            }
            return result.ToArray();
        };
        InterfaceRules.prototype.SheetP1FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column > 0) {
                var sheet = this.Document.Sheets.getValue(sheetId);
                var lastRow = sheet.RowCount - 1;
                if (row === lastRow) {
                    return SheetFormatCollection.Calc;
                }
                else if (row === lastRow - 1) {
                    if (column === 2 || column === 3) {
                        return SheetFormatCollection.Free;
                    }
                }
                else if (row === lastRow - 2) {
                    if (column > 0 && column < 6) {
                        return SheetFormatCollection.Calc;
                    }
                    else if (column > 17) {
                        return SheetFormatCollection.Related;
                    }
                }
                else {
                    if (column > 9) {
                        return SheetFormatCollection.Related;
                    }
                    else {
                        return SheetFormatCollection.Calc;
                    }
                }
            }
            return SheetFormatCollection.Default;
        };
        InterfaceRules.prototype.SheetP1EditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var sheet = this.Document.Sheets.getValue(sheetId);
            var corrRow = sheet.RowCount - 2;
            return row === corrRow && (column === 2 || column === 3);
        };
        InterfaceRules.prototype.SheetPTotalFormatEventHandler = function (sheetId, row, column, groupIndex, isCalcCorrection) {
            if (isCalcCorrection === void 0) { isCalcCorrection = false; }
            if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetPTotalTRowCount)) {
                if (column < 3) {
                    return SheetFormatCollection.Default;
                }
                else {
                    var rowCount = this._document.Sheets.getValue(sheetId).RowCount;
                    if (row === (rowCount - 2) && column > 11 && !isCalcCorrection) {
                        return SheetFormatCollection.Free;
                    }
                    else {
                        return SheetFormatCollection.Calc;
                    }
                }
            }
            else {
                if (column < 2) {
                    return SheetFormatCollection.Related;
                }
                else if (column === 2) {
                    return SheetFormatCollection.Default;
                }
                else if (column < 12) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    var relRow = row % InterfaceRules._sheetPTotalRelRowCount;
                    if (column < 16) {
                        if (relRow === 2) {
                            return SheetFormatCollection.Calc;
                        }
                        else {
                            return SheetFormatCollection.Related;
                        }
                    }
                    else {
                        switch (relRow) {
                            case 0:
                                return SheetFormatCollection.Related;
                            case 1:
                                return SheetFormatCollection.Free;
                            case 2:
                                return SheetFormatCollection.Calc;
                        }
                    }
                }
            }
            return SheetFormatCollection.Default;
        };
        InterfaceRules.prototype.SheetPTotalCorrectionFormatEventHandler = function (sheetId, row, column, groupIndex, isCalcCorrection) {
            if (isCalcCorrection === void 0) { isCalcCorrection = false; }
            return this.SheetPTotalFormatEventHandler(sheetId, row, column, groupIndex, true);
        };
        InterfaceRules.prototype.SheetPTotalEditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel, isCalcCorrection) {
            if (isCalcCorrection === void 0) { isCalcCorrection = false; }
            if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetPTotalTRowCount)) {
                var rowCount = this._document.Sheets.getValue(sheetId).RowCount;
                return row === (rowCount - 2) && column > 11 && !isCalcCorrection;
            }
            else {
                var relRow = row % InterfaceRules._sheetPTotalRelRowCount;
                return relRow === 1 && column > 15;
            }
        };
        InterfaceRules.prototype.SheetPTotalCorrectionEditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return this.SheetPTotalEditingCellEventHandler(sheetId, row, column, fieldId, rowLevel, true);
        };
        InterfaceRules.prototype.SheetPTotalCalcEventHandler = function (sheetId, row, column, fieldId, isCalcCorrection) {
            if (isCalcCorrection === void 0) { isCalcCorrection = false; }
            if (column > 3 && column < 12) {
                var result = new SheetCalcResult(BaseFormulas.SUM);
                var offset = 2;
                result.AddCoordinates(new CellCoordinate(row, column + ObasStageSettings.YearsCount));
                if (column < 8) {
                    offset = 4;
                }
                result.AddCoordinates(new CellCoordinate(row, column + ObasStageSettings.YearsCount * offset));
                return result.ToArray();
            }
            else if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetPTotalTRowCount)) {
                if (column > 3) {
                    var lastRow = this._document.Sheets.getValue(sheetId).RowCount - 1;
                    var relRow = row % InterfaceRules._sheetPTotalRelRowCount;
                    switch (row) {
                        case lastRow - 3:
                        case lastRow - 2:
                            return this._document.CommonRules.GetFooterSum(sheetId, row, column, {
                                Step: InterfaceRules._sheetPTotalRelRowCount,
                                StartRow: relRow
                            });
                        case lastRow - 1:
                            if (isCalcCorrection) {
                                var result = new SheetCalcResult("%Doc%.InterfaceRules.CorrectionFormula");
                                result.AddCoordinates(new CellCoordinate(row - 1, column));
                                result.AddCoordinates(new CellCoordinate(row - 2, column));
                                return result.ToArray();
                            }
                            else {
                                return undefined;
                            }
                        case lastRow:
                            return this.GetRelRowTotalFormula(row, column, InterfaceRules._sheetPTotalTRowCount);
                    }
                }
            }
            else {
                if (fieldId === BaseObasTableFields.StrCodeField.Id) {
                    return this._document.CommonRules
                        .CalcRelRowCode(row, InterfaceRules._sheetPTotalRelRowCount, InterfaceRules._sheetPTotalCodeInfo);
                }
                else if (column > 11) {
                    var relRow = row % InterfaceRules._sheetPTotalRelRowCount;
                    if (relRow === 2) {
                        return this.GetRelRowTotalFormula(row, column, InterfaceRules._sheetPTotalRelRowCount);
                    }
                }
            }
            return undefined;
        };
        InterfaceRules.prototype.CorrectionFormula = function (fotVal, changeVal) {
            return ((fotVal || 0) + (changeVal || 0)) * this._activeCorrection * -1;
        };
        InterfaceRules.prototype.SheetPTotalCorrectionCalcEventHandler = function (sheetId, row, column, fieldId) {
            return this.SheetPTotalCalcEventHandler(sheetId, row, column, fieldId, true);
        };
        InterfaceRules.prototype.SheetPTotalFotFormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column === 3) {
                return SheetFormatCollection.Default;
            }
            else if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetPTotalFotTRowCount)) {
                if (column > 3) {
                    return SheetFormatCollection.Calc;
                }
            }
            else {
                if (column < 2) {
                    return SheetFormatCollection.Related;
                }
                else if (column > 3) {
                    var relRow = row % InterfaceRules._sheetPTotalFotRelRowCount;
                    if (relRow === 3) {
                        return SheetFormatCollection.Calc;
                    }
                    else {
                        return SheetFormatCollection.Related;
                    }
                }
            }
            return SheetFormatCollection.Default;
        };
        InterfaceRules.prototype.SheetPTotalFotCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetPTotalFotTRowCount)) {
                if (column > 3) {
                    var lastRow = this._document.Sheets.getValue(sheetId).RowCount - 1;
                    var relRow = row % InterfaceRules._sheetPTotalFotRelRowCount;
                    switch (row) {
                        case lastRow - 4:
                        case lastRow - 3:
                        case lastRow - 1:
                            return this._document.CommonRules.GetFooterSum(sheetId, row, column, {
                                Step: InterfaceRules._sheetPTotalFotRelRowCount,
                                StartRow: row === lastRow - 1 ? relRow - 1 : relRow,
                                EndRow: lastRow - 4
                            });
                        case lastRow - 2:
                        case lastRow:
                            return this.GetRelRowTotalFormula(row, column, 3);
                    }
                }
            }
            else if (fieldId === BaseObasTableFields.StrCodeField.Id) {
                return this._document.CommonRules
                    .CalcRelRowCode(row, InterfaceRules._sheetPTotalFotRelRowCount, InterfaceRules
                    ._sheetPTotalCodeInfo);
            }
            else if (column > 3) {
                var relRow = row % InterfaceRules._sheetPTotalFotRelRowCount;
                if (relRow === 3) {
                    return this.GetRelRowTotalFormula(row, column, InterfaceRules._sheetPTotalFotRelRowCount);
                }
            }
            return undefined;
        };
        InterfaceRules.prototype.SheetPIndexFormatEventHandler = function (sheetId, row, column, groupIndex) {
            switch (column) {
                case 0:
                case 1:
                    if (this._document.CommonRules.IsFooterRow(sheetId, row)) {
                        return SheetFormatCollection.Default;
                    }
                    else {
                        return SheetFormatCollection.Related;
                    }
                case 2:
                case 3:
                    return SheetFormatCollection.Default;
                default:
                    if (this._document.CommonRules.IsFooterRow(sheetId, row)) {
                        return SheetFormatCollection.Calc;
                    }
                    else {
                        var relRow = row % InterfaceRules._sheetPIndexRelRowCount;
                        switch (relRow) {
                            case 0:
                                return SheetFormatCollection.Related;
                            case 1:
                            case 3:
                                return SheetFormatCollection.Free;
                            default:
                                return SheetFormatCollection.Calc;
                        }
                    }
            }
        };
        InterfaceRules.prototype.SheetPIndexEditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var relRow = row % InterfaceRules._sheetPIndexRelRowCount;
            return !this._document.CommonRules.IsFooterRow(sheetId, row) && (relRow === 1 || relRow === 3);
        };
        InterfaceRules.prototype.SheetPIndexCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this._document.CommonRules.IsFooterRow(sheetId, row)) {
                switch (column) {
                    case 2:
                        return "Всего фонд оплаты труда в год";
                    case 3:
                        return "9010";
                    default:
                        if (column > 3) {
                            return this._document.CommonRules
                                .GetFooterSum(sheetId, row, column, InterfaceRules._sheetPIndexFooterSumOptions);
                        }
                }
            }
            else if (fieldId === BaseObasTableFields.StrCodeField.Id) {
                return this._document.CommonRules
                    .CalcRelRowCode(row, InterfaceRules._sheetPIndexRelRowCount, InterfaceRules._sheetPTotalCodeInfo);
            }
            return undefined;
        };
        InterfaceRules.prototype.SheetP4Sp5CalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetP4Sp5RelRowCount)) {
                if (column > 3) {
                    var relRow = row % InterfaceRules._sheetP4Sp5RelRowCount;
                    return this._document.CommonRules.GetFooterSum(sheetId, row, column, {
                        StartRow: relRow,
                        Step: InterfaceRules._sheetP4Sp5RelRowCount
                    });
                }
            }
            else {
                if (fieldId === BaseObasTableFields.StrCodeField.Id) {
                    return this._document.CommonRules
                        .CalcRelRowCode(row, InterfaceRules._sheetP4Sp5RelRowCount, InterfaceRules._sheetP4Sp5CodeInfo);
                }
                else if (column > 3) {
                    var relRow = row % InterfaceRules._sheetP4Sp5RelRowCount;
                    if (relRow === 2) {
                        return this.GetRelRowTotalFormula(row, column, InterfaceRules._sheetP4Sp5RelRowCount);
                    }
                }
            }
            return undefined;
        };
        InterfaceRules.prototype.SheetP4Sp5FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (this._document.CommonRules.IsFooterRow(sheetId, row, InterfaceRules._sheetP4Sp5RelRowCount)) {
                if (column > 3) {
                    return SheetFormatCollection.Calc;
                }
            }
            else {
                switch (column) {
                    case 2:
                    case 3:
                        return SheetFormatCollection.Default;
                    default:
                        var relRow = row % InterfaceRules._sheetP4Sp5RelRowCount;
                        if (relRow === 0) {
                            return SheetFormatCollection.Related;
                        }
                        else {
                            return SheetFormatCollection.Calc;
                        }
                }
            }
            return SheetFormatCollection.Default;
        };
        InterfaceRules.prototype.SheetP2Sp3CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP2Sp3Info);
        };
        InterfaceRules.prototype.SheetP2Sp3FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP2Sp3Info);
        };
        InterfaceRules.prototype.SheetP2Sp6CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP2Sp6Info);
        };
        InterfaceRules.prototype.SheetP2Sp6FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP2Sp6Info);
        };
        InterfaceRules.prototype.SheetP3Sp3CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP3Sp3Info);
        };
        InterfaceRules.prototype.SheetP3Sp3FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP3Sp3Info);
        };
        InterfaceRules.prototype.SheetP3Sp7CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP3Sp7Info);
        };
        InterfaceRules.prototype.SheetP3Sp7FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP3Sp7Info);
        };
        InterfaceRules.prototype.SheetP3Sp8CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP3Sp8Info);
        };
        InterfaceRules.prototype.SheetP3Sp8FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP3Sp8Info);
        };
        InterfaceRules.prototype.SheetP4Sp3CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP4Sp3Info);
        };
        InterfaceRules.prototype.SheetP4Sp3FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP4Sp3Info);
        };
        InterfaceRules.prototype.SheetP4Sp6CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP4Sp6Info);
        };
        InterfaceRules.prototype.SheetP4Sp6FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP4Sp6Info);
        };
        InterfaceRules.prototype.SheetP5Sp3CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP5Sp3Info);
        };
        InterfaceRules.prototype.SheetP5Sp3FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP5Sp3Info);
        };
        InterfaceRules.prototype.SheetP5Sp6CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP5Sp6Info);
        };
        InterfaceRules.prototype.SheetP5Sp6FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP5Sp6Info);
        };
        InterfaceRules.prototype.SheetP5Sp7CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this._document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP5Sp7Info);
        };
        InterfaceRules.prototype.SheetP5Sp7FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this._document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP5Sp7Info);
        };
        InterfaceRules.prototype.CheckDocumentBeforeSave = function () {
            if (this._document.CommonRules.CanSaveDocument()) {
                var topSumTable = this._document.TableP1;
                var kosguSprTable = ObasTableCollection.KosguSprTable;
                var data = [];
                var record211 = {
                    Key: kosguSprTable.LookupKeyByCode("211"),
                    Data: new Float32Array(ObasStageSettings.YearsCount)
                };
                data.push(record211);
                var record213 = {
                    Key: kosguSprTable.LookupKeyByCode("213"),
                    Data: new Float32Array(ObasStageSettings.YearsCount)
                };
                data.push(record213);
                if (topSumTable.Locate([BaseObasTableFields.TotalRowFlagField.Id], [1])) {
                    for (var i = 0; i < ObasStageSettings.YearsCount; i++) {
                        record211.Data[i] += topSumTable.GetFieldValue(F01280.ObasTableFields.FotYearDataField.GenerateId(i + 1));
                        record213.Data[i] += topSumTable
                            .GetFieldValue(F01280.ObasTableFields.InsuranceYearDataField.GenerateId(i + 1));
                    }
                }
                this._document.CommonRules.UpdateKosguTable(data);
                return this._document.CommonRules.CheckChangeType();
            }
            return false;
        };
        InterfaceRules.prototype.P3PositionFilter = function () {
            var result = ObasTableCollection.ConsularPositionsSprTable
                .IsActualRecord(this._document.Settings.ActiveYear);
            if (result && this._document.MainParametersTable.Foiv.Code === "310") {
                var regNum = ObasTableCollection.ConsularPositionsSprTable.RegNum.Value;
                result = regNum != null && regNum.length >= 2 && regNum.substr(0, 2) === "12";
            }
            return result;
        };
        InterfaceRules.prototype.ShiftDataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.ShiftData();
        };
        InterfaceRules.prototype.CopyDataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.CopyData();
        };
        InterfaceRules.prototype.RecalcDataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcData();
        };
        InterfaceRules.prototype.Recalc1DataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcDataPInsOnly();
        };
        InterfaceRules.prototype.Recalc2DataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcDataP2();
        };
        InterfaceRules.prototype.Recalc3DataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcDataP3();
        };
        InterfaceRules.prototype.Recalc4DataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcDataP4();
        };
        InterfaceRules.prototype.Recalc5DataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcDataP5();
        };
        InterfaceRules.prototype.RecalcTotalDataMenuItemClickEventHandler = function () {
            this._document.UpdateRules.RecalcDataP1Total();
        };
        InterfaceRules.prototype.CanEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return this._document.CommonRules
                .CantEditPrevCurYearsEditingCellEventHandler(sheetId, row, column, fieldId, rowLevel) && column > 1;
        };
        InterfaceRules.prototype.NpaSheetFormatEventHandler = function (sheetId, row, column, groupIndex) {
            switch (column) {
                case 1:
                    return SheetFormatCollection.Default;
                case 2:
                case 6:
                    return SheetFormatCollection.Spr;
                default:
                    return SheetFormatCollection.Free;
            }
        };
        InterfaceRules.prototype.NpaSheetCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (fieldId === BaseObasTableFields.StrCodeField.Id) {
                return ObasHelper.FillWithCharacter(row + 1, 3);
            }
            return undefined;
        };
        InterfaceRules.prototype.ObjectDescSheetFormatEventHandler = function (sheetId, row, column, groupIndex) {
            switch (column) {
                case 0:
                case 1:
                case 2:
                    return SheetFormatCollection.Related;
                case 8:
                    return SheetFormatCollection.Default;
                case 9:
                case 13:
                    return SheetFormatCollection.Spr;
                default:
                    return SheetFormatCollection.Free;
            }
        };
        InterfaceRules.prototype.ObjectDescSheetCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (BaseObasTableFields.StrCodeField.Equal(fieldId)) {
                return ObasHelper.FillWithCharacter(row + 1, 6);
            }
            return undefined;
        };
        InterfaceRules.prototype.ObjectDescSheetCanAddEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return column > 7;
        };
        InterfaceRules.prototype.ObjectDescSheetCanEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var table = this._document.Sheets.getValue(sheetId).Table;
            if (column > 7) {
                return table.GetKeyBySourceTable(this._document.P7RefObjDescNpaTable) != null;
            }
            else {
                return table.GetKeyBySourceTable(this._document.P7RefObjDescNpaTable.ParentTable) != null;
            }
        };
        InterfaceRules.prototype.ObjectDescSheetCanDeleteEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var table = this._document.Sheets.getValue(sheetId).Table;
            if (column > 7) {
                return table.GetKeyBySourceTable(this._document.P7RefObjDescNpaTable) != null;
            }
            else {
                return false;
            }
        };
        InterfaceRules.prototype.CountMonthForCalcSheetFormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column > 1) {
                return SheetFormatCollection.Free;
            }
            else {
                return SheetFormatCollection.Default;
            }
        };
        InterfaceRules.prototype.CountMonthForCalcSheetCanEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return column > 1;
        };
        InterfaceRules.prototype.FilterOKPD = function () {
            var okpdCode = ObasTableCollection.OkpdSprTable.Code.Value || "";
            return okpdCode.length >= 5;
        };
        InterfaceRules.prototype.FilterKosgu = function () {
            var kosguCode = ObasTableCollection.KosguSprTable.Code.Value || "";
            var analyticsDataTable = this._document.AnalyticsDataTable;
            return analyticsDataTable.Locate(analyticsDataTable.AnalyticCode.Id, kosguCode);
        };
        InterfaceRules.prototype.FilterNPAStatuses = function () {
            var npaStatusesTable = ObasTableCollection.NpaStatusesSprTable;
            return npaStatusesTable.RecordKey.Value === 1 || npaStatusesTable.RecordKey.Value === 2;
        };
        return InterfaceRules;
    }());
    InterfaceRules.TotalOrgRowName = "Итого по учреждению";
    InterfaceRules.TotalRowName = "Всего";
    InterfaceRules._sheetPTotalRelRowCount = 3;
    InterfaceRules._sheetPTotalTRowCount = InterfaceRules._sheetPTotalRelRowCount + 1;
    InterfaceRules._sheetPTotalFotRelRowCount = 4;
    InterfaceRules._sheetPTotalFotTRowCount = InterfaceRules._sheetPTotalFotRelRowCount + 1;
    InterfaceRules._sheetPIndexRelRowCount = 5;
    InterfaceRules._sheetP4Sp5RelRowCount = 3;
    InterfaceRules.SheetCodeInfo = {
        Column: 3,
        Length: 5,
        LevelIncs: [100, 1],
        CalcTotalCode: function () {
            return 90100;
        }
    };
    InterfaceRules._sheetP2Sp6CodeInfo = {
        Column: 3,
        Length: 6,
        LevelIncs: [100, 1],
        CalcTotalCode: function () {
            return 900100;
        }
    };
    InterfaceRules._sheetP3SpXCodeInfo = {
        Column: 5,
        Length: 5,
        LevelIncs: [100, 1],
        CalcTotalCode: function () {
            return 90100;
        }
    };
    InterfaceRules._sheetP4Sp5CodeInfo = {
        Column: 3,
        Length: 5,
        LevelIncs: [10, 1],
        CalcTotalCode: function () {
            return 90010;
        }
    };
    InterfaceRules._sheetPTotalCodeInfo = {
        Column: 3,
        Length: 4,
        LevelIncs: [10, 1],
        CalcTotalCode: function () {
            return 9000;
        }
    };
    InterfaceRules._sheetPIndexFooterSumOptions = {
        StartRow: InterfaceRules._sheetPIndexRelRowCount - 1,
        Step: InterfaceRules._sheetPIndexRelRowCount
    };
    InterfaceRules._totalRowInfo = {
        IsCalculated: false,
        Name: InterfaceRules.TotalRowName,
        Format: SheetFormatCollection.Default
    };
    InterfaceRules._subTotalRowInfo = {
        IsCalculated: false,
        Name: InterfaceRules.TotalOrgRowName,
        Format: SheetFormatCollection.Default
    };
    InterfaceRules._sprColConstAll = {
        Cell: { Type: SheetCellTypes.Spr },
        SubTotalRow: InterfaceRules._subTotalRowInfo,
        TotalRow: InterfaceRules._totalRowInfo
    };
    InterfaceRules.RelatedColConstAll = {
        Cell: { Type: SheetCellTypes.Related },
        SubTotalRow: InterfaceRules._subTotalRowInfo,
        TotalRow: InterfaceRules._totalRowInfo
    };
    InterfaceRules._sheetP2Sp3Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.SprColDefaultTotal,
            SheetColumnInfoCollection.FreeColDefaultTotal,
            InterfaceRules._sprColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP2Sp6Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules._sheetP2Sp6CodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            InterfaceRules.RelatedColConstAll,
            SheetColumnInfoCollection.CalcColFormatOnly,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP3Sp3Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.SprColDefaultTotal,
            SheetColumnInfoCollection.FreeColDefaultTotal,
            InterfaceRules._sprColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.RelatedColAllDefault,
            SheetColumnInfoCollection.RelatedColAllDefault,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP3Sp7CalcCol9AllX = {
        Cell: {
            Type: SheetCellTypes.Calc,
            FormulaId: BaseFormulas[BaseFormulas.SUM],
            SourceColumns: [10, 11, 12, 13]
        },
        TotalRow: SheetRowInfoCollection.XRow,
        SubTotalRow: SheetRowInfoCollection.XRow
    };
    InterfaceRules._sheetP3Sp7CalcCol14AllX = {
        Cell: {
            Type: SheetCellTypes.Calc,
            FormulaId: BaseFormulas[BaseFormulas.SUM],
            SourceColumns: [15, 16]
        },
        TotalRow: SheetRowInfoCollection.XRow,
        SubTotalRow: SheetRowInfoCollection.XRow
    };
    InterfaceRules._sheetP3Sp7Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules._sheetP3SpXCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColAllDefault,
            SheetColumnInfoCollection.RelatedColAllDefault,
            InterfaceRules.RelatedColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            InterfaceRules._sheetP3Sp7CalcCol9AllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            InterfaceRules._sheetP3Sp7CalcCol14AllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX
        ]
    };
    InterfaceRules._sheetP3Sp8Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules._sheetP3SpXCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColAllDefault,
            SheetColumnInfoCollection.RelatedColAllDefault,
            InterfaceRules.RelatedColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP4Sp3CalcCol5AllCalc = {
        Cell: {
            Type: SheetCellTypes.Calc,
            FormulaId: BaseFormulas[BaseFormulas.SUM],
            SourceColumns: [6, 7]
        },
        TotalRow: SheetRowInfoCollection.XRow,
        SubTotalRow: SheetRowInfoCollection.XRow
    };
    InterfaceRules._sheetP4Sp3Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.SprColDefaultTotal,
            SheetColumnInfoCollection.FreeColDefaultTotal,
            InterfaceRules._sprColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.FreeColAllCalc,
            InterfaceRules._sheetP4Sp3CalcCol5AllCalc,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP4Sp6Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            InterfaceRules.RelatedColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.CalcColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP5Sp3Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.SprColDefaultTotal,
            SheetColumnInfoCollection.FreeColDefaultTotal,
            InterfaceRules._sprColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.FreeColAllX,
            SheetColumnInfoCollection.CalcColAllX,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    InterfaceRules._sheetP5Sp6CalcCol6AllX = {
        Cell: {
            Type: SheetCellTypes.Calc,
            FormulaId: BaseFormulas[BaseFormulas.SUM],
            SourceColumns: [7, 8, 9, 10, 11]
        },
        TotalRow: SheetRowInfoCollection.XRow,
        SubTotalRow: SheetRowInfoCollection.XRow
    };
    InterfaceRules._sheetP5Sp6Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            InterfaceRules.RelatedColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.FreeColAllCalc,
            SheetColumnInfoCollection.RelatedColAllX,
            InterfaceRules._sheetP5Sp6CalcCol6AllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX,
            SheetColumnInfoCollection.RelatedColAllX
        ]
    };
    InterfaceRules._sheetP5Sp7Info = {
        MaxLevel: 2,
        CodeInfo: InterfaceRules.SheetCodeInfo,
        ColumnsInfo: [
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            SheetColumnInfoCollection.RelatedColDefaultTotal,
            InterfaceRules.RelatedColConstAll,
            SheetColumnInfoCollection.AllDefault,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.RelatedColAllCalc,
            SheetColumnInfoCollection.CalcColAllCalc
        ]
    };
    F01280.InterfaceRules = InterfaceRules;
    var GroupSheetTyped = (function () {
        function GroupSheetTyped(_document) {
            this._document = _document;
        }
        Object.defineProperty(GroupSheetTyped.prototype, "Document", {
            get: function () {
                return this._document;
            },
            enumerable: true,
            configurable: true
        });
        GroupSheetTyped.prototype.GetSheetFromParam = function (param) {
            if (param instanceof Sheet) {
                return param;
            }
            else if (typeof param === "string") {
                return this._document.Sheets.getValue(param);
            }
            throw new Error("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u044C Sheet");
        };
        GroupSheetTyped.prototype.ReadOnlyEventHandler = function (sheetId, isReadOnly) {
            return ObasStageSettings.BlockCurrentYear && (this.Document.Settings.ActiveYear <= ObasStageSettings.CurrentYear);
        };
        Object.defineProperty(GroupSheetTyped.prototype, "YearsCount", {
            get: function () {
                return this.Document.Settings.YearsCount;
            },
            enumerable: true,
            configurable: true
        });
        return GroupSheetTyped;
    }());
    var YearGroupSheetTyped = (function (_super) {
        __extends(YearGroupSheetTyped, _super);
        function YearGroupSheetTyped() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        YearGroupSheetTyped.prototype.ActivateSheetEventHandler = function (sheetId) {
            this.Document.Settings.SetActiveYear(ObasHelper.GetYearOffsetById(sheetId));
        };
        YearGroupSheetTyped.prototype.GetTableFromParam = function (param) {
            if (param instanceof Table) {
                return param;
            }
            else if (typeof param === "string") {
                return this.Document.Tables.getValue(param);
            }
            throw new Error("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u044C Table");
        };
        YearGroupSheetTyped.prototype.FilterTableByYear = function (param, year) {
            var realTable = this.GetTableFromParam(param);
            return realTable.GetFieldValue(BaseObasTableFields.YearField.Id) === year;
        };
        YearGroupSheetTyped.prototype.GetSheetYear = function (sheetId) {
            var yearOffset = ObasHelper.GetYearOffsetById(sheetId);
            return ObasStageSettings.CurrentYear + (yearOffset == null ? 0 : yearOffset);
        };
        YearGroupSheetTyped.prototype.ViewLoadEventHandler = function (tableId, sourceTableId) {
            return this.FilterTableByYear(tableId, this.Document.Settings.ActiveYear);
        };
        YearGroupSheetTyped.prototype.CreateCaptionEventHandler = function (sheetId, oldText) {
            var sheetYear = this.GetSheetYear(sheetId);
            oldText = oldText.replace(DocumentSettings.YearSign, sheetYear.toString());
            oldText = oldText.replace(DocumentSettings.YearSignIndex, (sheetYear - this.Document.Settings.StartYear + 1).toString());
            return oldText;
        };
        return YearGroupSheetTyped;
    }(GroupSheetTyped));
    var HierarchyYearGroupSheetTyped = (function (_super) {
        __extends(HierarchyYearGroupSheetTyped, _super);
        function HierarchyYearGroupSheetTyped() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        HierarchyYearGroupSheetTyped.prototype.StandardCalcStrCode = function (param, row, column, info) {
            var sheet = this.GetSheetFromParam(param);
            var curLvl = sheet.GetRowLevel(row) - 1;
            var lvlInc = curLvl > 0 ? info.LevelIncs[curLvl - 1] : 0;
            var prevLvl = -1;
            var prevCode = 0;
            var curCode;
            if (row > 0) {
                prevLvl = sheet.GetRowLevel(row - 1) - 1;
                prevCode = parseInt(sheet.GetCellValue(row - 1, column), 10);
            }
            if (prevLvl === curLvl) {
                curCode = prevCode + lvlInc;
            }
            else if (curLvl === 0) {
                curCode = info.CalcTotalCode(sheet, row, column);
            }
            else {
                if (lvlInc === 0) {
                    curCode = 0;
                }
                else {
                    curCode = (((prevCode / lvlInc) | 0) + 1) * lvlInc;
                }
            }
            return ObasHelper.FillWithCharacter(curCode.toString(), info.Length);
        };
        HierarchyYearGroupSheetTyped.prototype.InitCustomStandardcalcResult = function (row, cellInfo) {
            var result = new SheetCalcResult(cellInfo.FormulaId);
            var columns = cellInfo.SourceColumns;
            for (var i = 0; i < columns.length; i++) {
                result.AddCoordinates(new CellCoordinate(row, columns[i]));
            }
            return result.ToArray();
        };
        HierarchyYearGroupSheetTyped.prototype.StandardCalc = function (param, row, column, info) {
            var sheet = this.GetSheetFromParam(param);
            if (column === info.CodeInfo.Column) {
                return this.StandardCalcStrCode(sheet, row, column, info.CodeInfo);
            }
            else {
                var curLvl = sheet.GetRowLevel(row) - 1;
                var columnInfo = info.ColumnsInfo[column];
                if (columnInfo != null) {
                    if (columnInfo.SubTotalRow instanceof Array) {
                        if (columnInfo.SubTotalRow.length < info.MaxLevel - 1) {
                            throw Error("Must add rowInfo for " + (info.MaxLevel - 1 - columnInfo.SubTotalRow.length) + " levels for column " + (column + 1));
                        }
                    }
                    var cellInfo = columnInfo.Cell;
                    var result = void 0;
                    if (curLvl === info.MaxLevel) {
                        if (cellInfo.FormulaId != null) {
                            return this.InitCustomStandardcalcResult(row, cellInfo);
                        }
                    }
                    else {
                        var rowInfo = void 0;
                        if (curLvl === 0) {
                            rowInfo = columnInfo.TotalRow;
                        }
                        else {
                            if (columnInfo.SubTotalRow instanceof Array) {
                                rowInfo = columnInfo.SubTotalRow[curLvl - 1];
                            }
                            else {
                                var temp = columnInfo.SubTotalRow;
                                rowInfo = temp;
                            }
                        }
                        if (!rowInfo.IsCalculated && rowInfo.Name != null) {
                            return rowInfo.Name;
                        }
                        else if (rowInfo.IsCalculated) {
                            if (cellInfo.FormulaId) {
                                return this.InitCustomStandardcalcResult(row, cellInfo);
                            }
                            else {
                                result = new SheetCalcResult(BaseFormulas.SUM);
                                result.AddCoordinates(sheet.GetChildRows(row, column));
                                return result.ToArray();
                            }
                        }
                    }
                }
            }
            return undefined;
        };
        HierarchyYearGroupSheetTyped.prototype.StandardFormat = function (param, row, column, info) {
            var sheet = this.GetSheetFromParam(param);
            var curLvl = sheet.GetRowLevel(row) - 1;
            var columnInfo = info.ColumnsInfo[column];
            if (columnInfo != null) {
                if (columnInfo.SubTotalRow instanceof Array) {
                    if (columnInfo.SubTotalRow.length < info.MaxLevel - 1) {
                        throw Error("Must add rowInfo for " + (info.MaxLevel - 1 - columnInfo.SubTotalRow.length) + " levels for column " + (column + 1));
                    }
                }
                if (curLvl === info.MaxLevel) {
                    var cellInfo = columnInfo.Cell;
                    if (cellInfo.Format != null) {
                        return cellInfo.Format;
                    }
                    else {
                        return SheetFormatCollection.GetFormat(cellInfo.Type);
                    }
                }
                var rowInfo = void 0;
                if (curLvl === 0) {
                    rowInfo = columnInfo.TotalRow;
                }
                else {
                    if (columnInfo.SubTotalRow instanceof Array) {
                        rowInfo = columnInfo.SubTotalRow[curLvl - 1];
                    }
                    else {
                        var temp = columnInfo.SubTotalRow;
                        rowInfo = temp;
                    }
                }
                if (rowInfo.Format != null) {
                    return rowInfo.Format;
                }
                else {
                    return SheetFormatCollection.Calc;
                }
            }
            return SheetFormatCollection.Default;
        };
        HierarchyYearGroupSheetTyped.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this.StandardCalc(sheetId, row, column, this.SheetInfo);
        };
        HierarchyYearGroupSheetTyped.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this.StandardFormat(sheetId, row, column, this.SheetInfo);
        };
        return HierarchyYearGroupSheetTyped;
    }(YearGroupSheetTyped));
    var BaseGroupSheet = (function (_super) {
        __extends(BaseGroupSheet, _super);
        function BaseGroupSheet(document, _rowCodeColumn, _relRowCount, _totalRowCount) {
            if (_relRowCount === void 0) { _relRowCount = 1; }
            if (_totalRowCount === void 0) { _totalRowCount = _relRowCount; }
            var _this = _super.call(this, document) || this;
            _this._rowCodeColumn = _rowCodeColumn;
            _this._relRowCount = _relRowCount;
            _this._totalRowCount = _totalRowCount;
            _this._strNameColumn = _this._rowCodeColumn - 1;
            return _this;
        }
        BaseGroupSheet.prototype.IsFooterRow = function (sheetId, row) {
            return this.Document.CommonRules.IsFooterRow(sheetId, row, this._totalRowCount);
        };
        Object.defineProperty(BaseGroupSheet.prototype, "StartDataColumn", {
            get: function () {
                return this.RowCodeColumn + 1;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseGroupSheet.prototype, "RowCodeColumn", {
            get: function () {
                return this._rowCodeColumn;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseGroupSheet.prototype, "RowNameColumn", {
            get: function () {
                return this._strNameColumn;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseGroupSheet.prototype, "RelRowCount", {
            get: function () {
                return this._relRowCount;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseGroupSheet.prototype, "TotalRowCount", {
            get: function () {
                return this._totalRowCount;
            },
            enumerable: true,
            configurable: true
        });
        BaseGroupSheet.prototype.CalcRelRow = function (row) {
            return row % this._relRowCount;
        };
        BaseGroupSheet.prototype.CalcStartFooterRow = function (sheetId) {
            return this.GetSheetFromParam(sheetId).RowCount - this.TotalRowCount;
        };
        BaseGroupSheet.prototype.CalcOffsetCol = function (column) {
            return column - (this._rowCodeColumn + 1);
        };
        BaseGroupSheet.prototype.IsDataColumn = function (column) {
            return this.CalcOffsetCol(column) >= 0;
        };
        BaseGroupSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (this.IsFooterRow(sheetId, row)) {
                if (column > this.RowCodeColumn) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Default;
                }
            }
            else {
                switch (column) {
                    case this.RowCodeColumn:
                    case this.RowNameColumn:
                        return SheetFormatCollection.Default;
                    default:
                        if (column < this.RowNameColumn) {
                            return SheetFormatCollection.Related;
                        }
                }
            }
            return SheetFormatCollection.Default;
        };
        return BaseGroupSheet;
    }(GroupSheetTyped));
    F01280.BaseGroupSheet = BaseGroupSheet;
    var TotalSheetColumnBlocks;
    (function (TotalSheetColumnBlocks) {
        TotalSheetColumnBlocks[TotalSheetColumnBlocks["Total"] = 0] = "Total";
        TotalSheetColumnBlocks[TotalSheetColumnBlocks["FotTotal"] = 1] = "FotTotal";
        TotalSheetColumnBlocks[TotalSheetColumnBlocks["UsdFot"] = 2] = "UsdFot";
        TotalSheetColumnBlocks[TotalSheetColumnBlocks["RubFot"] = 3] = "RubFot";
        TotalSheetColumnBlocks[TotalSheetColumnBlocks["Insurance"] = 4] = "Insurance";
    })(TotalSheetColumnBlocks = F01280.TotalSheetColumnBlocks || (F01280.TotalSheetColumnBlocks = {}));
    var FotInsTotalSheet = (function (_super) {
        __extends(FotInsTotalSheet, _super);
        function FotInsTotalSheet(document, rowCodeColumn, relRowCount, totalRowCount) {
            return _super.call(this, document, rowCodeColumn, relRowCount, totalRowCount) || this;
        }
        FotInsTotalSheet.prototype.CalcDataColumnBlock = function (column) {
            return (this.CalcOffsetCol(column) / this.YearsCount) | 0;
        };
        FotInsTotalSheet.prototype.InDataColumnBlock = function (column, block) {
            return ((this.CalcDataColumnBlock(column) === block) && this.IsDataColumn(column));
        };
        FotInsTotalSheet.prototype.IsTotalColumn = function (column) {
            return this.InDataColumnBlock(column, TotalSheetColumnBlocks.Total);
        };
        FotInsTotalSheet.prototype.IsTotalFotColumn = function (column) {
            return this.InDataColumnBlock(column, TotalSheetColumnBlocks.FotTotal);
        };
        FotInsTotalSheet.prototype.IsUsdFotColumn = function (column) {
            return this.InDataColumnBlock(column, TotalSheetColumnBlocks.UsdFot);
        };
        FotInsTotalSheet.prototype.IsRubFotColumn = function (column) {
            return this.InDataColumnBlock(column, TotalSheetColumnBlocks.RubFot);
        };
        FotInsTotalSheet.prototype.IsFotColumn = function (column) {
            return this.IsDataColumn(column) && !this.IsTotalColumn(column) && !this.IsInsuranceColumn(column);
        };
        FotInsTotalSheet.prototype.IsInsuranceColumn = function (column) {
            return this.InDataColumnBlock(column, TotalSheetColumnBlocks.Insurance);
        };
        FotInsTotalSheet.prototype.IsFotInsDataColumn = function (column) {
            return this.CalcOffsetCol(column) >= this.YearsCount * TotalSheetColumnBlocks.UsdFot;
        };
        FotInsTotalSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (this.IsTotalColumn(column) || this.IsTotalFotColumn(column)) {
                return SheetFormatCollection.Calc;
            }
            else if (!this.IsFooterRow(sheetId, row) && this.IsUsdFotColumn(column)) {
                return SheetFormatCollection.Related;
            }
            return _super.prototype.FormatEventHandler.call(this, sheetId, row, column, groupIndex);
        };
        FotInsTotalSheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this.IsTotalColumn(column)) {
                var result = new SheetCalcResult(BaseFormulas.SUM);
                result.AddCoordinates(new CellCoordinate(row, column + this.YearsCount));
                result.AddCoordinates(new CellCoordinate(row, column + this.YearsCount * TotalSheetColumnBlocks.Insurance));
                return result.ToArray();
            }
            else if (this.IsTotalFotColumn(column)) {
                var result = new SheetCalcResult(BaseFormulas.SUM);
                result.AddCoordinates(new CellCoordinate(row, column + this.YearsCount));
                result.AddCoordinates(new CellCoordinate(row, column + this.YearsCount * 2));
                return result.ToArray();
            }
            return undefined;
        };
        FotInsTotalSheet.prototype.GetTotalYearsCaptionEventHandler = function (tableId, index, defaultCaption, fieldCaption) {
            var formulaParts = [];
            var realStartDataColumn = this.StartDataColumn + index + 1;
            var yearsCount = this.YearsCount;
            formulaParts.push("\u0433\u0440. " + (realStartDataColumn + yearsCount * TotalSheetColumnBlocks.FotTotal));
            formulaParts.push("\u0433\u0440. " + (realStartDataColumn + yearsCount * TotalSheetColumnBlocks.Insurance));
            return "\u043D\u0430 " + (ObasStageSettings.CurrentYear + index) + " \u0433\u043E\u0434\n(" + formulaParts.join(" + ") + ")";
        };
        FotInsTotalSheet.prototype.GetTotalFotYearsCaptionEventHandler = function (tableId, index, defaultCaption, fieldCaption) {
            return this.Document.CommonRules.CalcColumnCaption(index, this.StartDataColumn + this.YearsCount * TotalSheetColumnBlocks.UsdFot + 1, 2);
        };
        return FotInsTotalSheet;
    }(BaseGroupSheet));
    F01280.FotInsTotalSheet = FotInsTotalSheet;
    var P1SheetRows;
    (function (P1SheetRows) {
        P1SheetRows[P1SheetRows["P2"] = 0] = "P2";
        P1SheetRows[P1SheetRows["P3"] = 1] = "P3";
        P1SheetRows[P1SheetRows["P4"] = 2] = "P4";
        P1SheetRows[P1SheetRows["P5"] = 3] = "P5";
        P1SheetRows[P1SheetRows["OnlyIns"] = 4] = "OnlyIns";
        P1SheetRows[P1SheetRows["Correction"] = 5] = "Correction";
        P1SheetRows[P1SheetRows["Total"] = 6] = "Total";
    })(P1SheetRows || (P1SheetRows = {}));
    var P1Sheet = (function (_super) {
        __extends(P1Sheet, _super);
        function P1Sheet(document) {
            return _super.call(this, document, 1, 1) || this;
        }
        P1Sheet.prototype.IsXCell = function (row, column) {
            return ((row === P1SheetRows.OnlyIns && this.IsFotColumn(column)));
        };
        P1Sheet.prototype.IsCorrectionCell = function (row, column) {
            var offsetCol = this.CalcOffsetCol(column);
            return ((row === P1SheetRows.Correction) && (offsetCol > 0) && this.IsFotInsDataColumn(column));
        };
        P1Sheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (!this.IsFooterRow(sheetId, row)) {
                if (this.IsXCell(row, column)) {
                    return SheetFormatCollection.Default;
                }
                else if (this.IsCorrectionCell(row, column)) {
                    return SheetFormatCollection.Free;
                }
                else if (this.IsFotInsDataColumn(column)) {
                    return SheetFormatCollection.Related;
                }
            }
            return _super.prototype.FormatEventHandler.call(this, sheetId, row, column, groupIndex);
        };
        P1Sheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            var _this = this;
            if (this.IsFooterRow(sheetId, row)) {
                if (this.IsDataColumn(column)) {
                    return this.Document.CommonRules.GetFooterSum(sheetId, row, column, {
                        Filter: function (inSheet, inRow, inColumn) {
                            return _this.IsXCell(inRow, inColumn);
                        }
                    });
                }
            }
            else {
                if (this.IsXCell(row, column)) {
                    return ObasHelper.X;
                }
                else if (this.IsCorrectionCell(row, column)) {
                    return undefined;
                }
            }
            return _super.prototype.CalcEventHandler.call(this, sheetId, row, column, fieldId);
        };
        P1Sheet.prototype.EditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return this.IsCorrectionCell(row, column);
        };
        return P1Sheet;
    }(FotInsTotalSheet));
    F01280.P1Sheet = P1Sheet;
    var PxTotalSheetRelRows;
    (function (PxTotalSheetRelRows) {
        PxTotalSheetRelRows[PxTotalSheetRelRows["Fot"] = 0] = "Fot";
        PxTotalSheetRelRows[PxTotalSheetRelRows["Change"] = 1] = "Change";
        PxTotalSheetRelRows[PxTotalSheetRelRows["Total"] = 2] = "Total";
    })(PxTotalSheetRelRows || (PxTotalSheetRelRows = {}));
    var PxTotalSheet = (function (_super) {
        __extends(PxTotalSheet, _super);
        function PxTotalSheet(document, _isEditCorrection, _correctionVal, _propName) {
            var _this = _super.call(this, document, 3, PxTotalSheet._relRowCount, PxTotalSheet._totalRowCount) || this;
            _this._isEditCorrection = _isEditCorrection;
            _this._correctionVal = _correctionVal;
            _this._propName = _propName;
            _this._codeInfo = null;
            return _this;
        }
        Object.defineProperty(PxTotalSheet.prototype, "CodeInfo", {
            get: function () {
                if (this._codeInfo == null) {
                    this._codeInfo = {
                        Column: this.RowCodeColumn,
                        Length: 4,
                        LevelIncs: [10, 1],
                        CalcTotalCode: function () {
                            return 9000;
                        }
                    };
                }
                return this._codeInfo;
            },
            enumerable: true,
            configurable: true
        });
        PxTotalSheet.prototype.CorrectionFormula = function (fotVal, changeVal) {
            return ((fotVal || 0) + (changeVal || 0)) * this._correctionVal * -1;
        };
        PxTotalSheet.prototype.IsCorrectionRow = function (sheetId, row) {
            return row === (this.GetSheetFromParam(sheetId).RowCount - 2);
        };
        PxTotalSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (this.IsFotInsDataColumn(column)) {
                if (this.IsFooterRow(sheetId, row)) {
                    if (this.IsCorrectionRow(sheetId, row)) {
                        return this._isEditCorrection ? SheetFormatCollection.Free : SheetFormatCollection.Calc;
                    }
                }
                else {
                    var relRow = this.CalcRelRow(row);
                    switch (relRow) {
                        case PxTotalSheetRelRows.Fot:
                            return SheetFormatCollection.Related;
                        case PxTotalSheetRelRows.Change:
                            if (this.IsUsdFotColumn(column)) {
                                return SheetFormatCollection.Related;
                            }
                            else {
                                return SheetFormatCollection.Free;
                            }
                        case PxTotalSheetRelRows.Total:
                            return SheetFormatCollection.Calc;
                    }
                }
            }
            return _super.prototype.FormatEventHandler.call(this, sheetId, row, column, groupIndex);
        };
        PxTotalSheet.prototype.GetTotalFormula = function (row, column, childCount) {
            var result = new SheetCalcResult(BaseFormulas.SUM);
            for (var i = 1; i < childCount; i++) {
                result.AddCoordinates(new CellCoordinate(row - i, column));
            }
            return result.ToArray();
        };
        PxTotalSheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this.IsFooterRow(sheetId, row)) {
                if (this.IsFotInsDataColumn(column)) {
                    var rowCount = this.GetSheetFromParam(sheetId).RowCount;
                    switch (row) {
                        case rowCount - 1:
                            return this.GetTotalFormula(row, column, this.TotalRowCount);
                        case rowCount - 2:
                            if (this._isEditCorrection) {
                                return undefined;
                            }
                            else {
                                var result = new SheetCalcResult("%Doc%." + this._propName + ".CorrectionFormula");
                                result.AddCoordinates(new CellCoordinate(row - 1, column));
                                result.AddCoordinates(new CellCoordinate(row - 2, column));
                                return result.ToArray();
                            }
                            ;
                        default:
                            return this.Document.CommonRules.GetFooterSum(sheetId, row, column, {
                                EndRow: rowCount - this.TotalRowCount,
                                StartRow: this.CalcRelRow(row),
                                Step: this.RelRowCount
                            });
                    }
                }
            }
            else {
                if (this.IsFotInsDataColumn(column)) {
                    if (this.CalcRelRow(row) === PxTotalSheetRelRows.Total) {
                        return this.GetTotalFormula(row, column, this.RelRowCount);
                    }
                }
                else if (column === this.RowCodeColumn) {
                    return this.Document.CommonRules.CalcRelRowCode(row, this.RelRowCount, this.CodeInfo);
                }
            }
            return _super.prototype.CalcEventHandler.call(this, sheetId, row, column, fieldId);
        };
        PxTotalSheet.prototype.EditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var relRow = this.CalcRelRow(row);
            return ((relRow === PxTotalSheetRelRows.Change && (this.IsRubFotColumn(column) || this.IsInsuranceColumn(column))) ||
                (this._isEditCorrection && this.IsCorrectionRow(sheetId, row) && this.IsFotInsDataColumn(column)));
        };
        return PxTotalSheet;
    }(FotInsTotalSheet));
    PxTotalSheet._relRowCount = ObasHelper.GetEnumLength(PxTotalSheetRelRows);
    PxTotalSheet._totalRowCount = PxTotalSheet._relRowCount + 1;
    F01280.PxTotalSheet = PxTotalSheet;
    var P2Sp6Sheet = (function (_super) {
        __extends(P2Sp6Sheet, _super);
        function P2Sp6Sheet() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._sheetInfo = {
                MaxLevel: 2,
                CodeInfo: P2Sp6Sheet._sheetCodeInfo,
                ColumnsInfo: [
                    SheetColumnInfoCollection.RelatedColDefaultTotal,
                    SheetColumnInfoCollection.RelatedColDefaultTotal,
                    InterfaceRules.RelatedColConstAll,
                    SheetColumnInfoCollection.AllDefault
                ]
            };
            _this._fullSheetInfo = null;
            return _this;
        }
        Object.defineProperty(P2Sp6Sheet.prototype, "SheetInfo", {
            get: function () {
                var _this = this;
                if (this._fullSheetInfo == null) {
                    this._fullSheetInfo = this._sheetInfo;
                    var insertColumns = function () {
                        var columnInfos = [];
                        for (var _i = 0; _i < arguments.length; _i++) {
                            columnInfos[_i] = arguments[_i];
                        }
                        var _loop_1 = function (columnInfo) {
                            _this.Document.IterateByYears(function () {
                                _this._fullSheetInfo.ColumnsInfo.push(columnInfo);
                            });
                        };
                        for (var _a = 0, columnInfos_1 = columnInfos; _a < columnInfos_1.length; _a++) {
                            var columnInfo = columnInfos_1[_a];
                            _loop_1(columnInfo);
                        }
                    };
                    insertColumns(SheetColumnInfoCollection.FreeColAllCalc, SheetColumnInfoCollection.RelatedColAllX, SheetColumnInfoCollection.CalcColAllCalc);
                }
                return this._fullSheetInfo;
            },
            enumerable: true,
            configurable: true
        });
        P2Sp6Sheet.prototype.GetYearsCaptionEventHandler = function (tableId, index, defaultCaption, fieldCaption) {
            var formulaParts = [];
            var realStartDataColumn = P2Sp6Sheet._sheetCodeInfo.Column + 2 + index;
            var yearsCount = this.YearsCount;
            for (var i = 0; i < 2; i++) {
                formulaParts.push("\u0433\u0440. " + (realStartDataColumn + yearsCount * i));
            }
            formulaParts.push("\u0433\u0440. " + (index + 3) + " \u0440\u0430\u0437\u0434. 8");
            return "\u043D\u0430 " + (ObasStageSettings.CurrentYear + index) + " \u0433\u043E\u0434\n(" + formulaParts.join(" * ") + ")";
        };
        return P2Sp6Sheet;
    }(HierarchyYearGroupSheetTyped));
    P2Sp6Sheet._sheetCodeInfo = {
        Column: 3,
        Length: 6,
        LevelIncs: [100, 1],
        CalcTotalCode: function () {
            return 900100;
        }
    };
    F01280.P2Sp6Sheet = P2Sp6Sheet;
    var ExecWritsSheetColumnBlocks;
    (function (ExecWritsSheetColumnBlocks) {
        ExecWritsSheetColumnBlocks[ExecWritsSheetColumnBlocks["UsdFot"] = 0] = "UsdFot";
        ExecWritsSheetColumnBlocks[ExecWritsSheetColumnBlocks["Total"] = 1] = "Total";
    })(ExecWritsSheetColumnBlocks || (ExecWritsSheetColumnBlocks = {}));
    var ExecWritsSheet = (function (_super) {
        __extends(ExecWritsSheet, _super);
        function ExecWritsSheet(id, document) {
            return _super.call(this, id, document, 2) || this;
        }
        ExecWritsSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (this.IsFooterRow(row)) {
                if (this.IsDataColumn(column)) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Default;
                }
            }
            else {
                if (column < this.RowCodeColumn) {
                    return SheetFormatCollection.Spr;
                }
                else if (column === this.RowCodeColumn) {
                    return SheetFormatCollection.Default;
                }
                else {
                    if (this.IsColumnInDataBlock(column, ExecWritsSheetColumnBlocks.Total)) {
                        return SheetFormatCollection.Calc;
                    }
                    else {
                        return SheetFormatCollection.Free;
                    }
                }
            }
        };
        ExecWritsSheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this.IsFooterRow(row)) {
                switch (column) {
                    case this.RowNameColumn:
                        return ExecWritsSheet._totalRowName;
                    case this.RowCodeColumn:
                        return ExecWritsSheet._totalRowCode;
                    default:
                        if (this.IsDataColumn(column)) {
                            return this.Document.CommonRules.GetFooterSum(sheetId, row, column);
                        }
                }
            }
            else if (column === this.RowCodeColumn) {
                return ObasHelper.FillWithCharacter(row + 1, ExecWritsSheet._codeLength);
            }
            return undefined;
        };
        ExecWritsSheet._totalRowName = "\u0418\u0442\u043E\u0433\u043E";
        ExecWritsSheet._totalRowCode = "90100";
        ExecWritsSheet._codeLength = 5;
        return ExecWritsSheet;
    }(YearsSheet));
    F01280.ExecWritsSheet = ExecWritsSheet;
    var InsuranceGroupSheet = (function (_super) {
        __extends(InsuranceGroupSheet, _super);
        function InsuranceGroupSheet() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._insuranceSheets = new collections.Dictionary();
            return _this;
        }
        InsuranceGroupSheet.prototype.GetInsuranceSheet = function (sheetId) {
            var result = this._insuranceSheets.getValue(sheetId);
            if (result == null) {
                result = new OrgInsuranceSheet(sheetId, this.Document, InterfaceRules.SheetCodeInfo, InterfaceRules.TotalOrgRowName, 100);
                this._insuranceSheets.setValue(sheetId, result);
            }
            return result;
        };
        InsuranceGroupSheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this.GetInsuranceSheet(sheetId).CalcEventHandler(sheetId, row, column, fieldId);
        };
        InsuranceGroupSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this.GetInsuranceSheet(sheetId).FormatEventHandler(sheetId, row, column, groupIndex);
        };
        InsuranceGroupSheet.prototype.EditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return this.GetInsuranceSheet(sheetId).EditingCellEventHandler(sheetId, row, column, fieldId, rowLevel);
        };
        return InsuranceGroupSheet;
    }(GroupSheetTyped));
    F01280.InsuranceGroupSheet = InsuranceGroupSheet;
    var AnalyticSheet = (function (_super) {
        __extends(AnalyticSheet, _super);
        function AnalyticSheet(id, _document) {
            var _this = _super.call(this, id, false) || this;
            _this._document = _document;
            return _this;
        }
        AnalyticSheet.prototype.IsTotal = function (row) {
            return (row === 0 || row === 1 || row === 4 || row === 7 || row === 9 || row === 11);
        };
        AnalyticSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column > AnalyticSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Free;
                }
            }
            else {
                return SheetFormatCollection.Default;
            }
        };
        AnalyticSheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            if (column > AnalyticSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    var result = new SheetCalcResult(BaseFormulas.SUM);
                    switch (row) {
                        case 0:
                            for (var i = 1; i < this.RowCount; i++) {
                                if (!this.IsTotal(i)) {
                                    result.AddCoordinates(new CellCoordinate(i, column));
                                }
                            }
                            break;
                        case 1:
                            for (var i = 2; i < 4; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                        case 4:
                            for (var i = 5; i < 7; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                        case 7:
                            result.AddCoordinates(new CellCoordinate(8, column));
                            break;
                        case 9:
                            result.AddCoordinates(new CellCoordinate(10, column));
                            break;
                        case 11:
                            for (var i = 12; i < this.RowCount; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                    }
                    return result.ToArray();
                }
            }
            return undefined;
        };
        AnalyticSheet.prototype.CanEditCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return ((column > AnalyticSheet._strCodeColumn) && !this.IsTotal(row));
        };
        AnalyticSheet._strCodeColumn = 1;
        return AnalyticSheet;
    }(Sheet));
    F01280.AnalyticSheet = AnalyticSheet;
    var BaseHierarchySheet = (function (_super) {
        __extends(BaseHierarchySheet, _super);
        function BaseHierarchySheet() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        BaseHierarchySheet.prototype.EditCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return column > 0;
        };
        BaseHierarchySheet.TotalRecBudgFundRowName = "\u0418\u0442\u043E\u0433\u043E \u043F\u043E \u0441\u0442\u0440\u0430\u043D\u0435";
        BaseHierarchySheet._totalRowName = "\u0412\u0441\u0435\u0433\u043E";
        BaseHierarchySheet._totalObjRowName = "\u0418\u0442\u043E\u0433\u043E \u043F\u043E \u043E\u0431\u044A\u0435\u043A\u0442\u0443 \u0437\u0430\u043A\u0443\u043F\u043A\u0438";
        BaseHierarchySheet._totalRowInfo = {
            IsCalculated: false,
            Name: BaseHierarchySheet._totalRowName,
            Format: SheetFormatCollection.Default
        };
        BaseHierarchySheet._totalObjRowInfo = {
            IsCalculated: false,
            Name: BaseHierarchySheet._totalObjRowName,
            Format: SheetFormatCollection.Default
        };
        BaseHierarchySheet._totalRecBudgFundRowInfo = {
            IsCalculated: false,
            Name: BaseHierarchySheet.TotalRecBudgFundRowName,
            Format: SheetFormatCollection.Default
        };
        BaseHierarchySheet._subTotalRowInfos = [
            BaseHierarchySheet._totalRecBudgFundRowInfo, BaseHierarchySheet._totalObjRowInfo
        ];
        BaseHierarchySheet.SprDefaultTotalFirstSubtotal = {
            Cell: { Type: SheetCellTypes.Spr },
            SubTotalRow: [SheetRowInfoCollection.Default, SheetRowInfoCollection.SprOnlyFormatRow],
            TotalRow: SheetRowInfoCollection.Default
        };
        BaseHierarchySheet.RelatedDefaultTotalFirstSubtotal = {
            Cell: { Type: SheetCellTypes.Related },
            SubTotalRow: [SheetRowInfoCollection.Default, SheetRowInfoCollection.SprOnlyFormatRow],
            TotalRow: SheetRowInfoCollection.Default
        };
        BaseHierarchySheet.SprColConstAll = {
            Cell: { Type: SheetCellTypes.Spr },
            SubTotalRow: BaseHierarchySheet._subTotalRowInfos,
            TotalRow: BaseHierarchySheet._totalRowInfo
        };
        BaseHierarchySheet.RelatedColConstAll = {
            Cell: { Type: SheetCellTypes.Related },
            SubTotalRow: BaseHierarchySheet._subTotalRowInfos,
            TotalRow: BaseHierarchySheet._totalRowInfo
        };
        BaseHierarchySheet.FreeColConstAll = {
            Cell: { Type: SheetCellTypes.Free },
            SubTotalRow: BaseHierarchySheet._subTotalRowInfos,
            TotalRow: BaseHierarchySheet._totalRowInfo
        };
        BaseHierarchySheet.DefaultColConstAll = {
            Cell: { Type: SheetCellTypes.Default },
            SubTotalRow: BaseHierarchySheet._subTotalRowInfos,
            TotalRow: BaseHierarchySheet._totalRowInfo
        };
        BaseHierarchySheet._CodeInfo = {
            Column: 10,
            Length: 6,
            LevelIncs: [10000, 100, 1],
            CalcTotalCode: function () {
                return 900000;
            }
        };
        return BaseHierarchySheet;
    }(HierarchyYearGroupSheet));
    F01280.BaseHierarchySheet = BaseHierarchySheet;
    var UsdSheetColumnBlocks;
    (function (UsdSheetColumnBlocks) {
        UsdSheetColumnBlocks[UsdSheetColumnBlocks["Usd"] = 0] = "Usd";
        UsdSheetColumnBlocks[UsdSheetColumnBlocks["Rub"] = 1] = "Rub";
        UsdSheetColumnBlocks[UsdSheetColumnBlocks["OtherRub"] = 2] = "OtherRub";
        UsdSheetColumnBlocks[UsdSheetColumnBlocks["Total"] = 3] = "Total";
    })(UsdSheetColumnBlocks || (UsdSheetColumnBlocks = {}));
    var BaseUsdHierarchySheet = (function (_super) {
        __extends(BaseUsdHierarchySheet, _super);
        function BaseUsdHierarchySheet(document, _startDataColumn, _allDataCalc) {
            if (_allDataCalc === void 0) { _allDataCalc = false; }
            var _this = _super.call(this, document) || this;
            _this._startDataColumn = _startDataColumn;
            _this._allDataCalc = _allDataCalc;
            _this._fullSheetInfo = null;
            _this._formulaYearsCount = document.MainDataYearsCount;
            _this._addFormulaYearsCount = document.AddDataYearsCount;
            _this._startFormulaColumn = _this.CalcStartBlockColumn(UsdSheetColumnBlocks.Rub) + 1;
            _this._startAddFormulaColumn = _this.CalcEndBlockColumn(UsdSheetColumnBlocks.Total) + 2;
            return _this;
        }
        Object.defineProperty(BaseUsdHierarchySheet.prototype, "SheetInfo", {
            get: function () {
                var _this = this;
                if (this._fullSheetInfo == null) {
                    this._fullSheetInfo = this.StartSheetInfo;
                    var insertColumns = function () {
                        var columnInfos = [];
                        for (var _i = 0; _i < arguments.length; _i++) {
                            columnInfos[_i] = arguments[_i];
                        }
                        for (var _a = 0, columnInfos_2 = columnInfos; _a < columnInfos_2.length; _a++) {
                            var columnInfo = columnInfos_2[_a];
                            for (var i = 0; i < _this._formulaYearsCount; i++) {
                                _this._fullSheetInfo.ColumnsInfo.push(columnInfo);
                            }
                        }
                    };
                    var dataColFormat = this._allDataCalc
                        ? SheetColumnInfoCollection.CalcColAllCalc
                        : SheetColumnInfoCollection.FreeColAllCalc;
                    insertColumns(dataColFormat, SheetColumnInfoCollection.CalcColAllCalc, dataColFormat, SheetColumnInfoCollection.CalcColAllCalc);
                    for (var j = 0; j < this._addFormulaYearsCount; j++) {
                        this._fullSheetInfo.ColumnsInfo.push(dataColFormat);
                        this._fullSheetInfo.ColumnsInfo.push(SheetColumnInfoCollection.CalcColAllCalc);
                        this._fullSheetInfo.ColumnsInfo.push(dataColFormat);
                        this._fullSheetInfo.ColumnsInfo.push(SheetColumnInfoCollection.CalcColAllCalc);
                    }
                }
                return this._fullSheetInfo;
            },
            enumerable: true,
            configurable: true
        });
        BaseUsdHierarchySheet.prototype.CalcStartBlockColumn = function (block) {
            return this._startDataColumn + this._formulaYearsCount * block;
        };
        BaseUsdHierarchySheet.prototype.CalcEndBlockColumn = function (block) {
            return this._startDataColumn + this._formulaYearsCount * (block + 1) - 1;
        };
        BaseUsdHierarchySheet.prototype.GetYearsCaptionEventHandler = function (tableId, index, defaultCaption, fieldCaption) {
            return this.Document.CommonRules.CalcColumnCaption(index, this._startFormulaColumn, 2, this._formulaYearsCount);
        };
        BaseUsdHierarchySheet.prototype.GetAddYearsCaptionEventHandler = function (tableId, index, defaultCaption, fieldCaption) {
            var startColumn = this._startAddFormulaColumn + BaseUsdHierarchySheet._blocksCount * index + UsdSheetColumnBlocks.Rub;
            var result = "\u0432\u0441\u0435\u0433\u043E \u043E\u0431\u044A\u0435\u043C \u0431\u044E\u0434\u0436\u0435\u0442\u043D\u044B\u0445 \u0430\u0441\u0441\u0438\u0433\u043D\u043E\u0432\u0430\u043D\u0438\u0439,\n(\u0433\u0440. " + startColumn + " + \u0433\u0440. " + (startColumn + 1) + ")";
            return result;
        };
        BaseUsdHierarchySheet._blocksCount = ObasHelper.GetEnumLength(UsdSheetColumnBlocks);
        return BaseUsdHierarchySheet;
    }(BaseHierarchySheet));
    F01280.BaseUsdHierarchySheet = BaseUsdHierarchySheet;
    var PurchaseObjectUsdHierarchySheet = (function (_super) {
        __extends(PurchaseObjectUsdHierarchySheet, _super);
        function PurchaseObjectUsdHierarchySheet(document) {
            return _super.call(this, document, 11) || this;
        }
        Object.defineProperty(PurchaseObjectUsdHierarchySheet.prototype, "StartSheetInfo", {
            get: function () {
                return PurchaseObjectUsdHierarchySheet._sheetInfo;
            },
            enumerable: true,
            configurable: true
        });
        PurchaseObjectUsdHierarchySheet._sheetInfo = {
            MaxLevel: 3,
            CodeInfo: PurchaseObjectUsdHierarchySheet._CodeInfo,
            ColumnsInfo: [
                SheetColumnInfoCollection.SprColDefaultTotal,
                SheetColumnInfoCollection.FreeColDefaultTotal,
                PurchaseObjectUsdHierarchySheet.SprDefaultTotalFirstSubtotal,
                PurchaseObjectUsdHierarchySheet.SprDefaultTotalFirstSubtotal,
                PurchaseObjectUsdHierarchySheet.SprDefaultTotalFirstSubtotal,
                SheetColumnInfoCollection.SprColAllDefault,
                SheetColumnInfoCollection.SprColAllDefault,
                SheetColumnInfoCollection.SprColAllDefault,
                SheetColumnInfoCollection.SprColAllDefault,
                PurchaseObjectUsdHierarchySheet.FreeColConstAll,
                PurchaseObjectUsdHierarchySheet.DefaultColConstAll
            ]
        };
        return PurchaseObjectUsdHierarchySheet;
    }(BaseUsdHierarchySheet));
    F01280.PurchaseObjectUsdHierarchySheet = PurchaseObjectUsdHierarchySheet;
})(F01280 || (F01280 = {}));
