Search in sources :

Example 86 with AccountActionDateEntity

use of org.mifos.accounts.business.AccountActionDateEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenBothCustomerAccountChargesAndFeesAreDue.

@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenBothCustomerAccountChargesAndFeesAreDue() throws Exception {
    createCenter();
    FeeBO extraFee = TestObjectFactory.createPeriodicAmountFee("extra fee", FeeCategory.ALLCUSTOMERS, "5.5", RecurrenceType.WEEKLY, Short.valueOf("1"));
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    AccountFeesEntity extraAccountFeesEntity = new AccountFeesEntity(customerAccount, extraFee, 11.66);
    // FIXME: a fee is being added by exposing an internal data structure and adding it directly to it
    customerAccount.getAccountFeesIncludingInactiveFees().add(extraAccountFeesEntity);
    final Money eightAmount = new Money(getCurrency(), "8.0");
    final Money fiftyAmount = new Money(getCurrency(), "50.0");
    final Money seventyAmount = new Money(getCurrency(), "70.0");
    final Money oneHundredTwentyAmount = new Money(getCurrency(), "120.0");
    for (AccountActionDateEntity accountActionDateEntity : customerAccount.getAccountActionDates()) {
        CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerSchedule.getInstallmentId() == 2) {
            customerSchedule.setMiscFee(fiftyAmount);
            customerSchedule.setMiscPenalty(seventyAmount);
        }
        if (customerSchedule.getInstallmentId() == 3) {
            CustomerAccountBOTestUtils.applyPeriodicFees(customerSchedule, extraAccountFeesEntity.getFees().getFeeId(), new Money(getCurrency(), "8"));
        }
    }
    Date transactionDate = incrementCurrentDate(14);
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "428"), center.getPersonnel(), Short.valueOf("1"), transactionDate);
    paymentData.setCustomer(center);
    IntegrationTestObjectMother.applyAccountPayment(customerAccount, paymentData);
    if (customerAccount.getAccountPayments() != null && customerAccount.getAccountPayments().size() == 1) {
        for (AccountPaymentEntity accountPaymentEntity : customerAccount.getAccountPayments()) {
            final Money zeroAmount = new Money(accountPaymentEntity.getAmount().getCurrency(), "0.0");
            final Money OneHundredAmount = new Money(accountPaymentEntity.getAmount().getCurrency(), "100.0");
            if (accountPaymentEntity.getAccountTrxns() != null && accountPaymentEntity.getAccountTrxns().size() == 3) {
                for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
                    CustomerTrxnDetailEntity customerTrxnDetailEntity = (CustomerTrxnDetailEntity) accountTrxnEntity;
                    if (customerTrxnDetailEntity.getInstallmentId() == 2) {
                        Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getAmount());
                        Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getTotalAmount());
                        Assert.assertEquals(fiftyAmount, customerTrxnDetailEntity.getMiscFeeAmount());
                        Assert.assertEquals(seventyAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
                    } else {
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getAmount());
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getTotalAmount());
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscFeeAmount());
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
                    }
                    if (customerTrxnDetailEntity.getFeesTrxnDetails() != null && customerTrxnDetailEntity.getFeesTrxnDetails().size() < 3) {
                        for (FeesTrxnDetailEntity feesTrxnDetailEntity : customerTrxnDetailEntity.getFeesTrxnDetails()) {
                            if (feesTrxnDetailEntity.getAccountFees().getAccountFeeId() == extraAccountFeesEntity.getAccountFeeId()) {
                                Assert.assertEquals(eightAmount, feesTrxnDetailEntity.getFeeAmount());
                            } else {
                                Assert.assertEquals(OneHundredAmount, feesTrxnDetailEntity.getFeeAmount());
                            }
                        }
                    } else {
                        throw new Exception("Expected one FeesTrxnDetailEntity, found none or more than two");
                    }
                }
            } else {
                throw new Exception("Expected three CustomerTrxnDetailEntity, found none or not three");
            }
        }
    } else {
        throw new Exception("Expected one AccountPaymentEntity, found none or more than one");
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) SystemException(org.mifos.framework.exceptions.SystemException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity) Test(org.junit.Test)

Example 87 with AccountActionDateEntity

use of org.mifos.accounts.business.AccountActionDateEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testSuccessfulMakePayment.

@Test
public void testSuccessfulMakePayment() throws Exception {
    createCenter();
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    Assert.assertNotNull(customerAccount);
    Date transactionDate = new Date(System.currentTimeMillis());
    List<AccountActionDateEntity> dueActionDates = TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate);
    Assert.assertEquals("The size of the due insallments is ", dueActionDates.size(), 1);
    PaymentData accountPaymentDataView = TestObjectFactory.getCustomerAccountPaymentDataView(dueActionDates, TestUtils.createMoney("100.0"), null, center.getPersonnel(), "3424324", Short.valueOf("1"), transactionDate, transactionDate);
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    customerAccount = center.getCustomerAccount();
    IntegrationTestObjectMother.applyAccountPayment(customerAccount, accountPaymentDataView);
    Assert.assertEquals(customerAccount.getCustomerActivitDetails().size(), 1);
    Assert.assertEquals("The size of the payments done is", customerAccount.getAccountPayments().size(), 1);
    Assert.assertEquals("The size of the due insallments after payment is", TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate).size(), 0);
    for (CustomerActivityEntity activity : customerAccount.getCustomerActivitDetails()) {
        Assert.assertEquals(transactionDate, activity.getCreatedDate());
    }
    assertThat(customerAccount.getAccountPayments().size(), is(1));
    for (AccountPaymentEntity accountPayment : customerAccount.getAccountPayments()) {
        assertThat(accountPayment.getAccountTrxns().size(), is(1));
        for (AccountTrxnEntity accountTrxnEntity : accountPayment.getAccountTrxns()) {
            assertThat(accountTrxnEntity.getFinancialTransactions().size(), is(2));
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 88 with AccountActionDateEntity

use of org.mifos.accounts.business.AccountActionDateEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testPayMiscChargePlusWeeklyFeeExactPreviousDay.

@Test
public void testPayMiscChargePlusWeeklyFeeExactPreviousDay() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    customerAccountBO = group.getCustomerAccount();
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
    CustomerScheduleEntity firstInstallment = null;
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            firstInstallment = customerScheduleEntity;
            Assert.assertEquals(new Money(getCurrency(), "33.0"), customerScheduleEntity.getMiscFee());
        }
    }
    DateMidnight pDate = new DateMidnight(firstInstallment.getActionDate());
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "133.0"), center.getPersonnel(), (short) 1, pDate.minusDays(1).toDate());
    customerAccountBO.applyPayment(paymentData);
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFee());
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFeePaid());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 89 with AccountActionDateEntity

use of org.mifos.accounts.business.AccountActionDateEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testPayMiscChargePlusPartOfWeeklyFeePreviousDay.

@Test
public void testPayMiscChargePlusPartOfWeeklyFeePreviousDay() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    customerAccountBO = group.getCustomerAccount();
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
    CustomerScheduleEntity firstInstallment = null;
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            firstInstallment = customerScheduleEntity;
            Assert.assertEquals(new Money(getCurrency(), "33.0"), customerScheduleEntity.getMiscFee());
        }
    }
    DateMidnight pDate = new DateMidnight(firstInstallment.getActionDate());
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "50.0"), center.getPersonnel(), (short) 1, pDate.minusDays(1).toDate());
    customerAccountBO.applyPayment(paymentData);
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFee());
            Assert.assertEquals(new Money(getCurrency(), "0"), customerScheduleEntity.getMiscFeePaid());
            Assert.assertEquals(new Money(getCurrency(), "100"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmount());
            Assert.assertEquals(new Money(getCurrency(), "50"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmountPaid());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 90 with AccountActionDateEntity

use of org.mifos.accounts.business.AccountActionDateEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method changeAllInstallmentDateToPreviousDate.

private void changeAllInstallmentDateToPreviousDate(final CustomerAccountBO customerAccountBO, final int noOfDays) {
    Calendar currentDateCalendar = new GregorianCalendar();
    int year = currentDateCalendar.get(Calendar.YEAR);
    int month = currentDateCalendar.get(Calendar.MONTH);
    int day = currentDateCalendar.get(Calendar.DAY_OF_MONTH);
    currentDateCalendar = new GregorianCalendar(year, month, day - noOfDays);
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        ((CustomerScheduleEntity) accountActionDateEntity).setActionDate(new java.sql.Date(currentDateCalendar.getTimeInMillis()));
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.sql.Date)

Aggregations

AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)211 Money (org.mifos.framework.util.helpers.Money)80 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)58 LocalDate (org.joda.time.LocalDate)42 Date (java.util.Date)39 DateTime (org.joda.time.DateTime)33 MeetingBO (org.mifos.application.meeting.business.MeetingBO)33 AccountException (org.mifos.accounts.exceptions.AccountException)24 PaymentData (org.mifos.accounts.util.helpers.PaymentData)24 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)21 Date (java.sql.Date)19 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)15 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)14 UserContext (org.mifos.security.util.UserContext)14 Calendar (java.util.Calendar)13 GregorianCalendar (java.util.GregorianCalendar)13 CenterBuilder (org.mifos.domain.builders.CenterBuilder)13