FINERACT-1968: Fix when multiple disbursement happens on the 1st day of the loan

This commit is contained in:
Adam Saghy
2024-01-03 10:39:38 +01:00
committed by Arnold Gálovics
parent d3b626558f
commit 2f38d284df
3 changed files with 70 additions and 12 deletions
@@ -77,7 +77,8 @@ public abstract class AbstractProgressiveLoanScheduleGenerator implements LoanSc
: loanApplicationTerms.getSubmittedOnDate();
LoanScheduleParams scheduleParams = LoanScheduleParams.createLoanScheduleParams(currency,
Money.of(currency, chargesDueAtTimeOfDisbursement), periodStartDate, getPrincipalToBeScheduled(loanApplicationTerms));
Money.of(currency, chargesDueAtTimeOfDisbursement), periodStartDate,
getPrincipalToBeScheduled(loanApplicationTerms, periodStartDate));
List<LoanScheduleModelPeriod> periods = createNewLoanScheduleListWithDisbursementDetails(loanApplicationTerms, scheduleParams,
chargesDueAtTimeOfDisbursement);
@@ -233,12 +234,14 @@ public abstract class AbstractProgressiveLoanScheduleGenerator implements LoanSc
/**
* this method calculates the principal amount for generating the repayment schedule.
*/
private Money getPrincipalToBeScheduled(final LoanApplicationTerms loanApplicationTerms) {
private Money getPrincipalToBeScheduled(final LoanApplicationTerms loanApplicationTerms, LocalDate periodStartDate) {
Money principalToBeScheduled;
if (loanApplicationTerms.isMultiDisburseLoan()) {
if (loanApplicationTerms.getTotalDisbursedAmount().isGreaterThanZero()) {
principalToBeScheduled = Money.of(loanApplicationTerms.getCurrency(),
loanApplicationTerms.getDisbursementDatas().get(0).getPrincipal());
BigDecimal totalDisbursalAmountsOnThe = loanApplicationTerms.getDisbursementDatas().stream()
.filter(d -> d.getActualDisbursementDate().equals(periodStartDate)).map(DisbursementData::getPrincipal)
.reduce(BigDecimal.ZERO, BigDecimal::add);
principalToBeScheduled = Money.of(loanApplicationTerms.getCurrency(), totalDisbursalAmountsOnThe);
} else if (loanApplicationTerms.getApprovedPrincipal().isGreaterThanZero()) {
principalToBeScheduled = loanApplicationTerms.getApprovedPrincipal();
} else {