Search in sources :

Example 76 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method testLoanWithOnePaymentMadeAndNoOverduePayments.

@Ignore
@Test
public void testLoanWithOnePaymentMadeAndNoOverduePayments() throws Exception {
    LoanBO loan = setUpLoan(dateTime, AccountState.LOAN_ACTIVE_IN_BAD_STANDING);
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    short daysPastPaymentDate = 3;
    // advance time daysOverdue past the second repayment interval
    dateTime = dateTime.plusDays(repaymentInterval + daysPastPaymentDate);
    new DateTimeService().setCurrentDateTimeFixed(dateTime);
    runLoanArrearsThenLoanArrearsAging();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNotNull(loan.getLoanArrearsAgingEntity());
    // make one payment, so we should still be one payment behind after that
    PaymentData paymentData = PaymentData.createPaymentData(new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "" + onePayment), loan.getPersonnel(), Short.valueOf("1"), dateTime.toDate());
    IntegrationTestObjectMother.applyAccountPayment(loan, paymentData);
    //jpwrunLoanArrearsThenLoanArrearsAging();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    Assert.assertTrue(loan.getState().equals(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING));
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) DateTimeService(org.mifos.framework.util.DateTimeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 77 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method testLoanWithEarlyRepaymentWithInterestWaiver.

@Ignore
@Test
public void testLoanWithEarlyRepaymentWithInterestWaiver() throws Exception {
    LoanBO loan = setUpLoan(dateTime, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    short daysPastPaymentDate = 3;
    // advance time daysOverdue past the second repayment interval
    dateTime = dateTime.plusDays(repaymentInterval + daysPastPaymentDate);
    new DateTimeService().setCurrentDateTimeFixed(dateTime);
    runLoanArrearsThenLoanArrearsAging();
    StaticHibernateUtil.flushAndClearSession();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNotNull(loan.getLoanArrearsAgingEntity());
    Money totalAmount = new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "" + loanAmount + 0);
    String receiptNumber = "1";
    loan.makeEarlyRepayment(null, loan.getPersonnel().getPersonnelId(), true, new Money(loan.getCurrency(), "0"));
    //jpw runLoanArrearsThenLoanArrearsAging();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    Assert.assertTrue(loan.getState().equals(AccountState.LOAN_CLOSED_OBLIGATIONS_MET));
}
Also used : Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) DateTimeService(org.mifos.framework.util.DateTimeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 78 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method initializeToFixedDateTime.

private DateTime initializeToFixedDateTime() {
    DateTime dateTime = new DateTime(2009, 12, 7, 0, 0, 0, 0);
    DateTimeService dateTimeService = new DateTimeService();
    dateTimeService.setCurrentDateTimeFixed(dateTime);
    return dateTime;
}
Also used : DateTimeService(org.mifos.framework.util.DateTimeService) DateTime(org.joda.time.DateTime)

Example 79 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method testLoanWithEarlyRepayment.

@Ignore
@Test
public void testLoanWithEarlyRepayment() throws Exception {
    LoanBO loan = setUpLoan(dateTime, AccountState.LOAN_ACTIVE_IN_BAD_STANDING);
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    short daysPastPaymentDate = 3;
    // advance time daysOverdue past the second repayment interval
    dateTime = dateTime.plusDays(repaymentInterval + daysPastPaymentDate);
    new DateTimeService().setCurrentDateTimeFixed(dateTime);
    runLoanArrearsThenLoanArrearsAging();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNotNull(loan.getLoanArrearsAgingEntity());
    Money totalAmount = new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "" + loanAmount + totalInterest);
    String receiptNumber = "1";
    loan.makeEarlyRepayment(null, loan.getPersonnel().getPersonnelId(), false, new Money(loan.getCurrency(), "0"));
    //jpw runLoanArrearsThenLoanArrearsAging();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    Assert.assertTrue(loan.getState().equals(AccountState.LOAN_CLOSED_OBLIGATIONS_MET));
}
Also used : Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) DateTimeService(org.mifos.framework.util.DateTimeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 80 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method testLoanWithOnePartialPayment.

/**
     * unsure why its failing.
     */
@Ignore
@Test
public void testLoanWithOnePartialPayment() throws Exception {
    LoanBO loan = setUpLoan(dateTime, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
    Assert.assertNull(loan.getLoanArrearsAgingEntity());
    short daysOverdue = 3;
    dateTime = dateTime.plusDays(repaymentInterval + daysOverdue);
    new DateTimeService().setCurrentDateTimeFixed(dateTime);
    // make one payment of 8. Interest is paid off first, so 2 goes to interest and 6 to principal
    int principalPayment = 6;
    int interestPayment = 2;
    // paymentAmount == 8
    int paymentAmount = interestPayment + principalPayment;
    PaymentData paymentData = PaymentData.createPaymentData(new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "" + paymentAmount), loan.getPersonnel(), Short.valueOf("1"), dateTime.toDate());
    IntegrationTestObjectMother.applyAccountPayment(loan, paymentData);
    runLoanArrearsThenLoanArrearsAging();
    StaticHibernateUtil.flushAndClearSession();
    loan = legacyLoanDao.getAccount(loan.getAccountId());
    Assert.assertNotNull(loan.getLoanArrearsAgingEntity());
    LoanArrearsAgingEntity loanArrearsAgingEntity = loan.getLoanArrearsAgingEntity();
    Assert.assertEquals(new Money(getCurrency(), "" + (loanAmount - principalPayment)), loanArrearsAgingEntity.getUnpaidPrincipal());
    Assert.assertEquals(new Money(getCurrency(), "" + (totalInterest - interestPayment)), loanArrearsAgingEntity.getUnpaidInterest());
    Assert.assertEquals(new Money(getCurrency(), "" + (principalForOneInstallment - principalPayment)), loanArrearsAgingEntity.getOverduePrincipal());
    Assert.assertEquals(new Money(getCurrency(), "0"), loanArrearsAgingEntity.getOverdueInterest());
    Assert.assertEquals(new Money(getCurrency(), "" + (principalForOneInstallment - principalPayment)), loanArrearsAgingEntity.getOverdueBalance());
    Assert.assertEquals(Short.valueOf(daysOverdue), loanArrearsAgingEntity.getDaysInArrears());
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanArrearsAgingEntity(org.mifos.accounts.loan.business.LoanArrearsAgingEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8