Search in sources :

Example 26 with RepaymentScheduleInstallment

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

the class LoanServiceFacadeWebTierTest method shouldValidateForRepaymentCapacity.

@Ignore
@Test
public void shouldValidateForRepaymentCapacity() {
    CashFlowDetail cashFlowDetail = new CashFlowDetail(Collections.EMPTY_LIST);
    BigDecimal loanAmount = new BigDecimal(1000);
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, loanAmount, 10d);
    cashFlowForm.setTotalExpenses(BigDecimal.valueOf(76));
    cashFlowForm.setTotalRevenues(BigDecimal.valueOf(55).add(loanAmount));
    RepaymentScheduleInstallment installment1 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").build();
    RepaymentScheduleInstallment installment2 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("20").build();
    RepaymentScheduleInstallment installment3 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("30").build();
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3);
    // calcuated repayment capacity is 3298.33
    Errors errors;
//        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1600d);
//        assertThat(errors.hasErrorEntryWithCode(AccountConstants.REPAYMENT_CAPACITY_LESS_THAN_ALLOWED), is(false));
//        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 3300d);
//        assertThat(errors.hasErrorEntryWithCode(AccountConstants.REPAYMENT_CAPACITY_LESS_THAN_ALLOWED), is(true));
}
Also used : Money(org.mifos.framework.util.helpers.Money) Errors(org.mifos.platform.validations.Errors) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) CashFlowForm(org.mifos.platform.cashflow.ui.model.CashFlowForm) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with RepaymentScheduleInstallment

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

the class LoanServiceFacadeWebTierTest method retrieveOriginalLoanSchedule.

@Test
public void retrieveOriginalLoanSchedule() throws PersistenceException {
    Integer accountId = new Integer(1);
    List<OriginalLoanScheduleEntity> loanScheduleEntities = new ArrayList<OriginalLoanScheduleEntity>();
    OriginalLoanScheduleEntity originalLoanScheduleEntity1 = mock(OriginalLoanScheduleEntity.class);
    OriginalLoanScheduleEntity originalLoanScheduleEntity2 = mock(OriginalLoanScheduleEntity.class);
    loanScheduleEntities.add(originalLoanScheduleEntity1);
    loanScheduleEntities.add(originalLoanScheduleEntity2);
    RepaymentScheduleInstallment installment1 = new RepaymentScheduleInstallment();
    RepaymentScheduleInstallment installment2 = new RepaymentScheduleInstallment();
    when(originalLoanScheduleEntity1.toDto()).thenReturn(installment1);
    when(originalLoanScheduleEntity2.toDto()).thenReturn(installment2);
    List<RepaymentScheduleInstallment> expected = new ArrayList<RepaymentScheduleInstallment>();
    expected.add(installment1);
    expected.add(installment2);
    Date date = new Date();
    when(loanBO.getDisbursementDate()).thenReturn(date);
    Money money = new Money(rupee, "4.9");
    when(loanBO.getLoanAmount()).thenReturn(money);
    when(loanBusinessService.retrieveOriginalLoanSchedule(accountId)).thenReturn(loanScheduleEntities);
    when(loanDao.findById(accountId)).thenReturn(loanBO);
    OriginalScheduleInfoDto expectedOriginalScheduleInfoDto = new OriginalScheduleInfoDto(money.toString(), date, expected);
    OriginalScheduleInfoDto originalScheduleInfoDto = loanServiceFacade.retrieveOriginalLoanSchedule(accountId);
    assertThat(originalScheduleInfoDto, is(new OriginalScheduleInfoDtoMatcher(expectedOriginalScheduleInfoDto)));
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDtoMatcher(org.mifos.accounts.loan.business.matchers.OriginalScheduleInfoDtoMatcher) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 28 with RepaymentScheduleInstallment

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

the class InstallmentsValidatorImpl method validateInstallmentFormat.

private void validateInstallmentFormat(List<RepaymentScheduleInstallment> installments, Errors errors) {
    for (RepaymentScheduleInstallment installment : installments) {
        errors.addErrors(installmentFormatValidator.validateTotalAmountFormat(installment));
        errors.addErrors(installmentFormatValidator.validateDueDateFormat(installment));
    }
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)

Example 29 with RepaymentScheduleInstallment

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

the class ListOfInstallmentsValidatorImpl method getDueDateInstallmentsLookup.

private Map<Date, List<String>> getDueDateInstallmentsLookup(List<RepaymentScheduleInstallment> installments) {
    Map<Date, List<String>> dateInstallmentsLookup = new LinkedHashMap<Date, List<String>>();
    for (RepaymentScheduleInstallment installment : installments) {
        Date key = installment.getDueDateValue();
        String value = installment.getInstallmentNumberAsString();
        CollectionUtils.addKeyValue(dateInstallmentsLookup, key, value);
    }
    return dateInstallmentsLookup;
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with RepaymentScheduleInstallment

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

the class LoanBO method updateInstallmentSchedule.

public void updateInstallmentSchedule(List<RepaymentScheduleInstallment> installments) {
    Map<Integer, LoanScheduleEntity> loanScheduleEntityLookUp = getLoanScheduleEntityMap();
    for (RepaymentScheduleInstallment installment : installments) {
        LoanScheduleEntity loanScheduleEntity = loanScheduleEntityLookUp.get(installment.getInstallment());
        loanScheduleEntity.setPrincipal(installment.getPrincipal());
        loanScheduleEntity.setInterest(installment.getInterest());
        loanScheduleEntity.setActionDate(new java.sql.Date(installment.getDueDateValue().getTime()));
    }
    updateLoanSummary();
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)

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