From a889dbdd2fb5512be00c2c59fa3d665fc79430ea Mon Sep 17 00:00:00 2001 From: Sander van der Heyden Date: Tue, 11 Feb 2014 11:00:30 +0100 Subject: [PATCH] MIFOSX-867 - Fixed disbursement or submit date after repayment startdate by adding validations --- .../portfolio/loanaccount/domain/Loan.java | 10 ++++++++++ ...cationWritePlatformServiceJpaRepositoryImpl.java | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java index 546039e97..9c3acaa03 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java @@ -1649,6 +1649,14 @@ public class Loan extends AbstractPersistable { throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.before.approval.date", errorMessage, disbursedOn, getApprovedOnDate()); } + + if(getExpectedFirstRepaymentOnDate() != null && disbursedOn.isAfter(getExpectedFirstRepaymentOnDate())) + { + final String errorMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate: " + getExpectedFirstRepaymentOnDate().toString(); + throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.after.expected.first.repayment.date", errorMessage, disbursedOn, + getExpectedFirstRepaymentOnDate()); + } + validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_DISBURSED, disbursedOn); @@ -2923,6 +2931,8 @@ public class Loan extends AbstractPersistable { } } } + + public Group group() { return this.group; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java index db618cf78..a15f8dbdf 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java @@ -300,7 +300,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa if (changes.containsKey("expectedDisbursementDate")) { this.loanAssembler.validateExpectedDisbursementForHolidayAndNonWorkingDay(existingLoanApplication); } - + final String clientIdParamName = "clientId"; if (changes.containsKey(clientIdParamName)) { final Long clientId = command.longValueOfParameterNamed(clientIdParamName); @@ -712,6 +712,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa private void validateSubmittedOnDate(final Loan loan) { final LocalDate startDate = loan.loanProduct().getStartDate(); final LocalDate closeDate = loan.loanProduct().getCloseDate(); + final LocalDate expectedFirstRepaymentOnDate = loan.getExpectedFirstRepaymentOnDate(); final LocalDate submittedOnDate = loan.getSubmittedOnDate(); String defaultUserMessage = ""; @@ -726,7 +727,17 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa throw new LoanApplicationDateException("submitted.on.date.cannot.be.after.the.loan.product.close.date", defaultUserMessage, submittedOnDate.toString(), closeDate.toString()); } + + if(expectedFirstRepaymentOnDate != null && submittedOnDate.isAfter(expectedFirstRepaymentOnDate)) + { + defaultUserMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate."; + throw new LoanApplicationDateException("submitted.on.date.cannot.be.after.the.loan.expected.first.repayment.date", defaultUserMessage, + submittedOnDate.toString(), expectedFirstRepaymentOnDate.toString()); + } } + + + private void checkClientOrGroupActive(final Loan loan) { final Client client = loan.client();