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