FINERACT-1971: Accrual for interest bearing loan with charge accrual based on submitted On Date fix

This commit is contained in:
Ruchi Dhamankar
2024-06-06 14:08:02 +02:00
committed by Adam Saghy
parent 4bf93fdde7
commit a078cfd8c5
2 changed files with 253 additions and 3 deletions
@@ -1358,9 +1358,7 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
Money fee = Money.zero(getCurrency());
Money penality = Money.zero(getCurrency());
for (LoanTransaction loanTransaction : accruals) {
LocalDate transactionDateForRange = isBasedOnSubmittedOnDate
? loanTransaction.getLoanChargesPaid().stream().findFirst().get().getLoanCharge().getDueDate()
: loanTransaction.getTransactionDate();
LocalDate transactionDateForRange = getDateForRangeCalculation(loanTransaction, isBasedOnSubmittedOnDate);
boolean isInPeriod = LoanRepaymentScheduleProcessingWrapper.isInPeriod(transactionDateForRange, installment, installments);
if (isInPeriod) {
interest = interest.plus(loanTransaction.getInterestPortion(getCurrency()));
@@ -1389,6 +1387,12 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
}
}
private LocalDate getDateForRangeCalculation(LoanTransaction loanTransaction, boolean isChargeAccrualBasedOnSubmittedOnDate) {
return isChargeAccrualBasedOnSubmittedOnDate && !loanTransaction.getLoanChargesPaid().isEmpty()
? loanTransaction.getLoanChargesPaid().stream().findFirst().get().getLoanCharge().getEffectiveDueDate()
: loanTransaction.getTransactionDate();
}
private void updateAccrualsForNonPeriodicAccruals(final Collection<LoanTransaction> accruals) {
final Money interestApplied = Money.of(getCurrency(), this.summary.getTotalInterestCharged());
ExternalId externalId = ExternalId.empty();