Search in sources :

Example 41 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class CustomerDaoHibernate method getTotalOutstandingLoanAmountForGroupAndClientsOfGroups.

@SuppressWarnings("unchecked")
@Override
public String getTotalOutstandingLoanAmountForGroupAndClientsOfGroups(String groupSearchId, Short groupOfficeId) {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_STRING", groupSearchId);
    queryParameters.put("SEARCH_STRING2", groupSearchId + ".%");
    queryParameters.put("OFFICE_ID", groupOfficeId);
    List<Object[]> queryResult = (List<Object[]>) genericDao.executeNamedQuery("Customer.getTotalOutstandingLoanAmountForGroupAndClientsOfGroups", queryParameters);
    if (queryResult.size() > 1) {
        return localizedMessageLookup("errors.multipleCurrencies");
    }
    if (queryResult.size() == 0) {
        return new Money(Money.getDefaultCurrency()).toString();
    }
    // TODO - use default currency or retrieved currency?
    Short currency = (Short) queryResult.get(0)[0];
    MifosCurrency mifosCurrency = Money.getDefaultCurrency();
    Money totalOutstandingLoanAmount = new Money(mifosCurrency, (BigDecimal) queryResult.get(0)[1]);
    return totalOutstandingLoanAmount.toString();
}
Also used : 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)

Example 42 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class CustomerPersistence method getTotalAmountForAllClientsOfGroup.

public Money getTotalAmountForAllClientsOfGroup(final Short officeId, final AccountState accountState, final String searchIdString) throws PersistenceException {
    MifosCurrency currency = getCurrencyForTotalAmountForAllClientsOfGroup(officeId, accountState, searchIdString);
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("officeId", officeId);
    params.put("accountState", accountState.getValue());
    params.put("searchId", searchIdString);
    BigDecimal amount = getCalculateValueFromQueryResult(executeNamedQuery(NamedQueryConstants.GET_TOTAL_AMOUNT_FOR_ALL_CLIENTS_OF_GROUP, params));
    Money totalAmount = new Money(currency, amount);
    return totalAmount;
}
Also used : Money(org.mifos.framework.util.helpers.Money) HashMap(java.util.HashMap) MifosCurrency(org.mifos.application.master.business.MifosCurrency) BigDecimal(java.math.BigDecimal)

Example 43 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class CustomerDaoHibernate method getTotalLoanAmountForGroup.

@SuppressWarnings("unchecked")
@Override
public String getTotalLoanAmountForGroup(String groupSearchId, Short groupOfficeId) {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_STRING", groupSearchId);
    queryParameters.put("SEARCH_STRING2", groupSearchId + ".%");
    queryParameters.put("OFFICE_ID", groupOfficeId);
    List<Object[]> queryResult = (List<Object[]>) genericDao.executeNamedQuery("Customer.getTotalLoanAmountForGroup", queryParameters);
    if (queryResult.size() > 1) {
        return localizedMessageLookup("errors.multipleCurrencies");
    }
    if (queryResult.size() == 0) {
        return new Money(Money.getDefaultCurrency()).toString();
    }
    // TODO - use default currency or retrieved currency?
    Short currency = (Short) queryResult.get(0)[0];
    MifosCurrency mifosCurrency = Money.getDefaultCurrency();
    Money totalLoanAmount = new Money(mifosCurrency, (BigDecimal) queryResult.get(0)[1]);
    return totalLoanAmount.toString();
}
Also used : 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)

Example 44 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class CustomerDaoHibernate method getAvgLoanAmountForMemberInGoodOrBadStanding.

@SuppressWarnings("unchecked")
@Override
public String getAvgLoanAmountForMemberInGoodOrBadStanding(String groupSearchId, Short groupOfficeId) {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_STRING", groupSearchId + ".%");
    queryParameters.put("OFFICE_ID", groupOfficeId);
    List<Object[]> queryResult = (List<Object[]>) genericDao.executeNamedQuery("Customer.getAvgLoanAmountForMemberInGoodOrBadStanding", queryParameters);
    if (queryResult.size() > 1) {
        return localizedMessageLookup("errors.multipleCurrencies");
    }
    if (queryResult.size() == 0) {
        return new Money(Money.getDefaultCurrency()).toString();
    }
    // TODO - use default currency or retrieved currency?
    Short currency = (Short) queryResult.get(0)[0];
    MifosCurrency mifosCurrency = Money.getDefaultCurrency();
    Integer numberOfLoansInGoodOrBadStanding = (Integer) queryResult.get(0)[1];
    Money totalLoanAmountInGoodOrBadStanding = new Money(mifosCurrency, (BigDecimal) queryResult.get(0)[2]);
    Money avgLoanAmountInGoodOrBadStanding = new Money(mifosCurrency);
    if (numberOfLoansInGoodOrBadStanding.intValue() > 0) {
        avgLoanAmountInGoodOrBadStanding = totalLoanAmountInGoodOrBadStanding.divide(numberOfLoansInGoodOrBadStanding);
    }
    return avgLoanAmountInGoodOrBadStanding.toString();
}
Also used : BigInteger(java.math.BigInteger) 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)

Example 45 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class InterestPostingAccountingEntryTest method testBuildAccountEntryForAction.

@Test
public void testBuildAccountEntryForAction() throws FinancialException {
    // setup
    DateMidnight savingsTrxnDetailActionDate = new DateMidnight(2009, 9, 9);
    DateMidnight savingsTrxnDetailCreationDate = new DateMidnight(2009, 1, 1);
    MifosCurrency currency = TestUtils.RUPEE;
    // stubbing
    when(savingsTrxnDetail.getAccount()).thenReturn(savingsBO);
    when(savingsTrxnDetail.getInterestAmount()).thenReturn(new Money(currency, interestAmount));
    when(savingsTrxnDetail.getActionDate()).thenReturn(savingsTrxnDetailActionDate.toDate());
    when(savingsTrxnDetail.getTrxnCreatedDate()).thenReturn(new Timestamp(savingsTrxnDetailCreationDate.getMillis()));
    when(savingsTrxnDetail.getPersonnel()).thenReturn(transactionCreator);
    when(savingsBO.getSavingsOffering()).thenReturn(savingsOffering);
    when(savingsOffering.getInterestGLCode()).thenReturn(coaSavingsInterestPayable.getAssociatedGlcode());
    when(savingsOffering.getDepositGLCode()).thenReturn(coaClientsSavings.getAssociatedGlcode());
    SavingsInterestPostingFinancialActivity financialActivity = new SavingsInterestPostingFinancialActivity(savingsTrxnDetail);
    // exercise test
    interestPostingAccountingEntry.buildAccountEntryForAction(financialActivity);
    // verification
    List<FinancialTransactionBO> transactions = financialActivity.getFinanacialTransaction();
    assertThat(transactions.size(), is(2));
    /*
         * Sort by GLCode strings so "22100" (interest payable tran) should be first, followed by "22200" (client
         * savings tran)
         */
    Collections.sort(transactions, new GLCodeComparator());
    Iterator<FinancialTransactionBO> it = transactions.iterator();
    FinancialTransactionBO interestPostingTrans = it.next();
    assertThat(interestPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
    assertThat(interestPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
    assertThat(interestPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
    assertThat(interestPostingTrans.getGlcode().getGlcode(), is(coaSavingsInterestPayable.getGlCode()));
    assertThat(interestPostingTrans.getDebitCreditFlag(), is(FinancialConstants.DEBIT.getValue()));
    assertThat(interestPostingTrans.getPostedBy(), is(transactionCreator));
    FinancialTransactionBO savingsPostingTrans = it.next();
    assertThat(savingsPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
    assertThat(savingsPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
    assertThat(savingsPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
    assertThat(savingsPostingTrans.getGlcode().getGlcode(), is(coaClientsSavings.getGlCode()));
    assertThat(savingsPostingTrans.getDebitCreditFlag(), is(FinancialConstants.CREDIT.getValue()));
    assertThat(savingsPostingTrans.getPostedBy(), is(transactionCreator));
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) DateMidnight(org.joda.time.DateMidnight) SavingsInterestPostingFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity) Timestamp(java.sql.Timestamp) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Aggregations

MifosCurrency (org.mifos.application.master.business.MifosCurrency)54 Money (org.mifos.framework.util.helpers.Money)26 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)12 BigDecimal (java.math.BigDecimal)10 Date (java.util.Date)10 HashMap (java.util.HashMap)10 Before (org.junit.Before)8 List (java.util.List)7 Locale (java.util.Locale)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)5 RepaymentScheduleInstallmentBuilder (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallmentBuilder)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 LocalDate (org.joda.time.LocalDate)3 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)3 BigInteger (java.math.BigInteger)2 Calendar (java.util.Calendar)2