From 145adaa9fe8ba070b9aa87a4f341dc278b41d67d Mon Sep 17 00:00:00 2001 From: Ruchi Dhamankar Date: Mon, 9 Jan 2023 20:39:55 +0530 Subject: [PATCH] FINERACT-1818-Credit-Refund-Payout-Not-Getting-Created --- .../portfolio/loanaccount/domain/Loan.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) 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); } }