use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class CustomerAccountCreationTest method givenBiMonthlyFrequencyFirstCustomerScheduleForChildSynchsWithNearestScheduleOfParent.
@Test
public void givenBiMonthlyFrequencyFirstCustomerScheduleForChildSynchsWithNearestScheduleOfParent() throws Exception {
// setup
applicableCalendarEvents = new CalendarEventBuilder().build();
DateTime tue19thOfApril = new DateTime().withDate(2011, 4, 19);
DateTime tue26thOfApril = new DateTime().withDate(2011, 4, 26);
accountFees = new ArrayList<AccountFeesEntity>();
MeetingBO centerMeeting = new MeetingBuilder().customerMeeting().monthly().every(2).occuringOnA(WeekDay.MONDAY).startingFrom(tue19thOfApril.minusDays(1).toDate()).onDayOfMonth(18).build();
MeetingBO groupMeeting = new MeetingBuilder().customerMeeting().monthly().every(2).occuringOnA(WeekDay.MONDAY).startingFrom(tue26thOfApril.minusDays(1).toDate()).onDayOfMonth(18).build();
CenterBO center = new CenterBuilder().active().withActivationDate(tue19thOfApril).with(centerMeeting).build();
GroupBO group = new GroupBuilder().active().withParentCustomer(center).withActivationDate(tue26thOfApril).withMeeting(groupMeeting).build();
// exercise test
CustomerAccountBO centerAccount = CustomerAccountBO.createNew(center, accountFees, centerMeeting, applicableCalendarEvents);
CustomerAccountBO groupAccount = CustomerAccountBO.createNew(group, accountFees, groupMeeting, applicableCalendarEvents);
// verification
List<AccountActionDateEntity> centerSchedules = new ArrayList<AccountActionDateEntity>(centerAccount.getAccountActionDates());
List<AccountActionDateEntity> groupSchedules = new ArrayList<AccountActionDateEntity>(groupAccount.getAccountActionDates());
LocalDate firstCenterDate = new LocalDate(centerSchedules.get(0).getActionDate());
LocalDate secondCenterDate = new LocalDate(centerSchedules.get(1).getActionDate());
LocalDate firstGroupDate = new LocalDate(groupSchedules.get(0).getActionDate());
LocalDate secondGroupDate = new LocalDate(groupSchedules.get(1).getActionDate());
assertThat(firstGroupDate, is(firstCenterDate));
assertThat(secondGroupDate, is(secondCenterDate));
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class CustomerAccountCreationTest method givenTriMonthlyFrequencyFirstCustomerScheduleForChildSynchsWithNearestScheduleOfParent.
@Test
public void givenTriMonthlyFrequencyFirstCustomerScheduleForChildSynchsWithNearestScheduleOfParent() throws Exception {
// setup
applicableCalendarEvents = new CalendarEventBuilder().build();
DateTime tue19thOfApril = new DateTime().withDate(2011, 4, 19);
DateTime tue26thOfApril = new DateTime().withDate(2011, 4, 26);
accountFees = new ArrayList<AccountFeesEntity>();
MeetingBO centerMeeting = new MeetingBuilder().customerMeeting().monthly().every(3).occuringOnA(WeekDay.MONDAY).startingFrom(tue19thOfApril.minusDays(1).toDate()).onDayOfMonth(18).build();
MeetingBO groupMeeting = new MeetingBuilder().customerMeeting().monthly().every(3).occuringOnA(WeekDay.MONDAY).startingFrom(tue26thOfApril.minusDays(1).toDate()).onDayOfMonth(18).build();
CenterBO center = new CenterBuilder().active().withActivationDate(tue19thOfApril).with(centerMeeting).build();
GroupBO group = new GroupBuilder().active().withParentCustomer(center).withActivationDate(tue26thOfApril).withMeeting(groupMeeting).build();
// exercise test
CustomerAccountBO centerAccount = CustomerAccountBO.createNew(center, accountFees, centerMeeting, applicableCalendarEvents);
CustomerAccountBO groupAccount = CustomerAccountBO.createNew(group, accountFees, groupMeeting, applicableCalendarEvents);
// verification
List<AccountActionDateEntity> centerSchedules = new ArrayList<AccountActionDateEntity>(centerAccount.getAccountActionDates());
List<AccountActionDateEntity> groupSchedules = new ArrayList<AccountActionDateEntity>(groupAccount.getAccountActionDates());
LocalDate firstCenterDate = new LocalDate(centerSchedules.get(0).getActionDate());
LocalDate secondCenterDate = new LocalDate(centerSchedules.get(1).getActionDate());
LocalDate firstGroupDate = new LocalDate(groupSchedules.get(0).getActionDate());
LocalDate secondGroupDate = new LocalDate(groupSchedules.get(1).getActionDate());
assertThat(firstGroupDate, is(firstCenterDate));
assertThat(secondGroupDate, is(secondCenterDate));
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class CustomerPersistenceIntegrationTest method testGetCustomerAccountsForFee.
@Test
public void testGetCustomerAccountsForFee() throws Exception {
groupAccount = getLoanAccount();
FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("ClientPeridoicFee", FeeCategory.CENTER, "5", RecurrenceType.WEEKLY, Short.valueOf("1"));
AccountFeesEntity accountFee = new AccountFeesEntity(center.getCustomerAccount(), periodicFee, ((AmountFeeBO) periodicFee).getFeeAmount().getAmountDoubleValue());
CustomerAccountBO customerAccount = center.getCustomerAccount();
AccountTestUtils.addAccountFees(accountFee, customerAccount);
TestObjectFactory.updateObject(customerAccount);
StaticHibernateUtil.flushSession();
// check for the account fee
List<AccountBO> accountList = new CustomerPersistence().getCustomerAccountsForFee(periodicFee.getFeeId());
Assert.assertNotNull(accountList);
Assert.assertEquals(1, accountList.size());
Assert.assertTrue(accountList.get(0) instanceof CustomerAccountBO);
// get all objects again
groupAccount = TestObjectFactory.getObject(LoanBO.class, groupAccount.getAccountId());
group = TestObjectFactory.getCustomer(group.getCustomerId());
center = TestObjectFactory.getCustomer(center.getCustomerId());
}
use of org.mifos.customers.business.CustomerAccountBO 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);
}
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class CustomerServiceImpl method createCustomer.
private void createCustomer(CustomerBO customer, MeetingBO meeting, List<AccountFeesEntity> accountFees) {
try {
this.hibernateTransactionHelper.startTransaction();
this.customerDao.save(customer);
this.hibernateTransactionHelper.flushSession();
// must first be saved via the customer save.
for (AccountBO account : customer.getAccounts()) {
if (account.isSavingsAccount()) {
SavingsBO savingsAccount = (SavingsBO) account;
savingsAccount.setUserContext(customer.getUserContext());
savingsAccount.generateSystemId(customer.getOffice().getGlobalOfficeNum());
}
}
this.customerDao.save(customer);
this.hibernateTransactionHelper.flushSession();
CalendarEvent applicableCalendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
CustomerAccountBO customerAccount = this.customerAccountFactory.create(customer, accountFees, meeting, applicableCalendarEvents);
customer.addAccount(customerAccount);
this.customerDao.save(customer);
this.hibernateTransactionHelper.flushSession();
if (customer.getParentCustomer() != null) {
this.customerDao.save(customer.getParentCustomer());
}
customer.generateGlobalCustomerNumber();
customer.generateSearchId();
this.customerDao.save(customer);
if (customer.getParentCustomer() != null) {
this.customerDao.save(customer.getParentCustomer());
}
this.hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
}
Aggregations