Search in sources :

Example 11 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowController method retrieveCashFlowForm.

public CashFlowForm retrieveCashFlowForm(CashFlowDto cashFlowSettings) {
    CashFlowBoundary cashFlowBoundary = cashFlowService.getCashFlowBoundary(cashFlowSettings.getFirstInstallmentDueDate(), cashFlowSettings.getLastInstallmentDueDate());
    CashFlowDetail cashFlowDetail = cashFlowService.cashFlowFor(cashFlowBoundary.getStartYear(), cashFlowBoundary.getStartMonth(), cashFlowBoundary.getNumberOfMonths());
    return new CashFlowForm(cashFlowDetail, cashFlowSettings.isCaptureCapitalLiabilityInfo(), cashFlowSettings.getLoanAmount(), cashFlowSettings.getIndebtednessRatio());
}
Also used : CashFlowBoundary(org.mifos.platform.cashflow.service.CashFlowBoundary) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) CashFlowForm(org.mifos.platform.cashflow.ui.model.CashFlowForm) MonthlyCashFlowForm(org.mifos.platform.cashflow.ui.model.MonthlyCashFlowForm)

Example 12 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class LoanServiceFacadeWebTierTest method shouldValidateForInstallmentDateBeyondCashFlowData.

@Ignore
@Test
public void shouldValidateForInstallmentDateBeyondCashFlowData() {
    ArrayList<MonthlyCashFlowDetail> monthlyCashFlows = new ArrayList<MonthlyCashFlowDetail>();
    DateTime dateTime = new DateTime().withDate(2010, 10, 30);
    monthlyCashFlows.add(new MonthlyCashFlowDetail(dateTime, new BigDecimal(123), new BigDecimal(234), ""));
    monthlyCashFlows.add(new MonthlyCashFlowDetail(dateTime.plusMonths(1), new BigDecimal(123), new BigDecimal(234), ""));
    monthlyCashFlows.add(new MonthlyCashFlowDetail(dateTime.plusMonths(2), new BigDecimal(123), new BigDecimal(234), ""));
    CashFlowDetail cashFlowDetail = new CashFlowDetail(monthlyCashFlows);
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
    cashFlowForm.setTotalExpenses(BigDecimal.valueOf(76));
    cashFlowForm.setTotalRevenues(BigDecimal.valueOf(55));
    RepaymentScheduleInstallment installment = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").withDueDateValue("30-Nov-2010").build();
    RepaymentScheduleInstallment installmentBeforeCashFlowDate = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").withDueDateValue("30-Nov-2010").build();
    List<RepaymentScheduleInstallment> installments = asList(installment);
    Errors errors;
    //        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1600d);
    //        assertThat(errors.hasErrorEntryWithCode(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE), is(false));
    RepaymentScheduleInstallment installmentBeyondCashFlowDate = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").withDueDateValue("30-Jan-2011").build();
    installments = asList(installmentBeyondCashFlowDate);
//        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1600d);
//        assertThat(errors.hasErrorEntryWithCode(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE), is(true));
//        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1700d);
//        assertThat(errors.hasErrorEntryWithCode(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE), 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) ArrayList(java.util.ArrayList) CashFlowForm(org.mifos.platform.cashflow.ui.model.CashFlowForm) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowValidatorTest method indebtednessRateCalculationShouldNotThrowAnyExceptionsOnUnterminatedDecimalPlaceCalculation.

@Test
public void indebtednessRateCalculationShouldNotThrowAnyExceptionsOnUnterminatedDecimalPlaceCalculation() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(33d));
    cashFlowDetail.setTotalLiability(new BigDecimal(5d));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, true, new BigDecimal(1000d), 1000d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(validationContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(CashFlowConstants.INDEBTEDNESS_RATIO_MORE_THAN_ALLOWED)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 14 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowValidatorTest method validateCaptureCashFlowWhenTotalCapitalAndTotalLiabilityIsNegative.

@Test
public void validateCaptureCashFlowWhenTotalCapitalAndTotalLiabilityIsNegative() throws Exception {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(-23));
    cashFlowDetail.setTotalLiability(new BigDecimal(-1));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, true, null, 0d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(validationContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(CashFlowConstants.TOTAL_CAPITAL_SHOULD_BE_GREATER_THAN_ZERO)));
    verify(messageContext).addMessage(argThat(new MessageMatcher(CashFlowConstants.TOTAL_LIABILITY_SHOULD_BE_NON_NEGATIVE)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 15 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowValidatorTest method cumulativeCashFlowShouldBeGreaterThanZero.

@Test
public void cumulativeCashFlowShouldBeGreaterThanZero() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(false);
    DateTime may = new DateTime(2001, 5, 12, 0, 0, 0, 0);
    DateTime june = new DateTime(2001, 6, 12, 0, 0, 0, 0);
    DateTime july = new DateTime(2001, 7, 12, 0, 0, 0, 0);
    MonthlyCashFlowDetail cashFlowDetail1 = new MonthlyCashFlowDetail(may, new BigDecimal(12), new BigDecimal(13), "notes");
    MonthlyCashFlowDetail cashFlowDetail2 = new MonthlyCashFlowDetail(june, new BigDecimal(120), new BigDecimal(12), "notes");
    MonthlyCashFlowDetail cashFlowDetail3 = new MonthlyCashFlowDetail(july, new BigDecimal(1), new BigDecimal(108), "notes");
    CashFlowDetail cashFlowDetail = new CashFlowDetail(asList(cashFlowDetail1, cashFlowDetail2, cashFlowDetail3));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
    assertEquals(new BigDecimal("-1"), cashFlowForm.getMonthlyCashFlows().get(0).getCumulativeCashFlow());
    assertEquals(new BigDecimal("107"), cashFlowForm.getMonthlyCashFlows().get(1).getCumulativeCashFlow());
    assertEquals(new BigDecimal("0"), cashFlowForm.getMonthlyCashFlows().get(2).getCumulativeCashFlow());
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(messageContext, times(2)).hasErrorMessages();
    verify(validationContext).getMessageContext();
    verify(messageContext, times(2)).addMessage(argThat(new MessageMatcher(CashFlowConstants.CUMULATIVE_CASH_FLOW_FOR_MONTH_SHOULD_BE_GREATER_THAN_ZERO)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) DateTime(org.joda.time.DateTime) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

CashFlowDetail (org.mifos.platform.cashflow.service.CashFlowDetail)18 Test (org.junit.Test)17 MonthlyCashFlowDetail (org.mifos.platform.cashflow.service.MonthlyCashFlowDetail)17 BigDecimal (java.math.BigDecimal)15 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)7 DateTime (org.joda.time.DateTime)5 CashFlowForm (org.mifos.platform.cashflow.ui.model.CashFlowForm)4 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)2 Money (org.mifos.framework.util.helpers.Money)2 Errors (org.mifos.platform.validations.Errors)2 CashFlowFormMatcher (org.mifos.platform.cashflow.matchers.CashFlowFormMatcher)1 MonthlyCashFlowFormMatcher (org.mifos.platform.cashflow.matchers.MonthlyCashFlowFormMatcher)1 CashFlowBoundary (org.mifos.platform.cashflow.service.CashFlowBoundary)1 MonthlyCashFlowForm (org.mifos.platform.cashflow.ui.model.MonthlyCashFlowForm)1