use of org.mifos.dto.screen.ClientDisplayDto 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);
}
use of org.mifos.dto.screen.ClientDisplayDto in project head by mifos.
the class CustomerDaoHibernate method getClientDisplayDto.
@SuppressWarnings("unchecked")
@Override
public ClientDisplayDto getClientDisplayDto(Integer clientId, UserContext userContext) {
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("CLIENT_ID", clientId);
List<Object[]> queryResult = (List<Object[]>) this.genericDao.executeNamedQuery("getClientDisplayDto", queryParameters);
if (queryResult.size() == 0) {
throw new MifosRuntimeException("Client not found: " + clientId);
}
if (queryResult.size() > 1) {
throw new MifosRuntimeException("Error finding Client id: " + clientId + " - Number found: " + queryResult.size());
}
final Integer customerId = (Integer) queryResult.get(0)[0];
final String globalCustNum = (String) queryResult.get(0)[1];
final String displayName = (String) queryResult.get(0)[2];
final String parentCustomerDisplayName = (String) queryResult.get(0)[3];
final String branchName = (String) queryResult.get(0)[4];
final String externalId = (String) queryResult.get(0)[5];
final String customerFormedByDisplayName = (String) queryResult.get(0)[6];
final Date customerActivationDate = (Date) queryResult.get(0)[7];
final Short customerLevelId = (Short) queryResult.get(0)[8];
final Short customerStatusId = (Short) queryResult.get(0)[9];
final String lookupName = (String) queryResult.get(0)[10];
final Date trainedDate = (Date) queryResult.get(0)[11];
final Date dateOfBirth = (Date) queryResult.get(0)[12];
final String governmentId = (String) queryResult.get(0)[13];
final Short groupFlag = (Short) queryResult.get(0)[14];
final Boolean blackListed = (Boolean) queryResult.get(0)[15];
final Short loanOfficerId = (Short) queryResult.get(0)[16];
final String loanOfficerName = (String) queryResult.get(0)[17];
final String businessActivitiesName = (String) queryResult.get(0)[18];
final String handicappedName = (String) queryResult.get(0)[19];
final String maritalStatusName = (String) queryResult.get(0)[20];
final String citizenshipName = (String) queryResult.get(0)[21];
final String ethnicityName = (String) queryResult.get(0)[22];
final String educationLevelName = (String) queryResult.get(0)[23];
final String povertyStatusName = (String) queryResult.get(0)[24];
final Short numChildren = (Short) queryResult.get(0)[25];
final Integer branchId = (Integer) queryResult.get(0)[26];
Boolean clientUnderGroup = false;
if (groupFlag.compareTo(Short.valueOf("0")) > 0) {
clientUnderGroup = true;
}
final String customerStatusName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupName);
final String businessActivities = ApplicationContextProvider.getBean(MessageLookup.class).lookup(businessActivitiesName);
final String handicapped = ApplicationContextProvider.getBean(MessageLookup.class).lookup(handicappedName);
final String maritalStatus = ApplicationContextProvider.getBean(MessageLookup.class).lookup(maritalStatusName);
final String citizenship = ApplicationContextProvider.getBean(MessageLookup.class).lookup(citizenshipName);
final String ethnicity = ApplicationContextProvider.getBean(MessageLookup.class).lookup(ethnicityName);
final String educationLevel = ApplicationContextProvider.getBean(MessageLookup.class).lookup(educationLevelName);
final String povertyStatus = ApplicationContextProvider.getBean(MessageLookup.class).lookup(povertyStatusName);
String spouseFatherValue = null;
String spouseFatherName = null;
List<ClientFamilyDetailOtherDto> familyDetails = null;
Boolean areFamilyDetailsRequired = ClientRules.isFamilyDetailsRequired();
if (areFamilyDetailsRequired) {
familyDetails = new ArrayList<ClientFamilyDetailOtherDto>();
List<Object[]> familyDetailsQueryResult = (List<Object[]>) this.genericDao.executeNamedQuery("getClientFamilyDetailDto", queryParameters);
for (Object[] familyDetail : familyDetailsQueryResult) {
final String relationshipLookup = (String) familyDetail[0];
final String familyDisplayName = (String) familyDetail[1];
final Date familyDateOfBirth = (Date) familyDetail[2];
final String genderLookup = (String) familyDetail[3];
final String livingStatusLookup = (String) familyDetail[4];
final String relationship = ApplicationContextProvider.getBean(MessageLookup.class).lookup(relationshipLookup);
final String gender = ApplicationContextProvider.getBean(MessageLookup.class).lookup(genderLookup);
final String livingStatus = ApplicationContextProvider.getBean(MessageLookup.class).lookup(livingStatusLookup);
String dateOfBirthAsString = "";
if (familyDateOfBirth != null) {
dateOfBirthAsString = DateUtils.makeDateAsSentFromBrowser(familyDateOfBirth);
}
familyDetails.add(new ClientFamilyDetailOtherDto(relationship, familyDisplayName, familyDateOfBirth, gender, livingStatus, dateOfBirthAsString));
}
} else {
List<Object[]> clientNameDetailsQueryResult = (List<Object[]>) this.genericDao.executeNamedQuery("getClientNameDetailDto", queryParameters);
if (clientNameDetailsQueryResult.size() > 0) {
final String spouseFatherValueLookUp = (String) clientNameDetailsQueryResult.get(0)[0];
spouseFatherName = (String) clientNameDetailsQueryResult.get(0)[1];
spouseFatherValue = ApplicationContextProvider.getBean(MessageLookup.class).lookup(spouseFatherValueLookUp);
}
}
Integer age = null;
if (dateOfBirth != null) {
age = DateUtils.DateDiffInYears(new java.sql.Date(dateOfBirth.getTime()));
}
return new ClientDisplayDto(customerId, globalCustNum, displayName, parentCustomerDisplayName, branchId, branchName, externalId, customerFormedByDisplayName, customerActivationDate, customerLevelId, customerStatusId, customerStatusName, trainedDate, dateOfBirth, governmentId, clientUnderGroup, blackListed, loanOfficerId, loanOfficerName, businessActivities, handicapped, maritalStatus, citizenship, ethnicity, educationLevel, povertyStatus, numChildren, areFamilyDetailsRequired, spouseFatherValue, spouseFatherName, familyDetails, age);
}
Aggregations