Search in sources :

Example 1 with LocalizationConverter

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

the class LoanAccountActionForm method validateSumOfTheAmountsSpecified.

void validateSumOfTheAmountsSpecified(ActionErrors errors) {
    List<String> ids_clients_selected = getClients();
    double totalAmount = new Double(0);
    boolean foundInvalidAmount = false;
    for (LoanAccountDetailsDto loanDetail : getClientDetails()) {
        if (!foundInvalidAmount) {
            if (ids_clients_selected.contains(loanDetail.getClientId())) {
                if (isAmountZeroOrNull(loanDetail.getLoanAmount())) {
                    addError(errors, LoanExceptionConstants.CUSTOMER_LOAN_AMOUNT_FIELD);
                    foundInvalidAmount = true;
                } else {
                    totalAmount = totalAmount + new LocalizationConverter().getDoubleValueForCurrentLocale(loanDetail.getLoanAmount());
                }
            }
        }
    }
    if (!foundInvalidAmount && (StringUtils.isBlank(Double.valueOf(totalAmount).toString()) || !amountRange.isInRange(totalAmount))) {
        addError(errors, LoanConstants.LOANAMOUNT, LoanExceptionConstants.SUM_OF_INDIVIDUAL_AMOUNTS_IS_NOT_IN_THE_RANGE_OF_ALLOWED_AMOUNTS, getStringValue(amountRange.getMinLoanAmount()), getStringValue(amountRange.getMaxLoanAmount()));
    }
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto)

Example 2 with LocalizationConverter

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

the class CollectionSheetEntryDto method setCustomerAccountAmountEntered.

public void setCustomerAccountAmountEntered(final String customerAccountAmountEntered) {
    customerAccountDetails.setCustomerAccountAmountEntered(customerAccountAmountEntered);
    try {
        new LocalizationConverter().getDoubleValueForCurrentLocale(customerAccountAmountEntered);
        customerAccountDetails.setValidCustomerAccountAmountEntered(true);
    } catch (NumberFormatException nfe) {
        customerAccountDetails.setValidCustomerAccountAmountEntered(false);
    }
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter)

Example 3 with LocalizationConverter

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

the class DateUtils method convertToMFIFormat.

public static String convertToMFIFormat(String date, String format) {
    String MFIString;
    String MFIfmt = getMFIFormat();
    String day = "";
    String month = "";
    String year = "";
    String token;
    String separator = new LocalizationConverter().getDateSeparatorForCurrentLocale();
    MFIfmt = convertToDateTagFormat(MFIfmt);
    StringTokenizer stfmt = new StringTokenizer(format, separator);
    StringTokenizer stdt = new StringTokenizer(date, separator);
    while (stfmt.hasMoreTokens() && stdt.hasMoreTokens()) {
        token = stfmt.nextToken();
        if (token.equalsIgnoreCase("D")) {
            day = stdt.nextToken();
        } else if (token.equalsIgnoreCase("M")) {
            month = stdt.nextToken();
        } else {
            year = stdt.nextToken();
        }
    }
    MFIString = createDateString(day, month, year, MFIfmt);
    return MFIString;
}
Also used : StringTokenizer(java.util.StringTokenizer) LocalizationConverter(org.mifos.framework.util.LocalizationConverter)

Example 4 with LocalizationConverter

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

the class MifosDoubleConverterTest method xtestConvert_is_IS.

/**
     * Currently broken -- incomplete support for multiple locales for numeric input.
     */
@Ignore
public void xtestConvert_is_IS() {
    LocalizationConverter converter = new LocalizationConverter();
    converter.setCurrentLocale(new Locale("IS", "is"));
    Assert.assertEquals(new Double(2.0), mifosDoubleConverter.convert(String.class, "2,0"));
}
Also used : Locale(java.util.Locale) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) Ignore(org.junit.Ignore)

Example 5 with LocalizationConverter

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

the class FiscalCalendarRulesTest method testIsWorkingDay.

@Test
public void testIsWorkingDay() {
    String configWorkingDays = "MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY";
    setNewWorkingDays(configWorkingDays);
    // get the supported ids for GMT-08:00 (Pacific Standard Time)
    String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    // if no ids were returned, something is wrong. get out.
    // Otherwise get an id for Pacific Standard Time
    String pstId = ids[0];
    // create a Pacific Standard Time time zone
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, pstId);
    // set up rules for daylight savings time
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    // create a GregorianCalendar with the Pacific Daylight time zone
    // and the current date and time
    Calendar calendar = new GregorianCalendar(pdt);
    try {
        Locale savedLocale = Localization.getInstance().getConfiguredLocale();
        new LocalizationConverter().setCurrentLocale(Locale.US);
        SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
        // Keith: DateFormat must be set to the same timezone as the
        // calendar
        // Otherwise dates don't roll over at the same exact time, causing
        // this and several other unit tests to fail
        df.setTimeZone(TimeZone.getTimeZone(pstId));
        df.applyPattern("yyyy/MM/dd");
        Date thursday = df.parse("2007/10/11");
        calendar.setTime(thursday);
        String out = thursday.toString();
        out.contains("A");
        new LocalizationConverter().setCurrentLocale(savedLocale);
    } catch (Exception e) {
    }
    Assert.assertTrue(new FiscalCalendarRules().isWorkingDay(calendar));
    // Friday
    calendar.add(Calendar.DAY_OF_WEEK, 1);
    Assert.assertTrue(new FiscalCalendarRules().isWorkingDay(calendar));
    // Sat
    calendar.add(Calendar.DAY_OF_WEEK, 1);
    Assert.assertTrue(!new FiscalCalendarRules().isWorkingDay(calendar));
    // Sunday
    calendar.add(Calendar.DAY_OF_WEEK, 1);
    Assert.assertTrue(!new FiscalCalendarRules().isWorkingDay(calendar));
}
Also used : Locale(java.util.Locale) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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