FINERACT-2398: Add handling for equal overdue interest split re-amortization
This commit is contained in:
committed by
Arnold Gálovics
parent
a229a55c49
commit
36d779eabf
+14
-16
@@ -32,6 +32,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.client.feign.FineractFeignClient;
|
||||
import org.apache.fineract.client.models.LoanScheduleData;
|
||||
import org.apache.fineract.client.models.LoanSchedulePeriodData;
|
||||
@@ -45,18 +46,15 @@ import org.apache.fineract.test.messaging.EventAssertion;
|
||||
import org.apache.fineract.test.messaging.event.loan.LoanReAmortizeEvent;
|
||||
import org.apache.fineract.test.stepdef.AbstractStepDef;
|
||||
import org.apache.fineract.test.support.TestContextKey;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class LoanReAmortizationStepDef extends AbstractStepDef {
|
||||
|
||||
private static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(DATE_FORMAT);
|
||||
|
||||
@Autowired
|
||||
private FineractFeignClient fineractClient;
|
||||
|
||||
@Autowired
|
||||
private EventAssertion eventAssertion;
|
||||
private final FineractFeignClient fineractClient;
|
||||
private final EventAssertion eventAssertion;
|
||||
|
||||
@When("When Admin creates a Loan re-amortization transaction on current business date")
|
||||
public void createLoanReAmortization() {
|
||||
@@ -66,20 +64,20 @@ public class LoanReAmortizationStepDef extends AbstractStepDef {
|
||||
PostLoansLoanIdTransactionsRequest reAmortizationRequest = LoanRequestFactory.defaultLoanReAmortizationRequest();
|
||||
|
||||
PostLoansLoanIdTransactionsResponse response = ok(() -> fineractClient.loanTransactions().executeLoanTransaction(loanId,
|
||||
reAmortizationRequest, Map.<String, Object>of("command", "reAmortize")));
|
||||
reAmortizationRequest, Map.of("command", "reAmortize")));
|
||||
testContext().set(TestContextKey.LOAN_REAMORTIZATION_RESPONSE, response);
|
||||
}
|
||||
|
||||
@When("Admin creates a Loan re-amortization transaction on current business date with reAmortizationInterestHandling {string}")
|
||||
public void createLoanReAmortizationWithInterestHandling(String reAmortizationInterestHandling) throws IOException {
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.body().getLoanId();
|
||||
public void createLoanReAmortizationWithInterestHandling(final String reAmortizationInterestHandling) {
|
||||
final PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
final Long loanId = loanResponse.getLoanId();
|
||||
|
||||
PostLoansLoanIdTransactionsRequest reAmortizationRequest = LoanRequestFactory.defaultLoanReAmortizationRequest().reAmortizationInterestHandling(reAmortizationInterestHandling);
|
||||
final PostLoansLoanIdTransactionsRequest reAmortizationRequest = LoanRequestFactory.defaultLoanReAmortizationRequest()
|
||||
.reAmortizationInterestHandling(reAmortizationInterestHandling);
|
||||
|
||||
Response<PostLoansLoanIdTransactionsResponse> response = loanTransactionsApi
|
||||
.executeLoanTransaction(loanId, reAmortizationRequest, "reAmortize").execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(response);
|
||||
final PostLoansLoanIdTransactionsResponse response = ok(() -> fineractClient.loanTransactions().executeLoanTransaction(loanId,
|
||||
reAmortizationRequest, Map.of("command", "reAmortize")));
|
||||
testContext().set(TestContextKey.LOAN_REAMORTIZATION_RESPONSE, response);
|
||||
}
|
||||
|
||||
@@ -91,7 +89,7 @@ public class LoanReAmortizationStepDef extends AbstractStepDef {
|
||||
PostLoansLoanIdTransactionsRequest reAmortizationRequest = LoanRequestFactory.defaultLoanReAmortizationRequest();
|
||||
|
||||
PostLoansLoanIdTransactionsResponse response = ok(() -> fineractClient.loanTransactions().executeLoanTransaction1(loanExternalId,
|
||||
reAmortizationRequest, Map.<String, Object>of("command", "reAmortize")));
|
||||
reAmortizationRequest, Map.of("command", "reAmortize")));
|
||||
testContext().set(TestContextKey.LOAN_REAMORTIZATION_RESPONSE, response);
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ public class LoanReAmortizationStepDef extends AbstractStepDef {
|
||||
long loanId = loanResponse.getLoanId();
|
||||
|
||||
PostLoansLoanIdTransactionsResponse response = ok(() -> fineractClient.loanTransactions().executeLoanTransaction(loanId,
|
||||
new PostLoansLoanIdTransactionsRequest(), Map.<String, Object>of("command", "undoReAmortize")));
|
||||
new PostLoansLoanIdTransactionsRequest(), Map.of("command", "undoReAmortize")));
|
||||
testContext().set(TestContextKey.LOAN_REAMORTIZATION_UNDO_RESPONSE, response);
|
||||
}
|
||||
|
||||
|
||||
@@ -1105,6 +1105,10 @@ Feature: LoanReAmortization
|
||||
| 01 January 2024 | Down Payment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
| 01 February 2024 | Repayment | 12.76 | 12.32 | 0.44 | 0.0 | 0.0 | 62.68 | false | false |
|
||||
| 15 March 2024 | Re-amortize | 12.76 | 12.39 | 0.37 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
When Loan Pay-off is made on "15 March 2024"
|
||||
Then Loan is closed with zero outstanding balance and it's all installments have obligations met
|
||||
|
||||
@TestRailId:C4219 @AdvancedPaymentAllocation
|
||||
Scenario: Verify Re-amortization transaction on interest bearing loan - Interest handling: EQUAL_AMORTIZATION_INTEREST_SPLIT - UC1: Principal and interest re-amortization
|
||||
When Admin sets the business date to "01 January 2024"
|
||||
@@ -1156,19 +1160,19 @@ Feature: LoanReAmortization
|
||||
| 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 | | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 2 | 29 | 01 March 2024 | 15 March 2024 | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 3 | 31 | 01 April 2024 | | 62.86 | 20.71 | 0.61 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 4 | 30 | 01 May 2024 | | 42.03 | 20.83 | 0.49 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 5 | 31 | 01 June 2024 | | 21.09 | 20.95 | 0.37 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 21.09 | 0.24 | 0.0 | 0.0 | 21.33 | 0.0 | 0.0 | 0.0 | 21.33 |
|
||||
| 5 | 31 | 01 June 2024 | | 21.08 | 20.95 | 0.37 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 21.08 | 0.24 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.3 | 0.0 | 0.0 | 102.3 | 17.01 | 0.0 | 0.0 | 85.29 |
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.29 | 0.0 | 0.0 | 102.29 | 17.01 | 0.0 | 0.0 | 85.28 |
|
||||
And 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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false | false |
|
||||
| 15 March 2024 | Re-amortization | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
| 15 March 2024 | Re-amortize | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
@TestRailId:C4220 @AdvancedPaymentAllocation
|
||||
Scenario: Verify Re-amortization transaction on interest bearing loan - Interest handling: EQUAL_AMORTIZATION_INTEREST_SPLIT - UC2: Principal interest and fee re-amortization
|
||||
@@ -1222,19 +1226,19 @@ Feature: LoanReAmortization
|
||||
| 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 | | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 2 | 29 | 01 March 2024 | 15 March 2024 | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 3 | 31 | 01 April 2024 | | 62.86 | 20.71 | 0.61 | 2.5 | 0.0 | 23.82 | 0.0 | 0.0 | 0.0 | 23.82 |
|
||||
| 4 | 30 | 01 May 2024 | | 42.03 | 20.83 | 0.49 | 2.5 | 0.0 | 23.82 | 0.0 | 0.0 | 0.0 | 23.82 |
|
||||
| 5 | 31 | 01 June 2024 | | 21.09 | 20.95 | 0.37 | 2.5 | 0.0 | 23.82 | 0.0 | 0.0 | 0.0 | 23.82 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 21.09 | 0.24 | 2.5 | 0.0 | 23.83 | 0.0 | 0.0 | 0.0 | 23.83 |
|
||||
| 5 | 31 | 01 June 2024 | | 21.08 | 20.95 | 0.37 | 2.5 | 0.0 | 23.82 | 0.0 | 0.0 | 0.0 | 23.82 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 21.08 | 0.24 | 2.5 | 0.0 | 23.82 | 0.0 | 0.0 | 0.0 | 23.82 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.3 | 10.0 | 0.0 | 112.3 | 17.01 | 0.0 | 0.0 | 95.29 |
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.29 | 10.0 | 0.0 | 112.29 | 17.01 | 0.0 | 0.0 | 95.28 |
|
||||
And 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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false | false |
|
||||
| 15 March 2024 | Re-amortization | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
| 15 March 2024 | Re-amortize | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
@TestRailId:C4221 @AdvancedPaymentAllocation
|
||||
Scenario: Verify Re-amortization transaction on interest bearing loan - Interest handling: EQUAL_AMORTIZATION_INTEREST_SPLIT - UC3: Principal interest and fee re-amortization, N+1 installment
|
||||
@@ -1285,33 +1289,32 @@ Feature: LoanReAmortization
|
||||
# --- Re-amortization transaction ---
|
||||
When Admin sets the business date to "15 March 2024"
|
||||
And Admin creates a Loan re-amortization transaction on current business date with reAmortizationInterestHandling "EQUAL_AMORTIZATION_INTEREST_SPLIT"
|
||||
Then Loan Repayment schedule has 6 periods, with the following data for periods:
|
||||
Then Loan Repayment schedule has 7 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 | | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 2 | 29 | 01 March 2024 | 15 March 2024 | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 3 | 31 | 01 April 2024 | | 62.86 | 20.71 | 0.61 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 4 | 30 | 01 May 2024 | | 42.03 | 20.83 | 0.49 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 5 | 31 | 01 June 2024 | | 21.09 | 20.95 | 0.37 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 21.09 | 0.24 | 0.0 | 0.0 | 21.33 | 0.0 | 0.0 | 0.0 | 21.33 |
|
||||
| 5 | 31 | 01 June 2024 | | 21.08 | 20.95 | 0.37 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 21.08 | 0.24 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
| 7 | 14 | 15 July 2024 | | 0.0 | 0.0 | 0.0 | 10.0 | 0.0 | 10.0 | 0.0 | 0.0 | 0.0 | 10.0 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.3 | 10.0 | 0.0 | 112.3 | 17.01 | 0.0 | 0.0 | 95.29 |
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.29 | 10.0 | 0.0 | 112.29 | 17.01 | 0.0 | 0.0 | 95.28 |
|
||||
And 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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false | false |
|
||||
| 15 March 2024 | Re-amortization | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
| 15 March 2024 | Re-amortize | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
@TestRailId:C4222 @AdvancedPaymentAllocation
|
||||
Scenario: Verify Re-amortization transaction on interest bearing loan - Interest handling: EQUAL_AMORTIZATION_INTEREST_SPLIT - UC4: Principal interest re-amortization, chargeback
|
||||
When Admin sets the business date to "01 January 2024"
|
||||
And Admin creates a client with random data
|
||||
And Admin set "LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL" loan product "DEFAULT" transaction type to "NEXT_INSTALLMENT" future installment allocation rule
|
||||
And 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 |
|
||||
| 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_PYMNT_INTEREST_DAILY_INTEREST_RECALC_EMI_360_30_CHARGEBACK_INTEREST_PENALTY_FEE_PRINCIPAL | 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"
|
||||
And Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount
|
||||
Then Loan Repayment schedule has 6 periods, with the following data for periods:
|
||||
@@ -1332,45 +1335,45 @@ Feature: LoanReAmortization
|
||||
# --- Repayment on due date and chargeback added ---
|
||||
When Admin sets the business date to "01 February 2024"
|
||||
And Customer makes "AUTOPAY" repayment on "01 February 2024" with 17.01 EUR transaction amount
|
||||
And Customer makes "REPAYMENT_ADJUSTMENT_CHARGEBACK" repayment on "01 February 2024" with 17.01 EUR transaction amount
|
||||
# TODO check numbers - is google sheet state OK for sure after chargeback?
|
||||
# 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 | 67.05 | 16.52 | 0.49 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
# | 3 | 31 | 01 April 2024 | | 50.43 | 16.62 | 0.39 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
# | 4 | 30 | 01 May 2024 | | 33.71 | 16.72 | 0.29 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
# | 5 | 31 | 01 June 2024 | | 16.9 | 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.9 | 0.1 | 0.0 | 0.0 | 17.0 | 0.0 | 0.0 | 0.0 | 17.0 |
|
||||
# And Loan Repayment schedule has the following data in Total row:
|
||||
# | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
# | 100.0 | 2.05 | 10.0 | 0.0 | 112.05 | 17.01 | 0.0 | 0.0 | 95.04 |
|
||||
# And 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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false |false |
|
||||
## --- Re-amortization transaction ---
|
||||
# When Admin sets the business date to "15 March 2024"
|
||||
# And Admin creates a Loan re-amortization transaction on current business date with reAmortizationInterestHandling "EQUAL_AMORTIZATION_INTEREST_SPLIT"
|
||||
# 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 | | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
# | 3 | 31 | 01 April 2024 | | 62.86 | 20.71 | 0.61 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
# | 4 | 30 | 01 May 2024 | | 42.03 | 20.83 | 0.49 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
# | 5 | 31 | 01 June 2024 | | 21.09 | 20.95 | 0.37 | 0.0 | 0.0 | 21.32 | 0.0 | 0.0 | 0.0 | 21.32 |
|
||||
# | 6 | 30 | 01 July 2024 | | 0.0 | 21.09 | 0.24 | 0.0 | 0.0 | 21.33 | 0.0 | 0.0 | 0.0 | 21.33 |
|
||||
# | 7 | 14 | 15 July 2024 | | 0.0 | 0.0 | 0.0 | 10.0 | 0.0 | 10.0 | 0.0 | 0.0 | 0.0 | 10.0 |
|
||||
# And Loan Repayment schedule has the following data in Total row:
|
||||
# | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
# | 100.0 | 2.3 | 10.0 | 0.0 | 112.3 | 17.01 | 0.0 | 0.0 | 95.29 |
|
||||
# And 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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false | false |
|
||||
# | 15 March 2024 | Re-amortization | 17.01 | 16.52 | 0.49 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
And Admin makes "REPAYMENT_ADJUSTMENT_CHARGEBACK" chargeback with 17.01 EUR transaction amount for Payment nr. 1
|
||||
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 | | 67.14 | 32.86 | 1.16 | 0.0 | 0.0 | 34.02 | 0.0 | 0.0 | 0.0 | 34.02 |
|
||||
| 3 | 31 | 01 April 2024 | | 50.52 | 16.62 | 0.39 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 4 | 30 | 01 May 2024 | | 33.8 | 16.72 | 0.29 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 5 | 31 | 01 June 2024 | | 16.99 | 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.99 | 0.1 | 0.0 | 0.0 | 17.09 | 0.0 | 0.0 | 0.0 | 17.09 |
|
||||
Then Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 116.43 | 2.72 | 0 | 0 | 119.15 | 17.01 | 0 | 0 | 102.14 |
|
||||
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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false | false |
|
||||
| 01 February 2024 | Chargeback | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 100.0 | false | false |
|
||||
# --- Re-amortization transaction ---
|
||||
When Admin sets the business date to "15 March 2024"
|
||||
And Admin creates a Loan re-amortization transaction on current business date with reAmortizationInterestHandling "EQUAL_AMORTIZATION_INTEREST_SPLIT"
|
||||
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 | 15 March 2024 | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 3 | 31 | 01 April 2024 | | 75.21 | 24.79 | 0.87 | 0.0 | 0.0 | 25.66 | 0.0 | 0.0 | 0.0 | 25.66 |
|
||||
| 4 | 30 | 01 May 2024 | | 50.28 | 24.93 | 0.73 | 0.0 | 0.0 | 25.66 | 0.0 | 0.0 | 0.0 | 25.66 |
|
||||
| 5 | 31 | 01 June 2024 | | 25.2 | 25.08 | 0.58 | 0.0 | 0.0 | 25.66 | 0.0 | 0.0 | 0.0 | 25.66 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 25.2 | 0.44 | 0.0 | 0.0 | 25.64 | 0.0 | 0.0 | 0.0 | 25.64 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 116.43 | 3.2 | 0.0 | 0.0 | 119.63 | 17.01 | 0.0 | 0.0 | 102.62 |
|
||||
And 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 | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 | false | false |
|
||||
| 01 February 2024 | Chargeback | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 100.0 | false | false |
|
||||
| 15 March 2024 | Re-amortize | 34.02 | 32.86 | 1.16 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
@TestRailId:C4223 @AdvancedPaymentAllocation
|
||||
Scenario: Verify Re-amortization transaction on interest bearing loan - Interest handling: EQUAL_AMORTIZATION_INTEREST_SPLIT - UC5: Principal interest and fee re-amortization, partial payment
|
||||
@@ -1411,7 +1414,7 @@ Feature: LoanReAmortization
|
||||
| 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 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 2.03 | 10.0 | 0.0 | 102.03 | 20.0 | 2.99 | 0.0 | 82.03 |
|
||||
| 100.0 | 2.03 | 0.0 | 0.0 | 102.03 | 20.0 | 2.99 | 0.0 | 82.03 |
|
||||
And 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 |
|
||||
@@ -1423,9 +1426,9 @@ Feature: LoanReAmortization
|
||||
| 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 | | 80.58 | 2.99 | 0.0 | 0.0 | 0.0 | 2.99 | 2.99 | 2.99 | 0.0 | 0.0 |
|
||||
| 2 | 29 | 01 March 2024 | 15 March 2024 | 80.58 | 2.99 | 0.0 | 0.0 | 0.0 | 2.99 | 2.99 | 2.99 | 0.0 | 0.0 |
|
||||
| 3 | 31 | 01 April 2024 | | 60.61 | 19.97 | 0.59 | 0.0 | 0.0 | 20.56 | 0.0 | 0.0 | 0.0 | 20.56 |
|
||||
| 4 | 30 | 01 May 2024 | | 42.53 | 20.08 | 0.48 | 0.0 | 0.0 | 20.56 | 0.0 | 0.0 | 0.0 | 20.56 |
|
||||
| 4 | 30 | 01 May 2024 | | 40.52 | 20.09 | 0.47 | 0.0 | 0.0 | 20.56 | 0.0 | 0.0 | 0.0 | 20.56 |
|
||||
| 5 | 31 | 01 June 2024 | | 20.32 | 20.2 | 0.36 | 0.0 | 0.0 | 20.56 | 0.0 | 0.0 | 0.0 | 20.56 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 20.32 | 0.24 | 0.0 | 0.0 | 20.56 | 0.0 | 0.0 | 0.0 | 20.56 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
@@ -1435,18 +1438,17 @@ Feature: LoanReAmortization
|
||||
| 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 | 20.0 | 19.42 | 0.58 | 0.0 | 0.0 | 80.58 | false | false |
|
||||
| 15 March 2024 | Re-amortization | 14.02 | 13.55 | 0.47 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
| 15 March 2024 | Re-amortize | 14.02 | 13.55 | 0.47 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
@TestRailId:C4224 @AdvancedPaymentAllocation
|
||||
Scenario: Verify Re-amortization transaction on interest bearing loan - Interest handling: EQUAL_AMORTIZATION_INTEREST_SPLIT - UC6: Principal and interest re-amortization, downpayment
|
||||
When Admin sets the business date to "01 January 2024"
|
||||
And Admin creates a client with random data
|
||||
And 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_PYMNT_INTEREST_DAILY_EMI_360_30_DOWNPAYMENT | 01 January 2024 | 100 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
|
||||
| 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_PYMNT_INTEREST_RECALCULATION_DAILY_EMI_360_30_MULTIDISBURSE_AUTO_DOWNPAYMENT | 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"
|
||||
And Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount
|
||||
And Customer makes "AUTOPAY" repayment on "01 January 2024" with 25.0 EUR transaction amount
|
||||
Then Loan Repayment schedule has 7 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 | | | |
|
||||
@@ -1463,7 +1465,7 @@ Feature: LoanReAmortization
|
||||
And 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 January 2024 | Repayment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
| 01 January 2024 | Down Payment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
# --- Repayment on due date ---
|
||||
When Admin sets the business date to "01 February 2024"
|
||||
And Customer makes "AUTOPAY" repayment on "01 February 2024" with 12.76 EUR transaction amount
|
||||
@@ -1483,34 +1485,30 @@ Feature: LoanReAmortization
|
||||
And 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 January 2024 | Repayment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
| 01 January 2024 | Down Payment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
| 01 February 2024 | Repayment | 12.76 | 12.32 | 0.44 | 0.0 | 0.0 | 62.68 | false | false |
|
||||
# --- Re-amortization transaction ---
|
||||
When Admin sets the business date to "15 March 2024"
|
||||
And Admin creates a Loan re-amortization transaction on current business date with reAmortizationInterestHandling "EQUAL_AMORTIZATION_INTEREST_SPLIT"
|
||||
# TODO check numbers is google sheet state OK for sure?
|
||||
Then Loan Repayment schedule has 7 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 | 0 | 01 January 2024 | 01 January 2024 | 75.0 | 25.0 | 0.0 | 0.0 | 0.0 | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 2 | 31 | 01 February 2024 | 01 February 2024 | 74.56 | 12.32 | 0.44 | 0.0 | 0.0 | 12.76 | 12.76 | 0.0 | 0.0 | 0.0 |
|
||||
| 3 | 29 | 01 March 2024 | | 74.56 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 4 | 31 | 01 April 2024 | | 59.03 | 15.53 | 0.46 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 5 | 30 | 01 May 2024 | | 43.41 | 15.62 | 0.37 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 6 | 31 | 01 June 2024 | | 29.69 | 15.72 | 0.27 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 7 | 30 | 01 July 2024 | | 11.88 | 15.81 | 0.18 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 2 | 31 | 01 February 2024 | 01 February 2024 | 62.68 | 12.32 | 0.44 | 0.0 | 0.0 | 12.76 | 12.76 | 0.0 | 0.0 | 0.0 |
|
||||
| 3 | 29 | 01 March 2024 | 15 March 2024 | 62.68 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
| 4 | 31 | 01 April 2024 | | 47.15 | 15.53 | 0.46 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 5 | 30 | 01 May 2024 | | 31.53 | 15.62 | 0.37 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 6 | 31 | 01 June 2024 | | 15.81 | 15.72 | 0.27 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
| 7 | 30 | 01 July 2024 | | 0.0 | 15.81 | 0.18 | 0.0 | 0.0 | 15.99 | 0.0 | 0.0 | 0.0 | 15.99 |
|
||||
And Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100.0 | 1.54 | 0.0 | 0.0 | 101.54 | 37.76 | 0.0 | 0.0 | 63.96 |
|
||||
And Loan Transactions tab has the following data:1
|
||||
| 100.0 | 1.72 | 0.0 | 0.0 | 101.72 | 37.76 | 0.0 | 0.0 | 63.96 |
|
||||
And 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 January 2024 | Repayment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
| 01 January 2024 | Down Payment | 25.0 | 25.0 | 0.0 | 0.0 | 0.0 | 75.0 | false | false |
|
||||
| 01 February 2024 | Repayment | 12.76 | 12.32 | 0.44 | 0.0 | 0.0 | 62.68 | false | false |
|
||||
| 15 March 2024 | Re-amortization | 12.76 | 12.39 | 0.37 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
When Loan Pay-off is made on "15 March 2024"
|
||||
Then Loan is closed with zero outstanding balance and it's all installments have obligations met
|
||||
| 15 March 2024 | Re-amortize | 12.76 | 12.39 | 0.37 | 0.0 | 0.0 | 0.0 | false | false |
|
||||
|
||||
#will be handled in separate story
|
||||
@Skip
|
||||
|
||||
+8
@@ -905,6 +905,14 @@ public class LoanRepaymentScheduleInstallment extends AbstractAuditableWithUTCDa
|
||||
checkIfRepaymentPeriodObligationsAreMet(transactionDate, transactionAmount.getCurrency());
|
||||
}
|
||||
|
||||
public void addToFeeCharges(final Money transactionAmount) {
|
||||
if (this.feeChargesCharged == null) {
|
||||
setFeeChargesCharged(transactionAmount.getAmount());
|
||||
} else {
|
||||
setFeeChargesCharged(this.feeChargesCharged.add(transactionAmount.getAmount()));
|
||||
}
|
||||
}
|
||||
|
||||
public void addToCreditedInterest(final BigDecimal amount) {
|
||||
if (this.creditedInterest == null) {
|
||||
setCreditedInterest(amount);
|
||||
|
||||
+68
-4
@@ -605,10 +605,74 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
|
||||
}
|
||||
}
|
||||
|
||||
private void handleReamortizationWithEqualAmortizationInterestSplitHandlingType(LoanTransaction loanTransaction,
|
||||
TransactionCtx transactionCtx) {
|
||||
throw new UnsupportedOperationException(
|
||||
"EQUAL_AMORTIZATION_INTEREST_SPLIT interest handling strategy for re-amortization is not implemented");
|
||||
private void handleReamortizationWithEqualAmortizationInterestSplitHandlingType(final LoanTransaction loanTransaction,
|
||||
final TransactionCtx transactionCtx) {
|
||||
if (transactionCtx instanceof ProgressiveTransactionCtx progressiveTransactionCtx
|
||||
&& loanTransaction.getLoan().isInterestBearingAndInterestRecalculationEnabled()) {
|
||||
final LocalDate transactionDate = loanTransaction.getTransactionDate();
|
||||
final MonetaryCurrency currency = progressiveTransactionCtx.getCurrency();
|
||||
|
||||
final List<LoanRepaymentScheduleInstallment> previousInstallments = progressiveTransactionCtx.getInstallments().stream()
|
||||
.filter(installment -> !installment.getDueDate().isAfter(transactionDate)).toList();
|
||||
|
||||
final List<LoanRepaymentScheduleInstallment> futureInstallments = progressiveTransactionCtx.getInstallments().stream()
|
||||
.filter(installment -> installment.getDueDate().isAfter(transactionDate))
|
||||
.filter(installment -> !installment.isAdditional() && !installment.isDownPayment() && !installment.isReAged()).toList();
|
||||
|
||||
Money totalOverDuePrincipal = Money.zero(currency);
|
||||
Money totalOverDueFee = Money.zero(currency);
|
||||
for (LoanRepaymentScheduleInstallment installment : previousInstallments) {
|
||||
final Money outstandingPrincipal = emiCalculator
|
||||
.findRepaymentPeriod(progressiveTransactionCtx.getModel(), installment.getFromDate(), installment.getDueDate())
|
||||
.map(RepaymentPeriod::getOutstandingPrincipal).map(amount -> Money.of(currency, amount.getAmount()))
|
||||
.orElse(Money.zero(currency));
|
||||
totalOverDuePrincipal = totalOverDuePrincipal.add(outstandingPrincipal);
|
||||
totalOverDueFee = totalOverDueFee.add(installment.getFeeChargesOutstanding(currency));
|
||||
installment.setFeeChargesCharged(installment.getFeeChargesPaid(currency).getAmount());
|
||||
}
|
||||
|
||||
final Money totalOverDueInterest = emiCalculator.getOutstandingInterestTillDate(progressiveTransactionCtx.getModel(),
|
||||
previousInstallments.getLast().getDueDate());
|
||||
|
||||
loanTransaction.resetDerivedComponents();
|
||||
loanTransaction.updateComponentsAndTotal(totalOverDuePrincipal, totalOverDueInterest, Money.zero(currency),
|
||||
Money.zero(currency));
|
||||
|
||||
emiCalculator.updateModelRepaymentPeriodsDuringReAmortizationWithEqualInterestSplit(progressiveTransactionCtx.getModel(),
|
||||
transactionDate);
|
||||
updateInstallmentsByRepaymentPeriods(loanTransaction, progressiveTransactionCtx);
|
||||
|
||||
distributeFeeAmongFutureInstallments(totalOverDueFee, futureInstallments);
|
||||
} else {
|
||||
// TODO: implement interestRecalculation = false logic
|
||||
throw new UnsupportedOperationException(
|
||||
"Logic for re-amortization when interest bearing loan has interestRecalculation disabled is not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
private void distributeFeeAmongFutureInstallments(final Money totalOverDueFee,
|
||||
final List<LoanRepaymentScheduleInstallment> futureInstallments) {
|
||||
if (totalOverDueFee.isZero() || futureInstallments.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int numberOfFutureInstallments = futureInstallments.size();
|
||||
final MonetaryCurrency currency = totalOverDueFee.getCurrency();
|
||||
BigDecimal feePortionPerInstallment = totalOverDueFee.getAmount().divide(BigDecimal.valueOf(numberOfFutureInstallments),
|
||||
MoneyHelper.getMathContext());
|
||||
|
||||
final LoanRepaymentScheduleInstallment lastFutureInstallment = futureInstallments.stream()
|
||||
.max(Comparator.comparing(LoanRepaymentScheduleInstallment::getDueDate)).get();
|
||||
|
||||
BigDecimal remainingFee = totalOverDueFee.getAmount();
|
||||
for (final LoanRepaymentScheduleInstallment installment : futureInstallments) {
|
||||
if (lastFutureInstallment.equals(installment)) {
|
||||
installment.addToFeeCharges(Money.of(currency, remainingFee));
|
||||
} else {
|
||||
installment.addToFeeCharges(Money.of(currency, feePortionPerInstallment));
|
||||
remainingFee = remainingFee.subtract(feePortionPerInstallment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleReamortizationWithWaiveInterestHandlingType(LoanTransaction loanTransaction, TransactionCtx transactionCtx) {
|
||||
|
||||
+3
@@ -172,4 +172,7 @@ public interface EMICalculator {
|
||||
LocalDate targetRepaymentPeriodDueDate, LocalDate newDueDate);
|
||||
|
||||
void updateModelRepaymentPeriodsDuringReAmortization(ProgressiveLoanInterestScheduleModel model, LocalDate transactionDate);
|
||||
|
||||
void updateModelRepaymentPeriodsDuringReAmortizationWithEqualInterestSplit(ProgressiveLoanInterestScheduleModel model,
|
||||
LocalDate transactionDate);
|
||||
}
|
||||
|
||||
+77
@@ -685,6 +685,83 @@ public final class ProgressiveEMICalculator implements EMICalculator {
|
||||
checkAndAdjustEmiIfNeededOnRelatedRepaymentPeriods(model, reAmortizedPeriods);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateModelRepaymentPeriodsDuringReAmortizationWithEqualInterestSplit(final ProgressiveLoanInterestScheduleModel model,
|
||||
final LocalDate transactionDate) {
|
||||
final MathContext mc = model.mc();
|
||||
final List<RepaymentPeriod> periodsBeforeTransactionDate = model.repaymentPeriods().stream()
|
||||
.filter(rp -> !rp.getDueDate().isAfter(transactionDate) && !rp.isFullyPaid()).toList();
|
||||
|
||||
Money totalAmortizedInterest = model.zero();
|
||||
for (RepaymentPeriod rp : periodsBeforeTransactionDate) {
|
||||
totalAmortizedInterest = totalAmortizedInterest.add(rp.getDueInterest().minus(rp.getPaidInterest(), mc), mc);
|
||||
}
|
||||
|
||||
final List<RepaymentPeriod> futurePeriods = model.repaymentPeriods().stream().filter(rp -> rp.getDueDate().isAfter(transactionDate))
|
||||
.toList();
|
||||
|
||||
final int numberOfFuturePeriods = futurePeriods.size();
|
||||
|
||||
Money interestPortionPerPeriod = model.zero();
|
||||
if (numberOfFuturePeriods > 0 && totalAmortizedInterest.isGreaterThanZero()) {
|
||||
interestPortionPerPeriod = totalAmortizedInterest.dividedBy(numberOfFuturePeriods, mc);
|
||||
}
|
||||
|
||||
model.repaymentPeriods().forEach(rp -> rp.getInterestPeriods().forEach(ip -> {
|
||||
if (!ip.getBalanceCorrectionAmount().isZero()) {
|
||||
ip.addBalanceCorrectionAmount(ip.getBalanceCorrectionAmount().negated());
|
||||
}
|
||||
}));
|
||||
|
||||
final List<RepaymentPeriod> allPeriods = model.repaymentPeriods();
|
||||
for (int i = 0; i < allPeriods.size(); i++) {
|
||||
final RepaymentPeriod rp = allPeriods.get(i);
|
||||
if (rp.isFullyPaid() && !rp.getDueDate().isAfter(transactionDate)) {
|
||||
Money nextPeriodCreditedPrincipal = model.zero();
|
||||
if (i + 1 < allPeriods.size()) {
|
||||
nextPeriodCreditedPrincipal = allPeriods.get(i + 1).getCreditedPrincipal();
|
||||
}
|
||||
final Money effectivePaidPrincipal = rp.getPaidPrincipal().minus(nextPeriodCreditedPrincipal, mc);
|
||||
if (effectivePaidPrincipal.isGreaterThanZero()) {
|
||||
final InterestPeriod lastInterestPeriod = rp.getInterestPeriods().getLast();
|
||||
lastInterestPeriod.addBalanceCorrectionAmount(effectivePaidPrincipal.negated());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
moveOutstandingAmountsFromPeriodsBeforeTransactionDateForEqualInterestSplit(periodsBeforeTransactionDate, transactionDate);
|
||||
|
||||
calculateRateFactorForPeriods(futurePeriods, model);
|
||||
|
||||
for (final RepaymentPeriod futurePeriod : futurePeriods) {
|
||||
futurePeriod.setReAgedInterest(MathUtil.plus(futurePeriod.getReAgedInterest(), interestPortionPerPeriod, mc));
|
||||
}
|
||||
|
||||
calculateEMIOnActualModel(futurePeriods, model);
|
||||
calculateOutstandingBalance(model);
|
||||
calculateLastUnpaidRepaymentPeriodEMI(model, transactionDate);
|
||||
checkAndAdjustEmiIfNeededOnRelatedRepaymentPeriods(model, futurePeriods);
|
||||
}
|
||||
|
||||
private void moveOutstandingAmountsFromPeriodsBeforeTransactionDateForEqualInterestSplit(
|
||||
final List<RepaymentPeriod> periodsBeforeTransactionDate, final LocalDate transactionDate) {
|
||||
periodsBeforeTransactionDate.forEach(rp -> {
|
||||
rp.getInterestPeriods().stream().filter(ip -> ip.getDueDate().isEqual(transactionDate)).forEach(ip -> {
|
||||
if (!ip.getBalanceCorrectionAmount().isZero()) {
|
||||
ip.addBalanceCorrectionAmount(ip.getBalanceCorrectionAmount().negated());
|
||||
}
|
||||
});
|
||||
final InterestPeriod lastInterestPeriod = rp.getInterestPeriods().getLast();
|
||||
Money paidPrincipal = rp.getPaidPrincipal();
|
||||
if (paidPrincipal.isGreaterThanZero()) {
|
||||
lastInterestPeriod.addBalanceCorrectionAmount(paidPrincipal.negated());
|
||||
}
|
||||
rp.setEmi(rp.getTotalPaidAmount());
|
||||
rp.moveOutstandingDueToReAging();
|
||||
rp.setNoUnrecognisedInterest(true);
|
||||
});
|
||||
}
|
||||
|
||||
private LocalDate calculateDateForFixedLength(final ProgressiveLoanInterestScheduleModel scheduleModel,
|
||||
final LoanApplicationTerms loanApplicationTerms, final LocalDate targetRepaymentPeriodDueDate, final LocalDate newDueDate) {
|
||||
final long variationDays = DateUtils.getDifferenceInDays(targetRepaymentPeriodDueDate, newDueDate);
|
||||
|
||||
Reference in New Issue
Block a user