}
return matchesCurrentSavingsOfficer;
}
public void reassignSavingsOfficer(final Staff newSavingsOfficer,final LocalDate assignmentDate) {
final SavingsOfficerAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
final SavingsOfficerAssignmentHistory lastAssignmentRecord = findLastAssignmentHistoryRecord(newSavingsOfficer);
// assignment date should not be less than savings account submitted date
if (isSubmittedOnDateAfter(assignmentDate)) {
final String errorMessage = "The Savings Officer assignment date (" + assignmentDate.toString()
+ ") cannot be before savings submitted date (" + getSubmittedOnDate().toString() + ").";
throw new SavingsOfficerAssignmentDateException("cannot.be.before.savings.submitted.date", errorMessage, assignmentDate,
getSubmittedOnDate());
} else if (lastAssignmentRecord != null && lastAssignmentRecord.isEndDateAfter(assignmentDate)) {
final String errorMessage = "The Savings Officer assignment date (" + assignmentDate
+ ") cannot be before previous Savings Officer unassigned date (" + lastAssignmentRecord.getEndDate() + ").";
throw new SavingsOfficerAssignmentDateException("cannot.be.before.previous.unassignement.date", errorMessage, assignmentDate,
lastAssignmentRecord.getEndDate());
} else if (DateUtils.getLocalDateOfTenant().isBefore(assignmentDate)) {
final String errorMessage = "The Savings Officer assignment date (" + assignmentDate + ") cannot be in the future.";
throw new SavingsOfficerAssignmentDateException("cannot.be.a.future.date", errorMessage, assignmentDate);
} else if (latestHistoryRecord != null && this.savingsOfficer.identifiedBy(newSavingsOfficer)) {
latestHistoryRecord.updateStartDate(assignmentDate);
} else if (latestHistoryRecord != null && latestHistoryRecord.matchesStartDateOf(assignmentDate)) {
latestHistoryRecord.updateSavingsOfficer(newSavingsOfficer);
this.savingsOfficer = newSavingsOfficer;
} else if (latestHistoryRecord != null && latestHistoryRecord.hasStartDateBefore(assignmentDate)) {
final String errorMessage = "Savings account with identifier " + getId() + " was already assigned before date " + assignmentDate;
throw new SavingsOfficerAssignmentDateException("is.before.last.assignment.date", errorMessage, getId(), assignmentDate);
} else {
if (latestHistoryRecord != null) {
// savings officer correctly changed from previous savings officer to
// new savings officer
latestHistoryRecord.updateEndDate(assignmentDate);
}
this.savingsOfficer = newSavingsOfficer;
if (isNotSubmittedAndPendingApproval()) {
final SavingsOfficerAssignmentHistory savingsOfficerAssignmentHistory =
SavingsOfficerAssignmentHistory.createNew(this,this.savingsOfficer,assignmentDate);
this.savingsOfficerHistory.add(savingsOfficerAssignmentHistory);
}
}
}