use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class LoanPrdActionForm method validateMinMaxDefInterestRates.
private void validateMinMaxDefInterestRates(ActionErrors errors, Locale locale, HttpServletRequest request) {
DoubleConversionResult minInterestResult = null;
DoubleConversionResult maxInterestResult = null;
DoubleConversionResult defInterestResult = null;
List<ConversionError> errorList = null;
Double maxInterest = null;
Double minInterest = null;
Double defInterest = null;
String label = getLabel(ConfigurationConstants.INTEREST);
String prdrate = getLocalizedMessage("product.prdrate");
String min = getLocalizedMessage("product.min");
String max = getLocalizedMessage("product.max");
String defaultString = getLocalizedMessage("product.default");
if (!StringUtils.isNotBlank(minInterestRate)) {
addError(errors, "minInterestRate", ProductDefinitionConstants.ERRORS_MANDATORY_MIN_INTEREST);
} else {
minInterestResult = parseDoubleForInterest(minInterestRate);
errorList = minInterestResult.getErrors();
if (errorList.size() > 0) {
for (int i = 0; i < errorList.size(); i++) {
addError(errors, ProductDefinitionConstants.ERRORMININTERESTINVALIDFORMAT, ProductDefinitionConstants.ERRORMININTERESTINVALIDFORMAT, getConversionErrorText(errorList.get(i)));
}
} else {
minInterest = minInterestResult.getDoubleValue();
}
}
if (!StringUtils.isNotBlank(maxInterestRate)) {
addError(errors, "maxInterestRate", ProductDefinitionConstants.ERRORS_MANDATORY_MAX_INTEREST);
} else {
maxInterestResult = parseDoubleForInterest(maxInterestRate);
errorList = maxInterestResult.getErrors();
if (errorList.size() > 0) {
for (ConversionError anErrorList : errorList) {
addError(errors, ProductDefinitionConstants.ERRORMAXINTERESTINVALIDFORMAT, ProductDefinitionConstants.ERRORMAXINTERESTINVALIDFORMAT, getConversionErrorText(anErrorList));
}
} else {
maxInterest = maxInterestResult.getDoubleValue();
}
}
if (!StringUtils.isNotBlank(defInterestRate)) {
addError(errors, "defInterestRate", ProductDefinitionConstants.ERRORS_MANDATORY_DEFAULT_INTEREST);
} else {
defInterestResult = parseDoubleForInterest(defInterestRate);
errorList = defInterestResult.getErrors();
if (errorList.size() > 0) {
for (int i = 0; i < errorList.size(); i++) {
addError(errors, ProductDefinitionConstants.ERRORDEFINTERESTINVALIDFORMAT, ProductDefinitionConstants.ERRORDEFINTERESTINVALIDFORMAT, getConversionErrorText(errorList.get(i)));
}
} else {
defInterest = defInterestResult.getDoubleValue();
}
}
if ((minInterest != null) && (maxInterest != null)) {
if (minInterest > maxInterest) {
addError(errors, "MinMaxInterestRate", ProductDefinitionConstants.ERRORSMINMAXINTCONFIG, max, label, prdrate, min);
}
if (defInterest != null) {
if ((defInterest < minInterest) || (defInterest > maxInterest)) {
addError(errors, "DefInterestRate", ProductDefinitionConstants.ERRORSDEFINTCONFIG, defaultString, label, prdrate, min, max);
} else {
minInterestRateValue = minInterest;
maxInterestRateValue = maxInterest;
defInterestRateValue = defInterest;
}
}
}
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class SavingsActionForm method validateAmount.
protected DoubleConversionResult validateAmount(String amountString, String fieldPropertyKey, ActionErrors errors, Locale locale, String propertyfileName) {
DoubleConversionResult conversionResult = parseDoubleForMoney(amountString);
String arg = getLocalizedMessage(fieldPropertyKey);
addConversionResultErrors(fieldPropertyKey, arg, errors, locale, conversionResult);
return conversionResult;
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class LoanAccountActionForm method validateIndividualLoanFieldsForGlim.
private void validateIndividualLoanFieldsForGlim(ActionErrors errors, Locale locale, MifosCurrency currency) {
int errorsBeforeLoanAmountsValidation = errors.size();
for (LoanAccountDetailsDto listDetail : clientDetails) {
if (getClients().contains(listDetail.getClientId())) {
DoubleConversionResult conversionResult = validateAmount(listDetail.getLoanAmount(), currency, LoanConstants.LOAN_AMOUNT_KEY, errors, "");
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));
}
} else {
if (!listDetail.isEmpty()) {
addError(errors, "", LoanExceptionConstants.LOAN_DETAILS_ENTERED_WITHOUT_SELECTING_INDIVIDUAL, "");
break;
}
}
}
int amountValidationErrors = errors.size() - errorsBeforeLoanAmountsValidation;
if (amountValidationErrors == 0) {
validateSumOfTheAmountsSpecified(errors);
}
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class LoanAccountActionForm method validateLoanAmount.
protected void validateLoanAmount(ActionErrors errors, Locale locale, MifosCurrency currency) {
DoubleConversionResult conversionResult = validateAmount(getLoanAmount(), currency, LoanConstants.LOAN_AMOUNT_KEY, errors, "");
Double loanAmountValue = conversionResult.getDoubleValue();
if (conversionResult.getErrors().size() == 0) {
if (loanAmountValue <= 0.0) {
addError(errors, LoanConstants.LOAN_AMOUNT_KEY, LoanConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(LoanConstants.LOAN_AMOUNT_KEY));
} else {
this.loanAmountValue = new Money(currency, loanAmountValue);
}
}
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class BaseActionForm method validateAmount.
protected DoubleConversionResult validateAmount(String amountString, MifosCurrency currency, String fieldPropertyKey, ActionErrors errors, String installmentNo) {
String fieldName = getLocalizedMessage(fieldPropertyKey);
DoubleConversionResult conversionResult = parseDoubleForMoney(amountString, currency);
for (ConversionError error : conversionResult.getErrors()) {
String errorText = error.toLocalizedMessage(currency);
addError(errors, fieldPropertyKey, "errors.generic", fieldName, errorText);
}
return conversionResult;
}
Aggregations