Search in sources :

Example 1 with PaymentDataHtmlBean

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));
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) PaymentDataHtmlBean(org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean) ActionMessage(org.apache.struts.action.ActionMessage)

Example 2 with PaymentDataHtmlBean

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));
    }
}
Also used : PaymentDataHtmlBean(org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean) ActionMessage(org.apache.struts.action.ActionMessage) Date(java.sql.Date)

Example 3 with PaymentDataHtmlBean

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());
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) PaymentDataHtmlBean(org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean) Date(java.util.Date) ActionErrors(org.apache.struts.action.ActionErrors)

Example 4 with PaymentDataHtmlBean

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());
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) PaymentDataHtmlBean(org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 5 with PaymentDataHtmlBean

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));
    }
}
Also used : Locale(java.util.Locale) FrameworkRuntimeException(org.mifos.framework.exceptions.FrameworkRuntimeException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) PaymentDataHtmlBean(org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO)

Aggregations

PaymentDataHtmlBean (org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean)5 ActionMessage (org.apache.struts.action.ActionMessage)4 Money (org.mifos.framework.util.helpers.Money)3 ActionErrors (org.apache.struts.action.ActionErrors)2 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)2 Date (java.sql.Date)1 Date (java.util.Date)1 Locale (java.util.Locale)1 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 FrameworkRuntimeException (org.mifos.framework.exceptions.FrameworkRuntimeException)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1