Search in sources :

Example 6 with CurrencyMismatchException

use of org.mifos.core.CurrencyMismatchException in project head by mifos.

the class CustomerPersistence method getCurrencyForTotalAmountForGroup.

private MifosCurrency getCurrencyForTotalAmountForGroup(final Integer groupId, final AccountState accountState) throws PersistenceException {
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("customerId", groupId);
    params.put("accountState", accountState.getValue());
    List queryResult = executeNamedQuery(NamedQueryConstants.GET_LOAN_SUMMARY_CURRENCIES_FOR_GROUP, params);
    if (queryResult.size() > 1) {
        throw new CurrencyMismatchException(ExceptionConstants.ILLEGALMONEYOPERATION);
    }
    if (queryResult.size() == 0) {
        // if we found no results, then return the default currency
        return Money.getDefaultCurrency();
    }
    Short currencyId = (Short) queryResult.get(0);
    return AccountingRules.getCurrencyByCurrencyId(currencyId);
}
Also used : CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with CurrencyMismatchException

use of org.mifos.core.CurrencyMismatchException in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForAllClientsOfGroupForMultipleCurrencies.

/*
     * When trying to sum amounts across loans with different currencies, we should get an exception
     */
@Test
public void testGetTotalAmountForAllClientsOfGroupForMultipleCurrencies() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES, TestUtils.EURO.getCurrencyCode());
    AccountBO clientAccount1;
    AccountBO clientAccount2;
    try {
        MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
        center = createCenter("new_center");
        group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
        client = TestObjectFactory.createClient("client1", CustomerStatus.CLIENT_ACTIVE, group);
        clientAccount1 = getLoanAccount(client, meeting, "fdbdhgsgh", "54hg", TestUtils.RUPEE);
        clientAccount2 = getLoanAccount(client, meeting, "fasdfdsfasdf", "1qwe", TestUtils.EURO);
        try {
            customerPersistence.getTotalAmountForAllClientsOfGroup(group.getOffice().getOfficeId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, group.getSearchId() + ".%");
            Assert.fail("didn't get the expected CurrencyMismatchException");
        } catch (CurrencyMismatchException e) {
            // if we got here then we got the exception we were expecting
            Assert.assertNotNull(e);
        } catch (Exception e) {
            Assert.fail("didn't get the expected CurrencyMismatchException");
        }
    } finally {
        configMgr.clearProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 8 with CurrencyMismatchException

use of org.mifos.core.CurrencyMismatchException in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForGroupForMultipleCurrencies.

/*
     * When trying to sum amounts across loans with different currencies, we should get an exception
     */
@Test
public void testGetTotalAmountForGroupForMultipleCurrencies() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES, TestUtils.EURO.getCurrencyCode());
    GroupBO group1;
    AccountBO account1;
    AccountBO account2;
    try {
        CustomerPersistence customerPersistence = new CustomerPersistence();
        meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
        center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
        group1 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center);
        account1 = getLoanAccount(group1, meeting, "adsfdsfsd", "3saf", TestUtils.RUPEE);
        account2 = getLoanAccount(group1, meeting, "adspp", "kkaf", TestUtils.EURO);
        try {
            customerPersistence.getTotalAmountForGroup(group1.getCustomerId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
            Assert.fail("didn't get the expected CurrencyMismatchException");
        } catch (CurrencyMismatchException e) {
            // if we got here then we got the exception we were expecting
            Assert.assertNotNull(e);
        } catch (Exception e) {
            Assert.fail("didn't get the expected CurrencyMismatchException");
        }
    } finally {
        configMgr.clearProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) GroupBO(org.mifos.customers.group.business.GroupBO) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Aggregations

CurrencyMismatchException (org.mifos.core.CurrencyMismatchException)8 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Money (org.mifos.framework.util.helpers.Money)3 BigInteger (java.math.BigInteger)2 Test (org.junit.Test)2 AccountBO (org.mifos.accounts.business.AccountBO)2 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)2 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)2 LoanCycleCounter (org.mifos.dto.screen.LoanCycleCounter)2 ApplicationException (org.mifos.framework.exceptions.ApplicationException)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 SystemException (org.mifos.framework.exceptions.SystemException)2 BigDecimal (java.math.BigDecimal)1 MifosCurrency (org.mifos.application.master.business.MifosCurrency)1 MeetingBO (org.mifos.application.meeting.business.MeetingBO)1 GroupBO (org.mifos.customers.group.business.GroupBO)1 CenterPerformanceHistoryDto (org.mifos.dto.domain.CenterPerformanceHistoryDto)1 ClientPerformanceHistoryDto (org.mifos.dto.screen.ClientPerformanceHistoryDto)1