From 1eeb1f882a24ef03d82c9756aa850f96f5a332f4 Mon Sep 17 00:00:00 2001 From: Kristof Jozsa Date: Thu, 1 Aug 2024 17:02:32 +0200 Subject: [PATCH] FINERACT-2081: fix disburse error scenario --- .../fineract/portfolio/loanaccount/domain/Loan.java | 10 +--------- .../serialization/LoanTransactionValidator.java | 6 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java index aff66589ff3..a9e25e923c3 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java @@ -2012,18 +2012,10 @@ public void handleDisbursementTransaction(final LocalDate disbursedOn, final Pay updateLoanOutstandingBalances(); } - if (getApprovedOnDate() != null && DateUtils.isBefore(disbursedOn, getApprovedOnDate())) { - final String errorMessage = "The date on which a loan is disbursed cannot be before its approval date: " - + getApprovedOnDate().toString(); - throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.before.approval.date", errorMessage, disbursedOn, - getApprovedOnDate()); - } - LocalDate expectedDate = getExpectedFirstRepaymentOnDate(); if (expectedDate != null && (DateUtils.isAfter(disbursedOn, this.fetchRepaymentScheduleInstallment(1).getDueDate()) || DateUtils.isAfter(disbursedOn, expectedDate)) && DateUtils.isEqual(disbursedOn, this.actualDisbursementDate)) { - final String errorMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate: " - + expectedDate.toString(); + final String errorMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate: " + expectedDate; throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.after.expected.first.repayment.date", errorMessage, disbursedOn, expectedDate); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java index feb50685519..2fc3746b48a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java @@ -213,6 +213,12 @@ public void validateDisbursement(JsonCommand command, boolean isAccountTransfer, loan.getExpectedDisbursedOnLocalDate()); } + LocalDate approvedOnDate = loan.getApprovedOnDate(); + if (DateUtils.isBefore(actualDisbursementDate, approvedOnDate)) { + final String errorMessage = "The date on which a loan is disbursed cannot be before its approval date: " + approvedOnDate; + throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.before.approval.date", errorMessage, + actualDisbursementDate, approvedOnDate); + } }); }