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();
}
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;
}
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();
}
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();
}
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));
}
Aggregations