Skip to content

Commit

Permalink
FINERACT-2081: Fix Accrual activity - reverse and replayed couple of …
Browse files Browse the repository at this point in the history
…times after backdated repayment
  • Loading branch information
Rustam Zeinalov authored and Jose Alberto Hernandez committed Feb 26, 2025
1 parent ccf213a commit 6051477
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ fineract-provider/src/main/generated/

**/out/
gradleExp/

.run/
.java-version
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public abstract class TestContextKey {
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_EMI_ACTUAL_ACTUAL_INTEREST_RECALCULATION_DAILY = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmiActualActualInterestRecalculationDaily";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_INTEREST_RECALCULATION_ACCELERATE_MATURITY_CHARGE_OFF_BEHAVIOUR = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyInterestRecalculationAccelerateMaturityChargeOffBehaviour";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_ACCRUAL_ACTIVITY = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030AccrualActivity";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_ACCELERATE_MATURITY_CHARGE_OFF_BEHAVIOUR = "loanProductCreateResponseLP2AdvancedPaymentAccelerateMaturityChargeOffBehaviour";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_RECOGNITION_DISBURSEMENT_DAILY_EMI_360_30_ACCRUAL_ACTIVITY = "loanProductCreateResponseLP2AdvancedPaymentInterestRecognitionDisbursementDailyEmi36030AccrualActivity";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_ACCELERATE_MATURITY_CHARGE_OFF_BEHAVIOUR = "loanProductCreateResponseLP2AdvancedPaymentAccelerateMaturityChargeOffBehaviour";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_RECOGNITION_DISBURSEMENT_DAILY_EMI_ACTUAL_ACTUAL_ACCRUAL_ACTIVITY = "loanProductCreateResponseLP2AdvancedPaymentInterestRecognitionDisbursementDailyEmiActualActualAccrualActivity";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_INTEREST_RECALC_EMI_360_30_CHARGEBACK_INTEREST_PENALTY_FEE_PRINCIPAL = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyInterestRecalcEmi36030ChargebackInterestPenaltyFeePrincipal";
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_INTEREST_RECALC_EMI_360_30_CHARGEBACK_INTEREST_FEE_PRINCIPAL = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyInterestRecalcEmi36030ChargebackInterestFeePrincipal";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4584,7 +4584,7 @@ Feature: LoanAccrualActivity
| 1 | 29 | 29 February 2024 | | 1671.5 | 328.5 | 11.67 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 2 | 31 | 31 March 2024 | | 1341.14 | 330.36 | 9.81 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 3 | 30 | 30 April 2024 | | 1008.79 | 332.35 | 7.82 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 4 | 31 | 31 May 2024 | | 674.5 | 334.29 | 5.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 4 | 31 | 31 May 2024 | | 674.5 | 334.29 | 5.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 5 | 30 | 30 June 2024 | | 338.26 | 336.24 | 3.93 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 6 | 31 | 31 July 2024 | | 0.0 | 338.26 | 1.97 | 0.0 | 0.0 | 340.23 | 0.0 | 0.0 | 0.0 | 340.23 |
Then Loan Repayment schedule has the following data in Total row:
Expand Down Expand Up @@ -4629,11 +4629,11 @@ Feature: LoanAccrualActivity
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 31 January 2024 | | 2000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 29 | 29 February 2024 | 15 February 2024 | 1665.86 | 334.14 | 6.03 | 0.0 | 0.0 | 340.17 | 340.17 | 340.17 | 0.0 | 0.0 |
| 2 | 31 | 31 March 2024 | | 1340.11 | 325.75 | 14.42 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 2 | 31 | 31 March 2024 | | 1340.11 | 325.75 | 14.42 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 3 | 30 | 30 April 2024 | | 1007.76 | 332.35 | 7.82 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 4 | 31 | 31 May 2024 | | 673.47 | 334.29 | 5.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 4 | 31 | 31 May 2024 | | 673.47 | 334.29 | 5.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 5 | 30 | 30 June 2024 | | 337.23 | 336.24 | 3.93 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 6 | 31 | 31 July 2024 | | 0.0 | 337.23 | 1.97 | 0.0 | 0.0 | 339.2 | 0.0 | 0.0 | 0.0 | 339.2 |
| 6 | 31 | 31 July 2024 | | 0.0 | 337.23 | 1.97 | 0.0 | 0.0 | 339.2 | 0.0 | 0.0 | 0.0 | 339.2 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 2000.0 | 40.05 | 0.0 | 0.0 | 2040.05 | 340.17 | 340.17 | 0.0 | 1699.88 |
Expand Down Expand Up @@ -4680,7 +4680,7 @@ Feature: LoanAccrualActivity
| 1 | 29 | 29 February 2024 | 15 February 2024 | 1665.86 | 334.14 | 6.03 | 0.0 | 0.0 | 340.17 | 340.17 | 340.17 | 0.0 | 0.0 |
| 2 | 31 | 31 March 2024 | | 1340.11 | 325.75 | 14.42 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 3 | 30 | 30 April 2024 | | 1007.82 | 332.29 | 7.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 4 | 31 | 31 May 2024 | | 673.53 | 334.29 | 5.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 4 | 31 | 31 May 2024 | | 673.53 | 334.29 | 5.88 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 5 | 30 | 30 June 2024 | | 337.29 | 336.24 | 3.93 | 0.0 | 0.0 | 340.17 | 0.0 | 0.0 | 0.0 | 340.17 |
| 6 | 31 | 31 July 2024 | | 0.0 | 337.29 | 1.97 | 0.0 | 0.0 | 339.26 | 0.0 | 0.0 | 0.0 | 339.26 |
Then Loan Repayment schedule has the following data in Total row:
Expand Down Expand Up @@ -4721,7 +4721,7 @@ Feature: LoanAccrualActivity
| 28 February 2024 | Accrual | 0.41 | 0.0 | 0.41 | 0.0 | 0.0 | 0.0 | false | false |
| 29 February 2024 | Accrual | 0.38 | 0.0 | 0.38 | 0.0 | 0.0 | 0.0 | false | false |
| 29 February 2024 | Accrual Activity | 6.03 | 0.0 | 6.03 | 0.0 | 0.0 | 0.0 | false | true |
| 01 March 2024 | Accrual Adjustment | 0.69 | 0.0 | 0.69 | 0.0 | 0.0 | 0.0 | false | false |
| 01 March 2024 | Accrual Adjustment | 0.69 | 0.0 | 0.69 | 0.0 | 0.0 | 0.0 | false | false |
| 02 March 2024 | Accrual | 0.31 | 0.0 | 0.31 | 0.0 | 0.0 | 0.0 | false | false |
| 03 March 2024 | Accrual | 0.31 | 0.0 | 0.31 | 0.0 | 0.0 | 0.0 | false | false |
| 04 March 2024 | Accrual | 0.32 | 0.0 | 0.32 | 0.0 | 0.0 | 0.0 | false | false |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,9 @@ public void resetPrincipalDue() {
public enum PaymentAction {
PAY, UNPAY
}

public boolean isTransactionDateWithinPeriod(LocalDate transactionDate) {
return !DateUtils.isBefore(transactionDate, getFromDate()) && DateUtils.isBefore(transactionDate, getDueDate());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1035,4 +1035,8 @@ public void updateAmount(BigDecimal bigDecimal) {

// TODO missing hashCode(), equals(Object obj), but probably OK as long as
// this is never stored in a Collection.

public void updateTransactionDate(final LocalDate transactionDate) {
this.dateOf = transactionDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,17 @@ protected void calculateAccrualActivity(LoanTransaction loanTransaction, Monetar
Money interestPortion = currentInstallment.getInterestCharged(currency);
Money feeChargesPortion = currentInstallment.getFeeChargesCharged(currency);
Money penaltyChargesPortion = currentInstallment.getPenaltyChargesCharged(currency);
loanTransaction.updateComponentsAndTotal(principalPortion, interestPortion, feeChargesPortion, penaltyChargesPortion);
if (interestPortion.plus(feeChargesPortion).plus(penaltyChargesPortion).isZero()) {
loanTransaction.reverse();
} else {
loanTransaction.updateComponentsAndTotal(principalPortion, interestPortion, feeChargesPortion, penaltyChargesPortion);
final Loan loan = loanTransaction.getLoan();
if ((loan.isClosedObligationsMet() || loan.isOverPaid()) && currentInstallment.isObligationsMet()
&& currentInstallment.getObligationsMetOnDate().isBefore(currentInstallment.getDueDate())
&& currentInstallment.isTransactionDateWithinPeriod(loanTransaction.getDateOf())) {
loanTransaction.updateTransactionDate(currentInstallment.getObligationsMetOnDate());
}
}
}
}

Expand Down
Loading

0 comments on commit 6051477

Please sign in to comment.