Search in sources :

Example 11 with DoubleConversionResult

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

the class LocalizationConverter method parseDoubleForInstallmentTotalAmount.

public DoubleConversionResult parseDoubleForInstallmentTotalAmount(String totalAmountStr) {
    DoubleConversionResult result = new DoubleConversionResult();
    if (totalAmountStr == null) {
        List<ConversionError> errors = new ArrayList<ConversionError>();
        errors.add(ConversionError.CONVERSION_ERROR);
        result.setErrors(errors);
        return result;
    }
    List<ConversionError> errors = checkDigits(digitsBeforeDecimalForMoney, digitsAfterDecimalForMoney, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_MONEY, totalAmountStr, true);
    result.setErrors(errors);
    if (errors.size() > 0) {
        return result;
    }
    try {
        result.setDoubleValue(getDoubleValueForCurrentLocale(totalAmountStr));
    } catch (Exception ex) {
        // after all the checkings this is not likely to happen, but just in
        // case
        result.getErrors().add(ConversionError.CONVERSION_ERROR);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 12 with DoubleConversionResult

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

the class LocalizationConverter method parseDoubleForMoney.

public DoubleConversionResult parseDoubleForMoney(String doubleStr) {
    DoubleConversionResult result = new DoubleConversionResult();
    if (doubleStr == null) {
        List<ConversionError> errors = new ArrayList<ConversionError>();
        errors.add(ConversionError.CONVERSION_ERROR);
        result.setErrors(errors);
        return result;
    }
    List<ConversionError> errors = checkDigits(digitsBeforeDecimalForMoney, digitsAfterDecimalForMoney, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_MONEY, doubleStr, false);
    result.setErrors(errors);
    if (errors.size() > 0) {
        return result;
    }
    try {
        result.setDoubleValue(getDoubleValueForCurrentLocale(doubleStr));
    } catch (Exception ex) {
        // after all the checkings this is not likely to happen, but just in
        // case
        result.getErrors().add(ConversionError.CONVERSION_ERROR);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 13 with DoubleConversionResult

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

the class LocalizationConverter method parseDoubleForInterest.

public DoubleConversionResult parseDoubleForInterest(String doubleStr) {
    DoubleConversionResult result = new DoubleConversionResult();
    if (doubleStr == null) {
        List<ConversionError> errors = new ArrayList<ConversionError>();
        errors.add(ConversionError.CONVERSION_ERROR);
        result.setErrors(errors);
        return result;
    }
    List<ConversionError> errors = checkDigits(digitsBeforeDecimalForInterest, digitsAfterDecimalForInterest, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_INTEREST, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_INTEREST, doubleStr, false);
    result.setErrors(errors);
    if (errors.size() > 0) {
        return result;
    }
    return validateTheValueIsWithinTheRange(ConversionError.INTEREST_OUT_OF_RANGE, AccountingRules.getMinInterest(), AccountingRules.getMaxInterest(), result, errors, doubleStr);
}
Also used : ArrayList(java.util.ArrayList) ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 14 with DoubleConversionResult

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

the class LocalizationConverter method parseDoubleForCashFlowValidations.

public DoubleConversionResult parseDoubleForCashFlowValidations(String doubleStr, ConversionError cashFlowValidationOutOfRange, Double minimumLimit, Double maximumLimit) {
    DoubleConversionResult result = new DoubleConversionResult();
    if (doubleStr == null) {
        List<ConversionError> errors = new ArrayList<ConversionError>();
        errors.add(ConversionError.CONVERSION_ERROR);
        result.setErrors(errors);
        return result;
    }
    List<ConversionError> errors = checkDigits(digitsBeforeDecimalForCashFlowValidations, digitsAfterDecimalForCashFlowValidations, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_CASHFLOW_VALIDATION, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_CASHFLOW_VALIDATION, doubleStr, false);
    result.setErrors(errors);
    if (errors.size() > 0) {
        return result;
    }
    return validateTheValueIsWithinTheRange(cashFlowValidationOutOfRange, minimumLimit, maximumLimit, result, errors, doubleStr);
}
Also used : ArrayList(java.util.ArrayList) ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 15 with DoubleConversionResult

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

the class LoanAccountActionForm method validateAdditionalFee.

protected void validateAdditionalFee(ActionErrors errors, Locale locale, MifosCurrency currency, HttpServletRequest request) throws PageExpiredException {
    Map<String, Boolean> addedFees = new HashMap<String, Boolean>();
    List<FeeDto> additionalFeeList = (List<FeeDto>) SessionUtils.getAttribute(LoanConstants.ADDITIONAL_FEES_LIST, request);
    for (FeeDto additionalFee : additionalFees) {
        if (additionalFee.getAmount() != null && !additionalFee.getAmount().equals("")) {
            FeeDto additionalFeeDetails = getAdditionalFeeType(additionalFeeList, additionalFee.getFeeId());
            if (additionalFeeDetails.getFeeType().equals(RateAmountFlag.AMOUNT)) {
                DoubleConversionResult conversionResult = validateAmount(additionalFee.getAmount(), currency, LoanConstants.LOAN_ADDITIONAL_FEE_KEY, errors, "");
                if (validPositiveValue(errors, locale, conversionResult)) {
                    validateFeeTypeIfVariableInstallmentLoanType(errors, additionalFeeDetails);
                }
            } else {
                DoubleConversionResult conversionResult = validateInterest(additionalFee.getAmount(), LoanConstants.LOAN_ADDITIONAL_FEE_KEY, errors);
                if (validPositiveValue(errors, locale, conversionResult)) {
                    validateFeeTypeIfVariableInstallmentLoanType(errors, additionalFeeDetails);
                }
            }
            if (!additionalFeeDetails.isPeriodic() && addedFees.get(additionalFeeDetails.getFeeId()) != null) {
                addError(errors, "AdditionalFee", ProductDefinitionConstants.MULTIPLE_ONE_TIME_FEES_NOT_ALLOWED);
            }
            addedFees.put(additionalFeeDetails.getFeeId(), true);
        }
    }
}
Also used : HashMap(java.util.HashMap) FeeDto(org.mifos.accounts.fees.business.FeeDto) List(java.util.List) ArrayList(java.util.ArrayList) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

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