use of org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean in project head by mifos.
the class LoanAccountActionForm method validateMaxPayableAmount.
private void validateMaxPayableAmount(HttpServletRequest request, ActionErrors errors) throws InvalidDateException {
Money totalAmount = Money.zero(getCurrencyFromLoanOffering(request));
Money paymentAmount = Money.zero(getCurrencyFromLoanOffering(request));
for (PaymentDataHtmlBean paymentDataHtmlBean : getPaymentDataBeans()) {
totalAmount = totalAmount.add(paymentDataHtmlBean.totalAsMoney());
paymentAmount = paymentAmount.add(paymentDataHtmlBean.paymentAmountAsMoney());
}
if (paymentAmount.isGreaterThan(totalAmount)) {
errors.add(LoanExceptionConstants.EXCESS_PAYMENT, new ActionMessage(LoanExceptionConstants.EXCESS_PAYMENT));
}
}
use of org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean in project head by mifos.
the class LoanAccountActionForm method validatePaymentDatesOrdering.
void validatePaymentDatesOrdering(List<PaymentDataHtmlBean> validPaymentBeans, ActionErrors errors) {
List<java.util.Date> transactionDates = collect(validPaymentBeans, new Transformer<PaymentDataHtmlBean, java.util.Date>() {
@Override
public java.util.Date transform(PaymentDataHtmlBean input) {
return input.getTransactionDate();
}
});
int indexOutOfOrder = itemIndexOutOfAscendingOrder(transactionDates);
if (indexOutOfOrder >= 0) {
String installmentNumber = validPaymentBeans.get(indexOutOfOrder).getInstallmentNumber();
String errorCode = LoanExceptionConstants.INVALIDTRANSACTIONDATEORDER;
errors.add(errorCode, new ActionMessage(errorCode, installmentNumber));
}
}
use of org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean in project head by mifos.
the class LoanAccountActionFormTest method testTransactionDateIsRequiredOnPayment.
public void testTransactionDateIsRequiredOnPayment() {
Money amount = new Money(rupee, "10");
RepaymentScheduleInstallment installment = new RepaymentScheduleInstallment(1, new Date(), amount, amount, amount, amount, amount);
PaymentDataHtmlBean bean = new PaymentDataHtmlBean(null, null, installment);
bean.setAmount("10");
bean.setDate("");
ActionErrors errors = new ActionErrors();
form.validateTransactionDateOnPayment(errors, bean);
Assert.assertEquals(1, errors.size());
errors = new ActionErrors();
bean.setDate("10/12/2010");
form.validateTransactionDateOnPayment(errors, bean);
Assert.assertEquals(0, errors.size());
}
use of org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean in project head by mifos.
the class LoanAccountActionFormTest method testValidatePaymentDatesOrdering.
public void testValidatePaymentDatesOrdering() {
ActionErrors actionErrors;
RepaymentScheduleInstallment installment1 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "49")).withTotalValue("50").withDueDateValue("01-Feb-2010").withTotalValue("522.0").withInstallment(1).build();
RepaymentScheduleInstallment installment2 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "49")).withTotalValue("50").withDueDateValue("01-Mar-2010").withTotalValue("522.0").withInstallment(2).build();
RepaymentScheduleInstallment installment3 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "49")).withTotalValue("50").withDueDateValue("01-Apr-2010").withTotalValue("522.0").withInstallment(3).build();
RepaymentScheduleInstallment installment4 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "49")).withTotalValue("50").withDueDateValue("01-May-2010").withTotalValue("522.0").withInstallment(4).build();
PaymentDataHtmlBean paymentDataHtmlBean1 = new PaymentDataHtmlBean(locale, null, installment1);
paymentDataHtmlBean1.setDate("01-Jan-2010");
PaymentDataHtmlBean paymentDataHtmlBean2 = new PaymentDataHtmlBean(locale, null, installment2);
paymentDataHtmlBean2.setDate("01-Mar-2010");
PaymentDataHtmlBean paymentDataHtmlBean3 = new PaymentDataHtmlBean(locale, null, installment3);
paymentDataHtmlBean3.setDate("01-Feb-2010");
PaymentDataHtmlBean paymentDataHtmlBean4 = new PaymentDataHtmlBean(locale, null, installment4);
paymentDataHtmlBean4.setDate("01-Apr-2010");
List<PaymentDataHtmlBean> validPaymentBeans = asList(paymentDataHtmlBean1, paymentDataHtmlBean2, paymentDataHtmlBean3, paymentDataHtmlBean4);
actionErrors = new ActionErrors();
form.validatePaymentDatesOrdering(validPaymentBeans, actionErrors);
Assert.assertEquals(1, actionErrors.size());
ActionMessage actionMessage = (ActionMessage) actionErrors.get().next();
org.junit.Assert.assertEquals("3", actionMessage.getValues()[0]);
paymentDataHtmlBean3.setDate("03-Mar-2010");
actionErrors = new ActionErrors();
form.validatePaymentDatesOrdering(validPaymentBeans, actionErrors);
Assert.assertEquals(0, actionErrors.size());
}
use of org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean in project head by mifos.
the class LoanAccountActionForm method validateRedoLoanPayments.
private void validateRedoLoanPayments(HttpServletRequest request, ActionErrors errors, MifosCurrency currency) {
Locale locale = getUserContext(request).getPreferredLocale();
try {
CustomerBO customer = getCustomer(request);
List<PaymentDataHtmlBean> validPaymentBeans = getValidatablePaymentBeans();
for (PaymentDataHtmlBean bean : validPaymentBeans) {
validatePaymentDataHtmlBean(errors, currency, locale, customer, bean);
}
validatePaymentDatesOrdering(validPaymentBeans, errors);
validateMaxPayableAmount(request, errors);
} catch (InvalidDateException invalidDate) {
errors.add(LoanExceptionConstants.INVALIDTRANSACTIONDATE, new ActionMessage(LoanExceptionConstants.INVALIDTRANSACTIONDATE));
} catch (FrameworkRuntimeException invalidDate) {
errors.add(LoanExceptionConstants.INVALIDTRANSACTIONDATE, new ActionMessage(LoanExceptionConstants.INVALIDTRANSACTIONDATE));
} catch (MeetingException e) {
errors.add(ExceptionConstants.FRAMEWORKRUNTIMEEXCEPTION, new ActionMessage(ExceptionConstants.FRAMEWORKRUNTIMEEXCEPTION));
} catch (PageExpiredException e) {
errors.add(ExceptionConstants.PAGEEXPIREDEXCEPTION, new ActionMessage(ExceptionConstants.PAGEEXPIREDEXCEPTION));
} catch (PersistenceException e) {
errors.add(ExceptionConstants.FRAMEWORKRUNTIMEEXCEPTION, new ActionMessage(ExceptionConstants.FRAMEWORKRUNTIMEEXCEPTION));
}
}
Aggregations