From 0928fb5136148b3df0ab0188e1208ffb890da61d Mon Sep 17 00:00:00 2001 From: Adam Saghy Date: Thu, 9 Mar 2023 16:05:51 +0100 Subject: [PATCH] FINERACT-1806: Charge-off validation --- .../LoanWritePlatformServiceJpaRepositoryImpl.java | 5 +++++ .../integrationtests/ClientLoanIntegrationTest.java | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 96b1352cb..3936b049c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -2729,6 +2729,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf "Loan: " + loanId + " charge-off cannot be executed. User transaction was found after the charge-off transaction date!", loanId); } + if (transactionDate.isAfter(DateUtils.getBusinessLocalDate())) { + final String errorMessage = "The transaction date cannot be in the future."; + throw new GeneralPlatformDomainRuleException("error.msg.loan.transaction.cannot.be.a.future.date", errorMessage, + transactionDate); + } if (loan.isInterestBearing()) { throw new GeneralPlatformDomainRuleException("error.msg.loan.is.interest.bearing", "Loan: " + loanId + " Charge-off is not allowed. Loan Account is interest bearing", loanId); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java index b410ca345..ca6415f48 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java @@ -7003,6 +7003,14 @@ public class ClientLoanIntegrationTest { loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithTransactionAmount("03 September 2022", loanID, "1000"); LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + exception = assertThrows(CallFailedRuntimeException.class, () -> { + this.loanTransactionHelper.chargeOffLoan((long) loanID, + new PostLoansLoanIdTransactionsRequest().transactionDate("1 October 2022").locale("en").dateFormat("dd MMMM yyyy") + .chargeOffReasonId((long) chargeOffReasonId)); + }); + assertEquals(403, exception.getResponse().code()); + assertTrue(exception.getMessage().contains("error.msg.loan.transaction.cannot.be.a.future.date")); + GetLoansLoanIdResponse loanDetails = this.loanTransactionHelper.getLoanDetails((long) loanID); assertTrue(loanDetails.getStatus().getActive()); assertEquals(2000.0, loanDetails.getSummary().getTotalOutstanding());