use of org.mifos.calendar.CalendarEvent in project head by mifos.
the class SavingsAccountBuilder method build.
// build individual savings account
public SavingsBO build() {
CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
LocalDate activationDate = new LocalDate(createdDate);
SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, activationDate);
return buildAccount(derivedActivationDetails);
}
use of org.mifos.calendar.CalendarEvent in project head by mifos.
the class CustomerServiceImpl method transferGroupTo.
@Override
public final String transferGroupTo(GroupBO group, CenterBO receivingCenter) throws CustomerException {
group.validateReceivingCenter(receivingCenter);
group.validateNoActiveAccountsExist();
if (group.isDifferentBranch(receivingCenter.getOffice())) {
customerDao.validateGroupNameIsNotTakenForOffice(group.getDisplayName(), receivingCenter.getOfficeId());
}
CustomerBO oldParent = group.getParentCustomer();
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(group);
boolean regenerateSchedules = group.transferTo(receivingCenter);
if (oldParent != null) {
oldParent.updateDetails(group.getUserContext());
customerDao.save(oldParent);
}
receivingCenter.updateDetails(group.getUserContext());
customerDao.save(receivingCenter);
group.updateDetails(group.getUserContext());
customerDao.save(group);
Set<CustomerBO> clients = group.getChildren();
for (CustomerBO client : clients) {
client.setUserContext(group.getUserContext());
((ClientBO) client).handleGroupTransfer();
client.setUpdateDetails();
customerDao.save(client);
}
hibernateTransactionHelper.flushSession();
GroupBO groupInitialised = group;
if (regenerateSchedules) {
CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(group.getOfficeId());
groupInitialised = customerDao.findGroupBySystemId(group.getGlobalCustNum());
handleChangeInMeetingSchedule(groupInitialised, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
}
hibernateTransactionHelper.commitTransaction();
return groupInitialised.getGlobalCustNum();
} catch (ApplicationException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.calendar.CalendarEvent 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);
}
}
use of org.mifos.calendar.CalendarEvent in project head by mifos.
the class CustomerServiceImpl method changeStatus.
private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
Short oldStatusId = oldStatus.getValue();
Short newStatusId = newStatus.getValue();
if (customer.isClient()) {
ClientBO client = (ClientBO) customer;
if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
if (client.getParentCustomer() != null) {
CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
client.addCustomerHierarchy(hierarchy);
}
CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
if (client.getOfferingsAssociatedInCreate() != null) {
for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
try {
SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
if (savingsOffering.isActive()) {
List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
}
} catch (AccountException pe) {
throw new CustomerException(pe);
}
}
}
new SavingsPersistence().persistSavingAccounts(client);
try {
if (client.getParentCustomer() != null) {
List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
if (client.getParentCustomer().getParentCustomer() != null) {
savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
}
for (SavingsBO savings : savingsList) {
savings.setUserContext(client.getUserContext());
if (client.getCustomerMeeting().getMeeting() != null) {
if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
DateTime today = new DateTime().toDateMidnight().toDateTime();
savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
savings.update();
}
}
}
}
} catch (PersistenceException pe) {
throw new CustomerException(pe);
} catch (AccountException ae) {
throw new CustomerException(ae);
}
}
}
}
use of org.mifos.calendar.CalendarEvent in project head by mifos.
the class CustomerServiceImpl method updateGroupStatus.
@Override
public final void updateGroupStatus(GroupBO group, CustomerStatus oldStatus, CustomerStatus newStatus, CustomerStatusFlag customerStatusFlag, CustomerNoteEntity customerNote) throws CustomerException {
validateChangeOfStatusForGroup(group, oldStatus, newStatus);
CustomerStatusFlagEntity customerStatusFlagEntity = populateCustomerStatusFlag(customerStatusFlag);
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(group);
if (group.isActiveForFirstTime(oldStatus.getValue(), newStatus.getValue())) {
group.setCustomerActivationDate(new DateTime().toDate());
group.updateCustomerHierarchy();
CalendarEvent applicableCalendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(group.getOfficeId());
group.regenerateCustomerFeeSchedule(applicableCalendarEvents);
}
Set<CustomerBO> groupChildren = group.getChildren();
if (oldStatus.isGroupPending() && newStatus.isGroupCancelled() && groupChildren != null) {
for (CustomerBO child : groupChildren) {
ClientBO client = (ClientBO) child;
if (client.isPending()) {
client.setUserContext(group.getUserContext());
hibernateTransactionHelper.beginAuditLoggingFor(client);
client.updateCustomerStatus(CustomerStatus.CLIENT_PARTIAL);
customerDao.save(client);
}
}
}
group.updateCustomerStatus(newStatus, customerNote, customerStatusFlagEntity);
customerDao.save(group);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
Aggregations