Search in sources :

Example 1 with ClientPerformanceHistoryDto

use of org.mifos.dto.screen.ClientPerformanceHistoryDto 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 2 with ClientPerformanceHistoryDto

use of org.mifos.dto.screen.ClientPerformanceHistoryDto in project head by mifos.

the class ClientServiceFacadeWebTier method assembleClientPerformanceHistoryDto.

private ClientPerformanceHistoryDto assembleClientPerformanceHistoryDto(ClientPerformanceHistoryEntity clientPerformanceHistory, Integer clientId) {
    Integer loanCycleNumber = clientPerformanceHistory.getLoanCycleNumber();
    Money lastLoanAmount = clientPerformanceHistory.getLastLoanAmount();
    Integer noOfActiveLoans = clientPerformanceHistory.getNoOfActiveLoans();
    String delinquentPortfolioAmountString;
    try {
        Money delinquentPortfolioAmount = clientPerformanceHistory.getDelinquentPortfolioAmount();
        delinquentPortfolioAmountString = delinquentPortfolioAmount.toString();
    } catch (CurrencyMismatchException e) {
        delinquentPortfolioAmountString = localizedMessageLookup("errors.multipleCurrencies");
    }
    // TODO currency mismatch check
    Money totalSavingsAmount = clientPerformanceHistory.getTotalSavingsAmount();
    Integer meetingsAttended = this.customerDao.numberOfMeetings(true, clientId).getMeetingsAttended();
    Integer meetingsMissed = customerDao.numberOfMeetings(false, clientId).getMeetingsMissed();
    List<LoanCycleCounter> loanCycleCounters = this.customerDao.fetchLoanCycleCounter(clientId, CustomerLevel.CLIENT.getValue());
    return new ClientPerformanceHistoryDto(loanCycleNumber, lastLoanAmount.toString(), noOfActiveLoans, delinquentPortfolioAmountString, totalSavingsAmount.toString(), meetingsAttended, meetingsMissed, loanCycleCounters);
}
Also used : Money(org.mifos.framework.util.helpers.Money) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ClientPerformanceHistoryDto(org.mifos.dto.screen.ClientPerformanceHistoryDto) LoanCycleCounter(org.mifos.dto.screen.LoanCycleCounter)

Aggregations

ClientPerformanceHistoryDto (org.mifos.dto.screen.ClientPerformanceHistoryDto)2 ArrayList (java.util.ArrayList)1 AccountBO (org.mifos.accounts.business.AccountBO)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 GuarantyEntity (org.mifos.accounts.loan.business.GuarantyEntity)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 CurrencyMismatchException (org.mifos.core.CurrencyMismatchException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 CustomerAccountSummaryDto (org.mifos.dto.domain.CustomerAccountSummaryDto)1 CustomerAddressDto (org.mifos.dto.domain.CustomerAddressDto)1 CustomerFlagDto (org.mifos.dto.domain.CustomerFlagDto)1 CustomerMeetingDto (org.mifos.dto.domain.CustomerMeetingDto)1 CustomerNoteDto (org.mifos.dto.domain.CustomerNoteDto)1 LoanDetailDto (org.mifos.dto.domain.LoanDetailDto)1 SavingsDetailDto (org.mifos.dto.domain.SavingsDetailDto)1 SurveyDto (org.mifos.dto.domain.SurveyDto)1 ClientDisplayDto (org.mifos.dto.screen.ClientDisplayDto)1 ClientInformationDto (org.mifos.dto.screen.ClientInformationDto)1 LoanCycleCounter (org.mifos.dto.screen.LoanCycleCounter)1