Skip to content

Commit

Permalink
FINERACT-2081: Apply penalty to overdue loans enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Alberto Hernandez committed Sep 2, 2024
1 parent d5d7f7f commit fdfdf2d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class ApplyChargeToOverdueLoansBusinessStep implements LoanCOBBusinessSte
public Loan execute(Loan loan) {
final Collection<OverdueLoanScheduleData> overdueLoanScheduleDataList = loanReadPlatformService
.retrieveAllOverdueInstallmentsForLoan(loan);
loanChargeWritePlatformService.applyOverdueChargesForLoan(loan.getId(), overdueLoanScheduleDataList);
if (!overdueLoanScheduleDataList.isEmpty()) {
loanChargeWritePlatformService.applyOverdueChargesForLoan(loan.getId(), overdueLoanScheduleDataList);
}
return loan;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
List<Throwable> exceptions = new ArrayList<>();
for (Map.Entry<Long, Collection<OverdueLoanScheduleData>> entry : overdueScheduleData.entrySet()) {
try {
loanChargeWritePlatformService.applyOverdueChargesForLoan(entry.getKey(), entry.getValue());

if (!entry.getValue().isEmpty()) {
loanChargeWritePlatformService.applyOverdueChargesForLoan(entry.getKey(), entry.getValue());
}
} catch (final PlatformApiDataValidationException e) {
final List<ApiParameterError> errors = e.getErrors();
for (final ApiParameterError error : errors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -757,11 +758,19 @@ public CommandProcessingResult adjustmentForLoanCharge(Long loanId, Long loanCha
@Transactional
@Override
public void applyOverdueChargesForLoan(final Long loanId, Collection<OverdueLoanScheduleData> overdueLoanScheduleDataList) {
if (overdueLoanScheduleDataList.isEmpty()) {
return;
}
Loan loan = this.loanAssembler.assembleFrom(loanId);
if (loan.isChargedOff()) {
log.warn("Adding charge to Loan: {} is not allowed. Loan Account is Charged-off", loanId);
return;
}
Optional<Charge> optPenaltyCharge = loan.getLoanProduct().getCharges().stream()
.filter((e) -> ChargeTimeType.OVERDUE_INSTALLMENT.getValue().equals(e.getChargeTimeType()) && e.isLoanCharge()).findFirst();
if (optPenaltyCharge.isEmpty()) {
return;
}
final List<Long> existingTransactionIds = loan.findExistingTransactionIds();
final List<Long> existingReversedTransactionIds = loan.findExistingReversedTransactionIds();
boolean runInterestRecalculation = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,15 @@ public Collection<OverdueLoanScheduleData> retrieveAllOverdueInstallmentsForLoan
if (!loan.isOpen()) {
return list;
}

Optional<Charge> optPenaltyCharge = loan.getLoanProduct().getCharges().stream()
.filter((e) -> ChargeTimeType.OVERDUE_INSTALLMENT.getValue().equals(e.getChargeTimeType()) && e.isLoanCharge()).findFirst();

if (optPenaltyCharge.isEmpty()) {
return list;
}
final Charge penaltyCharge = optPenaltyCharge.get();

final Long penaltyWaitPeriod = configurationDomainService.retrievePenaltyWaitPeriod();
final boolean backdatePenalties = configurationDomainService.isBackdatePenaltiesEnabled();

Expand All @@ -1657,16 +1666,9 @@ public Collection<OverdueLoanScheduleData> retrieveAllOverdueInstallmentsForLoan
if (!backdatePenalties && !isDueToday) {
continue;
}
Optional<Charge> penaltyCharge = loan.getLoanProduct().getCharges().stream()
.filter((e) -> ChargeTimeType.OVERDUE_INSTALLMENT.getValue().equals(e.getChargeTimeType()) && e.isLoanCharge())
.findFirst();

if (penaltyCharge.isEmpty()) {
continue;
}

list.add(new OverdueLoanScheduleData(loan.getId(), penaltyCharge.get().getId(),
DateUtils.DEFAULT_DATE_FORMATTER.format(installment.getDueDate()), penaltyCharge.get().getAmount(),
list.add(new OverdueLoanScheduleData(loan.getId(), penaltyCharge.getId(),
DateUtils.DEFAULT_DATE_FORMATTER.format(installment.getDueDate()), penaltyCharge.getAmount(),
DateUtils.DEFAULT_DATE_FORMAT, Locale.ENGLISH.toLanguageTag(),
installment.getPrincipalOutstanding(loan.getCurrency()).getAmount(),
installment.getInterestOutstanding(loan.getCurrency()).getAmount(), installment.getInstallmentNumber()));
Expand Down

0 comments on commit fdfdf2d

Please sign in to comment.