env: add CALCULATION_IRR
This commit is contained in:
parent
84f8b2fffe
commit
5ba21a49fc
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using EvoCalculator.Core.Models.BaseCalculation.Models.Request;
|
||||
using EvoCalculator.Core.Models.BaseCalculation.Models.Response;
|
||||
@ -8,41 +9,42 @@ namespace EvoCalculator.Core.Calculation;
|
||||
|
||||
public class BaseCalculation
|
||||
{
|
||||
const double IRR = 0.155;
|
||||
private Constants.Calculation constants;
|
||||
private double IRR = 0;
|
||||
private Constants.Calculation constants = new();
|
||||
|
||||
public BaseCalculation()
|
||||
{
|
||||
this.constants = new Constants.Calculation();
|
||||
var envCalculationIRR = Environment.GetEnvironmentVariable("CALCULATION_IRR");
|
||||
IRR = float.Parse(envCalculationIRR, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public ResponseBaseCalculation Calculate(RequestBaseCalculation requestBaseCalculation)
|
||||
{
|
||||
var initialPaymentSum =
|
||||
requestBaseCalculation.car_price * (decimal) (requestBaseCalculation.initial_payment / 100);
|
||||
requestBaseCalculation.car_price * (decimal)(requestBaseCalculation.initial_payment / 100);
|
||||
var redemptionPaymentSum = requestBaseCalculation.car_price *
|
||||
(decimal) (requestBaseCalculation.redemption_payment / 100);
|
||||
(decimal)(requestBaseCalculation.redemption_payment / 100);
|
||||
|
||||
var IRRperMonth = Math.Pow(1 + IRR / 12, requestBaseCalculation.lease_period - 2);
|
||||
var monthlyPayment = (IRR / 12) *
|
||||
(double) ((requestBaseCalculation.car_price - initialPaymentSum) *
|
||||
(decimal) IRRperMonth - redemptionPaymentSum) / (IRRperMonth - 1);
|
||||
|
||||
var leaseContractSum = (requestBaseCalculation.lease_period - 2) * (decimal) monthlyPayment +
|
||||
(double)((requestBaseCalculation.car_price - initialPaymentSum) *
|
||||
(decimal)IRRperMonth - redemptionPaymentSum) / (IRRperMonth - 1);
|
||||
|
||||
var leaseContractSum = (requestBaseCalculation.lease_period - 2) * (decimal)monthlyPayment +
|
||||
initialPaymentSum +
|
||||
redemptionPaymentSum;
|
||||
var taxSavings = leaseContractSum * (decimal) (constants.VatValue / 1.2);
|
||||
var taxSavings = leaseContractSum * (decimal)(constants.VatValue / 1.2);
|
||||
|
||||
var schedule = Array<decimal>.Concat(
|
||||
new decimal[] {initialPaymentSum}
|
||||
, Enumerable.Repeat((decimal) monthlyPayment, requestBaseCalculation.lease_period - 2).ToArray()
|
||||
, new decimal[] {redemptionPaymentSum}
|
||||
new decimal[] { initialPaymentSum }
|
||||
, Enumerable.Repeat((decimal)monthlyPayment, requestBaseCalculation.lease_period - 2).ToArray()
|
||||
, new decimal[] { redemptionPaymentSum }
|
||||
);
|
||||
|
||||
|
||||
return new ResponseBaseCalculation()
|
||||
{
|
||||
monthly_payment = (decimal) monthlyPayment,
|
||||
monthly_payment = (decimal)monthlyPayment,
|
||||
tax_savings = taxSavings,
|
||||
vat_reimbursement = taxSavings,
|
||||
schedule = schedule
|
||||
|
||||
@ -26,7 +26,8 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"calculation_v2_date": "2021-09-02",
|
||||
"calculation_v3_date": "2022-03-30",
|
||||
"post_calculation_v2_date": "2022-04-14"
|
||||
"post_calculation_v2_date": "2022-04-14",
|
||||
"calculation_irr": "0.21"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user