use of org.mifos.application.master.business.MifosCurrency in project head by mifos.
the class LoanBusinessServiceTest method persistOriginalSchedule.
@Test
public void persistOriginalSchedule() throws PersistenceException {
Set<LoanScheduleEntity> installments = new LinkedHashSet<LoanScheduleEntity>();
MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
Money money = new Money(mifosCurrency, "123");
AccountBO accountBO = mock(AccountBO.class);
CustomerBO customerBO = mock(CustomerBO.class);
when(accountBO.getCurrency()).thenReturn(mifosCurrency);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(accountBO, customerBO, new Short("1"), new java.sql.Date(new Date().getTime()), PaymentStatus.UNPAID, money, money);
installments.add(loanScheduleEntity);
when(loanBO.getLoanScheduleEntities()).thenReturn(installments);
loanBusinessService.persistOriginalSchedule(loanBO);
ArrayList<OriginalLoanScheduleEntity> expected = new ArrayList<OriginalLoanScheduleEntity>();
expected.add(new OriginalLoanScheduleEntity(loanScheduleEntity));
verify(legacyLoanDao).saveOriginalSchedule(Mockito.argThat(new OriginalLoanScheduleEntitiesMatcher(expected)));
}
use of org.mifos.application.master.business.MifosCurrency in project head by mifos.
the class InstallmentFormatValidatorTest method setupAndInjectDependencies.
@Before
public void setupAndInjectDependencies() {
installmentBuilder = new RepaymentScheduleInstallmentBuilder(new Locale("en", "GB"));
rupeeCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
installmentFormatValidator = new InstallmentFormatValidatorImpl();
}
use of org.mifos.application.master.business.MifosCurrency in project head by mifos.
the class SavingsPaymentStrategyImpl method makeScheduledPayments.
@Override
public Money makeScheduledPayments(final AccountPaymentEntity payment, final List<SavingsScheduleEntity> scheduledDeposits, final CustomerBO payingCustomer, final SavingsType savingsType, final Money savingsBalanceBeforeDeposit) {
MifosCurrency currency = payment.getAccount().getCurrency();
Money amountRemaining = new Money(currency, payment.getAmount().getAmount());
Money runningBalance = new Money(currency, savingsBalanceBeforeDeposit.getAmount());
final Date transactionDate = payment.getPaymentDate();
Money depositAmount;
PaymentStatus paymentStatus;
if (savingsType.getValue().equals(SavingsType.VOLUNTARY.getValue())) {
// For voluntary savings accounts - mark all outstanding
// installments as paid and then put the deposit amount in the
// latest installment
paymentStatus = PaymentStatus.PAID;
SavingsScheduleEntity lastExpectedPayment = null;
for (SavingsScheduleEntity expectedPayment : scheduledDeposits) {
lastExpectedPayment = expectedPayment;
expectedPayment.setPaymentDetails(new Money(currency), paymentStatus, new java.sql.Date(transactionDate.getTime()));
}
if (lastExpectedPayment != null) {
if (amountRemaining.isGreaterThanOrEqual(lastExpectedPayment.getTotalDepositDue())) {
depositAmount = lastExpectedPayment.getTotalDepositDue();
amountRemaining = amountRemaining.subtract(lastExpectedPayment.getTotalDepositDue());
} else {
depositAmount = new Money(currency, amountRemaining.getAmount());
amountRemaining = new Money(currency);
}
lastExpectedPayment.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
runningBalance = runningBalance.add(depositAmount);
final SavingsTrxnDetailEntity voluntaryPaymentTrxn = savingsTransactionActivityHelper.createSavingsTrxnForDeposit(payment, depositAmount, payingCustomer, lastExpectedPayment, runningBalance);
payment.addAccountTrxn(voluntaryPaymentTrxn);
}
} else {
// mandatory savings - pay off mandatory amounts as much as possible
for (SavingsScheduleEntity accountAction : scheduledDeposits) {
paymentStatus = PaymentStatus.UNPAID;
if (amountRemaining.isGreaterThanOrEqual(accountAction.getTotalDepositDue())) {
depositAmount = accountAction.getTotalDepositDue();
amountRemaining = amountRemaining.subtract(accountAction.getTotalDepositDue());
paymentStatus = PaymentStatus.PAID;
} else {
depositAmount = new Money(currency, amountRemaining.getAmount());
amountRemaining = new Money(currency);
}
accountAction.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
runningBalance = runningBalance.add(depositAmount);
final SavingsTrxnDetailEntity mandatoryScheduledPaymentTrxn = savingsTransactionActivityHelper.createSavingsTrxnForDeposit(payment, depositAmount, payingCustomer, accountAction, runningBalance);
payment.addAccountTrxn(mandatoryScheduledPaymentTrxn);
if (amountRemaining.isLessThanOrEqualZero()) {
return amountRemaining;
}
}
}
return amountRemaining;
}
use of org.mifos.application.master.business.MifosCurrency in project head by mifos.
the class CustomerDaoHibernate method getSavingsDetailDto.
@SuppressWarnings("unchecked")
@Override
public List<SavingsDetailDto> getSavingsDetailDto(Integer customerId, UserContext userContext) {
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("CUSTOMER_ID", customerId);
List<Object[]> queryResult = (List<Object[]>) this.genericDao.executeNamedQuery("Customer.getSavingsDetailDto", queryParameters);
if (queryResult.size() == 0) {
return null;
}
List<SavingsDetailDto> savingsDetails = new ArrayList<SavingsDetailDto>();
String globalAccountNum;
String prdOfferingName;
Short accountStateId;
String accountStateName;
Money savingsBalance;
String lookupName;
Short currency;
BigDecimal maxWithdrawalAmount;
String savingsType = "";
MifosCurrency mifosCurrency = Money.getDefaultCurrency();
for (Object[] savingsDetail : queryResult) {
globalAccountNum = (String) savingsDetail[0];
prdOfferingName = (String) savingsDetail[1];
accountStateId = (Short) savingsDetail[2];
lookupName = (String) savingsDetail[3];
accountStateName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupName);
// TODO - use default currency or retrieved currency?
currency = (Short) savingsDetail[4];
savingsBalance = new Money(mifosCurrency, (BigDecimal) savingsDetail[5]);
try {
SavingsBO savingsBO = (SavingsBO) new AccountBusinessService().findBySystemId(globalAccountNum);
maxWithdrawalAmount = savingsBO.getSavingsOffering().getMaxAmntWithdrawl().getAmount();
if (savingsBO.getSavingsOffering().getSavingsType().getLookUpValue() != null) {
savingsType = savingsBO.getSavingsOffering().getSavingsType().getName();
}
savingsDetails.add(new SavingsDetailDto(globalAccountNum, prdOfferingName, accountStateId, accountStateName, savingsBalance.toString(), maxWithdrawalAmount, savingsType));
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
}
return savingsDetails;
}
use of org.mifos.application.master.business.MifosCurrency 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);
}
Aggregations