var F01280;
(function (F01280) {
    var UpdateRules = (function () {
        function UpdateRules(_document) {
            this._document = _document;
        }
        UpdateRules.prototype.UpdateTemplate = function (oldVersion, currentVersion) {
            this._document.StartUpdate();
            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 pInsData = pInsTable.CollectUserData();
            this._document.TableP1.ResetData();
            pInsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            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 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 p2SpIndexData = p2SpIndexTable.CollectUserData();
            var p2Sp3Data = p2Sp3Table.CollectUserData();
            var p2SpInsData = p2SpInsTable.CollectUserData();
            var p2SpWritsData = p2SpWritsTable.CollectUserData();
            var p2Sp6Data = p2Sp6Table.CollectUserData();
            p2Sp1Table.ResetData();
            this._document.TableP2Sp2.ResetData();
            p2SpIndexTable.ResetData();
            p2Sp3Table.ResetData();
            p2SpInsTable.ResetData();
            p2SpWritsTable.ResetData();
            p2Sp6Table.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            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 p3SpIndexTable = this._document.TableP3SpIndexation;
            var p3Sp3Table = this._document.TableP3Sp3;
            var p3SpInsTable = this._document.TableP3SpInsurance;
            var p3SpWritsTable = this._document.TableP3SpExecWrits;
            var p3Sp1Data = p3Sp1Table.CollectUserData();
            var p3SpIndexData = p3SpIndexTable.CollectUserData();
            var p3Sp3Data = p3Sp3Table.CollectUserData();
            var p3SpInsData = p3SpInsTable.CollectUserData();
            var p3SpWritsData = p3SpWritsTable.CollectUserData();
            p3Sp1Table.ResetData();
            this._document.TableP3Sp2.ResetData();
            p3SpIndexTable.ResetData();
            p3Sp3Table.ResetData();
            p3SpInsTable.ResetData();
            p3SpWritsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            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 p4Sp3Table = this._document.TableP4Sp3;
            var p4SpInsTable = this._document.TableP4SpInsurance;
            var p4SpWritsTable = this._document.TableP4SpExecWrits;
            var p4Sp1Data = p4Sp1Table.CollectUserData();
            var p4Sp3Data = p4Sp3Table.CollectUserData();
            var p4SpInsData = p4SpInsTable.CollectUserData();
            var p4SpWritsData = p4SpWritsTable.CollectUserData();
            p4Sp1Table.ResetData();
            this._document.TableP4Sp2.ResetData();
            this._document.TableP4SpIndexation.ResetData();
            p4Sp3Table.ResetData();
            p4SpInsTable.ResetData();
            p4SpWritsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            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 p5SpIndexTable = this._document.TableP5SpIndexation;
            var p5Sp3Table = this._document.TableP5Sp3;
            var p5SpInsTable = this._document.TableP5SpInsurance;
            var p5SpWritsTable = this._document.TableP5SpExecWrits;
            var p5Sp1Data = p5Sp1Table.CollectUserData();
            var p5SpIndexData = p5SpIndexTable.CollectUserData();
            var p5Sp3Data = p5Sp3Table.CollectUserData();
            var p5SpInsData = p5SpInsTable.CollectUserData();
            var p5SpWritsData = p5SpWritsTable.CollectUserData();
            p5Sp1Table.ResetData();
            this._document.TableP5Sp2.ResetData();
            p5SpIndexTable.ResetData();
            p5Sp3Table.ResetData();
            p5SpInsTable.ResetData();
            p5SpWritsTable.ResetData();
            this._document.EnableRulesAndNotice = true;
            this._document.EnableDatasetNotification = false;
            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.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.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.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.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.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.TableP2Sp3.DeleteAllRow(yearFilter);
            this._document.TableP3Sp3.DeleteAllRow(yearFilter);
            this._document.TableP4Sp3.DeleteAllRow(yearFilter);
            this._document.TableP5Sp3.DeleteAllRow(yearFilter);
        };
        return UpdateRules;
    }());
    F01280.UpdateRules = UpdateRules;
})(F01280 || (F01280 = {}));
