Skip to content

Commit

Permalink
FINERACT-1958-Loan-repayment-calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchiD authored and adamsaghy committed Sep 29, 2023
1 parent 480b954 commit 7e893ea
Show file tree
Hide file tree
Showing 4 changed files with 477 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public static double roundToMultiplesOf(final double existingVal, final Integer
return amountScaled;
}

public static BigDecimal roundToMultiplesOf(final BigDecimal existingVal, final Integer inMultiplesOf) {
BigDecimal amountScaled = existingVal;
BigDecimal inMultiplesOfValue = BigDecimal.valueOf(inMultiplesOf.intValue());
if (inMultiplesOfValue.compareTo(BigDecimal.ZERO) > 0) {
amountScaled = existingVal.divide(inMultiplesOfValue, 0, RoundingMode.HALF_UP).multiply(inMultiplesOfValue);
}
return amountScaled;
}

public static double ceiling(final double n, final double s) {
double c;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1774,4 +1774,8 @@ public LocalDate getSubmittedOnDate() {
public boolean isScheduleExtensionForDownPaymentDisabled() {
return isScheduleExtensionForDownPaymentDisabled;
}

public Integer getInstallmentAmountInMultiplesOf() {
return installmentAmountInMultiplesOf;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ private LoanScheduleModel generate(final MathContext mc, final LoanApplicationTe
if (loanApplicationTerms.isDownPaymentEnabled()) {
downPaymentAmount = MathUtil.percentageOf(scheduleParams.getOutstandingBalance().getAmount(),
loanApplicationTerms.getDisbursedAmountPercentageForDownPayment(), 19);
if (loanApplicationTerms.getInstallmentAmountInMultiplesOf() != null) {
downPaymentAmount = Money.roundToMultiplesOf(downPaymentAmount,
loanApplicationTerms.getInstallmentAmountInMultiplesOf());
}

}
Money calculatedAmortizableAmount = loanApplicationTerms.getPrincipal().minus(downPaymentAmount);
scheduleParams.setOutstandingBalance(calculatedAmortizableAmount);
Expand All @@ -155,6 +160,9 @@ private LoanScheduleModel generate(final MathContext mc, final LoanApplicationTe
if (loanApplicationTerms.isDownPaymentEnabled()) {
downPaymentAmt = MathUtil.percentageOf(disburseAmt, loanApplicationTerms.getDisbursedAmountPercentageForDownPayment(),
19);
if (loanApplicationTerms.getInstallmentAmountInMultiplesOf() != null) {
downPaymentAmt = Money.roundToMultiplesOf(downPaymentAmt, loanApplicationTerms.getInstallmentAmountInMultiplesOf());
}
}
BigDecimal remainingPrincipalAmt = disburseAmt.subtract(downPaymentAmt);
scheduleParams.setPrincipalToBeScheduled(Money.of(currency, remainingPrincipalAmt));
Expand Down Expand Up @@ -2022,6 +2030,9 @@ private LoanScheduleModelDownPaymentPeriod createDownPaymentPeriod(LoanApplicati
LoanScheduleParams scheduleParams, LocalDate date, BigDecimal periodBaseAmount) {
BigDecimal downPaymentAmount = MathUtil.percentageOf(periodBaseAmount,
loanApplicationTerms.getDisbursedAmountPercentageForDownPayment(), 19);
if (loanApplicationTerms.getInstallmentAmountInMultiplesOf() != null) {
downPaymentAmount = Money.roundToMultiplesOf(downPaymentAmount, loanApplicationTerms.getInstallmentAmountInMultiplesOf());
}
Money downPayment = Money.of(loanApplicationTerms.getCurrency(), downPaymentAmount);
LoanScheduleModelDownPaymentPeriod installment = LoanScheduleModelDownPaymentPeriod
.downPayment(scheduleParams.getInstalmentNumber(), date, downPayment, scheduleParams.getOutstandingBalance());
Expand Down Expand Up @@ -2238,8 +2249,12 @@ private LoanScheduleDTO rescheduleNextInstallments(final MathContext mc, final L
: loanApplicationTerms.getSubmittedOnDate();
BigDecimal downPaymentAmount = BigDecimal.ZERO;
if (loanApplicationTerms.isDownPaymentEnabled()) {
downPaymentAmount = MathUtil.percentageOf(loanScheduleParams.getOutstandingBalance().getAmount(),
loanApplicationTerms.getDisbursedAmountPercentageForDownPayment(), 19);
double downPaymentAmt = MathUtil.percentageOf(loanScheduleParams.getOutstandingBalance().getAmount(),
loanApplicationTerms.getDisbursedAmountPercentageForDownPayment(), 19).doubleValue();
if (loanApplicationTerms.getInstallmentAmountInMultiplesOf() != null) {
downPaymentAmt = Money.roundToMultiplesOf(downPaymentAmt, loanApplicationTerms.getInstallmentAmountInMultiplesOf());
}
downPaymentAmount = BigDecimal.valueOf(downPaymentAmt);
}
Money calculatedAmortizableAmount = principalToBeScheduled.minus(downPaymentAmount);
loanScheduleParams.setOutstandingBalance(calculatedAmortizableAmount);
Expand Down
Loading

0 comments on commit 7e893ea

Please sign in to comment.