Search in sources :

Example 36 with MifosCurrency

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)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) OriginalLoanScheduleEntitiesMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 37 with MifosCurrency

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();
}
Also used : Locale(java.util.Locale) RepaymentScheduleInstallmentBuilder(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallmentBuilder) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Before(org.junit.Before)

Example 38 with MifosCurrency

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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Date(java.util.Date) PaymentStatus(org.mifos.accounts.util.helpers.PaymentStatus)

Example 39 with MifosCurrency

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;
}
Also used : SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ArrayList(java.util.ArrayList) List(java.util.List) MifosCurrency(org.mifos.application.master.business.MifosCurrency) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 40 with MifosCurrency

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

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