Skip to content

Commit 47012f4

Browse files
author
Jose Alberto Hernandez
committed
FINERACT-2181: Any amount payment after reage loan is overpaid
1 parent 8c3c44b commit 47012f4

File tree

2 files changed

+64
-17
lines changed

2 files changed

+64
-17
lines changed

fineract-e2e-tests-runner/src/test/resources/features/LoanReAging.feature

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,3 +4413,59 @@ Feature: LoanReAging
44134413
Then Loan Charges tab has the following data:
44144414
| Name | isPenalty | Payment due at | Due as of | Calculation type | Due | Paid | Waived | Outstanding |
44154415
| Snooze fee | false | Specified due date | 15 May 2024 | Flat | 10.0 | 0.0 | 0.0 | 10.0 |
4416+
4417+
@TestRailId:C4092 @AdvancedPaymentAllocation
4418+
Scenario: Verify Loan in case loan paid-off the status is closed outstanding amount is 0, in case any repayment amount less that paid-off amount the status is active with correct outstanding amount
4419+
When Admin sets the business date to "01 January 2025"
4420+
When Admin creates a client with random data
4421+
And Admin creates a fully customized loan with the following data:
4422+
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
4423+
| LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_IR_DAILY_TILL_PRECLOSE_LAST_INSTALLMENT_STRATEGY | 01 January 2025 | 1000.0 | 0 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
4424+
And Admin successfully approves the loan on "01 January 2025" with "1000" amount and expected disbursement date on "01 January 2025"
4425+
When Admin successfully disburse the loan on "01 January 2025" with "1000" EUR transaction amount
4426+
Then Loan Repayment schedule has 6 periods, with the following data for periods:
4427+
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
4428+
| | | 01 January 2025 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
4429+
| 1 | 31 | 01 February 2025 | | 833.33 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4430+
| 2 | 28 | 01 March 2025 | | 666.66 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4431+
| 3 | 31 | 01 April 2025 | | 499.99 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4432+
| 4 | 30 | 01 May 2025 | | 333.32 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4433+
| 5 | 31 | 01 June 2025 | | 166.65 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4434+
| 6 | 30 | 01 July 2025 | | 0.0 | 166.65 | 0.0 | 0.0 | 0.0 | 166.65 | 0.0 | 0.0 | 0.0 | 166.65 |
4435+
Then Loan Repayment schedule has the following data in Total row:
4436+
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
4437+
| 1000.0 | 0.0 | 0.0 | 0.0 | 1000.0 | 0.0 | 0.0 | 0.0 | 1000.0 |
4438+
Then Loan Transactions tab has the following data:
4439+
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted |
4440+
| 01 January 2025 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false |
4441+
# --- make early repayment --- #
4442+
When Admin sets the business date to "15 January 2025"
4443+
And Customer makes "AUTOPAY" repayment on "15 January 2025" with 166.65 EUR transaction amount
4444+
Then Loan Repayment schedule has 6 periods, with the following data for periods:
4445+
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
4446+
| | | 01 January 2025 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
4447+
| 1 | 31 | 01 February 2025 | | 833.33 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4448+
| 2 | 28 | 01 March 2025 | | 666.66 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4449+
| 3 | 31 | 01 April 2025 | | 499.99 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4450+
| 4 | 30 | 01 May 2025 | | 333.32 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4451+
| 5 | 31 | 01 June 2025 | | 166.65 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 | 0.0 | 0.0 | 0.0 | 166.67 |
4452+
| 6 | 30 | 01 July 2025 | 15 January 2025 | 0.0 | 166.65 | 0.0 | 0.0 | 0.0 | 166.65 | 166.65 | 166.65 | 0.0 | 0.0 |
4453+
Then Loan Repayment schedule has the following data in Total row:
4454+
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
4455+
| 1000.0 | 0.0 | 0.0 | 0.0 | 1000.0 | 166.65 | 166.65 | 0.0 | 833.35 |
4456+
Then Loan Transactions tab has the following data:
4457+
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted |
4458+
| 01 January 2025 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false |
4459+
| 15 January 2025 | Repayment | 166.65 | 166.65 | 0.0 | 0.0 | 0.0 | 833.35 | false |
4460+
# --- re-age loan on 1st installment ---#
4461+
When Admin creates a Loan re-aging transaction by Loan external ID with the following data:
4462+
| frequencyNumber | frequencyType | startDate | numberOfInstallments |
4463+
| 1 | MONTHS | 16 January 2025 | 8 |
4464+
Then Loan Transactions tab has the following data:
4465+
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted |
4466+
| 01 January 2025 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false |
4467+
| 15 January 2025 | Repayment | 166.65 | 166.65 | 0.0 | 0.0 | 0.0 | 833.35 | false |
4468+
| 15 January 2025 | Re-age | 833.35 | 833.35 | 0.0 | 0.0 | 0.0 | 0.0 | false |
4469+
When Loan Pay-off is made on "15 January 2025"
4470+
Then Loan status will be "CLOSED_OBLIGATIONS_MET"
4471+
Then Loan has 0 outstanding amount

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,11 @@
4646
import org.apache.fineract.portfolio.loanaccount.api.LoanReAgingApiConstants;
4747
import org.apache.fineract.portfolio.loanaccount.data.ScheduleGeneratorDTO;
4848
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
49-
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleTransactionProcessorFactory;
5049
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
5150
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
5251
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
5352
import org.apache.fineract.portfolio.loanaccount.domain.reaging.LoanReAgeInterestHandlingType;
5453
import org.apache.fineract.portfolio.loanaccount.domain.reaging.LoanReAgeParameter;
55-
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.LoanRepaymentScheduleTransactionProcessor;
56-
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.MoneyHolder;
57-
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.TransactionCtx;
5854
import org.apache.fineract.portfolio.loanaccount.exception.LoanTransactionNotFoundException;
5955
import org.apache.fineract.portfolio.loanaccount.serialization.LoanChargeValidator;
6056
import org.apache.fineract.portfolio.loanaccount.service.LoanAssembler;
@@ -76,7 +72,6 @@ public class LoanReAgingServiceImpl {
7672
private final ExternalIdFactory externalIdFactory;
7773
private final BusinessEventNotifierService businessEventNotifierService;
7874
private final LoanTransactionRepository loanTransactionRepository;
79-
private final LoanRepaymentScheduleTransactionProcessorFactory loanRepaymentScheduleTransactionProcessorFactory;
8075
private final NoteRepository noteRepository;
8176
private final LoanChargeValidator loanChargeValidator;
8277
private final LoanUtilService loanUtilService;
@@ -96,25 +91,21 @@ public CommandProcessingResult reAge(Long loanId, JsonCommand command) {
9691
LoanReAgeParameter reAgeParameter = createReAgeParameter(reAgeTransaction, command);
9792
reAgeTransaction.setLoanReAgeParameter(reAgeParameter);
9893
loanTransactionRepository.saveAndFlush(reAgeTransaction);
99-
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = loanRepaymentScheduleTransactionProcessorFactory
100-
.determineProcessor(loan.transactionProcessingStrategy());
10194
if (reAgeTransaction.getTransactionDate().isBefore(reAgeTransaction.getSubmittedOnDate())
10295
&& !loan.isInterestBearingAndInterestRecalculationEnabled()) {
10396
reprocessLoanTransactionsService.reprocessTransactionsWithPostTransactionChecks(loan, reAgeTransaction.getTransactionDate());
104-
} else if (loan.isInterestBearingAndInterestRecalculationEnabled()) {
105-
if (loan.isProgressiveSchedule() && ((loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy())
106-
|| loan.hasContractTerminationTransaction()
107-
|| (loan.isInterestRecalculationEnabled() && loan.hasReAgingTransaction()))) {
108-
final ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan, null);
109-
loanScheduleService.regenerateRepaymentSchedule(loan, scheduleGeneratorDTO);
97+
} else {
98+
if (loan.isInterestBearingAndInterestRecalculationEnabled()) {
99+
if (loan.isProgressiveSchedule() && ((loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy())
100+
|| loan.hasContractTerminationTransaction()
101+
|| (loan.isInterestRecalculationEnabled() && loan.hasReAgingTransaction()))) {
102+
final ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan, null);
103+
loanScheduleService.regenerateRepaymentSchedule(loan, scheduleGeneratorDTO);
104+
}
110105
}
111106
final List<LoanTransaction> loanTransactions = loanTransactionRepository.findNonReversedTransactionsForReprocessingByLoan(loan);
112107
loanTransactions.add(reAgeTransaction);
113108
reprocessLoanTransactionsService.reprocessParticularTransactions(loan, loanTransactions);
114-
} else {
115-
loanRepaymentScheduleTransactionProcessor.processLatestTransaction(reAgeTransaction,
116-
new TransactionCtx(loan.getCurrency(), loan.getRepaymentScheduleInstallments(), loan.getActiveCharges(),
117-
new MoneyHolder(loan.getTotalOverpaidAsMoney()), null));
118109
}
119110
loan.updateLoanScheduleDependentDerivedFields();
120111
persistNote(loan, command, changes);

0 commit comments

Comments
 (0)