use of org.mifos.clientportfolio.loan.ui.DateValidator in project head by mifos.
the class LoanRepaymentFormBean method validateEnterLoanRepaymentDetails.
public void validateEnterLoanRepaymentDetails(ValidationContext context) {
MessageContext messageContext = context.getMessageContext();
Errors errors = validator.checkConstraints(this);
if (errors.hasErrors()) {
for (FieldError fieldError : errors.getFieldErrors()) {
String arg = "";
if ("paymentAmount".equals(fieldError.getField())) {
arg = "Amount";
}
messageContext.addMessage(buildValidationMessage("errors.mandatory", fieldError.getField(), arg));
}
}
if (dateValidator == null) {
dateValidator = new DateValidator();
}
//payment date validation
if (!dateValidator.formsValidDate(paymentDateDD, paymentDateMM, paymentDateYY)) {
messageContext.addMessage(buildValidationMessage("errors.invaliddate", "paymentDate", "accounts.date_of_trxn"));
} else if (getPaymentDate().isAfter(new LocalDate())) {
messageContext.addMessage(buildValidationMessage("errors.futuredate", "paymentDate", "accounts.date_of_trxn"));
} else if (getPaymentDate().isBefore(lastPaymentDate)) {
messageContext.addMessage(buildValidationMessage("errors.payment.date.before.last.payment", "paymentDate", "accounts.date_of_trxn"));
}
//receipt date validation
if (isReceiptDateSpecified() && !dateValidator.formsValidDate(receiptDateDD, receiptDateMM, receiptDateYY)) {
messageContext.addMessage(buildValidationMessage("errors.invaliddate", "receiptDate", "accounts.receiptdate"));
}
//amount validation
if (paymentAmount != null && paymentAmount.doubleValue() <= 0) {
messageContext.addMessage(buildValidationMessage("error.penalty.incorrectDouble", "paymentAmount", "Amount"));
}
if (messageContext.hasErrorMessages()) {
this.truePrintReceipt = this.printReceipt;
this.printReceipt = false;
}
}
Aggregations