Search in sources :

Example 16 with LocalizationConverter

use of org.mifos.framework.util.LocalizationConverter in project head by mifos.

the class DateTag method prepareOutputString.

String prepareOutputString(String format, String dateName, String ddValue, String mmValue, String yyValue, String separator, String userfrmt) {
    StringBuilder dateFunction = new StringBuilder();
    dateFunction.append("onBlur,");
    dateFunction.append("makeDateString(");
    String dateSeparator = new LocalizationConverter().getDateSeparatorForCurrentLocale();
    StringTokenizer tokenizer = new StringTokenizer(format, dateSeparator);
    while (tokenizer.hasMoreTokens()) {
        String ch = tokenizer.nextToken();
        if (ch.equalsIgnoreCase("D")) {
            dateFunction.append("'" + dateName + "DD',");
        } else if (ch.equalsIgnoreCase("M")) {
            dateFunction.append("'" + dateName + "MM',");
        } else {
            dateFunction.append("'" + dateName + "YY',");
        }
    }
    dateFunction.append("'" + dateName + "'");
    dateFunction.append(",'" + separator + "')");
    String date = "";
    if (ddValue != null && !ddValue.equals("") && mmValue != null && !mmValue.equals("") && yyValue != null && !yyValue.equals("")) {
        date = DateUtils.createDateString(ddValue, mmValue, yyValue, format);
    }
    XmlBuilder htmlBuilder = makeUserFields(dateName, ddValue, mmValue, yyValue, dateFunction.toString(), format, dateSeparator);
    htmlBuilder.singleTag("input", "type", "hidden", "id", dateName, "name", dateName, "value", date);
    htmlBuilder.singleTag("input", "type", "hidden", "id", dateName + "Format", "name", dateName + "Format", "value", format);
    htmlBuilder.singleTag("input", "type", "hidden", "id", "datePattern", "name", "datePattern", "value", userfrmt);
    return htmlBuilder.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) LocalizationConverter(org.mifos.framework.util.LocalizationConverter)

Example 17 with LocalizationConverter

use of org.mifos.framework.util.LocalizationConverter in project head by mifos.

the class InstallmentFormatValidatorImpl method setTotalAmountValue.

private void setTotalAmountValue(RepaymentScheduleInstallment installment, String identifier, List<ErrorEntry> errorEntries) {
    LocalizationConverter localizationConverter = new LocalizationConverter(installment.getCurrency());
    DoubleConversionResult conversionResult = localizationConverter.parseDoubleForInstallmentTotalAmount(installment.getTotal());
    List<ConversionError> conversionErrors = conversionResult.getErrors();
    if (conversionErrors.isEmpty()) {
        installment.setTotalValue(conversionResult.getDoubleValue());
    } else {
        processConversionErrors(installment, identifier, conversionErrors, errorEntries);
    }
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter) ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 18 with LocalizationConverter

use of org.mifos.framework.util.LocalizationConverter in project head by mifos.

the class LoanBusinessService method populaleApplicableCharge.

private void populaleApplicableCharge(List<ApplicableCharge> applicableChargeList, List<PenaltyBO> penaltyList, UserContext userContext) {
    for (PenaltyBO penalty : penaltyList) {
        ApplicableCharge applicableCharge = new ApplicableCharge();
        applicableCharge.setFeeId(penalty.getPenaltyId().toString());
        applicableCharge.setFeeName(penalty.getPenaltyName());
        applicableCharge.setIsPenaltyType(true);
        if (penalty instanceof RatePenaltyBO) {
            applicableCharge.setAmountOrRate(new LocalizationConverter().getDoubleStringForInterest(((RatePenaltyBO) penalty).getRate()));
            applicableCharge.setFormula(((RatePenaltyBO) penalty).getFormula().getFormulaStringThatHasName());
            applicableCharge.setIsRateType(true);
        } else {
            applicableCharge.setAmountOrRate(((AmountPenaltyBO) penalty).getAmount().toString());
            applicableCharge.setIsRateType(false);
        }
        if (!penalty.isOneTime()) {
            applicableCharge.setPeriodicity("true");
            applicableCharge.setFormula(penalty.getPenaltyFrequency().getName());
        }
        applicableChargeList.add(applicableCharge);
    }
}
Also used : RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO)

Example 19 with LocalizationConverter

use of org.mifos.framework.util.LocalizationConverter in project head by mifos.

the class BaseActionFormTest method xtestParseDoubleForMoney_is_IS.

/**
     * Currently broken -- incomplete support for multiple locales for numeric
     * input.
     */
@Ignore
@Test
public void xtestParseDoubleForMoney_is_IS() {
    LocalizationConverter converter = new LocalizationConverter();
    String doubleStr = "222.12345";
    Double value = 222.12345;
    DoubleConversionResult result = baseActionForm.parseDoubleForInterest("222,12345");
    result = baseActionForm.parseDoubleForMoney("222,4");
    Assert.assertEquals(value, result.getDoubleValue());
    doubleStr = "222.4";
    result = baseActionForm.parseDoubleForMoney(doubleStr);
    Assert.assertEquals(ConversionError.NOT_ALL_NUMBER, result.getErrors().get(0));
    doubleStr = "222a4";
    result = baseActionForm.parseDoubleForMoney(doubleStr);
    Assert.assertEquals(ConversionError.NOT_ALL_NUMBER, result.getErrors().get(0));
    doubleStr = "222,40000";
    result = baseActionForm.parseDoubleForMoney(doubleStr);
    Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_MONEY, result.getErrors().get(0));
    doubleStr = "222222222222,4";
    result = baseActionForm.parseDoubleForMoney(doubleStr);
    Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY, result.getErrors().get(0));
// converter.setCurrentLocale(locale);
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LocalizationConverter (org.mifos.framework.util.LocalizationConverter)19 Test (org.junit.Test)6 Ignore (org.junit.Ignore)5 Locale (java.util.Locale)4 FeeBO (org.mifos.accounts.fees.business.FeeBO)4 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)4 ArrayList (java.util.ArrayList)3 AccountBO (org.mifos.accounts.business.AccountBO)3 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)3 StringTokenizer (java.util.StringTokenizer)2 ApplicableAccountFeeDto (org.mifos.dto.domain.ApplicableAccountFeeDto)2 ApplicableCharge (org.mifos.dto.domain.ApplicableCharge)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 SimpleTimeZone (java.util.SimpleTimeZone)1 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)1 RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)1 LoanAccountsProductDto (org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto)1