Search in sources :

Example 1 with DateValidator

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;
    }
}
Also used : DateValidator(org.mifos.clientportfolio.loan.ui.DateValidator) Errors(org.springframework.validation.Errors) FieldError(org.springframework.validation.FieldError) MessageContext(org.springframework.binding.message.MessageContext) LocalDate(org.joda.time.LocalDate)

Aggregations

LocalDate (org.joda.time.LocalDate)1 DateValidator (org.mifos.clientportfolio.loan.ui.DateValidator)1 MessageContext (org.springframework.binding.message.MessageContext)1 Errors (org.springframework.validation.Errors)1 FieldError (org.springframework.validation.FieldError)1