Search in sources :

Example 1 with CurrencyMismatchException

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

the class GroupServiceFacadeWebTier method assembleGroupPerformanceHistoryDto.

private GroupPerformanceHistoryDto assembleGroupPerformanceHistoryDto(GroupPerformanceHistoryEntity groupPerformanceHistory, String searchId, Short branchId, Integer groupId) {
    Integer activeClientCount = this.customerDao.getActiveAndOnHoldClientCountForGroup(searchId, branchId);
    Money lastGroupLoanAmountMoney = groupPerformanceHistory.getLastGroupLoanAmount();
    String lastGroupLoanAmount = "";
    if (lastGroupLoanAmountMoney != null) {
        lastGroupLoanAmount = lastGroupLoanAmountMoney.toString();
    }
    String avgLoanAmountForMember = this.customerDao.getAvgLoanAmountForMemberInGoodOrBadStanding(searchId, branchId);
    String totalLoanAmountForGroup = this.customerDao.getTotalLoanAmountForGroup(searchId, branchId);
    String portfolioAtRisk;
    String totalSavingsAmount;
    try {
        if (groupPerformanceHistory.getPortfolioAtRisk() == null) {
            portfolioAtRisk = "0";
        } else {
            portfolioAtRisk = groupPerformanceHistory.getPortfolioAtRisk().toString();
        }
    } catch (CurrencyMismatchException e) {
        portfolioAtRisk = localizedMessageLookup("errors.multipleCurrencies");
    }
    totalSavingsAmount = this.customerDao.getTotalSavingsAmountForGroupandClientsOfGroup(searchId, branchId);
    List<LoanCycleCounter> loanCycleCounters = this.customerDao.fetchLoanCycleCounter(groupId, CustomerLevel.GROUP.getValue());
    return new GroupPerformanceHistoryDto(activeClientCount.toString(), lastGroupLoanAmount, avgLoanAmountForMember, totalLoanAmountForGroup, portfolioAtRisk, totalSavingsAmount, loanCycleCounters);
}
Also used : Money(org.mifos.framework.util.helpers.Money) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) GroupPerformanceHistoryDto(org.mifos.dto.screen.GroupPerformanceHistoryDto) LoanCycleCounter(org.mifos.dto.screen.LoanCycleCounter)

Example 2 with CurrencyMismatchException

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

the class CustomerDaoHibernate method getCenterPerformanceHistory.

/**
     * FIXME: THIS METHOD DOES NOT WORK. Specifically, the portfolioAtRisk calculation. Please see issue 2204.
     */
@Override
public CenterPerformanceHistoryDto getCenterPerformanceHistory(String searchId, Short officeId) {
    Integer activeAndOnHoldGroupCount;
    Integer activeAndOnHoldClientCount;
    String totalSavings;
    String totalLoan;
    activeAndOnHoldGroupCount = getActiveAndOnHoldChildrenCount(searchId, officeId, CustomerLevel.GROUP);
    activeAndOnHoldClientCount = getActiveAndOnHoldChildrenCount(searchId, officeId, CustomerLevel.CLIENT);
    try {
        totalSavings = retrieveTotalSavings(searchId, officeId).toString();
    } catch (CurrencyMismatchException e) {
        totalSavings = localizedMessageLookup("errors.multipleCurrencies");
    }
    try {
        totalLoan = retrieveTotalLoan(searchId, officeId).toString();
    } catch (CurrencyMismatchException e) {
        totalLoan = localizedMessageLookup("errors.multipleCurrencies");
    }
    String portfolioAtRisk = "0.2";
    return new CenterPerformanceHistoryDto(activeAndOnHoldGroupCount, activeAndOnHoldClientCount, totalLoan, totalSavings, portfolioAtRisk);
}
Also used : BigInteger(java.math.BigInteger) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) CenterPerformanceHistoryDto(org.mifos.dto.domain.CenterPerformanceHistoryDto)

Example 3 with CurrencyMismatchException

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

the class ClientServiceFacadeWebTier method assembleClientPerformanceHistoryDto.

private ClientPerformanceHistoryDto assembleClientPerformanceHistoryDto(ClientPerformanceHistoryEntity clientPerformanceHistory, Integer clientId) {
    Integer loanCycleNumber = clientPerformanceHistory.getLoanCycleNumber();
    Money lastLoanAmount = clientPerformanceHistory.getLastLoanAmount();
    Integer noOfActiveLoans = clientPerformanceHistory.getNoOfActiveLoans();
    String delinquentPortfolioAmountString;
    try {
        Money delinquentPortfolioAmount = clientPerformanceHistory.getDelinquentPortfolioAmount();
        delinquentPortfolioAmountString = delinquentPortfolioAmount.toString();
    } catch (CurrencyMismatchException e) {
        delinquentPortfolioAmountString = localizedMessageLookup("errors.multipleCurrencies");
    }
    // TODO currency mismatch check
    Money totalSavingsAmount = clientPerformanceHistory.getTotalSavingsAmount();
    Integer meetingsAttended = this.customerDao.numberOfMeetings(true, clientId).getMeetingsAttended();
    Integer meetingsMissed = customerDao.numberOfMeetings(false, clientId).getMeetingsMissed();
    List<LoanCycleCounter> loanCycleCounters = this.customerDao.fetchLoanCycleCounter(clientId, CustomerLevel.CLIENT.getValue());
    return new ClientPerformanceHistoryDto(loanCycleNumber, lastLoanAmount.toString(), noOfActiveLoans, delinquentPortfolioAmountString, totalSavingsAmount.toString(), meetingsAttended, meetingsMissed, loanCycleCounters);
}
Also used : Money(org.mifos.framework.util.helpers.Money) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ClientPerformanceHistoryDto(org.mifos.dto.screen.ClientPerformanceHistoryDto) LoanCycleCounter(org.mifos.dto.screen.LoanCycleCounter)

Example 4 with CurrencyMismatchException

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

the class CustomerDaoHibernate method retrieveTotalForQuery.

@SuppressWarnings("unchecked")
private Money retrieveTotalForQuery(String query, final String searchId, final Short officeId) {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_STRING1", searchId);
    queryParameters.put("SEARCH_STRING2", searchId + ".%");
    queryParameters.put("OFFICE_ID", officeId);
    List queryResult = this.genericDao.executeNamedQuery(query, queryParameters);
    if (queryResult.size() > 1) {
        throw new CurrencyMismatchException(ExceptionConstants.ILLEGALMONEYOPERATION);
    }
    if (queryResult.size() == 0) {
        // if we found no results, then return zero using the default currency
        return new Money(Money.getDefaultCurrency(), "0.0");
    }
    Integer currencyId = (Integer) ((Object[]) queryResult.get(0))[0];
    MifosCurrency currency = AccountingRules.getCurrencyByCurrencyId(currencyId.shortValue());
    BigDecimal total = (BigDecimal) ((Object[]) queryResult.get(0))[1];
    return new Money(currency, total);
}
Also used : BigInteger(java.math.BigInteger) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) Money(org.mifos.framework.util.helpers.Money) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) MifosCurrency(org.mifos.application.master.business.MifosCurrency) BigDecimal(java.math.BigDecimal)

Example 5 with CurrencyMismatchException

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

the class CustomerPersistence method getCurrencyForTotalAmountForAllClientsOfGroup.

private MifosCurrency getCurrencyForTotalAmountForAllClientsOfGroup(final Short officeId, final AccountState accountState, final String searchIdString) throws PersistenceException {
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("officeId", officeId);
    params.put("accountState", accountState.getValue());
    params.put("searchId", searchIdString);
    List queryResult = executeNamedQuery(NamedQueryConstants.GET_LOAN_SUMMARY_CURRENCIES_FOR_ALL_CLIENTS_OF_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)

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