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 FDocument = (function (_super) {
        __extends(FDocument, _super);
        function FDocument(id, version, oldVersion) {
            var _this = _super.call(this, id, version, oldVersion) || this;
            _this._p1TotalTable = null;
            _this._pnoDataTable = null;
            _this._purchaseObjectsSprTable = null;
            _this._recipientsDataTable = null;
            _this._analyticsDataTable = null;
            _this._analyticSheet = null;
            _this._p2RefObjTable = null;
            _this._p2RefOkpdTable = null;
            _this._p2RefKosguTable = null;
            _this._p3RefObjDescTable = null;
            _this._p3RefObjDescNpaTable = null;
            _this._p4NpaTable = null;
            _this._importedProcurementTable = null;
            _this._p1Sheet = null;
            _this._p2Sheet = null;
            _this._addYearsHelper = null;
            _this._tableRules = new F03310.TableRules(_this);
            _this._interfaceRules = new F03310.InterfaceRules(_this);
            _this._updateRules = new F03310.UpdateRules(_this);
            _this._exportRules = new F03310.ExportRules(_this);
            _this._addDataYearsCount = 1;
            _this._mainDataYearsCount = ObasStageSettings.YearsCount;
            return _this;
        }
        Object.defineProperty(FDocument.prototype, "AddYearsHelper", {
            get: function () {
                if (this._addYearsHelper == null) {
                    this._addYearsHelper = new F03310.AddYearsHelper(this);
                }
                return this._addYearsHelper;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P1TotalTable", {
            get: function () {
                if (this._p1TotalTable == null) {
                    this._p1TotalTable = new F03310.FObasTableP1Total("F03_310_R1_Values", this);
                }
                return this._p1TotalTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "PurchaseObjectsSprTable", {
            get: function () {
                if (this._purchaseObjectsSprTable == null) {
                    this._purchaseObjectsSprTable = new SprTable("PurchaseObjects");
                }
                return this._purchaseObjectsSprTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "PnoDataTable", {
            get: function () {
                if (this._pnoDataTable == null) {
                    this._pnoDataTable = new F03310.PnoDataTable("F03_310_R2_PNO", this);
                }
                return this._pnoDataTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "RecipientsDataTable", {
            get: function () {
                if (this._recipientsDataTable == null) {
                    this._recipientsDataTable = new F03310.RecipientsDataTable("F03_310_R2_RecipientCategory", this.PnoDataTable, this.P4NpaTable);
                }
                return this._recipientsDataTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P2RefObjTable", {
            get: function () {
                if (this._p2RefObjTable == null) {
                    this._p2RefObjTable = new F03310.PartObjectDataTable("F03_310_R2_Ref_Object", this, this.RecipientsDataTable, this.P3RefObjDescTable);
                }
                return this._p2RefObjTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P2RefOkpdTable", {
            get: function () {
                if (this._p2RefOkpdTable == null) {
                    this._p2RefOkpdTable = new F03310.PartOkpdTable("F03_310_R2_Ref_Okpd", this, this.P2RefObjTable);
                }
                return this._p2RefOkpdTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P2RefKosguTable", {
            get: function () {
                if (this._p2RefKosguTable == null) {
                    this._p2RefKosguTable = new F03310.PartKosguTable("F03_310_R2_Ref_Kosgu", this, this.P2RefOkpdTable);
                }
                return this._p2RefKosguTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P3RefObjDescTable", {
            get: function () {
                if (this._p3RefObjDescTable == null) {
                    this._p3RefObjDescTable = new F03310.ObjectDescTable("F03_310_R3_Ref_ObjectDesc", this);
                }
                return this._p3RefObjDescTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P3RefObjDescNpaTable", {
            get: function () {
                if (this._p3RefObjDescNpaTable == null) {
                    this._p3RefObjDescNpaTable = new F03310.ObjectDescNpaTable("F03_310_R3_Ref_Npa", this, this.P3RefObjDescTable);
                }
                return this._p3RefObjDescNpaTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P4NpaTable", {
            get: function () {
                if (this._p4NpaTable == null) {
                    this._p4NpaTable = new F03310.NpaTable("F03_310_4", this);
                }
                return this._p4NpaTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "ImportedProcurementTable", {
            get: function () {
                if (this._importedProcurementTable == null) {
                    this._importedProcurementTable = new F03310.ImportedProcurementTable();
                }
                return this._importedProcurementTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P1Sheet", {
            get: function () {
                if (this._p1Sheet == null) {
                    this._p1Sheet = new F03310.P1Sheet("SHT_F03_310_R1", this);
                }
                return this._p1Sheet;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "P2Sheet", {
            get: function () {
                if (this._p2Sheet == null) {
                    this._p2Sheet = new F03310.PurchaseObjectHierarchySheet(this);
                }
                return this._p2Sheet;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "AnalyticsDataTable", {
            get: function () {
                if (this._analyticsDataTable == null) {
                    this._analyticsDataTable = new AnalyticsKosgu.AnalyticsDataTable("AnalyticsData", this);
                }
                return this._analyticsDataTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "AnalyticSheet", {
            get: function () {
                if (this._analyticSheet == null) {
                    this._analyticSheet = new AnalyticsKosgu.AnalyticsSheet("SHT_RA", this);
                }
                return this._analyticSheet;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "TotalTable", {
            get: function () {
                return this.P1TotalTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "AddDataYearsCount", {
            get: function () {
                return this._addDataYearsCount;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "MainDataYearsCount", {
            get: function () {
                return this._mainDataYearsCount;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "TableRules", {
            get: function () {
                return this._tableRules;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "InterfaceRules", {
            get: function () {
                return this._interfaceRules;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "UpdateRules", {
            get: function () {
                return this._updateRules;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(FDocument.prototype, "ExportRules", {
            get: function () {
                return this._exportRules;
            },
            enumerable: true,
            configurable: true
        });
        FDocument.prototype.ObjectDataTableIds = function () {
            return ["F03_310_R2_Ref_Object"];
        };
        FDocument.prototype.SaveTotalTableAndPartIndicateBudgetTables = function (tableId) {
            this.CommonRules.SaveTotalTable(tableId);
            var data = [];
            var kosguKeys = [];
            var yearField = F03310.ObasTableFields.R4YearField;
            var yearsCnt = ObasStageSettings.YearsCount;
            var reader = this.P2RefKosguTable.CreateReader();
            while (reader.Read()) {
                var record = {
                    Key: reader.GetFieldValue("KOSGU_Id"),
                    Data: []
                };
                if (kosguKeys.indexOf(record.Key) > -1) {
                    record = data[kosguKeys.indexOf(record.Key)];
                    for (var i = 0; i < yearsCnt; i++) {
                        record.Data[i] = record.Data[i] + reader.GetFieldValue(yearField.GenerateId(i + 1)) || 0;
                    }
                }
                else {
                    kosguKeys.push(record.Key);
                    for (var i = 0; i < yearsCnt; i++) {
                        record.Data[i] = reader.GetFieldValue(yearField.GenerateId(i + 1)) || 0;
                    }
                    data.push(record);
                }
            }
            Client.SendMessage(Client.MainDocumentId, "%Doc%.TableRules.UpdateRROIndicateBudget", [this.FileType, this.ObasVersion, data]);
        };
        return FDocument;
    }(BaseDocumentObject));
    F03310.FDocument = FDocument;
})(F03310 || (F03310 = {}));
