Search in sources :

Example 21 with Schedule

use of org.mifos.accounts.loan.schedule.domain.Schedule in project head by mifos.

the class ScheduleCalculatorAdaptorTest method computeExtraInterestAndPopulateInLoanScheduleEntities.

@Test
public void computeExtraInterestAndPopulateInLoanScheduleEntities() {
    List<Installment> installments = getInstallments(0, 0, 0);
    Schedule schedule = new Schedule(DISBURSEMENT_DATE, DAILY_INTEREST_RATE, LOAN_AMOUNT, installments);
    new ScheduleCalculator().computeExtraInterest(schedule, getDate(30, 10, 2010));
    Set<LoanScheduleEntity> loanScheduleEntities = getLoanScheduleEntities();
    Map<Integer, LoanScheduleEntity> loanScheduleEntityMap = getLoanScheduleEntityMap(loanScheduleEntities);
    assertThat(schedule.getInstallments().get(2).getExtraInterest().doubleValue(), is(0.46));
    scheduleCalculatorAdaptor.populateExtraInterestInLoanScheduleEntities(schedule, loanScheduleEntityMap);
    for (Installment installment : installments) {
        LoanScheduleEntity loanScheduleEntity = loanScheduleEntityMap.get(installment.getId());
        assertExtraInterest(loanScheduleEntity, installment.getExtraInterest().doubleValue());
    }
}
Also used : Installment(org.mifos.accounts.loan.schedule.domain.Installment) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) ScheduleCalculator(org.mifos.accounts.loan.schedule.calculation.ScheduleCalculator) Test(org.junit.Test)

Example 22 with Schedule

use of org.mifos.accounts.loan.schedule.domain.Schedule in project head by mifos.

the class ScheduleMapperTest method shouldPopulateExtraInterestInLoanScheduleEntities.

@Test
public void shouldPopulateExtraInterestInLoanScheduleEntities() {
    List<Installment> installments = getInstallments(0, 0, 0);
    Schedule schedule = new Schedule(DISBURSEMENT_DATE, DAILY_INTEREST_RATE, LOAN_AMOUNT, installments);
    for (int i = 0; i < installments.size(); i++) {
        installments.get(i).setExtraInterest(new BigDecimal(i));
    }
    Collection<LoanScheduleEntity> loanScheduleEntities = getLoanScheduleEntities(getDate(24, 11, 2010));
    Map<Integer, LoanScheduleEntity> loanScheduleEntityMap = getLoanScheduleEntityMap(loanScheduleEntities);
    scheduleMapper.populateExtraInterestInLoanScheduleEntities(schedule, loanScheduleEntityMap);
    assertExtraInterest(loanScheduleEntityMap.get(1), 0d);
    assertExtraInterest(loanScheduleEntityMap.get(2), 1d);
    assertExtraInterest(loanScheduleEntityMap.get(3), 2d);
}
Also used : Installment(org.mifos.accounts.loan.schedule.domain.Installment) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 23 with Schedule

use of org.mifos.accounts.loan.schedule.domain.Schedule in project head by mifos.

the class ScheduleMapperTest method shouldMapScheduleToLoanScheduleEntity.

@Test
public void shouldMapScheduleToLoanScheduleEntity() throws PersistenceException {
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loanBO, null, null, null, null, null);
    LoanScheduleEntity scheduleEntityForPopulateTestInput = getLoanScheduleEntityForPopulateTestInput();
    Set<LoanScheduleEntity> loanScheduleEntities = new LinkedHashSet<LoanScheduleEntity>();
    loanScheduleEntities.add(scheduleEntityForPopulateTestInput);
    when(loanBO.getLoanScheduleEntities()).thenReturn(loanScheduleEntities);
    when(loanBO.getlegacyLoanDao()).thenReturn(legacyLoanDao);
    Date paymentDate = getDate(24, 11, 2010);
    Schedule schedule = getScheduleWithSingleInstallment();
    scheduleMapper.populatePaymentDetails(schedule, loanBO, paymentDate, personnelBO, accountPaymentEntity);
    assertCalculatedInterestOnPayment(accountPaymentEntity);
    assertThat(getLoanScheduleEntity(paymentDate), new LoanScheduleEntityMatcher(scheduleEntityForPopulateTestInput));
    verify(loanBO, times(1)).getLoanScheduleEntities();
    verify(loanBO, times(1)).getlegacyLoanDao();
    verify(loanBO, times(1)).recordSummaryAndPerfHistory(anyBoolean(), Matchers.<PaymentAllocation>any());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LoanScheduleEntityMatcher(org.mifos.accounts.loan.business.matchers.LoanScheduleEntityMatcher) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) TestUtils.getDate(org.mifos.framework.TestUtils.getDate) Test(org.junit.Test)

Example 24 with Schedule

use of org.mifos.accounts.loan.schedule.domain.Schedule in project head by mifos.

the class ScheduleMapperTest method shouldMapLoanScheduleEntityToSchedule.

@Test
public void shouldMapLoanScheduleEntityToSchedule() {
    Collection<LoanScheduleEntity> loanScheduleEntities = getLoanScheduleEntities(getDate(24, 11, 2010));
    Schedule schedule = scheduleMapper.mapToSchedule(loanScheduleEntities, DISBURSEMENT_DATE, DAILY_INTEREST_RATE, LOAN_AMOUNT);
    assertThat(schedule, new ScheduleMatcher(getSchedule()));
}
Also used : Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) ScheduleMatcher(org.mifos.accounts.loan.schedule.domain.ScheduleMatcher) Test(org.junit.Test)

Example 25 with Schedule

use of org.mifos.accounts.loan.schedule.domain.Schedule in project head by mifos.

the class ScheduleCalculatorTest method withTwoInstallmentsAdjusted.

@Test
public void withTwoInstallmentsAdjusted() {
    Installment installment1 = getInstallment(1, getDate(25, 9, 2010), 242.24, 20.40, 0);
    Installment installment2 = getInstallment(2, getDate(25, 10, 2010), 247.67, 14.96, 0);
    Installment installment3 = getInstallment(3, getDate(25, 11, 2010), 252.22, 10.40, 0);
    Installment installment4 = getInstallment(4, getDate(25, 12, 2010), 257.87, 5.09, 0);
    schedule = new Schedule(getDate(25, 8, 2010), 0.000658, BigDecimal.valueOf(1000d), asList(installment1, installment2, installment3, installment4));
    scheduleCalculator.applyPayment(schedule, BigDecimal.valueOf(550d), getDate(25, 9, 2010), false);
    assertInstallmentPrincipals(installment1, 242.24, 0, 242.24);
    assertInstallmentPrincipals(installment2, 247.67, 0, 247.67);
    assertInstallmentPrincipals(installment3, 252.22, 212.53, 39.69);
    assertInstallmentPrincipals(installment4, 257.87, 257.87, 0);
    assertInstallmentInterests(installment1, 20.40, 0, 20.40);
    assertInstallmentInterests(installment2, 9.29, 9.29, 0);
    assertInstallmentInterests(installment3, 9.6, 9.6, 0);
    assertInstallmentInterests(installment4, 5.09, 5.09, 0);
}
Also used : Installment(org.mifos.accounts.loan.schedule.domain.Installment) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) Test(org.junit.Test)

Aggregations

Schedule (org.mifos.accounts.loan.schedule.domain.Schedule)39 Test (org.junit.Test)36 Installment (org.mifos.accounts.loan.schedule.domain.Installment)34 BigDecimal (java.math.BigDecimal)4 RepaymentResultsHolder (org.mifos.accounts.loan.business.RepaymentResultsHolder)4 ArrayList (java.util.ArrayList)2 ScheduleMatcher (org.mifos.accounts.loan.schedule.domain.ScheduleMatcher)2 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 LoanScheduleEntityMatcher (org.mifos.accounts.loan.business.matchers.LoanScheduleEntityMatcher)1 ScheduleCalculator (org.mifos.accounts.loan.schedule.calculation.ScheduleCalculator)1 InstallmentBuilder (org.mifos.accounts.loan.schedule.domain.InstallmentBuilder)1 TestUtils.getDate (org.mifos.framework.TestUtils.getDate)1 Money (org.mifos.framework.util.helpers.Money)1