This is an automated email from the ASF dual-hosted git repository.

adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git

commit 4c238801ace07f0f1ddd04e56352cdc8309d3e11
Author: mariiaKraievska <[email protected]>
AuthorDate: Wed Oct 22 13:03:18 2025 +0300

    FINERACT-2354: Fourth step - Chargeback before re-age edge case for 
Interest bearing loans - Default Behavior, interestRecalculation = true, 
without dueDate change
---
 .../test/resources/features/LoanReAging.feature    | 187 +++++++++++++++++++++
 .../portfolio/loanproduct/calc/EMICalculator.java  |   2 +-
 .../loanproduct/calc/ProgressiveEMICalculator.java |   1 +
 .../loanproduct/calc/data/RepaymentPeriod.java     |   9 +-
 4 files changed, 197 insertions(+), 2 deletions(-)

diff --git 
a/fineract-e2e-tests-runner/src/test/resources/features/LoanReAging.feature 
b/fineract-e2e-tests-runner/src/test/resources/features/LoanReAging.feature
index f180ffe10f..c1512bb65c 100644
--- a/fineract-e2e-tests-runner/src/test/resources/features/LoanReAging.feature
+++ b/fineract-e2e-tests-runner/src/test/resources/features/LoanReAging.feature
@@ -3967,6 +3967,193 @@ Feature: LoanReAging
     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:C4077 @AdvancedPaymentAllocation
+  Scenario: Verify allowing Re-aging on interest bearing loan - Interest 
calculation: Default Behavior - Charge-back before re-aging - UC3
+    When Admin sets the business date to "01 January 2024"
+    When Admin creates a client with random data
+    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_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"
+    When 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:
+      | 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.57           | 16.43     
    | 0.58     | 0.0  | 0.0       | 17.01 | 0.0  | 0.0        | 0.0  | 17.01    
   |
+      | 2  | 29   | 01 March 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     
   |
+    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.05     | 0.0  | 0.0       | 102.05 | 0.0  | 0.0      
  | 0.0  | 102.05      |
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type | Amount | Principal | Interest | 
Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement     | 100.0  | 0.0       | 0.0      | 
0.0  | 0.0       | 100.0        | false    |
+    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
+    When Admin makes "REPAYMENT_ADJUSTMENT_CHARGEBACK" chargeback with 17.01 
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    |                  | 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  | 0.0       | 119.15 | 17.01 | 0.0     
   | 0.0  | 102.14      |
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type | Amount | Principal | Interest | 
Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement     | 100.0  | 0.0       | 0.0      | 
0.0  | 0.0       | 100.0        | false    |
+      | 01 February 2024 | Repayment        | 17.01  | 16.43     | 0.58     | 
0.0  | 0.0       | 83.57        | false    |
+      | 01 February 2024 | Chargeback       | 17.01  | 16.43     | 0.58     | 
0.0  | 0.0       | 100.0        | false    |
+    When Admin sets the business date to "15 March 2024"
+    When Admin creates a Loan re-aging transaction with the following data:
+      | frequencyNumber | frequencyType | startDate    | numberOfInstallments |
+      | 1               | MONTHS        | 01 April 2024| 6                    |
+    Then Loan Repayment schedule has 8 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    |                  | 84.53           | 
15.47         | 1.74     | 0.0  | 0.0       | 17.21 | 0.0   | 0.0        | 0.0  
| 17.21       |
+      | 4  | 30   | 01 May 2024      |                  | 67.81           | 
16.72         | 0.49     | 0.0  | 0.0       | 17.21 | 0.0   | 0.0        | 0.0  
| 17.21       |
+      | 5  | 31   | 01 June 2024     |                  | 51.0            | 
16.81         | 0.4      | 0.0  | 0.0       | 17.21 | 0.0   | 0.0        | 0.0  
| 17.21       |
+      | 6  | 30   | 01 July 2024     |                  | 34.09           | 
16.91         | 0.3      | 0.0  | 0.0       | 17.21 | 0.0   | 0.0        | 0.0  
| 17.21       |
+      | 7  | 31   | 01 August 2024   |                  | 17.08           | 
17.01         | 0.2      | 0.0  | 0.0       | 17.21 | 0.0   | 0.0        | 0.0  
| 17.21       |
+      | 8  | 31   | 01 September 2024|                  | 0.0             | 
17.08         | 0.1      | 0.0  | 0.0       | 17.18 | 0.0   | 0.0        | 0.0  
| 17.18       |
+    Then Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due    | Paid | In 
advance | Late | Outstanding |
+      | 116.43        | 3.81     | 0.0  | 0.0       | 120.24 | 17.01| 0.0      
  | 0.0  | 103.23      |
+    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    |
+      | 15 March 2024    | Re-age           | 101.42 | 100.0     | 1.42     | 
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
+    Then Loan Repayment schedule has 8 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    | 15 March 2024    | 84.21           | 
15.79         | 1.42     | 0.0  | 0.0       | 17.21 | 17.21 | 17.21      | 0.0  
| 0.0         |
+      | 4  | 30   | 01 May 2024      | 15 March 2024    | 67.0            | 
17.21         | 0.0      | 0.0  | 0.0       | 17.21 | 17.21 | 17.21      | 0.0  
| 0.0         |
+      | 5  | 31   | 01 June 2024     | 15 March 2024    | 49.79           | 
17.21         | 0.0      | 0.0  | 0.0       | 17.21 | 17.21 | 17.21      | 0.0  
| 0.0         |
+      | 6  | 30   | 01 July 2024     | 15 March 2024    | 32.58           | 
17.21         | 0.0      | 0.0  | 0.0       | 17.21 | 17.21 | 17.21      | 0.0  
| 0.0         |
+      | 7  | 31   | 01 August 2024   | 15 March 2024    | 15.37           | 
17.21         | 0.0      | 0.0  | 0.0       | 17.21 | 17.21 | 17.21      | 0.0  
| 0.0         |
+      | 8  | 31   | 01 September 2024| 15 March 2024    | 0.0             | 
15.37         | 0.0      | 0.0  | 0.0       | 15.37 | 15.37 | 15.37      | 0.0  
| 0.0         |
+    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.0      | 0.0  | 0.0       | 118.43 | 118.43 | 101.42 
    | 0.0  | 0.0         |
+    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    |
+      | 15 March 2024    | Re-age           | 101.42 | 100.0     | 1.42     | 
0.0  | 0.0       | 0.0          | false    | false    |
+      | 15 March 2024    | Repayment        | 101.42 | 100.0     | 1.42     | 
0.0  | 0.0       | 0.0          | false    | false    |
+
+  Scenario: Verify allowing Re-aging on interest bearing loan - Interest 
calculation: Default Behavior - Charge-back before re-aging and installment is 
partially paid - UC3.1
+    When Admin sets the business date to "01 January 2024"
+    When Admin creates a client with random data
+    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_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"
+    When 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:
+      | 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.57           | 16.43     
    | 0.58     | 0.0  | 0.0       | 17.01 | 0.0  | 0.0        | 0.0  | 17.01    
   |
+      | 2  | 29   | 01 March 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     
   |
+    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.05     | 0.0  | 0.0       | 102.05 | 0.0  | 0.0      
  | 0.0  | 102.05      |
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type | Amount | Principal | Interest | 
Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement     | 100.0  | 0.0       | 0.0      | 
0.0  | 0.0       | 100.0        | false    |
+    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
+    When Admin makes "REPAYMENT_ADJUSTMENT_CHARGEBACK" chargeback with 17.01 
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    |                  | 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  | 0.0       | 119.15 | 17.01 | 0.0     
   | 0.0  | 102.14      |
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type | Amount | Principal | Interest | 
Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement     | 100.0  | 0.0       | 0.0      | 
0.0  | 0.0       | 100.0        | false    |
+      | 01 February 2024 | Repayment        | 17.01  | 16.43     | 0.58     | 
0.0  | 0.0       | 83.57        | false    |
+      | 01 February 2024 | Chargeback       | 17.01  | 16.43     | 0.58     | 
0.0  | 0.0       | 100.0        | false    |
+    When Admin sets the business date to "01 March 2024"
+    And Customer makes "AUTOPAY" repayment on "01 March 2024" with 10.0 EUR 
transaction amount
+    When Admin sets the business date to "15 March 2024"
+    When Admin creates a Loan re-aging transaction with the following data:
+      | frequencyNumber | frequencyType | startDate    | numberOfInstallments |
+      | 1               | MONTHS        | 01 April 2024| 6                    |
+    Then Loan Repayment schedule has 8 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    | 90.0            | 
10.0          | 0.0      | 0.0  | 0.0       | 10.0  | 10.0  | 0.0        | 0.0  
| 0.0         |
+      | 3  | 31   | 01 April 2024    |                  | 76.18           | 
13.82         | 1.68     | 0.0  | 0.0       | 15.5  | 0.0   | 0.0        | 0.0  
| 15.5        |
+      | 4  | 30   | 01 May 2024      |                  | 61.12           | 
15.06         | 0.44     | 0.0  | 0.0       | 15.5  | 0.0   | 0.0        | 0.0  
| 15.5        |
+      | 5  | 31   | 01 June 2024     |                  | 45.98           | 
15.14         | 0.36     | 0.0  | 0.0       | 15.5  | 0.0   | 0.0        | 0.0  
| 15.5        |
+      | 6  | 30   | 01 July 2024     |                  | 30.75           | 
15.23         | 0.27     | 0.0  | 0.0       | 15.5  | 0.0   | 0.0        | 0.0  
| 15.5        |
+      | 7  | 31   | 01 August 2024   |                  | 15.43           | 
15.32         | 0.18     | 0.0  | 0.0       | 15.5  | 0.0   | 0.0        | 0.0  
| 15.5        |
+      | 8  | 31   | 01 September 2024|                  | 0.0             | 
15.43         | 0.09     | 0.0  | 0.0       | 15.52 | 0.0   | 0.0        | 0.0  
| 15.52       |
+    Then Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due    | Paid | In 
advance | Late | Outstanding |
+      | 116.43        | 3.6      | 0.0  | 0.0       | 120.03 | 27.01| 0.0      
  | 0.0  | 93.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    |
+      | 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    |
+      | 01 March 2024    | Repayment        | 10.0   | 10.0      | 0.0      | 
0.0  | 0.0       | 90.0         | false    | false    |
+      | 15 March 2024    | Re-age           | 91.4   | 90.0      | 1.4      | 
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
+    Then Loan Repayment schedule has 8 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    | 90.0            | 
10.0          | 0.0      | 0.0  | 0.0       | 10.0  | 10.0  | 0.0        | 0.0  
| 0.0         |
+      | 3  | 31   | 01 April 2024    | 15 March 2024    | 75.9            | 
14.1          | 1.4      | 0.0  | 0.0       | 15.5  | 15.5  | 15.5       | 0.0  
| 0.0         |
+      | 4  | 30   | 01 May 2024      | 15 March 2024    | 60.4            | 
15.5          | 0.0      | 0.0  | 0.0       | 15.5  | 15.5  | 15.5       | 0.0  
| 0.0         |
+      | 5  | 31   | 01 June 2024     | 15 March 2024    | 44.9            | 
15.5          | 0.0      | 0.0  | 0.0       | 15.5  | 15.5  | 15.5       | 0.0  
| 0.0         |
+      | 6  | 30   | 01 July 2024     | 15 March 2024    | 29.4            | 
15.5          | 0.0      | 0.0  | 0.0       | 15.5  | 15.5  | 15.5       | 0.0  
| 0.0         |
+      | 7  | 31   | 01 August 2024   | 15 March 2024    | 13.9            | 
15.5          | 0.0      | 0.0  | 0.0       | 15.5  | 15.5  | 15.5       | 0.0  
| 0.0         |
+      | 8  | 31   | 01 September 2024| 15 March 2024    | 0.0             | 
13.9          | 0.0      | 0.0  | 0.0       | 13.9  | 13.9  | 13.9       | 0.0  
| 0.0         |
+    Then Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due    | Paid   | In 
advance | Late | Outstanding |
+      | 116.43        | 1.98     | 0.0  | 0.0       | 118.41 | 118.41 | 91.4   
    | 0.0  | 0.0         |
+    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    |
+      | 01 March 2024    | Repayment        | 10.0   | 10.0      | 0.0      | 
0.0  | 0.0       | 90.0         | false    | false    |
+      | 15 March 2024    | Re-age           | 91.4   | 90.0      | 1.4      | 
0.0  | 0.0       | 0.0          | false    | false    |
+      | 15 March 2024    | Repayment        | 91.4   | 90.0      | 1.4      | 
0.0  | 0.0       | 0.0          | false    | false    |
+
   @TestRailId:C4083 @AdvancedPaymentAllocation
   Scenario: Verify allowing Re-aging on interest bearing loan - Interest 
calculation: Default Behavior - N+1 Scenario - UC4
     When Admin sets the business date to "01 January 2024"
diff --git 
a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/EMICalculator.java
 
b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/EMICalculator.java
index 6228e2c4d9..2706efb751 100644
--- 
a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/EMICalculator.java
+++ 
b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/EMICalculator.java
@@ -142,7 +142,7 @@ public interface EMICalculator {
     void applyInterestPause(ProgressiveLoanInterestScheduleModel 
scheduleModel, LocalDate fromDate, LocalDate endDate);
 
     void 
updateModelRepaymentPeriodsDuringReAge(ProgressiveLoanInterestScheduleModel 
ctx, LocalDate loanTransaction,
-            LocalDate reageFirstDueDate, LocalDate transactionDate, 
LoanApplicationTerms loanApplicationTerms, MathContext mc);
+            LocalDate reAgeFirstDueDate, LocalDate transactionDate, 
LoanApplicationTerms loanApplicationTerms, MathContext mc);
 
     boolean 
recalculateModelOverdueAmountsTillDate(ProgressiveLoanInterestScheduleModel 
ctx, LocalDate targetDate, boolean prepayAttempt);
 
diff --git 
a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java
 
b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java
index 311098ab56..cb51772ebd 100644
--- 
a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java
+++ 
b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java
@@ -777,6 +777,7 @@ public final class ProgressiveEMICalculator implements 
EMICalculator {
             final InterestPeriod lastInterestPeriod = 
rp.getInterestPeriods().getLast();
             
lastInterestPeriod.addBalanceCorrectionAmount(rp.getOutstandingPrincipal().negated());
             rp.setEmi(rp.getTotalPaidAmount());
+            rp.setOutstandingMovedDueToReAging(true);
         });
     }
 
diff --git 
a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/RepaymentPeriod.java
 
b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/RepaymentPeriod.java
index 2367733da9..5d25eab78a 100644
--- 
a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/RepaymentPeriod.java
+++ 
b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/RepaymentPeriod.java
@@ -88,6 +88,10 @@ public class RepaymentPeriod {
     @JsonExclude
     private MonetaryCurrency currency;
 
+    @Getter
+    @Setter
+    private boolean isOutstandingMovedDueToReAging = false;
+
     protected RepaymentPeriod(RepaymentPeriod previous, LocalDate fromDate, 
LocalDate dueDate, List<InterestPeriod> interestPeriods,
             Money emi, Money originalEmi, Money paidPrincipal, Money 
paidInterest, Money futureUnrecognizedInterest, MathContext mc,
             ILoanConfigurationDetails loanProductRelatedDetail) {
@@ -123,6 +127,7 @@ public class RepaymentPeriod {
                 repaymentPeriod.getDueDate(), new ArrayList<>(), 
repaymentPeriod.getEmi(), repaymentPeriod.getOriginalEmi(),
                 repaymentPeriod.getPaidPrincipal(), 
repaymentPeriod.getPaidInterest(), 
repaymentPeriod.getFutureUnrecognizedInterest(), mc,
                 repaymentPeriod.getLoanProductRelatedDetail());
+        
newRepaymentPeriod.setOutstandingMovedDueToReAging(repaymentPeriod.isOutstandingMovedDueToReAging());
         // There is always at least 1 interest period, by default with same 
from-due date as repayment period
         for (InterestPeriod interestPeriod : 
repaymentPeriod.getInterestPeriods()) {
             
newRepaymentPeriod.getInterestPeriods().add(InterestPeriod.copy(newRepaymentPeriod,
 interestPeriod, mc));
@@ -135,6 +140,7 @@ public class RepaymentPeriod {
         final RepaymentPeriod newRepaymentPeriod = new 
RepaymentPeriod(previous, repaymentPeriod.getFromDate(),
                 repaymentPeriod.getDueDate(), new ArrayList<>(), 
repaymentPeriod.getEmi(), repaymentPeriod.getOriginalEmi(), zero, zero,
                 zero, mc, repaymentPeriod.getLoanProductRelatedDetail());
+        
newRepaymentPeriod.setOutstandingMovedDueToReAging(repaymentPeriod.isOutstandingMovedDueToReAging());
         // There is always at least 1 interest period, by default with same 
from-due date as repayment period
         for (InterestPeriod interestPeriod : 
repaymentPeriod.getInterestPeriods()) {
             var interestPeriodCopy = InterestPeriod.copy(newRepaymentPeriod, 
interestPeriod);
@@ -282,7 +288,8 @@ public class RepaymentPeriod {
      * @return
      */
     public Money getTotalCreditedAmount() {
-        return getCreditedPrincipal().plus(getCreditedInterest(), getMc());
+        return isOutstandingMovedDueToReAging ? Money.zero(getCurrency(), 
getMc())
+                : getCreditedPrincipal().plus(getCreditedInterest(), getMc());
     }
 
     /**

Reply via email to