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 8f13a73e27e..2902c022293 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 @@ -3253,10 +3253,11 @@ private ChangedTransactionDetail handleRepaymentOrRecoveryOrWaiverTransaction(fi if (this.loanProduct.isMultiDisburseLoan() && adjustedTransaction == null) { BigDecimal totalDisbursed = getDisbursedAmount(); - if (totalDisbursed.compareTo(this.summary.getTotalPrincipalRepaid()) < 0) { - final String errorMessage = "The transaction cannot be done before the loan disbursement: " - + getApprovedOnDate().toString(); - throw new InvalidLoanStateTransitionException("transaction", "cannot.be.done.before.disbursement", errorMessage); + BigDecimal totalPrincipalAdjusted = this.summary.getTotalPrincipalAdjustments(); + BigDecimal totalPrincipalCredited = totalDisbursed.add(totalPrincipalAdjusted); + if (totalPrincipalCredited.compareTo(this.summary.getTotalPrincipalRepaid()) < 0) { + final String errorMessage = "The transaction amount cannot exceed threshold."; + throw new InvalidLoanStateTransitionException("transaction", "amount.exceeds.threshold", errorMessage); } } @@ -3318,11 +3319,12 @@ private ChangedTransactionDetail handleRepaymentOrRecoveryOrWaiverTransaction(fi if (this.loanProduct.isMultiDisburseLoan()) { BigDecimal totalDisbursed = getDisbursedAmount(); - if (totalDisbursed.compareTo(this.summary.getTotalPrincipalRepaid()) < 0 + BigDecimal totalPrincipalAdjusted = this.summary.getTotalPrincipalAdjustments(); + BigDecimal totalPrincipalCredited = totalDisbursed.add(totalPrincipalAdjusted); + if (totalPrincipalCredited.compareTo(this.summary.getTotalPrincipalRepaid()) < 0 && this.repaymentScheduleDetail().getPrincipal().minus(totalDisbursed).isGreaterThanZero()) { - final String errorMessage = "The transaction cannot be done before the loan disbursement: " - + getApprovedOnDate().toString(); - throw new InvalidLoanStateTransitionException("transaction", "cannot.be.done.before.disbursement", errorMessage); + final String errorMessage = "The transaction amount cannot exceed threshold."; + throw new InvalidLoanStateTransitionException("transaction", "amount.exceeds.threshold", errorMessage); } } @@ -6197,10 +6199,11 @@ private ChangedTransactionDetail handleRefundTransaction(final LoanTransaction l if (this.loanProduct.isMultiDisburseLoan() && adjustedTransaction == null) { BigDecimal totalDisbursed = getDisbursedAmount(); - if (totalDisbursed.compareTo(this.summary.getTotalPrincipalRepaid()) < 0) { - final String errorMessage = "The transaction cannot be done before the loan disbursement: " - + getApprovedOnDate().toString(); - throw new InvalidLoanStateTransitionException("transaction", "cannot.be.done.before.disbursement", errorMessage); + BigDecimal totalPrincipalAdjusted = this.summary.getTotalPrincipalAdjustments(); + BigDecimal totalPrincipalCredited = totalDisbursed.add(totalPrincipalAdjusted); + if (totalPrincipalCredited.compareTo(this.summary.getTotalPrincipalRepaid()) < 0) { + final String errorMessage = "The transaction amount cannot exceed threshold."; + throw new InvalidLoanStateTransitionException("transaction", "amount.exceeds.threshold", errorMessage); } }