FINERACT-2220: Use stored ProgressiveLoanInterestScheduleModel for processLatestTransaction if applicable

This commit is contained in:
Soma Sörös
2025-05-16 10:03:54 +02:00
committed by Adam Saghy
parent 1fc2aae654
commit cd03dc020e
9 changed files with 129 additions and 51 deletions
@@ -127,34 +127,28 @@ public class LoanDownPaymentHandlerServiceImpl implements LoanDownPaymentHandler
final LoanRepaymentScheduleInstallment currentInstallment = loan
.fetchLoanRepaymentScheduleInstallmentByDueDate(loanTransaction.getTransactionDate());
boolean reprocess = loan.isForeclosure() || !isTransactionChronologicallyLatest || adjustedTransaction != null
|| !DateUtils.isEqualBusinessDate(loanTransaction.getTransactionDate()) || currentInstallment == null
|| !currentInstallment.getTotalOutstanding(loan.getCurrency()).isEqualTo(loanTransaction.getAmount(loan.getCurrency()));
// TODO FINERACT-2220 fix processLatestTransaction to save model.
if (loan.isProgressiveSchedule() && loan.isInterestBearing()) {
reprocess = true;
}
if (isTransactionChronologicallyLatest && adjustedTransaction == null
&& (!reprocess || !loan.isInterestBearingAndInterestRecalculationEnabled()) && !loan.isForeclosure()) {
boolean reprocessOnPostConditions = false;
boolean processLatest = isTransactionChronologicallyLatest //
&& adjustedTransaction == null // covers reversals
&& !loan.isForeclosure() //
&& loanTransactionProcessingService.canProcessLatestTransactionOnly(loan, loanTransaction, currentInstallment); //
if (processLatest) {
loanTransactionProcessingService.processLatestTransaction(loan.getTransactionProcessingStrategyCode(), loanTransaction,
new TransactionCtx(loan.getCurrency(), loan.getRepaymentScheduleInstallments(), loan.getActiveCharges(),
new MoneyHolder(loan.getTotalOverpaidAsMoney()), null));
reprocess = false;
if (loan.isInterestBearingAndInterestRecalculationEnabled()) {
if (!loan.isProgressiveSchedule() && loan.isInterestBearingAndInterestRecalculationEnabled()) {
if (currentInstallment == null || currentInstallment.isNotFullyPaidOff()) {
reprocess = true;
reprocessOnPostConditions = true;
} else {
final LoanRepaymentScheduleInstallment nextInstallment = loan
.fetchRepaymentScheduleInstallment(currentInstallment.getInstallmentNumber() + 1);
if (nextInstallment != null && nextInstallment.getTotalPaidInAdvance(loan.getCurrency()).isGreaterThanZero()) {
reprocess = true;
reprocessOnPostConditions = true;
}
}
}
}
if (reprocess) {
if (!processLatest || reprocessOnPostConditions) {
if (loan.isCumulativeSchedule() && loan.isInterestBearingAndInterestRecalculationEnabled()) {
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, scheduleGeneratorDTO);
} else if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
@@ -36,6 +36,9 @@ import org.apache.fineract.portfolio.loanaccount.loanschedule.data.LoanScheduleD
public interface LoanTransactionProcessingService {
boolean canProcessLatestTransactionOnly(Loan loan, LoanTransaction loanTransaction,
LoanRepaymentScheduleInstallment currentInstallment);
ChangedTransactionDetail processLatestTransaction(String transactionProcessingStrategyCode, LoanTransaction loanTransaction,
TransactionCtx ctx);