Search in sources :

Example 6 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class ApplyChargeActionForm method validateAmount.

protected void validateAmount(ActionErrors errors, Locale locale) {
    if (StringUtils.isBlank(getChargeType())) {
        addError(errors, FilePaths.ACCOUNTS_UI_RESOURCE_PROPERTYFILE, "errors.mandatoryselect", getLocalizedMessage("account.chargetype"));
        return;
    }
    DoubleConversionResult conversionResult = null;
    String chargeAmount = getCharge();
    if (StringUtils.isBlank(chargeAmount)) {
        Double amount = 0.0;
        for (Map.Entry<Integer, String> entry : individualValues.entrySet()) {
            amount += Double.valueOf(entry.getValue());
        }
        chargeAmount = amount.toString();
    }
    if (!StringUtils.isBlank(chargeAmount)) {
        if (isRateType()) {
            conversionResult = validateInterest(getCharge(), AccountConstants.ACCOUNT_AMOUNT, errors);
        } else {
            conversionResult = validateAmount(getCharge(), getChargeCurrency(), AccountConstants.ACCOUNT_AMOUNT, errors, "");
        }
    } else {
        addError(errors, AccountConstants.ACCOUNT_AMOUNT, "errors.mandatory", "amount");
    }
    if (conversionResult != null && conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
        addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class SavingsDepositWithdrawalActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = null;
    if (method != null && method.equals(Methods.preview.toString())) {
        errors = new ActionErrors();
        if (StringUtils.isBlank(getTrxnTypeId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.paymentType")));
        }
        if (StringUtils.isBlank(getAmount())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.amount")));
        }
        if (StringUtils.isNotBlank(getAmount())) {
            Locale locale = getUserContext(request).getPreferredLocale();
            DoubleConversionResult conversionResult = validateAmount(getAmount(), AccountConstants.ACCOUNT_AMOUNT, errors);
            if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
                addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
            }
        }
        if (StringUtils.isBlank(getPaymentTypeId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.modeOfPayment")));
        }
        ActionErrors dateError = validateDate(this.trxnDate, getLocalizedMessage("Savings.dateOfTrxn"));
        if (dateError != null && !dateError.isEmpty()) {
            errors.add(dateError);
        }
        dateError = validateTrxnDate(this.trxnDate, getLocalizedMessage("Savings.dateOfTrxn"));
        if (dateError != null && !dateError.isEmpty()) {
            errors.add(dateError);
        }
        if (this.getReceiptDate() != null && !this.getReceiptDate().equals("")) {
            dateError = validateDate(getReceiptDate(), getLocalizedMessage("Savings.receiptDate"));
            if (dateError != null && !dateError.isEmpty()) {
                errors.add(dateError);
            }
        }
        if (StringUtils.isBlank(getCustomerId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.ClientName")));
        }
    }
    if (null != errors && !errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : Locale(java.util.Locale) ActionMessage(org.apache.struts.action.ActionMessage) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) ActionErrors(org.apache.struts.action.ActionErrors)

Example 8 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class LoanAccountActionForm method validateTotalAmount.

protected void validateTotalAmount(ActionErrors errors, Locale locale, MifosCurrency currency, PaymentDataHtmlBean bean) {
    String installmentNo = bean.getInstallment().getInstallmentNumberAsString();
    DoubleConversionResult conversionResult = validateAmount(bean.getAmount(), currency, LoanConstants.LOAN_AMOUNT_KEY, errors, " " + installmentNo);
    if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
        addError(errors, LoanConstants.LOAN_AMOUNT_KEY, LoanConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(LoanConstants.LOAN_AMOUNT_KEY), installmentNo);
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 9 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class AccountApplyPaymentActionForm method validateAmount.

protected void validateAmount(ActionErrors errors) {
    MifosCurrency currency = null;
    if (getCurrencyId() != null && AccountingRules.isMultiCurrencyEnabled()) {
        currency = AccountingRules.getCurrencyByCurrencyId(getCurrencyId());
    }
    DoubleConversionResult conversionResult = validateAmount(getAmount(), currency, AccountConstants.ACCOUNT_AMOUNT, errors, "");
    if (amountCannotBeZero() && conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
        addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 10 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class ApplyAdjustmentActionForm method validateAmount.

protected void validateAmount(ActionErrors errors) {
    MifosCurrency currency = null;
    if (getCurrencyId() != null && AccountingRules.isMultiCurrencyEnabled()) {
        currency = AccountingRules.getCurrencyByCurrencyId(getCurrencyId());
    }
    DoubleConversionResult conversionResult = validateAmount(getAmount(), currency, AccountConstants.ACCOUNT_AMOUNT, errors, "");
    if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
        addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Aggregations

DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)43 ConversionError (org.mifos.framework.util.helpers.ConversionError)20 Locale (java.util.Locale)9 ArrayList (java.util.ArrayList)7 ActionErrors (org.apache.struts.action.ActionErrors)7 ActionMessage (org.apache.struts.action.ActionMessage)7 Test (org.junit.Test)7 ResourceBundle (java.util.ResourceBundle)6 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)5 MifosCurrency (org.mifos.application.master.business.MifosCurrency)4 LocalizationConverter (org.mifos.framework.util.LocalizationConverter)4 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 List (java.util.List)1 Map (java.util.Map)1 FeeDto (org.mifos.accounts.fees.business.FeeDto)1 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)1 Money (org.mifos.framework.util.helpers.Money)1