Search in sources :

Example 11 with CustomerPositionDto

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

the class CustomerServiceImpl method assembleCustomerPostionsFromDto.

private void assembleCustomerPostionsFromDto(List<CustomerPositionDto> customerPositions, CustomerBO customer) {
    for (CustomerPositionDto positionView : customerPositions) {
        boolean isPositionFound = false;
        for (CustomerPositionEntity positionEntity : customer.getCustomerPositions()) {
            if (positionView.getPositionId().equals(positionEntity.getPosition().getId())) {
                CustomerBO customerInPosition = null;
                if (positionView.getCustomerId() != null) {
                    customerInPosition = customerDao.findCustomerById(positionView.getCustomerId());
                }
                positionEntity.setCustomer(customerInPosition);
                isPositionFound = true;
                break;
            }
        }
        if (!isPositionFound) {
            CustomerBO customerInPosition = null;
            if (positionView.getCustomerId() != null) {
                customerInPosition = customerDao.findCustomerById(positionView.getCustomerId());
            }
            CustomerPositionEntity customerPosition = new CustomerPositionEntity(new PositionEntity(positionView.getPositionId()), customerInPosition, customer);
            customer.addCustomerPosition(customerPosition);
        }
    }
}
Also used : CustomerPositionEntity(org.mifos.customers.business.CustomerPositionEntity) CustomerPositionEntity(org.mifos.customers.business.CustomerPositionEntity) PositionEntity(org.mifos.customers.business.PositionEntity) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 12 with CustomerPositionDto

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

the class CenterServiceFacadeWebTier method generateNewListOfPositions.

private void generateNewListOfPositions(CustomerBO customer, List<PositionEntity> customerPositions, List<CustomerPositionDto> customerPositionDtos) {
    for (PositionEntity position : customerPositions) {
        CustomerPositionDto customerPosition = new CustomerPositionDto(customer.getCustomerId(), position.getId(), position.getName());
        customerPositionDtos.add(customerPosition);
    }
}
Also used : CustomerPositionEntity(org.mifos.customers.business.CustomerPositionEntity) PositionEntity(org.mifos.customers.business.PositionEntity) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 13 with CustomerPositionDto

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

the class CenterServiceFacadeWebTier method retrieveCenterDetailsForUpdate.

@Override
public CenterDto retrieveCenterDetailsForUpdate(Integer centerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO center = customerDao.findCustomerById(centerId);
    Short officeId = center.getOffice().getOfficeId();
    String searchId = center.getSearchId();
    Short loanOfficerId = extractLoanOfficerId(center);
    CenterCreation centerCreation = new CenterCreation(officeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
    List<PersonnelDto> activeLoanOfficersForBranch = personnelDao.findActiveLoanOfficersForOffice(centerCreation);
    List<CustomerDto> customerList = customerDao.findClientsThatAreNotCancelledOrClosed(searchId, officeId);
    List<CustomerPositionDto> customerPositionDtos = generateCustomerPositionViews(center, userContext.getLocaleId());
    DateTime mfiJoiningDate = new DateTime();
    String mfiJoiningDateAsString = "";
    if (center.getMfiJoiningDate() != null) {
        mfiJoiningDate = new DateTime(center.getMfiJoiningDate());
        mfiJoiningDateAsString = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), center.getMfiJoiningDate().toString());
    }
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    return new CenterDto(loanOfficerId, center.getCustomerId(), center.getGlobalCustNum(), mfiJoiningDate, mfiJoiningDateAsString, center.getExternalId(), address, customerPositionDtos, customerList, activeLoanOfficersForBranch, true);
}
Also used : UserContext(org.mifos.security.util.UserContext) 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) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 14 with CustomerPositionDto

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

the class CenterHierarchyCustomerServiceIntegrationTest method updatingCenterWithDifferentLoanOfficerUpdatesAllChildrenInHierarchyIncludingTheirAssociatedLoansSavingsAndCustomerAccounts.

@Test
public void updatingCenterWithDifferentLoanOfficerUpdatesAllChildrenInHierarchyIncludingTheirAssociatedLoansSavingsAndCustomerAccounts() throws Exception {
    // setup
    String externalId = center.getExternalId();
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(center.getMfiJoiningDate());
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), otherLoanOfficer.getPersonnelId(), externalId, mfiJoiningDate, address, customFields, customerPositions);
    UserContext userContext = TestUtils.makeUser();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    StaticHibernateUtil.flushAndClearSession();
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    group = customerDao.findGroupBySystemId(group.getGlobalCustNum());
    group2 = customerDao.findGroupBySystemId(group2.getGlobalCustNum());
    assertThat(center.getDisplayName(), is(updatedDisplayName));
    assertThat(center.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
    assertThat(group.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
    assertThat(group2.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 15 with CustomerPositionDto

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

the class CenterUpdateUsingCustomerServiceIntegrationTest method canUpdateCenterWithDifferentMfiJoiningDateInPastOrFuture.

@Test
public void canUpdateCenterWithDifferentMfiJoiningDateInPastOrFuture() throws Exception {
    // setup
    Short loanOfficerId = center.getPersonnel().getPersonnelId();
    String externalId = center.getExternalId();
    LocalDate dateInPast = new LocalDate(center.getMfiJoiningDate()).minusWeeks(4);
    String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(dateInPast.toDateMidnight().toDate());
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
    String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
    CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), loanOfficerId, externalId, mfiJoiningDate, address, customFields, customerPositions);
    UserContext userContext = TestUtils.makeUser();
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
    // verification
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    assertThat(center.getMfiJoiningDate(), is(dateInPast.toDateMidnight().toDate()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) LocalDate(org.joda.time.LocalDate) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

CustomerPositionDto (org.mifos.dto.domain.CustomerPositionDto)15 AddressDto (org.mifos.dto.domain.AddressDto)8 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)8 ArrayList (java.util.ArrayList)7 UserContext (org.mifos.security.util.UserContext)7 SimpleDateFormat (java.text.SimpleDateFormat)6 CenterUpdate (org.mifos.dto.domain.CenterUpdate)6 Test (org.junit.Test)5 CustomerPositionEntity (org.mifos.customers.business.CustomerPositionEntity)5 PositionEntity (org.mifos.customers.business.PositionEntity)5 DateTime (org.joda.time.DateTime)2 LocalDate (org.joda.time.LocalDate)2 CustomerBO (org.mifos.customers.business.CustomerBO)2 ApplicableAccountFeeDto (org.mifos.dto.domain.ApplicableAccountFeeDto)2 CenterCreation (org.mifos.dto.domain.CenterCreation)2 CenterDto (org.mifos.dto.domain.CenterDto)2 CustomerAddressDto (org.mifos.dto.domain.CustomerAddressDto)2 CustomerDto (org.mifos.dto.domain.CustomerDto)2 PersonnelDto (org.mifos.dto.domain.PersonnelDto)2 Address (org.mifos.framework.business.util.Address)2