@Override
  public CustomerDetailsDto createNewCenter(
      CenterCreationDetail createCenterDetail, MeetingDto meetingDto) {

    MifosUser user =
        (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());

    String centerName = createCenterDetail.getDisplayName();
    String externalId = createCenterDetail.getExternalId();
    AddressDto addressDto = createCenterDetail.getAddressDto();
    Address centerAddress =
        new Address(
            addressDto.getLine1(),
            addressDto.getLine2(),
            addressDto.getLine3(),
            addressDto.getCity(),
            addressDto.getState(),
            addressDto.getCountry(),
            addressDto.getZip(),
            addressDto.getPhoneNumber());
    PersonnelBO loanOfficer =
        this.personnelDao.findPersonnelById(createCenterDetail.getLoanOfficerId());
    OfficeBO centerOffice = this.officeDao.findOfficeById(createCenterDetail.getOfficeId());

    List<AccountFeesEntity> feesForCustomerAccount =
        createAccountFeeEntities(createCenterDetail.getFeesToApply());

    DateTime mfiJoiningDate = null;
    if (createCenterDetail.getMfiJoiningDate() != null) {
      mfiJoiningDate = createCenterDetail.getMfiJoiningDate().toDateMidnight().toDateTime();
    }

    MeetingBO meeting = new MeetingFactory().create(meetingDto);
    meeting.setUserContext(userContext);

    CenterBO center =
        CenterBO.createNew(
            userContext,
            centerName,
            mfiJoiningDate,
            meeting,
            loanOfficer,
            centerOffice,
            centerAddress,
            externalId,
            new DateMidnight().toDateTime());

    this.customerService.createCenter(center, meeting, feesForCustomerAccount);

    return new CustomerDetailsDto(center.getCustomerId(), center.getGlobalCustNum());
  }
  @Override
  public void initializeCenterStates(String centerGlobalNum) {
    CenterBO center = this.customerDao.findCenterBySystemId(centerGlobalNum);

    try {
      List<ListElement> savingsStatesList = new ArrayList<ListElement>();
      AccountStateMachines.getInstance().initializeCenterStates();

      List<CustomerStatusEntity> statusList =
          AccountStateMachines.getInstance().getCenterStatusList(center.getCustomerStatus());
      for (CustomerStatusEntity customerState : statusList) {
        savingsStatesList.add(
            new ListElement(customerState.getId().intValue(), customerState.getName()));
      }
    } catch (StatesInitializationException e) {
      throw new MifosRuntimeException(e);
    }
  }
  /* (non-Javadoc)
   * @see org.mifos.customers.client.business.service.ClientDetailsServiceFacade#getClientInformationDto(java.lang.String, java.lang.Short)
   */
  @Override
  public CenterInformationDto getCenterInformationDto(String globalCustNum, Short levelId)
      throws ServiceException {
    CenterBO center =
        (CenterBO) getCustomerBusinessService().findBySystemId(globalCustNum, levelId);
    if (center == null) {
      throw new MifosRuntimeException(
          "Client not found for globalCustNum, levelId: " + globalCustNum + "," + levelId);
    }

    CenterPerformanceHistory centerPerformanceHistory =
        customerBusinessService.getCenterPerformanceHistory(
            center.getSearchId(), center.getOffice().getOfficeId());

    CenterInformationDto clientInformationDto =
        new CenterInformationDto(
            centerPerformanceHistory.getNumberOfGroups(),
            centerPerformanceHistory.getNumberOfClients(),
            centerPerformanceHistory.getTotalOutstandingPortfolio(),
            centerPerformanceHistory.getTotalSavings(),
            centerPerformanceHistory.getPortfolioAtRisk(),
            center.getDisplayName());
    return clientInformationDto;
  }
  @Override
  public CenterInformationDto getCenterInformationDto(String globalCustNum) {

    MifosUser user =
        (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    CenterBO center = customerDao.findCenterBySystemId(globalCustNum);
    if (center == null) {
      throw new MifosRuntimeException("Center not found for globalCustNum" + globalCustNum);
    }

    try {
      personnelDao.checkAccessPermission(
          userContext, center.getOfficeId(), center.getLoanOfficerId());
    } catch (AccountException e) {
      throw new MifosRuntimeException("Access denied!", e);
    }

    CenterDisplayDto centerDisplay =
        customerDao.getCenterDisplayDto(center.getCustomerId(), userContext);

    Integer centerId = center.getCustomerId();
    String searchId = center.getSearchId();
    Short branchId = centerDisplay.getBranchId();

    CustomerAccountSummaryDto customerAccountSummary =
        customerDao.getCustomerAccountSummaryDto(centerId);

    CenterPerformanceHistoryDto centerPerformanceHistory =
        customerDao.getCenterPerformanceHistory(searchId, branchId);

    CustomerAddressDto centerAddress = customerDao.getCustomerAddressDto(center);

    List<CustomerDetailDto> groups =
        customerDao.getGroupsOtherThanClosedAndCancelledForGroup(searchId, branchId);

    List<CustomerNoteDto> recentCustomerNotes = customerDao.getRecentCustomerNoteDto(centerId);

    List<CustomerPositionOtherDto> customerPositions =
        customerDao.getCustomerPositionDto(centerId, userContext);

    List<SavingsDetailDto> savingsDetail = customerDao.getSavingsDetailDto(centerId, userContext);

    CustomerMeetingDto customerMeeting =
        customerDao.getCustomerMeetingDto(center.getCustomerMeeting(), userContext);

    Boolean activeSurveys =
        Boolean.FALSE; // new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.CENTER);

    List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();

    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();

    return new CenterInformationDto(
        centerDisplay,
        customerAccountSummary,
        centerPerformanceHistory,
        centerAddress,
        groups,
        recentCustomerNotes,
        customerPositions,
        savingsDetail,
        customerMeeting,
        activeSurveys,
        customerSurveys,
        customFields);
  }