TLMCostColumn: fix Computing Values
This commit is contained in:
parent
6be855c204
commit
8cc1b3d64a
@ -17,11 +17,71 @@ public class TLMCostColumn : BaseColumnWithSum
|
||||
|
||||
public DateTime[] Dates { get; set; }
|
||||
|
||||
public void ComputeValues(
|
||||
PreparedValues preparedValues
|
||||
public void ComputeValues(PreparedValues preparedValues
|
||||
, ChangingValue<TableTLMTrackerRow[]> tableTLMTracker)
|
||||
{
|
||||
if (preparedValues.ChangeTrackerTLM == false)
|
||||
/* Вариант 1: меняем системы ТЛМ */
|
||||
if (preparedValues.ChangeTrackerTLM == true
|
||||
&& tableTLMTracker.Current != null
|
||||
&& tableTLMTracker.Next != null)
|
||||
{
|
||||
var currentIndex = tableTLMTracker.Current
|
||||
.ToList()
|
||||
.FindIndex(x =>
|
||||
x.DateTLM.Month == preparedValues.EditPaymentDate.Current.Month
|
||||
&& x.DateTLM.Year == preparedValues.EditPaymentDate.Current.Year
|
||||
);
|
||||
var currentPart = tableTLMTracker.Current.Take(currentIndex + 1);
|
||||
|
||||
|
||||
var nextIndex = (Dates.Length - 1) - currentIndex;
|
||||
/* @offset: не берем первый платеж в таблице next потому что он всегда = 0 */
|
||||
const int offset = 1;
|
||||
var nextPart
|
||||
= tableTLMTracker.Next
|
||||
.Skip(offset)
|
||||
.Take(nextIndex - offset);
|
||||
|
||||
Values = Array<decimal>.Concat(
|
||||
new decimal[] {0}
|
||||
, currentPart.Select(x => x.CostTLM)
|
||||
, nextPart.Select(x => x.CostTLM));
|
||||
}
|
||||
/* Вариант 2: добавляем ТЛМ */
|
||||
else if (preparedValues.ChangeTrackerTLM == true
|
||||
&& tableTLMTracker.Current == null
|
||||
&& tableTLMTracker.Next != null)
|
||||
{
|
||||
var nextIndex = Dates.Length - 1;
|
||||
var nextPart
|
||||
= tableTLMTracker.Next.Take(nextIndex);
|
||||
|
||||
Values = Array<decimal>.Concat(
|
||||
new decimal[] {0}
|
||||
, nextPart.Select(x => x.CostTLM));
|
||||
}
|
||||
/* Вариант 3: удаляем ТЛМ */
|
||||
else if (preparedValues.ChangeTrackerTLM == true
|
||||
&& tableTLMTracker.Current != null
|
||||
&& tableTLMTracker.Next == null)
|
||||
{
|
||||
var currentIndex = tableTLMTracker.Current
|
||||
.ToList()
|
||||
.FindIndex(x =>
|
||||
x.DateTLM.Month == preparedValues.EditPaymentDate.Current.Month
|
||||
&& x.DateTLM.Year == preparedValues.EditPaymentDate.Current.Year
|
||||
);
|
||||
var currentPart = tableTLMTracker.Current.Take(currentIndex + 1);
|
||||
|
||||
Values = Array<decimal>.Concat(
|
||||
new decimal[] {0}
|
||||
, currentPart.Select(x => x.CostTLM)
|
||||
);
|
||||
}
|
||||
/* Вариант 4: ТЛМ есть и не меняется */
|
||||
else if (preparedValues.ChangeTrackerTLM == false
|
||||
&& tableTLMTracker.Current != null
|
||||
&& tableTLMTracker.Next == null)
|
||||
{
|
||||
var lastValue = tableTLMTracker.Current[^1].CostTLM;
|
||||
|
||||
@ -40,22 +100,15 @@ public class TLMCostColumn : BaseColumnWithSum
|
||||
, Enumerable.Repeat(lastValue, tailNumber));
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Вариант 5: ТЛМ нет и не меняется */
|
||||
else if (preparedValues.ChangeTrackerTLM == false
|
||||
&& tableTLMTracker.Current != null
|
||||
&& tableTLMTracker.Next != null)
|
||||
{
|
||||
var currentIndex = tableTLMTracker.Current
|
||||
.ToList()
|
||||
.FindIndex(x =>
|
||||
x.DateTLM.Month == preparedValues.EditPaymentDate.Next.Month
|
||||
&& x.DateTLM.Year == preparedValues.EditPaymentDate.Next.Year
|
||||
);
|
||||
var currentPart = tableTLMTracker.Current.Take(currentIndex);
|
||||
|
||||
Values = Array<decimal>.Concat(
|
||||
new decimal[] {0}
|
||||
, currentPart.Select(x => x.CostTLM)
|
||||
, tableTLMTracker.Next.Select(x => x.CostTLM));
|
||||
// вариант не применим т.к. невозможно найти даты
|
||||
}
|
||||
|
||||
|
||||
Values[0] = Sum;
|
||||
}
|
||||
|
||||
|
||||
@ -28,10 +28,10 @@ public class Helper
|
||||
DateTime endDate;
|
||||
if (preparedValues.ChangeTrackerTLM)
|
||||
{
|
||||
startDate = currentTableTLMTracker?[0]?.DateTLM ?? preparedValues.EditPaymentDate.Next;
|
||||
startDate = currentTableTLMTracker?[0]?.DateTLM ?? preparedValues.EditPaymentDate.Current;
|
||||
endDate = nextTableTLMTracker != null
|
||||
? nextDateColumn.Values[^1]
|
||||
: preparedValues.EditPaymentDate.Next;
|
||||
: preparedValues.EditPaymentDate.Current;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user