Search in sources :

Example 1 with LoanCreationProductDetailsDto

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

the class LoanAccountServiceFacadeWebTier method retrieveGetProductDetailsForLoanAccountCreation.

@Override
public LoanCreationProductDetailsDto retrieveGetProductDetailsForLoanAccountCreation(final Integer customerId) {
    final CustomerBO customer = this.customerDao.findCustomerById(customerId);
    final CustomerDetailDto customerDetailDto = customer.toCustomerDetailDto();
    // FIXME - keithw - below code is not needed when jsp/struts is removed as this is worked out for enter loan account details step.
    final Date nextMeetingDate = customer.getCustomerAccount().getNextMeetingDate();
    final String recurMonth = customer.getCustomerMeeting().getMeeting().getMeetingDetails().getRecurAfter().toString();
    final boolean isGroup = customer.isGroup();
    final boolean isGlimEnabled = configurationPersistence.isGlimEnabled();
    final boolean isLsimEnabled = configurationPersistence.isRepaymentIndepOfMeetingEnabled();
    final boolean isGroupLoanWithMembersEnabled = AccountingRules.isGroupLoanWithMembers();
    List<PrdOfferingDto> loanProductDtos = retrieveActiveLoanProductsApplicableForCustomer(customer, isLsimEnabled);
    LoanCreationGlimDto loanCreationGlimDto = null;
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    Errors errors = new Errors();
    List<ErrorEntry> errorEntry = new ArrayList<ErrorEntry>();
    if (isGroup && isGlimEnabled && isGroupLoanWithMembersEnabled) {
        String defaultMessage = "New Group Loan option is enabled in configuration file and also GLIM option is enabled in the database. Loan for Group will be created using new Group Loan approach. Please turn off GLIM option in database. If you want to create Loan for Group using old approach, then please disable AccountingRules.GroupLoanWithMembers option in configuration file and restart Mifos.";
        errorEntry.add(new ErrorEntry("createLoanAccount.glim.and.new.glim.are.enabled", "activeClients2", defaultMessage));
        errors.addErrors(errorEntry);
    }
    if (isGroup && (isGlimEnabled || isGroupLoanWithMembersEnabled)) {
        final List<ValueListElement> loanPurposes = loanProductDao.findAllLoanPurposes();
        final List<ClientBO> activeClientsOfGroup = customerDao.findActiveClientsUnderGroup(customer);
        loanCreationGlimDto = new LoanCreationGlimDto(loanPurposes);
        if (activeClientsOfGroup == null || activeClientsOfGroup.size() < 2) {
            errorEntry.clear();
            String defaultMessage = "Group loan is not allowed as there must be at least two active clients within the group when Group loan with individual monitoring (GLIM) is enabled";
            errorEntry.add(new ErrorEntry("createLoanAccount.glim.invalid.less.than.two.active.clients.in.group", "activeClients", defaultMessage));
            errors.addErrors(errorEntry);
            loanProductDtos = new ArrayList<PrdOfferingDto>();
        } else {
            for (ClientBO client : activeClientsOfGroup) {
                LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
                clientDetail.setClientId(client.getCustomerId().toString());
                clientDetail.setClientName(client.getDisplayName());
                clientDetails.add(clientDetail);
            }
        }
    }
    return new LoanCreationProductDetailsDto(loanProductDtos, customerDetailDto, nextMeetingDate, recurMonth, isGroup, isGlimEnabled, loanCreationGlimDto, clientDetails, errors);
}
Also used : LoanCreationGlimDto(org.mifos.dto.screen.LoanCreationGlimDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) MultipleLoanAccountDetailsDto(org.mifos.dto.screen.MultipleLoanAccountDetailsDto) Errors(org.mifos.platform.validations.Errors) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) CustomerBO(org.mifos.customers.business.CustomerBO) PrdOfferingDto(org.mifos.dto.domain.PrdOfferingDto) LoanCreationProductDetailsDto(org.mifos.dto.screen.LoanCreationProductDetailsDto) ValueListElement(org.mifos.dto.domain.ValueListElement)

Example 2 with LoanCreationProductDetailsDto

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

the class LoanAccountController method retrieveLoanProducts.

public LoanCreationProductDetailsDto retrieveLoanProducts(int customerId, org.springframework.binding.message.MessageContext messageContext) {
    LoanCreationProductDetailsDto loanProductDetails = this.loanAccountServiceFacade.retrieveGetProductDetailsForLoanAccountCreation(customerId);
    if (loanProductDetails.getErrors().hasErrors()) {
        List<ErrorEntry> errorList = loanProductDetails.getErrors().getErrorEntries();
        for (int i = 0; i < errorList.size(); i++) {
            MessageBuilder builder = new MessageBuilder().error().source(errorList.get(i).getFieldName()).codes(Arrays.asList(errorList.get(i).getErrorCode()).toArray(new String[1])).defaultText(errorList.get(i).getDefaultMessage());
            messageContext.addMessage(builder.build());
        }
    }
    return loanProductDetails;
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) LoanCreationProductDetailsDto(org.mifos.dto.screen.LoanCreationProductDetailsDto) ErrorEntry(org.mifos.platform.validations.ErrorEntry)

Aggregations

LoanCreationProductDetailsDto (org.mifos.dto.screen.LoanCreationProductDetailsDto)2 ErrorEntry (org.mifos.platform.validations.ErrorEntry)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LocalDate (org.joda.time.LocalDate)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 CustomerDetailDto (org.mifos.dto.domain.CustomerDetailDto)1 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)1 PrdOfferingDto (org.mifos.dto.domain.PrdOfferingDto)1 ValueListElement (org.mifos.dto.domain.ValueListElement)1 LoanCreationGlimDto (org.mifos.dto.screen.LoanCreationGlimDto)1 MultipleLoanAccountDetailsDto (org.mifos.dto.screen.MultipleLoanAccountDetailsDto)1 Errors (org.mifos.platform.validations.Errors)1 MessageBuilder (org.springframework.binding.message.MessageBuilder)1