var F01280;
(function (F01280) {
    var UpdateRules = (function () {
        function UpdateRules(_document) {
            this._document = _document;
        }
        UpdateRules.prototype.UpdateTemplate = function (oldVersion, currentVersion) {
            this._document.StartUpdate();
            if (oldVersion < "5.0.0" && currentVersion >= "5.0.0") {
                this.UpdateDocTo5();
                this.ShiftData();
                this.CopyData();
            }
            if (oldVersion < "5.1.8" && currentVersion >= "5.1.8") {
                this.RecalcData();
            }
            if (oldVersion < "6.0.0" && currentVersion >= "6.0.0") {
                this.ShiftData();
                this.CopyData();
                this.RecalcData();
            }
            if (oldVersion < "6.1.0" && currentVersion >= "6.1.0") {
                this.ShiftData();
                this.CopyData();
                this.RecalcData();
            }
            this._document.EndUpdate();
        };
        UpdateRules.prototype.RecalcDataP1Total = function () {
            var curState = new UpdateDocSettingsState(this._document);
            this._document.StartUpdate();
            var p1Table = this._document.TableP1;
            var p1Data = p1Table.CollectUserData();
            p1Table.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            p1Table.SetupTableData(p1Data);
            this._document.EndUpdate();
            curState.RestoreState();
        };
        UpdateRules.prototype.RecalcDataPInsOnly = function () {
            var curState = new UpdateDocSettingsState(this._document);
            this._document.StartUpdate();
            var pInsTable = this._document.TableFormInsurValues;
            var totalTable = this._document.TableP1;
            var pInsData = pInsTable.CollectUserData();
            totalTable.SaveCorrectionData();
            totalTable.ResetData();
            pInsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            totalTable.RestoreCorrectionData();
            pInsTable.SetupTableData(pInsData);
            pInsData = null;
            this._document.EndUpdate();
            curState.RestoreState();
        };
        UpdateRules.prototype.RecalcDataP2 = function () {
            var curState = new UpdateDocSettingsState(this._document);
            this._document.StartUpdate();
            var p2Sp1Table = this._document.TableP2Sp1;
            var p2Sp1TotalTable = this._document.TableP2Sp1Total;
            var p2SpIndexTable = this._document.TableP2SpIndexation;
            var p2Sp3Table = this._document.TableP2Sp3;
            var p2SpInsTable = this._document.TableP2SpInsurance;
            var p2SpWritsTable = this._document.TableP2SpExecWrits;
            var p2Sp6Table = this._document.TableP2Sp6;
            var p2Sp1Data = p2Sp1Table.CollectUserData();
            var p2Sp1TotalData = p2Sp1TotalTable.CollectUserData();
            var p2SpIndexData = p2SpIndexTable.CollectUserData();
            var p2Sp3Data = p2Sp3Table.CollectUserData();
            var p2SpInsData = p2SpInsTable.CollectUserData();
            var p2SpWritsData = p2SpWritsTable.CollectUserData();
            var p2Sp6Data = p2Sp6Table.CollectUserData();
            p2Sp1Table.ResetData();
            p2Sp1TotalTable.ResetData();
            this._document.TableP2Sp2.ResetData();
            p2SpIndexTable.ResetData();
            p2Sp3Table.ResetData();
            p2SpInsTable.ResetData();
            p2SpWritsTable.ResetData();
            p2Sp6Table.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            p2Sp1TotalTable.SetupTableData(p2Sp1TotalData);
            p2Sp1TotalData = null;
            p2Sp1Table.SetupTableData(p2Sp1Data);
            p2Sp1Data = null;
            p2SpIndexTable.SetupTableData(p2SpIndexData);
            p2SpIndexData = null;
            p2Sp3Table.SetupTableData(p2Sp3Data);
            p2Sp3Data = null;
            p2SpInsTable.SetupTableData(p2SpInsData);
            p2SpInsData = null;
            p2SpWritsTable.SetupTableData(p2SpWritsData);
            p2SpWritsData = null;
            p2Sp6Table.SetupTableData(p2Sp6Data);
            p2Sp6Data = null;
            this._document.EndUpdate();
            curState.RestoreState();
        };
        UpdateRules.prototype.RecalcDataP3 = function () {
            var curState = new UpdateDocSettingsState(this._document);
            this._document.StartUpdate();
            var p3Sp1Table = this._document.TableP3Sp1;
            var p3Sp1TotalTable = this._document.TableP3Sp1Total;
            var p3SpIndexTable = this._document.TableP3SpIndexation;
            var p3Sp3Table = this._document.TableP3Sp3;
            var p3SpInsTable = this._document.TableP3SpInsurance;
            var p3SpWritsTable = this._document.TableP3SpExecWrits;
            var p3Sp1Data = p3Sp1Table.CollectUserData();
            var p3Sp1TotalData = p3Sp1TotalTable.CollectUserData();
            var p3SpIndexData = p3SpIndexTable.CollectUserData();
            var p3Sp3Data = p3Sp3Table.CollectUserData();
            var p3SpInsData = p3SpInsTable.CollectUserData();
            var p3SpWritsData = p3SpWritsTable.CollectUserData();
            p3Sp1Table.ResetData();
            p3Sp1TotalTable.ResetData();
            this._document.TableP3Sp2.ResetData();
            p3SpIndexTable.ResetData();
            p3Sp3Table.ResetData();
            p3SpInsTable.ResetData();
            p3SpWritsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            p3Sp1TotalTable.SetupTableData(p3Sp1TotalData);
            p3Sp1TotalData = null;
            p3Sp1Table.SetupTableData(p3Sp1Data);
            p3Sp1Data = null;
            p3SpIndexTable.SetupTableData(p3SpIndexData);
            p3SpIndexData = null;
            p3Sp3Table.SetupTableData(p3Sp3Data);
            p3Sp3Data = null;
            p3SpInsTable.SetupTableData(p3SpInsData);
            p3SpInsData = null;
            p3SpWritsTable.SetupTableData(p3SpWritsData);
            p3SpWritsData = null;
            this._document.EndUpdate();
            curState.RestoreState();
        };
        UpdateRules.prototype.RecalcDataP4 = function () {
            var curState = new UpdateDocSettingsState(this._document);
            this._document.StartUpdate();
            var p4Sp1Table = this._document.TableP4Sp1;
            var p4Sp1TotalTable = this._document.TableP4Sp1Total;
            var p4Sp3Table = this._document.TableP4Sp3;
            var p4SpInsTable = this._document.TableP4SpInsurance;
            var p4SpWritsTable = this._document.TableP4SpExecWrits;
            var p4Sp1Data = p4Sp1Table.CollectUserData();
            var p4Sp1TotalData = p4Sp1TotalTable.CollectUserData();
            var p4Sp3Data = p4Sp3Table.CollectUserData();
            var p4SpInsData = p4SpInsTable.CollectUserData();
            var p4SpWritsData = p4SpWritsTable.CollectUserData();
            p4Sp1Table.ResetData();
            p4Sp1TotalTable.ResetData();
            this._document.TableP4Sp2.ResetData();
            this._document.TableP4SpIndexation.ResetData();
            p4Sp3Table.ResetData();
            p4SpInsTable.ResetData();
            p4SpWritsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            p4Sp1TotalTable.SetupTableData(p4Sp1TotalData);
            p4Sp1TotalData = null;
            p4Sp1Table.SetupTableData(p4Sp1Data);
            p4Sp1Data = null;
            p4Sp3Table.SetupTableData(p4Sp3Data);
            p4Sp3Data = null;
            p4SpInsTable.SetupTableData(p4SpInsData);
            p4SpInsData = null;
            p4SpWritsTable.SetupTableData(p4SpWritsData);
            p4SpWritsData = null;
            this._document.EndUpdate();
            curState.RestoreState();
        };
        UpdateRules.prototype.RecalcDataP5 = function () {
            var curState = new UpdateDocSettingsState(this._document);
            this._document.StartUpdate();
            var p5Sp1Table = this._document.TableP5Sp1;
            var p5Sp1TotalTable = this._document.TableP5Sp1Total;
            var p5SpIndexTable = this._document.TableP5SpIndexation;
            var p5Sp3Table = this._document.TableP5Sp3;
            var p5SpInsTable = this._document.TableP5SpInsurance;
            var p5SpWritsTable = this._document.TableP5SpExecWrits;
            var p5Sp1Data = p5Sp1Table.CollectUserData();
            var p5Sp1TotalData = p5Sp1TotalTable.CollectUserData();
            var p5SpIndexData = p5SpIndexTable.CollectUserData();
            var p5Sp3Data = p5Sp3Table.CollectUserData();
            var p5SpInsData = p5SpInsTable.CollectUserData();
            var p5SpWritsData = p5SpWritsTable.CollectUserData();
            p5Sp1Table.ResetData();
            p5Sp1TotalTable.ResetData();
            this._document.TableP5Sp2.ResetData();
            p5SpIndexTable.ResetData();
            p5Sp3Table.ResetData();
            p5SpInsTable.ResetData();
            p5SpWritsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            p5Sp1TotalTable.SetupTableData(p5Sp1TotalData);
            p5Sp1TotalData = null;
            p5Sp1Table.SetupTableData(p5Sp1Data);
            p5Sp1Data = null;
            p5SpIndexTable.SetupTableData(p5SpIndexData);
            p5SpIndexData = null;
            p5Sp3Table.SetupTableData(p5Sp3Data);
            p5Sp3Data = null;
            p5SpInsTable.SetupTableData(p5SpInsData);
            p5SpInsData = null;
            p5SpWritsTable.SetupTableData(p5SpWritsData);
            p5SpWritsData = null;
            this._document.EndUpdate();
            curState.RestoreState();
        };
        UpdateRules.prototype.RecalcData = function () {
            this.RecalcDataPInsOnly();
            this.RecalcDataP2();
            this.RecalcDataP3();
            this.RecalcDataP4();
            this.RecalcDataP5();
        };
        UpdateRules.prototype.CopyData = function (srcYear, destYear) {
            this._document.TableP2Sp1.CopyData();
            this._document.TableP3Sp1.CopyData();
            this._document.TableP4Sp1.CopyData();
            this._document.TableP5Sp1.CopyData();
            this._document.TableP2Sp1Total.CopyData();
            this._document.TableP3Sp1Total.CopyData();
            this._document.TableP4Sp1Total.CopyData();
            this._document.TableP5Sp1Total.CopyData();
            this._document.TableP2SpIndexation.CopyData();
            this._document.TableP3SpIndexation.CopyData();
            this._document.TableP5SpIndexation.CopyData();
            this._document.TableP2SpExecWrits.CopyData();
            this._document.TableP3SpExecWrits.CopyData();
            this._document.TableP4SpExecWrits.CopyData();
            this._document.TableP5SpExecWrits.CopyData();
            this._document.TableP2SpInsurance.CopyData();
            this._document.TableP3SpInsurance.CopyData();
            this._document.TableP4SpInsurance.CopyData();
            this._document.TableP5SpInsurance.CopyData();
            this._document.TableFormInsurValues.CopyData();
            this._document.TableP2Sp3.CopyData();
            this._document.TableP2Sp6.CopyData();
            this._document.TableP3Sp3.CopyData();
            this._document.TableP4Sp3.CopyData();
            this._document.TableP5Sp3.CopyData();
        };
        UpdateRules.prototype.ShiftData = function () {
            var totalSrcField = [];
            var totalDestField = [];
            var insSrcField = [];
            var insDestField = [];
            var pXSp2SrcField = [];
            var pXSp2DestField = [];
            var pXSpInsSrcField = [];
            var pXSpInsDestField = [];
            var writsSrcField = [];
            var writsDestField = [];
            var p2Sp6SrcField = [];
            var p2Sp6DestField = [];
            var yearDataField = BaseObasTableFields.YearDataField;
            var yearUsdDataField = BaseObasTableFields.UsdYearDataField;
            var yearFotDataField = BaseObasTableFields.FotYearDataField;
            var yearInsDataField = BaseObasTableFields.InsuranceYearDataField;
            var yearFotRubDataField = F01280.ObasTableFields.FotRubYearDataField;
            var yearFotUsdDataField = F01280.ObasTableFields.FotUsdYearDataField;
            var taxDataField = BaseObasTableFields.TaxYearDataField;
            var cntDataField = BaseObasTableFields.CountYearDataField;
            for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                totalDestField.push(yearDataField.GenerateId(i));
                totalDestField.push(yearFotDataField.GenerateId(i));
                totalDestField.push(yearInsDataField.GenerateId(i));
                totalDestField.push(yearFotRubDataField.GenerateId(i));
                totalDestField.push(yearFotUsdDataField.GenerateId(i));
                pXSp2DestField.push(yearDataField.GenerateId(i));
                pXSpInsDestField.push(yearDataField.GenerateId(i));
                pXSpInsDestField.push(yearFotDataField.GenerateId(i));
                pXSpInsDestField.push(taxDataField.GenerateId(i));
                pXSpInsDestField.push(cntDataField.GenerateId(i));
                insDestField.push(yearDataField.GenerateId(i));
                insDestField.push(taxDataField.GenerateId(i));
                writsDestField.push(yearDataField.GenerateId(i));
                writsDestField.push(yearUsdDataField.GenerateId(i));
                p2Sp6DestField.push(yearDataField.GenerateId(i));
                p2Sp6DestField.push(cntDataField.GenerateId(i));
                if (i === ObasStageSettings.YearsCount) {
                    totalSrcField.push(null);
                    totalSrcField.push(null);
                    totalSrcField.push(null);
                    totalSrcField.push(null);
                    totalSrcField.push(null);
                    pXSp2SrcField.push(null);
                    pXSpInsSrcField.push(null);
                    pXSpInsSrcField.push(null);
                    pXSpInsSrcField.push(null);
                    pXSpInsSrcField.push(null);
                    insSrcField.push(null);
                    insSrcField.push(null);
                    writsSrcField.push(null);
                    writsSrcField.push(null);
                    p2Sp6SrcField.push(null);
                    p2Sp6SrcField.push(null);
                }
                else {
                    totalSrcField.push(yearDataField.GenerateId(i + 1));
                    totalSrcField.push(yearFotDataField.GenerateId(i + 1));
                    totalSrcField.push(yearInsDataField.GenerateId(i + 1));
                    totalSrcField.push(yearFotRubDataField.GenerateId(i + 1));
                    totalSrcField.push(yearFotUsdDataField.GenerateId(i + 1));
                    pXSp2SrcField.push(yearDataField.GenerateId(i + 1));
                    pXSpInsSrcField.push(yearDataField.GenerateId(i + 1));
                    pXSpInsSrcField.push(yearFotDataField.GenerateId(i + 1));
                    pXSpInsSrcField.push(taxDataField.GenerateId(i + 1));
                    pXSpInsSrcField.push(cntDataField.GenerateId(i + 1));
                    insSrcField.push(yearDataField.GenerateId(i + 1));
                    insSrcField.push(taxDataField.GenerateId(i + 1));
                    writsSrcField.push(yearDataField.GenerateId(i + 1));
                    writsSrcField.push(yearUsdDataField.GenerateId(i + 1));
                    p2Sp6SrcField.push(yearDataField.GenerateId(i + 1));
                    p2Sp6SrcField.push(cntDataField.GenerateId(i + 1));
                }
            }
            this._document.CommonRules.ShiftTableData(this._document.TableP1, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableFormInsurValues, insSrcField, insDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP2Sp1, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP2Sp1Total, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP2Sp2, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document
                .TableP2SpIndexation, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP2Sp6, p2Sp6SrcField, p2Sp6DestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP2SpInsurance, pXSpInsSrcField, pXSpInsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP2SpExecWrits, writsSrcField, writsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP3Sp1, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP3Sp1Total, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP3Sp2, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document
                .TableP3SpIndexation, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP3SpInsurance, pXSpInsSrcField, pXSpInsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP3SpExecWrits, writsSrcField, writsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP4Sp1, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP4Sp1Total, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP4Sp2, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document
                .TableP4SpIndexation, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP4SpInsurance, pXSpInsSrcField, pXSpInsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP4SpExecWrits, writsSrcField, writsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP5Sp1, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP5Sp1Total, totalSrcField, totalDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP5Sp2, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document
                .TableP5SpIndexation, pXSp2SrcField, pXSp2DestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP5SpInsurance, pXSpInsSrcField, pXSpInsDestField);
            this._document.CommonRules.ShiftTableData(this._document.TableP5SpExecWrits, writsSrcField, writsDestField);
            var yearFilter = function (table) {
                return table.GetFieldValue(BaseObasTableFields.YearField.Id) < ObasStageSettings.CurrentYear;
            };
            this._document.TableP2YearUniqOrgs.DeleteAllRow(yearFilter);
            this._document.TableP3YearUniqOrgs.DeleteAllRow(yearFilter);
            this._document.TableP4YearUniqOrgs.DeleteAllRow(yearFilter);
            this._document.TableP5YearUniqOrgs.DeleteAllRow(yearFilter);
        };
        UpdateRules.prototype.UpdateDocTo5 = function () {
            var tablesCanChange = this._document.EnableRulesAndNotice;
            this._document.EnableRulesAndNotice = false;
            this._document.CommonRules.CopyTableRows("Organizations", ObasTableCollection.OrganizationTable, true);
            this._document.DeleteTemporaryTable("Organizations");
            this.UpdatePartUniqueOrgsTo5("F01_280_r2_UniqueOrgs", this._document.TableP2UniqOrgs);
            this.UpdateYearPartUniqueOrgsTo5("F01_280_r2_2", this._document.TableP2YearUniqOrgs);
            this.UpdateP2Sp3To5();
            this.UpdateP2Sp6To5();
            this.UpdateSpLastTo5(2, this._document.TableP2SpExecWrits);
            this.UpdatePartUniqueOrgsTo5("F01_280_r3_UniqueOrgs", this._document.TableP3UniqOrgs);
            this.UpdateYearPartUniqueOrgsTo5("F01_280_r3_2", this._document.TableP3YearUniqOrgs);
            this.UpdateP3Sp3To5();
            this.UpdateSpLastTo5(3, this._document.TableP3SpExecWrits);
            this.UpdatePartUniqueOrgsTo5("F01_280_r4_UniqueOrgs", this._document.TableP4UniqOrgs);
            this.UpdateYearPartUniqueOrgsTo5("F01_280_r4_2", this._document.TableP4YearUniqOrgs);
            this.UpdateP4Sp3To5();
            this.UpdateSpLastTo5(4, this._document.TableP4SpExecWrits);
            this.UpdatePartUniqueOrgsTo5("F01_280_r5_UniqueOrgs", this._document.TableP5UniqOrgs);
            this.UpdateYearPartUniqueOrgsTo5("F01_280_r5_2", this._document.TableP5YearUniqOrgs);
            this.UpdateP5Sp3To5();
            this.UpdateSpLastTo5(5, this._document.TableP5SpExecWrits);
            this.UpdateInsTo5(this._document.TableP2SpInsurance);
            this.UpdateInsTo5(this._document.TableP3SpInsurance);
            this.UpdateInsTo5(this._document.TableP4SpInsurance);
            this.UpdateInsTo5(this._document.TableP5SpInsurance);
            this.UpdateInsTo5(this._document.TableFormInsurValues);
            this._document.EnableRulesAndNotice = tablesCanChange;
        };
        UpdateRules.prototype.UpdateYearPartUniqueOrgsTo5 = function (oldTableId, destTable) {
            var mapping = {
                FieldsMapping: [
                    {
                        SrcFieldId: "g1",
                        DestFieldId: destTable.Country.ForeignKey.Id
                    },
                    {
                        SrcFieldId: "g2",
                        DestFieldId: destTable.Org.ForeignKey.Id
                    }
                ],
                CopyExistsFields: true
            };
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
        };
        UpdateRules.prototype.UpdatePartUniqueOrgsTo5 = function (oldTableId, destTable) {
            var mapping = {
                FieldsMapping: [
                    {
                        SrcFieldId: "Country_Key",
                        DestFieldId: destTable.Country.ForeignKey.Id
                    },
                    {
                        SrcFieldId: "Org_Key",
                        DestFieldId: destTable.Org.ForeignKey.Id
                    }
                ],
                CopyExistsFields: true
            };
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
        };
        UpdateRules.prototype.UpdateP2Sp3To5 = function () {
            var destTable = this._document.TableP2Sp3;
            var oldTableId = "F01_280_r2_2_PosInfo";
            var mapping = {
                FieldsMapping: [
                    {
                        SrcFieldId: "F01_280_r2_2_Key",
                        DestFieldId: destTable.OwnerKeyField.Id
                    },
                    {
                        SrcFieldId: "g3",
                        DestFieldId: destTable.PositionKey.Id
                    },
                    {
                        SrcFieldId: "g4",
                        DestFieldId: destTable.UsdEmplCountField.Id
                    },
                    {
                        SrcFieldId: "g9",
                        DestFieldId: destTable.UsdData.Id
                    },
                    {
                        SrcFieldId: "g10",
                        DestFieldId: destTable.UsdFotData.Id
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldUsd.Id,
                        Value: true
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldRub.Id,
                        Value: true
                    }
                ],
                CopyExistsFields: true
            };
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
        };
        UpdateRules.prototype.UpdateP2Sp6To5 = function () {
            var destTable = this._document.TableP2Sp6;
            var oldTableId = "F01_280_r2_5";
            var fieldsMap = [
                {
                    SrcFieldId: "F01_280_r2_UO_key",
                    DestFieldId: destTable.OrgKeyField.Id
                },
                {
                    SrcFieldId: "Pos_ID",
                    DestFieldId: destTable.PositionKeyField.Id
                }
            ];
            var countField = BaseObasTableFields.CountYearDataField;
            var yearField = BaseObasTableFields.YearDataField;
            for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                fieldsMap.push({
                    SrcFieldId: "g" + i + "r2_5",
                    DestFieldId: countField.GenerateId(i)
                });
                fieldsMap.push({
                    SrcFieldId: "g" + (i + 5) + "r2_5",
                    DestFieldId: yearField.GenerateId(i)
                });
            }
            var mapping = {
                FieldsMapping: fieldsMap,
                CopyExistsFields: true
            };
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
        };
        UpdateRules.prototype.UpdateP3Sp3To5 = function () {
            var destTable = this._document.TableP3Sp3;
            var mapping = {
                FieldsMapping: [
                    {
                        SrcFieldId: "F01_280_r3_2_Key",
                        DestFieldId: destTable.OwnerKeyField.Id
                    },
                    {
                        SrcFieldId: "Post_Key",
                        DestFieldId: destTable.PositionKey.Id
                    },
                    {
                        SrcFieldId: "g6",
                        DestFieldId: destTable.UsdEmplCountField.Id
                    },
                    {
                        SrcFieldId: "g12",
                        DestFieldId: destTable.UsdData.Id
                    },
                    {
                        SrcFieldId: "g13",
                        DestFieldId: destTable.UsdFotData.Id
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldUsd.Id,
                        Value: true
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldRub.Id,
                        Value: true
                    }
                ],
                CopyExistsFields: true
            };
            var oldTableId = "F01_280_r3_2_PosInfo";
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
            var keyFields = [destTable.OwnerKeyField.Id, destTable.PositionKey.Id];
            var oldP3Sp7 = this._document.Tables.getValue("F01_280_R3_6");
            var copySp7Handler = function (table, recordKey) {
                var orgKey = table.GetFieldValue("F01_280_r3_2_key");
                var postKey = table.GetFieldValue("Post_Key");
                if (destTable.Locate(keyFields, [orgKey, postKey])) {
                    destTable.SetFieldValue("g8_3_7", table.GetFieldValue("g8"));
                    destTable.SetFieldValue("g9_3_7", table.GetFieldValue("g9"));
                    destTable.SetFieldValue("g14_3_7", table.GetFieldValue("g14"));
                    destTable.SetFieldValue("g15_3_7", table.GetFieldValue("g15"));
                    destTable.SetFieldValue("g16_3_7", table.GetFieldValue("g16"));
                }
            };
            oldP3Sp7.Iterate(copySp7Handler);
            this._document.DeleteTemporaryTable(oldP3Sp7);
            var oldP3Sp8 = this._document.Tables.getValue("F01_280_R3_7");
            var copySp8Handler = function (table, recordKey) {
                var orgKey = table.GetFieldValue("F01_280_r3_2_key");
                var postKey = table.GetFieldValue("Post_Key");
                if (destTable.Locate(keyFields, [orgKey, postKey])) {
                    for (var i = 7; i < 17; i++) {
                        destTable.SetFieldValue("g" + i + "_3_8", table.GetFieldValue("g" + (i - 1)));
                    }
                    destTable.RubFotData.Value = table.GetFieldValue("g16");
                }
            };
            oldP3Sp8.Iterate(copySp8Handler);
            this._document.DeleteTemporaryTable(oldP3Sp8);
        };
        UpdateRules.prototype.UpdateP4Sp3To5 = function () {
            var destTable = this._document.TableP4Sp3;
            var mapping = {
                FieldsMapping: [
                    {
                        SrcFieldId: "F01_280_r4_2_Key",
                        DestFieldId: destTable.OwnerKeyField.Id
                    },
                    {
                        SrcFieldId: "g3",
                        DestFieldId: destTable.PositionKey.Id
                    },
                    {
                        SrcFieldId: "g4",
                        DestFieldId: destTable.UsdEmplCountField.Id
                    },
                    {
                        SrcFieldId: "g8",
                        DestFieldId: destTable.UsdData.Id
                    },
                    {
                        SrcFieldId: "g9",
                        DestFieldId: destTable.UsdFotData.Id
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldUsd.Id,
                        Value: true
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldRub.Id,
                        Value: true
                    }
                ],
                CopyExistsFields: true
            };
            var oldTableId = "F01_280_r4_2_PosInfo";
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
            var keyFields = [destTable.OwnerKeyField.Id, destTable.PositionKey.Id];
            var oldP4Sp6 = this._document.Tables.getValue("F01_280_R4_4");
            var copySp7Handler = function (table, recordKey) {
                var orgKey = table.GetFieldValue("F01_280_r4_2_key");
                var postKey = table.GetFieldValue("Pos_ID");
                if (destTable.Locate(keyFields, [orgKey, postKey])) {
                    for (var i = 5; i < 9; i++) {
                        destTable.SetFieldValue("g" + i + "_4_6", table.GetFieldValue("g" + i));
                    }
                    destTable.RubEmplCountField.Value = table.GetFieldValue("g4");
                    destTable.RubFotData.Value = table.GetFieldValue("g9");
                }
            };
            oldP4Sp6.Iterate(copySp7Handler);
            this._document.DeleteTemporaryTable(oldP4Sp6);
        };
        UpdateRules.prototype.UpdateP5Sp3To5 = function () {
            var destTable = this._document.TableP5Sp3;
            var mapping = {
                FieldsMapping: [
                    {
                        SrcFieldId: "F01_280_r5_2_Key",
                        DestFieldId: destTable.OwnerKeyField.Id
                    },
                    {
                        SrcFieldId: "g3",
                        DestFieldId: destTable.PositionKey.Id
                    },
                    {
                        SrcFieldId: "g4",
                        DestFieldId: destTable.UsdEmplCountField.Id
                    },
                    {
                        SrcFieldId: "g7",
                        DestFieldId: destTable.UsdData.Id
                    },
                    {
                        SrcFieldId: "g8",
                        DestFieldId: destTable.UsdFotData.Id
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldUsd.Id,
                        Value: true
                    },
                    {
                        SrcFieldId: "",
                        DestFieldId: destTable.IsCopiedFieldRub.Id,
                        Value: true
                    }
                ],
                CopyExistsFields: true
            };
            var oldTableId = "F01_280_r5_2_PosInfo";
            this._document.CommonRules.CopyTableRows(oldTableId, destTable, mapping);
            this._document.DeleteTemporaryTable(oldTableId);
            var keyFields = [destTable.OwnerKeyField.Id, destTable.PositionKey.Id];
            var oldP5Sp5 = this._document.Tables.getValue("F01_280_R5_5");
            var copySp5Handler = function (table, recordKey) {
                var orgKey = table.GetFieldValue("F01_280_r5_2_key");
                var postKey = table.GetFieldValue("g3");
                if (destTable.Locate(keyFields, [orgKey, postKey])) {
                    destTable.SetFieldValue("g6_5_5", table.GetFieldValue("g6"));
                    destTable.SetFieldValue("g7_5_5", table.GetFieldValue("g7"));
                    destTable.SetFieldValue("g9_5_5", table.GetFieldValue("g9"));
                    destTable.RubEmplCountField.Value = table.GetFieldValue("g4");
                }
            };
            oldP5Sp5.Iterate(copySp5Handler);
            this._document.DeleteTemporaryTable(oldP5Sp5);
            var oldP5Sp6 = this._document.Tables.getValue("F01_280_R5_6");
            var copySp6Handler = function (table, recordKey) {
                var orgKey = table.GetFieldValue("F01_280_r5_2_key");
                var postKey = table.GetFieldValue("g3");
                if (destTable.Locate(keyFields, [orgKey, postKey])) {
                    for (var i = 5; i < 11; i++) {
                        destTable.SetFieldValue("g" + i + "_5_6", table.GetFieldValue("g" + (i - 1)));
                    }
                    destTable.RubFotData.Value = table.GetFieldValue("g11");
                }
            };
            oldP5Sp6.Iterate(copySp6Handler);
            this._document.DeleteTemporaryTable(oldP5Sp6);
        };
        UpdateRules.prototype.UpdateSpLastTo5 = function (partNum, destTable) {
            var srcTable = this._document.Tables.getValue("F01_280_RX_Last");
            var yearField = BaseObasTableFields.YearDataField;
            var usdField = BaseObasTableFields.UsdYearDataField;
            while (srcTable.Locate("R_Num", partNum, true)) {
                destTable.AddRow();
                destTable.Country.ForeignKey.Value = srcTable.GetFieldValue("g1");
                destTable.Org.ForeignKey.Value = srcTable.GetFieldValue("g2");
                for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                    destTable.SetFieldValue(usdField.GenerateId(i), srcTable.GetFieldValue("g" + (i + 2)));
                    destTable.SetFieldValue(yearField.GenerateId(i), srcTable.GetFieldValue("g" + (i + 6)));
                }
                destTable.PostRow();
            }
            srcTable.ClearLocateFlag();
        };
        UpdateRules.prototype.UpdateInsTo5 = function (destTable) {
            var strKeyFieldId = BaseObasTableFields.StrKeyField.Id;
            var keyRepair = function (table) {
                var strKey = table.GetFieldValue(strKeyFieldId);
                if (strKey != null) {
                    table.SetFieldValue(strKeyFieldId, strKey + 1);
                }
            };
            var rowFilter = function (table) {
                return table.GetFieldValue(strKeyFieldId) == null;
            };
            destTable.DeleteAllRow(rowFilter);
            destTable.Iterate(keyRepair);
        };
        return UpdateRules;
    }());
    F01280.UpdateRules = UpdateRules;
})(F01280 || (F01280 = {}));
