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 F03310;
(function (F03310) {
    var TableRules = (function () {
        function TableRules(_document) {
            this._document = _document;
        }
        return TableRules;
    }());
    F03310.TableRules = TableRules;
    var ObasTableFields = (function (_super) {
        __extends(ObasTableFields, _super);
        function ObasTableFields() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Object.defineProperty(ObasTableFields, "FnYearField", {
            get: function () {
                if (this._fnYearField == null) {
                    this._fnYearField = new BaseGenericObasTableField("Fn_Y");
                }
                return this._fnYearField;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObasTableFields, "R4YearField", {
            get: function () {
                if (this._r4YearField == null) {
                    this._r4YearField = new BaseGenericObasTableField("R4_Y");
                }
                return this._r4YearField;
            },
            enumerable: true,
            configurable: true
        });
        ObasTableFields._fnYearField = null;
        ObasTableFields._r4YearField = null;
        return ObasTableFields;
    }(BaseObasTableFields));
    F03310.ObasTableFields = ObasTableFields;
    var StrKeysP1;
    (function (StrKeysP1) {
        StrKeysP1[StrKeysP1["Total"] = 1] = "Total";
    })(StrKeysP1 = F03310.StrKeysP1 || (F03310.StrKeysP1 = {}));
    var FObasTableP1Total = (function (_super) {
        __extends(FObasTableP1Total, _super);
        function FObasTableP1Total() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        FObasTableP1Total.prototype.GetTotalKey = function () {
            return StrKeysP1.Total;
        };
        return FObasTableP1Total;
    }(P1TotalObasTable));
    F03310.FObasTableP1Total = FObasTableP1Total;
    var ObasTablePnoKeys = (function (_super) {
        __extends(ObasTablePnoKeys, _super);
        function ObasTablePnoKeys(PnoKey) {
            var _this = _super.call(this) || this;
            _this.PnoKey = PnoKey;
            return _this;
        }
        return ObasTablePnoKeys;
    }(ObasTableKeys));
    F03310.ObasTablePnoKeys = ObasTablePnoKeys;
    var PnoDataTable = (function (_super) {
        __extends(PnoDataTable, _super);
        function PnoDataTable(id, document) {
            var _this = _super.call(this, id, ["PNO_ID"], document) || this;
            _this._pno = null;
            return _this;
        }
        Object.defineProperty(PnoDataTable.prototype, "Pno", {
            get: function () {
                if (this._pno == null) {
                    this._pno = new ObasSprTableField(ObasTableCollection.PnoSprTable, this);
                }
                return this._pno;
            },
            enumerable: true,
            configurable: true
        });
        PnoDataTable.prototype.GetKeys = function (pnoKey) {
            if (pnoKey === void 0) { pnoKey = this.Pno.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new ObasTablePnoKeys(pnoKey);
            }
            else {
                this._keys.PnoKey = pnoKey;
            }
            return this._keys;
        };
        return PnoDataTable;
    }(ObasTableWithKeys));
    F03310.PnoDataTable = PnoDataTable;
    var ObasTablePnoRecipientKeys = (function (_super) {
        __extends(ObasTablePnoRecipientKeys, _super);
        function ObasTablePnoRecipientKeys(pnoKey, RecipientKey) {
            var _this = _super.call(this, pnoKey) || this;
            _this.RecipientKey = RecipientKey;
            return _this;
        }
        return ObasTablePnoRecipientKeys;
    }(ObasTablePnoKeys));
    F03310.ObasTablePnoRecipientKeys = ObasTablePnoRecipientKeys;
    var RecipientsDataTable = (function (_super) {
        __extends(RecipientsDataTable, _super);
        function RecipientsDataTable(id, parentTable, _npaTable) {
            var _this = _super.call(this, id, parentTable.KeyFieldIds.concat("RecipientCategory_ID"), parentTable.Document, parentTable) || this;
            _this._npaTable = _npaTable;
            _this._recipient = null;
            _this._copyData = null;
            _this._copyFields = null;
            _this._recipientKey = null;
            _this._pnoKey = null;
            return _this;
        }
        Object.defineProperty(RecipientsDataTable.prototype, "Recipient", {
            get: function () {
                if (this._recipient == null) {
                    this._recipient = new ObasSprTableField(ObasTableCollection.RecipientCategorySprTable, this);
                }
                return this._recipient;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(RecipientsDataTable.prototype, "ParentTable", {
            get: function () {
                return this.OwnerKey.SourceTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(RecipientsDataTable.prototype, "Pno", {
            get: function () {
                return this.ParentTable.Pno;
            },
            enumerable: true,
            configurable: true
        });
        RecipientsDataTable.prototype.RecipientChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this._npaTable.AddLink([this.Pno.ForeignKey.Value, this.Recipient.ForeignKey.Value]);
        };
        RecipientsDataTable.prototype.DeleteEventHandler = function (tableId) {
            this._pnoKey = this.Pno.ForeignKey.Value;
            this._recipientKey = this.Recipient.ForeignKey.Value;
        };
        RecipientsDataTable.prototype.AfterDeleteEventHandler = function (tableId) {
            this._npaTable.DeleteLink(tableId, [this._pnoKey, this._recipientKey]);
        };
        RecipientsDataTable.prototype.GetKeys = function (pnoKey, recipientKey) {
            if (pnoKey === void 0) { pnoKey = this.Pno.ForeignKey.Value; }
            if (recipientKey === void 0) { recipientKey = this.Recipient.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new ObasTablePnoRecipientKeys(pnoKey, recipientKey);
            }
            else {
                this._keys.PnoKey = pnoKey;
                this._keys.RecipientKey = recipientKey;
            }
            return this._keys;
        };
        return RecipientsDataTable;
    }(ObasTableWithKeysParent));
    F03310.RecipientsDataTable = RecipientsDataTable;
    var PurchaseObjectsSprTable = (function (_super) {
        __extends(PurchaseObjectsSprTable, _super);
        function PurchaseObjectsSprTable() {
            var _this = _super.call(this, "PurchaseObjects") || this;
            _this._number = null;
            _this._npaGroupKey = null;
            _this._npaGroup = null;
            return _this;
        }
        Object.defineProperty(PurchaseObjectsSprTable.prototype, "Number", {
            get: function () {
                if (this._number == null) {
                    this._number = new ObasTableField("Number", this);
                }
                return this._number;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PurchaseObjectsSprTable.prototype, "NpaGroupKey", {
            get: function () {
                if (this._npaGroupKey == null) {
                    this._npaGroupKey = new NumberObasTableField("SubgroupNormativeExpenses_ID", this);
                }
                return this._npaGroupKey;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PurchaseObjectsSprTable.prototype, "NpaGroup", {
            get: function () {
                if (this._npaGroup == null) {
                    this._npaGroup = new ObasSprTableField(ObasTableCollection.SubgroupNormativeExpensesSprTable, this);
                }
                return this._npaGroup;
            },
            enumerable: true,
            configurable: true
        });
        return PurchaseObjectsSprTable;
    }(SprTable));
    F03310.PurchaseObjectsSprTable = PurchaseObjectsSprTable;
    var PartObjectDataTable = (function (_super) {
        __extends(PartObjectDataTable, _super);
        function PartObjectDataTable(id, document, parentTable, _descTable) {
            var _this = _super.call(this, id, document, parentTable) || this;
            _this._descTable = _descTable;
            _this._objectKey = null;
            _this._object = _this._document.PurchaseObjectsSprTable;
            _this._deletedObjKey = 0;
            return _this;
        }
        Object.defineProperty(PartObjectDataTable.prototype, "ObjectKey", {
            get: function () {
                if (this._objectKey == null) {
                    this._objectKey = new NumberObasTableField("PurchaseObjects_ID", this);
                }
                return this._objectKey;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartObjectDataTable.prototype, "ObjectName", {
            get: function () {
                this._object.LocateByKeys(this.ObjectKey.Value);
                return this._object.Name;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartObjectDataTable.prototype, "ObjectNumber", {
            get: function () {
                this._object.LocateByKeys(this.ObjectKey.Value);
                return this._object.Number;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartObjectDataTable.prototype, "ObjectNpaGroupCode", {
            get: function () {
                this._object.LocateByKeys(this.ObjectKey.Value);
                return this._object.NpaGroup.Code;
            },
            enumerable: true,
            configurable: true
        });
        PartObjectDataTable.prototype.CalcSubgroupNormativeExpensesName = function () {
            this._object.LocateByKeys(this.ObjectKey.Value);
            return this._object.NpaGroup.Name || "";
        };
        PartObjectDataTable.prototype.ObjectChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this.AfterDeleteEventHandler(this.Id, oldValue);
            this._descTable.AddObject(newValue);
        };
        PartObjectDataTable.prototype.DeleteEventHandler = function (tableId) {
            this._deletedObjKey = this.ObjectKey.Value;
        };
        PartObjectDataTable.prototype.AfterDeleteEventHandler = function (tableId, objKey) {
            if (objKey === void 0) { objKey = this._deletedObjKey; }
            this._descTable.DeleteObject(objKey);
        };
        return PartObjectDataTable;
    }(ObasTableWithSimpleKeysParent));
    F03310.PartObjectDataTable = PartObjectDataTable;
    var PartOkpdTable = (function (_super) {
        __extends(PartOkpdTable, _super);
        function PartOkpdTable(id, document, parent) {
            var _this = _super.call(this, id, document, parent) || this;
            _this._okpdKey = null;
            _this._okpd = null;
            return _this;
        }
        Object.defineProperty(PartOkpdTable.prototype, "OKPDKey", {
            get: function () {
                if (this._okpdKey == null) {
                    this._okpdKey = new NumberObasTableField("OKPD_ID", this);
                }
                return this._okpdKey;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartOkpdTable.prototype, "Okpd", {
            get: function () {
                if (this._okpd == null) {
                    this._okpd = new ObasSprTableField(ObasTableCollection.OkpdSprTable, this);
                }
                return this._okpd;
            },
            enumerable: true,
            configurable: true
        });
        return PartOkpdTable;
    }(ObasTableWithSimpleKeysParent));
    F03310.PartOkpdTable = PartOkpdTable;
    var PartKosguTable = (function (_super) {
        __extends(PartKosguTable, _super);
        function PartKosguTable(id, document, parent) {
            var _this = _super.call(this, id, document, parent) || this;
            _this._kosguKey = null;
            _this._kosgu = null;
            _this._analysisFeatureKey = null;
            _this._analysisFeature = null;
            _this._year = null;
            return _this;
        }
        Object.defineProperty(PartKosguTable.prototype, "KosguKey", {
            get: function () {
                if (this._kosguKey == null) {
                    this._kosguKey = new NumberObasTableField("KOSGU_ID", this);
                }
                return this._kosguKey;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartKosguTable.prototype, "Kosgu", {
            get: function () {
                if (this._kosgu == null) {
                    this._kosgu = new ObasSprTableField(ObasTableCollection.KosguSprTable, this);
                }
                return this._kosgu;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartKosguTable.prototype, "AnalysisFeatureKey", {
            get: function () {
                if (this._analysisFeatureKey == null) {
                    this._analysisFeatureKey = new NumberObasTableField("AddAnalysisFeature_ID", this);
                }
                return this._analysisFeatureKey;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartKosguTable.prototype, "AnalysisFeature", {
            get: function () {
                if (this._analysisFeature == null) {
                    this._analysisFeature = new ObasSprTableField(ObasTableCollection.AddAnalysisFeatureSprtable, this);
                }
                return this._analysisFeature;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PartKosguTable.prototype, "Year", {
            get: function () {
                if (this._year == null) {
                    this._year = new NumberObasTableField(BaseObasTableFields.YearField.Id, this);
                }
                return this._year;
            },
            enumerable: true,
            configurable: true
        });
        PartKosguTable.prototype.SumPartsChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this.SetFieldValue(BaseObasTableFields.YearDataField.GenerateId(fieldId), (this.GetFieldValue(ObasTableFields.FnYearField.GenerateId(fieldId)) || 0) +
                (this.GetFieldValue(ObasTableFields.R4YearField.GenerateId(fieldId)) || 0));
        };
        PartKosguTable.prototype.TotalSumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var totalTable = this._document.TotalTable;
            var yearDataField = BaseObasTableFields.YearDataField;
            totalTable.SetSumByKeys(fieldId, totalTable.GetKeys(StrKeysP1.P2), oldValue, newValue);
        };
        PartKosguTable.prototype.DeleteEventHandler = function (tableId) {
            var totalTable = this._document.TotalTable;
            totalTable.Locate("StrKey", StrKeysP1.P2);
            for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
                var fieldId = "Y" + (i + 1);
                totalTable.SetFieldValue(fieldId, totalTable.GetFieldValue(fieldId) - (this.GetFieldValue(fieldId) || 0));
            }
        };
        return PartKosguTable;
    }(ObasTableWithSimpleKeysParent));
    F03310.PartKosguTable = PartKosguTable;
    var ObjectDescTable = (function (_super) {
        __extends(ObjectDescTable, _super);
        function ObjectDescTable(id, _document) {
            var _this = _super.call(this, id) || this;
            _this._document = _document;
            _this._program = null;
            _this._action = null;
            _this._result = null;
            _this._rationale = null;
            _this._info = null;
            _this._objectKey = null;
            _this._object = _this._document.PurchaseObjectsSprTable;
            return _this;
        }
        Object.defineProperty(ObjectDescTable.prototype, "Info", {
            get: function () {
                if (this._info == null) {
                    this._info = new ObasTableField("Info", this);
                }
                return this._info;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "Rationale", {
            get: function () {
                if (this._rationale == null) {
                    this._rationale = new ObasTableField("Rationale", this);
                }
                return this._rationale;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "Result", {
            get: function () {
                if (this._result == null) {
                    this._result = new ObasTableField("Result", this);
                }
                return this._result;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "Action", {
            get: function () {
                if (this._action == null) {
                    this._action = new ObasTableField("ActionName", this);
                }
                return this._action;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "Program", {
            get: function () {
                if (this._program == null) {
                    this._program = new ObasTableField("ProgName", this);
                }
                return this._program;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "ObjectKey", {
            get: function () {
                if (this._objectKey == null) {
                    this._objectKey = new NumberObasTableField("PurchaseObjects_ID", this);
                }
                return this._objectKey;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "ObjectName", {
            get: function () {
                this._object.LocateByKeys(this.ObjectKey.Value);
                return this._object.Name;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "ObjectNumber", {
            get: function () {
                this._object.LocateByKeys(this.ObjectKey.Value);
                return this._object.Number;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescTable.prototype, "ObjectNpaGroupCode", {
            get: function () {
                this._object.LocateByKeys(this.ObjectKey.Value);
                return this._object.NpaGroup.Code;
            },
            enumerable: true,
            configurable: true
        });
        ObjectDescTable.prototype.CalcSubgroupNormativeExpensesName = function () {
            this._object.LocateByKeys(this.ObjectKey.Value);
            return this._object.NpaGroup.Name || "";
        };
        ObjectDescTable.prototype.AddObject = function (objKey) {
            this._document.CommonRules.AddNewLink(this.Id, [this.ObjectKey.Id], [objKey]);
        };
        ObjectDescTable.prototype.DeleteObject = function (objKey) {
            this._document.CommonRules.DeleteOldLink(this.Id, this._document.ObjectDataTableIds(), [this.ObjectKey.Id], [objKey]);
        };
        return ObjectDescTable;
    }(ObasTable));
    F03310.ObjectDescTable = ObjectDescTable;
    var ObjectDescNpaTable = (function (_super) {
        __extends(ObjectDescNpaTable, _super);
        function ObjectDescNpaTable() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._npaFields = null;
            _this._npaStatus = null;
            _this._npsStatusChangeDate = null;
            return _this;
        }
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaFields", {
            get: function () {
                if (this._npaFields == null) {
                    this._npaFields = new NpaRequisitesFields(this);
                }
                return this._npaFields;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaNumber", {
            get: function () {
                return this.NpaFields.NpaNumber;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaName", {
            get: function () {
                return this.NpaFields.NpaName;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaDate", {
            get: function () {
                return this.NpaFields.NpaDate;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaType", {
            get: function () {
                return this.NpaFields.NpaType;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaStatus", {
            get: function () {
                if (this._npaStatus == null) {
                    this._npaStatus = new ObasSprTableField(ObasTableCollection.NpaStatusesSprTable, this);
                }
                return this._npaStatus;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ObjectDescNpaTable.prototype, "NpaStatusChangeDate", {
            get: function () {
                if (this._npsStatusChangeDate == null) {
                    this._npsStatusChangeDate = new ObasTableField("NpaChangeDate", this);
                }
                return this._npsStatusChangeDate;
            },
            enumerable: true,
            configurable: true
        });
        return ObjectDescNpaTable;
    }(ObasTableWithSimpleKeysParent));
    F03310.ObjectDescNpaTable = ObjectDescNpaTable;
    var NpaTable = (function (_super) {
        __extends(NpaTable, _super);
        function NpaTable(id, _document) {
            var _this = _super.call(this, id) || this;
            _this._document = _document;
            _this._pno = null;
            _this._recipient = null;
            return _this;
        }
        Object.defineProperty(NpaTable.prototype, "Pno", {
            get: function () {
                if (this._pno == null) {
                    this._pno = new ObasSprTableField(ObasTableCollection.PublicCommitmentsSprTable, this);
                }
                return this._pno;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NpaTable.prototype, "Recipient", {
            get: function () {
                if (this._recipient == null) {
                    this._recipient = new ObasSprTableField(ObasTableCollection.RecipientCategorySprTable, this);
                }
                return this._recipient;
            },
            enumerable: true,
            configurable: true
        });
        NpaTable.prototype.AddLink = function (srcFieldValues) {
            this._document.CommonRules.AddNewLink(this.Id, [this.Pno.ForeignKey.Id, this.Recipient.ForeignKey.Id], srcFieldValues);
        };
        NpaTable.prototype.DeleteLink = function (parentTable, srcFieldValues) {
            this._document.CommonRules.DeleteOldLink(this.Id, [parentTable], [this.Pno.ForeignKey.Id, this.Recipient.ForeignKey.Id], srcFieldValues);
        };
        return NpaTable;
    }(NpaObasTable));
    F03310.NpaTable = NpaTable;
    var ImportedProcurementTable = (function (_super) {
        __extends(ImportedProcurementTable, _super);
        function ImportedProcurementTable() {
            var _this = _super.call(this, "ImportedProcurement") || this;
            _this._isMarked = null;
            _this._procurementKBK = null;
            _this._fullKBKCode = null;
            return _this;
        }
        Object.defineProperty(ImportedProcurementTable.prototype, "IsMarked", {
            get: function () {
                if (this._isMarked == null) {
                    this._isMarked = new ObasTableField("IsMarked", this);
                }
                return this._isMarked;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ImportedProcurementTable.prototype, "ProcurementKBK", {
            get: function () {
                if (this._procurementKBK == null) {
                    this._procurementKBK = new ObasSprTableFieldTyped(ObasTableCollection.RroProcurementKBKTable, this);
                }
                return this._procurementKBK;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ImportedProcurementTable.prototype, "FullKBKCode", {
            get: function () {
                if (this._fullKBKCode == null) {
                    this._fullKBKCode = new ObasTableField("FullKBKCode", this);
                }
                return this._fullKBKCode;
            },
            enumerable: true,
            configurable: true
        });
        return ImportedProcurementTable;
    }(ObasTable));
    F03310.ImportedProcurementTable = ImportedProcurementTable;
})(F03310 || (F03310 = {}));
