186 lines
7.9 KiB
C#
186 lines
7.9 KiB
C#
using System;
|
||
using System.Linq;
|
||
using EvoCalculator.Core.Base.Columns;
|
||
using EvoCalculator.Core.Models.PostCalculation.Models.Prepared;
|
||
using EvoCalculator.Core.Models.PostCalculation.Models.Prepared.PreparedTables;
|
||
|
||
namespace EvoCalculator.Core.PostCalculation.v1;
|
||
|
||
public class NextValues
|
||
{
|
||
public decimal AcquisitionExpenses;
|
||
public decimal BaseCost;
|
||
public decimal NiAtInception;
|
||
public decimal NiAtInceptionMSFO;
|
||
public int Nmper;
|
||
protected PreparedValues preparedValues;
|
||
public decimal SumTotal;
|
||
|
||
public NextValues(PreparedValues preparedValues)
|
||
{
|
||
this.preparedValues = preparedValues;
|
||
}
|
||
|
||
public void ComputeAcquisitionExpenses(TableInsuranceRow[]? nextTableInsurance)
|
||
{
|
||
var tracker = 0m;
|
||
if (preparedValues.TrackerCost.Next == 0)
|
||
tracker = preparedValues.TrackerCost.Current;
|
||
else if (preparedValues.TypeChangeTracker == 100000000)
|
||
tracker = preparedValues.TrackerCost.Current + preparedValues.TrackerCost.Next;
|
||
else
|
||
tracker = preparedValues.TrackerCostRemove + preparedValues.TrackerCost.Next;
|
||
|
||
var tlm = 0m;
|
||
if (preparedValues.TLMCost.Next == 0)
|
||
tlm = preparedValues.TLMCost.Current;
|
||
else if (preparedValues.TypeChangeTLM == 100000000)
|
||
tlm = preparedValues.TLMCost.Current + preparedValues.TLMCost.Next;
|
||
else
|
||
tlm = preparedValues.TLMCostRemove + preparedValues.TLMCost.Next;
|
||
|
||
|
||
var baseRegistration = 0m;
|
||
if (preparedValues.BaseRegistration.Next == 0)
|
||
baseRegistration = preparedValues.BaseRegistration.Current;
|
||
else if (preparedValues.TypeChangeRegistration == 100000000)
|
||
baseRegistration = preparedValues.BaseRegistration.Next;
|
||
else
|
||
baseRegistration = preparedValues.BaseRegistration.Current + preparedValues.BaseRegistration.Next;
|
||
|
||
|
||
var nextCostInsurance = 0m;
|
||
if (nextTableInsurance != null)
|
||
nextCostInsurance = nextTableInsurance
|
||
.Where(x => x.TypeRiskInsurance is "KASKO" or "OSAGO" or "GAP" && x.PeriodNumberInsurance == 1)
|
||
.Sum(x => x.CostInsurance);
|
||
|
||
|
||
AcquisitionExpenses = preparedValues.PlPrice.Next
|
||
+ nextCostInsurance
|
||
- preparedValues.ComissionRub
|
||
- preparedValues.Discount.Next
|
||
+ tracker
|
||
+ tlm
|
||
+ preparedValues.TechnicalCardSum
|
||
+ baseRegistration
|
||
+ preparedValues.TransportTaxGr.Next switch
|
||
{
|
||
> 0 => preparedValues.TransportTaxGr.Next,
|
||
_ => preparedValues.TransportTaxGr.Current
|
||
}
|
||
+ preparedValues.InceptDelta;
|
||
|
||
if (AcquisitionExpenses <= 0)
|
||
throw new Exception(
|
||
"Невозможно осуществить расчет графика, при заданных параметрах получаются отрицательные значения nextValues. Измените параметры для расчета.");
|
||
}
|
||
|
||
public void ComputeBaseCost(TableInsuranceRow[]? nextTableInsurance,
|
||
BaseColumn<decimal>? nextTLMGrColumn, TablePaymentsRow[] currentTablePayments)
|
||
{
|
||
var registration = 0m;
|
||
if (preparedValues.Registration.Next == 0)
|
||
registration = preparedValues.Registration.Current;
|
||
else if (preparedValues.TypeChangeRegistration == 100000000)
|
||
registration = preparedValues.Registration.Next;
|
||
else
|
||
registration = preparedValues.Registration.Current + preparedValues.Registration.Next;
|
||
|
||
|
||
var tracker = 0m;
|
||
if (preparedValues.TrackerCost.Next == 0)
|
||
tracker = preparedValues.TrackerCost.Current;
|
||
else if (preparedValues.TypeChangeTracker == 100000000)
|
||
tracker = preparedValues.TrackerCost.Current + preparedValues.TrackerCost.Next;
|
||
else
|
||
tracker = preparedValues.TrackerCostRemove + preparedValues.TrackerCost.Next;
|
||
|
||
var tlm = 0m;
|
||
if (preparedValues.TLMCost.Next == 0)
|
||
tlm = preparedValues.TLMCost.Current;
|
||
else if (preparedValues.TypeChangeTLM == 100000000)
|
||
tlm = preparedValues.TLMCost.Current + preparedValues.TLMCost.Next;
|
||
else
|
||
tlm = preparedValues.TLMCostRemove + preparedValues.TLMCost.Next;
|
||
|
||
var nextTlmGrValue = 0m;
|
||
if (nextTLMGrColumn != null)
|
||
nextTlmGrValue = nextTLMGrColumn.GetValue(0);
|
||
|
||
|
||
var nextCostInsurance = 0m;
|
||
if (nextTableInsurance != null)
|
||
nextCostInsurance = nextTableInsurance
|
||
.Where(x => x.TypeRiskInsurance is "KASKO" or "OSAGO" or "GAP")
|
||
.Sum(x => x.CostInsurance);
|
||
|
||
BaseCost = (preparedValues.PlPrice.Next
|
||
+ nextCostInsurance
|
||
+ preparedValues.TechnicalCardSum
|
||
+ registration
|
||
+ preparedValues.TransportTaxGr.Next switch
|
||
{
|
||
> 0 => preparedValues.TransportTaxGr.Next,
|
||
_ => preparedValues.TransportTaxGr.Current
|
||
}
|
||
+ tracker
|
||
+ tlm
|
||
+ nextTlmGrValue)
|
||
* preparedValues.Leasing0K
|
||
+ currentTablePayments.Sum(x => x.NSIBBruttoPayment)
|
||
+ preparedValues.InceptDelta;
|
||
|
||
// PostCheck
|
||
if (BaseCost <= 0)
|
||
throw new Exception(
|
||
"Невозможно осуществить расчет графика, при заданных параметрах получаются отрицательные значения nextValues. Измените параметры для расчета.");
|
||
}
|
||
|
||
public void ComputeNiAtInception(TablePaymentsRow[] currentTablePayments)
|
||
{
|
||
NiAtInception = AcquisitionExpenses - currentTablePayments[0].SumPayment;
|
||
}
|
||
|
||
public void ComputeNiAtInceptionMSFO()
|
||
{
|
||
NiAtInceptionMSFO = NiAtInception
|
||
+ preparedValues.BonusManagerLeasing
|
||
+ preparedValues.BonusManagerProducts
|
||
+ preparedValues.BonusManagerLeasingExtra
|
||
+ preparedValues.AgentFLSum
|
||
+ preparedValues.AgentULSum;
|
||
}
|
||
|
||
public void ComputeNmper(TablePaymentsRow[] nextTablePayments, TablePaymentsRow[] currentTablePayments)
|
||
{
|
||
var targetNextPaymentsRow = nextTablePayments.Last();
|
||
var n = targetNextPaymentsRow.NumberPayment;
|
||
|
||
var targetPaymentSum = targetNextPaymentsRow.SumPayment;
|
||
var i = 0;
|
||
while (targetPaymentSum >= currentTablePayments[i + n].SumPayment)
|
||
{
|
||
targetPaymentSum -= currentTablePayments[i + n].SumPayment;
|
||
i++;
|
||
}
|
||
|
||
if (i == 0)
|
||
throw new Exception(
|
||
"Невозможно осуществить расчет ЧДП с изменением срока. Необходимо увеличить сумму ЧДП");
|
||
|
||
Nmper = preparedValues.Nmper.Current - i + 1;
|
||
|
||
// PostCheck
|
||
if (Nmper < 13 && preparedValues.BalanceHolder.Next == 100000001)
|
||
throw new Exception(
|
||
"По итогам расчета срок лизинга получается меньше 13, при балансе ЛД это запрещено. Измените параметры для расчета");
|
||
}
|
||
|
||
public void ComputeSumTotal(BaseColumn<decimal> nextSumWithVATColumn)
|
||
{
|
||
SumTotal = preparedValues.TotalExpected
|
||
- (preparedValues.TotalExpected - nextSumWithVATColumn.GetValue(0))
|
||
* (decimal) preparedValues.Repayment;
|
||
}
|
||
} |