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 F01285;
(function (F01285) {
    var TableRules = (function () {
        function TableRules(_document) {
            this._document = _document;
        }
        return TableRules;
    }());
    F01285.TableRules = TableRules;
    var P2Sp2Sp3StrKeys;
    (function (P2Sp2Sp3StrKeys) {
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["AllContracts"] = 1] = "AllContracts";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["AllOfficers"] = 2] = "AllOfficers";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["SeniorOfficers"] = 3] = "SeniorOfficers";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["MiddleOfficers"] = 4] = "MiddleOfficers";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["JuniorOfficers"] = 5] = "JuniorOfficers";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["Ensigns"] = 6] = "Ensigns";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["OtherContracts"] = 7] = "OtherContracts";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["CadetsWithContract"] = 8] = "CadetsWithContract";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["CadetsWithoutContract"] = 9] = "CadetsWithoutContract";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["Inductees"] = 10] = "Inductees";
        P2Sp2Sp3StrKeys[P2Sp2Sp3StrKeys["Total"] = 11] = "Total";
    })(P2Sp2Sp3StrKeys = F01285.P2Sp2Sp3StrKeys || (F01285.P2Sp2Sp3StrKeys = {}));
    var StrKeysP1Total;
    (function (StrKeysP1Total) {
        StrKeysP1Total[StrKeysP1Total["P2"] = 3] = "P2";
        StrKeysP1Total[StrKeysP1Total["P3"] = 4] = "P3";
        StrKeysP1Total[StrKeysP1Total["Correction"] = 100] = "Correction";
        StrKeysP1Total[StrKeysP1Total["Total"] = 1] = "Total";
    })(StrKeysP1Total = F01285.StrKeysP1Total || (F01285.StrKeysP1Total = {}));
    var StrKeysPXSp1;
    (function (StrKeysPXSp1) {
        StrKeysPXSp1[StrKeysPXSp1["TotalFot"] = 2] = "TotalFot";
        StrKeysPXSp1[StrKeysPXSp1["Correction"] = 3] = "Correction";
        StrKeysPXSp1[StrKeysPXSp1["Total"] = 1] = "Total";
    })(StrKeysPXSp1 = F01285.StrKeysPXSp1 || (F01285.StrKeysPXSp1 = {}));
    var StrKeysPXSp2;
    (function (StrKeysPXSp2) {
        StrKeysPXSp2[StrKeysPXSp2["Fot"] = 2] = "Fot";
        StrKeysPXSp2[StrKeysPXSp2["FotRub"] = 3] = "FotRub";
        StrKeysPXSp2[StrKeysPXSp2["Total"] = 1] = "Total";
    })(StrKeysPXSp2 = F01285.StrKeysPXSp2 || (F01285.StrKeysPXSp2 = {}));
    var TableP1 = (function (_super) {
        __extends(TableP1, _super);
        function TableP1() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._yearData = null;
            _this._usdFotData = null;
            _this._rubFotData = null;
            return _this;
        }
        TableP1.prototype.GetTotalKey = function () {
            return StrKeysP1Total.Total;
        };
        ;
        Object.defineProperty(TableP1.prototype, "YearData", {
            get: function () {
                if (this._yearData == null) {
                    this._yearData = new NumberGenericObasTableField(BaseObasTableFields.YearDataField.Id, this);
                }
                return this._yearData;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(TableP1.prototype, "RubFotData", {
            get: function () {
                if (this._rubFotData == null) {
                    this._rubFotData = new NumberGenericObasTableField("Fot_Rub_Y", this);
                }
                return this._rubFotData;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(TableP1.prototype, "UsdFotData", {
            get: function () {
                if (this._usdFotData == null) {
                    this._usdFotData = new NumberGenericObasTableField("Fot_Usd_Y", this);
                }
                return this._usdFotData;
            },
            enumerable: true,
            configurable: true
        });
        TableP1.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            if (this.StrKey === 100) {
                if (this.GetFieldValue(fieldId) < -100 || this.GetFieldValue(fieldId) > 100) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u043F\u043E\u043B\u044F \u0434\u043E\u043B\u0436\u043D\u043E \u043D\u0430\u0445\u043E\u0434\u0438\u0442\u044C\u0441\u044F \u0432 \u0434\u0438\u0430\u043F\u0430\u0437\u043E\u043D\u0435 \u043E\u0442 -100 \u0434\u043E 100.", MessageIcons.Error);
                    this.SetFieldValue(fieldId, oldValue);
                }
            }
            this.YearData.GetFieldByField(fieldId).NValue = this.UsdFotData.GetFieldByField(fieldId).NValue + this.RubFotData.GetFieldByField(fieldId).NValue;
            _super.prototype.SumChangeEventHandler.call(this, tableId, oldValue, newValue, fieldId);
            if (this.StrKey === StrKeysP1Total.Total) {
                var analyticsDataTable = this._document.AnalyticsDataTable;
                analyticsDataTable.Locate(analyticsDataTable.RecordKey.Id, 2);
                var yearOffset = ObasHelper.GetYearOffsetById(fieldId) + 1;
                analyticsDataTable.SetFieldValue("Y" + yearOffset, this.YearData.GetFieldByField(fieldId).NValue);
            }
        };
        TableP1.prototype.ResetData = function (keys) {
            this.Document.CommonRules.ResetTableDataWithKeys(this, keys, BaseObasTableFields.FotUsdYearDataField, BaseObasTableFields.FotRubYearDataField, BaseObasTableFields.YearDataField);
        };
        return TableP1;
    }(P1TotalObasTable));
    F01285.TableP1 = TableP1;
    var PxSp2Table = (function (_super) {
        __extends(PxSp2Table, _super);
        function PxSp2Table() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        PxSp2Table.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            switch (this.StrKey) {
                case StrKeysPXSp2.FotRub:
                case StrKeysPXSp2.Fot:
                    this.ParentTable.SetSumByKeys(fieldId, this.ParentTable.GetKeys(this.StrKey), oldValue, newValue);
                    var fotValue = this.GetValueByKeys(fieldId, this.GetKeys(StrKeysPXSp2.FotRub));
                    var fotRubValue = this.GetValueByKeys(fieldId, this.GetKeys(StrKeysPXSp2.Fot));
                    var sumValue = fotValue + fotRubValue;
                    this.SetValueByKeys(fieldId, this.GetKeys(StrKeysPXSp2.Total), sumValue);
                    break;
            }
        };
        PxSp2Table.prototype.AfterDeleteChildsEventHandler = function (tableId) {
            var _this = this;
            var yearField = BaseObasTableFields.YearDataField;
            this.Document.IterateByYears(function (i) {
                _this.SetFieldValue(yearField.GenerateId(i), 0);
            });
        };
        return PxSp2Table;
    }(ObasTableP1));
    F01285.PxSp2Table = PxSp2Table;
    var PxSp1Table = (function (_super) {
        __extends(PxSp1Table, _super);
        function PxSp1Table(id, document, sumTable, _sumKey) {
            var _this = _super.call(this, id, document, sumTable) || this;
            _this._sumKey = _sumKey;
            _this._usdFotData = null;
            _this._rubFotData = null;
            _this._yearData = null;
            return _this;
        }
        Object.defineProperty(PxSp1Table.prototype, "RubFotData", {
            get: function () {
                if (this._rubFotData == null) {
                    this._rubFotData = new NumberGenericObasTableField("Fot_Rub_Y", this);
                }
                return this._rubFotData;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp1Table.prototype, "UsdFotData", {
            get: function () {
                if (this._usdFotData == null) {
                    this._usdFotData = new NumberGenericObasTableField("Fot_Usd_Y", this);
                }
                return this._usdFotData;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp1Table.prototype, "YearData", {
            get: function () {
                if (this._yearData == null) {
                    this._yearData = new NumberGenericObasTableField(BaseObasTableFields.YearDataField.Id, this);
                }
                return this._yearData;
            },
            enumerable: true,
            configurable: true
        });
        PxSp1Table.prototype.GetKeys = function (strKey) {
            if (strKey === void 0) { strKey = this.StrKey; }
            if (this._keys == null) {
                this._keys = new StrObasTableKeys(strKey);
            }
            else {
                this._keys.StrKey = strKey;
            }
            return this._keys;
        };
        PxSp1Table.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            switch (this.StrKey) {
                case StrKeysPXSp1.TotalFot:
                case StrKeysPXSp1.Correction:
                    var fotValue = this.GetValueByKeys(fieldId, this.GetKeys(StrKeysPXSp1.TotalFot));
                    var sumValue = fotValue;
                    var correctionValue = this.GetValueByKeys(fieldId, this.GetKeys(StrKeysPXSp1.Correction));
                    sumValue += correctionValue;
                    this.SetValueByKeys(fieldId, this.GetKeys(StrKeysPXSp1.Total), sumValue);
                    break;
                case StrKeysPXSp1.Total:
                    this.ParentTable.SetSumByKeys(fieldId, this.ParentTable.GetKeys(this._sumKey), oldValue, newValue);
                    break;
            }
        };
        PxSp1Table.prototype.ResetData = function (keys) {
            this.Document.CommonRules.ResetTableDataWithKeys(this, keys, BaseObasTableFields.FotUsdYearDataField, BaseObasTableFields.FotRubYearDataField);
        };
        return PxSp1Table;
    }(ObasTableWithStrParent));
    F01285.PxSp1Table = PxSp1Table;
    var PxSp2TotalTable = (function (_super) {
        __extends(PxSp2TotalTable, _super);
        function PxSp2TotalTable(id, document, _pTable) {
            var _this = _super.call(this, id, document) || this;
            _this._pTable = _pTable;
            return _this;
        }
        PxSp2TotalTable.prototype.GetTotalKey = function () {
            return StrKeysPXSp2.Total;
        };
        ;
        PxSp2TotalTable.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            switch (this.StrKey) {
                case StrKeysPXSp2.FotRub:
                    this._pTable.SetSumByKeys(this._pTable.RubFotData.GetFieldByField(fieldId).Id, this._pTable.GetKeys(StrKeysPXSp1.TotalFot), oldValue, newValue);
                    break;
                case StrKeysPXSp2.Fot:
                    this._pTable.SetSumByKeys(this._pTable.UsdFotData.GetFieldByField(fieldId).Id, this._pTable.GetKeys(StrKeysPXSp1.TotalFot), oldValue, newValue);
                    break;
            }
            if (!this.IsTotal) {
                this.SetSumByKeys(fieldId, this.GetKeys(this.GetTotalKey()), oldValue, newValue);
            }
        };
        return PxSp2TotalTable;
    }(P1TotalObasTable));
    F01285.PxSp2TotalTable = PxSp2TotalTable;
    var PxSp2Sp2DataTable = (function (_super) {
        __extends(PxSp2Sp2DataTable, _super);
        function PxSp2Sp2DataTable(id, parentTable, _sumTable, addKeyFields) {
            var _this = _super.call(this, id, parentTable.KeyFieldIds.concat(addKeyFields), _sumTable.Document, parentTable) || this;
            _this._sumTable = _sumTable;
            _this._year = null;
            _this._country = null;
            _this._orgField = null;
            _this._fot = null;
            _this._totalFot = null;
            _this._addFot = null;
            _this._emplCount = null;
            _this._salary = null;
            _this._salaryCount = null;
            _this._isCopied = null;
            _this._copyData = null;
            return _this;
        }
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "CopyFieldsInfo", {
            get: function () {
                if (this._copyData == null) {
                    this._copyData = this.InitCopyFieldsInfo();
                }
                return this.CollectTableRecordData(this._copyData);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "IsCopied", {
            get: function () {
                if (this._isCopied == null) {
                    this._isCopied = new ObasTableField(BaseObasTableFields.CopiedRowFlagField.Id, this);
                }
                return this._isCopied;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "SalaryCount", {
            get: function () {
                if (this._salaryCount == null) {
                    this._salaryCount = new NumberObasTableField("SalaryCount", this);
                }
                return this._salaryCount;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "Salary", {
            get: function () {
                if (this._salary == null) {
                    this._salary = new NumberObasTableField("Salary", this);
                }
                return this._salary;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "EmplCount", {
            get: function () {
                if (this._emplCount == null) {
                    this._emplCount = new NumberObasTableField("EmplCount", this);
                }
                return this._emplCount;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "AddFot", {
            get: function () {
                if (this._addFot == null) {
                    this._addFot = new NumberObasTableField("AddFot", this);
                }
                return this._addFot;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "TotalFot", {
            get: function () {
                if (this._totalFot == null) {
                    this._totalFot = new NumberObasTableField("TotalFot", this);
                }
                return this._totalFot;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "Fot", {
            get: function () {
                if (this._fot == null) {
                    this._fot = new NumberObasTableField("Fot", this);
                }
                return this._fot;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "Country", {
            get: function () {
                if (this._country == null) {
                    this._country = new ObasSprTableField(ObasTableCollection.OksmSprTable, this);
                }
                return this._country;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "Year", {
            get: function () {
                if (this._year == null) {
                    this._year = new NumberObasTableField(BaseObasTableFields.YearField.Id, this);
                }
                return this._year;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "YearOffset", {
            get: function () {
                return ObasHelper.GetYearOffset(this);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "Org", {
            get: function () {
                if (this._orgField == null) {
                    this._orgField = new ObasSprTableField(ObasTableCollection.OrganizationTable, this);
                }
                return this._orgField;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSp2Sp2DataTable.prototype, "ParentTable", {
            get: function () {
                return this.OwnerKey.SourceTable;
            },
            enumerable: true,
            configurable: true
        });
        PxSp2Sp2DataTable.prototype.TotalFotChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this._sumTable.SetSumByKeys(BaseObasTableFields.YearDataField.GenerateId(this.YearOffset + 1), this._sumTable.GetKeys(StrKeysPXSp2.FotRub, this.ParentTable.UniqRecordKey), oldValue, newValue);
        };
        PxSp2Sp2DataTable.prototype.FotPartsChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this.Fot.Value = this.EmplCount.NValue * this.Salary.NValue * this.SalaryCount.NValue;
        };
        PxSp2Sp2DataTable.prototype.AfterDeleteChildsEventHandler = function (tableId) {
            this.TotalFot.NValue = 0;
        };
        PxSp2Sp2DataTable.prototype.CopyData = function (srcYear, destYear) {
            var _this = this;
            var endYear = ObasStageSettings.CurrentYear + ObasStageSettings.YearsCount;
            if (srcYear == null) {
                srcYear = endYear - 2;
            }
            if (destYear == null) {
                destYear = endYear - 1;
            }
            if (srcYear && destYear) {
                var copyHandler = function (table, recordKey) {
                    if (_this.Year.Value === srcYear) {
                        _this.InnerCopyData(recordKey, destYear);
                    }
                };
                this.Iterate(copyHandler);
            }
        };
        PxSp2Sp2DataTable.prototype.GetRecordKey = function (keys, addIfNotExists) {
            if (addIfNotExists === void 0) { addIfNotExists = false; }
            this.ParentTable.GetRecordKey(keys, true);
            return _super.prototype.GetRecordKey.call(this, keys, true);
        };
        PxSp2Sp2DataTable.prototype.InnerCopyData = function (recordKey, endYear) {
            if (this.Locate(this.RecordKey.Id, recordKey)) {
                this.IsCopied.Value = true;
                var copyData = this.CopyFieldsInfo;
                var keys = this.GetKeys();
                var parentTable = this.ParentTable;
                for (var year = keys.Year + 1; year <= endYear; year++) {
                    var ownerKey = parentTable.GetRecordKey(parentTable.GetKeys(keys.OrgKey, keys.CountryKey, year), true);
                    copyData.getValue(this.OwnerKey.Id).Value = ownerKey;
                    keys.Year = year;
                    this.SetupTableRecordData(copyData, this.RecordKey.LookupByKeys(keys.ToArray()), true);
                }
                this.RecordKey.Locate(recordKey);
            }
        };
        PxSp2Sp2DataTable.prototype.EditEventHandler = function (tableId) {
            if (this.Document.NotOnUpdate && !this.IsCopied.Value && this.IsRedyForCopy()) {
                this.InnerCopyData(this.RecordKey.Value, ObasStageSettings.CurrentYear + ObasStageSettings.YearsCount - 1);
            }
        };
        PxSp2Sp2DataTable.prototype.IsRedyForCopy = function () {
            return ObasHelper.CheckIsReadyForCopy(this.CopyFieldsInfo);
        };
        PxSp2Sp2DataTable.prototype.ResetData = function (keys) {
            if (keys) {
                if (this.LocateByKeys(keys.ToArray())) {
                    this.ResetDataHandler(this, this.RecordKey.Value);
                }
            }
            else {
                this.Iterate(this.ResetDataHandler);
            }
        };
        PxSp2Sp2DataTable.prototype.CollectUserData = function () {
            return this.CollectTableData(this.InitCopyFieldsInfo());
        };
        return PxSp2Sp2DataTable;
    }(ObasTableWithKeysParent));
    F01285.PxSp2Sp2DataTable = PxSp2Sp2DataTable;
    var ObasTableOrgCountryYearStrKeys = (function (_super) {
        __extends(ObasTableOrgCountryYearStrKeys, _super);
        function ObasTableOrgCountryYearStrKeys(orgKey, countryKey, year, StrKey) {
            var _this = _super.call(this, orgKey, countryKey, year) || this;
            _this.StrKey = StrKey;
            return _this;
        }
        return ObasTableOrgCountryYearStrKeys;
    }(OrgCountryYearObasTableKeys));
    F01285.ObasTableOrgCountryYearStrKeys = ObasTableOrgCountryYearStrKeys;
    var ObasTableOrgCountryYearPostKeys = (function (_super) {
        __extends(ObasTableOrgCountryYearPostKeys, _super);
        function ObasTableOrgCountryYearPostKeys(orgKey, countryKey, year, PostKey) {
            var _this = _super.call(this, orgKey, countryKey, year) || this;
            _this.PostKey = PostKey;
            return _this;
        }
        return ObasTableOrgCountryYearPostKeys;
    }(OrgCountryYearObasTableKeys));
    F01285.ObasTableOrgCountryYearPostKeys = ObasTableOrgCountryYearPostKeys;
    var ObasTableOrgCountryYearStrPayKeys = (function (_super) {
        __extends(ObasTableOrgCountryYearStrPayKeys, _super);
        function ObasTableOrgCountryYearStrPayKeys(orgKey, countryKey, year, strKey, PayKey) {
            var _this = _super.call(this, orgKey, countryKey, year, strKey) || this;
            _this.PayKey = PayKey;
            return _this;
        }
        return ObasTableOrgCountryYearStrPayKeys;
    }(ObasTableOrgCountryYearStrKeys));
    F01285.ObasTableOrgCountryYearStrPayKeys = ObasTableOrgCountryYearStrPayKeys;
    var ObasTableOrgCountryYearPostPayKeys = (function (_super) {
        __extends(ObasTableOrgCountryYearPostPayKeys, _super);
        function ObasTableOrgCountryYearPostPayKeys(orgKey, countryKey, year, postKey, PayKey) {
            var _this = _super.call(this, orgKey, countryKey, year, postKey) || this;
            _this.PayKey = PayKey;
            return _this;
        }
        return ObasTableOrgCountryYearPostPayKeys;
    }(ObasTableOrgCountryYearPostKeys));
    F01285.ObasTableOrgCountryYearPostPayKeys = ObasTableOrgCountryYearPostPayKeys;
    var P2Sp2Sp3RowsSprTable = (function (_super) {
        __extends(P2Sp2Sp3RowsSprTable, _super);
        function P2Sp2Sp3RowsSprTable(id, _document) {
            var _this = _super.call(this, id, [BaseObasTableFields.RecordKeyField.Id], BaseObasTableFields.StrCodeField.Id) || this;
            _this._document = _document;
            _this._isDataRowField = null;
            return _this;
        }
        Object.defineProperty(P2Sp2Sp3RowsSprTable.prototype, "IsDataRowField", {
            get: function () {
                if (this._isDataRowField == null) {
                    this._isDataRowField = new ObasTableField("isDataRow", this);
                }
                return this._isDataRowField;
            },
            enumerable: true,
            configurable: true
        });
        P2Sp2Sp3RowsSprTable.prototype.IsDataRow = function () {
            return this.IsDataRowField.Value || false;
        };
        return P2Sp2Sp3RowsSprTable;
    }(BarsRowsSprTable));
    F01285.P2Sp2Sp3RowsSprTable = P2Sp2Sp3RowsSprTable;
    var P2Sp2Sp2DataTable = (function (_super) {
        __extends(P2Sp2Sp2DataTable, _super);
        function P2Sp2Sp2DataTable(id, parentTable, sumTable) {
            var _this = _super.call(this, id, parentTable, sumTable, [BaseObasTableFields.StrKeyField.Id]) || this;
            _this._strKeyField = null;
            return _this;
        }
        Object.defineProperty(P2Sp2Sp2DataTable.prototype, "StrKeyField", {
            get: function () {
                if (this._strKeyField == null) {
                    this._strKeyField = new ObasForeignKeyTableField(this.Document.P2Sp2Sp3RowsTable, this, BaseObasTableFields.StrKeyField.Id, false);
                }
                return this._strKeyField;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2Sp2Sp2DataTable.prototype, "StrKey", {
            get: function () {
                return this.StrKeyField.Value;
            },
            set: function (value) {
                this.StrKeyField.Value = value;
            },
            enumerable: true,
            configurable: true
        });
        P2Sp2Sp2DataTable.prototype.GetKeys = function (orgKey, countryKey, year, strKey) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (year === void 0) { year = this.Year.Value; }
            if (strKey === void 0) { strKey = this.StrKey; }
            if (this._keys == null) {
                this._keys = new ObasTableOrgCountryYearStrKeys(orgKey, countryKey, year, strKey);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.Year = year;
                this._keys.CountryKey = countryKey;
                this._keys.StrKey = strKey;
            }
            return this._keys;
        };
        P2Sp2Sp2DataTable.prototype.TotalFotPartsChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this.TotalFot.NValue = this.Fot.NValue + this.AddFot.NValue;
        };
        P2Sp2Sp2DataTable.prototype.ResetDataHandler = function (table) {
            table.EmplCount.Value = 0;
            table.Salary.Value = 0;
            table.SalaryCount.Value = 0;
            table.Fot.Value = 0;
            table.AddFot.Value = 0;
            table.TotalFot.Value = 0;
        };
        P2Sp2Sp2DataTable.prototype.InitCopyFieldsInfo = function () {
            var result = new collections.Dictionary();
            result.setValue(this.IsCopied.Id, {
                Id: this.IsCopied.Id,
                IsData: false
            });
            result.setValue(this.OwnerKey.Id, {
                Id: this.OwnerKey.Id,
                IsData: false
            });
            result.setValue(this.StrKeyField.Id, {
                Id: this.StrKeyField.Id,
                IsData: false
            });
            result.setValue(this.EmplCount.Id, {
                Id: this.EmplCount.Id,
                IsData: true
            });
            result.setValue(this.Salary.Id, {
                Id: this.Salary.Id,
                IsData: true
            });
            result.setValue(this.SalaryCount.Id, {
                Id: this.SalaryCount.Id,
                IsData: true
            });
            return result;
        };
        P2Sp2Sp2DataTable.prototype.SetSumByKeys = function (fieldId, keys, oldValue, newValue) {
            var parentTable = this.ParentTable;
            var ownerKey = parentTable.GetRecordKey(parentTable.GetKeys(keys.OrgKey, keys.CountryKey, keys.Year), true);
            this.Document.CommonRules.SetSumByKeys(this, P2Sp2Sp2DataTable._systemKeyIds, [ownerKey, keys.StrKey], fieldId, oldValue || 0, newValue || 0);
        };
        P2Sp2Sp2DataTable.prototype.IsUserEditRow = function (rowKey) {
            if (rowKey === void 0) { rowKey = this.StrKey; }
            return !(rowKey === P2Sp2Sp3StrKeys.AllContracts || rowKey === P2Sp2Sp3StrKeys.AllOfficers || rowKey === P2Sp2Sp3StrKeys.Total);
        };
        P2Sp2Sp2DataTable.prototype.CollectUserData = function () {
            var _this = this;
            return this.CollectTableData(this.InitCopyFieldsInfo(), function () {
                return _this.IsUserEditRow();
            });
        };
        return P2Sp2Sp2DataTable;
    }(PxSp2Sp2DataTable));
    P2Sp2Sp2DataTable._systemKeyIds = [BaseObasTableFields.OwnerKeyField.Id, BaseObasTableFields.StrKeyField.Id];
    F01285.P2Sp2Sp2DataTable = P2Sp2Sp2DataTable;
    var P3Sp2Sp2DataTable = (function (_super) {
        __extends(P3Sp2Sp2DataTable, _super);
        function P3Sp2Sp2DataTable(id, parentTable, sumTable) {
            var _this = _super.call(this, id, parentTable, sumTable, ["Post_ID"]) || this;
            _this._post = null;
            _this._indexation = null;
            return _this;
        }
        Object.defineProperty(P3Sp2Sp2DataTable.prototype, "Indexation", {
            get: function () {
                if (this._indexation == null) {
                    this._indexation = new NumberObasTableField("Indexation", this);
                }
                return this._indexation;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P3Sp2Sp2DataTable.prototype, "Post", {
            get: function () {
                if (this._post == null) {
                    this._post = new ObasSprTableField(this.Document.Post0109SprTable, this, "Post");
                }
                return this._post;
            },
            enumerable: true,
            configurable: true
        });
        P3Sp2Sp2DataTable.prototype.GetKeys = function (orgKey, countryKey, year, postKey) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (year === void 0) { year = this.Year.Value; }
            if (postKey === void 0) { postKey = this.Post.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new ObasTableOrgCountryYearPostKeys(orgKey, countryKey, year, postKey);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.Year = year;
                this._keys.CountryKey = countryKey;
                this._keys.PostKey = postKey;
            }
            return this._keys;
        };
        P3Sp2Sp2DataTable.prototype.TotalFotPartsChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var fot = this.Fot.NValue + this.AddFot.NValue;
            var index = this.Document.CommonRules.CalcIndexationByYear(fot, this.Year.Value);
            this.Indexation.NValue = index;
            this.TotalFot.NValue = fot + index;
        };
        P3Sp2Sp2DataTable.prototype.ResetDataHandler = function (table) {
            table.EmplCount.Value = 0;
            table.SalaryCount.Value = 0;
            table.Fot.Value = 0;
            table.AddFot.Value = 0;
            table.Indexation.Value = 0;
            table.TotalFot.Value = 0;
        };
        P3Sp2Sp2DataTable.prototype.InitCopyFieldsInfo = function () {
            var result = new collections.Dictionary();
            result.setValue(this.IsCopied.Id, {
                Id: this.IsCopied.Id,
                IsData: false
            });
            result.setValue(this.OwnerKey.Id, {
                Id: this.OwnerKey.Id,
                IsData: false
            });
            result.setValue(this.Post.ForeignKey.Id, {
                Id: this.Post.ForeignKey.Id,
                IsData: false
            });
            result.setValue(this.EmplCount.Id, {
                Id: this.EmplCount.Id,
                IsData: true
            });
            result.setValue(this.SalaryCount.Id, {
                Id: this.SalaryCount.Id,
                IsData: true
            });
            return result;
        };
        return P3Sp2Sp2DataTable;
    }(PxSp2Sp2DataTable));
    F01285.P3Sp2Sp2DataTable = P3Sp2Sp2DataTable;
    var PxSpxSp3DataTable = (function (_super) {
        __extends(PxSpxSp3DataTable, _super);
        function PxSpxSp3DataTable(id, document, parent) {
            var _this = _super.call(this, id, parent.KeyFieldIds.concat("Payments_ID"), document, parent) || this;
            _this._isCopied = null;
            _this._payment = null;
            _this._addFot = null;
            _this._copyData = null;
            _this._npaType = null;
            _this._npaFields = null;
            return _this;
        }
        Object.defineProperty(PxSpxSp3DataTable.prototype, "NpaFields", {
            get: function () {
                if (this._npaFields == null) {
                    this._npaFields = new NpaRequisitesFields(this);
                }
                return this._npaFields;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "NpaType", {
            get: function () {
                if (this._npaType == null) {
                    this._npaType = new ObasSprTableField(ObasTableCollection.NpaTypeTable, this);
                }
                return this._npaType;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "CopyFieldsInfo", {
            get: function () {
                if (this._copyData == null) {
                    this._copyData = this.InitCopyFieldsInfo();
                }
                return this.CollectTableRecordData(this._copyData);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "AddFot", {
            get: function () {
                if (this._addFot == null) {
                    this._addFot = new NumberObasTableField("g9", this);
                }
                return this._addFot;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "Payment", {
            get: function () {
                if (this._payment == null) {
                    this._payment = new ObasSprTableField(this.Document.PaymentsSprTable, this);
                }
                return this._payment;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "IsCopied", {
            get: function () {
                if (this._isCopied == null) {
                    this._isCopied = new ObasTableField(BaseObasTableFields.CopiedRowFlagField.Id, this);
                }
                return this._isCopied;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "Country", {
            get: function () {
                return this.ParentTable.Country;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "Year", {
            get: function () {
                return this.ParentTable.Year;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "YearOffset", {
            get: function () {
                return ObasHelper.GetYearOffset(this);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "Org", {
            get: function () {
                return this.ParentTable.Org;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PxSpxSp3DataTable.prototype, "ParentTable", {
            get: function () {
                return this.OwnerKey.SourceTable;
            },
            enumerable: true,
            configurable: true
        });
        PxSpxSp3DataTable.prototype.AfterDeleteChildsEventHandler = function (tableId) {
            this.AddFot.NValue = 0;
        };
        PxSpxSp3DataTable.prototype.CopyData = function (srcYear, destYear) {
            var _this = this;
            var endYear = ObasStageSettings.CurrentYear + ObasStageSettings.YearsCount;
            if (srcYear == null) {
                srcYear = endYear - 2;
            }
            if (destYear == null) {
                destYear = endYear - 1;
            }
            if (srcYear && destYear) {
                var copyHandler = function (table, recordKey) {
                    if (_this.Year.Value === srcYear) {
                        _this.InnerCopyData(recordKey, destYear);
                    }
                };
                this.Iterate(copyHandler);
            }
        };
        PxSpxSp3DataTable.prototype.EditEventHandler = function (tableId) {
            if (this.Document.NotOnUpdate && !this.IsCopied.Value && this.IsRedyForCopy()) {
                this.InnerCopyData(this.RecordKey.Value, ObasStageSettings.CurrentYear + ObasStageSettings.YearsCount - 1);
            }
        };
        PxSpxSp3DataTable.prototype.IsRedyForCopy = function () {
            return ObasHelper.CheckIsReadyForCopy(this.CopyFieldsInfo);
        };
        PxSpxSp3DataTable.prototype.ResetData = function (keys) {
            var _this = this;
            var resetHandler = function () {
                _this.AddFot.Value = 0;
            };
            if (keys) {
                if (this.LocateByKeys(keys.ToArray())) {
                    resetHandler();
                }
            }
            else {
                this.Iterate(resetHandler);
            }
        };
        PxSpxSp3DataTable.prototype.CollectUserData = function () {
            return this.CollectTableData(this.InitCopyFieldsInfo());
        };
        return PxSpxSp3DataTable;
    }(ObasTableWithKeysParent));
    F01285.PxSpxSp3DataTable = PxSpxSp3DataTable;
    var P2Sp2Sp3DataTable = (function (_super) {
        __extends(P2Sp2Sp3DataTable, _super);
        function P2Sp2Sp3DataTable(id, parentTable, _sumTable) {
            var _this = _super.call(this, id, _sumTable.Document, parentTable) || this;
            _this._sumTable = _sumTable;
            _this._strKeyField = null;
            return _this;
        }
        Object.defineProperty(P2Sp2Sp3DataTable.prototype, "StrKeyField", {
            get: function () {
                if (this._strKeyField == null) {
                    this._strKeyField = new ObasForeignKeyTableField(this.Document.P2Sp2Sp3RowsTable, this, BaseObasTableFields.StrKeyField.Id, false);
                }
                return this._strKeyField;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2Sp2Sp3DataTable.prototype, "StrKey", {
            get: function () {
                return this.StrKeyField.Value;
            },
            set: function (value) {
                this.StrKeyField.Value = value;
            },
            enumerable: true,
            configurable: true
        });
        P2Sp2Sp3DataTable.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var parentKeys = this.ParentTable.GetKeys();
            var sumTable = this._sumTable;
            sumTable.SetSumByKeys(sumTable.AddFot.Id, sumTable.GetKeys(parentKeys.OrgKey, parentKeys.CountryKey, parentKeys.Year, this.StrKey), oldValue, newValue);
        };
        P2Sp2Sp3DataTable.prototype.AfterDeleteChildsEventHandler = function (tableId) {
            var parentKeys = this.ParentTable.GetKeys();
            if (this._sumTable.LocateByKeys(this._sumTable
                .GetKeys(parentKeys.OrgKey, parentKeys.CountryKey, parentKeys.Year, this.StrKey)
                .ToArray())) {
                this.AddFot.NValue = 0;
            }
        };
        P2Sp2Sp3DataTable.prototype.GetKeys = function (orgKey, countryKey, year, strKey, payKey) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (year === void 0) { year = this.Year.Value; }
            if (strKey === void 0) { strKey = this.StrKey; }
            if (payKey === void 0) { payKey = this.Payment.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new ObasTableOrgCountryYearStrPayKeys(orgKey, countryKey, year, strKey, payKey);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.Year = year;
                this._keys.CountryKey = countryKey;
                this._keys.StrKey = strKey;
                this._keys.PayKey = payKey;
            }
            return this._keys;
        };
        P2Sp2Sp3DataTable.prototype.InnerCopyData = function (recordKey, endYear) {
            if (this.Locate(this.RecordKey.Id, recordKey)) {
                this.IsCopied.Value = true;
                var copyData = this.CopyFieldsInfo;
                var keys = this.GetKeys();
                var parentTable = this.ParentTable;
                for (var year = keys.Year + 1; year <= endYear; year++) {
                    var ownerKey = parentTable.GetRecordKey(parentTable.GetKeys(keys.OrgKey, keys.CountryKey, year), true);
                    copyData.getValue(this.OwnerKey.Id).Value = ownerKey;
                    keys.Year = year;
                    this.SetupTableRecordData(copyData, this.Lookup([this.OwnerKey.Id, this.StrKeyField.Id, this.Payment.ForeignKey.Id], [ownerKey, keys.StrKey, keys.PayKey], this.RecordKey.Id), true);
                }
                this.RecordKey.Locate(recordKey);
            }
        };
        P2Sp2Sp3DataTable.prototype.InitCopyFieldsInfo = function () {
            var result = new collections.Dictionary();
            result.setValue(this.IsCopied.Id, {
                Id: this.IsCopied.Id,
                IsData: false
            });
            result.setValue(this.OwnerKey.Id, {
                Id: this.OwnerKey.Id,
                IsData: false
            });
            result.setValue(this.StrKeyField.Id, {
                Id: this.StrKeyField.Id,
                IsData: false
            });
            result.setValue(this.Payment.ForeignKey.Id, {
                Id: this.Payment.ForeignKey.Id,
                IsData: false
            });
            result.setValue(this.NpaType.ForeignKey.Id, {
                Id: this.NpaType.ForeignKey.Id,
                IsData: true
            });
            result.setValue("NpaDate", {
                Id: "NpaDate",
                IsData: true
            });
            result.setValue("NpaNumber", {
                Id: "NpaNumber",
                IsData: true
            });
            result.setValue("NpaName", {
                Id: "NpaName",
                IsData: true
            });
            result.setValue("NPAStatuses_ID", {
                Id: "NPAStatuses_ID",
                IsData: true
            });
            result.setValue("NpaChangeDate", {
                Id: "NpaChangeDate",
                IsData: true
            });
            result.setValue("g9", {
                Id: "g9",
                IsData: true
            });
            return result;
        };
        return P2Sp2Sp3DataTable;
    }(PxSpxSp3DataTable));
    F01285.P2Sp2Sp3DataTable = P2Sp2Sp3DataTable;
    var P3Sp2Sp3DataTable = (function (_super) {
        __extends(P3Sp2Sp3DataTable, _super);
        function P3Sp2Sp3DataTable() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Object.defineProperty(P3Sp2Sp3DataTable.prototype, "Post", {
            get: function () {
                return this.ParentTable.Post;
            },
            enumerable: true,
            configurable: true
        });
        P3Sp2Sp3DataTable.prototype.SumChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var parentTable = this.ParentTable;
            parentTable.SetSumByKeys(parentTable.AddFot.Id, parentTable.GetKeys(), oldValue, newValue);
        };
        P3Sp2Sp3DataTable.prototype.GetKeys = function (orgKey, countryKey, year, postKey, payKey) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (year === void 0) { year = this.Year.Value; }
            if (postKey === void 0) { postKey = this.Post.ForeignKey.Value; }
            if (payKey === void 0) { payKey = this.Payment.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new ObasTableOrgCountryYearPostPayKeys(orgKey, countryKey, year, postKey, payKey);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.Year = year;
                this._keys.CountryKey = countryKey;
                this._keys.PostKey = postKey;
                this._keys.PayKey = payKey;
            }
            return this._keys;
        };
        P3Sp2Sp3DataTable.prototype.InnerCopyData = function (recordKey, endYear) {
            if (this.Locate(this.RecordKey.Id, recordKey)) {
                this.IsCopied.Value = true;
                var copyData = this.CopyFieldsInfo;
                var keys = this.GetKeys();
                var parentTable = this.ParentTable;
                for (var year = keys.Year + 1; year <= endYear; year++) {
                    var ownerKey = parentTable.GetRecordKey(parentTable.GetKeys(keys.OrgKey, keys.CountryKey, year, keys.PostKey), true);
                    copyData.getValue(this.OwnerKey.Id).Value = ownerKey;
                    keys.Year = year;
                    this.SetupTableRecordData(copyData, this.RecordKey.LookupByKeys(keys.ToArray()), true);
                }
                this.RecordKey.Locate(recordKey);
            }
        };
        P3Sp2Sp3DataTable.prototype.InitCopyFieldsInfo = function () {
            var result = new collections.Dictionary();
            result.setValue(this.IsCopied.Id, {
                Id: this.IsCopied.Id,
                IsData: false
            });
            result.setValue(this.OwnerKey.Id, {
                Id: this.OwnerKey.Id,
                IsData: false
            });
            result.setValue(this.Payment.ForeignKey.Id, {
                Id: this.Payment.ForeignKey.Id,
                IsData: false
            });
            result.setValue(this.NpaType.ForeignKey.Id, {
                Id: this.NpaType.ForeignKey.Id,
                IsData: true
            });
            result.setValue("NpaDate", {
                Id: "NpaDate",
                IsData: true
            });
            result.setValue("NpaNumber", {
                Id: "NpaNumber",
                IsData: true
            });
            result.setValue("NpaName", {
                Id: "NpaName",
                IsData: true
            });
            result.setValue("NPAStatuses_ID", {
                Id: "NPAStatuses_ID",
                IsData: true
            });
            result.setValue("NpaChangeDate", {
                Id: "NpaChangeDate",
                IsData: true
            });
            result.setValue("g9", {
                Id: "g9",
                IsData: true
            });
            return result;
        };
        return P3Sp2Sp3DataTable;
    }(PxSpxSp3DataTable));
    F01285.P3Sp2Sp3DataTable = P3Sp2Sp3DataTable;
    var BaseOrgsTable = (function (_super) {
        __extends(BaseOrgsTable, _super);
        function BaseOrgsTable() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._org = null;
            _this._country = null;
            return _this;
        }
        Object.defineProperty(BaseOrgsTable.prototype, "Country", {
            get: function () {
                if (this._country == null) {
                    this._country = new ObasSprTableField(ObasTableCollection.OksmSprTable, this);
                }
                return this._country;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseOrgsTable.prototype, "Org", {
            get: function () {
                if (this._org == null) {
                    this._org = new ObasSprTableField(ObasTableCollection.OrganizationTable, this);
                }
                return this._org;
            },
            enumerable: true,
            configurable: true
        });
        BaseOrgsTable.prototype.CalcFilterKey = function () {
            return this.Country.ForeignKey.Value + "_" + this.Org.ForeignKey.Value;
        };
        return BaseOrgsTable;
    }(ObasTableWithKeys));
    F01285.BaseOrgsTable = BaseOrgsTable;
    var TableUniqueOrgs = (function (_super) {
        __extends(TableUniqueOrgs, _super);
        function TableUniqueOrgs(id, document) {
            var _this = _super.call(this, id, ["Organization_ID", "OKSM_ID"], document) || this;
            _this._childTableIds = [];
            return _this;
        }
        TableUniqueOrgs.prototype.GetKeys = function (orgKey, countryKey) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new OrgCountryObasTableKeys(orgKey, countryKey);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.CountryKey = countryKey;
            }
            return this._keys;
        };
        TableUniqueOrgs.prototype.AddChildTable = function (child) {
            var id = child.Id;
            if (this._childTableIds.indexOf(id) === -1) {
                this._childTableIds.push(child.Id);
            }
        };
        TableUniqueOrgs.prototype.AddOrg = function (orgKey, countryKey) {
            if (orgKey != null && countryKey != null) {
                this.Document.CommonRules.AddNewLink(this.Id, this.KeyFieldIds, [orgKey, countryKey]);
            }
        };
        TableUniqueOrgs.prototype.DeleteOrg = function (orgKey, countryKey) {
            this.Document.CommonRules.DeleteOldLink(this.Id, this._childTableIds, this.KeyFieldIds, [orgKey, countryKey]);
        };
        return TableUniqueOrgs;
    }(BaseOrgsTable));
    F01285.TableUniqueOrgs = TableUniqueOrgs;
    var OrgsTable = (function (_super) {
        __extends(OrgsTable, _super);
        function OrgsTable(id, _parent) {
            var _this = _super.call(this, id, ["Organization_ID", "OKSM_ID", "Year"], _parent.Document) || this;
            _this._parent = _parent;
            _this._year = null;
            _this._orgKey = null;
            _this._countryKey = null;
            _parent.AddChildTable(_this);
            return _this;
        }
        OrgsTable.prototype.UniqKeyChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var orgField = this.Org.ForeignKey;
            var countryField = this.Country.ForeignKey;
            var orgKey = orgField.Value;
            var countryKey = countryField.Value;
            var oldOrgKey = fieldId === orgField.Id ? oldValue : orgKey;
            var oldCountryKey = fieldId === countryField.Id ? oldValue : countryKey;
            this.AfterDeleteEventHandler(tableId, oldOrgKey, oldCountryKey);
            this._parent.AddOrg(orgKey, countryKey);
        };
        OrgsTable.prototype.DeleteEventHandler = function (tableId) {
            this._orgKey = this.Org.ForeignKey.Value;
            this._countryKey = this.Country.ForeignKey.Value;
        };
        OrgsTable.prototype.AfterDeleteEventHandler = function (tableId, orgKey, countryKey) {
            if (orgKey === void 0) { orgKey = this._orgKey; }
            if (countryKey === void 0) { countryKey = this._countryKey; }
            this._parent.DeleteOrg(orgKey, countryKey);
        };
        Object.defineProperty(OrgsTable.prototype, "Year", {
            get: function () {
                if (this._year == null) {
                    this._year = new NumberObasTableField(BaseObasTableFields.YearField.Id, this);
                }
                return this._year;
            },
            enumerable: true,
            configurable: true
        });
        OrgsTable.prototype.GetKeys = function (orgKey, countryKey, year) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (year === void 0) { year = this.Year.Value; }
            if (this._keys == null) {
                this._keys = new OrgCountryYearObasTableKeys(orgKey, countryKey, year);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.CountryKey = countryKey;
                this._keys.Year = year;
            }
            return this._keys;
        };
        OrgsTable.prototype.GetRecordKey = function (keys, addIfNotExists) {
            if (addIfNotExists === void 0) { addIfNotExists = false; }
            this.Document.CommonRules.GetValueByKeys(this, this.KeyFieldIds, keys.ToArray(), this.RecordKey.Id, addIfNotExists);
            return this.RecordKey.Value;
        };
        Object.defineProperty(OrgsTable.prototype, "UniqRecordKey", {
            get: function () {
                return this._parent.RecordKey.LookupByKeys(this._parent
                    .GetKeys(this.Org.ForeignKey.Value, this.Country.ForeignKey.Value)
                    .ToArray());
            },
            enumerable: true,
            configurable: true
        });
        return OrgsTable;
    }(BaseOrgsTable));
    F01285.OrgsTable = OrgsTable;
    var P2DataTable = (function (_super) {
        __extends(P2DataTable, _super);
        function P2DataTable(id, parent, _sumTable) {
            var _this = _super.call(this, id, parent.KeyFieldIds.concat(["PostName_ID"]), parent.Document, parent) || this;
            _this._sumTable = _sumTable;
            _this._org = null;
            _this._country = null;
            _this._year = null;
            _this._post = null;
            _this._usdFot = null;
            _this._rubFot = null;
            _this._isCopied = null;
            _this._copyData = null;
            return _this;
        }
        Object.defineProperty(P2DataTable.prototype, "CopyFieldsInfo", {
            get: function () {
                if (this._copyData == null) {
                    this._copyData = this.InitCopyFieldsInfo();
                }
                return this.CollectTableRecordData(this._copyData);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "IsCopied", {
            get: function () {
                if (this._isCopied == null) {
                    this._isCopied = new ObasTableField(BaseObasTableFields.CopiedRowFlagField.Id, this);
                }
                return this._isCopied;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "RubFot", {
            get: function () {
                if (this._rubFot == null) {
                    this._rubFot = new NumberObasTableField("RubFot", this);
                }
                return this._rubFot;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "UsdFot", {
            get: function () {
                if (this._usdFot == null) {
                    this._usdFot = new NumberObasTableField("UsdFot", this);
                }
                return this._usdFot;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "Post", {
            get: function () {
                if (this._post == null) {
                    this._post = new ObasSprTableField(this.Document.PostSprTable, this);
                }
                return this._post;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "Year", {
            get: function () {
                if (this._year == null) {
                    this._year = new NumberObasTableField(BaseObasTableFields.YearField.Id, this);
                }
                return this._year;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "Country", {
            get: function () {
                if (this._country == null) {
                    this._country = new ObasSprTableField(ObasTableCollection.OksmSprTable, this);
                }
                return this._country;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "Org", {
            get: function () {
                if (this._org == null) {
                    this._org = new ObasSprTableField(ObasTableCollection.OrganizationTable, this);
                }
                return this._org;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "YearOffset", {
            get: function () {
                return ObasHelper.GetYearOffset(this);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(P2DataTable.prototype, "ParentTable", {
            get: function () {
                return this.OwnerKey.SourceTable;
            },
            enumerable: true,
            configurable: true
        });
        P2DataTable.prototype.GetKeys = function (orgKey, countryKey, year, postKey) {
            if (orgKey === void 0) { orgKey = this.Org.ForeignKey.Value; }
            if (countryKey === void 0) { countryKey = this.Country.ForeignKey.Value; }
            if (year === void 0) { year = this.Year.Value; }
            if (postKey === void 0) { postKey = this.Post.ForeignKey.Value; }
            if (this._keys == null) {
                this._keys = new OrgCountryYearPostObasTableKeys(orgKey, countryKey, year, postKey);
            }
            else {
                this._keys.OrgKey = orgKey;
                this._keys.CountryKey = countryKey;
                this._keys.Year = year;
                this._keys.PositionKey = postKey;
            }
            return this._keys;
        };
        P2DataTable.prototype.CalcPercent = function (fieldId) {
            return (this.GetFieldValue(fieldId) || 0) / 100;
        };
        Object.defineProperty(P2DataTable.prototype, "CountMonth", {
            get: function () {
                return this.Document.CountMonthForCalcTable.GetCountMonthByYear(this.Year.Value);
            },
            enumerable: true,
            configurable: true
        });
        P2DataTable.prototype.CountMonthChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var countMonth = this.CountMonth;
            if (countMonth >= 0 && countMonth <= 12) {
                this.UsdPartsChangeEventHandler(tableId, oldValue, newValue, fieldId);
            }
            else {
                Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u043F\u043E\u043B\u044F \u00AB\u041A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E \u043C\u0435\u0441\u044F\u0446\u0435\u0432\u00BB \u0434\u043E\u043B\u0436\u043D\u043E \u043D\u0430\u0445\u043E\u0434\u0438\u0442\u044C\u0441\u044F \u0432 \u0434\u0438\u0430\u043F\u0430\u0437\u043E\u043D\u0435 \u043E\u0442 0 \u0434\u043E 12.", MessageIcons.Error);
                this.SetFieldValue("CountMonth", oldValue);
            }
        };
        P2DataTable.prototype.UsdPartsChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this.UsdFot.Value = this.CountMonth *
                this.GetFieldValue("g4") *
                this.GetFieldValue("g5") *
                (this.CalcPercent("g6") +
                    this.CalcPercent("g7") +
                    this.CalcPercent("g8") +
                    this.CalcPercent("g9") +
                    1);
        };
        P2DataTable.prototype.UsdChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this.RubFot.Value = newValue * this.Document.CommonRules.GetDollarRateByYear(this.Year.Value);
        };
        P2DataTable.prototype.RubChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            this._sumTable.SetSumByKeys(BaseObasTableFields.YearDataField.GenerateId(this.YearOffset + 1), this._sumTable.GetKeys(StrKeysPXSp2.Fot, this.ParentTable.UniqRecordKey), oldValue, newValue);
        };
        P2DataTable.prototype.AfterDeleteChildsEventHandler = function (tableId) {
            this.RubFot.Value = 0;
        };
        P2DataTable.prototype.InitCopyFieldsInfo = function () {
            var result = new collections.Dictionary();
            result.setValue(this.IsCopied.Id, {
                Id: this.IsCopied.Id,
                IsData: false
            });
            result.setValue(this.OwnerKey.Id, {
                Id: this.OwnerKey.Id,
                IsData: false
            });
            result.setValue(this.Post.ForeignKey.Id, {
                Id: this.Post.ForeignKey.Id,
                IsData: false
            });
            for (var i = 4; i < 10; i++) {
                result.setValue("g" + i, {
                    Id: "g" + i,
                    IsData: true
                });
            }
            return result;
        };
        P2DataTable.prototype.CollectUserData = function () {
            return this.CollectTableData(this.InitCopyFieldsInfo());
        };
        P2DataTable.prototype.ResetData = function (keys) {
            var _this = this;
            var resetHandler = function () {
                for (var i = 4; i < 10; i++) {
                    _this.SetFieldValue("g" + i, 0);
                }
                _this.UsdFot.Value = 0;
                _this.RubFot.Value = 0;
            };
            if (keys) {
                if (this.LocateByKeys(keys.ToArray())) {
                    resetHandler();
                }
            }
            else {
                this.Iterate(resetHandler);
            }
        };
        P2DataTable.prototype.CopyData = function (srcYear, destYear) {
            var _this = this;
            var endYear = ObasStageSettings.CurrentYear + ObasStageSettings.YearsCount;
            if (srcYear == null) {
                srcYear = endYear - 2;
            }
            if (destYear == null) {
                destYear = endYear - 1;
            }
            if (srcYear && destYear) {
                var copyHandler = function (table, recordKey) {
                    if (_this.Year.Value === srcYear) {
                        _this.InnerCopyData(recordKey, destYear);
                    }
                };
                this.Iterate(copyHandler);
            }
        };
        P2DataTable.prototype.InnerCopyData = function (recordKey, endYear) {
            if (this.Locate(this.RecordKey.Id, recordKey)) {
                this.IsCopied.Value = true;
                var copyData = this.CopyFieldsInfo;
                var keys = this.GetKeys();
                var ownerVal = copyData.getValue(this.OwnerKey.Id);
                for (var year = keys.Year + 1; year <= endYear; year++) {
                    keys.Year = year;
                    var ownerKey = this.ParentTable.GetRecordKey(this.ParentTable.GetKeys(keys.OrgKey, keys.CountryKey, year), true);
                    ownerVal.Value = ownerKey;
                    this.SetupTableRecordData(copyData, this.RecordKey.LookupByKeys(keys.ToArray()), true);
                }
                this.RecordKey.Locate(recordKey);
            }
        };
        P2DataTable.prototype.EditEventHandler = function (tableId) {
            if (this.Document.NotOnUpdate && !this.IsCopied.Value && this.IsRedyForCopy()) {
                this.InnerCopyData(this.RecordKey.Value, ObasStageSettings.CurrentYear + ObasStageSettings.YearsCount - 1);
            }
        };
        P2DataTable.prototype.IsRedyForCopy = function () {
            return ObasHelper.CheckIsReadyForCopy(this.CopyFieldsInfo);
        };
        return P2DataTable;
    }(ObasTableWithKeysParent));
    F01285.P2DataTable = P2DataTable;
    var TableNpa = (function (_super) {
        __extends(TableNpa, _super);
        function TableNpa(id, _document) {
            var _this = _super.call(this, id) || this;
            _this._document = _document;
            _this._salary = null;
            return _this;
        }
        Object.defineProperty(TableNpa.prototype, "Salary", {
            get: function () {
                if (this._salary == null) {
                    this._salary = new ObasSprTableField(this._document.SalarySprTable, this);
                }
                return this._salary;
            },
            enumerable: true,
            configurable: true
        });
        return TableNpa;
    }(NpaObasTable));
    F01285.TableNpa = TableNpa;
    var CountMonthForCalcTable = (function (_super) {
        __extends(CountMonthForCalcTable, _super);
        function CountMonthForCalcTable(id, _document) {
            var _this = _super.call(this, id) || this;
            _this._document = _document;
            return _this;
        }
        CountMonthForCalcTable.prototype.GetCountMonthByYear = function (year) {
            var yearOffset = year - ObasStageSettings.CurrentYear + 1;
            return this.GetFieldValue("CountMonthY" + yearOffset);
        };
        CountMonthForCalcTable.prototype.GetCountMonthByYearOffset = function (yearOffset) {
            return this.GetFieldValue("CountMonthY" + yearOffset);
        };
        CountMonthForCalcTable.prototype.CountMonthChangeEventHandler = function (tableId, oldValue, newValue, fieldId) {
            var countMonth = this.GetFieldValue(fieldId);
            if (countMonth >= 0 && countMonth <= 12) {
                var year = ObasStageSettings.CurrentYear + ObasHelper.GetYearOffsetById(fieldId);
                var p2DataTable = this._document.P2DataTable;
                while (p2DataTable.Locate(p2DataTable.Year.Id, year, true)) {
                    p2DataTable.SetFieldValue("CountMonth", countMonth);
                }
                p2DataTable.ClearLocateFlag();
                var p3DataTable = this._document.P3DataTable;
                while (p3DataTable.Locate(p3DataTable.Year.Id, year, true)) {
                    p3DataTable.SetFieldValue("CountMonth", countMonth);
                }
                p3DataTable.ClearLocateFlag();
            }
            else {
                Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u043F\u043E\u043B\u044F \u00AB\u041A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E \u043C\u0435\u0441\u044F\u0446\u0435\u0432\u00BB \u0434\u043E\u043B\u0436\u043D\u043E \u043D\u0430\u0445\u043E\u0434\u0438\u0442\u044C\u0441\u044F \u0432 \u0434\u0438\u0430\u043F\u0430\u0437\u043E\u043D\u0435 \u043E\u0442 0 \u0434\u043E 12.", MessageIcons.Error);
                this.SetFieldValue(fieldId, oldValue);
            }
        };
        return CountMonthForCalcTable;
    }(SprTable));
    F01285.CountMonthForCalcTable = CountMonthForCalcTable;
})(F01285 || (F01285 = {}));
