Skip to content

Commit

Permalink
FINERACT-2060: Fix balance of reamortization at the event of reverse-…
Browse files Browse the repository at this point in the history
…replay
  • Loading branch information
adamsaghy committed Apr 8, 2024
1 parent 60b4a61 commit 4c503ff
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ Feature: LoanReAmortization
| 01 January 2024 | Disbursement | 500.0 | 0.0 | 0.0 | 0.0 | 0.0 | 500.0 |
| 01 January 2024 | Down Payment | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 | 375.0 |
| 15 January 2024 | Repayment | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 | 250.0 |
| 01 February 2024 | Re-amortize | 375.0 | 375.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 01 February 2024 | Re-amortize | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 | 0.0 |

@TestRailId:C3076 @AdvancedPaymentAllocation
Scenario: Verify Loan re-amortization transaction - UC4: N+1 Installment scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public void processLatestTransaction(LoanTransaction loanTransaction, Transactio

private void handleReAmortization(LoanTransaction loanTransaction, MonetaryCurrency currency,
List<LoanRepaymentScheduleInstallment> installments) {
BigDecimal remainingAmount = loanTransaction.getAmount();
LocalDate transactionDate = loanTransaction.getTransactionDate();
List<LoanRepaymentScheduleInstallment> previousInstallments = installments.stream() //
.filter(installment -> !installment.getDueDate().isAfter(transactionDate)) //
Expand All @@ -224,28 +223,26 @@ private void handleReAmortization(LoanTransaction loanTransaction, MonetaryCurre
installment.updateDerivedFields(currency, transactionDate);
}

if (overallOverDuePrincipal.compareTo(remainingAmount) != 0) {
remainingAmount = overallOverDuePrincipal;
loanTransaction.updateComponentsAndTotal(Money.of(currency, remainingAmount), Money.zero(currency), Money.zero(currency),
Money.zero(currency));
}
loanTransaction.resetDerivedComponents();
loanTransaction.updateComponentsAndTotal(Money.of(currency, overallOverDuePrincipal), Money.zero(currency), Money.zero(currency),
Money.zero(currency));

LoanRepaymentScheduleInstallment lastFutureInstallment = futureInstallments.stream()
.max(Comparator.comparing(LoanRepaymentScheduleInstallment::getDueDate)).get();
BigDecimal reAmortizationAmountPerInstallment = remainingAmount.divide(BigDecimal.valueOf(futureInstallments.size()),
BigDecimal reAmortizationAmountPerInstallment = overallOverDuePrincipal.divide(BigDecimal.valueOf(futureInstallments.size()),
MoneyHelper.getRoundingMode());
Integer installmentAmountInMultiplesOf = loanTransaction.getLoan().getLoanProduct().getInstallmentAmountInMultiplesOf();

for (LoanRepaymentScheduleInstallment installment : futureInstallments) {
if (lastFutureInstallment.equals(installment)) {
installment.addToPrincipal(transactionDate, Money.of(currency, remainingAmount));
installment.addToPrincipal(transactionDate, Money.of(currency, overallOverDuePrincipal));
} else {
if (installmentAmountInMultiplesOf != null) {
reAmortizationAmountPerInstallment = Money.roundToMultiplesOf(reAmortizationAmountPerInstallment,
installmentAmountInMultiplesOf);
}
installment.addToPrincipal(transactionDate, Money.of(currency, reAmortizationAmountPerInstallment));
remainingAmount = remainingAmount.subtract(reAmortizationAmountPerInstallment);
overallOverDuePrincipal = overallOverDuePrincipal.subtract(reAmortizationAmountPerInstallment);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class LoanTestLifecycleExtension implements AfterEachCallback {
private DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().appendPattern("dd MMMM yyyy").toFormatter();

@Override
public void afterEach(ExtensionContext context) throws Exception {
public void afterEach(ExtensionContext context) {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
Expand Down
Loading

0 comments on commit 4c503ff

Please sign in to comment.