Search in sources :

Example 6 with CustomerStatus

use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.

the class ClientServiceFacadeWebTier method createNewClient.

@Override
public CustomerDetailsDto createNewClient(ClientCreationDetail clientCreationDetail, MeetingDto meetingDto, List<SavingsDetailDto> allowedSavingProducts) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    try {
        ClientBO client = null;
        List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(clientCreationDetail.getFeesToApply());
        List<SavingsOfferingBO> selectedOfferings = new ArrayList<SavingsOfferingBO>();
        for (Short productId : clientCreationDetail.getSelectedSavingProducts()) {
            if (productId != null) {
                for (SavingsDetailDto savingsOffering : allowedSavingProducts) {
                    if (productId.equals(savingsOffering.getPrdOfferingId())) {
                        SavingsOfferingBO savingsProduct = savingsProductDao.findById(productId.intValue());
                        selectedOfferings.add(savingsProduct);
                    }
                }
            }
        }
        List<ClientInitialSavingsOfferingEntity> offeringsAssociatedInCreate = new ArrayList<ClientInitialSavingsOfferingEntity>();
        for (SavingsOfferingBO offering : selectedOfferings) {
            offeringsAssociatedInCreate.add(new ClientInitialSavingsOfferingEntity(null, offering));
        }
        Short personnelId = null;
        Short officeId = null;
        ClientNameDetailDto spouseNameDetailView = null;
        if (ClientRules.isFamilyDetailsRequired()) {
        //                actionForm.setFamilyDateOfBirth();
        //                actionForm.constructFamilyDetails();
        } else {
            spouseNameDetailView = clientCreationDetail.getSpouseFatherName();
        }
        String secondMiddleName = null;
        ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getClientNameDetailDto());
        ClientNameDetailEntity spouseFatherNameDetailEntity = null;
        if (spouseNameDetailView != null) {
            spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, spouseNameDetailView);
        }
        ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
        clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
        DateTime dob = new DateTime(clientCreationDetail.getDateOfBirth());
        boolean trainedBool = clientCreationDetail.isTrained();
        DateTime trainedDateTime = null;
        if (clientCreationDetail.getTrainedDate() != null) {
            trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
        }
        String clientFirstName = clientCreationDetail.getClientNameDetailDto().getFirstName();
        String clientLastName = clientCreationDetail.getClientNameDetailDto().getLastName();
        String secondLastName = clientCreationDetail.getClientNameDetailDto().getSecondLastName();
        CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
        PersonnelBO formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
        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());
        }
        if (YesNoFlag.YES.getValue().equals(clientCreationDetail.getGroupFlag())) {
            Integer parentGroupId = Integer.parseInt(clientCreationDetail.getParentGroupId());
            CustomerBO group = this.customerDao.findCustomerById(parentGroupId);
            if (group.getPersonnel() != null) {
                personnelId = group.getPersonnel().getPersonnelId();
            }
            officeId = group.getOffice().getOfficeId();
            client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), group, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
            if (ClientRules.isFamilyDetailsRequired()) {
                client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
            }
            this.customerService.createClient(client, client.getCustomerMeetingValue(), feesForCustomerAccount, selectedOfferings);
        } else {
            personnelId = clientCreationDetail.getLoanOfficerId();
            officeId = clientCreationDetail.getOfficeId();
            PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(personnelId);
            OfficeBO office = this.officeDao.findOfficeById(officeId);
            int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            MeetingBO clientMeeting = null;
            if (meetingDto != null) {
                clientMeeting = new MeetingFactory().create(meetingDto);
                clientMeeting.setUserContext(userContext);
            }
            client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
            if (ClientRules.isFamilyDetailsRequired()) {
                client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
            }
            try {
                personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
            } catch (AccountException e) {
                throw new MifosRuntimeException("Access denied!", e);
            }
            this.customerService.createClient(client, clientMeeting, feesForCustomerAccount, selectedOfferings);
        }
        clientPhotoService.create(client.getCustomerId().longValue(), clientCreationDetail.getPicture());
        return new CustomerDetailsDto(client.getCustomerId(), client.getGlobalCustNum());
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e.getValues(), e);
    }
}
Also used : Address(org.mifos.framework.business.util.Address) 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) BusinessRuleException(org.mifos.service.BusinessRuleException) 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) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with CustomerStatus

use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.

the class CustomerServiceImpl method updateCustomerStatus.

@Override
public final void updateCustomerStatus(UserContext userContext, CustomerStatusUpdate customerStatusUpdate) throws CustomerException {
    CustomerBO customer = this.customerDao.findCustomerById(customerStatusUpdate.getCustomerId());
    customer.validateVersion(customerStatusUpdate.getVersionNum());
    customer.updateDetails(userContext);
    checkPermission(customer, userContext, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag());
    Short oldStatusId = customer.getCustomerStatus().getId();
    CustomerStatus oldStatus = CustomerStatus.fromInt(oldStatusId);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    CustomerNoteEntity customerNote = new CustomerNoteEntity(customerStatusUpdate.getNotes(), new Date(), loggedInUser, customer);
    if (customer.isGroup()) {
        GroupBO group = (GroupBO) customer;
        updateGroupStatus(group, oldStatus, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
    } else if (customer.isClient()) {
        ClientBO client = (ClientBO) customer;
        updateClientStatus(client, oldStatus, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
    } else {
        CenterBO center = (CenterBO) customer;
        updateCenterStatus(center, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) CenterBO(org.mifos.customers.center.business.CenterBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 8 with CustomerStatus

use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.

the class GroupBO method isActiveForFirstTime.

@Override
public boolean isActiveForFirstTime(final Short oldStatusId, final Short newStatusId) {
    CustomerStatus oldStatus = CustomerStatus.fromInt(oldStatusId);
    CustomerStatus newStatus = CustomerStatus.fromInt(newStatusId);
    return oldStatus.isGroupPartialOrGroupPending() && newStatus.isGroupActive();
}
Also used : CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus)

Example 9 with CustomerStatus

use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.

the class CenterServiceFacadeWebTier method updateCustomerStatus.

@Override
public void updateCustomerStatus(Integer customerId, Integer previousCustomerVersionNo, String flagIdAsString, String newStatusIdAsString, String notes) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    Short flagId = null;
    Short newStatusId = null;
    if (StringUtils.isNotBlank(flagIdAsString)) {
        flagId = Short.valueOf(flagIdAsString);
    }
    if (StringUtils.isNotBlank(newStatusIdAsString)) {
        newStatusId = Short.valueOf(newStatusIdAsString);
    }
    CustomerStatusFlag customerStatusFlag = null;
    if (flagId != null) {
        customerStatusFlag = CustomerStatusFlag.fromInt(flagId);
    }
    CustomerStatus newStatus = CustomerStatus.fromInt(newStatusId);
    CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdate(customerId, previousCustomerVersionNo, customerStatusFlag, newStatus, notes);
    try {
        this.customerService.updateCustomerStatus(userContext, customerStatusUpdate);
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) UserContext(org.mifos.security.util.UserContext) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) MifosUser(org.mifos.security.MifosUser)

Aggregations

CustomerStatus (org.mifos.customers.util.helpers.CustomerStatus)9 CustomerException (org.mifos.customers.exceptions.CustomerException)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)4 MifosUser (org.mifos.security.MifosUser)4 UserContext (org.mifos.security.util.UserContext)4 DateTime (org.joda.time.DateTime)3 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 MeetingFactory (org.mifos.application.meeting.business.MeetingFactory)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 CustomerBO (org.mifos.customers.business.CustomerBO)3 ClientBO (org.mifos.customers.client.business.ClientBO)3 GroupBO (org.mifos.customers.group.business.GroupBO)3 OfficeBO (org.mifos.customers.office.business.OfficeBO)3 AddressDto (org.mifos.dto.domain.AddressDto)3 Address (org.mifos.framework.business.util.Address)3 BusinessRuleException (org.mifos.service.BusinessRuleException)3 ArrayList (java.util.ArrayList)2 AccountException (org.mifos.accounts.exceptions.AccountException)2 CenterBO (org.mifos.customers.center.business.CenterBO)2