private AccountEstimationProjectionModel CreateProjection(DateTime period, decimal accountRemainingTransferBalance, decimal lastProjectedBalance) { var transferModelledCostOfTraining = _virtualEmployerCommitments.GetTotalCostOfTraining(period, true); var transferModelledCompletionPayments = _virtualEmployerCommitments.GetTotalCompletionPayments(period, true); var allModelledCostOfTraining = _virtualEmployerCommitments.GetTotalCostOfTraining(period); var allModelledCompletionPayments = _virtualEmployerCommitments.GetTotalCompletionPayments(period); var actualAccountProjection = _actualAccountProjections.FirstOrDefault(c => c.Month == period.Month && c.Year == period.Year); var projection = new AccountEstimationProjectionModel { Month = (short)period.Month, Year = (short)period.Year, ProjectionGenerationType = actualAccountProjection?.ProjectionGenerationType ?? ProjectionGenerationType.LevyDeclaration, FundsIn = actualAccountProjection?.LevyFundsIn ?? 0m, TransferModelledCosts = new AccountEstimationProjectionModel.Cost { LevyCostOfTraining = transferModelledCostOfTraining.LevyFunded, LevyCompletionPayments = transferModelledCompletionPayments.LevyFundedCompletionPayment, TransferInCostOfTraining = transferModelledCostOfTraining.TransferIn, TransferInCompletionPayments = transferModelledCompletionPayments.TransferInCompletionPayment, TransferOutCostOfTraining = transferModelledCostOfTraining.TransferOut, TransferOutCompletionPayments = transferModelledCompletionPayments.TransferOutCompletionPayment }, AllModelledCosts = new AccountEstimationProjectionModel.Cost { LevyCostOfTraining = allModelledCostOfTraining.LevyFunded, LevyCompletionPayments = allModelledCompletionPayments.LevyFundedCompletionPayment, TransferInCostOfTraining = allModelledCostOfTraining.TransferIn, TransferInCompletionPayments = allModelledCompletionPayments.TransferInCompletionPayment, TransferOutCostOfTraining = allModelledCostOfTraining.TransferOut, TransferOutCompletionPayments = allModelledCompletionPayments.TransferOutCompletionPayment }, ActualCosts = new AccountEstimationProjectionModel.Cost { LevyCostOfTraining = actualAccountProjection?.LevyFundedCostOfTraining ?? 0m, LevyCompletionPayments = actualAccountProjection?.LevyFundedCompletionPayments ?? 0m, TransferInCostOfTraining = actualAccountProjection?.TransferInCostOfTraining ?? 0m, TransferInCompletionPayments = actualAccountProjection?.TransferInCompletionPayments ?? 0m, TransferOutCostOfTraining = actualAccountProjection?.TransferOutCostOfTraining ?? 0m, TransferOutCompletionPayments = actualAccountProjection?.TransferOutCompletionPayments ?? 0m, ExpiredFunds = actualAccountProjection?.ExpiredFunds ?? 0m, } }; if (_estimatedProjections.Any()) { lastProjectedBalance = lastProjectedBalance - projection.ActualCosts.FundsOut; } //transfer projection projection.AvailableTransferFundsBalance = accountRemainingTransferBalance - projection.TransferFundsOut; //estimate balance projection.EstimatedProjectionBalance = lastProjectedBalance - projection.AllModelledCosts.FundsOut; return(projection); }
private AccountProjectionModel CreateProjection(DateTime period, decimal levyFundsIn, decimal lastBalance, ProjectionGenerationType projectionGenerationType, bool isFirstMonth, int periodStartDay) { var totalCostOfTraning = _employerCommitments.GetTotalCostOfTraining(period); var completionPayments = _employerCommitments.GetTotalCompletionPayments(period); var currentBalance = GetCurrentBalance(lastBalance, completionPayments.TransferOutCompletionPayment, totalCostOfTraning.TransferOut, isFirstMonth); var trainingCosts = totalCostOfTraning.LevyFunded + completionPayments.LevyFundedCompletionPayment; var coInvestmentAmount = GetCoInvestmentAmountBasedOnCurrentBalanceAndTrainingCosts(currentBalance, trainingCosts); var moneyOut = isFirstMonth ? coInvestmentAmount : trainingCosts - coInvestmentAmount; var moneyIn = isFirstMonth && projectionGenerationType == ProjectionGenerationType.LevyDeclaration ? 0: levyFundsIn; var futureFunds = GetMonthEndBalance(currentBalance, moneyOut, moneyIn, projectionGenerationType, isFirstMonth, periodStartDay); var projection = new AccountProjectionModel { LevyFundsIn = _account.LevyDeclared, EmployerAccountId = _account.EmployerAccountId, Month = (short)period.Month, Year = (short)period.Year, LevyFundedCostOfTraining = totalCostOfTraning.LevyFunded, TransferInCostOfTraining = totalCostOfTraning.TransferIn, TransferOutCostOfTraining = totalCostOfTraning.TransferOut, LevyFundedCompletionPayments = completionPayments.LevyFundedCompletionPayment, TransferInCompletionPayments = completionPayments.TransferInCompletionPayment, TransferOutCompletionPayments = completionPayments.TransferOutCompletionPayment, CoInvestmentEmployer = coInvestmentAmount > 0 ? (coInvestmentAmount * 0.1m) : 0m, CoInvestmentGovernment = coInvestmentAmount > 0 ? (coInvestmentAmount * 0.9m) : 0m, FutureFunds = futureFunds, ProjectionCreationDate = DateTime.UtcNow, ProjectionGenerationType = projectionGenerationType }; return(projection); }