Search in sources :

Example 41 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ClientServiceFacadeWebTier method getClientInformationDto.

@Override
public ClientInformationDto getClientInformationDto(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client = customerDao.findClientBySystemId(globalCustNum);
    if (client == null) {
        throw new MifosRuntimeException("Client not found for globalCustNum, levelId: " + globalCustNum);
    }
    try {
        personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    ClientDisplayDto clientDisplay = this.customerDao.getClientDisplayDto(client.getCustomerId(), userContext);
    Integer clientId = client.getCustomerId();
    CustomerAccountSummaryDto customerAccountSummary = this.customerDao.getCustomerAccountSummaryDto(clientId);
    ClientPerformanceHistoryDto clientPerformanceHistory = assembleClientPerformanceHistoryDto(client.getClientPerformanceHistory(), clientId);
    CustomerAddressDto clientAddress = this.customerDao.getCustomerAddressDto(client);
    List<CustomerNoteDto> recentCustomerNotes = customerDao.getRecentCustomerNoteDto(clientId);
    List<CustomerFlagDto> customerFlags = customerDao.getCustomerFlagDto(client.getCustomerFlags());
    List<LoanDetailDto> loanDetail = customerDao.getLoanDetailDto(client.getOpenLoanAccounts());
    List<LoanDetailDto> groupLoanDetail = customerDao.getLoanDetailDto(client.getOpenGroupLoanAccounts());
    List<SavingsDetailDto> savingsDetail = customerDao.getSavingsDetailDto(clientId, userContext);
    CustomerMeetingDto customerMeeting = customerDao.getCustomerMeetingDto(client.getCustomerMeeting(), userContext);
    List<AccountBO> allClosedLoanAndSavingsAccounts = customerDao.retrieveAllClosedLoanAndSavingsAccounts(clientId);
    List<LoanDetailDto> closedLoanAccounts = new ArrayList<LoanDetailDto>();
    List<SavingsDetailDto> closedSavingsAccounts = new ArrayList<SavingsDetailDto>();
    for (AccountBO closedAccount : allClosedLoanAndSavingsAccounts) {
        if (closedAccount.getAccountType().getAccountTypeId() == AccountTypes.LOAN_ACCOUNT.getValue().intValue()) {
            closedLoanAccounts.add(new LoanDetailDto(closedAccount.getGlobalAccountNum(), ((LoanBO) closedAccount).getLoanOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((LoanBO) closedAccount).getLoanSummary().getOutstandingBalance().toString(), closedAccount.getTotalAmountDue().toString(), closedAccount.getTotalAmountInArrears().toString()));
        } else {
            closedSavingsAccounts.add(new SavingsDetailDto(closedAccount.getGlobalAccountNum(), ((SavingsBO) closedAccount).getSavingsOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((SavingsBO) closedAccount).getSavingsBalance().toString()));
        }
    }
    Boolean activeSurveys = Boolean.FALSE;
    //        Boolean activeSurveys = new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.CLIENT);
    List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();
    List<LoanDetailDto> guarantedLoanAccounts = new ArrayList<LoanDetailDto>();
    try {
        List<GuarantyEntity> guaranties = legacyAccountDao.getGuarantyByGurantorId(clientId);
        if (guaranties != null && guaranties.size() > 0) {
            for (GuarantyEntity guaranty : guaranties) {
                if (guaranty != null && guaranty.getState() != null && guaranty.getState()) {
                    LoanBO loan = loanDao.findById(guaranty.getLoanId());
                    guarantedLoanAccounts.add(new LoanDetailDto(loan.getGlobalAccountNum(), loan.getLoanOffering().getPrdOfferingName(), loan.getAccountState().getId(), loan.getAccountState().getName(), loan.getLoanSummary().getOutstandingBalance().toString(), loan.getTotalAmountDue().toString(), loan.getAccountType().getAccountTypeId(), loan.getTotalAmountInArrears().toString()));
                }
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException("Can not get guaranted loan accounts", e);
    }
    return new ClientInformationDto(clientDisplay, customerAccountSummary, clientPerformanceHistory, clientAddress, recentCustomerNotes, customerFlags, loanDetail, groupLoanDetail, savingsDetail, customerMeeting, activeSurveys, customerSurveys, closedLoanAccounts, closedSavingsAccounts, guarantedLoanAccounts);
}
Also used : CustomerAccountSummaryDto(org.mifos.dto.domain.CustomerAccountSummaryDto) SurveyDto(org.mifos.dto.domain.SurveyDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) GuarantyEntity(org.mifos.accounts.loan.business.GuarantyEntity) AccountBO(org.mifos.accounts.business.AccountBO) CustomerMeetingDto(org.mifos.dto.domain.CustomerMeetingDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) ClientPerformanceHistoryDto(org.mifos.dto.screen.ClientPerformanceHistoryDto) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ClientDisplayDto(org.mifos.dto.screen.ClientDisplayDto) UserContext(org.mifos.security.util.UserContext) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) CustomerFlagDto(org.mifos.dto.domain.CustomerFlagDto) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ClientInformationDto(org.mifos.dto.screen.ClientInformationDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 42 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ClientServiceFacadeWebTier method retrieveMfiInfoForEdit.

@Override
public ClientMfiInfoDto retrieveMfiInfoForEdit(String clientSystemId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client = this.customerDao.findClientBySystemId(clientSystemId);
    String groupDisplayName = "";
    String centerDisplayName = "";
    if (client.getParentCustomer() != null) {
        groupDisplayName = client.getParentCustomer().getDisplayName();
        if (client.getParentCustomer().getParentCustomer() != null) {
            centerDisplayName = client.getParentCustomer().getParentCustomer().getDisplayName();
        }
    }
    List<PersonnelDto> loanOfficersList = new ArrayList<PersonnelDto>();
    if (!client.isClientUnderGroup()) {
        CenterCreation centerCreation = new CenterCreation(client.getOffice().getOfficeId(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        loanOfficersList = this.personnelDao.findActiveLoanOfficersForOffice(centerCreation);
    }
    CustomerDetailDto customerDetail = client.toCustomerDetailDto();
    ClientDetailDto clientDetail = client.toClientDetailDto(ClientRules.isFamilyDetailsRequired());
    return new ClientMfiInfoDto(groupDisplayName, centerDisplayName, loanOfficersList, customerDetail, clientDetail);
}
Also used : UserContext(org.mifos.security.util.UserContext) CenterCreation(org.mifos.dto.domain.CenterCreation) ClientBO(org.mifos.customers.client.business.ClientBO) ClientDetailDto(org.mifos.dto.screen.ClientDetailDto) ArrayList(java.util.ArrayList) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) MifosUser(org.mifos.security.MifosUser) ClientMfiInfoDto(org.mifos.dto.screen.ClientMfiInfoDto)

Example 43 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ClientServiceFacadeWebTier method retrieveFamilyInfoForEdit.

@Override
public ClientFamilyInfoDto retrieveFamilyInfoForEdit(String clientGlobalCustNum) {
    ClientBO client = this.customerDao.findClientBySystemId(clientGlobalCustNum);
    ClientDropdownsDto clientDropdowns = retrieveClientDropdownData();
    ClientRulesDto clientRules = retrieveClientRules();
    CustomerDetailDto customerDetail = client.toCustomerDetailDto();
    ClientDetailDto clientDetail = client.toClientDetailDto(clientRules.isFamilyDetailsRequired());
    List<ClientNameDetailDto> familyMembers = new ArrayList<ClientNameDetailDto>();
    Map<Integer, List<ClientFamilyDetailDto>> clientFamilyDetails = new HashMap<Integer, List<ClientFamilyDetailDto>>();
    int familyMemberCount = 0;
    for (ClientNameDetailEntity clientNameDetailEntity : client.getNameDetailSet()) {
        if (clientNameDetailEntity.isNotClientNameType()) {
            ClientNameDetailDto nameView1 = clientNameDetailEntity.toDto();
            familyMembers.add(nameView1);
            for (ClientFamilyDetailEntity clientFamilyDetailEntity : client.getFamilyDetailSet()) {
                if (clientNameDetailEntity.matchesCustomerId(clientFamilyDetailEntity.getClientName().getCustomerNameId())) {
                    ClientFamilyDetailDto clientFamilyDetail = clientFamilyDetailEntity.toDto();
                    addFamilyDetailsDtoToMap(clientFamilyDetails, familyMemberCount, clientFamilyDetail);
                }
            }
            familyMemberCount++;
        }
    }
    return new ClientFamilyInfoDto(clientDropdowns, customerDetail, clientDetail, familyMembers, clientFamilyDetails);
}
Also used : HashMap(java.util.HashMap) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ClientFamilyDetailDto(org.mifos.dto.screen.ClientFamilyDetailDto) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientNameDetailEntity(org.mifos.customers.client.business.ClientNameDetailEntity) ClientRulesDto(org.mifos.dto.domain.ClientRulesDto) ClientDetailDto(org.mifos.dto.screen.ClientDetailDto) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) ArrayList(java.util.ArrayList) List(java.util.List) ClientDropdownsDto(org.mifos.dto.screen.ClientDropdownsDto) ClientFamilyDetailEntity(org.mifos.customers.client.business.ClientFamilyDetailEntity) ClientFamilyInfoDto(org.mifos.dto.screen.ClientFamilyInfoDto)

Example 44 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ClientServiceFacadeWebTier method removeGroupMembership.

@Override
public void removeGroupMembership(String globalCustNum, Short loanOfficerId, String comment) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(mifosUser);
    ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
    client.updateDetails(userContext);
    PersonnelBO loanOfficer = null;
    if (loanOfficerId != null) {
        loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
    }
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    java.sql.Date commentDate = new DateTimeService().getCurrentJavaSqlDate();
    CustomerNoteEntity accountNotesEntity = new CustomerNoteEntity(comment, commentDate, loggedInUser, client);
    customerService.removeGroupMembership(client, loanOfficer, accountNotesEntity, userContext.getLocaleId());
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 45 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ClientServiceFacadeWebTier method previewClient.

@Override
public ProcessRulesDto previewClient(String governmentId, DateTime dateOfBirth, String clientName, boolean defaultFeeRemoval, Short officeId, Short loanOfficerId) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        boolean clientPendingApprovalStateEnabled = ProcessFlowRules.isClientPendingApprovalStateEnabled();
        boolean governmentIdValidationFailing = false;
        boolean duplicateNameOnClosedClient = false;
        boolean duplicateNameOnBlackListedClient = false;
        boolean governmentIdValidationUnclosedFailing = false;
        boolean duplicateNameOnClient = false;
        List<ClientBO> matchedClients = new ArrayList<ClientBO>();
        List<ClientBO> temp;
        if (defaultFeeRemoval) {
            customerDao.checkPermissionForDefaultFeeRemoval(userContext, officeId, loanOfficerId);
        }
        if (StringUtils.isNotBlank(governmentId)) {
            temp = this.customerDao.validateGovernmentIdForUnclosedClient(governmentId);
            if (temp != null) {
                matchedClients.addAll(temp);
            }
            governmentIdValidationUnclosedFailing = temp != null && temp.size() > 0;
            if (!governmentIdValidationUnclosedFailing) {
                temp = this.customerDao.validateGovernmentIdForClient(governmentId);
                if (temp != null) {
                    matchedClients.addAll(temp);
                }
                governmentIdValidationFailing = temp != null && temp.size() > 0;
            }
        }
        if (!governmentIdValidationFailing && !governmentIdValidationUnclosedFailing) {
            temp = this.customerDao.validateForBlackListedClientsOnNameAndDob(clientName, dateOfBirth);
            if (temp != null) {
                matchedClients.addAll(temp);
            }
            duplicateNameOnBlackListedClient = temp != null && temp.size() > 0;
            if (!duplicateNameOnBlackListedClient) {
                temp = this.customerDao.validateForClosedClientsOnNameAndDob(clientName, dateOfBirth);
                if (temp != null) {
                    matchedClients.addAll(temp);
                }
                duplicateNameOnClosedClient = temp != null && temp.size() > 0;
                if (!duplicateNameOnClosedClient) {
                    temp = this.customerDao.validateForClientsOnName(clientName);
                    if (temp != null) {
                        matchedClients.addAll(temp);
                    }
                    duplicateNameOnClient = temp != null && temp.size() > 0;
                }
            }
        }
        List<MatchedClientDto> matched = new ArrayList<MatchedClientDto>();
        for (ClientBO client : matchedClients) {
            matched.add(new MatchedClientDto(client.getGlobalCustNum(), client.getDisplayName(), client.getAddress().getPhoneNumber(), client.getGovernmentId(), client.getDisplayAddress(), client.getOffice().getOfficeName(), client.getOffice().getGlobalOfficeNum()));
        }
        return new ProcessRulesDto(clientPendingApprovalStateEnabled, governmentIdValidationFailing, duplicateNameOnClosedClient, duplicateNameOnBlackListedClient, governmentIdValidationUnclosedFailing, duplicateNameOnClient, matched);
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : ProcessRulesDto(org.mifos.dto.domain.ProcessRulesDto) CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MatchedClientDto(org.mifos.dto.domain.MatchedClientDto) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser)

Aggregations

ClientBO (org.mifos.customers.client.business.ClientBO)93 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 CustomerException (org.mifos.customers.exceptions.CustomerException)25 CustomerBO (org.mifos.customers.business.CustomerBO)23 GroupBO (org.mifos.customers.group.business.GroupBO)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 UserContext (org.mifos.security.util.UserContext)21 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 CenterBO (org.mifos.customers.center.business.CenterBO)19 BusinessRuleException (org.mifos.service.BusinessRuleException)17 ClientBuilder (org.mifos.domain.builders.ClientBuilder)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)14 GroupBuilder (org.mifos.domain.builders.GroupBuilder)14 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)14 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)14 Date (java.util.Date)13 DateTime (org.joda.time.DateTime)13 AccountException (org.mifos.accounts.exceptions.AccountException)13