protected virtual void AdjustMethodLines(FADepreciationMethod meth) { if (meth.UsefulLife == null || meth.AveragingConvention == null || meth.AveragingConvPeriod == null) { return; } int periodFactor; switch (meth.AveragingConvention) { case FAAveragingConvention.HalfYear: case FAAveragingConvention.FullYear: periodFactor = 12; break; case FAAveragingConvention.HalfQuarter: case FAAveragingConvention.FullQuarter: periodFactor = 3; break; default: periodFactor = 1; break; } int offsetPeriods = ((int)meth.AveragingConvPeriod - 1) * periodFactor; int periods = (int)Math.Ceiling((decimal)meth.UsefulLife * 12 + offsetPeriods); if (meth.AveragingConvention == FAAveragingConvention.HalfYear || meth.AveragingConvention == FAAveragingConvention.HalfQuarter || meth.AveragingConvention == FAAveragingConvention.HalfPeriod || meth.AveragingConvention == FAAveragingConvention.ModifiedPeriod || meth.AveragingConvention == FAAveragingConvention.ModifiedPeriod2 || meth.AveragingConvention == FAAveragingConvention.NextPeriod ) { periods++; } int years = (int)Math.Ceiling(periods / 12d); List <FADepreciationMethodLines> lines = PXSelect <FADepreciationMethodLines, Where <FADepreciationMethodLines.methodID, Equal <Current <FADepreciationMethod.methodID> > > > .Select(this) .RowCast <FADepreciationMethodLines>() .ToList(); if (years != lines.Count) { decimal oldTotalRate = 0m; decimal newTotalRate = 0m; int count = 0; FADepreciationMethodLines lastLine = null; lines.Sort((line1, line2) => (line1.Year ?? 0m).CompareTo(line2.Year ?? 0m)); foreach (FADepreciationMethodLines line in lines) { oldTotalRate += line.RatioPerYear ?? 0m; count++; if (count > years) { details.Delete(PXCache <FADepreciationMethodLines> .CreateCopy(line)); } else { lastLine = PXCache <FADepreciationMethodLines> .CreateCopy(line); newTotalRate += line.RatioPerYear ?? 0m; } } if (count > years && lastLine != null) { lastLine.RatioPerYear += oldTotalRate - newTotalRate; lastLine = details.Update(lastLine); details.Cache.SetDefaultExt <FADepreciationMethodLines.displayRatioPerYear>(lastLine); } else { for (int year_num = count + 1; year_num <= years; year_num++) { details.Insert(new FADepreciationMethodLines { Year = year_num, RatioPerYear = 0m }); } } } }
protected virtual void AdjustMethodLines(FADepreciationMethod meth) { if (meth.UsefulLife == null || meth.AveragingConvention == null || meth.AveragingConvPeriod == null) { return; } int periodFactor; if (meth.AveragingConvention == FAAveragingConvention.FullYear || meth.AveragingConvention == FAAveragingConvention.HalfYear) { periodFactor = 12; } else if (meth.AveragingConvention == FAAveragingConvention.FullQuarter || meth.AveragingConvention == FAAveragingConvention.HalfQuarter) { periodFactor = 3; } else { periodFactor = 1; } int offsetPeriods = ((int)meth.AveragingConvPeriod - 1) * periodFactor; int periods = (int)Math.Ceiling((decimal)meth.UsefulLife * 12 + offsetPeriods); if (meth.AveragingConvention == FAAveragingConvention.HalfYear || meth.AveragingConvention == FAAveragingConvention.HalfQuarter || meth.AveragingConvention == FAAveragingConvention.HalfPeriod || meth.AveragingConvention == FAAveragingConvention.ModifiedPeriod || meth.AveragingConvention == FAAveragingConvention.ModifiedPeriod2 || meth.AveragingConvention == FAAveragingConvention.NextPeriod ) { periods++; } int years = (int)Math.Ceiling(periods / 12d); List <FADepreciationMethodLines> lines = new List <FADepreciationMethodLines>(); foreach (FADepreciationMethodLines line in PXSelect <FADepreciationMethodLines, Where <FADepreciationMethodLines.methodID, Equal <Current <FADepreciationMethod.methodID> > > > .Select(this)) { lines.Add(line); } if (years != lines.Count) { decimal newTotalRate = 0m; int count = 0; FADepreciationMethodLines lastLine = null; lines.Sort(delegate(FADepreciationMethodLines line1, FADepreciationMethodLines line2) { return((line1.Year ?? 0m).CompareTo(line2.Year ?? 0m)); }); foreach (FADepreciationMethodLines line in lines) { count++; if (count > years) { details.Delete((FADepreciationMethodLines)details.Cache.CreateCopy(line)); } else { lastLine = (FADepreciationMethodLines)details.Cache.CreateCopy(line); newTotalRate += line.RatioPerYear ?? 0m; } } if (count > years && lastLine != null) { lastLine.RatioPerYear += 1m - newTotalRate; details.Update(lastLine); } else { for (int year_num = count + 1; year_num <= years; year_num++) { details.Insert(new FADepreciationMethodLines { Year = year_num, RatioPerYear = 0m }); } } } }