From 3479e44b4048ff5e4eacb65c2c4f4ed623a15caf Mon Sep 17 00:00:00 2001 From: Brian C Cooke Date: Tue, 29 Sep 2020 12:11:11 -0400 Subject: [PATCH] Add validation error for recovery repayments (FINERACT-1113) per FINERACT-1113 and community-app issue #2225, add a validation error when a user attempts a recovery repayment which is greater than the total written off for the loan. Return an error if the recovery repayment amount is greater than the written off amount. Co-authored-by: tonic889 --- .../apache/fineract/portfolio/loanaccount/domain/Loan.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java index 9a419b19f..6b1cf04b2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java @@ -3026,6 +3026,12 @@ public class Loan extends AbstractPersistableCustom { statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_REPAYMENT_OR_WAIVER, LoanStatus.fromInt(this.loanStatus)); } + if (loanTransaction.isRecoveryRepayment() + && loanTransaction.getAmount(loanCurrency()).getAmount().compareTo(getSummary().getTotalWrittenOff()) > 0) { + final String errorMessage = "The transaction amount cannot greater than the remaining written off amount."; + throw new InvalidLoanStateTransitionException("transaction", "cannot.be.greater.than.total.written.off", errorMessage); + } + this.loanStatus = statusEnum.getValue(); loanTransaction.updateLoan(this);