Search in sources :

Example 56 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class TestObjectFactory method createSavingsAccount.

/**
     * Also see {@link SavingsTestHelper#createSavingsAccount(SavingsOfferingBO, CustomerBO, AccountState, UserContext)}
     * which is less elaborate.
     */
public static SavingsBO createSavingsAccount(final String globalNum, final CustomerBO customer, final AccountState state, final Date startDate, final SavingsOfferingBO savingsOffering, UserContext userContext) throws Exception {
    userContext = TestUtils.makeUserWithLocales();
    SavingsBO savings = new SavingsBO(userContext, savingsOffering, customer, state, savingsOffering.getRecommendedAmount(), getCustomFieldView());
    savings.save();
    SavingBOTestUtils.setActivationDate(savings, new DateTimeService().getCurrentJavaDateTime());
    StaticHibernateUtil.flushSession();
    return getObject(SavingsBO.class, savings.getAccountId());
}
Also used : SavingsBO(org.mifos.accounts.savings.business.SavingsBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 57 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class TestObjectFactory method deleteSpecificAccount.

private static void deleteSpecificAccount(final AccountBO account, final Session session) {
    if (account instanceof LoanBO) {
        LoanBO loan = (LoanBO) account;
        if (null != loan.getLoanSummary()) {
            session.delete(loan.getLoanSummary());
        }
        session.delete(account);
        loan.getLoanOffering().getLoanOfferingMeeting().setMeeting(null);
        session.delete(loan.getLoanOffering().getLoanOfferingMeeting());
        session.delete(loan.getLoanOffering());
    }
    if (account instanceof SavingsBO) {
        SavingsBO savings = (SavingsBO) account;
        session.delete(account);
        // FIXME - no longer create a meeting to track intereswt calculation for each savings account, instead we always use value from savigns product.
        //            session.delete(savings.getTimePerForInstcalc());
        PrdOfferingMeetingEntity prdOfferingMeeting1 = savings.getSavingsOffering().getTimePerForInstcalc();
        prdOfferingMeeting1.setMeeting(null);
        session.delete(prdOfferingMeeting1);
        PrdOfferingMeetingEntity prdOfferingMeeting2 = savings.getSavingsOffering().getFreqOfPostIntcalc();
        prdOfferingMeeting2.setMeeting(null);
        session.delete(prdOfferingMeeting2);
        session.delete(savings.getSavingsOffering());
    } else {
        session.delete(account);
    }
}
Also used : PrdOfferingMeetingEntity(org.mifos.accounts.productdefinition.business.PrdOfferingMeetingEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Example 58 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class CustomerBOIntegrationTest method testgetSavingsBalance.

@Test
public void testgetSavingsBalance() throws Exception {
    SavingsBO savings = getSavingsAccount("fsaf4", "ads4");
    SavingBOTestUtils.setBalance(savings, new Money(getCurrency(), "1000"));
    savings.update();
    StaticHibernateUtil.flushAndClearSession();
    savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
    client = TestObjectFactory.getClient(client.getCustomerId());
    Assert.assertEquals(new Money(getCurrency(), "1000.0"), savings.getSavingsBalance());
    Assert.assertEquals(new Money(getCurrency(), "1000.0"), client.getSavingsBalance(getCurrency()));
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCenter(center.getCustomerId());
    group = TestObjectFactory.getGroup(group.getCustomerId());
    client = TestObjectFactory.getClient(client.getCustomerId());
    savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
    savings = null;
}
Also used : Money(org.mifos.framework.util.helpers.Money) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Test(org.junit.Test)

Example 59 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class GroupValidationTest method givenAnActiveSavingsAccountExistsGroupTransferToCenterShouldFailValidation.

@Test
public void givenAnActiveSavingsAccountExistsGroupTransferToCenterShouldFailValidation() {
    // setup
    CenterBO center = new CenterBuilder().build();
    GroupBO group = new GroupBuilder().withParentCustomer(center).build();
    SavingsBO savings = new SavingsAccountBuilder().active().withCustomer(group).build();
    group.addAccount(savings);
    // exercise test
    try {
        group.validateNoActiveAccountsExist();
        fail("should fail validation");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_HAS_ACTIVE_ACCOUNT));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) GroupBuilder(org.mifos.domain.builders.GroupBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) Test(org.junit.Test)

Example 60 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class CenterServiceFacadeWebTier method waiveChargesDue.

@Override
public void waiveChargesDue(Integer accountId, Integer waiveType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        account.updateDetails(userContext);
        PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
        WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        try {
            this.transactionHelper.startTransaction();
            if (account instanceof LoanBO) {
                ((LoanBO) account).waiveAmountDue(waiveEnum);
            } else if (account instanceof SavingsBO) {
                ((SavingsBO) account).waiveNextDepositAmountDue(loggedInUser);
            } else {
                ((CustomerAccountBO) account).waiveAmountDue();
            }
            this.customerDao.save(account);
            this.transactionHelper.commitTransaction();
        } catch (Exception e) {
            this.transactionHelper.rollbackTransaction();
            throw new BusinessRuleException(account.getAccountId().toString(), e);
        } finally {
            this.transactionHelper.closeSession();
        }
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

SavingsBO (org.mifos.accounts.savings.business.SavingsBO)111 UserContext (org.mifos.security.util.UserContext)43 MifosRuntimeException (org.mifos.core.MifosRuntimeException)30 AccountException (org.mifos.accounts.exceptions.AccountException)28 LocalDate (org.joda.time.LocalDate)27 MifosUser (org.mifos.security.MifosUser)26 Test (org.junit.Test)25 Money (org.mifos.framework.util.helpers.Money)24 ArrayList (java.util.ArrayList)22 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 Date (java.util.Date)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)19 BusinessRuleException (org.mifos.service.BusinessRuleException)18 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)17 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)17 CustomerBO (org.mifos.customers.business.CustomerBO)15 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 ServiceException (org.mifos.framework.exceptions.ServiceException)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12