Search in sources :

Example 1 with GroupBO

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();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) CalendarEvent(org.mifos.calendar.CalendarEvent) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with GroupBO

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));
    }
}
Also used : CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) GroupBO(org.mifos.customers.group.business.GroupBO)

Example 3 with GroupBO

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());
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) GroupBO(org.mifos.customers.group.business.GroupBO) AddressDto(org.mifos.dto.domain.AddressDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) GroupUpdate(org.mifos.dto.domain.GroupUpdate) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with GroupBO

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);
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) CenterBO(org.mifos.customers.center.business.CenterBO) GroupBO(org.mifos.customers.group.business.GroupBO)

Example 5 with GroupBO

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);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBO(org.mifos.customers.center.business.CenterBO) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

GroupBO (org.mifos.customers.group.business.GroupBO)84 Test (org.junit.Test)56 CenterBO (org.mifos.customers.center.business.CenterBO)45 GroupBuilder (org.mifos.domain.builders.GroupBuilder)42 CenterBuilder (org.mifos.domain.builders.CenterBuilder)36 CustomerException (org.mifos.customers.exceptions.CustomerException)23 ClientBO (org.mifos.customers.client.business.ClientBO)22 ArrayList (java.util.ArrayList)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)16 MeetingBO (org.mifos.application.meeting.business.MeetingBO)15 ClientBuilder (org.mifos.domain.builders.ClientBuilder)15 DateTime (org.joda.time.DateTime)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)11 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)11 UserContext (org.mifos.security.util.UserContext)11 LocalDate (org.joda.time.LocalDate)10 MifosRuntimeException (org.mifos.core.MifosRuntimeException)10 ApplicationException (org.mifos.framework.exceptions.ApplicationException)10 Date (java.util.Date)9