Search in sources :

Example 21 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class OriginalScheduleInfoHelper method sumRepaymentSchedule.

public static OriginalScheduleInfoDto sumRepaymentSchedule(List<OriginalScheduleInfoDto> originalScheduleInfoDtos) {
    Money sumAmount = new Money(Money.getDefaultCurrency(), new Double(0.0));
    Date disburseDate = null;
    List<RepaymentScheduleInstallment> newRepayments = new ArrayList<RepaymentScheduleInstallment>();
    RepaymentScheduleInstallment sumRepayment = new RepaymentScheduleInstallment();
    for (OriginalScheduleInfoDto dto : originalScheduleInfoDtos) {
        sumRepayment = sumRepayment.init();
        Money dtoAmount = new Money(Money.getDefaultCurrency(), new Double(dto.getLoanAmount()));
        sumAmount = sumAmount.add(dtoAmount);
        for (RepaymentScheduleInstallment scheduleInstallment : dto.getOriginalLoanScheduleInstallment()) {
            sumRepayment.setFees(sumRepayment.getFees().add(scheduleInstallment.getFees()));
            sumRepayment.setMiscFees(sumRepayment.getMiscFees().add(scheduleInstallment.getMiscFees()));
            sumRepayment.setMiscPenalty(sumRepayment.getMiscPenalty().add(scheduleInstallment.getMiscPenalty()));
            sumRepayment.setPrincipal(sumRepayment.getPrincipal().add(scheduleInstallment.getPrincipal()));
            sumRepayment.setInterest(sumRepayment.getInterest().add(scheduleInstallment.getInterest()));
            sumRepayment.setTotalAndTotalValue(sumRepayment.getTotalValue().add(scheduleInstallment.getTotalValue()));
            sumRepayment.setDueDate(scheduleInstallment.getDueDate());
        }
        newRepayments.add(sumRepayment);
        if (null == disburseDate) {
            disburseDate = dto.getDisbursementDate();
        }
    }
    return new OriginalScheduleInfoDto(sumAmount.toString(), disburseDate, newRepayments);
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 22 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanAccountAction method getGroupLoanAccountDetails.

@TransactionDemarcate(saveToken = true)
public ActionForward getGroupLoanAccountDetails(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;
    List<LoanInformationDto> memberloanInformationDtos = new ArrayList<LoanInformationDto>();
    try {
        loanInformationDto = this.loanAccountServiceFacade.retrieveLoanInformation(globalAccountNum);
        for (LoanBO member : loanDao.findByGlobalAccountNum(globalAccountNum).getMemberAccounts()) {
            memberloanInformationDtos.add(this.loanAccountServiceFacade.retrieveLoanInformation(member.getGlobalAccountNum()));
            request.getSession().setAttribute("guarantyInformation", loanAccountServiceFacade.handleGuaranties(this.loanAccountServiceFacade.retrieveLoanInformation(member.getGlobalAccountNum())));
        }
    } catch (MifosRuntimeException e) {
        if (e.getCause() instanceof ApplicationException) {
            throw (ApplicationException) e.getCause();
        }
        throw e;
    }
    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();
    SessionUtils.setCollectionAttribute(MasterConstants.BUSINESS_ACTIVITIES, allLoanPurposes, request);
    if ((null != loanIndividualMonitoringIsEnabled && 0 != loanIndividualMonitoringIsEnabled.intValue() && loanInformationDto.isGroup()) || loanInformationDto.isGroupLoanWithMembersEnabled() || (null != GroupLoanWithMembers && GroupLoanWithMembers != false)) {
        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);
    //loanAccountServiceFacade.putLoanBusinessKeyInSession(globalAccountNum, request);
    List<LoanActivityDto> activities = loanInformationDto.getRecentAccountActivity();
    for (LoanActivityDto activity : activities) {
        activity.setUserPrefferedDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), activity.getActionDate().toString()));
    }
    SessionUtils.removeAttribute(RECENTACCOUNTACTIVITIES, request.getSession());
    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 = questionnaireServiceFacadeLocator.getService(request);
    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);
    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 23 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanBOTest method testCopyInstallmentSchedule.

/**
     * does't work when changing applicatonConfiguration.custom.properties file.
     * Need to pull out static references to AccountingRules in used classes.
     */
@Ignore
@Test
public void testCopyInstallmentSchedule() {
    Money.setDefaultCurrency(rupee);
    LoanBO loanBO = new LoanAccountBuilder().build();
    loanBO.addAccountActionDate(getLoanScheduleEntity(rupee, getDate(23, 10, 2010), "100", "10", "1", Money.zero(rupee)));
    loanBO.addAccountActionDate(getLoanScheduleEntity(rupee, getDate(23, 11, 2010), "100", "10", "2", Money.zero(rupee)));
    loanBO.addAccountActionDate(getLoanScheduleEntity(rupee, getDate(23, 12, 2010), "100", "10", "3", Money.zero(rupee)));
    List<RepaymentScheduleInstallment> installments = new ArrayList<RepaymentScheduleInstallment>();
    installments.add(getRepaymentScheduleInstallment("24-Oct-2010", 1, "123", "12"));
    installments.add(getRepaymentScheduleInstallment("24-Nov-2010", 2, "231", "23"));
    installments.add(getRepaymentScheduleInstallment("24-Dec-2010", 3, "312", "31"));
    loanBO.updateInstallmentSchedule(installments);
    Set<LoanScheduleEntity> loanScheduleEntities = loanBO.getLoanScheduleEntities();
    LoanScheduleEntity[] loanScheduleEntitiesArr = loanScheduleEntities.toArray(new LoanScheduleEntity[loanScheduleEntities.size()]);
    assertLoanScheduleEntity(loanScheduleEntitiesArr[0], "123.0", "12.0", "2010-10-24");
    assertLoanScheduleEntity(loanScheduleEntitiesArr[1], "231.0", "23.0", "2010-11-24");
    assertLoanScheduleEntity(loanScheduleEntitiesArr[2], "312.0", "31.0", "2010-12-24");
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) LoanAccountBuilder(org.mifos.domain.builders.LoanAccountBuilder) ArrayList(java.util.ArrayList) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanBOTest method testLoanSummaryShouldBeUpdateOnInstallmentScheduleUpdate.

/**
     * does't work when changing applicatonConfiguration.custom.properties file.
     * Need to pull out static references to AccountingRules in used classes.
     */
@Ignore
@Test
public void testLoanSummaryShouldBeUpdateOnInstallmentScheduleUpdate() {
    Money.setDefaultCurrency(rupee);
    LoanBO loanBO = new LoanAccountBuilder().build();
    loanBO.addAccountActionDate(getLoanScheduleEntity(rupee, getDate(23, 10, 2010), "100", "10", "1", Money.zero(rupee)));
    loanBO.addAccountActionDate(getLoanScheduleEntity(rupee, getDate(23, 11, 2010), "100", "10", "2", Money.zero(rupee)));
    loanBO.addAccountActionDate(getLoanScheduleEntity(rupee, getDate(23, 12, 2010), "100", "10", "3", Money.zero(rupee)));
    List<RepaymentScheduleInstallment> installments = new ArrayList<RepaymentScheduleInstallment>();
    installments.add(getRepaymentScheduleInstallment("24-Oct-2010", 1, "123", "12"));
    installments.add(getRepaymentScheduleInstallment("24-Nov-2010", 2, "231", "23"));
    installments.add(getRepaymentScheduleInstallment("24-Dec-2010", 3, "312", "31"));
    loanBO.updateInstallmentSchedule(installments);
    Set<LoanScheduleEntity> loanScheduleEntities = loanBO.getLoanScheduleEntities();
    LoanScheduleEntity[] loanScheduleEntitiesArr = loanScheduleEntities.toArray(new LoanScheduleEntity[loanScheduleEntities.size()]);
    assertLoanScheduleEntity(loanScheduleEntitiesArr[0], "123.0", "12.0", "2010-10-24");
    assertLoanScheduleEntity(loanScheduleEntitiesArr[1], "231.0", "23.0", "2010-11-24");
    assertLoanScheduleEntity(loanScheduleEntitiesArr[2], "312.0", "31.0", "2010-12-24");
    LoanSummaryEntity loanSummary = loanBO.getLoanSummary();
    assertEquals("666.0", loanSummary.getOriginalPrincipal().toString());
    assertEquals("66.0", loanSummary.getOriginalInterest().toString());
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) LoanAccountBuilder(org.mifos.domain.builders.LoanAccountBuilder) ArrayList(java.util.ArrayList) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanAccountServiceFacadeWebTierTest method shouldValidateInstallmentSchedule.

@Test
public void shouldValidateInstallmentSchedule() {
    List<RepaymentScheduleInstallment> installments = new ArrayList<RepaymentScheduleInstallment>();
    Errors expectedErrors = new Errors();
    BigDecimal minInstallmentAmount = BigDecimal.ZERO;
    when(installmentsValidator.validateInstallmentSchedule(installments, minInstallmentAmount)).thenReturn(expectedErrors);
    Errors errors = loanAccountServiceFacade.validateInstallmentSchedule(new ArrayList<LoanCreationInstallmentDto>(), minInstallmentAmount);
    assertThat(errors, is(expectedErrors));
    verify(installmentsValidator).validateInstallmentSchedule(installments, minInstallmentAmount);
}
Also used : Errors(org.mifos.platform.validations.Errors) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) ArrayList(java.util.ArrayList) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)66 Test (org.junit.Test)44 Money (org.mifos.framework.util.helpers.Money)34 Date (java.util.Date)27 ArrayList (java.util.ArrayList)19 ErrorEntry (org.mifos.platform.validations.ErrorEntry)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 VariableInstallmentDetailsBO (org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO)7 OriginalScheduleInfoDto (org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto)6 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)6 Errors (org.mifos.platform.validations.Errors)6 MifosCurrency (org.mifos.application.master.business.MifosCurrency)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 BigDecimal (java.math.BigDecimal)4 ActionErrors (org.apache.struts.action.ActionErrors)4 Ignore (org.junit.Ignore)4 HashSet (java.util.HashSet)3 LocalDate (org.joda.time.LocalDate)3 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)3 MessageLookup (org.mifos.application.master.MessageLookup)3