FINERACT-2179: Advance Payment Allocation- Next-Last Option behaviour change

This commit is contained in:
mariiaKraievska
2025-05-16 15:51:16 +02:00
committed by Adam Saghy
parent 6d49d76e73
commit ed42fb2410
3 changed files with 99 additions and 22 deletions
@@ -4437,14 +4437,14 @@ Feature: LoanRepayment
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 31 | 01 February 2024 | 01 February 2024 | 83.57 | 16.43 | 0.58 | 0.0 | 0.0 | 17.01 | 17.01 | 0.0 | 0.0 | 0.0 |
| 2 | 29 | 01 March 2024 | | 67.03 | 16.54 | 0.47 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 3 | 31 | 01 April 2024 | | 50.39 | 16.64 | 0.37 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 4 | 30 | 01 May 2024 | | 33.66 | 16.73 | 0.28 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 5 | 31 | 01 June 2024 | | 16.83 | 16.83 | 0.18 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 6 | 30 | 01 July 2024 | | 0.0 | 16.83 | 0.08 | 0.0 | 0.0 | 16.91 | 2.99 | 2.99 | 0.0 | 13.92 |
| 2 | 29 | 01 March 2024 | | 67.03 | 16.54 | 0.47 | 0.0 | 0.0 | 17.01 | 2.99 | 2.99 | 0.0 | 14.02 |
| 3 | 31 | 01 April 2024 | | 50.41 | 16.62 | 0.39 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 4 | 30 | 01 May 2024 | | 33.69 | 16.72 | 0.29 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 5 | 31 | 01 June 2024 | | 16.88 | 16.81 | 0.2 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 6 | 30 | 01 July 2024 | | 0.0 | 16.88 | 0.1 | 0.0 | 0.0 | 16.98 | 0.0 | 0.0 | 0.0 | 16.98 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 100.0 | 1.96 | 0.0 | 0.0 | 101.96 | 20.0 | 2.99 | 0.0 | 81.96 |
| 100.0 | 2.03 | 0.0 | 0.0 | 102.03 | 20.0 | 2.99 | 0.0 | 82.03 |
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 | false | false |
@@ -5327,4 +5327,83 @@ Feature: LoanRepayment
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted |
| 03 June 2025 | Disbursement | 200.0 | 0.0 | 0.0 | 0.0 | 0.0 | 200.0 | false |
| 18 June 2025 | Merchant Issued Refund | 50.0 | 50.0 | 0.0 | 0.0 | 0.0 | 150.0 | false |
| 18 June 2025 | Interest Refund | 0.31 | 0.31 | 0.0 | 0.0 | 0.0 | 149.69 | false |
| 18 June 2025 | Interest Refund | 0.31 | 0.31 | 0.0 | 0.0 | 0.0 | 149.69 | false |
@TestRailId:C3666
Scenario: Verify the next/last installment payment allocation in case the repayment is before the installment date
When Admin sets the business date to "01 January 2024"
When Admin creates a client with random data
When Admin set "LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL" loan product "DEFAULT" transaction type to "NEXT_LAST_INSTALLMENT" future installment allocation rule
When Admin creates a fully customized loan with the following data:
| 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 |
| LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL | 01 January 2024 | 100 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2024" with "100" amount and expected disbursement date on "01 January 2024"
When Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount
When Admin sets the business date to "15 January 2024"
And Customer makes "AUTOPAY" repayment on "15 January 2024" with 10 EUR transaction amount
Then Loan Repayment schedule has 6 periods, with the following data for periods:
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 31 | 01 February 2024 | | 83.54 | 16.46 | 0.55 | 0.0 | 0.0 | 17.01 | 10.0 | 10.0 | 0.0 | 7.01 |
| 2 | 29 | 01 March 2024 | | 67.02 | 16.52 | 0.49 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 3 | 31 | 01 April 2024 | | 50.4 | 16.62 | 0.39 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 4 | 30 | 01 May 2024 | | 33.68 | 16.72 | 0.29 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 5 | 31 | 01 June 2024 | | 16.87 | 16.81 | 0.2 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 6 | 30 | 01 July 2024 | | 0.0 | 16.87 | 0.1 | 0.0 | 0.0 | 16.97 | 0.0 | 0.0 | 0.0 | 16.97 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 100.0 | 2.02 | 0.0 | 0.0 | 102.02 | 10.0 | 10.0 | 0.0 | 92.02 |
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 | false | false |
| 15 January 2024 | Repayment | 10.0 | 9.74 | 0.26 | 0.0 | 0.0 | 90.26 | false | false |
When Admin sets the business date to "15 February 2024"
And Customer makes "AUTOPAY" repayment on "15 February 2024" with 30 EUR transaction amount
Then Loan Repayment schedule has 6 periods, with the following data for periods:
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 31 | 01 February 2024 | 15 February 2024 | 83.54 | 16.46 | 0.55 | 0.0 | 0.0 | 17.01 | 17.01 | 10.0 | 7.01 | 0.0 |
| 2 | 29 | 01 March 2024 | 15 February 2024 | 66.78 | 16.76 | 0.25 | 0.0 | 0.0 | 17.01 | 17.01 | 17.01 | 0.0 | 0.0 |
| 3 | 31 | 01 April 2024 | | 50.31 | 16.47 | 0.54 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 4 | 30 | 01 May 2024 | | 33.56 | 16.75 | 0.26 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 5 | 31 | 01 June 2024 | | 16.71 | 16.85 | 0.16 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 6 | 30 | 01 July 2024 | | 0.0 | 16.71 | 0.06 | 0.0 | 0.0 | 16.77 | 5.98 | 5.98 | 0.0 | 10.79 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 100.0 | 1.82 | 0.0 | 0.0 | 101.82 | 40.0 | 32.99 | 7.01 | 61.82 |
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 | false | false |
| 15 January 2024 | Repayment | 10.0 | 9.74 | 0.26 | 0.0 | 0.0 | 90.26 | false | false |
| 15 February 2024 | Repayment | 30.0 | 29.46 | 0.54 | 0.0 | 0.0 | 60.8 | false | false |
When Admin set "LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL" loan product "DEFAULT" transaction type to "NEXT_INSTALLMENT" future installment allocation rule
@TestRailId:C3667
Scenario: Verify the next/last installment payment allocation in case the repayment is on the installment date, amount should go first to the next installment and only then to the last
When Admin sets the business date to "01 January 2024"
When Admin creates a client with random data
When Admin set "LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL" loan product "DEFAULT" transaction type to "NEXT_LAST_INSTALLMENT" future installment allocation rule
When Admin creates a fully customized loan with the following data:
| 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 |
| LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL | 01 January 2024 | 100 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2024" with "100" amount and expected disbursement date on "01 January 2024"
When Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount
When Admin sets the business date to "01 February 2024"
And Customer makes "AUTOPAY" repayment on "01 February 2024" with 40 EUR transaction amount
Then Loan Repayment schedule has 6 periods, with the following data for periods:
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 31 | 01 February 2024 | 01 February 2024 | 83.57 | 16.43 | 0.58 | 0.0 | 0.0 | 17.01 | 17.01 | 0.0 | 0.0 | 0.0 |
| 2 | 29 | 01 March 2024 | 01 February 2024 | 66.56 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 | 17.01 | 17.01 | 0.0 | 0.0 |
| 3 | 31 | 01 April 2024 | | 50.25 | 16.31 | 0.7 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 4 | 30 | 01 May 2024 | | 33.5 | 16.75 | 0.26 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 5 | 31 | 01 June 2024 | | 16.65 | 16.85 | 0.16 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
| 6 | 30 | 01 July 2024 | | 0.0 | 16.65 | 0.06 | 0.0 | 0.0 | 16.71 | 5.98 | 5.98 | 0.0 | 10.73 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 100.0 | 1.76 | 0.0 | 0.0 | 101.76 | 40.0 | 22.99 | 0.0 | 61.76 |
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 | false | false |
| 01 February 2024 | Repayment | 40.0 | 39.42 | 0.58 | 0.0 | 0.0 | 60.58 | false | false |
When Admin set "LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL" loan product "DEFAULT" transaction type to "NEXT_INSTALLMENT" future installment allocation rule
@@ -1867,9 +1867,8 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
} else if (FutureInstallmentAllocationRule.NEXT_LAST_INSTALLMENT.equals(futureInstallmentAllocationRule)) {
// try to resolve as current installment ( not due )
inAdvanceInstallments = installments.stream().filter(installment -> installment.getTotalPaid(currency).isGreaterThanZero())
.filter(e -> loanTransaction.isBefore(e.getDueDate())).filter(f -> loanTransaction.isAfter(f.getFromDate())
|| (loanTransaction.isOn(f.getFromDate()) && f.getInstallmentNumber() == 1))
.toList();
.filter(e -> loanTransaction.isBefore(e.getDueDate()))
.filter(f -> loanTransaction.isAfter(f.getFromDate()) || loanTransaction.isOn(f.getFromDate())).toList();
// if there is no current installment, resolve similar to LAST_INSTALLMENT
if (inAdvanceInstallments.isEmpty()) {
inAdvanceInstallments = installments.stream().filter(installment -> installment.getTotalPaid(currency).isGreaterThanZero())
@@ -1993,7 +1992,7 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
.filter(LoanRepaymentScheduleInstallment::isNotFullyPaidOff) //
.filter(e -> context.getLoanTransaction().isBefore(e.getDueDate())) //
.filter(f -> context.getLoanTransaction().isAfter(f.getFromDate())
|| (context.getLoanTransaction().isOn(f.getFromDate()) && f.getInstallmentNumber() == 1)) //
|| context.getLoanTransaction().isOn(f.getFromDate())) //
.toList(); //
// if there is no current installment, resolve similar to LAST_INSTALLMENT
if (inAdvanceInstallments.isEmpty()) {
@@ -2299,8 +2298,7 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
currentInstallments = context.getCtx().getInstallments().stream().filter(predicate)
.filter(e -> context.getLoanTransaction().isBefore(e.getDueDate()))
.filter(f -> context.getLoanTransaction().isAfter(f.getFromDate())
|| (context.getLoanTransaction().isOn(f.getFromDate())
&& f.getInstallmentNumber() == 1))
|| context.getLoanTransaction().isOn(f.getFromDate()))
.toList();
// if there is no current in advance installment resolve similar to LAST_INSTALLMENT
if (currentInstallments.isEmpty()) {
@@ -85,8 +85,8 @@ public class ProgressiveLoanTransactionProcessorNextLastTest extends BaseLoanInt
loanTransactionHelper.makeLoanRepayment(loanId, "Repayment", "1 March 2024", 26.0);
verifyRepaymentSchedule(loanId, installment(100.0, null, "01 January 2024"),
installment(14.97, 5.03, 0.0, true, "01 February 2024"), installment(15.7, 4.3, 0.0, true, "01 March 2024"),
installment(17.03, 2.97, 20.0, false, "01 April 2024"), installment(17.96, 2.04, 20.0, false, "01 May 2024"),
installment(18.94, 1.06, 20.0, false, "01 June 2024"), installment(15.4, 0.02, 0.42, false, "01 July 2024"));
installment(17.03, 2.97, 14.0, false, "01 April 2024"), installment(17.63, 2.37, 20.0, false, "01 May 2024"),
installment(18.59, 1.41, 20.0, false, "01 June 2024"), installment(16.08, 0.39, 7.47, false, "01 July 2024"));
});
runAt("2 March 2024", () -> {
Long loanId = loanIdRef.get();
@@ -94,26 +94,26 @@ public class ProgressiveLoanTransactionProcessorNextLastTest extends BaseLoanInt
loanTransactionHelper.makeLoanRepayment(loanId, "Repayment", "2 March 2024", 7.0);
verifyRepaymentSchedule(loanId, installment(100.0, null, "01 January 2024"),
installment(14.97, 5.03, 0.0, true, "01 February 2024"), installment(15.7, 4.3, 0.0, true, "01 March 2024"),
installment(17.4, 2.6, 13.0, false, "01 April 2024"), installment(17.98, 2.02, 20.0, false, "01 May 2024"),
installment(18.95, 1.04, 19.99, false, "01 June 2024"), installment(15.0, 0.0, 0.0, true, "01 July 2024"));
installment(17.4, 2.6, 7.0, false, "01 April 2024"), installment(17.65, 2.35, 20.0, false, "01 May 2024"),
installment(18.62, 1.38, 20.0, false, "01 June 2024"), installment(15.66, 0.36, 7.02, false, "01 July 2024"));
// verify multiple partial repayment for "current" installment
loanTransactionHelper.makeLoanRepayment(loanId, "Repayment", "2 March 2024", 7.0);
verifyRepaymentSchedule(loanId, installment(100.0, null, "01 January 2024"),
installment(14.97, 5.03, 0.0, true, "01 February 2024"), installment(15.7, 4.3, 0.0, true, "01 March 2024"),
installment(17.77, 2.23, 6.0, false, "01 April 2024"), installment(18.0, 2.0, 20.0, false, "01 May 2024"),
installment(18.56, 1.02, 19.58, false, "01 June 2024"), installment(15.0, 0.0, 0.0, true, "01 July 2024"));
installment(19.9, 0.1, 0.0, true, "01 April 2024"), installment(15.65, 4.35, 20.0, false, "01 May 2024"),
installment(18.64, 1.36, 20.0, false, "01 June 2024"), installment(15.14, 0.34, 6.48, false, "01 July 2024"));
// verify next then last installment logic.
loanTransactionHelper.makeLoanRepayment(loanId, "Repayment", "2 March 2024", 22.0);
verifyRepaymentSchedule(loanId, installment(100.0, null, "01 January 2024"),
installment(14.97, 5.03, 0.0, true, "01 February 2024"), installment(15.7, 4.3, 0.0, true, "01 March 2024"),
installment(19.9, 0.1, 0.0, true, "01 April 2024"), installment(18.02, 1.98, 20.0, false, "01 May 2024"),
installment(16.41, 0.02, 0.43, false, "01 June 2024"), installment(15.0, 0.0, 0.0, true, "01 July 2024"));
installment(11.41, 0.02, 0.43, false, "01 June 2024"), installment(20.0, 0.0, 0.0, true, "01 July 2024"));
// verify last installment logic.
loanTransactionHelper.makeLoanRepayment(loanId, "Repayment", "2 March 2024", 22.0);
verifyRepaymentSchedule(loanId, installment(100.0, null, "01 January 2024"),
installment(14.97, 5.03, 0.0, true, "01 February 2024"), installment(15.7, 4.3, 0.0, true, "01 March 2024"),
installment(19.9, 0.1, 0.0, true, "01 April 2024"), installment(14.43, 0.0, 0.0, true, "01 May 2024"),
installment(20.0, 0.0, 0.0, true, "01 June 2024"), installment(15.0, 0.0, 0.0, true, "01 July 2024"));
installment(19.9, 0.1, 0.0, true, "01 April 2024"), installment(9.43, 0.0, 0.0, true, "01 May 2024"),
installment(20.0, 0.0, 0.0, true, "01 June 2024"), installment(20.0, 0.0, 0.0, true, "01 July 2024"));
});
}