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 BaseRroOutlayTable = (function (_super) {
    __extends(BaseRroOutlayTable, _super);
    function BaseRroOutlayTable(id) {
        var _this = _super.call(this, id) || this;
        _this._name = null;
        _this._createDateField = null;
        _this._approvedDate = null;
        _this._statusSprField = null;
        _this._isActiveField = null;
        _this._sourceOutlayKey = null;
        _this._agreedDate = null;
        _this._number = null;
        _this._type = null;
        _this._versionNumber = null;
        _this._typeEditable = null;
        return _this;
    }
    Object.defineProperty(BaseRroOutlayTable.prototype, "AgreedDate", {
        get: function () {
            if (this._agreedDate == null) {
                this._agreedDate = new ObasTableField("AgreedDate", this);
            }
            return this._agreedDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "SourceOutlayKey", {
        get: function () {
            if (this._sourceOutlayKey == null) {
                this._sourceOutlayKey = new NumberObasTableField("SrcOutlayKey", this);
            }
            return this._sourceOutlayKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "IsActiveField", {
        get: function () {
            if (this._isActiveField == null) {
                this._isActiveField = new ObasTableField("IsActive", this, false);
            }
            return this._isActiveField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "IsActive", {
        get: function () {
            return this.IsActiveField.Value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "StatusSprField", {
        get: function () {
            if (this._statusSprField == null) {
                this._statusSprField = new ObasSprTableField(ObasTableCollection.OutlayStatusSprTable, this);
            }
            return this._statusSprField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "Status", {
        get: function () {
            return this.StatusSprField.ForeignKey.Value;
        },
        set: function (value) {
            this.StatusSprField.ForeignKey.Value = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "ApprovedDate", {
        get: function () {
            if (this._approvedDate == null) {
                this._approvedDate = new ObasTableField("ApprovedDate", this, false);
            }
            return this._approvedDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "CreateDate", {
        get: function () {
            return this.CreateDateField.Value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "CreateDateField", {
        get: function () {
            if (this._createDateField == null) {
                this._createDateField = new ObasTableField("CreateDate", this, true);
            }
            return this._createDateField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "Name", {
        get: function () {
            if (this._name == null) {
                this._name = new ObasTableField("Name", this, true);
            }
            return this._name;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "Number", {
        get: function () {
            if (this._number == null) {
                this._number = new ObasTableField("Number", this);
            }
            return this._number;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "Type", {
        get: function () {
            if (this._type == null) {
                this._type = new NumberObasTableField("Type", this);
            }
            return this._type;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "VersionNumber", {
        get: function () {
            if (this._versionNumber == null) {
                this._versionNumber = new NumberObasTableField("VersionNumber", this);
            }
            return this._versionNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayTable.prototype, "TypeEditable", {
        get: function () {
            if (this._typeEditable == null) {
                this._typeEditable = new NumberObasTableField("TypeEditable", this);
            }
            return this._typeEditable;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroOutlayTable.prototype.InitStatusEventHandler = function (tableId, fieldId) {
        return OutlayStatuses.Draft;
    };
    BaseRroOutlayTable.prototype.InitIsActiveEventHandler = function (tableId, fieldId) {
        return true;
    };
    BaseRroOutlayTable.prototype.InitCreateDateEventHandler = function (tableId, fieldId) {
        return ObasHelper.GetToday().toJSON();
    };
    BaseRroOutlayTable.prototype.SetActive = function (key) {
        if (key === void 0) { key = this.RecordKey.Value; }
        var currentActiveKey = this.GetActive();
        if (!(currentActiveKey == null || currentActiveKey === key)) {
            this.IsActiveField.Value = false;
        }
        if (this.LocateByKeys(key)) {
            this.IsActiveField.Value = true;
        }
    };
    BaseRroOutlayTable.prototype.GetActive = function (locate) {
        if (locate === void 0) { locate = true; }
        if (locate) {
            if (this.Locate(this.IsActiveField.Id, true)) {
                return this.RecordKey.Value;
            }
            return null;
        }
        else {
            return this.Lookup(this.IsActiveField.Id, true, this.RecordKey.Id);
        }
    };
    BaseRroOutlayTable.prototype.AddEventHandler = function (tableId) {
        this.SetActive();
    };
    BaseRroOutlayTable.prototype.StatusChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        if (newValue !== OutlayStatuses.Approved) {
            this.ApprovedDate.Value = null;
        }
        if (newValue !== OutlayStatuses.Agreed) {
            this.AgreedDate.Value = null;
        }
    };
    BaseRroOutlayTable.prototype.TypeChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.Name.Value = this.GenerateName();
        this.VersionNumber.Value = this.GenerateVersionNumber(this.Type.Value);
    };
    BaseRroOutlayTable.prototype.VersionNumberChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.Number.Value = this.GenerateNumber();
    };
    BaseRroOutlayTable.prototype.CreateNewVersion = function (sourceKey) {
        this.AddRow();
        this.SourceOutlayKey.DefferedSetValue(sourceKey);
        this.PostRow();
        var newKey = this.RecordKey.Value;
        this.RroDataTable.CreateNewVersions(sourceKey, newKey);
        return newKey;
    };
    BaseRroOutlayTable.prototype.SendToPack = function (outlayKey) {
        if (outlayKey === void 0) { outlayKey = this.RecordKey.Value; }
        this.RroObasVersionsTable.SendToPack(outlayKey);
    };
    BaseRroOutlayTable.prototype.IsDraft = function () {
        return this.Status === OutlayStatuses.Draft;
    };
    BaseRroOutlayTable.prototype.IsExistRowThisType = function (outlayType) {
        var curKey = this.RecordKey.Value;
        var result = this.Locate(this.Type.Id, outlayType);
        this.Locate(this.RecordKey.Id, curKey);
        return result;
    };
    BaseRroOutlayTable.prototype.IsExistNotApprovedVersion = function () {
        var curKey = this.RecordKey.Value;
        var result = false;
        var reader = this.CreateReader();
        while (reader.Read()) {
            if (this.Status != OutlayStatuses.Approved) {
                result = true;
                break;
            }
        }
        this.Locate(this.RecordKey.Id, curKey);
        return result;
    };
    BaseRroOutlayTable.prototype.GenerateName = function () {
        if (this.Type.Value === OutlayTypes.ProjectOutlay) {
            return "\u041F\u0440\u043E\u0435\u043A\u0442 \u0431\u044E\u0434\u0436\u0435\u0442\u043D\u043E\u0439 \u0441\u043C\u0435\u0442\u044B";
        }
        else if (this.Type.Value === OutlayTypes.Outlay) {
            return "\u0411\u044E\u0434\u0436\u0435\u0442\u043D\u0430\u044F \u0441\u043C\u0435\u0442\u0430 (\u0444. 0501019)";
        }
        else if (this.Type.Value === OutlayTypes.DeltaOutlay) {
            return "\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0435 \u043F\u043E\u043A\u0430\u0437\u0430\u0442\u0435\u043B\u0435\u0439 \u0431\u044E\u0434\u0436\u0435\u0442\u043D\u043E\u0439 \u0441\u043C\u0435\u0442\u044B (\u0444. 0501020)";
        }
        else if (this.Type.Value === OutlayTypes.ProjectSumOutlay) {
            return "C\u0432\u043E\u0434 \u043F\u0440\u043E\u0435\u043A\u0442\u043E\u0432 \u0441\u043C\u0435\u0442";
        }
        else if (this.Type.Value === OutlayTypes.SumOutlay) {
            return "\u0421\u0432\u043E\u0434 \u0441\u043C\u0435\u0442 \u0443\u0447\u0440\u0435\u0436\u0434\u0435\u043D\u0438\u0439";
        }
    };
    BaseRroOutlayTable.prototype.GenerateNumber = function () {
        var prefix = "";
        if (this.Type.Value === OutlayTypes.ProjectOutlay) {
            prefix = "3-61-";
        }
        else if (this.Type.Value === OutlayTypes.Outlay) {
            prefix = "3-71-";
        }
        else if (this.Type.Value === OutlayTypes.DeltaOutlay) {
            prefix = "3-52-";
        }
        else if (this.Type.Value === OutlayTypes.ProjectSumOutlay) {
            prefix = "3-75-";
        }
        else if (this.Type.Value === OutlayTypes.SumOutlay) {
            prefix = "3-90-";
        }
        var codeGrbs = ObasTableCollection.SelectedFoivTable.Foiv.Code;
        var userCode = ObasTableCollection.SelectedFoivTable.UserRegCode;
        var version = "0001";
        if (this.Type.Value === OutlayTypes.DeltaOutlay) {
            var version_1 = ObasHelper.FillWithCharacter(this.VersionNumber.Value, 4);
        }
        return prefix + codeGrbs + "/" + userCode + "/" + version;
    };
    BaseRroOutlayTable.prototype.GenerateVersionNumber = function (outlayType) {
        var maxVersionNumber = 0;
        if (outlayType != OutlayTypes.Outlay) {
            var curKey = this.RecordKey.Value;
            while (this.Locate(this.Type.Id, outlayType, true)) {
                var verionNumber = this.VersionNumber.Value;
                if (verionNumber > maxVersionNumber) {
                    maxVersionNumber = verionNumber;
                }
            }
            this.ClearLocateFlag();
            this.Locate(this.RecordKey.Id, curKey);
        }
        return maxVersionNumber + 1;
    };
    return BaseRroOutlayTable;
}(ObasTable));
var RroOutlayTable = (function (_super) {
    __extends(RroOutlayTable, _super);
    function RroOutlayTable() {
        var _this = _super.call(this, "RRO_Outlays") || this;
        _this._lastRroSumOutlayRecipientKey = null;
        _this._isExpendSheduleLoaded = null;
        return _this;
    }
    Object.defineProperty(RroOutlayTable.prototype, "IsExpendSheduleLoaded", {
        get: function () {
            if (this._isExpendSheduleLoaded == null) {
                this._isExpendSheduleLoaded = new ObasTableField("IsExpendSheduleLoaded", this);
            }
            return this._isExpendSheduleLoaded;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlayTable.prototype, "LastRroSumOutlayRecipientKey", {
        get: function () {
            if (this._lastRroSumOutlayRecipientKey == null) {
                this._lastRroSumOutlayRecipientKey = new ObasForeignKeyTableFieldTyped(ObasTableCollection.RroSumOutlayTable, this, "LastSumOutlayRecipientKey", false, false);
            }
            return this._lastRroSumOutlayRecipientKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlayTable.prototype, "RroDataTable", {
        get: function () {
            return ObasTableCollection.RroDataTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlayTable.prototype, "RroObasVersionsTable", {
        get: function () {
            return ObasTableCollection.RroObasVersionsTable;
        },
        enumerable: true,
        configurable: true
    });
    RroOutlayTable.prototype.LockOutlay = function (flag) {
        this.RroObasVersionsTable.LockFiles(this.RecordKey.Value, flag);
    };
    RroOutlayTable.prototype.ApproveVersion = function () {
        this.RroObasVersionsTable.ApproveVersions(this.RecordKey.Value);
    };
    RroOutlayTable.prototype.HasFullData = function () {
        var _this = this;
        var result = false;
        this.DoWithRestorePosition(function () {
            result = _this.RroObasVersionsTable.IsAllVersionsHasFiles(_this.RecordKey.Value, DocumentFileType.Obas);
        });
        return result;
    };
    return RroOutlayTable;
}(BaseRroOutlayTable));
var RroSumOutlayTable = (function (_super) {
    __extends(RroSumOutlayTable, _super);
    function RroSumOutlayTable() {
        return _super.call(this, "RRO_SumOutlays") || this;
    }
    Object.defineProperty(RroSumOutlayTable.prototype, "RroDataTable", {
        get: function () {
            return ObasTableCollection.RroSumDataTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroSumOutlayTable.prototype, "RroObasVersionsTable", {
        get: function () {
            return ObasTableCollection.RroSumObasVersionsTable;
        },
        enumerable: true,
        configurable: true
    });
    RroSumOutlayTable.prototype.ApproveVersion = function () { };
    return RroSumOutlayTable;
}(BaseRroOutlayTable));
var BaseRroObasVersionsTable = (function (_super) {
    __extends(BaseRroObasVersionsTable, _super);
    function BaseRroObasVersionsTable(id, _rroObasTable) {
        var _this = _super.call(this, id) || this;
        _this._rroObasTable = _rroObasTable;
        _this._deletedObasKey = null;
        _this._isApproveError = null;
        _this._changeType = null;
        _this._status = null;
        _this._fileNameMainField = null;
        _this._fileNameDeltaField = null;
        _this._sourceVersion = null;
        _this._fileNameSourceField = null;
        _this._rroPedKey = new ObasForeignKeyTableField(ObasTableCollection.RroPedTable, _this);
        _this._versionNumber = new ObasTableField("VerNum", _this);
        _this._dateApprove = new ObasTableField("DateApprove", _this);
        _this._ownerKbkCode = new ObasTableField("KBK_OwnerVR", _this);
        _this._kbkCode = new ObasTableField("KBK", _this);
        _this._prevVersion = new ObasTableField("PREV_OBAS_VERSION_KEY", _this);
        _this._autoFillDelta = new ObasTableField("AutoFillDeltaOBAS", _this);
        _this._isMultiRow = new ObasTableField("isMultiRow", _this);
        _this._isSynonymRow = new ObasTableField("isSynonymRow", _this);
        _this._issueContent = new ObasTableField("IssueContents", _this);
        _this._issueJustification = new ObasTableField("IssueJustification", _this);
        _this._issueComment = new ObasTableField("IssueComment", _this);
        return _this;
    }
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "FileNameSourceField", {
        get: function () {
            if (this._fileNameSourceField == null) {
                this._fileNameSourceField = new ObasTableField("FileName_Source", this);
            }
            return this._fileNameSourceField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "RroOutlayKey", {
        get: function () {
            return this.RroObasKey.SourceTable.RroOutlayKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "SourceVersion", {
        get: function () {
            if (this._sourceVersion == null) {
                this._sourceVersion = new NumberObasTableField("PARENT_OBAS_VERSION_KEY", this);
            }
            return this._sourceVersion;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "FileNameDeltaField", {
        get: function () {
            if (this._fileNameDeltaField == null) {
                this._fileNameDeltaField = new ObasTableField("FileName_D", this);
            }
            return this._fileNameDeltaField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "FileNameMainField", {
        get: function () {
            if (this._fileNameMainField == null) {
                this._fileNameMainField = new ObasTableField("FileName", this);
            }
            return this._fileNameMainField;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroObasVersionsTable.prototype.CreateFileName = function () {
        return Client.GenerateGuid();
    };
    BaseRroObasVersionsTable.prototype.GetFileNameField = function (fileType) {
        var isMainObas = ObasTableCollection.FileTypeTable.IsMain.LookupByKeys(fileType);
        if (fileType === DocumentFileType.Source) {
            return this.FileNameSourceField;
        }
        else if (isMainObas) {
            return this.FileNameMainField;
        }
        else {
            return this.FileNameDeltaField;
        }
    };
    BaseRroObasVersionsTable.prototype.GetFileName = function (fileType, autoGenerate) {
        if (autoGenerate === void 0) { autoGenerate = false; }
        var field = this.GetFileNameField(fileType);
        var fileName = field.Value;
        if (!fileName && autoGenerate) {
            fileName = this.CreateFileName();
            field.Value = fileName;
        }
        return fileName;
    };
    BaseRroObasVersionsTable.prototype.SetFileName = function (fileType, fileName) {
        this.GetFileNameField(fileType).Value = fileName;
    };
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "RroObasTable", {
        get: function () {
            return this._rroObasTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "IsMultiRow", {
        get: function () {
            return this._isMultiRow;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "IsSynonymRow", {
        get: function () {
            return this._isSynonymRow;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "AutoFillDelta", {
        get: function () {
            return this._autoFillDelta;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "RroObasKey", {
        get: function () {
            if (this._rroObasKey == null) {
                this._rroObasKey = new ObasForeignKeyTableFieldTyped(this._rroObasTable, this);
            }
            return this._rroObasKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "RroPedKey", {
        get: function () {
            return this._rroPedKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "RroDataKey", {
        get: function () {
            if (this._rroDataKey == null) {
                this._rroDataKey = new ObasForeignKeyTableFieldTyped(this._rroObasTable.RroDataTable, this);
            }
            return this._rroDataKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "VersionNumber", {
        get: function () {
            return this._versionNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "Version", {
        get: function () {
            return this.RecordKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "PreviosVersion", {
        get: function () {
            return this._prevVersion;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "DateApprove", {
        get: function () {
            return this._dateApprove;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "ChangeType", {
        get: function () {
            if (this._changeType == null)
                this._changeType = new ObasSprTableField(ObasTableCollection.ChangeTypeTable, this);
            return this._changeType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "Status", {
        get: function () {
            if (this._status == null)
                this._status = new ObasSprTableField(ObasTableCollection.StatusSprTable, this);
            return this._status;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "VersionStatus", {
        get: function () {
            return this.Status.ForeignKey.Value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "OwnerKbkCode", {
        get: function () {
            return this._ownerKbkCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "IssueComment", {
        get: function () {
            return this._issueComment;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "IssueContent", {
        get: function () {
            return this._issueContent;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "IssueJustification", {
        get: function () {
            return this._issueJustification;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasVersionsTable.prototype, "KbkCode", {
        get: function () {
            return this._kbkCode;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroObasVersionsTable.prototype.DateApproveChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var obasTable = this._rroObasTable;
        if (obasTable.LocateByKeys(this.RroObasKey.Value)) {
            this.PreviosVersion.Value = obasTable.LastApprovedVersion.Value;
            obasTable.LastApprovedVersion.Value = this.Version.Value;
            obasTable.DateApprove.Value = this.DateApprove.Value;
        }
    };
    BaseRroObasVersionsTable.prototype.DateApproveCheckEventHandler = function (tableId) {
        var obasTable = this._rroObasTable;
        var errorTxt = undefined;
        if (obasTable.LocateByKeys(this.RroObasKey.Value)) {
            var maxApproveDate = obasTable.DateApprove.Value;
            if (maxApproveDate != null) {
                if (obasTable.LastApprovedVersion.Value === this.Version.Value) {
                    if (this.DateApprove.Value < maxApproveDate) {
                        errorTxt = "\u0414\u0430\u0442\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u044F \u0434\u043E\u043B\u0436\u043D\u0430 \u0431\u044B\u0442\u044C \u0431\u043E\u043B\u044C\u0448\u0435 \u0438\u043B\u0438 \u0440\u0430\u0432\u043D\u0430 " + ObasHelper.ConvertToString(maxApproveDate);
                    }
                }
                else {
                    if (this.DateApprove.Value <= maxApproveDate) {
                        errorTxt = "\u0414\u0430\u0442\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u044F \u0434\u043E\u043B\u0436\u043D\u0430 \u0431\u044B\u0442\u044C \u0431\u043E\u043B\u044C\u0448\u0435 " + ObasHelper.ConvertToString(maxApproveDate);
                    }
                }
            }
        }
        return errorTxt;
    };
    BaseRroObasVersionsTable.prototype.AutoFillDeltaOBASInitEventHandler = function (tableId, fieldId) {
        return ObasStageSettings.CurrentStage === ObasStageType.First;
    };
    BaseRroObasVersionsTable.prototype.AddEventHandler = function (tableId) {
        var rroObas = this._rroObasTable;
        var rroData = this._rroObasTable.RroDataTable;
        var maxVersionNum = rroObas.LastVersionNumber.Value;
        if (maxVersionNum == null)
            maxVersionNum = 0;
        maxVersionNum++;
        rroObas.LastVersionNumber.Value = maxVersionNum;
        this.VersionNumber.Value = maxVersionNum;
        if (rroData.LocateByKeys(rroObas.RroDataKey.Value)) {
            this.KbkCode.Value = rroData.GetKbkCode();
        }
        if (this.IsMultiRow.Value && ObasHelper.IsInsuranceCode(this.RroObasKey.SourceTable.RroDataKey.SourceTable.CostType.Code)) {
            this.IsSynonymRow.Value = true;
        }
    };
    BaseRroObasVersionsTable.prototype.DeleteFile = function (fileType) {
        var filePath = this.GetFilePath(fileType);
        if (filePath) {
            Client.DeleteFile(filePath);
        }
    };
    BaseRroObasVersionsTable.prototype.DeleteEventHandler = function (tableId) {
        this._deletedObasKey = this.RroObasKey.Value;
        this.DeleteFile(ObasStageSettings.FileType);
        this.DeleteFile(ObasStageSettings.DeltaFileType);
//        this.DeleteFile(DocumentFileType.Source);
    };
    BaseRroObasVersionsTable.prototype.AfterDeleteEventHandler = function (tableId) {
        var rroObas = this._rroObasTable;
        if (rroObas.Locate(rroObas.RecordKey.Id, this._deletedObasKey)) {
            rroObas.LastVersionNumber.Value = this.GetMaxVersionNumber(this._deletedObasKey);
        }
    };
    BaseRroObasVersionsTable.prototype.RroPedKeyChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var statusKey;
        if (newValue == null) {
            statusKey = ObasTableCollection.StatusSprTable.FirstStatusInitEventHandler(this.Id);
        }
        else {
            var rroPed = ObasTableCollection.RroPedTable;
            statusKey = rroPed.PedStatus.ForeignKey.LookupByKeys(newValue);
        }
        this.Status.ForeignKey.Value = statusKey;
    };
    BaseRroObasVersionsTable.prototype.KbkCodeChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.OwnerKbkCode.Value = newValue.substr(0, newValue.length - 2) + "00";
    };
    BaseRroObasVersionsTable.prototype.YearValueChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        if (this.VersionNumber.Value === 1) {
            var rroObas = this._rroObasTable;
            if (rroObas.LocateByKeys(this.RroObasKey.Value)) {
                var index = fieldId.indexOf("_D");
                var destFieldId = (index > -1 ? fieldId.substring(0, index) : fieldId + "_First");
                rroObas.SetFieldValue(destFieldId, newValue);
            }
        }
    };
    BaseRroObasVersionsTable.prototype.CalcVersionName = function () {
        var result = "";
        if (this.VersionStatus === VersionStatus.Approved) {
            result += "\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u043E " + ObasHelper.ConvertToString(this.DateApprove.Value);
        }
        else {
            result += this.Status.Name + " (\u0412\u0435\u0440\u0441\u0438\u044F " + this.VersionNumber.Value + ")";
        }
        return result;
    };
    BaseRroObasVersionsTable.prototype.GetMaxVersionNumber = function (rroObasKey) {
        var result = 0;
        while (this.Locate(this.RroObasKey.Id, rroObasKey, true)) {
            var versionNumber = this.VersionNumber.Value;
            if (versionNumber > result)
                result = versionNumber;
        }
        this.ClearLocateFlag();
        return result;
    };
    BaseRroObasVersionsTable.prototype.GetFilePath = function (fileType, autoGenerate) {
        if (autoGenerate === void 0) { autoGenerate = false; }
        var result = "" + ObasHelper.GetFullDirectoryPath(undefined) + this.GetFileName(fileType, autoGenerate) + ".xml";
        if (autoGenerate || Client.IsFileExists(result)) {
            return result;
        }
        else {
            this.SetFileName(fileType, undefined);
        }
        return undefined;
    };
    BaseRroObasVersionsTable.prototype.CloneFile = function (fileType) {
        var srcFilePath = this.GetFilePath(fileType);
        if (srcFilePath) {
            var newFileName = this.CreateFileName();
            var destDir = ObasHelper.GetFullDirectoryPath(undefined);
            Client.CopyFile(srcFilePath, "" + destDir + newFileName + ".xml", true);
            this.SetFileName(fileType, newFileName);
        }
    };
    BaseRroObasVersionsTable.prototype.CreateNewVersion = function (sourceVersionKey, destRroObasKey) {
        var newKey = this.CloneRow(sourceVersionKey, false);
        this.RroObasKey.DefferedSetValue(destRroObasKey);
        this.VersionNumber.DefferedSetValue(1);
        this.SourceVersion.DefferedSetValue(sourceVersionKey);
        var yearField = BaseObasTableFields.YearDataField;
        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
            this.SetFieldValue(yearField.GenerateId(i) + "_D", 0, false);
        }
        this.PostRow();
        var sourceFilePath = this.GetFilePath(DocumentFileType.Source, true);
        if (sourceFilePath) {
            if (this.IsFreezeDocument(sourceFilePath)) {
                recoveryFilePath = ObasHelper.GetFullDirectoryPath(undefined) + this.GetFieldValue("FileName_Recovery") + ".xml";
                if (Client.IsFileExists(recoveryFilePath)) {
                    Client.CopyFile(recoveryFilePath, sourceFilePath, false);
                }
            }
        }
        this.SetFileName(ObasStageSettings.FileType, this.GetFileName(DocumentFileType.Source, true));
        this.SetFileName(ObasStageSettings.DeltaFileType, undefined);
        this.CloneFile(ObasStageSettings.FileType);
        this.SetFieldValue("FileName_Recovery", this.GetFileName(ObasStageSettings.FileType));
        this.RroOutlayKosguTable.CreateNewVersions(sourceVersionKey, newKey);
        this.RroPartIndicateBudgetValuesTable.CreateNewVersions(sourceVersionKey, newKey);
        return newKey;
    };
    BaseRroObasVersionsTable.prototype.LockFile = function (fileType, isReadOnly) {
        var filePath = this.GetFilePath(ObasStageSettings.FileType);
        if (filePath) {
            Client.SetFileReadOnly(filePath, isReadOnly);
        }
    };
    BaseRroObasVersionsTable.prototype.IterateByOutlay = function (rroOutlayKey, handler) {
        var outlayKeyFieldId = this.RroOutlayKey.Id;
        while (this.Locate(outlayKeyFieldId, rroOutlayKey, true)) {
            handler(this, this.RecordKey.Value);
        }
        this.ClearLocateFlag();
    };
    BaseRroObasVersionsTable.prototype.LockFiles = function (rroOutlayKey, isReadOnly) {
        var _this = this;
        this.IterateByOutlay(rroOutlayKey, function () {
            _this.LockFile(ObasStageSettings.FileType, isReadOnly);
        });
    };
    BaseRroObasVersionsTable.prototype.ApproveVersions = function (rroOutlayKey) {
        var _this = this;
        this._isApproveError = false;
        this.IterateByOutlay(rroOutlayKey, function () {
            _this.ApproveVersion();
        });
        if (this._isApproveError) {
            Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0412\u043E\u0437\u043D\u0438\u043A\u043B\u0430 \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0438 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432.\n\u0412\u044B\u0439\u0434\u0438\u0442\u0435 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043C\u044B \u0431\u0435\u0437 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F \u0434\u0430\u043D\u043D\u044B\u0445 \u0438 \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435 \u0441\u0432\u043E\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044F \u0441\u043D\u043E\u0432\u0430.", MessageIcons.Error);
        }
    };
    BaseRroObasVersionsTable.prototype.IsAllVersionsHasFiles = function (rroOutlayKey, fileType) {
        var outlayKeyFieldId = this.RroOutlayKey.Id;
        var result = true;
        while (result && this.Locate(outlayKeyFieldId, rroOutlayKey, true)) {
            result = this.IsVersionHasFile(fileType);
        }
        this.ClearLocateFlag();
        return result;
    };
    BaseRroObasVersionsTable.prototype.IsVersionHasFile = function (fileType) {
        return Client.IsFileExists(this.GetFilePath(fileType));
    };
    BaseRroObasVersionsTable.prototype.ApproveVersion = function () {
        var rroObasTable = this.RroObasKey.SourceTable;
        var fileType = ObasStageSettings.FileType;
        rroObasTable.LastApprovedVersion.Value = this.RecordKey.Value;
        if (!this.IsSynonymRow.Value) {
            var approvedFilePath = this.GetFilePath(fileType);
            if (approvedFilePath) {
                if (this.IsFreezeDocument(approvedFilePath)) {
                    approvedFilePath = ObasHelper.GetFullDirectoryPath(undefined) + this.GetFieldValue("FileName_Recovery") + ".xml";
                    if (!Client.IsFileExists(approvedFilePath)) {
                        this._isApproveError = true;
                        return;
                    }
                    else {
			var deletedFilePath = this.GetFilePath(fileType);
                        if (Client.IsFileExists(deletedFilePath)) {
	                    Client.DeleteFile(deletedFilePath);
			}
			deletedFilePath = deletedFilePath.replace(".xml", ".jsz");
                        if (Client.IsFileExists(deletedFilePath)) {
	                    Client.DeleteFile(deletedFilePath);
			}
                        this.SetFileName(fileType, this.GetFieldValue("FileName_Recovery"));
                    }
                }
                this.CloneFile(fileType);
                approvedFilePath = this.GetFilePath(fileType);
                var sourceFilePath = this.GetFilePath(DocumentFileType.Source, true);
		var recoveryFileName = this.GetFieldValue("FileName_Recovery");
                Client.CopyFile(approvedFilePath, sourceFilePath, false);
                Client.SetFileReadOnly(approvedFilePath, false);
                var approvedDocId = Client.OpenDocument(ObasHelper.GetTemplateFileName(fileType, this.RroObasKey.SourceTable.Obas.ForeignKey.Value, true), approvedFilePath);
                Client.SendMessage(approvedDocId, "%Doc%.CommonRules.FreezeDocument", []);
                Client.SaveDocument(approvedDocId);
                Client.CloseDocument(approvedDocId);
                Client.SetFileReadOnly(approvedFilePath, true);
		this.SetFieldValue("FileName_Recovery", recoveryFileName);
            }
        }
    };
    BaseRroObasVersionsTable.prototype.IsFreezeDocument = function (filePath) {
        var expendData = Client.GetFileData(filePath);
        var apElems = expendData.split("\n");
        for (var _i = 0, apElems_1 = apElems; _i < apElems_1.length; _i++) {
            var apElem = apElems_1[_i];
            if (apElem.indexOf("isFreezed=\"true\"") != -1) {
                return true;
            }
        }
        return false;
    };
    BaseRroObasVersionsTable.prototype.GetUserRegCode = function () {
        return ObasTableCollection.SelectedFoivTable.UserRegCode;
    };
    BaseRroObasVersionsTable.prototype.AddToPack = function () {
        var _this = this;
        var destTable = ObasTableCollection.OutlayExchangeDataTable;
        var rroObasTable = this.RroObasKey.SourceTable;
        var rroDataTable = rroObasTable.RroDataKey.SourceTable;
        if (destTable.GetRecordKey(destTable.GetKeys(rroDataTable.Fcr.ForeignKey.Value, rroDataTable.GovermentProgram.ForeignKey.Value, rroDataTable.SubProgram.ForeignKey.Value, rroDataTable.MainAction.ForeignKey.Value, rroDataTable.DirectionCost.ForeignKey.Value, rroDataTable.CostType.ForeignKey.Value, rroObasTable.Obas.ForeignKey.Value, this.GetUserRegCode()), true)) {
            destTable.SecurityType.ForeignKey.Value = rroDataTable.SecurityType.ForeignKey.Value;
            destTable.Okv.ForeignKey.Value = rroObasTable.Okv.ForeignKey.Value;
            var yearDataField = BaseObasTableFields.YearDataField;
            var usdDataField = BaseObasTableFields.UsdYearDataField;
            var fieldChange_1 = function (fieldId) {
                var oldValue = destTable.GetFieldValue(fieldId) || 0;
                var newValue = oldValue + _this.GetFieldValue(fieldId) || 0;
                destTable.SetFieldValue(fieldId, newValue);
            };
            var fieldGen = function (field, yearIndex) {
                var fieldId = field.GenerateId(yearIndex);
                fieldChange_1(fieldId);
                fieldId = fieldId + "_D";
                fieldChange_1(fieldId);
            };
            for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                fieldGen(yearDataField, i);
                fieldGen(usdDataField, i);
            }
            this.RroOutlayKosguTable.SendToPack(this.RecordKey.Value, destTable.RecordKey.Value);
            this.RroPartIndicateBudgetValuesTable.SendToPack(this.RecordKey.Value, destTable.RecordKey.Value);
            return destTable.RecordKey.Value;
        }
        return null;
    };
    return BaseRroObasVersionsTable;
}(ObasTable));
var RroObasVersionsTable = (function (_super) {
    __extends(RroObasVersionsTable, _super);
    function RroObasVersionsTable() {
        var _this = _super.call(this, "RRO_OBAS_VERSIONS", ObasTableCollection.RroObasTable) || this;
        _this._outlayCreateDate = null;
        _this._excelAttachFileName = null;
        return _this;
    }
    Object.defineProperty(RroObasVersionsTable.prototype, "ExcelAttachFileName", {
        get: function () {
            if (this._excelAttachFileName == null) {
                this._excelAttachFileName = new ObasTableField("ExcelAttachFileName", this);
            }
            return this._excelAttachFileName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasVersionsTable.prototype, "OutlayCreateDate", {
        get: function () {
            if (this._outlayCreateDate == null) {
                this._outlayCreateDate = new ObasTableField("OutlayCreateDate", this);
            }
            return this._outlayCreateDate.Value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasVersionsTable.prototype, "RroOutlayKosguTable", {
        get: function () {
            return ObasTableCollection.RroOutlayKosguTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasVersionsTable.prototype, "RroPartIndicateBudgetValuesTable", {
        get: function () {
            return ObasTableCollection.RroPartIndicateBudgetValuesTable;
        },
        enumerable: true,
        configurable: true
    });
    RroObasVersionsTable.prototype.SendToPack = function (rroOutlayKey) {
        var _this = this;
        this.IterateByOutlay(rroOutlayKey, function () {
            var approvedVersKey = _this.RroObasKey.SourceTable.LastApprovedVersion.Value;
            if (_this.Version.Value === approvedVersKey) {
                _this.AddToPack();
            }
        });
    };
    RroObasVersionsTable.prototype.CreateNewVersion = function (sourceVersionKey, destRroObasKey) {
        var newKey = _super.prototype.CreateNewVersion.call(this, sourceVersionKey, destRroObasKey);
        this.ExcelAttachFileName.Value = undefined;
        ObasTableCollection.RroObasKosguTable.CreateNewVersions(sourceVersionKey, newKey);
        return newKey;
    };
    RroObasVersionsTable.prototype.GetAttachFileName = function (autoGenerate) {
        if (autoGenerate === void 0) { autoGenerate = false; }
        var field = this.ExcelAttachFileName;
        var fileName = field.Value;
        if (!fileName && autoGenerate) {
            fileName = this.CreateFileName();
            field.Value = fileName;
        }
        return fileName;
    };
    return RroObasVersionsTable;
}(BaseRroObasVersionsTable));
var RroSumObasVersionsTable = (function (_super) {
    __extends(RroSumObasVersionsTable, _super);
    function RroSumObasVersionsTable() {
        var _this = _super.call(this, "RRO_SumOBAS_VERSIONS", ObasTableCollection.RroSumObasTable) || this;
        _this._senderCode = null;
        return _this;
    }
    Object.defineProperty(RroSumObasVersionsTable.prototype, "RroOutlayKosguTable", {
        get: function () {
            return ObasTableCollection.RroSumOutlayKosguTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroSumObasVersionsTable.prototype, "RroPartIndicateBudgetValuesTable", {
        get: function () {
            return ObasTableCollection.RroSumPartIndicateBudgetValuesTable;
        },
        enumerable: true,
        configurable: true
    });
    RroSumObasVersionsTable.prototype.SendToPack = function (rroOutlayKey) {
        var _this = this;
        this.IterateByOutlay(rroOutlayKey, function () {
            _this.AddToPack();
        });
    };
    Object.defineProperty(RroSumObasVersionsTable.prototype, "SenderCode", {
        get: function () {
            if (this._senderCode == null) {
                this._senderCode = new ObasTableField("Sender_Code", this);
            }
            return this._senderCode;
        },
        enumerable: true,
        configurable: true
    });
    RroSumObasVersionsTable.prototype.GetRecordKey = function (senderCode, rroObasKey, addIfNotExists) {
        return ObasHelper.GetValueByKeys(this, [this.SenderCode.Id, this.RroObasKey.Id], [senderCode, rroObasKey], this.RecordKey.Id, addIfNotExists);
    };
    RroSumObasVersionsTable.prototype.CreateNewVersions = function (sourceRroObasKey, destRroObasKey) {
        while (this.Locate(this.RroObasKey.Id, sourceRroObasKey, true)) {
            _super.prototype.CreateNewVersion.call(this, this.RecordKey.Value, destRroObasKey);
        }
        this.ClearLocateFlag();
    };
    return RroSumObasVersionsTable;
}(BaseRroObasVersionsTable));
var BaseRroObasTable = (function (_super) {
    __extends(BaseRroObasTable, _super);
    function BaseRroObasTable(id, _rroDataTable) {
        var _this = _super.call(this, id, [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._rroDataTable = _rroDataTable;
        _this._obas = null;
        _this._costTypeKey = null;
        _this._okv = null;
        _this._rroDataKey = new ObasForeignKeyTableFieldTyped(_this._rroDataTable, _this);
        _this._lastApprovedVersion = new ObasTableField("LAST_APPROVED_OBAS_VERSION_KEY", _this);
        _this._lastVersionNumber = new ObasTableField("LAST_OBAS_VERSION_NUM", _this);
        _this._dateApprove = new ObasTableField("DateApprove", _this);
        _this._isMultiRow = new ObasTableField("isMultiRow", _this);
        return _this;
    }
    Object.defineProperty(BaseRroObasTable.prototype, "Okv", {
        get: function () {
            if (this._okv == null) {
                this._okv = new ObasSprTableFieldTyped(ObasTableCollection.OkvSprTable, this);
            }
            return this._okv;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "RroOutlayKey", {
        get: function () {
            return this.RroDataKey.SourceTable.RroOutlayKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "RroDataTable", {
        get: function () {
            return this._rroDataTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "IsMultiRow", {
        get: function () {
            return this._isMultiRow;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "CostType", {
        get: function () {
            if (this._costTypeKey == null)
                this._costTypeKey = new ObasSprTableField(ObasTableCollection.CostTypeTable, this);
            return this._costTypeKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "DateApprove", {
        get: function () {
            return this._dateApprove;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "Obas", {
        get: function () {
            if (this._obas == null)
                this._obas = new ObasSprTableField(ObasTableCollection.ObasSprTable, this);
            return this._obas;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "RroDataKey", {
        get: function () {
            return this._rroDataKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "LastApprovedVersion", {
        get: function () {
            return this._lastApprovedVersion;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasTable.prototype, "LastVersionNumber", {
        get: function () {
            return this._lastVersionNumber;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroObasTable.prototype.InitOkvEventHandler = function (tableId, fieldId) {
        return this.Okv.SprTable.RubleKey;
    };
    BaseRroObasTable.prototype.CreateNewVersions = function (sourceRroDataKey, destRroDataKey) {
        while (this.Locate(this.RroDataKey.Id, sourceRroDataKey, true)) {
            this.CreateNewVersion(this.RecordKey.Value, destRroDataKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroObasTable.prototype.CreateNewVersion = function (sourceKey, destRroDataKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.RroDataKey.DefferedSetValue(destRroDataKey);
        this.LastApprovedVersion.DefferedSetValue(undefined);
        this.LastVersionNumber.DefferedSetValue(undefined);
        this.PostRow();
        this.InnerCreateNewVersion(newKey, sourceKey, destRroDataKey);
        return newKey;
    };
    BaseRroObasTable.prototype.GetRecordKey = function (obasKey, rroDataKey, addIfNotExists) {
        return ObasHelper.GetValueByKeys(this, [this.Obas.ForeignKey.Id, this.RroDataKey.Id], [obasKey, rroDataKey], this.RecordKey.Id, addIfNotExists);
    };
    return BaseRroObasTable;
}(ObasTable));
var RroObasTable = (function (_super) {
    __extends(RroObasTable, _super);
    function RroObasTable() {
        return _super.call(this, "RRO_OBAS", ObasTableCollection.RroDataTable) || this;
    }
    Object.defineProperty(RroObasTable.prototype, "RroObasVersionsTable", {
        get: function () {
            return ObasTableCollection.RroObasVersionsTable;
        },
        enumerable: true,
        configurable: true
    });
    RroObasTable.prototype.InnerCreateNewVersion = function (destKey, sourceKey, destRroDataKey) {
        var sourceRroObasVersion = this.LastApprovedVersion.LookupByKeys(sourceKey);
        this.RroObasVersionsTable.CreateNewVersion(sourceRroObasVersion, destKey);
    };
    return RroObasTable;
}(BaseRroObasTable));
var RroSumObasTable = (function (_super) {
    __extends(RroSumObasTable, _super);
    function RroSumObasTable() {
        return _super.call(this, "RRO_SumOBAS", ObasTableCollection.RroSumDataTable) || this;
    }
    Object.defineProperty(RroSumObasTable.prototype, "RroObasVersionsTable", {
        get: function () {
            return ObasTableCollection.RroSumObasVersionsTable;
        },
        enumerable: true,
        configurable: true
    });
    RroSumObasTable.prototype.InnerCreateNewVersion = function (destKey, sourceKey, destRroDataKey) {
        this.RroObasVersionsTable.CreateNewVersions(sourceKey, destKey);
    };
    return RroSumObasTable;
}(BaseRroObasTable));
var BaseRroDataTable = (function (_super) {
    __extends(BaseRroDataTable, _super);
    function BaseRroDataTable(id, _rroOutlayTable, keyFields) {
        var _this = _super.call(this, id, keyFields) || this;
        _this._rroOutlayTable = _rroOutlayTable;
        _this._securityType = null;
        _this._department = null;
        _this._prfNpaRequisites = null;
        _this._prfNpaLink = null;
        _this._costNpaRequisites = null;
        _this._costNpaLink = null;
        _this._rroOutlayKey = null;
        _this._synonymKey = null;
        _this._mainActionFullCode = new ObasTableField("MainAction_FullCode", _this);
        _this._costTypeOwnerCode = new ObasTableField("ParentVR_Code", _this);
        _this._dirCostOwnerCode = new ObasTableField("ParentDirCost_Code", _this);
        _this._spenObligCode = new ObasTableField("PO_Code", _this);
        _this._spenObligName = new ObasTableField("PO_Name", _this);
        return _this;
    }
    Object.defineProperty(BaseRroDataTable.prototype, "RroOutlayKey", {
        get: function () {
            if (this._rroOutlayKey == null) {
                this._rroOutlayKey = new ObasForeignKeyTableFieldTyped(this._rroOutlayTable, this);
            }
            return this._rroOutlayKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "CostNpaLink", {
        get: function () {
            if (this._costNpaLink == null) {
                this._costNpaLink = new EndingNpaLinkFields(this, "N2");
            }
            return this._costNpaLink;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "CostNpaRequisites", {
        get: function () {
            if (this._costNpaRequisites == null) {
                this._costNpaRequisites = new NpaRequisitesFields(this, "N2Num", "N2Name", "N2Date", "N2Type");
            }
            return this._costNpaRequisites;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "PrfNpaLink", {
        get: function () {
            if (this._prfNpaLink == null) {
                this._prfNpaLink = new NpaLinkFields(this, "N1");
            }
            return this._prfNpaLink;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "PrfNpaRequisites", {
        get: function () {
            if (this._prfNpaRequisites == null) {
                this._prfNpaRequisites = new PrfNpaRequisitesFields(this, "N1Num", "N1Name", "N1Date", "N1Type");
            }
            return this._prfNpaRequisites;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "SpendObligationCode", {
        get: function () {
            return this._spenObligCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "SpendObligationName", {
        get: function () {
            return this._spenObligName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "SecurityType", {
        get: function () {
            if (this._securityType == null)
                this._securityType = new ObasSprTableField(ObasTableCollection.SecurityTypesTable, this);
            return this._securityType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "Department", {
        get: function () {
            if (this._department == null)
                this._department = new ObasSprTableField(ObasTableCollection.DepartmentSprTable, this);
            return this._department;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "MainActionFullCode", {
        get: function () {
            return this._mainActionFullCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "CostTypeOwnerCode", {
        get: function () {
            return this._costTypeOwnerCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroDataTable.prototype, "DirectionCostOwnerCode", {
        get: function () {
            return this._dirCostOwnerCode;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroDataTable.prototype.RroOutlayInitEventHandler = function (tableId, fieldId) {
        return this._rroOutlayTable.GetActive();
    };
    BaseRroDataTable.prototype.FoivInitEventHandler = function (tableId, fieldId) {
        return ObasTableCollection.SelectedFoivTable.Foiv.ForeignKey.Value;
    };
    BaseRroDataTable.prototype.CostTypeChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var ctSoLinks = ObasTableCollection.CostTypeSpendObligationLinksTable;
        if (ctSoLinks.Locate(ctSoLinks.CostTypeCode.Id, this.CostType.Code)) {
            this.SpendObligationCode.Value = ctSoLinks.SpendObligationCode.Value;
            this.SpendObligationName.Value = ctSoLinks.SpendObligationName.Value;
        }
        this.KbkChangeEventHandler(tableId, oldValue, newValue, fieldId);
    };
    BaseRroDataTable.prototype.KbkChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        switch (fieldId) {
            case this.CostType.ForeignKey.Id:
                this.CostTypeOwnerCode.Value = this.CalcOwnerCostTypeCode();
                break;
            case this.DirectionCost.ForeignKey.Id:
                this.DirectionCostOwnerCode.Value = this.CalcOwnerDirectionCostCode();
                break;
        }
        Client.SendMessage(Client.MainDocumentId, "%Doc%.TableRules.CreateRroObas", []);
    };
    BaseRroDataTable.prototype.IsActiveOutlayLoadEventHandler = function (tableId) {
        return this.RroOutlayKey.SourceTable.IsActive;
    };
    BaseRroDataTable.prototype.DeleteEventHandler = function (tableId) {
        var curKey = this.RecordKey.Value;
        var kbkTable = ObasTableCollection.RroProcurementKBKTable;
        if (kbkTable.Locate(kbkTable.RroDataKey.Id, curKey)) {
            kbkTable.RroDataKey.Value = null;
        }
        this._synonymKey = ObasHelper.GetSynonymRROKey(curKey);
        this.LocateByKeys(curKey);
    };
    BaseRroDataTable.prototype.AfterDeleteEventHandler = function (tableId) {
        if (this._synonymKey != null) {
            if (this.LocateByKeys(this._synonymKey)) {
                this.DeleteRow();
            }
        }
    };
    BaseRroDataTable.prototype.CreateSynonym = function (srcKey) {
        if (srcKey === void 0) { srcKey = this.RecordKey.Value; }
        var costTypeCode = this.CostType.Code;
        var needCode = ObasHelper.GetSynonymCostType(costTypeCode);
        if (needCode) {
            var needCostTypeKey = ObasTableCollection.CostTypeTable.LookupKeyByCode(needCode);
            if (needCostTypeKey && (ObasHelper.GetSynonymRROKey(srcKey) == null)) {
                this.CloneRow(srcKey, false);
                this.CostType.ForeignKey.DefferedSetValue(needCostTypeKey);
                this.PostRow();
            }
        }
    };
    BaseRroDataTable.prototype.GetRecordKeyByKbk = function (fcrKey, programKey, subprogramKey, mainActionKey, directionCostKey, costTypeKey, rroOutlayKey, addIfNotExists) {
        var locateFieldIds = this.GetKbkKeyFieldsId();
        locateFieldIds.push(this.RroOutlayKey.Id);
        return ObasHelper.GetValueByKeys(this, locateFieldIds, [fcrKey, programKey, subprogramKey, directionCostKey, costTypeKey, mainActionKey, rroOutlayKey], this.RecordKey.Id, addIfNotExists);
    };
    BaseRroDataTable.prototype.CreateNewVersions = function (sourceOutlayKey, destOutlayKey) {
        while (this.Locate(this.RroOutlayKey.Id, sourceOutlayKey, true)) {
            this.CreateNewVersion(this.RecordKey.Value, destOutlayKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroDataTable.prototype.CreateNewVersion = function (sourceKey, destOutlayKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.RroOutlayKey.DefferedSetValue(destOutlayKey);
        this.PostRow();
        this.RroObasTable.CreateNewVersions(sourceKey, newKey);
        return newKey;
    };
    Object.defineProperty(BaseRroDataTable.prototype, "Status", {
        get: function () {
            return this.GetFieldValue("Outlay_Status_ID");
        },
        enumerable: true,
        configurable: true
    });
    BaseRroDataTable.prototype.IsDraft = function () {
        return this.Status === OutlayStatuses.Draft;
    };
    return BaseRroDataTable;
}(ObasTableWithKbkData));
var RroDataTable = (function (_super) {
    __extends(RroDataTable, _super);
    function RroDataTable() {
        return _super.call(this, "RRO_DATA", ObasTableCollection.RroOutlayTable) || this;
    }
    Object.defineProperty(RroDataTable.prototype, "RroObasTable", {
        get: function () {
            return ObasTableCollection.RroObasTable;
        },
        enumerable: true,
        configurable: true
    });
    RroDataTable.prototype.GetObasKey = function () {
        var obasKbkLinks = ObasTableCollection.ObasKbkLinksTable;
        var reader = obasKbkLinks.CreateReader();
        var csrCode = this.GetCSRCode();
        var costTypeCode = this.CostType.Code;
        var foivCode = this.Foiv.Code;
        while (reader.Read()) {
            if (ObasHelper.CheckObasKbkLink(csrCode, costTypeCode, foivCode)) {
                return obasKbkLinks.Obas.ForeignKey.Value;
            }
        }
        return null;
    };
    RroDataTable.prototype.CreateRroObasRow = function () {
        var obasKey = this.GetObasKey();
        if (obasKey != null) {
            var rroObas = ObasTableCollection.RroObasTable;
            if (!rroObas.Locate(rroObas.RroDataKey.Id, this.RecordKey.Value)) {
                rroObas.AddRow();
                rroObas.Obas.ForeignKey.DefferedSetValue(obasKey);
                rroObas.PostRow();
            }
        }
    };
    RroDataTable.prototype.CreateRroKuDataRow = function () {
        var kbkKeyValues = this.GetKbkKeyFieldsValue();
        var kbkKeyIds = this.GetKbkKeyFieldsId();
        var index = kbkKeyIds.indexOf(this.CostType.ForeignKey.Id);
        if (index > -1) {
            var costTypeSpr = ObasTableCollection.CostTypeTable;
            kbkKeyValues[index] = costTypeSpr.LookupKeyByCode(this.CostTypeOwnerCode.Value);
        }
        index = kbkKeyIds.indexOf(this.DirectionCost.ForeignKey.Id);
        if (index > -1) {
            var dirCostSpr = ObasTableCollection.DirectionCostTable;
            kbkKeyValues[index] = dirCostSpr.LookupKeyByCode(this.DirectionCostOwnerCode.Value);
        }
        var notFullKbk = kbkKeyValues.some(function (value) {
            return value == null;
        });
        if (!notFullKbk) {
            var rroKuData = ObasTableCollection.RroKUDataTable;
            if (!rroKuData.Locate(kbkKeyIds, kbkKeyValues)) {
                rroKuData.AddRow();
                for (var i = 0; i < kbkKeyIds.length; i++) {
                    rroKuData.SetFieldValue(kbkKeyIds[i], kbkKeyValues[i]);
                }
                rroKuData.KbkWithKosguCode.Value = rroKuData.GetKbkCode();
                rroKuData.PostRow();
            }
        }
    };
    RroDataTable.prototype.CreateNewVersion = function (sourceKey, destOutlayKey) {
        var newKey = _super.prototype.CreateNewVersion.call(this, sourceKey, destOutlayKey);
        ObasTableCollection.RroExpendSheduleTable.CreateNewVersion(sourceKey, newKey);
        return newKey;
    };
    RroDataTable.prototype.CreateExpendShedule = function () {
        var expendTable = ObasTableCollection.RroExpendSheduleTable;
        expendTable.AddRow();
        expendTable.RroDataKey.DefferedSetValue(this.RecordKey.Value);
        expendTable.PostRow();
    };
    return RroDataTable;
}(BaseRroDataTable));
var RroSumDataTable = (function (_super) {
    __extends(RroSumDataTable, _super);
    function RroSumDataTable() {
        return _super.call(this, "RRO_SumDATA", ObasTableCollection.RroSumOutlayTable) || this;
    }
    Object.defineProperty(RroSumDataTable.prototype, "RroObasTable", {
        get: function () {
            return ObasTableCollection.RroSumObasTable;
        },
        enumerable: true,
        configurable: true
    });
    RroSumDataTable.prototype.RestoreData = function (exchangeDataTable, exchangeAnalysisDataTable, rroOutlayKey) {
        var _this = this;
        var rroObasTable = this.RroObasTable;
        var rroObasVersionsTable = rroObasTable.RroObasVersionsTable;
        var rroOutlayKosguTable = rroObasVersionsTable.RroOutlayKosguTable;
        var rroObasAddAnalysisIndicatorTable = rroOutlayKosguTable.RroAddAnalysisIndicatorTable;
        var rroPartIndicateBudgetValuesTable = rroObasVersionsTable.RroPartIndicateBudgetValuesTable;
        var yearDataField = BaseObasTableFields.YearDataField;
        var usdDataField = BaseObasTableFields.UsdYearDataField;
        var fieldGen = function (sourcetable, destTable, field, yearIndex) {
            var fieldId = field.GenerateId(yearIndex);
            destTable.SetFieldValue(fieldId, sourcetable.GetFieldValue(fieldId));
            fieldId = fieldId + "_D";
            destTable.SetFieldValue(fieldId, sourcetable.GetFieldValue(fieldId));
        };
        exchangeDataTable.Iterate(function () {
            var rroDataKey = _this.GetRecordKeyByKbk(exchangeDataTable.Fcr.ForeignKey.Value, exchangeDataTable.GovermentProgram.ForeignKey.Value, exchangeDataTable.SubProgram.ForeignKey.Value, exchangeDataTable.MainAction.ForeignKey.Value, exchangeDataTable.DirectionCost.ForeignKey.Value, exchangeDataTable.CostType.ForeignKey.Value, rroOutlayKey, true);
            if (rroDataKey) {
                _this.SecurityType.ForeignKey.Value = exchangeDataTable.SecurityType.ForeignKey.Value;
                var rroObasKey = rroObasTable.GetRecordKey(exchangeDataTable.Obas.ForeignKey.Value, rroDataKey, true);
                if (rroObasKey) {
                    rroObasTable.Okv.ForeignKey.Value = exchangeDataTable.Okv.ForeignKey.Value;
                    var rroObasVersionKey = rroObasVersionsTable.GetRecordKey(exchangeDataTable.SenderCode.Value, rroObasKey, true);
                    if (rroObasVersionKey) {
                        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                            fieldGen(exchangeDataTable, rroObasVersionsTable, yearDataField, i);
                            fieldGen(exchangeDataTable, rroObasVersionsTable, usdDataField, i);
                        }
                        while (exchangeAnalysisDataTable.Locate(exchangeAnalysisDataTable.OwnerKey.Id, exchangeDataTable.RecordKey.Value, true)) {
                            var rroKosguKey = exchangeAnalysisDataTable.Kosgu.ForeignKey.Value;
                            var rroAddAnalyticIndicatorKey = exchangeAnalysisDataTable.AddAnalyticIndicator.ForeignKey.Value;
                            var isPart4Outlay = exchangeAnalysisDataTable.IsPart4Outlay.Value;
                            if (isPart4Outlay) {
                                var rroPartIndicateBudgetValuesKey = rroPartIndicateBudgetValuesTable.GetRecordKey(rroObasVersionKey, rroKosguKey, true);
                                if (rroPartIndicateBudgetValuesKey) {
                                    for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                                        fieldGen(exchangeAnalysisDataTable, rroPartIndicateBudgetValuesTable, yearDataField, i);
                                        fieldGen(exchangeAnalysisDataTable, rroPartIndicateBudgetValuesTable, usdDataField, i);
                                    }
                                }
                            }
                            else {
                                var rroOutlayKosguKey = rroOutlayKosguTable.GetRecordKey(rroObasVersionKey, rroKosguKey, true);
                                if (rroOutlayKosguKey && !rroAddAnalyticIndicatorKey) {
                                    for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                                        fieldGen(exchangeAnalysisDataTable, rroOutlayKosguTable, yearDataField, i);
                                        fieldGen(exchangeAnalysisDataTable, rroOutlayKosguTable, usdDataField, i);
                                    }
                                }
                                else if (rroAddAnalyticIndicatorKey) {
                                    var rroObasAddAnalysisIndicatorKey = rroObasAddAnalysisIndicatorTable.GetRecordKey(rroOutlayKosguKey, rroAddAnalyticIndicatorKey, true);
                                    if (rroObasAddAnalysisIndicatorKey) {
                                        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                                            fieldGen(exchangeAnalysisDataTable, rroObasAddAnalysisIndicatorTable, yearDataField, i);
                                            fieldGen(exchangeAnalysisDataTable, rroObasAddAnalysisIndicatorTable, usdDataField, i);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            exchangeAnalysisDataTable.ClearLocateFlag();
        }, true);
    };
    return RroSumDataTable;
}(BaseRroDataTable));
var RroSecurityTypeTable = (function (_super) {
    __extends(RroSecurityTypeTable, _super);
    function RroSecurityTypeTable() {
        var _this = _super.call(this, "RRO_OBAS_SC", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._securityType = null;
        _this._securityBase = null;
        return _this;
    }
    Object.defineProperty(RroSecurityTypeTable.prototype, "SecurityType", {
        get: function () {
            if (this._securityType == null)
                this._securityType = new ObasSprTableField(ObasTableCollection.SecurityTypesTable, this);
            return this._securityType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroSecurityTypeTable.prototype, "SecurityBase", {
        get: function () {
            if (this._securityBase == null) {
                this._securityBase = new ObasTableField("SecBase", this);
            }
            return this._securityBase;
        },
        enumerable: true,
        configurable: true
    });
    return RroSecurityTypeTable;
}(ObasTable));
var RroPlanTable = (function (_super) {
    __extends(RroPlanTable, _super);
    function RroPlanTable() {
        return _super.call(this, "RRO_PLAN") || this;
    }
    return RroPlanTable;
}(ObasTableWithKbkData));
var RroKuDataTable = (function (_super) {
    __extends(RroKuDataTable, _super);
    function RroKuDataTable() {
        var _this = _super.call(this, "RRO_KU_Data") || this;
        _this._dataType = null;
        _this._kbkWithKosguCode = new ObasTableField("FullKBK_KOSGU", _this);
        return _this;
    }
    Object.defineProperty(RroKuDataTable.prototype, "KbkWithKosguCode", {
        get: function () {
            return this._kbkWithKosguCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroKuDataTable.prototype, "DataType", {
        get: function () {
            if (this._dataType == null) {
                this._dataType = new ObasSprTableField(ObasTableCollection.KuDataTypeSprTable, this);
            }
            return this._dataType;
        },
        enumerable: true,
        configurable: true
    });
    RroKuDataTable.prototype.KbkWithKosguCodeChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        if (newValue != null && this.DataType.ForeignKey.Value === KuDataType.LBO) {
            var kbkCode = newValue.substr(0, 16);
            var obasVersions = ObasTableCollection.RroObasVersionsTable;
            var rroObasKosgu = ObasTableCollection.RroObasKosguTable;
            while (obasVersions.Locate(obasVersions.KbkCode.Id, kbkCode, true)) {
                while (rroObasKosgu.Locate(rroObasKosgu.RroVersionKey.Id, obasVersions.Version.Value, true)) {
                    rroObasKosgu.RroKuKey.Value = this.RecordKey.Value;
                }
            }
            rroObasKosgu.ClearLocateFlag();
            obasVersions.ClearLocateFlag();
        }
    };
    return RroKuDataTable;
}(ObasTableWithKbkData));
var RroLboTable = (function (_super) {
    __extends(RroLboTable, _super);
    function RroLboTable() {
        return _super.call(this, "RRO_LBO") || this;
    }
    return RroLboTable;
}(ObasTableWithCSRData));
var RroObasNumbersTable = (function (_super) {
    __extends(RroObasNumbersTable, _super);
    function RroObasNumbersTable() {
        var _this = _super.call(this, "RRO_OBAS_Numbers", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._copyNumber = new ObasTableField("CopyNumber", _this);
        _this._strNumber = new ObasTableField("StrNumber", _this);
        return _this;
    }
    Object.defineProperty(RroObasNumbersTable.prototype, "CopyNumber", {
        get: function () {
            return this._copyNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasNumbersTable.prototype, "StringNumber", {
        get: function () {
            return this._strNumber;
        },
        enumerable: true,
        configurable: true
    });
    return RroObasNumbersTable;
}(ObasTable));
var RroObasRecvisitsTable = (function (_super) {
    __extends(RroObasRecvisitsTable, _super);
    function RroObasRecvisitsTable() {
        var _this = _super.call(this, "RRO_OBAS_Recvisits") || this;
        _this._boss = null;
        _this._executor = null;
        _this._cfo = null;
        _this._agreed = null;
        _this._approved = null;
        return _this;
    }
    Object.defineProperty(RroObasRecvisitsTable.prototype, "Approved", {
        get: function () {
            if (this._approved == null) {
                this._approved = new ObasPersonInfoTableFields("OutlayApprovedRecvisits_", this);
            }
            return this._approved;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasRecvisitsTable.prototype, "Agreed", {
        get: function () {
            if (this._agreed == null) {
                this._agreed = new ObasPersonInfoTableFields("OutlayAgreedRecvisits_", this);
            }
            return this._agreed;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasRecvisitsTable.prototype, "CFO", {
        get: function () {
            if (this._cfo == null) {
                this._cfo = new ObasForeignKeyTableFieldTyped(new ObasPersonInfoTable("RRO_FinanceChiefRecvisits"), this);
            }
            return this._cfo.SourceTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasRecvisitsTable.prototype, "Executor", {
        get: function () {
            if (this._executor == null) {
                this._executor = new ObasForeignKeyTableFieldTyped(new ObasPersonInfoTable("RRO_ExecutorRecvisits"), this);
            }
            return this._executor.SourceTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasRecvisitsTable.prototype, "Boss", {
        get: function () {
            if (this._boss == null) {
                this._boss = new ObasForeignKeyTableFieldTyped(new ObasPersonInfoTable("RRO_OfficeChiefRecvisits"), this);
            }
            return this._boss.SourceTable;
        },
        enumerable: true,
        configurable: true
    });
    return RroObasRecvisitsTable;
}(ObasTable));
var RroObasKosguTable = (function (_super) {
    __extends(RroObasKosguTable, _super);
    function RroObasKosguTable() {
        var _this = _super.call(this, "RRO_OBAS_KOSGU", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._kosgu = null;
        _this._obasVersion = new ObasForeignKeyTableField(ObasTableCollection.RroObasVersionsTable, _this);
        _this._lboKey = new ObasForeignKeyTableField(ObasTableCollection.RroKUDataTable, _this);
        return _this;
    }
    Object.defineProperty(RroObasKosguTable.prototype, "Kosgu", {
        get: function () {
            if (this._kosgu == null) {
                this._kosgu = new ObasSprTableField(ObasTableCollection.KosguSprTable, this);
            }
            return this._kosgu;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasKosguTable.prototype, "RroVersionKey", {
        get: function () {
            return this._obasVersion;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroObasKosguTable.prototype, "RroKuKey", {
        get: function () {
            return this._lboKey;
        },
        enumerable: true,
        configurable: true
    });
    RroObasKosguTable.prototype.RroVersionKeyChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var rroVersions = ObasTableCollection.RroObasVersionsTable;
        var rroData = ObasTableCollection.RroDataTable;
        if (rroData.LocateByKeys(rroVersions.RroDataKey.LookupByKeys(newValue))) {
            var kbkCode = rroData.GetKbkCode();
            kbkCode += " ";
            kbkCode += this.Kosgu.Code;
            var rroKuTable = ObasTableCollection.RroKUDataTable;
            this.RroKuKey.Value = rroKuTable.Lookup(rroKuTable.KbkWithKosguCode.Id, kbkCode, rroKuTable.RecordKey.Id);
        }
    };
    RroObasKosguTable.prototype.YearValueChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var obasVersions = ObasTableCollection.RroObasVersionsTable;
        var obasVersion = this.RroVersionKey.Value;
        if (obasVersions.IsMultiRow.LookupByKeys(obasVersion)) {
            if (this.Kosgu.Code === "213") {
                obasVersion = ObasHelper.GetSynonymVersion(obasVersion);
            }
            if (obasVersion != null) {
                ObasHelper.SetSumByKeys(obasVersions, [obasVersions.RecordKey.Id], [obasVersion], fieldId, oldValue, newValue);
            }
        }
    };
    RroObasKosguTable.prototype.CalcY2Delta = function () {
        return this.GetRealDelta(ObasStageSettings.CurrentYear + 1);
    };
    RroObasKosguTable.prototype.CalcY3Delta = function () {
        return this.GetRealDelta(ObasStageSettings.CurrentYear + 2);
    };
    RroObasKosguTable.prototype.CalcY4Delta = function () {
        return this.GetRealDelta(ObasStageSettings.CurrentYear + 3);
    };
    RroObasKosguTable.prototype.GetRealDelta = function (year) {
        var yearOffset = year - ObasStageSettings.CurrentYear + 1;
        var sourceValue = this.GetFieldValue("Y" + yearOffset + "_D");
        var result = (sourceValue == null ? 0 : sourceValue);
        if (result < 0) {
            var negativeLBO = this.GetFieldValue("SUM_Y" + yearOffset);
            negativeLBO = (negativeLBO == null ? 0 : -1 * negativeLBO);
            if (result < negativeLBO) {
                result = negativeLBO;
            }
        }
        return result;
    };
    RroObasKosguTable.prototype.CreateNewVersions = function (sourceVersionKey, destVersionKey) {
        while (this.Locate(this.RroVersionKey.Id, sourceVersionKey, true)) {
            this.CreateNewVersion(this.RecordKey.Value, destVersionKey);
        }
        this.ClearLocateFlag();
    };
    RroObasKosguTable.prototype.CreateNewVersion = function (sourceKey, destVersionKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.RroVersionKey.Value = destVersionKey;
        this.PostRow();
        return newKey;
    };
    return RroObasKosguTable;
}(ObasTable));
var BaseRroOutlayKosguTable = (function (_super) {
    __extends(BaseRroOutlayKosguTable, _super);
    function BaseRroOutlayKosguTable() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._kosgu = null;
        _this._rroObasVersion = null;
        _this._sourceOutlayKosgu = null;
        return _this;
    }
    Object.defineProperty(BaseRroOutlayKosguTable.prototype, "SourceOutlayKosgu", {
        get: function () {
            if (this._sourceOutlayKosgu == null) {
                this._sourceOutlayKosgu = new NumberObasTableField("PARENT_Outlay_KOSGU_KEY", this);
            }
            return this._sourceOutlayKosgu;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayKosguTable.prototype, "RroObasVersion", {
        get: function () {
            if (this._rroObasVersion == null) {
                this._rroObasVersion = new ObasForeignKeyTableFieldTyped(this.RroObasVersions, this);
            }
            return this._rroObasVersion;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlayKosguTable.prototype, "Kosgu", {
        get: function () {
            if (this._kosgu == null) {
                this._kosgu = new ObasSprTableFieldTyped(ObasTableCollection.KosguSprTable, this);
            }
            return this._kosgu;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroOutlayKosguTable.prototype.SendToPack = function (rroObasVersion, sourcePackKey) {
        var versionKeyId = this.RroObasVersion.Id;
        while (this.Locate(versionKeyId, rroObasVersion, true)) {
            this.AddToPack(sourcePackKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroOutlayKosguTable.prototype.AddToPack = function (sourcePackKey) {
        var _this = this;
        var destTable = ObasTableCollection.OutlayAnalysisIndicatorExchangeDataTable;
        if (destTable.GetRecordKey(destTable.GetKeys(sourcePackKey, this.Kosgu.ForeignKey.Value, null, false), true)) {
            var fieldChange_2 = function (fieldId) {
                var oldValue = destTable.GetFieldValue(fieldId) || 0;
                var newValue = oldValue + _this.GetFieldValue(fieldId) || 0;
                destTable.SetFieldValue(fieldId, newValue);
            };
            var fieldGen = function (field, yearIndex) {
                var fieldId = field.GenerateId(yearIndex);
                fieldChange_2(fieldId);
                fieldId = fieldId + "_D";
                fieldChange_2(fieldId);
            };
            var yearDataField = BaseObasTableFields.YearDataField;
            var usdDataField = BaseObasTableFields.UsdYearDataField;
            for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                fieldGen(yearDataField, i);
                fieldGen(usdDataField, i);
            }
            this.RroAddAnalysisIndicatorTable.SendToPack(this.RecordKey.Value, sourcePackKey, this.Kosgu.ForeignKey.Value);
            return destTable.RecordKey.Value;
        }
        return null;
    };
    BaseRroOutlayKosguTable.prototype.CreateNewVersions = function (sourceVersionKey, destVersionKey) {
        while (this.Locate(this.RroObasVersion.Id, sourceVersionKey, true)) {
            this.CreateNewVersion(this.RecordKey.Value, destVersionKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroOutlayKosguTable.prototype.CreateNewVersion = function (sourceKey, destVersionKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.RroObasVersion.DefferedSetValue(destVersionKey);
        this.SourceOutlayKosgu.DefferedSetValue(sourceKey);
        this.PostRow();
        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
            this.SetFieldValue("Y" + i + "_D", 0);
        }
        this.RroAddAnalysisIndicatorTable.CreateNewVersions(sourceKey, newKey);
        return newKey;
    };
    BaseRroOutlayKosguTable.prototype.FilterKosgu = function () {
        var rroObasTable = this.RroObasVersion.SourceTable.RroObasKey.SourceTable;
        var costCode = rroObasTable.RroDataKey.SourceTable.CostType.Code;
        return ObasTableCollection.KosguSprTable.Filter(rroObasTable.Obas.ForeignKey.Value, costCode);
    };
    return BaseRroOutlayKosguTable;
}(ObasTable));
var RroOutlayKosguTable = (function (_super) {
    __extends(RroOutlayKosguTable, _super);
    function RroOutlayKosguTable() {
        return _super.call(this, "RRO_Outlay_KOSGU") || this;
    }
    Object.defineProperty(RroOutlayKosguTable.prototype, "RroObasVersions", {
        get: function () {
            return ObasTableCollection.RroObasVersionsTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlayKosguTable.prototype, "RroAddAnalysisIndicatorTable", {
        get: function () {
            return ObasTableCollection.RroObasAddAnalysisIndicatorTable;
        },
        enumerable: true,
        configurable: true
    });
    return RroOutlayKosguTable;
}(BaseRroOutlayKosguTable));
var RroSumOutlayKosguTable = (function (_super) {
    __extends(RroSumOutlayKosguTable, _super);
    function RroSumOutlayKosguTable() {
        return _super.call(this, "RRO_SumOutlay_KOSGU") || this;
    }
    Object.defineProperty(RroSumOutlayKosguTable.prototype, "RroObasVersions", {
        get: function () {
            return ObasTableCollection.RroSumObasVersionsTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroSumOutlayKosguTable.prototype, "RroAddAnalysisIndicatorTable", {
        get: function () {
            return ObasTableCollection.RroSumObasAddAnalysisIndicatorTable;
        },
        enumerable: true,
        configurable: true
    });
    RroSumOutlayKosguTable.prototype.GetRecordKey = function (rroObasVersionKey, rroKosguKey, addIfNotExists) {
        return ObasHelper.GetValueByKeys(this, [this.RroObasVersion.Id, this.Kosgu.ForeignKey.Id], [rroObasVersionKey, rroKosguKey], this.RecordKey.Id, addIfNotExists);
    };
    return RroSumOutlayKosguTable;
}(BaseRroOutlayKosguTable));
var BaseRroObasAddAnalysisIndicatorTable = (function (_super) {
    __extends(BaseRroObasAddAnalysisIndicatorTable, _super);
    function BaseRroObasAddAnalysisIndicatorTable() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._addAnalyticIndicator = null;
        _this._rroOutlayKosgu = null;
        return _this;
    }
    Object.defineProperty(BaseRroObasAddAnalysisIndicatorTable.prototype, "RroOutlayKosguKey", {
        get: function () {
            if (this._rroOutlayKosgu == null) {
                this._rroOutlayKosgu = new ObasForeignKeyTableFieldTyped(this.RroOutlayKosguTable, this);
            }
            return this._rroOutlayKosgu;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroObasAddAnalysisIndicatorTable.prototype, "AddAnalyticIndicator", {
        get: function () {
            if (this._addAnalyticIndicator == null) {
                this._addAnalyticIndicator = new ObasSprTableFieldTyped(ObasTableCollection.AddAnalysisIndicatorSprTable, this);
            }
            return this._addAnalyticIndicator;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroObasAddAnalysisIndicatorTable.prototype.IsKosguChild = function (kosguKey) {
        if (kosguKey === void 0) { kosguKey = this.RroOutlayKosguTable.Kosgu.ForeignKey.Value; }
        return ObasTableCollection.AddAnalysisIndicatorSprTable.IsKosguChild(kosguKey);
    };
    BaseRroObasAddAnalysisIndicatorTable.prototype.SendToPack = function (rroOutlayKosguKey, sourcePackKey, rroKosguKey) {
        var versionKeyId = this.RroOutlayKosguKey.Id;
        while (this.Locate(versionKeyId, rroOutlayKosguKey, true)) {
            this.AddToPack(sourcePackKey, rroKosguKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroObasAddAnalysisIndicatorTable.prototype.AddToPack = function (sourcePackKey, rroKosguKey) {
        var _this = this;
        var destTable = ObasTableCollection.OutlayAnalysisIndicatorExchangeDataTable;
        if (destTable.GetRecordKey(destTable.GetKeys(sourcePackKey, rroKosguKey, this.AddAnalyticIndicator.ForeignKey.Value, false), true)) {
            var fieldChange_2 = function (fieldId) {
                var oldValue = destTable.GetFieldValue(fieldId) || 0;
                var newValue = oldValue + _this.GetFieldValue(fieldId) || 0;
                destTable.SetFieldValue(fieldId, newValue);
            };
            var fieldGen = function (field, yearIndex) {
                var fieldId = field.GenerateId(yearIndex);
                fieldChange_2(fieldId);
                fieldId = fieldId + "_D";
                fieldChange_2(fieldId);
            };
            var yearDataField = BaseObasTableFields.YearDataField;
            var usdDataField = BaseObasTableFields.UsdYearDataField;
            for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                fieldGen(yearDataField, i);
                fieldGen(usdDataField, i);
            }
            return destTable.RecordKey.Value;
        }
        return null;
    };
    BaseRroObasAddAnalysisIndicatorTable.prototype.CreateNewVersions = function (sourceRroKosguKey, destRroKosguKey) {
        while (this.Locate(this.RroOutlayKosguKey.Id, sourceRroKosguKey, true)) {
            this.CreateNewVersion(this.RecordKey.Value, destRroKosguKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroObasAddAnalysisIndicatorTable.prototype.CreateNewVersion = function (sourceKey, destRroKosguKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.RroOutlayKosguKey.DefferedSetValue(destRroKosguKey);
        this.PostRow();
        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
            this.SetFieldValue("Y" + i + "_D", 0);
        }
        return newKey;
    };
    return BaseRroObasAddAnalysisIndicatorTable;
}(ObasTable));
var RroObasAddAnalysisIndicatorTable = (function (_super) {
    __extends(RroObasAddAnalysisIndicatorTable, _super);
    function RroObasAddAnalysisIndicatorTable() {
        return _super.call(this, "RRO_OBAS_AddAnalysisIndicator") || this;
    }
    Object.defineProperty(RroObasAddAnalysisIndicatorTable.prototype, "RroOutlayKosguTable", {
        get: function () {
            return ObasTableCollection.RroOutlayKosguTable;
        },
        enumerable: true,
        configurable: true
    });
    return RroObasAddAnalysisIndicatorTable;
}(BaseRroObasAddAnalysisIndicatorTable));
var RroSumObasAddAnalysisIndicatorTable = (function (_super) {
    __extends(RroSumObasAddAnalysisIndicatorTable, _super);
    function RroSumObasAddAnalysisIndicatorTable() {
        return _super.call(this, "RRO_SumOBAS_AddAnalysisIndicator") || this;
    }
    Object.defineProperty(RroSumObasAddAnalysisIndicatorTable.prototype, "RroOutlayKosguTable", {
        get: function () {
            return ObasTableCollection.RroSumOutlayKosguTable;
        },
        enumerable: true,
        configurable: true
    });
    RroSumObasAddAnalysisIndicatorTable.prototype.GetRecordKey = function (rroOutlayKosguKey, addAnalysisIndicatorKey, addIfNotExists) {
        return ObasHelper.GetValueByKeys(this, [this.RroOutlayKosguKey.Id, this.AddAnalyticIndicator.ForeignKey.Id], [rroOutlayKosguKey, addAnalysisIndicatorKey], this.RecordKey.Id, addIfNotExists);
    };
    return RroSumObasAddAnalysisIndicatorTable;
}(BaseRroObasAddAnalysisIndicatorTable));
var RroPedCountTable = (function (_super) {
    __extends(RroPedCountTable, _super);
    function RroPedCountTable() {
        var _this = _super.call(this, "RRO_PED_Count", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._docsCount = new ObasTableField("DocsCount", _this);
        _this._pedType = new ObasSprTableField(ObasTableCollection.PedTypeSprTable, _this);
        return _this;
    }
    Object.defineProperty(RroPedCountTable.prototype, "DocumentsCount", {
        get: function () {
            return this._docsCount;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroPedCountTable.prototype, "PedType", {
        get: function () {
            return this._pedType;
        },
        enumerable: true,
        configurable: true
    });
    return RroPedCountTable;
}(ObasTable));
var RroPedTable = (function (_super) {
    __extends(RroPedTable, _super);
    function RroPedTable() {
        var _this = _super.call(this, "RRO_PED", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._pedType = null;
        _this._pedStatus = null;
        _this._dateApprove = new ObasTableField("DateApprove", _this);
        _this._pedNumber = new ObasTableField("Spr_Num", _this);
        return _this;
    }
    Object.defineProperty(RroPedTable.prototype, "PedNumber", {
        get: function () {
            return this._pedNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroPedTable.prototype, "DateApprove", {
        get: function () {
            return this._dateApprove;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroPedTable.prototype, "PedType", {
        get: function () {
            if (this._pedType == null) {
                this._pedType = new ObasSprTableField(ObasTableCollection.PedTypeSprTable, this);
            }
            return this._pedType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroPedTable.prototype, "PedStatus", {
        get: function () {
            if (this._pedStatus == null) {
                this._pedStatus = new ObasSprTableField(ObasTableCollection.StatusSprTable, this);
            }
            return this._pedStatus;
        },
        enumerable: true,
        configurable: true
    });
    RroPedTable.prototype.ChangeTypeChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var versionTable = ObasTableCollection.RroObasVersionsTable;
        var locateValues = this.RecordKey.Value;
        while (versionTable.Locate(versionTable.RroPedKey.Id, locateValues, true)) {
            versionTable.ChangeType.ForeignKey.Value = newValue;
        }
        versionTable.ClearLocateFlag();
    };
    RroPedTable.prototype.PedTypeChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var pedSpr = ObasTableCollection.PedTypeSprTable;
        var pedTypesKey = new Array();
        var attachNum = pedSpr.AttachNumber.LookupByKeys(this.PedType.ForeignKey.Value);
        while (pedSpr.Locate(pedSpr.AttachNumber.Id, attachNum, true)) {
            pedTypesKey.push(pedSpr.RecordKey.Value);
        }
        pedSpr.ClearLocateFlag();
        var pedCountTable = ObasTableCollection.RroPedCountTable;
        var result = 0;
        for (var i = 0; i < pedTypesKey.length; i++) {
            var pedTypeKey = pedTypesKey[i];
            if (!pedCountTable.Locate(pedCountTable.PedType.Id, pedTypeKey)) {
                pedCountTable.AddRow();
                pedCountTable.PedType.ForeignKey.Value = pedTypeKey;
                pedCountTable.DocumentsCount.Value = 0;
                pedCountTable.PostRow();
            }
            if (pedCountTable.PedType.ForeignKey.Value === pedTypeKey) {
                pedCountTable.DocumentsCount.Value++;
            }
            result += pedCountTable.DocumentsCount.Value;
        }
        var strNumber = "";
        strNumber += "3-";
        strNumber += attachNum;
        strNumber += "-";
        strNumber += ObasTableCollection.SelectedFoivTable.Foiv.Code;
        strNumber += "//";
        strNumber += ObasHelper.FillWithCharacter(result.toString(), 4);
        this.PedNumber.Value = strNumber;
    };
    RroPedTable.prototype.PedStatusChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var rroVersions = ObasTableCollection.RroObasVersionsTable;
        var curPedKey = this.RecordKey.Value;
        while (rroVersions.Locate(rroVersions.RroPedKey.Id, curPedKey, true)) {
            rroVersions.Status.ForeignKey.Value = newValue;
        }
        rroVersions.ClearLocateFlag();
    };
    RroPedTable.prototype.PedStatusInitEventHandler = function (tableId, fieldId) {
        return VersionStatus.Draft;
    };
    return RroPedTable;
}(ObasTable));
var BuildParamsTable = (function (_super) {
    __extends(BuildParamsTable, _super);
    function BuildParamsTable() {
        var _this = _super.call(this, "BuildParams", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._canPrepareVersions = null;
        _this._exportFolder = new ObasTableField("ExportFolder", _this);
        _this._canSyncRroDataChanges = new ObasTableField("CanSyncRroDataChanges", _this);
        return _this;
    }
    Object.defineProperty(BuildParamsTable.prototype, "ExportDirectory", {
        get: function () {
            return this._exportFolder;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BuildParamsTable.prototype, "CanPrepareVersions", {
        get: function () {
            if (this._canPrepareVersions == null) {
                this._canPrepareVersions = new ObasTableField("CanPrepareVersions", this);
            }
            return this._canPrepareVersions;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BuildParamsTable.prototype, "CanSyncRroDataChanges", {
        get: function () {
            return this._canSyncRroDataChanges;
        },
        enumerable: true,
        configurable: true
    });
    BuildParamsTable.prototype.ExportDirectoryInitEventHandler = function (tableId, fieldId) {
        var result = ObasStageSettings.ExportExcelDirectory;
        if (!Client.IsDirectoryExists(result)) {
            Client.CreateDirectory(result);
        }
        return result;
    };
    BuildParamsTable.prototype.ExportDirectoryChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        if (!Client.IsDirectoryExists(newValue)) {
            Client.CreateDirectory(newValue);
        }
    };
    BuildParamsTable.prototype.CanPrepareVersionsInitEventHandler = function (tableId, fieldId) {
        return ObasTableCollection.RroObasVersionsTable.RowCount === 0;
    };
    return BuildParamsTable;
}(ObasTable));
var SelectedFoivTable = (function (_super) {
    __extends(SelectedFoivTable, _super);
    function SelectedFoivTable() {
        var _this = _super.call(this, "SELECTED_FOIV", [BaseObasTableFields.RecordKeyField.Id], false) || this;
        _this._foiv = null;
        _this._budgetAuthorityField = null;
        _this._recipient = null;
        _this._manager = null;
        _this._foivRegCode = null;
        _this._foivInfo = null;
        _this._budgetName = null;
        _this._calcRecipientName = null;
        return _this;
    }
    Object.defineProperty(SelectedFoivTable.prototype, "BudgetName", {
        get: function () {
            if (this._budgetName == null) {
                this._budgetName = new ObasTableField("BudgetName", this);
            }
            return this._budgetName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "FoivInfo", {
        get: function () {
            if (this._foivInfo == null) {
                this._foivInfo = new UserInfoTableField("FOIV", this);
            }
            return this._foivInfo;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "Manager", {
        get: function () {
            if (this._manager == null) {
                this._manager = new UserInfoTableField("Manager", this);
            }
            return this._manager;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "Recipient", {
        get: function () {
            if (this._recipient == null) {
                this._recipient = new UserInfoTableField("Recipient", this);
            }
            return this._recipient;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "BudgetAuthorityField", {
        get: function () {
            if (this._budgetAuthorityField == null) {
                this._budgetAuthorityField = new ObasSprTableField(ObasTableCollection.BudgetAuthoritySprTable, this);
            }
            return this._budgetAuthorityField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "CalcRecipientName", {
        get: function () {
            if (this._calcRecipientName == null) {
                this._calcRecipientName = new ObasTableField("cRecipient_Name", this);
            }
            return this._calcRecipientName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "Foiv", {
        get: function () {
            if (this._foiv == null) {
                this._foiv = new ObasSprTableField(ObasTableCollection.FoivTable, this);
            }
            return this._foiv;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "BudgetAuthority", {
        get: function () {
            return this.BudgetAuthorityField.ForeignKey.Value;
        },
        set: function (value) {
            this.BudgetAuthorityField.ForeignKey.Value = value;
        },
        enumerable: true,
        configurable: true
    });
    SelectedFoivTable.prototype.InitBudgetNameEventHandler = function (tableId, fieldId) {
        return "Федеральный бюджет";
    };
    Object.defineProperty(SelectedFoivTable.prototype, "UserField", {
        get: function () {
            switch (this.BudgetAuthority) {
                case BudgetAuthority.Recipient:
                    return this.Recipient;
                case BudgetAuthority.Manager:
                    return this.Manager;
                case BudgetAuthority.MainManager:
                    return this.FoivInfo;
            }
            return null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "ManagerField", {
        get: function () {
            switch (this.BudgetAuthority) {
                case BudgetAuthority.Recipient:
                case BudgetAuthority.Manager:
                    return this.Manager;
                case BudgetAuthority.MainManager:
                    return this.FoivInfo;
            }
            return null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "UserRegCode", {
        get: function () {
            var field = this.UserField;
            return field ? field.RegCodeField.Value : null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "UserOktmoCode", {
        get: function () {
            var field = this.UserField;
            return field ? field.OktmoCodeField.Value : null;
        },
        enumerable: true,
        configurable: true
    });
    SelectedFoivTable.prototype.CheckCode = function (code, length) {
        return (code || "").length === length;
    };
    SelectedFoivTable.prototype.CheckRegCode = function (auth, userField) {
        var code = userField.RegCodeField.Value;
        if (this.BudgetAuthority !== auth || this.CheckCode(code, 8)) {
            return undefined;
        }
        else {
            return "Код по перечню должен составлять 8 знаков";
        }
    };
    SelectedFoivTable.prototype.CheckFOIVRegCode = function () {
        return this.CheckRegCode(BudgetAuthority.MainManager, this.FoivInfo);
    };
    SelectedFoivTable.prototype.CheckManagerRegCode = function () {
        return this.CheckRegCode(BudgetAuthority.Manager, this.Manager);
    };
    SelectedFoivTable.prototype.IsMainManager = function () {
        return this.BudgetAuthority === BudgetAuthority.MainManager;
    };
    SelectedFoivTable.prototype.IsManager = function () {
        return this.BudgetAuthority === BudgetAuthority.Manager;
    };
    SelectedFoivTable.prototype.IsRecipient = function () {
        return this.BudgetAuthority === BudgetAuthority.Recipient;
    };
    SelectedFoivTable.prototype.CheckOktmoCode = function (tableId, fieldId) {
        if (this.IsRecipient() && fieldId === this.Recipient.OktmoCodeField.Id) {
            return this.Recipient.CheckOktmoCode();
        }
        else if (this.IsManager() && fieldId === this.Manager.OktmoCodeField.Id) {
            return this.Manager.CheckOktmoCode();
        }
        else if (this.IsMainManager() && fieldId === this.FoivInfo.OktmoCodeField.Id) {
            return this.FoivInfo.CheckOktmoCode();
        }
        return undefined;
    };
    Object.defineProperty(SelectedFoivTable.prototype, "RecipientName", {
        get: function () {
            var field = this.UserField;
            return field ? field.Name.Value : "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "RecipientRegCode", {
        get: function () {
            var field = this.UserField;
            return field ? field.RegCodeField.Value : "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "ManagerName", {
        get: function () {
            var field = this.ManagerField;
            return field ? field.Name.Value : "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedFoivTable.prototype, "ManagerRegCode", {
        get: function () {
            var field = this.ManagerField;
            return field ? field.RegCodeField.Value : "";
        },
        enumerable: true,
        configurable: true
    });
    SelectedFoivTable.prototype.RecipientNameChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.CalcRecipientName.Value = this.RecipientName;
    };
    SelectedFoivTable.prototype.InitcRecipientNameEventHandler = function (tableId, fieldId) {
        return this.RecipientName;
    };
    return SelectedFoivTable;
}(ObasTable));
var RroLimitsDetailsTable = (function (_super) {
    __extends(RroLimitsDetailsTable, _super);
    function RroLimitsDetailsTable() {
        var _this = _super.call(this, "RRO_LIMITS_DETAIL") || this;
        _this._limit = new ObasTableField("Y2_Plan", _this);
        return _this;
    }
    Object.defineProperty(RroLimitsDetailsTable.prototype, "Limit", {
        get: function () {
            return this._limit;
        },
        enumerable: true,
        configurable: true
    });
    return RroLimitsDetailsTable;
}(ObasTableWithKbkData));
var RroNpaTable = (function (_super) {
    __extends(RroNpaTable, _super);
    function RroNpaTable() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._prfNpaRequisites = null;
        _this._prfNpaLink = null;
        _this._costNpaRequisites = null;
        _this._costNpaLink = null;
        _this._rroDataKey = null;
        return _this;
    }
    Object.defineProperty(RroNpaTable.prototype, "RroDataKey", {
        get: function () {
            if (this._rroDataKey == null) {
                this._rroDataKey = new ObasForeignKeyTableFieldTyped(ObasTableCollection.RroDataTable, this);
            }
            return this._rroDataKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroNpaTable.prototype, "CostNpaLink", {
        get: function () {
            if (this._costNpaLink == null) {
                this._costNpaLink = new EndingNpaLinkFields(this, "N2");
            }
            return this._costNpaLink;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroNpaTable.prototype, "CostNpaRequisites", {
        get: function () {
            if (this._costNpaRequisites == null) {
                this._costNpaRequisites = new NpaRequisitesFields(this, "N2Num", "N2Name", "N2Date", "N2Type");
            }
            return this._costNpaRequisites;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroNpaTable.prototype, "PrfNpaLink", {
        get: function () {
            if (this._prfNpaLink == null) {
                this._prfNpaLink = new NpaLinkFields(this, "N1");
            }
            return this._prfNpaLink;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroNpaTable.prototype, "PrfNpaRequisites", {
        get: function () {
            if (this._prfNpaRequisites == null) {
                this._prfNpaRequisites = new PrfNpaRequisitesFields(this, "N1Num", "N1Name", "N1Date", "N1Type");
            }
            return this._prfNpaRequisites;
        },
        enumerable: true,
        configurable: true
    });
    return RroNpaTable;
}(ObasTable));
var OutlayExchangeDataTableKeys = (function (_super) {
    __extends(OutlayExchangeDataTableKeys, _super);
    function OutlayExchangeDataTableKeys(FcrKey, ProgramKey, SubprogramKey, MainActionKey, DirectionCostKey, CostTypeKey, ObasKey, SenderCode) {
        var _this = _super.call(this) || this;
        _this.FcrKey = FcrKey;
        _this.ProgramKey = ProgramKey;
        _this.SubprogramKey = SubprogramKey;
        _this.MainActionKey = MainActionKey;
        _this.DirectionCostKey = DirectionCostKey;
        _this.CostTypeKey = CostTypeKey;
        _this.ObasKey = ObasKey;
        _this.SenderCode = SenderCode;
        return _this;
    }
    return OutlayExchangeDataTableKeys;
}(ObasTableKeys));
var OutlayExchangeDataTable = (function (_super) {
    __extends(OutlayExchangeDataTable, _super);
    function OutlayExchangeDataTable(id) {
        if (id === void 0) { id = "OutlayExchangeData"; }
        var _this = _super.call(this, id, ["FCR_ID", "Program_ID", "SubProgram_ID", "MainAction_ID", "DirectionCost_ID", "VR_ID", "OBAS_SPR_ID", "Sender_Code"]) || this;
        _this._obas = null;
        _this._senderCode = null;
        _this._securityType = null;
        _this._kbkHelper = null;
        _this._okv = null;
        return _this;
    }
    Object.defineProperty(OutlayExchangeDataTable.prototype, "Okv", {
        get: function () {
            if (this._okv == null) {
                this._okv = new ObasSprTableFieldTyped(ObasTableCollection.OkvSprTable, this);
            }
            return this._okv;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "KbkHelper", {
        get: function () {
            if (this._kbkHelper == null) {
                this._kbkHelper = new ObasTableWithKbkData(this.Id, this.KeyFieldIds);
            }
            return this._kbkHelper;
        },
        enumerable: true,
        configurable: true
    });
    OutlayExchangeDataTable.prototype.GetKbkKeyFieldsValue = function () {
        return this.KbkHelper.GetKbkKeyFieldsValue();
    };
    Object.defineProperty(OutlayExchangeDataTable.prototype, "SecurityType", {
        get: function () {
            if (this._securityType == null) {
                this._securityType = new ObasSprTableFieldTyped(ObasTableCollection.SecurityTypesTable, this);
            }
            return this._securityType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "SenderCode", {
        get: function () {
            if (this._senderCode == null) {
                this._senderCode = new ObasTableField("Sender_Code", this);
            }
            return this._senderCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "Obas", {
        get: function () {
            if (this._obas == null) {
                this._obas = new ObasSprTableFieldTyped(ObasTableCollection.ObasSprTable, this);
            }
            return this._obas;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "Fcr", {
        get: function () {
            return this.KbkHelper.Fcr;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "GovermentProgram", {
        get: function () {
            return this.KbkHelper.GovermentProgram;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "SubProgram", {
        get: function () {
            return this.KbkHelper.SubProgram;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "MainAction", {
        get: function () {
            return this.KbkHelper.MainAction;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "DirectionCost", {
        get: function () {
            return this.KbkHelper.DirectionCost;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayExchangeDataTable.prototype, "CostType", {
        get: function () {
            return this.KbkHelper.CostType;
        },
        enumerable: true,
        configurable: true
    });
    OutlayExchangeDataTable.prototype.SenderCodeInitEventhandler = function (tableId, fieldId) {
        return ObasTableCollection.SelectedFoivTable.UserRegCode;
    };
    OutlayExchangeDataTable.prototype.GetKeys = function (fcrKey, programKey, subprogramKey, mainActionKey, directionCostKey, costTypeKey, obasKey, senderCode) {
        if (fcrKey === void 0) { fcrKey = this.Fcr.ForeignKey.Value; }
        if (programKey === void 0) { programKey = this.GovermentProgram.ForeignKey.Value; }
        if (subprogramKey === void 0) { subprogramKey = this.SubProgram.ForeignKey.Value; }
        if (mainActionKey === void 0) { mainActionKey = this.MainAction.ForeignKey.Value; }
        if (directionCostKey === void 0) { directionCostKey = this.DirectionCost.ForeignKey.Value; }
        if (costTypeKey === void 0) { costTypeKey = this.CostType.ForeignKey.Value; }
        if (obasKey === void 0) { obasKey = this.Obas.ForeignKey.Value; }
        if (senderCode === void 0) { senderCode = this.SenderCode.Value; }
        if (this._keys == null) {
            this._keys = new OutlayExchangeDataTableKeys(fcrKey, programKey, subprogramKey, mainActionKey, directionCostKey, costTypeKey, obasKey, senderCode);
        }
        else {
            this._keys.FcrKey = fcrKey;
            this._keys.ProgramKey = programKey;
            this._keys.SubprogramKey = subprogramKey;
            this._keys.MainActionKey = mainActionKey;
            this._keys.DirectionCostKey = directionCostKey;
            this._keys.CostTypeKey = costTypeKey;
            this._keys.ObasKey = obasKey;
            this._keys.SenderCode = senderCode;
        }
        return this._keys;
    };
    return OutlayExchangeDataTable;
}(BaseObasTableWithKeys));
var OutlayAnalysisIndicatorExchangeDataTableKeys = (function (_super) {
    __extends(OutlayAnalysisIndicatorExchangeDataTableKeys, _super);
    function OutlayAnalysisIndicatorExchangeDataTableKeys(OwnerKey, KosguKey, AddAnalysisIndicatorKey, IsPart4Outlay) {
        var _this = _super.call(this) || this;
        _this.OwnerKey = OwnerKey;
        _this.KosguKey = KosguKey;
        _this.AddAnalysisIndicatorKey = AddAnalysisIndicatorKey;
        _this.IsPart4Outlay = IsPart4Outlay;
        return _this;
    }
    return OutlayAnalysisIndicatorExchangeDataTableKeys;
}(ObasTableKeys));
var OutlayAnalysisIndicatorExchangeDataTable = (function (_super) {
    __extends(OutlayAnalysisIndicatorExchangeDataTable, _super);
    function OutlayAnalysisIndicatorExchangeDataTable(id, _parentTable) {
        var _this = _super.call(this, id, [BaseObasTableFields.OwnerKeyField.Id, "Kosgu_ID", "AddAnalysisIndicator_ID", "IsPart4Outlay"]) || this;
        _this._parentTable = _parentTable;
        _this._ownerKey = null;
        _this._kosgu = null;
        _this._addAnalyticIndicator = null;
        _this._isPart4Outlay = null;
        return _this;
    }
    Object.defineProperty(OutlayAnalysisIndicatorExchangeDataTable.prototype, "OwnerKey", {
        get: function () {
            if (this._ownerKey == null) {
                this._ownerKey = new ObasForeignKeyTableFieldTyped(this._parentTable, this, BaseObasTableFields.OwnerKeyField.Id, false, true);
            }
            return this._ownerKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayAnalysisIndicatorExchangeDataTable.prototype, "Kosgu", {
        get: function () {
            if (this._kosgu == null) {
                this._kosgu = new ObasSprTableField(ObasTableCollection.KosguSprTable, this);
            }
            return this._kosgu;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayAnalysisIndicatorExchangeDataTable.prototype, "AddAnalyticIndicator", {
        get: function () {
            if (this._addAnalyticIndicator == null) {
                this._addAnalyticIndicator = new ObasSprTableFieldTyped(ObasTableCollection.AddAnalysisIndicatorSprTable, this);
            }
            return this._addAnalyticIndicator;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OutlayAnalysisIndicatorExchangeDataTable.prototype, "IsPart4Outlay", {
        get: function () {
            if (this._isPart4Outlay == null) {
                this._isPart4Outlay = new ObasTableField("IsPart4Outlay", this);
            }
            return this._isPart4Outlay;
        },
        enumerable: true,
        configurable: true
    });
    OutlayAnalysisIndicatorExchangeDataTable.prototype.GetKeys = function (ownerKey, kosguKey, addAnalysisIndicatorKey, isPart4Outlay) {
        if (ownerKey === void 0) { ownerKey = this.OwnerKey.Value; }
        if (kosguKey === void 0) { kosguKey = this.KosguKey.Value; }
        if (addAnalysisIndicatorKey === void 0) { addAnalysisIndicatorKey = this.AddAnalyticIndicator.ForeignKey.Value; }
        if (isPart4Outlay === void 0) { isPart4Outlay = this.IsPart4Outlay.Value; }
        if (this._keys == null) {
            this._keys = new OutlayAnalysisIndicatorExchangeDataTableKeys(ownerKey, kosguKey, addAnalysisIndicatorKey);
        }
        else {
            this._keys.OwnerKey = ownerKey;
            this._keys.KosguKey = kosguKey;
            this._keys.AddAnalysisIndicatorKey = addAnalysisIndicatorKey;
            this._keys.IsPart4Outlay = isPart4Outlay;
        }
        return this._keys;
    };
    return OutlayAnalysisIndicatorExchangeDataTable;
}(BaseObasTableWithKeys));
var BaseRroExpendSheduleTable = (function (_super) {
    __extends(BaseRroExpendSheduleTable, _super);
    function BaseRroExpendSheduleTable() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._documentDate = null;
        _this._documentNumber = null;
        _this._loadDate = null;
        return _this;
    }
    Object.defineProperty(BaseRroExpendSheduleTable.prototype, "LoadDate", {
        get: function () {
            if (this._loadDate == null) {
                this._loadDate = new ObasTableField("LoadDate", this);
            }
            return this._loadDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroExpendSheduleTable.prototype, "DocumentNumber", {
        get: function () {
            if (this._documentNumber == null) {
                this._documentNumber = new ObasTableField("DocNumber", this);
            }
            return this._documentNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroExpendSheduleTable.prototype, "DocumentDate", {
        get: function () {
            if (this._documentDate == null) {
                this._documentDate = new ObasTableField("DocDate", this);
            }
            return this._documentDate;
        },
        enumerable: true,
        configurable: true
    });
    return BaseRroExpendSheduleTable;
}(ObasTable));
var ExpendSheduleElement = (function () {
    function ExpendSheduleElement(expendSheduleElementData) {
        this._docDate = null;
        this._docNumber = null;
        this._regCode = null;
        this._secType = null;
        this._kbks = [];
        var apRcElemParts = expendSheduleElementData.match(/APRC.*/gm)[0].split("|");
        this._docNumber = apRcElemParts[2];
        this._docDate = ObasHelper.ConvertStringToDate(apRcElemParts[3], DateFormat.Short);
        this._regCode = apRcElemParts[6];
        this._secType = this.ParseSecretType(apRcElemParts[5]);
        var apLboStrElems = expendSheduleElementData.match(/APLBOSTR.*/gm) || "";
        for (var _i = 0, apLboStrElems_1 = apLboStrElems; _i < apLboStrElems_1.length; _i++) {
            var apLboStrElem = apLboStrElems_1[_i];
            this._kbks.push(new ExpendSheduleKbkElement(apLboStrElem));
        }
    }
    ExpendSheduleElement.prototype.ParseSecretType = function (code) {
        switch (code) {
            case "0":
                return SecurityTypes.NotSecret;
            case "1":
                return SecurityTypes.DSP;
            case "2":
                return SecurityTypes.Secret;
            case "3":
                return SecurityTypes.TopSecret;
            default:
                return null;
        }
    };
    Object.defineProperty(ExpendSheduleElement.prototype, "SecurityType", {
        get: function () {
            return this._secType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleElement.prototype, "DocumentDate", {
        get: function () {
            return this._docDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleElement.prototype, "DocumentNumber", {
        get: function () {
            return this._docNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleElement.prototype, "UserRegCode", {
        get: function () {
            return this._regCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleElement.prototype, "KbkData", {
        get: function () {
            return this._kbks;
        },
        enumerable: true,
        configurable: true
    });
    return ExpendSheduleElement;
}());
var ExpendSheduleKbkElement = (function () {
    function ExpendSheduleKbkElement(expendSheduleLboElementData) {
        var apLboElemParts = expendSheduleLboElementData.split("|");
        this._code = apLboElemParts[1];
        this._lboData = [
            parseFloat(apLboElemParts[3]) || 0,
            parseFloat(apLboElemParts[4]) || 0,
            parseFloat(apLboElemParts[5]) || 0
        ];
    }
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "FullKbkCode", {
        get: function () {
            return this._code;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "LboData", {
        get: function () {
            return this._lboData;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "FoivCode", {
        get: function () {
            return this._code.substr(0, 3);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "FcrCode", {
        get: function () {
            return this._code.substr(3, 4);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "ProgramCode", {
        get: function () {
            return this._code.substr(7, 2);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "FullSubProgramCode", {
        get: function () {
            return this._code.substr(7, 3);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "FullMainActionCode", {
        get: function () {
            return this._code.substr(7, 5);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "DirectionCostCode", {
        get: function () {
            return this._code.substr(12, 5);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ExpendSheduleKbkElement.prototype, "TypeCostCode", {
        get: function () {
            return this._code.substr(17, 3);
        },
        enumerable: true,
        configurable: true
    });
    return ExpendSheduleKbkElement;
}());
var RroExpendSheduleTable = (function (_super) {
    __extends(RroExpendSheduleTable, _super);
    function RroExpendSheduleTable() {
        var _this = _super.call(this, "RRO_Expend_Shedule") || this;
        _this._rroDataKey = null;
        _this._historyTable = null;
        return _this;
    }
    Object.defineProperty(RroExpendSheduleTable.prototype, "HistoryTable", {
        get: function () {
            if (this._historyTable == null) {
                this._historyTable = new RroExpendSheduleHistoryTable();
            }
            return this._historyTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroExpendSheduleTable.prototype, "RroDataKey", {
        get: function () {
            if (this._rroDataKey == null) {
                this._rroDataKey = new ObasForeignKeyTableFieldTyped(ObasTableCollection.RroDataTable, this);
            }
            return this._rroDataKey;
        },
        enumerable: true,
        configurable: true
    });
    RroExpendSheduleTable.prototype.GetRecordKey = function (rroDataKey, addIfNotExists) {
        return ObasHelper.GetValueByKeys(this, [this.RroDataKey.Id], [rroDataKey], this.RecordKey.Id, addIfNotExists);
    };
    RroExpendSheduleTable.prototype.CreateNewVersion = function (srcRroDataKey, destRroDataKey) {
        var srcKey = this.GetRecordKey(srcRroDataKey);
        var newKey = this.CloneRow(srcKey, false);
        this.RroDataKey.DefferedSetValue(destRroDataKey);
        return newKey;
    };
    RroExpendSheduleTable.prototype.SetSum = function (fieldId, newValue) {
        var oldValue = this.GetFieldValue(fieldId) || 0;
        this.SetFieldValue(fieldId, oldValue + newValue);
    };
    RroExpendSheduleTable.prototype.LoadShedule = function (shedule, rroOutlayVersion) {
        var count = 0;
        var rroDataTable = ObasTableCollection.RroDataTable;
        var fcrSprTable = ObasTableCollection.FcrTable;
        var programSprTable = ObasTableCollection.GovermentProgramTable;
        var subprogramSprTable = ObasTableCollection.SubProgramTable;
        var mainActionSprTable = ObasTableCollection.MainActionTable;
        var directionCostSprTable = ObasTableCollection.DirectionCostTable;
        var typeCostSprTable = ObasTableCollection.CostTypeTable;
        var yearDataField = BaseObasTableFields.YearDataField;
        for (var _i = 0, _a = shedule.KbkData; _i < _a.length; _i++) {
            var kbkElem = _a[_i];
            if (rroDataTable.GetRecordKeyByKbk(fcrSprTable.LookupKeyByCode(kbkElem.FcrCode), programSprTable.LookupKeyByCode(kbkElem.ProgramCode), subprogramSprTable.LookupKeyByCode(kbkElem.FullSubProgramCode), mainActionSprTable.LookupKeyByCode(kbkElem.FullMainActionCode), directionCostSprTable.LookupKeyByCode(kbkElem.DirectionCostCode), typeCostSprTable.LookupKeyByCode(kbkElem.TypeCostCode), rroOutlayVersion, true)) {
                rroDataTable.SecurityType.ForeignKey.Value = shedule.SecurityType;
                if (this.GetRecordKey(rroDataTable.RecordKey.Value, true)) {
                    this.DocumentDate.Value = shedule.DocumentDate;
                    this.DocumentNumber.Value = shedule.DocumentNumber;
                    this.LoadDate.Value = new Date();
                    this.SaveVersion();
                    count++;
                    for (var i = 0; i < ObasStageSettings.YearsCount; i++) {
                        var fieldId = yearDataField.GenerateId(i + 1);
                        var value = kbkElem.LboData[i] || 0;
                        this.SetSum(fieldId, value);
                        this.HistoryTable.SetFieldValue(fieldId, value);
                    }
                }
            }
        }
        return count;
    };
    RroExpendSheduleTable.prototype.SaveVersion = function () {
        var _this = this;
        this.HistoryTable.AddRow();
        this.HistoryTable.RroSheduleKey.DefferedSetValue(this.RecordKey.Value);
        this.HistoryTable.LoadDate.DefferedSetValue(this.LoadDate.Value);
        this.HistoryTable.DocumentNumber.DefferedSetValue(this.DocumentNumber.Value);
        this.HistoryTable.DocumentDate.DefferedSetValue(this.DocumentDate.Value);
        var prevDataField = RroExpendSheduleHistoryTable.PrevYearDataField;
        var yearDataField = BaseObasTableFields.YearDataField;
        ObasStageSettings.IterateByYears(function (yearIndex) {
            _this.HistoryTable.SetFieldValue(prevDataField.GenerateId(yearIndex), _this.GetFieldValue(yearDataField.GenerateId(yearIndex)) || 0, false);
        });
        this.HistoryTable.PostRow();
    };
    return RroExpendSheduleTable;
}(BaseRroExpendSheduleTable));
var RroExpendSheduleHistoryTable = (function (_super) {
    __extends(RroExpendSheduleHistoryTable, _super);
    function RroExpendSheduleHistoryTable() {
        var _this = _super.call(this, "RRO_Expend_Shedule_History") || this;
        _this._rroSheduleKey = null;
        return _this;
    }
    Object.defineProperty(RroExpendSheduleHistoryTable, "PrevYearDataField", {
        get: function () {
            if (this._prevYearDataField == null) {
                this._prevYearDataField = new BaseGenericObasTableField("Prev_Y");
            }
            return this._prevYearDataField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroExpendSheduleHistoryTable.prototype, "RroSheduleKey", {
        get: function () {
            if (this._rroSheduleKey == null) {
                this._rroSheduleKey = new ObasForeignKeyTableFieldTyped(ObasTableCollection.RroExpendSheduleTable, this);
            }
            return this._rroSheduleKey;
        },
        enumerable: true,
        configurable: true
    });
    return RroExpendSheduleHistoryTable;
}(BaseRroExpendSheduleTable));
RroExpendSheduleHistoryTable._prevYearDataField = null;

var PartIndicateBudgetTypes;
(function (PartIndicateBudgetTypes) {
    PartIndicateBudgetTypes[PartIndicateBudgetTypes["Part1"] = 1] = "Part1";
    PartIndicateBudgetTypes[PartIndicateBudgetTypes["Part3"] = 2] = "Part3";
})(PartIndicateBudgetTypes || (PartIndicateBudgetTypes = {}));
var BaseRroPartIndicateBudgetValuesTable = (function (_super) {
    __extends(BaseRroPartIndicateBudgetValuesTable, _super);
    function BaseRroPartIndicateBudgetValuesTable(id, _rroObasVersionsTable) {
        var _this = _super.call(this, id) || this;
        _this._rroObasVersionsTable = _rroObasVersionsTable;
        _this._rroVersionKey = null;
        _this._partKey = null;
        _this._kosgu = null;
        return _this;
    }
    Object.defineProperty(BaseRroPartIndicateBudgetValuesTable.prototype, "PartKey", {
        get: function () {
            if (this._partKey == null) {
                this._partKey = new ObasTableField("RRO_PartIndicateBudgetStrCode_ID", this);
            }
            return this._partKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroPartIndicateBudgetValuesTable.prototype, "RroVersionKey", {
        get: function () {
            if (this._rroVersionKey == null) {
                this._rroVersionKey = new ObasForeignKeyTableFieldTyped(this._rroObasVersionsTable, this);
            }
            return this._rroVersionKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroPartIndicateBudgetValuesTable.prototype, "Kosgu", {
        get: function () {
            if (this._kosgu == null) {
                this._kosgu = new ObasSprTableField(ObasTableCollection.KosguSprTable, this);
            }
            return this._kosgu;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroPartIndicateBudgetValuesTable.prototype.IsPart3 = function () {
        return this.PartKey.Value === PartIndicateBudgetTypes.Part3;
    };
    BaseRroPartIndicateBudgetValuesTable.prototype.IsPart1 = function () {
        return this.PartKey.Value === PartIndicateBudgetTypes.Part1;
    };
    BaseRroPartIndicateBudgetValuesTable.prototype.SendToPack = function (rroObasVersion, sourcePackKey) {
        var versionKeyId = this.RroVersionKey.Id;
        while (this.Locate(versionKeyId, rroObasVersion, true)) {
            this.AddToPack(sourcePackKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroPartIndicateBudgetValuesTable.prototype.AddToPack = function (sourcePackKey) {
        var _this = this;
        var destTable = ObasTableCollection.OutlayAnalysisIndicatorExchangeDataTable;
        if (destTable.GetRecordKey(destTable.GetKeys(sourcePackKey, this.Kosgu.ForeignKey.Value, null, true), true)) {
            var fieldChange_4 = function (fieldId) {
                var oldValue = destTable.GetFieldValue(fieldId) || 0;
                var newValue = oldValue + _this.GetFieldValue(fieldId) || 0;
                destTable.SetFieldValue(fieldId, newValue);
            };
            var fieldGen = function (field, yearIndex) {
                var fieldId = field.GenerateId(yearIndex);
                fieldChange_4(fieldId);
                fieldId = fieldId + "_D";
                fieldChange_4(fieldId);
            };
            var yearDataField = BaseObasTableFields.YearDataField;
            var usdDataField = BaseObasTableFields.UsdYearDataField;
            for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                fieldGen(yearDataField, i);
                fieldGen(usdDataField, i);
            }
            return destTable.RecordKey.Value;
        }
        return null;
    };
    BaseRroPartIndicateBudgetValuesTable.prototype.CreateNewVersions = function (sourceVersionKey, destVersionKey) {
        while (this.Locate(this.RroVersionKey.Id, sourceVersionKey, true)) {
            this.CreateNewVersion(this.RecordKey.Value, destVersionKey);
        }
        this.ClearLocateFlag();
    };
    BaseRroPartIndicateBudgetValuesTable.prototype.CreateNewVersion = function (sourceKey, destVersionKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.RroVersionKey.DefferedSetValue(destVersionKey);
        this.PostRow();
        return newKey;
    };
    return BaseRroPartIndicateBudgetValuesTable;
}(ObasTable));
var RroPartIndicateBudgetValuesTable = (function (_super) {
    __extends(RroPartIndicateBudgetValuesTable, _super);
    function RroPartIndicateBudgetValuesTable() {
        return _super.call(this, "RRO_PartIndicateBudgetValues", ObasTableCollection.RroObasVersionsTable) || this;
    }
    return RroPartIndicateBudgetValuesTable;
}(BaseRroPartIndicateBudgetValuesTable));
var RroSumPartIndicateBudgetValuesTable = (function (_super) {
    __extends(RroSumPartIndicateBudgetValuesTable, _super);
    function RroSumPartIndicateBudgetValuesTable() {
        return _super.call(this, "RRO_SumPartIndicateBudgetValues", ObasTableCollection.RroSumObasVersionsTable) || this;
    }
    RroSumPartIndicateBudgetValuesTable.prototype.GetRecordKey = function (rroObasVersionKey, rroKosguKey, addIfNotExists) {
        return ObasHelper.GetValueByKeys(this, [this.RroVersionKey.Id, this.Kosgu.ForeignKey.Id], [rroObasVersionKey, rroKosguKey], this.RecordKey.Id, addIfNotExists);
    };
    return RroSumPartIndicateBudgetValuesTable;
}(BaseRroPartIndicateBudgetValuesTable));

var GroundsMakingChangesTable = (function (_super) {
    __extends(GroundsMakingChangesTable, _super);
    function GroundsMakingChangesTable() {
        var _this = _super.call(this, "GroundsMakingChanges") || this;
        _this._dateStart = null;
        _this._dateEnd = null;
        _this._isDescriptionRequired = null;
        return _this;
    }
    Object.defineProperty(GroundsMakingChangesTable.prototype, "DateStart", {
        get: function () {
            if (this._dateStart == null) {
                this._dateStart = new ObasTableField("DateStart", this);
            }
            return this._dateStart;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GroundsMakingChangesTable.prototype, "DateEnd", {
        get: function () {
            if (this._dateEnd == null) {
                this._dateEnd = new ObasTableField("DateEnd", this);
            }
            return this._dateEnd;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GroundsMakingChangesTable.prototype, "IsDescriptionRequired", {
        get: function () {
            if (this._isDescriptionRequired == null) {
                this._isDescriptionRequired = new ObasTableField("IsDescriptionRequired", this, false);
            }
            return this._isDescriptionRequired;
        },
        enumerable: true,
        configurable: true
    });
    GroundsMakingChangesTable.prototype.InitDateStartEventHandler = function (tableId, fieldId) {
        return ObasHelper.GetToday().toJSON();
    };
    GroundsMakingChangesTable.prototype.InitDateEndEventHandler = function (tableId, fieldId) {
        return "01.01.2099";
    };
    return GroundsMakingChangesTable;
}(ObasTable));
var ProcurementPlanStatuses;
(function (ProcurementPlanStatuses) {
    ProcurementPlanStatuses[ProcurementPlanStatuses["Draft"] = 1] = "Draft";
    ProcurementPlanStatuses[ProcurementPlanStatuses["AgreeSubmit"] = 2] = "AgreeSubmit";
    ProcurementPlanStatuses[ProcurementPlanStatuses["Agreed"] = 3] = "Agreed";
    ProcurementPlanStatuses[ProcurementPlanStatuses["ApproveSubmit"] = 4] = "ApproveSubmit";
    ProcurementPlanStatuses[ProcurementPlanStatuses["Approved"] = 5] = "Approved";
})(ProcurementPlanStatuses || (ProcurementPlanStatuses = {}));
var RroProcurementPlanTable = (function (_super) {
    __extends(RroProcurementPlanTable, _super);
    function RroProcurementPlanTable() {
        var _this = _super.call(this, "RRO_ProcurementPlan") || this;
        _this._numVersion = null;
        _this._name = null;
        _this._createDateField = null;
        _this._approvedDate = null;
        _this._statusSprField = null;
        _this._agreedDate = null;
        return _this;
    }
    Object.defineProperty(RroProcurementPlanTable.prototype, "NumVersion", {
        get: function () {
            if (this._numVersion == null) {
                this._numVersion = new NumberObasTableField("NumVersion", this);
            }
            return this._numVersion;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "AgreedDate", {
        get: function () {
            if (this._agreedDate == null) {
                this._agreedDate = new ObasTableField("AgreedDate", this);
            }
            return this._agreedDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "StatusSprField", {
        get: function () {
            if (this._statusSprField == null) {
                this._statusSprField = new ObasSprTableField(ObasTableCollection.ProcurementPlanStatusSprTable, this);
            }
            return this._statusSprField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "Status", {
        get: function () {
            return this.StatusSprField.ForeignKey.Value;
        },
        set: function (value) {
            this.StatusSprField.ForeignKey.Value = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "ApprovedDate", {
        get: function () {
            if (this._approvedDate == null) {
                this._approvedDate = new ObasTableField("ApprovedDate", this, false);
            }
            return this._approvedDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "CreateDate", {
        get: function () {
            return this.CreateDateField.Value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "CreateDateField", {
        get: function () {
            if (this._createDateField == null) {
                this._createDateField = new ObasTableField("CreateDate", this, true);
            }
            return this._createDateField;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementPlanTable.prototype, "Name", {
        get: function () {
            if (this._name == null) {
                this._name = new ObasTableField("Name", this, true);
            }
            return this._name;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementPlanTable.prototype.CalcDocNumber = function () {
        var year = ObasStageSettings.CurrentYear.toString();
        year = year.substring(2, 4);
        var foivCode = this.CalcFoivCode();
        var recipientRegCode = this.CalcRecipientRegCode();
        var num = "0001";
        return "3-77-" + year + "-" + foivCode + "/" + recipientRegCode + "/" + num;
    };
    RroProcurementPlanTable.prototype.CalcDocKind = function () {
        if (this.NumVersion.Value === 0) {
            return "\u0411\u0430\u0437\u043E\u0432\u044B\u0439";
        }
        else {
            return "\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0435";
        }
    };
    RroProcurementPlanTable.prototype.CalcFoivCode = function () {
        return ObasTableCollection.SelectedFoivTable.Foiv.Code;
    };
    RroProcurementPlanTable.prototype.CalcRecipientRegCode = function () {
        return ObasTableCollection.SelectedFoivTable.GetFieldValue("Recipient_RegCode");
    };
    RroProcurementPlanTable.prototype.CalcRecipientName = function () {
        return ObasTableCollection.SelectedFoivTable.GetFieldValue("Recipient_Name");
    };
    RroProcurementPlanTable.prototype.InitStatusEventHandler = function (tableId, fieldId) {
        return ProcurementPlanStatuses.Draft;
    };
    RroProcurementPlanTable.prototype.InitCreateDateEventHandler = function (tableId, fieldId) {
        return ObasHelper.GetToday().toJSON();
    };
    RroProcurementPlanTable.prototype.StatusChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        if (newValue !== ProcurementPlanStatuses.Approved) {
            this.ApprovedDate.Value = null;
        }
        if (newValue !== ProcurementPlanStatuses.Agreed) {
            this.AgreedDate.Value = null;
        }
    };
    RroProcurementPlanTable.prototype.AddEventHandler = function (tableId) {
        this.NumVersion.Value = this.GetMaxNumVersion();
        if (this.RowCount > 1) {
            this.NumVersion.Value = this.NumVersion.Value + 1;
        }
    };
    RroProcurementPlanTable.prototype.DeleteEventHandler = function (tableId) {
        var curKey = this.RecordKey.Value;
        ObasTableCollection.RroProcurementTable.DeleteRowsProcurementPlan(curKey);
    };
    RroProcurementPlanTable.prototype.GetMaxNumVersion = function () {
        var maxNumVersion = 0;
        this.SavePosition();
        this.First();
        for (var i = 0; i < this.RowCount; i++) {
            if (this.NumVersion.Value > maxNumVersion) {
                maxNumVersion = this.NumVersion.Value;
            }
            this.Next();
        }
        this.RestorePosition();
        return maxNumVersion;
    };
    RroProcurementPlanTable.prototype.CreateNewVersion = function (newKey) {
        if (this.RowCount > 1) {
            var sourceKey = 1;
            this.SavePosition();
            this.First();
            for (var i = 0; i < this.RowCount; i++) {
                var curKey = this.RecordKey.Value;
                if ((curKey > sourceKey) && (curKey < newKey)) {
                    sourceKey = curKey;
                }
                this.Next();
            }
            this.RestorePosition();
            ObasTableCollection.RroProcurementTable.CreateNewVersions(sourceKey, newKey);
        }
    };
    RroProcurementPlanTable.prototype.IsDraft = function () {
        return this.Status === ProcurementPlanStatuses.Draft;
    };
    return RroProcurementPlanTable;
}(ObasTable));

var RroProcurementTable = (function (_super) {
    __extends(RroProcurementTable, _super);
    function RroProcurementTable() {
        var _this = _super.call(this, "RRO_Procurement") || this;
        _this._procurementPlanKey = null;
        _this._numStr = null;
        _this._ikz = null;
        _this._objectName = null;
        _this._okpdCode = null;
        _this._okpdName = null;
        _this._procurementTypeKey = null;
        _this._isEnlargedKey = null;
        _this._placementYearKey = null;
        _this._dateBegin = null;
        _this._dateEnd = null;
        _this._periodicityKey = null;
        _this._groundsMakingChangesKey = null;
        _this._parentKey = null;
        _this._procurementPlanTable = ObasTableCollection.RroProcurementPlanTable;
        _this._filterTable = ObasTableCollection.RroFilterProcurementTable;
        _this._filterKey = 0;
        return _this;
    }
    Object.defineProperty(RroProcurementTable.prototype, "ProcurementPlanKey", {
        get: function () {
            if (this._procurementPlanKey == null) {
                this._procurementPlanKey = new NumberObasTableField("RRO_ProcurementPlan_ID", this);
            }
            return this._procurementPlanKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "NumStr", {
        get: function () {
            if (this._numStr == null) {
                this._numStr = new ObasTableField("NumStr", this);
            }
            return this._numStr;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "IKZ", {
        get: function () {
            if (this._ikz == null) {
                this._ikz = new ObasTableField("IKZ", this);
            }
            return this._ikz;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "ObjectName", {
        get: function () {
            if (this._objectName == null) {
                this._objectName = new ObasTableField("ObjectName", this);
            }
            return this._objectName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "OKPDCode", {
        get: function () {
            if (this._okpdCode == null) {
                this._okpdCode = new ObasTableField("OKPDCode", this);
            }
            return this._okpdCode;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "OKPDName", {
        get: function () {
            if (this._okpdName == null) {
                this._okpdName = new ObasTableField("OKPDName", this);
            }
            return this._okpdName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "ProcurementTypeKey", {
        get: function () {
            if (this._procurementTypeKey == null) {
                this._procurementTypeKey = new NumberObasTableField("Procurement_Types_ID", this);
            }
            return this._procurementTypeKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "IsEnlargedKey", {
        get: function () {
            if (this._isEnlargedKey == null) {
                this._isEnlargedKey = new NumberObasTableField("IsEnlarged_ID", this);
            }
            return this._isEnlargedKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "PlacementYearKey", {
        get: function () {
            if (this._placementYearKey == null) {
                this._placementYearKey = new NumberObasTableField("Procurement_PlacementYear_ID", this);
            }
            return this._placementYearKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "DateBegin", {
        get: function () {
            if (this._dateBegin == null) {
                this._dateBegin = new ObasTableField("DateBegin", this);
            }
            return this._dateBegin;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "DateEnd", {
        get: function () {
            if (this._dateEnd == null) {
                this._dateEnd = new ObasTableField("DateEnd", this);
            }
            return this._dateEnd;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "PeriodicityKey", {
        get: function () {
            if (this._periodicityKey == null) {
                this._periodicityKey = new NumberObasTableField("Procurement_Periodicity_ID", this);
            }
            return this._periodicityKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "GroundsMakingChangesKey", {
        get: function () {
            if (this._groundsMakingChangesKey == null) {
                this._groundsMakingChangesKey = new NumberObasTableField("GroundsMakingChanges_ID", this);
            }
            return this._groundsMakingChangesKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementTable.prototype, "ParentKey", {
        get: function () {
            if (this._parentKey == null) {
                this._parentKey = new NumberObasTableField("Parent_ID", this);
            }
            return this._parentKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementTable.prototype.CalcTotalSum = function () {
        var result = 0;
        for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
            result = result + this.GetFieldValue("Y" + (i + 1)) || 0;
        }
        return result;
    };
    RroProcurementTable.prototype.CalcTimingProcurement = function () {
        var result = "\u0421\u0440\u043E\u043A \u043E\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043B\u0435\u043D\u0438\u044F \u0437\u0430\u043A\u0443\u043F\u043A\u0438";
        if ((this.DateBegin.Value != null) && (this.DateEnd.Value != null)) {
            result = result + (" \u0441 " + ObasHelper.ConvertToString(this.GetFieldValue("DateBegin"), DateFormat.Short));
            result = result + (" \u0434\u043E " + ObasHelper.ConvertToString(this.GetFieldValue("DateEnd"), DateFormat.Short));
        }
        if (this.PeriodicityKey.Value != null) {
            var periodicityName = this.GetFieldValue("Procurement_Periodicity_Name");
            result = result + " " + periodicityName.toLocaleLowerCase();
        }
        return result;
    };
    RroProcurementTable.prototype.GetPlacementYear = function () {
        placementYearTable = ObasTableCollection.ProcurementPlacementYearSprTable;
        placementYearTable.Locate(placementYearTable.RecordKey.Id, this.PlacementYearKey.Value);
        return placementYearTable.Year.Value;
    };
    RroProcurementTable.prototype.AddEventHandler = function (tableId) {
        this._filterTable.AddRowFilter(this.RecordKey.Value);
    };
    RroProcurementTable.prototype.DeleteEventHandler = function (tableId) {
        var curKey = this.RecordKey.Value;
        this._filterTable.DeleteRowFilter(curKey);
        ObasTableCollection.RroProcurementKBKTable.DeleteRowsProcurement(curKey);
        ObasTableCollection.RroProcurementNPATable.DeleteRowsProcurement(curKey);
    };
    RroProcurementTable.prototype.InitProcurementPlanKeyEventHandler = function (tableId, fieldId) {
        return this._procurementPlanTable.RecordKey.Value;
    };
    RroProcurementTable.prototype.InitProcurementPeriodicityKeyEventHandler = function (tableId, fieldId) {
        return 1;
    };
    RroProcurementTable.prototype.NumStrChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.UpdateIKZ();
    };
    RroProcurementTable.prototype.ProcurementTypeKeyChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.UpdateOKPD();
        if (this.ProcurementTypeKey.Value === 1) {
            this.ObjectName.Value = null;
        }
        else {
            this.IsEnlargedKey.Value = null;
            var procurementTypesTable = ObasTableCollection.ProcurementTypesSprTable;
            procurementTypesTable.Locate(procurementTypesTable.RecordKey.Id, this.ProcurementTypeKey.Value);
            this.ObjectName.Value = procurementTypesTable.Name.Value;
        }
    };
    RroProcurementTable.prototype.IsEnlargedKeyChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this.UpdateOKPD();
    };
    RroProcurementTable.prototype.PlacementYearKeyChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var numStr = this.GenerateMaxNumStr(newValue);
        if (this.NumStr.Value === numStr) {
            this.UpdateIKZ();
        }
        this.NumStr.Value = numStr;
    };
    RroProcurementTable.prototype.ObjectNameChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var kbkTable = ObasTableCollection.RroProcurementKBKTable;
        while (kbkTable.Locate(kbkTable.ProcurementKey.Id, this.RecordKey.Value, true)) {
            kbkTable.ObjectName.Value = this.ObjectName.Value;
        }
        kbkTable.ClearLocateFlag();
    };
    RroProcurementTable.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var delta = newValue - oldValue;
        this.SetFieldValue(fieldId, this.GetFieldValue(fieldId) + delta);
    };
    RroProcurementTable.prototype.GenerateMaxNumStr = function (placementYearKey) {
        var maxNumStr = 0;
        var curKey = this.RecordKey.Value;
        while (this.Locate(this.PlacementYearKey.Id, placementYearKey, true)) {
            if (!isNaN(this.NumStr.Value) && (curKey != this.RecordKey.Value)) {
                var numStr = parseInt(this.NumStr.Value);
                if (numStr > maxNumStr) {
                    maxNumStr = numStr;
                }
            }
        }
        this.ClearLocateFlag();
        this.Locate(this.RecordKey.Id, curKey);
        maxNumStr = maxNumStr + 1;
        return ObasHelper.FillWithCharacter(maxNumStr.toString(), 4);
    };
    RroProcurementTable.prototype.IsUniqueNumStr = function (numStr, placementYearKey) {
        var result = 0;
        while (this.Locate([this.PlacementYearKey.Id, this.ProcurementPlanKey.Id, this.NumStr.Id], [placementYearKey, this.ProcurementPlanKey.Value, numStr], true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result === 1;
    };
    RroProcurementTable.prototype.CanAddProcurementType = function (procurementTypeKey, placementYearKey) {
        var result = 0;
        if (procurementTypeKey != 1) {
            while (this.Locate([this.PlacementYearKey.Id, this.ProcurementPlanKey.Id, this.ProcurementTypeKey.Id], [placementYearKey, this.ProcurementPlanKey.Value, procurementTypeKey], true)) {
                result = result + 1;
            }
            this.ClearLocateFlag();
        }
        return (result === 1) || (procurementTypeKey === 1);
    };
    RroProcurementTable.prototype.NeedClearYearsDataFields = function () {
        var placementYear = this.GetPlacementYear();
        var yearsCount = placementYear - ObasStageSettings.CurrentYear;
        if (yearsCount > 0) {
            if (yearsCount > ObasStageSettings.YearsCount) {
                yearsCount = ObasStageSettings.YearsCount;
            }
            var kbkTable = ObasTableCollection.RroProcurementKBKTable;
            while (kbkTable.Locate(kbkTable.ProcurementKey.Id, this.RecordKey.Value, true)) {
                for (var i = 0; i < yearsCount; i++) {
                    if ((kbkTable.GetFieldValue("Y" + (i + 1)) || 0) != 0) {
                        kbkTable.ClearLocateFlag();
                        return true;
                    }
                }
            }
            kbkTable.ClearLocateFlag();
        }
        return false;
    };
    RroProcurementTable.prototype.UpdateIKZ = function () {
        if (this.ParentKey.Value === null) {
            var year = this.GetPlacementYear().toString();
            year = year.substring(2, 4);
            var inn = ObasTableCollection.SelectedFoivTable.GetFieldValue("INN");
            var kpp = ObasTableCollection.SelectedFoivTable.GetFieldValue("KPP");
            var numstr = this.NumStr.Value;
            var okpd = this.OKPDCode.Value || "";
            okpd = okpd.replace(".", "");
            okpd = okpd.substring(0, 4);
            okpd = ObasHelper.FillWithCharacter(okpd, 4, "0", FillCharactersDirection.Last);
            var kbk = "000";
            var kbkTable = ObasTableCollection.RroProcurementKBKTable;
            if (kbkTable.RowCountProcurement(this.RecordKey.Value) === 1) {
                kbk = kbkTable.CostType.Code;
            }
            this.IKZ.Value = year + " 1 " + inn + " " + kpp + " " + numstr + " 000 " + okpd + " " + kbk;
        }
    };
    RroProcurementTable.prototype.UpdateOKPD = function () {
        this.OKPDCode.Value = "0000";
        this.OKPDName.Value = "";
        if (this.IsEnlargedKey.Value === ObasTableCollection.BooleanSprTable.GetFalseId()) {
            var okpdTable = ObasTableCollection.RroProcurementKBKTable;
            if (okpdTable.RowCountProcurement(this.RecordKey.Value) === 1) {
                this.OKPDCode.Value = okpdTable.OKPDCode;
                this.OKPDName.Value = okpdTable.OKPDName;
            }
        }
        this.UpdateIKZ();
    };
    RroProcurementTable.prototype.ClearYearsDataFields = function () {
        var placementYear = this.GetPlacementYear();
        var yearsCount = placementYear - ObasStageSettings.CurrentYear;
        if (yearsCount > 0) {
            if (yearsCount > ObasStageSettings.YearsCount) {
                yearsCount = ObasStageSettings.YearsCount;
            }
            var kbkTable = ObasTableCollection.RroProcurementKBKTable;
            while (kbkTable.Locate(kbkTable.ProcurementKey.Id, this.RecordKey.Value, true)) {
                for (var i = 0; i < yearsCount; i++) {
                    kbkTable.SetFieldValue("Y" + (i + 1), 0.0);
                    if (kbkTable.IsForeignProcurement.Value) {
                        kbkTable.SetFieldValue("Currency_Y" + (i + 1), 0.0);
                    }
                }
            }
            kbkTable.ClearLocateFlag();
        }
    };
    RroProcurementTable.prototype.CreateNewVersions = function (sourceProcurementPlanKey, destProcurementPlanKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementPlanKey.Id, sourceProcurementPlanKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        for (var i = 0; i < sourceKeys.length; i++) {
            this.CreateNewVersion(sourceKeys[i], destProcurementPlanKey);
        }
    };
    RroProcurementTable.prototype.CreateNewVersion = function (sourceKey, destProcurementPlanKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.ProcurementPlanKey.DefferedSetValue(destProcurementPlanKey);
        var curNumStr = this.NumStr.Value;
        var curObjectName = this.ObjectName.Value;
        this.PostRow();
        this.NumStr.Value = curNumStr;
        this.ObjectName.Value = curObjectName;
        for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
            this.SetFieldValue("Y" + (i + 1), null);
        }
        this.GroundsMakingChangesKey.Value = null;
        ObasTableCollection.RroProcurementKBKTable.CreateNewVersions(sourceKey, newKey);
        ObasTableCollection.RroProcurementNPATable.CreateNewVersions(sourceKey, newKey);
        ObasTableCollection.RroProcurementInfoNPATable.CreateNewVersions(sourceKey, newKey);
        this.ParentKey.Value = sourceKey;
        return newKey;
    };
    RroProcurementTable.prototype.DeleteRowsProcurementPlan = function (sourceProcurementPlanKey) {
        while (this.Locate(this.ProcurementPlanKey.Id, sourceProcurementPlanKey, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    RroProcurementTable.prototype.NeedResetFilter = function () {
        return this._filterKey != this._procurementPlanTable.RecordKey.Value;
    };
    RroProcurementTable.prototype.SetFilter = function () {
        var procurementKeys = new Array();
        while (this.Locate(this.ProcurementPlanKey.Id, this._procurementPlanTable.RecordKey.Value, true)) {
            procurementKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        if (this.NeedResetFilter()) {
            this._filterTable.DeleteAllRow();
            this._filterKey = this._procurementPlanTable.RecordKey.Value;
        }
        this._filterTable.UpdateRowsFilter(procurementKeys);
    };
    return RroProcurementTable;
}(ObasTable));

var RroProcurementOKPDTable = (function (_super) {
    __extends(RroProcurementOKPDTable, _super);
    function RroProcurementOKPDTable() {
        var _this = _super.call(this, "RRO_ProcurementOKPD") || this;
        _this._procurementKey = null;
        _this._okpdKey = null;
        _this._parentKey = null;
        _this._procurementTable = ObasTableCollection.RroProcurementTable;
        _this._filterTable = ObasTableCollection.RroFilterProcurementOKPDTable;
        _this._filterProcurementPlanTable = ObasTableCollection.RroFilterProcurementPlanOKPDTable;
        _this._filterKey = 0;
        return _this;
    }
    Object.defineProperty(RroProcurementOKPDTable.prototype, "ProcurementKey", {
        get: function () {
            if (this._procurementKey == null) {
                this._procurementKey = new NumberObasTableField("RRO_Procurement_ID", this);
            }
            return this._procurementKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementOKPDTable.prototype, "OKPDKey", {
        get: function () {
            if (this._okpdKey == null) {
                this._okpdKey = new NumberObasTableField("OKPD_ID", this);
            }
            return this._okpdKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementOKPDTable.prototype, "OKPDCode", {
        get: function () {
            var OkpdTable = ObasTableCollection.OkpdSprTable;
            OkpdTable.Locate(OkpdTable.RecordKey.Id, this.OKPDKey.Value);
            return OkpdTable.Code.Value || "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementOKPDTable.prototype, "OKPDName", {
        get: function () {
            var OkpdTable = ObasTableCollection.OkpdSprTable;
            OkpdTable.Locate(OkpdTable.RecordKey.Id, this.OKPDKey.Value);
            return OkpdTable.Name.Value || "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementOKPDTable.prototype, "ParentKey", {
        get: function () {
            if (this._parentKey == null) {
                this._parentKey = new NumberObasTableField("Parent_ID", this);
            }
            return this._parentKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementOKPDTable.prototype.AddEventHandler = function (tableId) {
        this._filterTable.AddRowFilter(this.RecordKey.Value);
    };
    RroProcurementOKPDTable.prototype.DeleteEventHandler = function (tableId) {
        this._filterTable.DeleteRowFilter(this.RecordKey.Value);
    };
    RroProcurementOKPDTable.prototype.AfterDeleteEventHandler = function (tableId) {
        this._procurementTable.UpdateOKPD();
    };
    RroProcurementOKPDTable.prototype.InitProcurementKeyEventHandler = function (tableId, fieldId) {
        return this._procurementTable.RecordKey.Value;
    };
    RroProcurementOKPDTable.prototype.OKPDChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this._procurementTable.UpdateOKPD();
    };
    RroProcurementOKPDTable.prototype.IsUniqueOKPDbyProcumerent = function (procurementKey, okpdKey) {
        var result = 0;
        while (this.Locate([this.ProcurementKey.Id, this.OKPDKey.Id], [procurementKey, okpdKey], true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result === 1;
    };
    RroProcurementOKPDTable.prototype.RowCountProcurement = function (sourceProcurementKey) {
        var result = 0;
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result;
    };
    RroProcurementOKPDTable.prototype.CheckWithPrevVersion = function (sourceProcurementKey, parentProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        var result = true;
        if (parentProcurementKey != null) {
            for (var i = 0; i < sourceKeys.length; i++) {
                result = this.Locate(this.RecordKey.Id, sourceKeys[i]);
                if (result) {
                    result = this.Locate([this.RecordKey.Id, this.OKPDKey.Id], [this.ParentKey.Value, this.OKPDKey.Value]);
                    if (!result) {
                        result = this.Locate([this.ProcurementKey.Id, this.OKPDKey.Id], [parentProcurementKey, this.OKPDKey.Value]);
                    }
                }
                if (!result) {
                    break;
                }
            }
            if (result) {
                result = (this.RowCountProcurement(sourceProcurementKey) === this.RowCountProcurement(parentProcurementKey));
            }
        }
        return result;
    };
    RroProcurementOKPDTable.prototype.CreateNewVersions = function (sourceProcurementKey, destProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        for (var i = 0; i < sourceKeys.length; i++) {
            this.CreateNewVersion(sourceKeys[i], destProcurementKey);
        }
    };
    RroProcurementOKPDTable.prototype.CreateNewVersion = function (sourceKey, destProcurementKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.ProcurementKey.DefferedSetValue(destProcurementKey);
        this.PostRow();
        this.ParentKey.Value = sourceKey;
        return newKey;
    };
    RroProcurementOKPDTable.prototype.DeleteRowsProcurement = function (sourceProcurementKey) {
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    RroProcurementOKPDTable.prototype.NeedResetFilter = function () {
        return this._filterKey != this._procurementTable.RecordKey.Value;
    };
    RroProcurementOKPDTable.prototype.SetFilter = function () {
        var okpdKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, this._procurementTable.RecordKey.Value, true)) {
            okpdKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        if (this.NeedResetFilter() || this._procurementTable.NeedResetFilter()) {
            this._filterTable.DeleteAllRow();
            this._filterKey = this._procurementTable.RecordKey.Value;
        }
        this._filterTable.UpdateRowsFilter(okpdKeys);
    };
    RroProcurementOKPDTable.prototype.SetFilterProcurementPlan = function () {
        var okpdKeys = new Array();
        var filterProcurementTable = this._procurementTable._filterTable;
        var reader = filterProcurementTable.CreateReader();
        while (reader.Read()) {
            var filterKey = filterProcurementTable.SourceKey.Value;
            while (this.Locate(this.ProcurementKey.Id, filterKey, true)) {
                okpdKeys.push(this.RecordKey.Value);
            }
            this.ClearLocateFlag();
        }
        this._filterProcurementPlanTable.UpdateRowsFilter(okpdKeys);
    };
    return RroProcurementOKPDTable;
}(ObasTable));

var RroProcurementKBKTable = (function (_super) {
    __extends(RroProcurementKBKTable, _super);
    function RroProcurementKBKTable() {
        var _this = _super.call(this, "RRO_ProcurementKBK") || this;
        _this._procurementKey = null;
        _this._rroDataKey = null;
        _this._objectName = null;
        _this._okpdKey = null;
        _this._parentKey = null;
        _this._isForeignProcurement = null;
        _this._okvKey = null;
        _this._procurementTable = ObasTableCollection.RroProcurementTable;
        _this._filterTable = ObasTableCollection.RroFilterProcurementKBKTable;
        _this._filterProcurementPlanTable = ObasTableCollection.RroFilterProcurementPlanKBKTable;
        _this._filterKey = 0;
        return _this;
    }
    Object.defineProperty(RroProcurementKBKTable.prototype, "ProcurementKey", {
        get: function () {
            if (this._procurementKey == null) {
                this._procurementKey = new NumberObasTableField("RRO_Procurement_ID", this);
            }
            return this._procurementKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "RroDataKey", {
        get: function () {
            if (this._rroDataKey == null) {
                this._rroDataKey = new NumberObasTableField("RRO_Data_ID", this);
            }
            return this._rroDataKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "ObjectName", {
        get: function () {
            if (this._objectName == null) {
                this._objectName = new ObasTableField("ObjectName", this);
            }
            return this._objectName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "OKPDKey", {
        get: function () {
            if (this._okpdKey == null) {
                this._okpdKey = new NumberObasTableField("OKPD_ID", this);
            }
            return this._okpdKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "OKPDCode", {
        get: function () {
            var OkpdTable = ObasTableCollection.OkpdSprTable;
            OkpdTable.Locate(OkpdTable.RecordKey.Id, this.OKPDKey.Value);
            return OkpdTable.Code.Value || "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "OKPDName", {
        get: function () {
            var OkpdTable = ObasTableCollection.OkpdSprTable;
            OkpdTable.Locate(OkpdTable.RecordKey.Id, this.OKPDKey.Value);
            return OkpdTable.Name.Value || "";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "ParentKey", {
        get: function () {
            if (this._parentKey == null) {
                this._parentKey = new NumberObasTableField("Parent_ID", this);
            }
            return this._parentKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "IsForeignProcurement", {
        get: function () {
            if (this._isForeignProcurement == null) {
                this._isForeignProcurement = new ObasTableField("IsForeignProcurement", this);
            }
            return this._isForeignProcurement;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementKBKTable.prototype, "OKVKey", {
        get: function () {
            if (this._okvKey == null) {
                this._okvKey = new NumberObasTableField("OKV_ID", this);
            }
            return this._okvKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementKBKTable.prototype.CalcSelectedFoivCode = function () {
        return ObasTableCollection.SelectedFoivTable.Foiv.Code;
    };
    RroProcurementKBKTable.prototype.CalcKBKFullCode = function () {
        var code = ObasTableCollection.SelectedFoivTable.Foiv.Code;
        code += " " + this.Fcr.Code;
        code += " " + this.GovermentProgram.Code;
        code += " " + this.CalcSubprogramCode();
        code += " " + ObasExportHelper.GetActionCode(this);
        code += " " + this.DirectionCost.Code;
        code += " " + this.CostType.Code;
        return code;
    };
    RroProcurementKBKTable.prototype.AddEventHandler = function (tableId) {
        this._filterTable.AddRowFilter(this.RecordKey.Value);
    };
    RroProcurementKBKTable.prototype.DeleteEventHandler = function (tableId) {
        this._filterTable.DeleteRowFilter(this.RecordKey.Value);
        for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
            var fieldId = "Y" + (i + 1);
            var oldValue = this.GetFieldValue(fieldId) || 0;
            var newValue = 0;
            this._procurementTable.SumChangeEventHandler(tableId, oldValue, newValue, fieldId);
        }
    };
    RroProcurementKBKTable.prototype.AfterDeleteEventHandler = function (tableId) {
        this._procurementTable.UpdateIKZ();
        this._procurementTable.UpdateOKPD();
    };
    RroProcurementKBKTable.prototype.InitProcurementKeyEventHandler = function (tableId, fieldId) {
        return this._procurementTable.RecordKey.Value;
    };
    RroProcurementKBKTable.prototype.InitObjectNameEventHandler = function (tableId, fieldId) {
        return this.GetProcurementObjectName();
    };
    RroProcurementKBKTable.prototype.OKPDChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this._procurementTable.UpdateOKPD();
    };
    RroProcurementKBKTable.prototype.KBKChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        var rroDataTable = ObasTableCollection.RroDataTable;
        if (rroDataTable.Locate(rroDataTable.RecordKey.Id, this.RroDataKey.Value)) {
            this.Fcr.ForeignKey.Value = rroDataTable.Fcr.ForeignKey.Value;
            this.GovermentProgram.ForeignKey.Value = rroDataTable.GovermentProgram.ForeignKey.Value;
            this.SubProgram.ForeignKey.Value = rroDataTable.SubProgram.ForeignKey.Value;
            this.MainAction.ForeignKey.Value = rroDataTable.MainAction.ForeignKey.Value;
            this.DirectionCost.ForeignKey.Value = rroDataTable.DirectionCost.ForeignKey.Value;
            this.CostType.ForeignKey.Value = rroDataTable.CostType.ForeignKey.Value;
        }
    };
    RroProcurementKBKTable.prototype.VRChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this._procurementTable.UpdateIKZ();
    };
    RroProcurementKBKTable.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        this._procurementTable.SumChangeEventHandler(tableId, oldValue, newValue, fieldId);
    };
    RroProcurementKBKTable.prototype.SumPartsChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
        if (this.IsForeignProcurement.Value) {
            var yearIndex = fieldId.slice(-1);
            var currencyRate = this.GetFieldValue("CurrencyRate_Y" + yearIndex) || 0;
            var currency = this.GetFieldValue("Currency_Y" + yearIndex) || 0;
            var rub = 0;
            if (currencyRate != 0) {
                rub = (currency / currencyRate) || 0;
            }
            this.SetFieldValue("Y" + yearIndex, rub);
            var usdValue = ObasTableCollection.DollarRateTable.GetFieldValue("Val" + (yearIndex - 1)) || 0;
            var usd = 0;
            if (usdValue != 0) {
                usd = (rub / usdValue) || 0;
            }
            this.SetFieldValue("Usd_Y" + yearIndex, usd);
        }
    };
    RroProcurementKBKTable.prototype.GetProcurementPlacementYear = function () {
        this._procurementTable.SavePosition();
        this._procurementTable.LocateByKeys(this.ProcurementKey.Value);
        var result = this._procurementTable.GetPlacementYear();
        this._procurementTable.RestorePosition();
        return result;
    };
    RroProcurementKBKTable.prototype.GetProcurementTypeKey = function () {
        this._procurementTable.SavePosition();
        this._procurementTable.LocateByKeys(this.ProcurementKey.Value);
        var result = this._procurementTable.ProcurementTypeKey.Value;
        this._procurementTable.RestorePosition();
        return result;
    };
    RroProcurementKBKTable.prototype.GetProcurementObjectName = function () {
        this._procurementTable.SavePosition();
        this._procurementTable.LocateByKeys(this.ProcurementKey.Value);
        var result = this._procurementTable.ObjectName.Value || "";
        this._procurementTable.RestorePosition();
        return result;
    };
    RroProcurementKBKTable.prototype.GetKeyLastApprovedOutlay = function () {
        var result = null;
        var rroOutlayTable = ObasTableCollection.RroOutlayTable;
        var reader = rroOutlayTable.CreateReader();
        while (reader.Read()) {
            if (rroOutlayTable.Status === OutlayStatuses.Approved) {
                result = rroOutlayTable.RecordKey.Value;
            }
        }
        return result;
    };
    RroProcurementKBKTable.prototype.GetKeyLastOutlay = function () {
        var result = null;
        var rroOutlayTable = ObasTableCollection.RroOutlayTable;
        rroOutlayTable.Last();
        result = rroOutlayTable.RecordKey.Value;
        return result;
    };
    RroProcurementKBKTable.prototype.IsCorrectKBK = function () {
        var rroOutlayKey = this.GetKeyLastApprovedOutlay();
        if (rroOutlayKey != null) {
            var rroDataTable = ObasTableCollection.RroDataTable;
            var KeyIds = this.GetKbkKeyFieldsId();
            KeyIds.push(rroDataTable.RroOutlayKey.Id);
            var KeyValues = this.GetKbkKeyFieldsValue();
            KeyValues.push(rroOutlayKey);
            return rroDataTable.Locate(KeyIds, KeyValues);
        }
        return false;
    };
    RroProcurementKBKTable.prototype.IsUniqueKBKbyProcumerent = function (procurementKey) {
        var result = 0;
        var KeyIds = this.GetKbkKeyFieldsId();
        KeyIds.push(this.ProcurementKey.Id);
        var KeyValues = this.GetKbkKeyFieldsValue();
        KeyValues.push(procurementKey);
        while (this.Locate(KeyIds, KeyValues, true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result === 1;
    };
    RroProcurementKBKTable.prototype.IsUniqueKBKandOKPDbyProcumerent = function (procurementKey) {
        var result = 0;
        var KeyIds = this.GetKbkKeyFieldsId();
        KeyIds.push(this.OKPDKey.Id);
        KeyIds.push(this.ProcurementKey.Id);
        var KeyValues = this.GetKbkKeyFieldsValue();
        KeyValues.push(this.OKPDKey.Value);
        KeyValues.push(procurementKey);
        while (this.Locate(KeyIds, KeyValues, true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result === 1;
    };
    RroProcurementKBKTable.prototype.ExistsKBKinLastOutlay = function () {
        var rroOutlayKey = this.GetKeyLastOutlay();
        if (rroOutlayKey != null) {
            var rroDataTable = ObasTableCollection.RroDataTable;
            var KeyIds = this.GetKbkKeyFieldsId();
            KeyIds.push(rroDataTable.RroOutlayKey.Id);
            var KeyValues = this.GetKbkKeyFieldsValue();
            KeyValues.push(rroOutlayKey);
            return rroDataTable.Locate(KeyIds, KeyValues);
        }
        return false;
    };
    RroProcurementKBKTable.prototype.ExistsEmptyOKPDbyProcurement = function (sourceProcurementKey) {
        var result = false;
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            if (this.OKPDKey.Value == null) {
                result = true;
                break;
            }
        }
        this.ClearLocateFlag();
        return result;
    };
    RroProcurementKBKTable.prototype.ExistsFilledSumProcurement = function (sourceProcurementKey, fieldId) {
        var result = false;
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            if (this.GetFieldValue(fieldId) != 0) {
                result = true;
                break;
            }
        }
        this.ClearLocateFlag();
        return result;
    };
    RroProcurementKBKTable.prototype.CanEditYearDataField = function (fieldId) {
        var placementYear = this.GetProcurementPlacementYear();
        var year = ObasStageSettings.CurrentYear + ObasHelper.GetYearOffsetById(fieldId);
        return year >= placementYear;
    };
    RroProcurementKBKTable.prototype.ClearSums = function () {
        var curIsForeignProcurement = this.IsForeignProcurement.Value;
        this.IsForeignProcurement.Value = false;
        this.OKVKey.Value = null;
        for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
            this.SetFieldValue("CurrencyRate_Y" + (i + 1), null);
            this.SetFieldValue("Currency_Y" + (i + 1), 0);
            this.SetFieldValue("Y" + (i + 1), 0);
            this.SetFieldValue("Usd_Y" + (i + 1), 0);
        }
        this.IsForeignProcurement.Value = curIsForeignProcurement;
    };
    RroProcurementKBKTable.prototype.RowCountProcurement = function (sourceProcurementKey) {
        var result = 0;
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result;
    };
    RroProcurementKBKTable.prototype.CheckWithPrevVersion = function (sourceProcurementKey, parentProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        var result = true;
        if (parentProcurementKey != null) {
            for (var i = 0; i < sourceKeys.length; i++) {
                result = this.Locate(this.RecordKey.Id, sourceKeys[i]);
                if (result) {
                    result = this.Locate([this.RecordKey.Id, "FCR_ID", "Program_ID", "SubProgram_ID", "MainAction_ID", "DirectionCost_ID", "VR_ID", "OKPD_ID", "ObjectName", "Y1", "Y2", "Y3", "Y4"], [this.ParentKey.Value, this.GetFieldValue("FCR_ID"), this.GetFieldValue("Program_ID"), this.GetFieldValue("SubProgram_ID"), this.GetFieldValue("MainAction_ID"), this.GetFieldValue("DirectionCost_ID"), this.GetFieldValue("VR_ID"),
                        this.GetFieldValue("OKPD_ID"), this.GetFieldValue("ObjectName"), this.GetFieldValue("Y1"), this.GetFieldValue("Y2"), this.GetFieldValue("Y3"), this.GetFieldValue("Y4")]);
                    if (!result) {
                        result = this.Locate([this.ProcurementKey.Id, "FCR_ID", "Program_ID", "SubProgram_ID", "MainAction_ID", "DirectionCost_ID", "VR_ID", "OKPD_ID", "ObjectName", "Y1", "Y2", "Y3", "Y4"], [parentProcurementKey, this.GetFieldValue("FCR_ID"), this.GetFieldValue("Program_ID"), this.GetFieldValue("SubProgram_ID"), this.GetFieldValue("MainAction_ID"), this.GetFieldValue("DirectionCost_ID"), this.GetFieldValue("VR_ID"),
                            this.GetFieldValue("OKPD_ID"), this.GetFieldValue("ObjectName"), this.GetFieldValue("Y1"), this.GetFieldValue("Y2"), this.GetFieldValue("Y3"), this.GetFieldValue("Y4")]);
                    }
                }
                if (!result) {
                    break;
                }
            }
            if (result) {
                result = (this.RowCountProcurement(sourceProcurementKey) === this.RowCountProcurement(parentProcurementKey));
            }
        }
        return result;
    };
    RroProcurementKBKTable.prototype.CreateNewVersions = function (sourceProcurementKey, destProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        for (var i = 0; i < sourceKeys.length; i++) {
            this.CreateNewVersion(sourceKeys[i], destProcurementKey);
        }
    };
    RroProcurementKBKTable.prototype.CreateNewVersion = function (sourceKey, destProcurementKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.ProcurementKey.DefferedSetValue(destProcurementKey);
        this.PostRow();
        this.ParentKey.Value = sourceKey;
        return newKey;
    };
    RroProcurementKBKTable.prototype.DeleteRowsProcurement = function (sourceProcurementKey) {
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    RroProcurementKBKTable.prototype.NeedResetFilter = function () {
        return this._filterKey != this._procurementTable.RecordKey.Value;
    };
    RroProcurementKBKTable.prototype.SetFilter = function () {
        var kbkKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, this._procurementTable.RecordKey.Value, true)) {
            kbkKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        if (this.NeedResetFilter() || this._procurementTable.NeedResetFilter()) {
            this._filterTable.DeleteAllRow();
            this._filterKey = this._procurementTable.RecordKey.Value;
        }
        this._filterTable.UpdateRowsFilter(kbkKeys);
    };
    RroProcurementKBKTable.prototype.SetFilterProcurementPlan = function () {
        var kbkKeys = new Array();
        var filterProcurementTable = this._procurementTable._filterTable;
        var reader = filterProcurementTable.CreateReader();
        while (reader.Read()) {
            var filterKey = filterProcurementTable.SourceKey.Value;
            while (this.Locate(this.ProcurementKey.Id, filterKey, true)) {
                kbkKeys.push(this.RecordKey.Value);
            }
            this.ClearLocateFlag();
        }
        this._filterProcurementPlanTable.UpdateRowsFilter(kbkKeys);
    };
    return RroProcurementKBKTable;
}(ObasTableWithKbkData));

var RroProcurementNPATable = (function (_super) {
    __extends(RroProcurementNPATable, _super);
    function RroProcurementNPATable() {
        var _this = _super.call(this, "RRO_ProcurementNPA") || this;
        _this._procurementKey = null;
        _this._npaType = null;
        _this._npaNumber = null;
        _this._npaDate = null;
        _this._npaName = null;
        _this._npaStatus = null;
        _this._npaStatusChangeDate = null;
        _this._parentKey = null;
        _this._procurementTable = ObasTableCollection.RroProcurementTable;
        _this._filterTable = ObasTableCollection.RroFilterProcurementNPATable;
        _this._filterKey = 0;
        return _this;
    }
    Object.defineProperty(RroProcurementNPATable.prototype, "ProcurementKey", {
        get: function () {
            if (this._procurementKey == null) {
                this._procurementKey = new NumberObasTableField("RRO_Procurement_ID", this);
            }
            return this._procurementKey;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "NpaType", {
        get: function () {
            if (this._npaType == null) {
                this._npaType = new ObasSprTableField(ObasTableCollection.NpaTypeTable, this);
            }
            return this._npaType;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "NpaNumber", {
        get: function () {
            if (this._npaNumber == null) {
                this._npaNumber = new ObasTableField("NpaNumber", this);
            }
            return this._npaNumber;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "NpaDate", {
        get: function () {
            if (this._npaDate == null) {
                this._npaDate = new ObasTableField("NpaDate", this);
            }
            return this._npaDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "NpaName", {
        get: function () {
            if (this._npaName == null) {
                this._npaName = new ObasTableField("NpaName", this);
            }
            return this._npaName;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "NpaStatus", {
        get: function () {
            if (this._npaStatus == null) {
                this._npaStatus = new ObasSprTableField(ObasTableCollection.NpaStatusesSprTable, this);
            }
            return this._npaStatus;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "NpaStatusChangeDate", {
        get: function () {
            if (this._npaStatusChangeDate == null) {
                this._npaStatusChangeDate = new ObasTableField("NpaChangeDate", this);
            }
            return this._npaStatusChangeDate;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroProcurementNPATable.prototype, "ParentKey", {
        get: function () {
            if (this._parentKey == null) {
                this._parentKey = new NumberObasTableField("Parent_ID", this);
            }
            return this._parentKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementNPATable.prototype.CalcActFullName = function () {
        var result = "\u2116" + this.NpaNumber.Value + " \u043E\u0442 " + ("" + ObasHelper.ConvertToString(this.NpaDate.Value, DateFormat.Short)) +
            (" \"" + this.NpaName.Value + "\"");
        if (result.length > 1000) {
            result = result.substring(0, 995) + "<...>";
        }
        return result;
    };
    RroProcurementNPATable.prototype.AddEventHandler = function (tableId) {
        this._filterTable.AddRowFilter(this.RecordKey.Value);
    };
    RroProcurementNPATable.prototype.DeleteEventHandler = function (tableId) {
        this._filterTable.DeleteRowFilter(this.RecordKey.Value);
    };
    RroProcurementNPATable.prototype.InitProcurementKeyEventHandler = function (tableId, fieldId) {
        return this._procurementTable.RecordKey.Value;
    };
    RroProcurementNPATable.prototype.ExistsBlankDatabyProcurement = function (sourceProcurementKey) {
        var result = false;
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            if ((this.NpaType.ForeignKey.Value == null) || (this.NpaNumber.Value == null) || (this.NpaDate.Value == null) ||
                (this.NpaName.Value == null) || (this.NpaStatus.ForeignKey.Value == null) || (this.NpaStatusChangeDate.Value == null)) {
                result = true;
                break;
            }
        }
        this.ClearLocateFlag();
        return result;
    };
    RroProcurementNPATable.prototype.RowCountProcurement = function (sourceProcurementKey) {
        var result = 0;
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            result = result + 1;
        }
        this.ClearLocateFlag();
        return result;
    };
    RroProcurementNPATable.prototype.CheckWithPrevVersion = function (sourceProcurementKey, parentProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        var result = true;
        if (parentProcurementKey != null) {
            for (var i = 0; i < sourceKeys.length; i++) {
                result = this.Locate(this.RecordKey.Id, sourceKeys[i]);
                if (result) {
                    result = this.Locate([this.RecordKey.Id, this.NpaType.ForeignKey.Id, this.NpaNumber.Id, this.NpaDate.Id, this.NpaName.Id, this.NpaStatus.ForeignKey.Id, this.NpaStatusChangeDate.Id], 
                    	[this.ParentKey.Value, this.NpaType.ForeignKey.Value, this.NpaNumber.Value, this.NpaDate.Value, this.NpaName.Value, this.NpaStatus.ForeignKey.Value, this.NpaStatusChangeDate.Value]);
                    if (!result) {
                        result = this.Locate([this.ProcurementKey.Id, this.NpaType.ForeignKey.Id, this.NpaNumber.Id, this.NpaDate.Id, this.NpaName.Id, this.NpaStatus.ForeignKey.Id, this.NpaStatusChangeDate.Id],
                            [parentProcurementKey, this.NpaType.ForeignKey.Value, this.NpaNumber.Value, this.NpaDate.Value, this.NpaName.Value, this.NpaStatus.ForeignKey.Value, this.NpaStatusChangeDate.Value]);
                    }
                }
                if (!result) {
                    break;
                }
            }
            if (result) {
                result = (this.RowCountProcurement(sourceProcurementKey) === this.RowCountProcurement(parentProcurementKey));
            }
        }
        return result;
    };
    RroProcurementNPATable.prototype.CreateNewVersions = function (sourceProcurementKey, destProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        for (var i = 0; i < sourceKeys.length; i++) {
            this.CreateNewVersion(sourceKeys[i], destProcurementKey);
        }
    };
    RroProcurementNPATable.prototype.CreateNewVersion = function (sourceKey, destProcurementKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.ProcurementKey.DefferedSetValue(destProcurementKey);
        this.PostRow();
        this.ParentKey.Value = sourceKey;
        return newKey;
    };
    RroProcurementNPATable.prototype.DeleteRowsProcurement = function (sourceProcurementKey) {
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    RroProcurementNPATable.prototype.NeedResetFilter = function () {
        return this._filterKey != this._procurementTable.RecordKey.Value;
    };
    RroProcurementNPATable.prototype.SetFilter = function () {
        var npaKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, this._procurementTable.RecordKey.Value, true)) {
            npaKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        if (this.NeedResetFilter() || this._procurementTable.NeedResetFilter()) {
            this._filterTable.DeleteAllRow();
            this._filterKey = this._procurementTable.RecordKey.Value;
        }
        this._filterTable.UpdateRowsFilter(npaKeys);
    };
    return RroProcurementNPATable;
}(ObasTable));

var RroProcurementInfoNPATable = (function (_super) {
    __extends(RroProcurementInfoNPATable, _super);
    function RroProcurementInfoNPATable() {
        var _this = _super.call(this, "RRO_ProcurementInfoNPA") || this;
        _this._procurementKey = null;
        _this._procurementTable = ObasTableCollection.RroProcurementTable;
        _this._filterTable = ObasTableCollection.RroFilterProcurementInfoNPATable;
        _this._filterKey = 0;
        return _this;
    }
    Object.defineProperty(RroProcurementInfoNPATable.prototype, "ProcurementKey", {
        get: function () {
            if (this._procurementKey == null) {
                this._procurementKey = new NumberObasTableField("RRO_Procurement_ID", this);
            }
            return this._procurementKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementInfoNPATable.prototype.AddEventHandler = function (tableId) {
        this._filterTable.AddRowFilter(this.RecordKey.Value);
    };
    RroProcurementInfoNPATable.prototype.DeleteEventHandler = function (tableId) {
        this._filterTable.DeleteRowFilter(this.RecordKey.Value);
    };
    RroProcurementInfoNPATable.prototype.InitProcurementKeyEventHandler = function (tableId, fieldId) {
        return this._procurementTable.RecordKey.Value;
    };
    RroProcurementInfoNPATable.prototype.CreateNewVersions = function (sourceProcurementKey, destProcurementKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        for (var i = 0; i < sourceKeys.length; i++) {
            this.CreateNewVersion(sourceKeys[i], destProcurementKey);
        }
    };
    RroProcurementInfoNPATable.prototype.CreateNewVersion = function (sourceKey, destProcurementKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.ProcurementKey.DefferedSetValue(destProcurementKey);
        this.PostRow();
        ObasTableCollection.RroProcurementInfoNPADetailsTable.CreateNewVersions(sourceKey, newKey);
        return newKey;
    };
    RroProcurementInfoNPATable.prototype.DeleteRowsProcurement = function (sourceProcurementKey) {
        while (this.Locate(this.ProcurementKey.Id, sourceProcurementKey, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    RroProcurementInfoNPATable.prototype.NeedResetFilter = function () {
        return this._filterKey != this._procurementTable.RecordKey.Value;
    };
    RroProcurementInfoNPATable.prototype.SetFilter = function () {
        var npaKeys = new Array();
        while (this.Locate(this.ProcurementKey.Id, this._procurementTable.RecordKey.Value, true)) {
            npaKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        if (this.NeedResetFilter() || this._procurementTable.NeedResetFilter()) {
            this._filterTable.DeleteAllRow();
            this._filterKey = this._procurementTable.RecordKey.Value;
        }
        this._filterTable.UpdateRowsFilter(npaKeys);
    };
    return RroProcurementInfoNPATable;
}(ObasTable));

var RroProcurementInfoNPADetailsTable = (function (_super) {
    __extends(RroProcurementInfoNPADetailsTable, _super);
    function RroProcurementInfoNPADetailsTable() {
        var _this = _super.call(this, "RRO_ProcurementInfoNPADetails") || this;
        _this._infoNPATable = ObasTableCollection.RroProcurementInfoNPATable;
        return _this;
    }
    Object.defineProperty(RroProcurementInfoNPADetailsTable.prototype, "InfoNPAKey", {
        get: function () {
            if (this._infoNPAKey == null) {
                this._infoNPAKey = new ObasForeignKeyTableFieldTyped(this._infoNPATable, this);
            }
            return this._infoNPAKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementInfoNPADetailsTable.prototype.CreateNewVersions = function (sourceInfoNPAKey, destInfoNPAKey) {
        var sourceKeys = new Array();
        while (this.Locate(this.InfoNPAKey.Id, sourceInfoNPAKey, true)) {
            sourceKeys.push(this.RecordKey.Value);
        }
        this.ClearLocateFlag();
        for (var i = 0; i < sourceKeys.length; i++) {
            this.CreateNewVersion(sourceKeys[i], destInfoNPAKey);
        }
    };
    RroProcurementInfoNPADetailsTable.prototype.CreateNewVersion = function (sourceKey, destInfoNPAKey) {
        var newKey = this.CloneRow(sourceKey, false);
        this.InfoNPAKey.DefferedSetValue(destInfoNPAKey);
        this.PostRow();
        return newKey;
    };
    return RroProcurementInfoNPADetailsTable;
}(ObasTable));

var RroProcurementPlanSumbyKBKTable = (function (_super) {
    __extends(RroProcurementPlanSumbyKBKTable, _super);
    function RroProcurementPlanSumbyKBKTable() {
        return _super.call(this, "RRO_ProcurementPlanSumbyKBK") || this;
    }
    RroProcurementPlanSumbyKBKTable.prototype.CalcKBKFullCode = function () {
        var code = ObasTableCollection.SelectedFoivTable.Foiv.Code;
        code += " " + this.Fcr.Code;
        code += " " + this.GovermentProgram.Code;
        code += " " + this.CalcSubprogramCode();
        code += " " + ObasExportHelper.GetActionCode(this);
        code += " " + this.DirectionCost.Code;
        code += " " + this.CostType.Code;
        return code;
    };
    RroProcurementPlanSumbyKBKTable.prototype.CalcTotalSum = function () {
        var result = 0;
        for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
            result = result + this.GetFieldValue("Y" + (i + 1)) || 0;
        }
        return result;
    };
    RroProcurementPlanSumbyKBKTable.prototype.UpdateDataRows = function (sourceProcurementPlanKey) {
        this.DeleteAllRow();
        var procurementTable = ObasTableCollection.RroProcurementTable;
        var procurementKeys = new Array();
        while (procurementTable.Locate(procurementTable.ProcurementPlanKey.Id, sourceProcurementPlanKey, true)) {
            procurementKeys.push(procurementTable.RecordKey.Value);
        }
        procurementTable.ClearLocateFlag();
        for (var i = 0; i < procurementKeys.length; i++) {
            this.UpdateDataRowsByProcurement(procurementKeys[i]);
        }
    };
    RroProcurementPlanSumbyKBKTable.prototype.UpdateDataRowsByProcurement = function (sourceProcurementKey) {
        var procurementKBKTable = ObasTableCollection.RroProcurementKBKTable;
        while (procurementKBKTable.Locate(procurementKBKTable.ProcurementKey.Id, sourceProcurementKey, true)) {
            this.InitRecord(procurementKBKTable.GetKbkKeyFieldsValue());
            for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
                var fieldId = "Y" + (i + 1);
                var curValue = procurementKBKTable.GetFieldValue(fieldId) || 0;
                var sumValue = this.GetFieldValue(fieldId) || 0;
                this.SetFieldValue(fieldId, sumValue + curValue);
            }
        }
        procurementKBKTable.ClearLocateFlag();
    };
    RroProcurementPlanSumbyKBKTable.prototype.InitRecord = function (keyValues) {
        var keyFieldIds = this.GetKbkKeyFieldsId();
        if (!this.Locate(keyFieldIds, keyValues)) {
            var length = keyFieldIds.length;
            this.AddRow();
            for (var i = 0; i < length; i++) {
                this.SetFieldValue(keyFieldIds[i], keyValues[i]);
            }
            this.PostRow();
        }
    };
    return RroProcurementPlanSumbyKBKTable;
}(ObasTableWithKbkData));

var RroProcurementCalcedDataTable = (function (_super) {
    __extends(RroProcurementCalcedDataTable, _super);
    function RroProcurementCalcedDataTable() {
        var _this = _super.call(this, "RRO_ProcurementCalcedData") || this;
        _this._procurementKey = null;
        _this._procurementTable = ObasTableCollection.RroProcurementTable;
        return _this;
    }
    Object.defineProperty(RroProcurementCalcedDataTable.prototype, "ProcurementKey", {
        get: function () {
            if (this._procurementKey == null) {
                this._procurementKey = new NumberObasTableField("RRO_Procurement_ID", this);
            }
            return this._procurementKey;
        },
        enumerable: true,
        configurable: true
    });
    RroProcurementCalcedDataTable.prototype.CalcListKBKProgramNames = function () {
        var names = new Array();
        var procurementKBKTable = ObasTableCollection.RroProcurementKBKTable;
        while (procurementKBKTable.Locate(procurementKBKTable.ProcurementKey.Id, this.ProcurementKey.Value, true)) {
            var name = procurementKBKTable.GetFieldValue("Program_Name");
            if (names.indexOf(name) === -1) {
                names.push(name);
            }
        }
        procurementKBKTable.ClearLocateFlag();
        var result = names.join(";\n\r") || "";
        if (result.length > 1000) {
            result = result.substring(0, 995) + "<...>";
        }
        return result;
    };
    RroProcurementCalcedDataTable.prototype.CalcListNPAFullNames = function () {
        var names = new Array();
        var procurementNPATable = ObasTableCollection.RroProcurementNPATable;
        while (procurementNPATable.Locate(procurementNPATable.ProcurementKey.Id, this.ProcurementKey.Value, true)) {
            names.push(procurementNPATable.CalcActFullName());
        }
        procurementNPATable.ClearLocateFlag();
        var result = names.join(";\n\r") || "";
        if (result.length > 1000) {
            result = result.substring(0, 995) + "<...>";
        }
        return result;
    };
    RroProcurementCalcedDataTable.prototype.InitRecord = function (sourceProcurementKey) {
        this.AddRow();
        this.ProcurementKey.Value = sourceProcurementKey;
        this.PostRow();
    };
    return RroProcurementCalcedDataTable;
}(ObasTable));

var RroFilterTable = (function (_super) {
    __extends(RroFilterTable, _super);
    function RroFilterTable(id) {
        var _this = _super.call(this, id) || this;
        _this._sourceKey = null;
        return _this;
    }
    Object.defineProperty(RroFilterTable.prototype, "SourceKey", {
        get: function () {
            if (this._sourceKey == null) {
                this._sourceKey = new NumberObasTableField("SourceKey", this, true);
            }
            return this._sourceKey;
        },
        enumerable: true,
        configurable: true
    });
    RroFilterTable.prototype.AddRowFilter = function (sourceKey) {
        if (!this.Locate(this.SourceKey.Id, sourceKey)) {
            this.AddRow();
            this.PostRow();
            this.SourceKey.Value = sourceKey;
        }
    };
    RroFilterTable.prototype.DeleteRowFilter = function (sourceKey) {
        if (this.Locate(this.SourceKey.Id, sourceKey)) {
            this.DeleteRow();
        }
    };
    RroFilterTable.prototype.AddRowsFilter = function (sourceKeys) {
        for (var i = 0; i < sourceKeys.length; i++) {
            var sourceKey = sourceKeys[i];
            this.AddRowFilter(sourceKey);
        }
    };
    RroFilterTable.prototype.UpdateRowsFilter = function (sourceKeys) {
        var deleteKeys = [];
        var reader = this.CreateReader();
        while (reader.Read()) {
            if (sourceKeys.indexOf(this.SourceKey.Value) === -1) {
                deleteKeys.push(this.SourceKey.Value);
            }
        }
        for (var i = 0; i < deleteKeys.length; i++) {
            this.DeleteRowFilter(deleteKeys[i]);
        }
        this.AddRowsFilter(sourceKeys);
    };
    return RroFilterTable;
}(ObasTable));
var RroFilterProcurementTable = (function (_super) {
    __extends(RroFilterProcurementTable, _super);
    function RroFilterProcurementTable() {
        return _super.call(this, "RRO_FilterProcurement") || this;
    }
    return RroFilterProcurementTable;
}(RroFilterTable));
var RroFilterProcurementOKPDTable = (function (_super) {
    __extends(RroFilterProcurementOKPDTable, _super);
    function RroFilterProcurementOKPDTable() {
        return _super.call(this, "RRO_FilterProcurementOKPD") || this;
    }
    return RroFilterProcurementOKPDTable;
}(RroFilterTable));
var RroFilterProcurementPlanOKPDTable = (function (_super) {
    __extends(RroFilterProcurementPlanOKPDTable, _super);
    function RroFilterProcurementPlanOKPDTable() {
        return _super.call(this, "RRO_FilterProcurementPlanOKPD") || this;
    }
    return RroFilterProcurementPlanOKPDTable;
}(RroFilterTable));
var RroFilterProcurementKBKTable = (function (_super) {
    __extends(RroFilterProcurementKBKTable, _super);
    function RroFilterProcurementKBKTable() {
        return _super.call(this, "RRO_FilterProcurementKBK") || this;
    }
    return RroFilterProcurementKBKTable;
}(RroFilterTable));
var RroFilterProcurementPlanKBKTable = (function (_super) {
    __extends(RroFilterProcurementPlanKBKTable, _super);
    function RroFilterProcurementPlanKBKTable() {
        return _super.call(this, "RRO_FilterProcurementPlanKBK") || this;
    }
    return RroFilterProcurementPlanKBKTable;
}(RroFilterTable));
var RroFilterProcurementNPATable = (function (_super) {
    __extends(RroFilterProcurementNPATable, _super);
    function RroFilterProcurementNPATable() {
        return _super.call(this, "RRO_FilterProcurementNPA") || this;
    }
    return RroFilterProcurementNPATable;
}(RroFilterTable));
var RroFilterProcurementInfoNPATable = (function (_super) {
    __extends(RroFilterProcurementInfoNPATable, _super);
    function RroFilterProcurementInfoNPATable() {
        return _super.call(this, "RRO_FilterProcurementInfoNPA") || this;
    }
    return RroFilterProcurementInfoNPATable;
}(RroFilterTable));
var BaseRroOutlaySumByAnalyticsTable = (function (_super) {
    __extends(BaseRroOutlaySumByAnalyticsTable, _super);
    function BaseRroOutlaySumByAnalyticsTable(id) {
        var _this = _super.call(this, id) || this;
        _this._rroOutlay = null;
        _this._rroSumOutlay = null;
        _this._kosgu = null;
        _this._addAnalyticIndicator = null;
        _this._fcrCodeSection = null;
        _this._level = null;
        return _this;
    }
    Object.defineProperty(BaseRroOutlaySumByAnalyticsTable.prototype, "RroOutlay", {
        get: function () {
            if (this._rroOutlay == null) {
                this._rroOutlay = new ObasSprTableFieldTyped(ObasTableCollection.RroOutlayTable, this);
            }
            return this._rroOutlay;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlaySumByAnalyticsTable.prototype, "RroSumOutlay", {
        get: function () {
            if (this._rroSumOutlay == null) {
                this._rroSumOutlay = new ObasSprTableFieldTyped(ObasTableCollection.RroSumOutlayTable, this);
            }
            return this._rroSumOutlay;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlaySumByAnalyticsTable.prototype, "Kosgu", {
        get: function () {
            if (this._kosgu == null) {
                this._kosgu = new ObasSprTableField(ObasTableCollection.KosguSprTable, this);
            }
            return this._kosgu;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlaySumByAnalyticsTable.prototype, "AddAnalyticIndicator", {
        get: function () {
            if (this._addAnalyticIndicator == null) {
                this._addAnalyticIndicator = new ObasSprTableFieldTyped(ObasTableCollection.AddAnalysisIndicatorSprTable, this);
            }
            return this._addAnalyticIndicator;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlaySumByAnalyticsTable.prototype, "FcrCodeSection", {
        get: function () {
            if (this._fcrCodeSection == null) {
                this._fcrCodeSection = new ObasTableField("FcrCodeSection", this);
            }
            return this._fcrCodeSection;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseRroOutlaySumByAnalyticsTable.prototype, "Level", {
        get: function () {
            if (this._level == null) {
                this._level = new NumberObasTableField("Level", this, true);
            }
            return this._level;
        },
        enumerable: true,
        configurable: true
    });
    BaseRroOutlaySumByAnalyticsTable.prototype.CalcAnalyticCode = function () {
        return (this.Kosgu.Code || "") + (this.AddAnalyticIndicator.Code || "");
    };
    BaseRroOutlaySumByAnalyticsTable.prototype.CalcAnalyticIndicatorName = function () {
        switch (this.Level.Value) {
            case 1:
                return (this.GetFieldValue("DirectionCost_Name") || "") + " (" + (this.CostType.Name || "") + ")";
            case 2:
                return this.Kosgu.Name || "";
            case 3:
                return this.AddAnalyticIndicator.Name || "";
        }
    };
    BaseRroOutlaySumByAnalyticsTable.prototype.DeleteRowsByFilter = function (fieldId, key) {
        while (this.Locate(fieldId, key, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    BaseRroOutlaySumByAnalyticsTable.prototype.UpdateDataRows = function (rroOutlayFieldId, rroOutlayKey) {
        var rroOutlayKosgu = null;
        var rroAddAnalysisIndicator = null;
        if (rroOutlayFieldId === this.RroOutlay.ForeignKey.Id) {
            rroOutlayKosgu = ObasTableCollection.RroOutlayKosguTable;
            rroAddAnalysisIndicator = ObasTableCollection.RroObasAddAnalysisIndicatorTable;
        }
        else if (rroOutlayFieldId === this.RroSumOutlay.ForeignKey.Id) {
            rroOutlayKosgu = ObasTableCollection.RroSumOutlayKosguTable;
            rroAddAnalysisIndicator = ObasTableCollection.RroSumObasAddAnalysisIndicatorTable;
        }
        else {
            return;
        }
        this.DeleteRowsByFilter(rroOutlayFieldId, rroOutlayKey);
        var reader = rroOutlayKosgu.CreateReader();
        while (reader.Read()) {
            var rroObasVersionsTable = rroOutlayKosgu.RroObasVersion.SourceTable;
            if (rroObasVersionsTable.RroOutlayKey.Value === rroOutlayKey) {
                var locateValues = rroObasVersionsTable.RroObasKey.SourceTable.RroDataKey.SourceTable.GetKbkKeyFieldsValue();
                locateValues.push(rroOutlayKey);
                this.InitRecord(locateValues, 1, rroOutlayFieldId);
                this.SetSums(rroOutlayKosgu);
                var locateValuesKosgu = locateValues.slice(0);
                locateValuesKosgu.push(rroOutlayKosgu.Kosgu.ForeignKey.Value);
                this.InitRecord(locateValuesKosgu, 2, rroOutlayFieldId);
                this.SetSums(rroOutlayKosgu);
                while (rroAddAnalysisIndicator.Locate(rroAddAnalysisIndicator.RroOutlayKosguKey.Id, rroOutlayKosgu.RecordKey.Value, true)) {
                    var locateValuesAdd = locateValuesKosgu.slice(0);
                    locateValuesAdd.push(rroAddAnalysisIndicator.AddAnalyticIndicator.ForeignKey.Value);
                    this.InitRecord(locateValuesAdd, 3, rroOutlayFieldId);
                    this.SetSums(rroAddAnalysisIndicator);
                }
                rroAddAnalysisIndicator.ClearLocateFlag();
            }
        }
    };
    BaseRroOutlaySumByAnalyticsTable.prototype.InitRecord = function (keyValues, level, rroOutlayFieldId) {
        var keyFieldIds = this.GetKbkKeyFieldsId();
        keyFieldIds.push(rroOutlayFieldId);
        if ((level === 2) || (level === 3)) {
            keyFieldIds.push(this.Kosgu.ForeignKey.Id);
        }
        if (level === 3) {
            keyFieldIds.push(this.AddAnalyticIndicator.ForeignKey.Id);
        }
        keyFieldIds.push(this.Level.Id);
        keyValues.push(level);
        if (!this.Locate(keyFieldIds, keyValues)) {
            var length = keyFieldIds.length;
            this.AddRow();
            for (var i = 0; i < length; i++) {
                this.SetFieldValue(keyFieldIds[i], keyValues[i]);
            }
            this.PostRow();
            this.FcrCodeSection.Value = this.CalcFcrSectionCode();
        }
        keyValues.pop();
    };
    BaseRroOutlaySumByAnalyticsTable.prototype.SetSums = function (sourceTable) {
        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
            var fieldId = "Y" + i;
            var curValue = this.GetFieldValue(fieldId) || 0;
            var addValue = sourceTable.GetFieldValue(fieldId) || 0;
            this.SetFieldValue(fieldId, curValue + addValue);
            fieldId = "Y" + i + "_D";
            curValue = this.GetFieldValue(fieldId) || 0;
            addValue = sourceTable.GetFieldValue(fieldId) || 0;
            this.SetFieldValue(fieldId, curValue + addValue);
        }
    };
    return BaseRroOutlaySumByAnalyticsTable;
}(ObasTableWithKbkData));
var RroOutlaySumByAnalyticsGroupTable = (function (_super) {
    __extends(RroOutlaySumByAnalyticsGroupTable, _super);
    function RroOutlaySumByAnalyticsGroupTable() {
        var _this = _super.call(this, "RRO_Outlay_SumByAnalyticsGroups") || this;
        _this._rroOutlay = null;
        _this._rroSumOutlay = null;
        _this._FcrCodeSection = null;
        return _this;
    }
    Object.defineProperty(RroOutlaySumByAnalyticsGroupTable.prototype, "RroOutlay", {
        get: function () {
            if (this._rroOutlay == null) {
                this._rroOutlay = new ObasSprTableFieldTyped(ObasTableCollection.RroOutlayTable, this);
            }
            return this._rroOutlay;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlaySumByAnalyticsGroupTable.prototype, "RroSumOutlay", {
        get: function () {
            if (this._rroSumOutlay == null) {
                this._rroSumOutlay = new ObasSprTableFieldTyped(ObasTableCollection.RroSumOutlayTable, this);
            }
            return this._rroSumOutlay;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlaySumByAnalyticsGroupTable.prototype, "FcrCodeSection", {
        get: function () {
            if (this._FcrCodeSection == null) {
                this._FcrCodeSection = new ObasTableField("FcrCodeSection", this);
            }
            return this._FcrCodeSection;
        },
        enumerable: true,
        configurable: true
    });
    RroOutlaySumByAnalyticsGroupTable.prototype.DeleteRowsByFilter = function (fieldId, key) {
        while (this.Locate(fieldId, key, true)) {
            this.DeleteRow();
        }
        this.ClearLocateFlag();
    };
    RroOutlaySumByAnalyticsGroupTable.prototype.UpdateDataRows = function (rroOutlayFieldId, rroOutlayKey) {
        if ((rroOutlayFieldId != this.RroOutlay.ForeignKey.Id) && (rroOutlayFieldId != this.RroSumOutlay.ForeignKey.Id)) {
            return;
        }
        this.DeleteRowsByFilter(rroOutlayFieldId, rroOutlayKey);
        var rroOutlaySumByAnalyticsTable = ObasTableCollection.RroOutlaySumByAnalyticsTable;
        var reader = rroOutlaySumByAnalyticsTable.CreateReader();
        while (reader.Read()) {
            var fcrCodeSection = rroOutlaySumByAnalyticsTable.FcrCodeSection.Value;
            if (!this.Locate([this.FcrCodeSection.Id, rroOutlayFieldId], [fcrCodeSection, rroOutlayKey])) {
                this.AddRow();
                this.FcrCodeSection.Value = fcrCodeSection;
                this.SetFieldValue(rroOutlayFieldId, rroOutlayKey);
                this.PostRow();
            }
        }
    };
    return RroOutlaySumByAnalyticsGroupTable;
}(ObasTable));
var RroOutlaySumByAnalyticsTable = (function (_super) {
    __extends(RroOutlaySumByAnalyticsTable, _super);
    function RroOutlaySumByAnalyticsTable() {
        return _super.call(this, "RRO_Outlay_SumByAnalytics") || this;
    }
    return RroOutlaySumByAnalyticsTable;
}(BaseRroOutlaySumByAnalyticsTable));
var RroOutlaySumByAnalyticsPart4Table = (function (_super) {
    __extends(RroOutlaySumByAnalyticsPart4Table, _super);
    function RroOutlaySumByAnalyticsPart4Table() {
        return _super.call(this, "RRO_Outlay_SumByAnalyticsPart4") || this;
    }
    RroOutlaySumByAnalyticsPart4Table.prototype.CalcAnalyticCode = function () {
        return (this.Kosgu.Code || "");
    };
    RroOutlaySumByAnalyticsPart4Table.prototype.CalcAnalyticIndicatorName = function () {
        switch (this.Level.Value) {
            case 1:
                return (this.GetFieldValue("DirectionCost_Name") || "") + " (" + (this.CostType.Name || "") + ")";
            case 2:
                return this.Kosgu.Name || "";
        }
    };
    RroOutlaySumByAnalyticsPart4Table.prototype.UpdateDataRows = function (rroOutlayFieldId, rroOutlayKey) {
        var rroOutlayPart4 = null;
        if (rroOutlayFieldId === this.RroOutlay.ForeignKey.Id) {
            rroOutlayPart4 = ObasTableCollection.RroPartIndicateBudgetValuesTable;
        }
        else if (rroOutlayFieldId === this.RroSumOutlay.ForeignKey.Id) {
            rroOutlayPart4 = ObasTableCollection.RroSumPartIndicateBudgetValuesTable;
        }
        else {
            return;
        }
        this.DeleteRowsByFilter(rroOutlayFieldId, rroOutlayKey);
        var reader = rroOutlayPart4.CreateReader();
        while (reader.Read()) {
            var rroObasVersionsTable = rroOutlayPart4.RroVersionKey.SourceTable;
            if (rroObasVersionsTable.RroOutlayKey.Value === rroOutlayKey) {
                var locateValues = rroObasVersionsTable.RroObasKey.SourceTable.RroDataKey.SourceTable.GetKbkKeyFieldsValue();
                locateValues.push(rroOutlayKey);
                this.InitRecord(locateValues, 1, rroOutlayFieldId);
                this.SetSums(rroOutlayPart4);
                var locateValuesKosgu = locateValues.slice(0);
                locateValuesKosgu.push(rroOutlayPart4.Kosgu.ForeignKey.Value);
                this.InitRecord(locateValuesKosgu, 2, rroOutlayFieldId);
                this.SetSums(rroOutlayPart4);
            }
        }
    };
    return RroOutlaySumByAnalyticsPart4Table;
}(BaseRroOutlaySumByAnalyticsTable));
var RroOutlaySumByAnalyticsPart5xxTable = (function (_super) {
    __extends(RroOutlaySumByAnalyticsPart5xxTable, _super);
    function RroOutlaySumByAnalyticsPart5xxTable() {
        var _this = _super.call(this, "RRO_Outlay_SumByAnalyticsPart5xx") || this;
        _this._rroOutlay = null;
        _this._rroSumOutlay = null;
        _this._fcrCodeSection = null;
        _this._filterCostTypeCode = ["32.", "2..", "52.", "530", "540", "81."];
        return _this;
    }
    Object.defineProperty(RroOutlaySumByAnalyticsPart5xxTable.prototype, "RroOutlay", {
        get: function () {
            if (this._rroOutlay == null) {
                this._rroOutlay = new ObasSprTableFieldTyped(ObasTableCollection.RroOutlayTable, this);
            }
            return this._rroOutlay;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlaySumByAnalyticsPart5xxTable.prototype, "RroSumOutlay", {
        get: function () {
            if (this._rroSumOutlay == null) {
                this._rroSumOutlay = new ObasSprTableFieldTyped(ObasTableCollection.RroSumOutlayTable, this);
            }
            return this._rroSumOutlay;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlaySumByAnalyticsPart5xxTable.prototype, "FcrCodeSection", {
        get: function () {
            if (this._fcrCodeSection == null) {
                this._fcrCodeSection = new ObasTableField("FcrCodeSection", this);
            }
            return this._fcrCodeSection;
        },
        enumerable: true,
        configurable: true
    });
    RroOutlaySumByAnalyticsPart5xxTable.prototype.UpdateDataRows = function (rroOutlayFieldId, rroOutlayKey) {
        if ((rroOutlayFieldId != this.RroOutlay.ForeignKey.Id) && (rroOutlayFieldId != this.RroSumOutlay.ForeignKey.Id)) {
            return;
        }
        var rroOutlaySumByAnalyticsTable = ObasTableCollection.RroOutlaySumByAnalyticsTable;
        var reader = rroOutlaySumByAnalyticsTable.CreateReader();
        while (reader.Read()) {
            if ((rroOutlaySumByAnalyticsTable.Level.Value === 1) &&
                ObasHelper.CheckPartialCode(rroOutlaySumByAnalyticsTable.CostType.Code, this._filterCostTypeCode, 3)) {
                var locateValues = rroOutlaySumByAnalyticsTable.GetKbkKeyFieldsValue();
                locateValues.push(rroOutlayKey);
                if (!this.IsExixtsRecord(locateValues, rroOutlayFieldId)) {
                    this.InitRecord(locateValues, rroOutlayFieldId);
                    this.SetSums(rroOutlaySumByAnalyticsTable);
                }
            }
        }
    };
    RroOutlaySumByAnalyticsPart5xxTable.prototype.IsExixtsRecord = function (keyValues, rroOutlayFieldId) {
        var keyFieldIds = this.GetKbkKeyFieldsId();
        keyFieldIds.push(rroOutlayFieldId);
        return this.Locate(keyFieldIds, keyValues);
    };
    RroOutlaySumByAnalyticsPart5xxTable.prototype.InitRecord = function (keyValues, rroOutlayFieldId) {
        var keyFieldIds = this.GetKbkKeyFieldsId();
        keyFieldIds.push(rroOutlayFieldId);
        if (!this.IsExixtsRecord(keyValues, rroOutlayFieldId)) {
            var length = keyFieldIds.length;
            this.AddRow();
            for (var i = 0; i < length; i++) {
                this.SetFieldValue(keyFieldIds[i], keyValues[i]);
            }
            this.PostRow();
            this.FcrCodeSection.Value = this.CalcFcrSectionCode();
        }
    };
    RroOutlaySumByAnalyticsPart5xxTable.prototype.SetSums = function (sourceTable) {
        for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
            var fieldId = "Y" + i;
            var curValue = this.GetFieldValue(fieldId) || 0;
            var addValue = sourceTable.GetFieldValue(fieldId) || 0;
            this.SetFieldValue(fieldId, curValue + addValue);
            fieldId = "Y" + i + "_D";
            curValue = this.GetFieldValue(fieldId) || 0;
            addValue = sourceTable.GetFieldValue(fieldId) || 0;
            this.SetFieldValue(fieldId, curValue + addValue);
        }
    };
    RroOutlaySumByAnalyticsPart5xxTable.prototype.CalcDeltaSums = function () {
    };
    return RroOutlaySumByAnalyticsPart5xxTable;
}(ObasTableWithKbkData));
var RroOutlayOrgTableWithParentTable = (function (_super) {
    __extends(RroOutlayOrgTableWithParentTable, _super);
    function RroOutlayOrgTableWithParentTable() {
        var _this = _super.call(this, "RRO_Outlay_OrgPart5xx") || this;
        _this._ownerKey = null;
        _this._parentTable = ObasTableCollection.RroOutlaySumByAnalyticsPart5xxTable;
        _this._parentTable.AddTableAddListener(function () { _this.CreateRow(); });
        return _this;
    }
    Object.defineProperty(RroOutlayOrgTableWithParentTable.prototype, "ParentTable", {
        get: function () {
            return this._parentTable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlayOrgTableWithParentTable.prototype, "OwnerKey", {
        get: function () {
            if (this._ownerKey == null) {
                this._ownerKey = new ObasForeignKeyTableFieldTyped(this._parentTable, this, BaseObasTableFields.OwnerKeyField.Id, false);
            }
            return this._ownerKey;
        },
        enumerable: true,
        configurable: true
    });
    RroOutlayOrgTableWithParentTable.prototype.CreateRow = function () {
        this.AddRow();
        this.PostRow();
    };
    return RroOutlayOrgTableWithParentTable;
}(ObasTable));
var RroOutlaySumByAnalyticsFilterTable = (function (_super) {
    __extends(RroOutlaySumByAnalyticsFilterTable, _super);
    function RroOutlaySumByAnalyticsFilterTable() {
        var _this = _super.call(this, "RRO_Outlay_SumByAnalyticsFilter") || this;
        _this._rroOutlayFieldId = null;
        _this._rroOutlayKey = null;
        return _this;
    }
    Object.defineProperty(RroOutlaySumByAnalyticsFilterTable.prototype, "RroOutlayFieldId", {
        get: function () {
            if (this._rroOutlayFieldId == null) {
                this._rroOutlayFieldId = new ObasTableField("RroOutlayFieldId", this);
            }
            return this._rroOutlayFieldId;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RroOutlaySumByAnalyticsFilterTable.prototype, "RroOutlayKey", {
        get: function () {
            if (this._rroOutlayKey == null) {
                this._rroOutlayKey = new NumberObasTableField("RroOutlayKey", this);
            }
            return this._rroOutlayKey;
        },
        enumerable: true,
        configurable: true
    });
    RroOutlaySumByAnalyticsFilterTable.prototype.SetFilter = function (rroOutlayFieldId, rroOutlayKey) {
        this.DeleteAllRow();
        this.AddRow();
        this.PostRow();
        this.RroOutlayFieldId.Value = rroOutlayFieldId;
        this.RroOutlayKey.Value = rroOutlayKey;
    };
    return RroOutlaySumByAnalyticsFilterTable;
}(ObasTable));
