69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using EvoCalculator.Core.Calculation.Post;
|
|
using EvoCalculator.Core.Models.Calculation.Models.Prepared;
|
|
using TridentGoalSeek;
|
|
|
|
namespace EvoCalculator.Core.Calculation.Columns
|
|
{
|
|
public class SumColumn : BaseColumnWithGoalSeek
|
|
{
|
|
private readonly PercentPaymentColumn _percentPaymentColumn;
|
|
private readonly PreparedValues _preparedValues;
|
|
private readonly PostValues _postValues;
|
|
|
|
public SumColumn(int count, DateTempColumn dateTempColumn
|
|
, PreparedValues preparedValues
|
|
, PercentPaymentColumn percentPaymentColumn, PostValues postValues) : base(count, dateTempColumn)
|
|
{
|
|
_preparedValues = preparedValues;
|
|
_percentPaymentColumn = percentPaymentColumn;
|
|
_postValues = postValues;
|
|
}
|
|
|
|
public override decimal Calculate(decimal inputVariable)
|
|
{
|
|
FillValues(inputVariable);
|
|
return Convert.ToDecimal(IRR);
|
|
}
|
|
|
|
protected override void FillValues(decimal x)
|
|
{
|
|
Values[0] = -_postValues.BaseCost.Value;
|
|
Values[1] = _preparedValues.FirstPaymentSum;
|
|
|
|
for (var i = 2; i < Values.Length - 1; i++) Values[i] = x * (decimal) _percentPaymentColumn.Values[i] / 100;
|
|
|
|
Values[^1] = _preparedValues.LastPaymentSum;
|
|
}
|
|
|
|
private void PostCheck()
|
|
{
|
|
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
|
|
|
if (Values[1] / Values.Skip(1).Sum() >= 0.5m)
|
|
{
|
|
throw new Exception(
|
|
"Первый платеж по графику более 50% от суммы лизинговых платежей. Необходимо уменьшить первый платеж");
|
|
}
|
|
}
|
|
|
|
public override void ComputeValues(decimal requiredValue)
|
|
{
|
|
var goalSeek = new GoalSeek(this);
|
|
goalSeek.SeekResult(requiredValue,
|
|
new GoalSeekOptions(
|
|
startingStabPoint: Convert.ToDecimal(
|
|
(_postValues.BaseCost.Value - _preparedValues.FirstPaymentSum) /
|
|
_preparedValues.Nmper)
|
|
, tineExplorePercentage: 10
|
|
// , maximumAttempts: 10000
|
|
// , initialTineSpacing: 1
|
|
// , focusPercentage: 100
|
|
// , trimFinalInputValue: true
|
|
));
|
|
|
|
PostCheck();
|
|
}
|
|
}
|
|
} |