Search in sources :

Example 51 with SavingsBO

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

the class SavingsServiceFacadeWebTier method fundTransfer.

@Override
public void fundTransfer(FundTransferDto fundTransferDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO targetAcc = this.savingsDao.findBySystemId(fundTransferDto.getTargetGlobalAccountNum());
    SavingsBO sourceAcc = this.savingsDao.findBySystemId(fundTransferDto.getSourceGlobalAccountNum());
    SavingsDepositDto depositDto;
    SavingsWithdrawalDto withdrawalDto;
    // prepare data
    try {
        depositDto = new SavingsDepositDto(targetAcc.getAccountId().longValue(), targetAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
        withdrawalDto = new SavingsWithdrawalDto(sourceAcc.getAccountId().longValue(), sourceAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
    } catch (PersistenceException ex) {
        throw new MifosRuntimeException(ex);
    }
    // transaction
    try {
        this.transactionHelper.startTransaction();
        PaymentDto deposit = deposit(depositDto, true);
        PaymentDto withdrawal = withdraw(withdrawalDto, true);
        // connect the two payments
        AccountPaymentEntity sourcePayment = sourceAcc.findPaymentById(withdrawal.getPaymentId());
        AccountPaymentEntity targetPayment = targetAcc.findPaymentById(deposit.getPaymentId());
        sourcePayment.setOtherTransferPayment(targetPayment);
        targetPayment.setOtherTransferPayment(sourcePayment);
        this.savingsDao.save(sourceAcc);
        this.savingsDao.save(targetAcc);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException ex) {
        this.transactionHelper.rollbackTransaction();
        throw ex;
    } catch (Exception ex) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) UserContext(org.mifos.security.util.UserContext) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) PaymentDto(org.mifos.dto.domain.PaymentDto) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 52 with SavingsBO

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

the class SavingsPrdPersistenceIntegrationTest method testRetrieveSavingsAccountsForPrd.

@Test
public void testRetrieveSavingsAccountsForPrd() throws Exception {
    SavingsTestHelper helper = new SavingsTestHelper();
    createInitialObjects();
    savingsOffering = helper.createSavingsOffering("fsaf6", "ads6");
    UserContext userContext = new UserContext();
    userContext.setId(PersonnelConstants.SYSTEM_USER);
    savings = helper.createSavingsAccount("000100000000017", savingsOffering, group, AccountStates.SAVINGS_ACC_APPROVED, userContext);
    StaticHibernateUtil.flushSession();
    List<SavingsBO> savingsList = savingsProductDao.retrieveSavingsAccountsForPrd(savingsOffering.getPrdOfferingId());
    Assert.assertEquals(Integer.valueOf("1").intValue(), savingsList.size());
    savings = savingsDao.findById(savings.getAccountId());
}
Also used : UserContext(org.mifos.security.util.UserContext) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsTestHelper(org.mifos.accounts.savings.util.helpers.SavingsTestHelper) Test(org.junit.Test)

Example 53 with SavingsBO

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

the class CustomerBusinessServiceIntegrationTest method testFindBySystemId.

@Test
public void testFindBySystemId() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    savingsBO = getSavingsAccount(group, "fsaf5", "ads5");
    StaticHibernateUtil.flushAndClearSession();
    group = (GroupBO) service.findBySystemId(group.getGlobalCustNum());
    Assert.assertEquals("Group_Active_test", group.getDisplayName());
    Assert.assertEquals(2, group.getAccounts().size());
    Assert.assertEquals(0, group.getOpenLoanAccounts().size());
    Assert.assertEquals(1, group.getOpenSavingAccounts().size());
    Assert.assertEquals(CustomerStatus.GROUP_ACTIVE, group.getStatus());
    StaticHibernateUtil.flushSession();
    savingsBO = TestObjectFactory.getObject(SavingsBO.class, savingsBO.getAccountId());
    center = TestObjectFactory.getCenter(center.getCustomerId());
    group = TestObjectFactory.getGroup(group.getCustomerId());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Test(org.junit.Test)

Example 54 with SavingsBO

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

the class ClientIntegrationTest method testSuccessfulCreateInActiveState_WithAssociatedSavingsOffering.

@Test
public void testSuccessfulCreateInActiveState_WithAssociatedSavingsOffering() throws Exception {
    savingsOffering1 = TestObjectFactory.createSavingsProduct("offering1", "s1", SavingsType.MANDATORY, ApplicableTo.CLIENTS, new Date(System.currentTimeMillis()));
    StaticHibernateUtil.flushSession();
    List<SavingsOfferingBO> selectedOfferings = new ArrayList<SavingsOfferingBO>();
    selectedOfferings.add(savingsOffering1);
    String name = "Client 1";
    Short povertyStatus = Short.valueOf("41");
    ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), TestObjectFactory.SAMPLE_SALUTATION, "Client", "", "1", "");
    clientNameDetailDto.setNames(ClientRules.getNameSequence());
    ClientNameDetailDto spouseNameDetailView = new ClientNameDetailDto(NameType.SPOUSE.getValue(), TestObjectFactory.SAMPLE_SALUTATION, "first", "middle", "last", "secondLast");
    spouseNameDetailView.setNames(ClientRules.getNameSequence());
    ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(1, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), povertyStatus);
    client = new ClientBO(TestUtils.makeUser(), clientNameDetailDto.getDisplayName(), CustomerStatus.CLIENT_ACTIVE, null, null, null, null, null, selectedOfferings, personnel, new OfficePersistence().getOffice(TestObjectFactory.SAMPLE_BRANCH_OFFICE), getMeeting(), personnel, null, null, null, null, YesNoFlag.NO.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto, null);
    legacyClientDao.saveClient(client);
    StaticHibernateUtil.flushSession();
    client = TestObjectFactory.getClient(client.getCustomerId());
    Assert.assertEquals(name, client.getDisplayName());
    Assert.assertEquals(1, client.getOfferingsAssociatedInCreate().size());
    Assert.assertEquals(2, client.getAccounts().size());
    for (AccountBO account : client.getAccounts()) {
        if (account instanceof SavingsBO) {
            Assert.assertEquals(savingsOffering1.getPrdOfferingId(), ((SavingsBO) account).getSavingsOffering().getPrdOfferingId());
            Assert.assertNotNull(account.getGlobalAccountNum());
            Assert.assertTrue(true);
        }
    }
    StaticHibernateUtil.flushSession();
    client = TestObjectFactory.getClient(client.getCustomerId());
    savingsOffering1 = null;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) ArrayList(java.util.ArrayList) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Date(java.sql.Date) Test(org.junit.Test)

Example 55 with SavingsBO

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

the class SavingsAccountBuilder method buildAccount.

private SavingsBO buildAccount(SavingsAccountActivationDetail derivedActivationDetails) {
    List<AccountActionDateEntity> listOfScheduledPayments = new ArrayList<AccountActionDateEntity>();
    if (scheduledPayments == null) {
        listOfScheduledPayments = derivedActivationDetails.getScheduledPayments();
    } else {
        listOfScheduledPayments = new ArrayList<AccountActionDateEntity>(scheduledPayments);
    }
    activationDetails = new SavingsAccountActivationDetail(new LocalDate(activationDate), nextInterestPostingDate, listOfScheduledPayments);
    CreationDetail creationDetail = new CreationDetail(new DateTime(createdDate), createdByUserId.intValue());
    SavingsBO savingsAccount = new SavingsBO(accountState, customer, activationDetails, creationDetail, savingsProduct, recommendedAmountUnit, recommendedAmount, createdBy, savingsBalanceAmount);
    savingsAccount.setCustomerPersistence(customerDao);
    savingsAccount.setSavingsPaymentStrategy(savingsPaymentStrategy);
    savingsAccount.setSavingsTransactionActivityHelper(savingsTransactionActivityHelper);
    savingsAccount.updateDetails(TestUtils.makeUserWithLocales());
    for (AccountPaymentEntity depositPayment : deposits) {
        try {
            depositPayment.setAccount(savingsAccount);
            savingsAccount.deposit(depositPayment, customer);
        } catch (AccountException e) {
            throw new MifosRuntimeException("builder failed to apply deposits.", e);
        }
    }
    for (AccountPaymentEntity withdrawal : withdrawals) {
        try {
            withdrawal.setAccount(savingsAccount);
            savingsAccount.withdraw(withdrawal, customer);
        } catch (AccountException e) {
            throw new MifosRuntimeException("builder failed to apply withdrawals.", e);
        }
    }
    return savingsAccount;
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) AccountException(org.mifos.accounts.exceptions.AccountException) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) CreationDetail(org.mifos.clientportfolio.newloan.domain.CreationDetail) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) 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