Search in sources :

Example 6 with OfficeBO

use of org.mifos.customers.office.business.OfficeBO in project head by mifos.

the class OfficeServiceFacadeWebTier method updateOffice.

@Override
public boolean updateOffice(Short officeId, Integer versionNum, OfficeUpdateRequest officeUpdateRequest) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        boolean isParentOfficeChanged = false;
        OfficeBO office = officeDao.findOfficeById(officeId);
        office.validateVersion(versionNum);
        OfficeBO parentOffice = null;
        if (officeUpdateRequest.getParentOfficeId() != null) {
            parentOffice = officeDao.findOfficeById(officeUpdateRequest.getParentOfficeId());
            if (office.isDifferentParentOffice(parentOffice)) {
                holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(office.getParentOffice().getOfficeId(), officeUpdateRequest.getParentOfficeId());
            }
        }
        if (office.isNameDifferent(officeUpdateRequest.getOfficeName())) {
            officeDao.validateOfficeNameIsNotTaken(officeUpdateRequest.getOfficeName());
        }
        if (office.isShortNameDifferent(officeUpdateRequest.getShortName())) {
            officeDao.validateOfficeShortNameIsNotTaken(officeUpdateRequest.getShortName());
        }
        OfficeStatus newStatus = OfficeStatus.getOfficeStatus(officeUpdateRequest.getNewStatus());
        if (!office.isStatusDifferent(newStatus)) {
            if (OfficeStatus.INACTIVE.equals(officeUpdateRequest.getNewStatus())) {
                officeDao.validateNoActiveChildrenExist(office.getOfficeId());
                officeDao.validateNoActivePeronnelExist(office.getOfficeId());
            }
            if (parentOffice != null) {
                if (parentOffice.isInActive()) {
                    throw new OfficeException(OfficeConstants.KEYPARENTNOTACTIVE);
                }
            }
        }
        StaticHibernateUtil.startTransaction();
        office.update(userContext, officeUpdateRequest, parentOffice);
        StaticHibernateUtil.commitTransaction();
        return isParentOfficeChanged;
    } catch (OfficeException e1) {
        throw new BusinessRuleException(e1.getKey(), e1);
    } catch (ApplicationException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e.getMessage(), e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) OfficeStatus(org.mifos.customers.office.util.helpers.OfficeStatus) OfficeValidationException(org.mifos.customers.office.exceptions.OfficeValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficeException(org.mifos.customers.office.exceptions.OfficeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with OfficeBO

use of org.mifos.customers.office.business.OfficeBO in project head by mifos.

the class HolidayServiceImpl method create.

@Override
public void create(HolidayDetails holidayDetails, List<Short> officeIds) {
    HolidayBO holiday = HolidayBO.fromDto(holidayDetails);
    holiday.validate();
    List<OfficeBO> offices = new ArrayList<OfficeBO>();
    for (Short officeId : officeIds) {
        OfficeBO office = officeDao.findOfficeById(officeId);
        offices.add(office);
        if (office.hasChildWithAnyOf(officeIds)) {
            throw new BusinessRuleException(HolidayConstants.HOLIDAY_CREATION_EXCEPTION);
        // "Holidays can only be associated with one level of office in an office hierarchy."
        }
    }
    try {
        hibernateTransactionHelper.startTransaction();
        this.holidayDao.save(holiday);
        for (OfficeBO office : offices) {
            office.addHoliday(holiday);
        }
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) ArrayList(java.util.ArrayList) HolidayBO(org.mifos.application.holiday.business.HolidayBO) BusinessRuleException(org.mifos.service.BusinessRuleException)

Example 8 with OfficeBO

use of org.mifos.customers.office.business.OfficeBO in project head by mifos.

the class ImportClientsServiceFacadeWebTier method save.

@Override
public ParsedClientsDto save(ParsedClientsDto parsedClientsDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    DateTimeService dateTimeService = new DateTimeService();
    /* Construct ClientBO objects */
    List<NewClientDto> newClients = new ArrayList<NewClientDto>();
    for (ImportedClientDetail importedClient : parsedClientsDto.getSuccessfullyParsedRows()) {
        String secondMiddleName = null;
        ClientCreationDetail clientCreationDetail = importedClient.getClientCreationDetail();
        PersonnelBO formedBy = null;
        /* Client name details */
        ClientNameDetailDto clientNameDetails = clientCreationDetail.getClientNameDetailDto();
        ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientNameDetails);
        ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
        clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
        String clientFirstName = clientNameDetails.getFirstName();
        String clientLastName = clientNameDetails.getLastName();
        String secondLastName = clientNameDetails.getSecondLastName();
        /* Spouse/father name details */
        ClientNameDetailEntity spouseFatherNameDetailEntity = null;
        if (clientCreationDetail.getSpouseFatherName() != null) {
            spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getSpouseFatherName());
        }
        /* Data conversion */
        DateTime dateOfBirth = new DateTime(clientCreationDetail.getDateOfBirth());
        DateTime mfiJoiningDate = new DateTime(clientCreationDetail.getMfiJoiningDate());
        DateTime trainedDateTime = null;
        if (clientCreationDetail.getTrainedDate() != null) {
            trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
        }
        /* Status */
        CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
        CustomerStatus finalStatus = clientStatus;
        if (clientStatus == CustomerStatus.CLIENT_ACTIVE && clientCreationDetail.getActivationDate() == null) {
            clientStatus = CustomerStatus.CLIENT_PENDING;
        }
        /* Address */
        Address address = null;
        if (clientCreationDetail.getAddress() != null) {
            AddressDto dto = clientCreationDetail.getAddress();
            address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
        }
        // empty list
        List<ClientInitialSavingsOfferingEntity> associatedOfferings = new ArrayList<ClientInitialSavingsOfferingEntity>();
        // client object
        ClientBO client;
        if (clientCreationDetail.getGroupFlag() == 1) {
            CustomerBO group = customerDao.findCustomerBySystemId(clientCreationDetail.getParentGroupId());
            if (clientCreationDetail.getFormedBy() != null) {
                formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
            } else {
                formedBy = group.getPersonnel();
            }
            client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, group, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
        } else {
            Short officeId = clientCreationDetail.getOfficeId();
            Short officerId = clientCreationDetail.getLoanOfficerId();
            PersonnelBO loanOfficer = personnelDao.findPersonnelById(officerId);
            OfficeBO office = this.officeDao.findOfficeById(officeId);
            if (clientCreationDetail.getFormedBy() != null) {
                formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
            } else {
                formedBy = loanOfficer;
            }
            int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            /* meeting */
            final MeetingDto meetingDto = importedClient.getMeeting();
            MeetingBO clientMeeting = null;
            if (meetingDto != null) {
                clientMeeting = new MeetingFactory().create(meetingDto);
                clientMeeting.setUserContext(userContext);
            }
            client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
            if (clientCreationDetail.getActivationDate() != null) {
                client.setCustomerActivationDate(clientCreationDetail.getActivationDate().toDateMidnight().toDate());
            }
        }
        // global id
        if (importedClient.getClientGlobalNum() != null) {
            client.setGlobalCustNum(importedClient.getClientGlobalNum());
        }
        NewClientDto newClient = new NewClientDto(client, finalStatus);
        newClients.add(newClient);
    }
    /* Validate client data */
    for (NewClientDto newClient : newClients) {
        ClientBO client = newClient.getClientBO();
        try {
            client.validate();
            customerDao.validateClientForDuplicateNameOrGovtId(client.getDisplayName(), client.getDateOfBirth(), client.getGovernmentId());
        } catch (CustomerException ex) {
            throw new MifosRuntimeException(ex);
        }
    }
    /* Save clients */
    // empty list
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    try {
        hibernateTransactionHelper.startTransaction();
        for (NewClientDto newClient : newClients) {
            ClientBO client = newClient.getClientBO();
            CustomerStatus finalStatus = newClient.getCustomerStatus();
            // status to pending approval if active
            MeetingBO meeting = client.getCustomerMeetingValue();
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
            CustomerAccountBO customerAccount = customerAccountFactory.create(client, accountFees, meeting, applicableCalendarEvents);
            client.addAccount(customerAccount);
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            if (client.getParentCustomer() != null) {
                customerDao.save(client.getParentCustomer());
            }
            if (client.getGlobalCustNum() == null) {
                client.generateGlobalCustomerNumber();
            }
            client.generateSearchId();
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            if (client.getParentCustomer() != null) {
                customerDao.save(client.getParentCustomer());
            }
            /* activate client */
            if (finalStatus == CustomerStatus.CLIENT_ACTIVE) {
                hibernateTransactionHelper.flushSession();
                hibernateTransactionHelper.beginAuditLoggingFor(client);
                client.clearCustomerFlagsIfApplicable(client.getStatus(), finalStatus);
                client.updateCustomerStatus(finalStatus);
                // changeStatus(client, oldStatus, newStatus);
                if (client.getParentCustomer() != null) {
                    CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
                    client.addCustomerHierarchy(hierarchy);
                }
                if (client.getCustomerActivationDate() != null) {
                    client.setCustomerActivationDate(client.getCustomerActivationDate());
                } else {
                    client.setCustomerActivationDate(dateTimeService.getCurrentJavaDateTime());
                }
                customerAccount.createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(client, accountFees, meeting, applicableCalendarEvents, new DateTime(client.getCustomerActivationDate()));
                customerDao.save(client);
            }
        }
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception ex) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    }
    return parsedClientsDto;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Address(org.mifos.framework.business.util.Address) NewClientDto(org.mifos.customers.client.util.helpers.NewClientDto) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientNameDetailEntity(org.mifos.customers.client.business.ClientNameDetailEntity) ClientDetailEntity(org.mifos.customers.client.business.ClientDetailEntity) CustomerBO(org.mifos.customers.business.CustomerBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) UserContext(org.mifos.security.util.UserContext) CalendarEvent(org.mifos.calendar.CalendarEvent) MifosUser(org.mifos.security.MifosUser) AddressDto(org.mifos.dto.domain.AddressDto) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingDto(org.mifos.dto.domain.MeetingDto) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) ImportedClientDetail(org.mifos.dto.domain.ImportedClientDetail) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 9 with OfficeBO

use of org.mifos.customers.office.business.OfficeBO in project head by mifos.

the class OfficeListTag method getAboveBranches.

void getAboveBranches(XmlBuilder html, List<OfficeBO> officeList, String regional, String subregional, String area) {
    if (null != officeList) {
        XmlBuilder regionalHtml = null;
        XmlBuilder subregionalHtml = null;
        XmlBuilder areaHtml = null;
        for (int i = 0; i < officeList.size(); i++) {
            OfficeBO office = officeList.get(i);
            if (office.getOfficeLevel() == OfficeLevel.HEADOFFICE) {
                html.singleTag("br");
                html.startTag("span", "class", "fontnormalbold");
                html.append(getLink(office.getOfficeId(), office.getOfficeName()));
                html.singleTag("br");
                html.endTag("span");
            } else if (office.getOfficeLevel() == OfficeLevel.REGIONALOFFICE) {
                regionalHtml = processOffice(regionalHtml, office, regional);
            } else if (office.getOfficeLevel() == OfficeLevel.SUBREGIONALOFFICE) {
                subregionalHtml = processOffice(subregionalHtml, office, subregional);
            } else if (office.getOfficeLevel() == OfficeLevel.AREAOFFICE) {
                areaHtml = processOffice(areaHtml, office, area);
            }
        }
        outputLevel(html, regionalHtml);
        outputLevel(html, subregionalHtml);
        outputLevel(html, areaHtml);
    }
}
Also used : OfficeBO(org.mifos.customers.office.business.OfficeBO) XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder)

Example 10 with OfficeBO

use of org.mifos.customers.office.business.OfficeBO in project head by mifos.

the class SavingsBO method save.

/**
     * @deprecated use {@link SavingsDao#save(SavingsBO)} to persist savings account.
     */
@Deprecated
public void save() throws AccountException {
    logger.info("In SavingsBO::save(), Before Saving , accountId: " + getAccountId());
    try {
        this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), this.getAccountState(), getPersonnelPersistence().getPersonnel(userContext.getId()), this));
        getSavingsPersistence().createOrUpdate(this);
        OfficeBO branch = getSavingsPersistence().getPersistentObject(OfficeBO.class, userContext.getBranchId());
        this.globalAccountNum = generateId(branch.getGlobalOfficeNum());
        getSavingsPersistence().createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
    logger.info("In SavingsBO::save(), Successfully saved , accountId: " + getAccountId());
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Aggregations

OfficeBO (org.mifos.customers.office.business.OfficeBO)115 Test (org.junit.Test)62 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)45 DateTime (org.joda.time.DateTime)33 ArrayList (java.util.ArrayList)31 MeetingBO (org.mifos.application.meeting.business.MeetingBO)28 UserContext (org.mifos.security.util.UserContext)25 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)23 CenterBO (org.mifos.customers.center.business.CenterBO)21 CenterBuilder (org.mifos.domain.builders.CenterBuilder)21 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)19 MifosUser (org.mifos.security.MifosUser)18 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)17 Address (org.mifos.framework.business.util.Address)17 GroupBO (org.mifos.customers.group.business.GroupBO)16 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)14 ClientBO (org.mifos.customers.client.business.ClientBO)14 GroupBuilder (org.mifos.domain.builders.GroupBuilder)14 AddressDto (org.mifos.dto.domain.AddressDto)13