public int ReCalculateRepaymentPeriod(CashRequest cashRequest) { var result = cashRequest.RepaymentPeriod; if (!string.IsNullOrEmpty(cashRequest.LoanTemplate)) { var model = EditLoanDetailsModel.Parse(cashRequest.LoanTemplate); var loan = _builder.CreateLoan(model); var start = DateTime.UtcNow; var end = loan.Schedule.Last().Date; result = GetTotalMonts(start, end); } return(result); }
public int CalculateCountRepayment(Loan loan) { int result; if (string.IsNullOrEmpty(loan.CashRequest.LoanTemplate)) { result = loan.Schedule.Count; } else { var model = EditLoanDetailsModel.Parse(loan.CashRequest.LoanTemplate); var newLoan = _builder.CreateLoan(model); result = newLoan.Schedule.Count; } return(result); }
public bool IsAmountChangingAllowed(CashRequest cr) { if (cr == null || string.IsNullOrEmpty(cr.LoanTemplate)) return true; var model = EditLoanDetailsModel.Parse(cr.LoanTemplate); //compare number of installments/other actions if (model.Items.Count(i => i.Type == "Installment") != cr.RepaymentPeriod) return false; if (model.Items.Count != cr.RepaymentPeriod) return false; //compare template balances with actual var expectedBalances = cr.LoanType.GetBalances(cr.ApprovedSum(), cr.RepaymentPeriod); var actualBalances = model.Items.Where(i => i.Type == "Installment").Select(i => i.Balance); if (expectedBalances.Except(actualBalances).Any()) return false; return true; }