use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CollectionSheetServiceFacadeWebTier method saveCollectionSheet.
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
final SaveCollectionSheetDto saveCollectionSheetDto = saveCollectionSheet;
UserContext userContext = new UserContextFactory().create(user);
int customerId = saveCollectionSheetDto.getSaveCollectionSheetCustomers().get(0).getCustomerId();
CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
try {
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
CollectionSheetErrorsDto collectionSheetErrorsDto = null;
try {
collectionSheetErrorsDto = collectionSheetService.saveCollectionSheet(saveCollectionSheet);
} catch (SaveCollectionSheetException e) {
throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
}
return collectionSheetErrorsDto;
}
use of org.mifos.customers.business.CustomerBO 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.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method handleChangeInMeetingSchedule.
private void handleChangeInMeetingSchedule(CustomerBO customer, final List<Days> workingDays, final List<Holiday> orderedUpcomingHolidays) throws AccountException {
boolean lsimEnabled = this.configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled();
Set<AccountBO> accounts = customer.getAccounts();
for (AccountBO account : accounts) {
if (account instanceof LoanBO && lsimEnabled) {
// do not change schedules when LSIm is on for loan accounts
} else {
account.handleChangeInMeetingSchedule(workingDays, orderedUpcomingHolidays, customer.isTopOfHierarchy());
customerDao.save(account);
}
}
for (CustomerBO child : customer.getChildren()) {
handleChangeInMeetingSchedule(child, workingDays, orderedUpcomingHolidays);
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method removeFromBlacklist.
public void removeFromBlacklist(UserContext userContext, Integer customerId) {
CustomerBO customer = this.customerDao.findCustomerById(customerId);
customer.updateDetails(userContext);
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(customer);
customer.unBlacklist();
customerDao.save(customer);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.customers.business.CustomerBO 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