Search in sources :

Example 16 with LoanAccountDetailsDto

use of org.mifos.dto.domain.LoanAccountDetailsDto in project head by mifos.

the class LoanAccountAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanBO loanBOInSession = (LoanBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    LoanBO loanBO = loanBusinessService.findBySystemId(loanBOInSession.getGlobalAccountNum());
    checkVersionMismatch(loanBOInSession.getVersionNo(), loanBO.getVersionNo());
    loanBO.setVersionNo(loanBOInSession.getVersionNo());
    loanBO.setUserContext(getUserContext(request));
    setInitialObjectForAuditLogging(loanBO);
    LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
    CustomerBO customer = loanBO.getCustomer();
    MeetingBO newMeetingForRepaymentDay = null;
    boolean isRepaymentIndepOfMeetingEnabled = configService.isRepaymentIndepOfMeetingEnabled();
    if (isRepaymentIndepOfMeetingEnabled) {
        newMeetingForRepaymentDay = this.createNewMeetingForRepaymentDay(request, loanAccountActionForm, customer);
    }
    loanBO.setExternalId(loanAccountActionForm.getExternalId());
    if ((configService.isGlimEnabled() || configService.isNewGlimEnabled()) && customer.isGroup()) {
        List<LoanAccountDetailsDto> loanAccountDetailsList = getLoanAccountDetailsFromSession(request);
        List<LoanBO> individualLoans = loanDao.findIndividualLoans(Integer.valueOf(loanBO.getAccountId()));
        handleIndividualLoans(loanBO, loanAccountActionForm, isRepaymentIndepOfMeetingEnabled, loanAccountDetailsList, individualLoans, getUserContext(request).getPreferredLocale());
        request.setAttribute(CUSTOMER_ID, loanBO.getCustomer().getCustomerId().toString());
    }
    loanBO.updateLoan(loanAccountActionForm.isInterestDedAtDisbValue(), new Money(loanBO.getCurrency(), loanAccountActionForm.getLoanAmount()), loanAccountActionForm.getInterestDoubleValue(), loanAccountActionForm.getNoOfInstallmentsValue(), loanAccountActionForm.getDisbursementDateValue(getUserContext(request).getPreferredLocale()), loanAccountActionForm.getGracePeriodDurationValue(), loanAccountActionForm.getBusinessActivityIdValue(), loanAccountActionForm.getCollateralNote(), loanAccountActionForm.getCollateralTypeIdValue(), loanAccountActionForm.getCustomFields(), isRepaymentIndepOfMeetingEnabled, newMeetingForRepaymentDay, getFund(loanAccountActionForm));
    loanBOInSession = null;
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loanBO, request);
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) Money(org.mifos.framework.util.helpers.Money) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerBO(org.mifos.customers.business.CustomerBO) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 17 with LoanAccountDetailsDto

use of org.mifos.dto.domain.LoanAccountDetailsDto in project head by mifos.

the class LoanAccountAction method get.

@TransactionDemarcate(saveToken = true)
public ActionForward get(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
    loanAccountActionForm.clearDetailsForLoan();
    String globalAccountNum = request.getParameter(GLOBAL_ACCOUNT_NUM);
    UserContext userContext = getUserContext(request);
    LoanInformationDto loanInformationDto;
    try {
        loanInformationDto = this.loanAccountServiceFacade.retrieveLoanInformation(globalAccountNum);
    } catch (MifosRuntimeException e) {
        if (e.getCause() instanceof ApplicationException) {
            throw (ApplicationException) e.getCause();
        }
        throw e;
    }
    request.getSession().setAttribute("guarantyInformation", loanAccountServiceFacade.handleGuaranties(loanInformationDto));
    final String accountStateNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getAccountStateName());
    SessionUtils.removeThenSetAttribute("accountStateNameLocalised", accountStateNameLocalised, request);
    final String gracePeriodTypeNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getGracePeriodTypeName());
    SessionUtils.removeThenSetAttribute("gracePeriodTypeNameLocalised", gracePeriodTypeNameLocalised, request);
    final String interestTypeNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getInterestTypeName());
    SessionUtils.removeThenSetAttribute("interestTypeNameLocalised", interestTypeNameLocalised, request);
    final Set<String> accountFlagStateEntityNamesLocalised = new HashSet<String>();
    for (String name : loanInformationDto.getAccountFlagNames()) {
        accountFlagStateEntityNamesLocalised.add(ApplicationContextProvider.getBean(MessageLookup.class).lookup(name));
    }
    SessionUtils.setCollectionAttribute("accountFlagNamesLocalised", accountFlagStateEntityNamesLocalised, request);
    SessionUtils.removeAttribute(BUSINESS_KEY, request);
    Integer loanIndividualMonitoringIsEnabled = configurationPersistence.getConfigurationValueInteger(LOAN_INDIVIDUAL_MONITORING_IS_ENABLED);
    if (null != loanIndividualMonitoringIsEnabled && loanIndividualMonitoringIsEnabled.intValue() != 0) {
        SessionUtils.setAttribute(LOAN_INDIVIDUAL_MONITORING_IS_ENABLED, loanIndividualMonitoringIsEnabled.intValue(), request);
    }
    Boolean GroupLoanWithMembers = AccountingRules.isGroupLoanWithMembers();
    if (null != GroupLoanWithMembers && GroupLoanWithMembers != false) {
        SessionUtils.setAttribute("GroupLoanWithMembers", GroupLoanWithMembers.booleanValue(), request);
    }
    List<ValueListElement> allLoanPurposes = this.loanProductDao.findAllLoanPurposes();
    //        List<BusinessActivityEntity> loanPurposes = (List<BusinessActivityEntity>)masterDataService.retrieveMasterEntities(MasterConstants.LOAN_PURPOSES, getUserContext(request).getLocaleId());
    SessionUtils.setCollectionAttribute(MasterConstants.BUSINESS_ACTIVITIES, allLoanPurposes, request);
    if ((null != loanIndividualMonitoringIsEnabled && 0 != loanIndividualMonitoringIsEnabled.intValue() || (null != GroupLoanWithMembers && GroupLoanWithMembers != false)) && loanInformationDto.isGroup()) {
        List<LoanAccountDetailsDto> loanAccountDetails = this.loanAccountServiceFacade.retrieveLoanAccountDetails(loanInformationDto);
        addEmptyBuisnessActivities(loanAccountDetails);
        SessionUtils.setCollectionAttribute("loanAccountDetailsView", loanAccountDetails, request);
    }
    SessionUtils.setCollectionAttribute(CUSTOM_FIELDS, new ArrayList<CustomFieldDefinitionEntity>(), request);
    // Retrieve and set into the session all collateral types from the
    // lookup_value_locale table associated with the current user context
    // locale
    SessionUtils.setCollectionAttribute(MasterConstants.COLLATERAL_TYPES, legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES).getCustomValueListElements(), request);
    SessionUtils.setAttribute(AccountConstants.LAST_PAYMENT_ACTION, loanBusinessService.getLastPaymentAction(loanInformationDto.getAccountId()), request);
    SessionUtils.removeThenSetAttribute("loanInformationDto", loanInformationDto, request);
    // inject preferred date
    List<LoanActivityDto> activities = loanInformationDto.getRecentAccountActivity();
    for (LoanActivityDto activity : activities) {
        activity.setUserPrefferedDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), activity.getActionDate().toString()));
    }
    SessionUtils.setCollectionAttribute(RECENTACCOUNTACTIVITIES, activities, request);
    request.setAttribute(CustomerConstants.SURVEY_KEY, loanInformationDto.getAccountSurveys());
    request.setAttribute(CustomerConstants.SURVEY_COUNT, loanInformationDto.getActiveSurveys());
    request.setAttribute(AccountConstants.SURVEY_KEY, loanInformationDto.getAccountSurveys());
    Integer administrativeDocumentsIsEnabled = configurationPersistence.getConfigurationValueInteger(ADMINISTRATIVE_DOCUMENT_IS_ENABLED);
    if (null != administrativeDocumentsIsEnabled && administrativeDocumentsIsEnabled.intValue() == 1) {
        SessionUtils.setCollectionAttribute(AdminDocumentsContants.ADMINISTRATIVEDOCUMENTSLIST, legacyAdminDocumentDao.getAllActiveAdminDocuments(), request);
        SessionUtils.setCollectionAttribute(AdminDocumentsContants.ADMINISTRATIVEDOCUMENTSACCSTATEMIXLIST, legacyAdminDocAccStateMixDao.getAllMixedAdminDocuments(), request);
    }
    List<QuestionGroupInstanceDetail> questions = new ArrayList<QuestionGroupInstanceDetail>();
    QuestionnaireServiceFacade questionnaireServiceFacade = ApplicationContextProvider.getBean(QuestionnaireServiceFacade.class);
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Create", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Approve", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "View", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Disburse", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Close", "Loan"));
    SessionUtils.setCollectionAttribute("questionGroups", questions, request);
    SessionUtils.setCollectionAttribute("personalInformationOrder", informationOrderServiceFacade.getInformationOrder("Loan"), request);
    // John W - temporarily put back because needed in applychargeaction - update
    // keithW - and for recentAccountNotes
    LoanBO loan = getLoan(loanInformationDto.getAccountId());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    LoanAccountAction.setSessionAtributeForGLIM(request, loan);
    setCurrentPageUrl(request, loan);
    setQuestionGroupInstances(request, loan);
    setOverpayments(request, loan);
    List<RepaymentScheduleInstallment> installments = loan.toRepaymentScheduleDto(userContext.getPreferredLocale());
    loanAccountActionForm.initializeInstallments(installments);
    return mapping.findForward(ActionForwards.get_success.toString());
}
Also used : ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) MessageLookup(org.mifos.application.master.MessageLookup) HashSet(java.util.HashSet) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) LoanActivityDto(org.mifos.dto.domain.LoanActivityDto) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) QuestionnaireServiceFacade(org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) ApplicationException(org.mifos.framework.exceptions.ApplicationException) LoanInformationDto(org.mifos.dto.screen.LoanInformationDto) ValueListElement(org.mifos.dto.domain.ValueListElement) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 18 with LoanAccountDetailsDto

use of org.mifos.dto.domain.LoanAccountDetailsDto in project head by mifos.

the class LoanAccountAction method addEmptyBuisnessActivities.

private void addEmptyBuisnessActivities(List<LoanAccountDetailsDto> loanAccountDetails) {
    for (LoanAccountDetailsDto details : loanAccountDetails) {
        if (details.getBusinessActivity() == null || details.getBusinessActivity().equals("")) {
            details.setBusinessActivity("-");
            details.setBusinessActivityName("-");
        }
    }
}
Also used : LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto)

Example 19 with LoanAccountDetailsDto

use of org.mifos.dto.domain.LoanAccountDetailsDto in project head by mifos.

the class LoanAccountAction method populateClientDetailsFromLoan.

List<LoanAccountDetailsDto> populateClientDetailsFromLoan(final List<ClientBO> activeClientsUnderGroup, final List<LoanBO> individualLoans, final List<ValueListElement> businessActivities) {
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    for (final ClientBO client : activeClientsUnderGroup) {
        LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
        clientDetail.setClientId(getStringValue(client.getCustomerId()));
        clientDetail.setClientName(client.getDisplayName());
        LoanBO loanAccount = (LoanBO) CollectionUtils.find(individualLoans, new Predicate() {

            @Override
            public boolean evaluate(final Object object) {
                return client.getCustomerId().equals(((LoanBO) object).getCustomer().getCustomerId());
            }
        });
        if (loanAccount != null) {
            final Integer businessActivityId = loanAccount.getBusinessActivityId();
            if (businessActivityId != null) {
                clientDetail.setBusinessActivity(Integer.toString(businessActivityId));
                ValueListElement businessActivityElement = (ValueListElement) CollectionUtils.find(businessActivities, new Predicate() {

                    @Override
                    public boolean evaluate(final Object object) {
                        return ((ValueListElement) object).getId().equals(businessActivityId);
                    }
                });
                if (businessActivityElement != null) {
                    clientDetail.setBusinessActivityName(businessActivityElement.getName());
                }
            }
            clientDetail.setLoanAmount(loanAccount.getLoanAmount() != null ? loanAccount.getLoanAmount().toString() : "0.0");
        }
        clientDetails.add(clientDetail);
    }
    return clientDetails;
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) ValueListElement(org.mifos.dto.domain.ValueListElement) Predicate(org.apache.commons.collections.Predicate)

Example 20 with LoanAccountDetailsDto

use of org.mifos.dto.domain.LoanAccountDetailsDto in project head by mifos.

the class LoanAccountAction method handleIndividualLoans.

void handleIndividualLoans(final LoanBO loanBO, final LoanAccountActionForm loanAccountActionForm, final boolean isRepaymentIndepOfMeetingEnabled, final List<LoanAccountDetailsDto> loanAccountDetailsList, final List<LoanBO> individualLoans, final Locale locale) throws AccountException, ServiceException {
    List<Integer> foundLoans = new ArrayList<Integer>();
    for (final LoanAccountDetailsDto loanAccountDetail : loanAccountDetailsList) {
        Predicate predicateOldGlim = new Predicate() {

            @Override
            public boolean evaluate(final Object object) {
                return ((LoanBO) object).getCustomer().getCustomerId().toString().equals(loanAccountDetail.getClientId());
            }
        };
        LoanBO individualLoan = (LoanBO) CollectionUtils.find(individualLoans, predicateOldGlim);
        if (individualLoan == null) {
        //                glimLoanUpdater.createIndividualLoan(loanAccountActionForm, loanBO, isRepaymentIndepOfMeetingEnabled,
        //                        loanAccountDetail);
        } else {
            foundLoans.add(individualLoan.getAccountId());
            try {
                if (!AccountingRules.isGroupLoanWithMembers() && loanAccountActionForm.getLoanAmount() != null) {
                    loanAccountDetail.setLoanAmount(loanAccountActionForm.getLoanAmountAsBigDecimal().divide(individualLoan.calcFactorOfEntireLoan(), 10, RoundingMode.HALF_UP).toString());
                }
                glimLoanUpdater.updateIndividualLoan(loanAccountActionForm.getDisbursementDateValue(locale), loanAccountActionForm.getInterestDoubleValue(), loanAccountActionForm.getNoOfInstallmentsValue(), loanAccountDetail, individualLoan);
            } catch (InvalidDateException e) {
                e.printStackTrace();
            }
        }
    }
    for (LoanBO loan : individualLoans) {
        if (!foundLoans.contains(loan.getAccountId())) {
            glimLoanUpdater.delete(loan);
        }
    }
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) Predicate(org.apache.commons.collections.Predicate)

Aggregations

LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)24 ArrayList (java.util.ArrayList)13 LoanBO (org.mifos.accounts.loan.business.LoanBO)11 ClientBO (org.mifos.customers.client.business.ClientBO)8 ValueListElement (org.mifos.dto.domain.ValueListElement)8 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)6 CustomerBO (org.mifos.customers.business.CustomerBO)5 MultipleLoanAccountDetailsDto (org.mifos.dto.screen.MultipleLoanAccountDetailsDto)5 MessageLookup (org.mifos.application.master.MessageLookup)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 LoanActivityDto (org.mifos.dto.domain.LoanActivityDto)4 LoanInformationDto (org.mifos.dto.screen.LoanInformationDto)4 HashSet (java.util.HashSet)3 Predicate (org.apache.commons.collections.Predicate)3 LocalDate (org.joda.time.LocalDate)3 Test (org.junit.Test)3 ConfigurationBusinessService (org.mifos.config.business.service.ConfigurationBusinessService)3 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)3 Locale (java.util.Locale)2 LoanBusinessService (org.mifos.accounts.loan.business.service.LoanBusinessService)2