MIFOSX-162 - Fixed date validation
This commit is contained in:
+27
-21
@@ -1840,6 +1840,10 @@ public class Loan extends AbstractPersistable<Long> {
|
|||||||
return hasRepaymentTransaction;
|
return hasRepaymentTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSubmittedOnDateAfter(final LocalDate compareDate) {
|
||||||
|
return this.submittedOnDate == null ? false : (new LocalDate(submittedOnDate)).isAfter(compareDate);
|
||||||
|
}
|
||||||
|
|
||||||
private LocalDate getSubmittedOnDate() {
|
private LocalDate getSubmittedOnDate() {
|
||||||
return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.submittedOnDate), null);
|
return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.submittedOnDate), null);
|
||||||
}
|
}
|
||||||
@@ -1973,31 +1977,31 @@ public class Loan extends AbstractPersistable<Long> {
|
|||||||
public void reassignLoanOfficer(final Staff newLoanOfficer, final LocalDate assignmentDate) {
|
public void reassignLoanOfficer(final Staff newLoanOfficer, final LocalDate assignmentDate) {
|
||||||
|
|
||||||
final LoanOfficerAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
|
final LoanOfficerAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
|
||||||
final LoanOfficerAssignmentHistory lastAssignmentRecordWithNoEndDate = findLastAssignmentHistoryRecord();
|
final LoanOfficerAssignmentHistory lastAssignmentRecord = findLastAssignmentHistoryRecord(newLoanOfficer);
|
||||||
|
|
||||||
// assignment date should not be less than loan submitted date
|
// assignment date should not be less than loan submitted date
|
||||||
if (getSubmittedOnDate().isAfter(assignmentDate)) {
|
if (this.isSubmittedOnDateAfter(assignmentDate)) {
|
||||||
|
|
||||||
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate.toString()
|
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate.toString()
|
||||||
+ ") cannot be before loan submitted date (" + getSubmittedOnDate().toString() + ").";
|
+ ") cannot be before loan submitted date (" + getSubmittedOnDate().toString() + ").";
|
||||||
|
|
||||||
throw new LoanOfficerAssignmentDateException("cannot.be.before.loan.submittal.date", errorMessage, assignmentDate,
|
throw new LoanOfficerAssignmentDateException("cannot.be.before.loan.submittal.date", errorMessage, assignmentDate,
|
||||||
getSubmittedOnDate());
|
getSubmittedOnDate());
|
||||||
|
|
||||||
// assignment date should not be less than latest unassignment date
|
} else if (lastAssignmentRecord != null && lastAssignmentRecord.isEndDateAfter(assignmentDate)) {
|
||||||
// FIXME - rather then fetching the data from the object all the
|
|
||||||
// time e.g
|
|
||||||
// getEndDate() and asking questions of it - move the operation to
|
|
||||||
// the object e.g. obj.isEndDateAfter(date)
|
|
||||||
} else if (lastAssignmentRecordWithNoEndDate != null && lastAssignmentRecordWithNoEndDate.getEndDate() != null
|
|
||||||
&& lastAssignmentRecordWithNoEndDate.getEndDate().isAfter(assignmentDate)) {
|
|
||||||
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate
|
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate
|
||||||
+ ") cannot be before previous Loan Officer unassigned date (" + lastAssignmentRecordWithNoEndDate.getEndDate() + ").";
|
+ ") cannot be before previous Loan Officer unassigned date (" + lastAssignmentRecord.getEndDate() + ").";
|
||||||
|
|
||||||
throw new LoanOfficerAssignmentDateException("cannot.be.before.previous.unassignement.date", errorMessage, assignmentDate,
|
throw new LoanOfficerAssignmentDateException("cannot.be.before.previous.unassignement.date", errorMessage, assignmentDate,
|
||||||
lastAssignmentRecordWithNoEndDate.getEndDate());
|
lastAssignmentRecord.getEndDate());
|
||||||
|
|
||||||
// assignment date should not be in the future
|
|
||||||
} else if (DateUtils.getLocalDateOfTenant().isBefore(assignmentDate)) {
|
} else if (DateUtils.getLocalDateOfTenant().isBefore(assignmentDate)) {
|
||||||
|
|
||||||
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate + ") cannot be in the future.";
|
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate + ") cannot be in the future.";
|
||||||
|
|
||||||
throw new LoanOfficerAssignmentDateException("cannot.be.a.future.date", errorMessage, assignmentDate);
|
throw new LoanOfficerAssignmentDateException("cannot.be.a.future.date", errorMessage, assignmentDate);
|
||||||
|
|
||||||
} else if (latestHistoryRecord != null && this.loanOfficer.identifiedBy(newLoanOfficer)) {
|
} else if (latestHistoryRecord != null && this.loanOfficer.identifiedBy(newLoanOfficer)) {
|
||||||
latestHistoryRecord.updateStartDate(assignmentDate);
|
latestHistoryRecord.updateStartDate(assignmentDate);
|
||||||
} else if (latestHistoryRecord != null && latestHistoryRecord.matchesStartDateOf(assignmentDate)) {
|
} else if (latestHistoryRecord != null && latestHistoryRecord.matchesStartDateOf(assignmentDate)) {
|
||||||
@@ -2066,22 +2070,24 @@ public class Loan extends AbstractPersistable<Long> {
|
|||||||
return latestRecordWithNoEndDate;
|
return latestRecordWithNoEndDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LoanOfficerAssignmentHistory findLastAssignmentHistoryRecord() {
|
private LoanOfficerAssignmentHistory findLastAssignmentHistoryRecord(final Staff newLoanOfficer) {
|
||||||
|
|
||||||
LoanOfficerAssignmentHistory lastAssignmentRecordWithNoEndDate = null;
|
LoanOfficerAssignmentHistory lastAssignmentRecordLatestEndDate = null;
|
||||||
for (LoanOfficerAssignmentHistory historyRecord : this.loanOfficerHistory) {
|
for (LoanOfficerAssignmentHistory historyRecord : this.loanOfficerHistory) {
|
||||||
if (historyRecord.isCurrentRecord()) {
|
|
||||||
lastAssignmentRecordWithNoEndDate = historyRecord;
|
if (historyRecord.isCurrentRecord() && !historyRecord.isSameLoanOfficer(newLoanOfficer)) {
|
||||||
|
lastAssignmentRecordLatestEndDate = historyRecord;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastAssignmentRecordWithNoEndDate == null) {
|
if (lastAssignmentRecordLatestEndDate == null){
|
||||||
lastAssignmentRecordWithNoEndDate = historyRecord;
|
lastAssignmentRecordLatestEndDate = historyRecord;
|
||||||
} else if (historyRecord.getEndDate().isAfter(lastAssignmentRecordWithNoEndDate.getEndDate())) {
|
} else if (historyRecord.isEndDateAfter(lastAssignmentRecordLatestEndDate.getEndDate())
|
||||||
lastAssignmentRecordWithNoEndDate = historyRecord;
|
&& !historyRecord.isSameLoanOfficer(newLoanOfficer)) {
|
||||||
|
lastAssignmentRecordLatestEndDate = historyRecord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lastAssignmentRecordWithNoEndDate;
|
return lastAssignmentRecordLatestEndDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getClientId() {
|
public Long getClientId() {
|
||||||
|
|||||||
+16
-5
@@ -15,6 +15,7 @@ import javax.persistence.Table;
|
|||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||||
@@ -29,7 +30,6 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom<AppUse
|
|||||||
@JoinColumn(name = "loan_id", nullable = false)
|
@JoinColumn(name = "loan_id", nullable = false)
|
||||||
private Loan loan;
|
private Loan loan;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "loan_officer_id", nullable = true)
|
@JoinColumn(name = "loan_officer_id", nullable = true)
|
||||||
private Staff loanOfficer;
|
private Staff loanOfficer;
|
||||||
@@ -85,9 +85,20 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom<AppUse
|
|||||||
return this.endDate == null;
|
return this.endDate == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getEndDate() {
|
/**
|
||||||
// FIXME - new LocalDate(null) will return todays date and endDate is
|
* If endDate is null then return false.
|
||||||
// likely to be null so you need to test for it.
|
* @param compareDate
|
||||||
return new LocalDate(endDate);
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isEndDateAfter(final LocalDate compareDate){
|
||||||
|
return this.endDate == null ? false : (new LocalDate(endDate)).isAfter(compareDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getEndDate(){
|
||||||
|
return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.endDate), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSameLoanOfficer(final Staff staff){
|
||||||
|
return this.loanOfficer.identifiedBy(staff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -58,13 +58,13 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
|
|||||||
+ "(c.display_name like :partialSearch and c.display_name not like :search) or "
|
+ "(c.display_name like :partialSearch and c.display_name not like :search) or "
|
||||||
+ "(c.external_id like :partialSearch and c.external_id not like :search))";
|
+ "(c.external_id like :partialSearch and c.external_id not like :search))";
|
||||||
|
|
||||||
String loanExactMatchSql = " (select 'LOAN' as entityType, l.id as entityId, l.account_no as entityName, l.external_id as entityExternalId, l.account_no as entityAccountNo "
|
String loanExactMatchSql = " (select 'LOAN' as entityType, l.id as entityId, pl.name as entityName, l.external_id as entityExternalId, l.account_no as entityAccountNo "
|
||||||
+ " , c.id as parentId, c.display_name as parentName "
|
+ " , c.id as parentId, c.display_name as parentName "
|
||||||
+ " from m_loan l join m_client c on l.client_id = c.id join m_office o on o.id = c.office_id where o.hierarchy like :hierarchy and l.account_no like :search) ";
|
+ " from m_loan l join m_client c on l.client_id = c.id join m_office o on o.id = c.office_id join m_product_loan pl on pl.id=l.product_id where o.hierarchy like :hierarchy and l.account_no like :search) ";
|
||||||
|
|
||||||
String loanMatchSql = " (select 'LOAN' as entityType, l.id as entityId, l.account_no as entityName, l.external_id as entityExternalId, l.account_no as entityAccountNo "
|
String loanMatchSql = " (select 'LOAN' as entityType, l.id as entityId, pl.name as entityName, l.external_id as entityExternalId, l.account_no as entityAccountNo "
|
||||||
+ " , c.id as parentId, c.display_name as parentName "
|
+ " , c.id as parentId, c.display_name as parentName "
|
||||||
+ " from m_loan l join m_client c on l.client_id = c.id join m_office o on o.id = c.office_id where o.hierarchy like :hierarchy and l.account_no like :partialSearch and l.account_no not like :search) ";
|
+ " from m_loan l join m_client c on l.client_id = c.id join m_office o on o.id = c.office_id join m_product_loan pl on pl.id=l.product_id where o.hierarchy like :hierarchy and l.account_no like :partialSearch and l.account_no not like :search) ";
|
||||||
|
|
||||||
String clientIdentifierExactMatchSql = " (select 'CLIENTIDENTIFIER' as entityType, ci.id as entityId, ci.document_key as entityName, "
|
String clientIdentifierExactMatchSql = " (select 'CLIENTIDENTIFIER' as entityType, ci.id as entityId, ci.document_key as entityName, "
|
||||||
+ " null as entityExternalId, null as entityAccountNo, c.id as parentId, c.display_name as parentName "
|
+ " null as entityExternalId, null as entityAccountNo, c.id as parentId, c.display_name as parentName "
|
||||||
|
|||||||
Reference in New Issue
Block a user