Skip to content

Commit

Permalink
FINERACT-2114: EMI Calculator outstanding balance correction
Browse files Browse the repository at this point in the history
  • Loading branch information
janez89 committed Sep 4, 2024
1 parent a6e3517 commit e47325a
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public class ProgressiveLoanInterestRepaymentInterestPeriod implements Comparabl
private BigDecimal rateFactorMinus1;

private Money disbursedAmount;
private Money correctionAmount;
private Money interestDue;

public ProgressiveLoanInterestRepaymentInterestPeriod(final ProgressiveLoanInterestRepaymentInterestPeriod period) {
this(period.fromDate, period.dueDate, period.rateFactorMinus1, period.disbursedAmount, period.interestDue);
this(period.fromDate, period.dueDate, period.rateFactorMinus1, period.disbursedAmount, period.correctionAmount, period.interestDue);
}

@Override
Expand All @@ -47,6 +48,14 @@ public int compareTo(@NotNull ProgressiveLoanInterestRepaymentInterestPeriod o)
}

public void addDisbursedAmount(final Money outstandingBalance) {
this.disbursedAmount = this.disbursedAmount.add(outstandingBalance);
if (outstandingBalance != null && !outstandingBalance.isZero()) {
this.disbursedAmount = this.disbursedAmount.add(outstandingBalance);
}
}

public void addCorrectionAmount(final Money correctionAmount) {
if (correctionAmount != null && !correctionAmount.isZero()) {
this.correctionAmount = this.correctionAmount.add(correctionAmount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,34 @@ public class ProgressiveLoanInterestRepaymentModel {

private LinkedList<ProgressiveLoanInterestRepaymentInterestPeriod> interestPeriods;

private boolean isLastPeriod;

private Money equalMonthlyInstallment;
private Money principalDue;
private Money remainingBalance;
private Money outstandingBalance;

public ProgressiveLoanInterestRepaymentModel(final LocalDate fromDate, final LocalDate dueDate, final Money equalMonthlyInstallment) {
this.fromDate = fromDate;
this.dueDate = dueDate;
this.equalMonthlyInstallment = equalMonthlyInstallment;
this.isLastPeriod = false;

final Money zeroAmount = Money.zero(equalMonthlyInstallment.getCurrency());
this.outstandingBalance = zeroAmount;
this.remainingBalance = zeroAmount;
this.principalDue = zeroAmount;
this.interestPeriods = new LinkedList<>();
this.interestPeriods
.add(new ProgressiveLoanInterestRepaymentInterestPeriod(fromDate, dueDate, BigDecimal.ZERO, zeroAmount, zeroAmount));
this.interestPeriods.add(
new ProgressiveLoanInterestRepaymentInterestPeriod(fromDate, dueDate, BigDecimal.ZERO, zeroAmount, zeroAmount, zeroAmount));
}

public ProgressiveLoanInterestRepaymentModel(ProgressiveLoanInterestRepaymentModel repaymentModel) {
this.fromDate = repaymentModel.fromDate;
this.dueDate = repaymentModel.dueDate;
this.isLastPeriod = repaymentModel.isLastPeriod;
this.equalMonthlyInstallment = repaymentModel.equalMonthlyInstallment;
this.outstandingBalance = repaymentModel.outstandingBalance;
this.remainingBalance = repaymentModel.remainingBalance;
this.principalDue = repaymentModel.principalDue;
this.interestPeriods = new LinkedList<>();
Expand All @@ -76,7 +83,12 @@ public Money getInterestDue() {
.reduce(Money.zero(equalMonthlyInstallment.getCurrency()), Money::plus);
}

public Money getOutstandingBalance() {
return remainingBalance.plus(principalDue);
public Money getCorrectionAmount() {
return interestPeriods.stream().map(ProgressiveLoanInterestRepaymentInterestPeriod::getCorrectionAmount)
.reduce(Money.zero(equalMonthlyInstallment.getCurrency()), Money::plus);
}

public Money getCorrectedOutstandingBalance() {
return outstandingBalance.plus(getCorrectionAmount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Optional<ProgressiveLoanInterestRepaymentModel> findInterestRepaymentPeriod(Prog
void changeInterestRate(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate newInterestEffectiveDate,
BigDecimal newInterestRate);

void addBalanceCorrection(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate balanceCorrectionDate,
Money balanceCorrectionAmount);

Optional<ProgressiveLoanInterestRepaymentModel> getPayableDetails(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate date);

ProgressiveLoanInterestScheduleModel makeScheduleModelDeepCopy(ProgressiveLoanInterestScheduleModel scheduleModel);

ProgressiveLoanInterestScheduleModel makeScheduleModelDeepCopy(ProgressiveLoanInterestScheduleModel scheduleModel,
Expand Down
Loading

0 comments on commit e47325a

Please sign in to comment.