MIFOSX-162 - Fixed date validation

This commit is contained in:
ashok-conflux
2013-03-11 16:52:39 +05:30
parent cf81fe92b1
commit d310d4df3c
3 changed files with 47 additions and 30 deletions
@@ -1840,6 +1840,10 @@ public class Loan extends AbstractPersistable<Long> {
return hasRepaymentTransaction;
}
public boolean isSubmittedOnDateAfter(final LocalDate compareDate) {
return this.submittedOnDate == null ? false : (new LocalDate(submittedOnDate)).isAfter(compareDate);
}
private LocalDate getSubmittedOnDate() {
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) {
final LoanOfficerAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
final LoanOfficerAssignmentHistory lastAssignmentRecordWithNoEndDate = findLastAssignmentHistoryRecord();
final LoanOfficerAssignmentHistory lastAssignmentRecord = findLastAssignmentHistoryRecord(newLoanOfficer);
// 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()
+ ") cannot be before loan submitted date (" + getSubmittedOnDate().toString() + ").";
throw new LoanOfficerAssignmentDateException("cannot.be.before.loan.submittal.date", errorMessage, assignmentDate,
getSubmittedOnDate());
// assignment date should not be less than latest unassignment date
// 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)) {
} else if (lastAssignmentRecord != null && lastAssignmentRecord.isEndDateAfter(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,
lastAssignmentRecordWithNoEndDate.getEndDate());
lastAssignmentRecord.getEndDate());
// assignment date should not be in the future
} else if (DateUtils.getLocalDateOfTenant().isBefore(assignmentDate)) {
final String errorMessage = "The Loan Officer assignment date (" + assignmentDate + ") cannot be in the future.";
throw new LoanOfficerAssignmentDateException("cannot.be.a.future.date", errorMessage, assignmentDate);
} else if (latestHistoryRecord != null && this.loanOfficer.identifiedBy(newLoanOfficer)) {
latestHistoryRecord.updateStartDate(assignmentDate);
} else if (latestHistoryRecord != null && latestHistoryRecord.matchesStartDateOf(assignmentDate)) {
@@ -2066,22 +2070,24 @@ public class Loan extends AbstractPersistable<Long> {
return latestRecordWithNoEndDate;
}
private LoanOfficerAssignmentHistory findLastAssignmentHistoryRecord() {
private LoanOfficerAssignmentHistory findLastAssignmentHistoryRecord(final Staff newLoanOfficer) {
LoanOfficerAssignmentHistory lastAssignmentRecordWithNoEndDate = null;
LoanOfficerAssignmentHistory lastAssignmentRecordLatestEndDate = null;
for (LoanOfficerAssignmentHistory historyRecord : this.loanOfficerHistory) {
if (historyRecord.isCurrentRecord()) {
lastAssignmentRecordWithNoEndDate = historyRecord;
if (historyRecord.isCurrentRecord() && !historyRecord.isSameLoanOfficer(newLoanOfficer)) {
lastAssignmentRecordLatestEndDate = historyRecord;
break;
}
if (lastAssignmentRecordWithNoEndDate == null) {
lastAssignmentRecordWithNoEndDate = historyRecord;
} else if (historyRecord.getEndDate().isAfter(lastAssignmentRecordWithNoEndDate.getEndDate())) {
lastAssignmentRecordWithNoEndDate = historyRecord;
if (lastAssignmentRecordLatestEndDate == null){
lastAssignmentRecordLatestEndDate = historyRecord;
} else if (historyRecord.isEndDateAfter(lastAssignmentRecordLatestEndDate.getEndDate())
&& !historyRecord.isSameLoanOfficer(newLoanOfficer)) {
lastAssignmentRecordLatestEndDate = historyRecord;
}
}
return lastAssignmentRecordWithNoEndDate;
return lastAssignmentRecordLatestEndDate;
}
public Long getClientId() {
@@ -15,6 +15,7 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang.ObjectUtils;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.organisation.staff.domain.Staff;
@@ -29,7 +30,6 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom<AppUse
@JoinColumn(name = "loan_id", nullable = false)
private Loan loan;
@SuppressWarnings("unused")
@ManyToOne
@JoinColumn(name = "loan_officer_id", nullable = true)
private Staff loanOfficer;
@@ -85,9 +85,20 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom<AppUse
return this.endDate == null;
}
public LocalDate getEndDate() {
// FIXME - new LocalDate(null) will return todays date and endDate is
// likely to be null so you need to test for it.
return new LocalDate(endDate);
/**
* If endDate is null then return false.
* @param compareDate
* @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);
}
}
@@ -58,13 +58,13 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
+ "(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))";
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 "
+ " 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 "
+ " 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, "
+ " null as entityExternalId, null as entityAccountNo, c.id as parentId, c.display_name as parentName "