use of org.mifos.customers.group.business.GroupBO 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.group.business.GroupBO in project head by mifos.
the class XlsClientsImporter method validateGroup.
private void validateGroup(final String globalGroupNum) throws CellException {
if (StringUtils.isBlank(globalGroupNum)) {
return;
}
final GroupBO group = customerDao.findGroupBySystemId(globalGroupNum);
if (group == null) {
throw new CellException(getMessage(XlsMessageConstants.GROUP_NOT_FOUND_ERROR, globalGroupNum));
}
final CustomerStatus groupStatus = group.getStatus();
if (groupStatus == CustomerStatus.GROUP_CANCELLED) {
throw new CellException(getMessage(XlsMessageConstants.GROUP_CANCELED, globalGroupNum));
} else if (groupStatus == CustomerStatus.GROUP_CLOSED) {
throw new CellException(getMessage(XlsMessageConstants.GROUP_CLOSED, globalGroupNum));
}
}
use of org.mifos.customers.group.business.GroupBO in project head by mifos.
the class GroupCustAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
GroupBO group = (GroupBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
GroupCustActionForm actionForm = (GroupCustActionForm) form;
boolean trained = false;
if (actionForm.getTrainedValue() != null && actionForm.getTrainedValue().equals(Short.valueOf("1"))) {
trained = true;
}
AddressDto address = null;
if (actionForm.getAddress() != null) {
address = Address.toDto(actionForm.getAddress());
}
GroupUpdate groupUpdate = new GroupUpdate(group.getCustomerId(), group.getGlobalCustNum(), group.getVersionNo(), actionForm.getDisplayName(), actionForm.getLoanOfficerIdValue(), actionForm.getExternalId(), trained, actionForm.getTrainedDate(), address, actionForm.getCustomFields(), actionForm.getCustomerPositions());
try {
this.groupServiceFacade.updateGroup(groupUpdate);
} catch (BusinessRuleException e) {
throw new ApplicationException(e.getMessageKey(), e);
}
return mapping.findForward(ActionForwards.update_success.toString());
}
use of org.mifos.customers.group.business.GroupBO in project head by mifos.
the class LoanBOTestUtils method getLoanAccount.
private LoanBO getLoanAccount(final AccountState state, final Date startDate) {
MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
CenterBO center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
GroupBO group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group", CustomerStatus.GROUP_ACTIVE, center);
LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
final int disbursalType = 3;
return TestObjectFactory.createLoanAccountWithDisbursement("99999999999", group, state, startDate, loanOffering, disbursalType);
}
use of org.mifos.customers.group.business.GroupBO in project head by mifos.
the class GroupServiceFacadeWebTier method createNewGroup.
@Override
public CustomerDetailsDto createNewGroup(GroupCreationDetail groupCreationDetail, MeetingDto meetingDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
GroupBO group;
try {
List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(groupCreationDetail.getFeesToApply());
PersonnelBO formedBy = this.personnelDao.findPersonnelById(groupCreationDetail.getLoanOfficerId());
Short officeId;
String groupName = groupCreationDetail.getDisplayName();
CustomerStatus customerStatus = CustomerStatus.fromInt(groupCreationDetail.getCustomerStatus());
String externalId = groupCreationDetail.getExternalId();
boolean trained = groupCreationDetail.isTrained();
DateTime trainedOn = groupCreationDetail.getTrainedOn();
DateTime mfiJoiningDate = groupCreationDetail.getMfiJoiningDate();
DateTime activationDate = groupCreationDetail.getActivationDate();
AddressDto dto = groupCreationDetail.getAddressDto();
Address address = null;
if (dto != null) {
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
MeetingBO groupMeeting = null;
if (meetingDto != null) {
groupMeeting = new MeetingFactory().create(meetingDto);
groupMeeting.setUserContext(userContext);
}
if (ClientRules.getCenterHierarchyExists()) {
CenterBO parentCustomer = this.customerDao.findCenterBySystemId(groupCreationDetail.getParentSystemId());
// loanOfficerId = parentCustomer.getPersonnel().getPersonnelId();
officeId = parentCustomer.getOffice().getOfficeId();
groupMeeting = parentCustomer.getCustomerMeetingValue();
group = GroupBO.createGroupWithCenterAsParent(userContext, groupName, formedBy, parentCustomer, address, externalId, trained, trainedOn, customerStatus, mfiJoiningDate, activationDate);
} else {
// create group without center as parent
Short loanOfficerId = groupCreationDetail.getLoanOfficerId() != null ? groupCreationDetail.getLoanOfficerId() : userContext.getId();
officeId = groupCreationDetail.getOfficeId();
OfficeBO office = this.officeDao.findOfficeById(groupCreationDetail.getOfficeId());
PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
int numberOfCustomersInOfficeAlready = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
group = GroupBO.createGroupAsTopOfCustomerHierarchy(userContext, groupName, formedBy, groupMeeting, loanOfficer, office, address, externalId, trained, trainedOn, customerStatus, numberOfCustomersInOfficeAlready, mfiJoiningDate, activationDate);
}
try {
personnelDao.checkAccessPermission(userContext, group.getOfficeId(), group.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.customerService.createGroup(group, groupMeeting, feesForCustomerAccount);
return new CustomerDetailsDto(group.getCustomerId(), group.getGlobalCustNum());
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
Aggregations