Search in sources :

Example 1 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class PersonnelServiceFacadeWebTier method getPersonnelInformationDto.

@Override
public PersonnelInformationDto getPersonnelInformationDto(final Long userId, final String globalNumber) {
    PersonnelBO personnel = null;
    if (userId != null) {
        personnel = personnelDao.findPersonnelById(userId.shortValue());
    } else {
        personnel = personnelDao.findByGlobalPersonnelNum(globalNumber);
    }
    if (personnel == null) {
        throw new MifosRuntimeException("personnel not found for id" + userId);
    }
    String displayName = personnel.getDisplayName();
    PersonnelStatusEntity personnelStatus = personnel.getStatus();
    String statusName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(personnelStatus.getLookUpValue());
    ListElement status = new ListElement(new Integer(personnelStatus.getId()), statusName);
    boolean locked = personnel.isLocked();
    PersonnelDetailsEntity personnelDetailsEntity = personnel.getPersonnelDetails();
    Address address = personnelDetailsEntity.getAddress();
    AddressDto addressDto = new AddressDto(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
    Name name = personnelDetailsEntity.getName();
    PersonnelDetailsDto personnelDetails = new PersonnelDetailsDto(personnelDetailsEntity.getGovernmentIdNumber(), new DateTime(personnelDetailsEntity.getDob()).toDateMidnight().toDateTime(), personnelDetailsEntity.getMaritalStatus(), personnelDetailsEntity.getGender(), new DateTime(personnelDetailsEntity.getDateOfJoiningMFI()).toDateMidnight().toDateTime(), new DateTime(personnelDetailsEntity.getDateOfJoiningBranch()).toDateMidnight().toDateTime(), new DateTime(personnelDetailsEntity.getDateOfLeavingBranch()).toDateMidnight().toDateTime(), addressDto, name.getFirstName(), name.getMiddleName(), name.getSecondLastName(), name.getLastName(), new DateTime(personnelDetailsEntity.getPersonnel().getPasswordExpirationDate()).toDateMidnight().toDateTime());
    String emailId = personnel.getEmailId();
    Short preferredLocale = personnel.getPreferredLocale();
    String languageName = Localization.getInstance().getDisplayName(preferredLocale);
    if (preferredLocale != null) {
        languageName = Localization.getInstance().getDisplayName(preferredLocale);
    }
    PersonnelLevelEntity level = personnel.getLevel();
    OfficeBO office = personnel.getOffice();
    Integer title = personnel.getTitle();
    Set<PersonnelRoleEntity> personnelRoleEntities = personnel.getPersonnelRoles();
    Set<ListElement> personnelRoles = new LinkedHashSet<ListElement>();
    for (PersonnelRoleEntity entity : personnelRoleEntities) {
        ListElement element = new ListElement(entity.getRole().getId().intValue(), entity.getRole().getName());
        personnelRoles.add(element);
    }
    Short personnelId = personnel.getPersonnelId();
    String userName = personnel.getUserName();
    Set<PersonnelCustomFieldEntity> personnelCustomFields = personnel.getCustomFields();
    Set<CustomFieldDto> customFields = new LinkedHashSet<CustomFieldDto>();
    for (PersonnelCustomFieldEntity fieldDef : personnelCustomFields) {
        customFields.add(new CustomFieldDto(fieldDef.getFieldId(), fieldDef.getFieldValue()));
    }
    Set<PersonnelNotesEntity> personnelNotesEntity = personnel.getPersonnelNotes();
    Set<PersonnelNoteDto> personnelNotes = new LinkedHashSet<PersonnelNoteDto>();
    for (PersonnelNotesEntity entity : personnelNotesEntity) {
        personnelNotes.add(new PersonnelNoteDto(new DateTime(entity.getCommentDate()), entity.getComment(), entity.getPersonnelName()));
    }
    return new PersonnelInformationDto(personnel.getPersonnelId().intValue(), personnel.getGlobalPersonnelNum(), displayName, status, locked, personnelDetails, emailId, languageName, preferredLocale.intValue(), level.getId(), office.getOfficeId().intValue(), office.getOfficeName(), title, personnelRoles, personnelId, userName, customFields, personnelNotes, personnel.getPasswordExpirationDate());
}
Also used : PersonnelDetailsEntity(org.mifos.customers.personnel.business.PersonnelDetailsEntity) LinkedHashSet(java.util.LinkedHashSet) PersonnelInformationDto(org.mifos.dto.screen.PersonnelInformationDto) Address(org.mifos.framework.business.util.Address) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) DateTime(org.joda.time.DateTime) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) Name(org.mifos.framework.business.util.Name) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelRoleEntity(org.mifos.customers.personnel.business.PersonnelRoleEntity) MessageLookup(org.mifos.application.master.MessageLookup) PersonnelCustomFieldEntity(org.mifos.customers.personnel.business.PersonnelCustomFieldEntity) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) AddressDto(org.mifos.dto.domain.AddressDto) PersonnelNoteDto(org.mifos.dto.screen.PersonnelNoteDto) PersonnelNotesEntity(org.mifos.customers.personnel.business.PersonnelNotesEntity) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) PersonnelDetailsDto(org.mifos.dto.screen.PersonnelDetailsDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with AddressDto

use of org.mifos.dto.domain.AddressDto 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)

Example 3 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class GroupServiceFacadeWebTier method retrieveGroupDetailsForUpdate.

@Override
public CenterDto retrieveGroupDetailsForUpdate(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    List<PersonnelDto> activeLoanOfficersForBranch = new ArrayList<PersonnelDto>();
    GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
    Short officeId = group.getOffice().getOfficeId();
    String searchId = group.getSearchId();
    Short loanOfficerId = extractLoanOfficerId(group);
    boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
    if (!isCenterHierarchyExists) {
        CenterCreation centerCreation = new CenterCreation(officeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        activeLoanOfficersForBranch = personnelDao.findActiveLoanOfficersForOffice(centerCreation);
    }
    List<CustomerDto> customerList = customerDao.findClientsThatAreNotCancelledOrClosed(searchId, officeId);
    List<CustomerPositionDto> customerPositionDtos = generateCustomerPositionViews(group, userContext.getLocaleId());
    DateTime mfiJoiningDate = new DateTime();
    String mfiJoiningDateAsString = "";
    if (group.getMfiJoiningDate() != null) {
        mfiJoiningDate = new DateTime(group.getMfiJoiningDate());
        mfiJoiningDateAsString = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), group.getMfiJoiningDate().toString());
    }
    AddressDto address = null;
    if (group.getAddress() != null) {
        address = Address.toDto(group.getAddress());
    }
    return new CenterDto(loanOfficerId, group.getCustomerId(), group.getGlobalCustNum(), mfiJoiningDate, mfiJoiningDateAsString, group.getExternalId(), address, customerPositionDtos, customerList, activeLoanOfficersForBranch, isCenterHierarchyExists);
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) CustomerDto(org.mifos.dto.domain.CustomerDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) CenterDto(org.mifos.dto.domain.CenterDto) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) DateTime(org.joda.time.DateTime) CenterCreation(org.mifos.dto.domain.CenterCreation) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 4 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class PictureFormFile method updatePersonalInfo.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updatePersonalInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    ClientBO clientInSession = getClientFromSession(request);
    Integer oldClientVersionNumber = clientInSession.getVersionNo();
    Integer customerId = clientInSession.getCustomerId();
    String clientStatus = clientInSession.getCustomerStatus().getName();
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    short loanOfficerId = clientInSession.getCreatedBy();
    final String clientSystemId = clientInSession.getGlobalCustNum();
    ClientPersonalInfoDto clientPersonalInfo = this.clientServiceFacade.retrieveClientPersonalInfoForUpdate(clientSystemId, clientStatus, loanOfficerId);
    AddressDto address = null;
    if (actionForm.getAddress() != null) {
        address = Address.toDto(actionForm.getAddress());
    }
    if (clientPersonalInfo.getCustomerDetail() != null) {
        if (clientPersonalInfo.getCustomerDetail().getAddress() != null) {
            if (clientPersonalInfo.getCustomerDetail().getAddress().getPhoneNumber() != null && (!clientPersonalInfo.getCustomerDetail().getAddress().getPhoneNumber().equals(address.getPhoneNumber()))) {
                UserContext userContext = getUserContext(request);
                if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
                    throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
                }
            } else if (clientPersonalInfo.getCustomerDetail().getAddress().getPhoneNumber() == null && address.getPhoneNumber() != null && !address.getPhoneNumber().equals("")) {
                UserContext userContext = getUserContext(request);
                if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
                    throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
                }
            }
        } else if (address.getPhoneNumber() != null && !address.getPhoneNumber().equals("")) {
            UserContext userContext = getUserContext(request);
            if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
                throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
            }
        }
    } else if (address.getPhoneNumber() != null && !address.getPhoneNumber().equals("")) {
        UserContext userContext = getUserContext(request);
        if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
            throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
        }
    }
    ClientNameDetailDto spouseFather = null;
    if (!ClientRules.isFamilyDetailsRequired()) {
        spouseFather = actionForm.getSpouseName();
    }
    InputStream picture = null;
    if (actionForm.getPicture() != null && StringUtils.isNotBlank(actionForm.getPicture().getFileName())) {
        picture = actionForm.getCustomerPicture();
    }
    ClientNameDetailDto clientNameDetails = actionForm.getClientName();
    ClientPersonalDetailDto clientDetail = actionForm.getClientDetailView();
    String governmentId = actionForm.getGovernmentId();
    String clientDisplayName = actionForm.getClientName().getDisplayName();
    String dateOfBirth = actionForm.getDateOfBirth();
    ClientPersonalInfoUpdate personalInfo = new ClientPersonalInfoUpdate(customerId, oldClientVersionNumber, customFields, address, clientDetail, clientNameDetails, spouseFather, picture, governmentId, clientDisplayName, dateOfBirth);
    this.clientServiceFacade.updateClientPersonalInfo(personalInfo, clientStatus, loanOfficerId);
    return mapping.findForward(ActionForwards.updatePersonalInfo_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientPersonalInfoDto(org.mifos.dto.screen.ClientPersonalInfoDto) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class CenterCustAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    CenterCustActionForm actionForm = (CenterCustActionForm) form;
    MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    LocalDate mfiJoiningDate = new LocalDate(CalendarUtils.getDateFromString(actionForm.getMfiJoiningDate(), getUserContext(request).getPreferredLocale()));
    Address address = actionForm.getAddress();
    AddressDto addressDto = Address.toDto(address);
    MeetingDto meetingDto = meeting.toDto();
    List<CreateAccountFeeDto> accountFeesToBeApplied = new ArrayList<CreateAccountFeeDto>();
    List<ApplicableAccountFeeDto> feesToBeApplied = actionForm.getFeesToApply();
    for (ApplicableAccountFeeDto feeDto : feesToBeApplied) {
        accountFeesToBeApplied.add(new CreateAccountFeeDto(feeDto.getFeeId(), feeDto.getAmount()));
    }
    try {
        CenterCreationDetail centerCreationDetail = new CenterCreationDetail(mfiJoiningDate, actionForm.getDisplayName(), actionForm.getExternalId(), addressDto, actionForm.getLoanOfficerIdValue(), actionForm.getOfficeIdValue(), accountFeesToBeApplied);
        CustomerDetailsDto centerDetails = this.centerServiceFacade.createNewCenter(centerCreationDetail, meetingDto);
        createCenterQuestionnaire.saveResponses(request, actionForm, centerDetails.getId());
        actionForm.setCustomerId(centerDetails.getId().toString());
        actionForm.setGlobalCustNum(centerDetails.getGlobalCustNum());
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e.getMessageValues());
    }
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : CenterCustActionForm(org.mifos.customers.center.struts.actionforms.CenterCustActionForm) Address(org.mifos.framework.business.util.Address) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) LocalDate(org.joda.time.LocalDate) ApplicableAccountFeeDto(org.mifos.dto.domain.ApplicableAccountFeeDto) MeetingDto(org.mifos.dto.domain.MeetingDto) CenterCreationDetail(org.mifos.dto.domain.CenterCreationDetail) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

AddressDto (org.mifos.dto.domain.AddressDto)37 ArrayList (java.util.ArrayList)24 DateTime (org.joda.time.DateTime)16 Address (org.mifos.framework.business.util.Address)16 UserContext (org.mifos.security.util.UserContext)16 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 OfficeBO (org.mifos.customers.office.business.OfficeBO)13 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)12 CustomerDetailsDto (org.mifos.dto.domain.CustomerDetailsDto)11 MeetingDto (org.mifos.dto.domain.MeetingDto)10 MifosUser (org.mifos.security.MifosUser)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 LocalDate (org.joda.time.LocalDate)8 Test (org.junit.Test)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 CustomerPositionDto (org.mifos.dto.domain.CustomerPositionDto)8 CenterUpdate (org.mifos.dto.domain.CenterUpdate)7 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)7 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7