From 4d6820333f48403f07f4ac3b26b517171d7db65a Mon Sep 17 00:00:00 2001 From: Michal Wisniewski Date: Thu, 16 May 2013 15:34:43 +0200 Subject: [PATCH] MIFOSX-328 Loan approval date should not be earlier to the Client activation date --- .../portfolio/client/domain/Client.java | 3 ++- .../portfolio/group/domain/Group.java | 2 +- .../portfolio/loanaccount/domain/Loan.java | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java index dde06235b..0bc1c5f45 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java @@ -367,7 +367,7 @@ public final class Client extends AbstractPersistable { this.displayName = nameBuilder.toString(); } - private LocalDate getActivationLocalDate() { + public LocalDate getActivationLocalDate() { LocalDate activationLocalDate = null; if (this.activationDate != null) { activationLocalDate = LocalDate.fromDateFields(this.activationDate); @@ -390,4 +390,5 @@ public final class Client extends AbstractPersistable { public Long officeId() { return this.office.getId(); } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java index 277240716..d397ce7d8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java @@ -244,7 +244,7 @@ public final class Group extends AbstractPersistable { return actualChanges; } - private LocalDate getActivationLocalDate() { + public LocalDate getActivationLocalDate() { LocalDate activationLocalDate = null; if (this.activationDate != null) { activationLocalDate = new LocalDate(this.activationDate); 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 19a24602f..19a2ec498 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 @@ -942,6 +942,18 @@ public class Loan extends AbstractPersistable { final String errorMessage = "The date on which a loan is submitted cannot be in the future."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.a.future.date", errorMessage, getSubmittedOnDate()); } + + if (!(client == null)){ + if (getSubmittedOnDate().isBefore(client.getActivationLocalDate())) { + final String errorMessage = "The date on which a loan is submitted cannot be earlier than client's activation date."; + throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.client.activation.date", errorMessage, getSubmittedOnDate()); + } + }else if (!(group == null)){ + if (getSubmittedOnDate().isBefore(group.getActivationLocalDate())) { + final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date."; + throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date", errorMessage, getSubmittedOnDate()); + } + } if (getSubmittedOnDate().isAfter(getExpectedDisbursedOnLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " @@ -1069,6 +1081,18 @@ public class Loan extends AbstractPersistable { throw new InvalidLoanStateTransitionException("submittal", "cannot.be.a.future.date", errorMessage, submittedOn); } + if (!(client == null)){ + if (submittedOn.isBefore(client.getActivationLocalDate())) { + final String errorMessage = "The date on which a loan is submitted cannot be earlier than client's activation date."; + throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.client.activation.date", errorMessage, submittedOn); + } + }else if (!(group == null)){ + if (submittedOn.isBefore(group.getActivationLocalDate())) { + final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date."; + throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date", errorMessage, submittedOn); + } + } + if (submittedOn.isAfter(getExpectedDisbursedOnLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " + getExpectedDisbursedOnLocalDate().toString();