Search in sources :

Example 81 with AccountActionDateEntity

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

the class CustomerAccountBOIntegrationTest method testGenerateMeetingScheduleForGroupWhenMeeingDatesOfCenterIsPassed.

@Ignore
@Test
public void testGenerateMeetingScheduleForGroupWhenMeeingDatesOfCenterIsPassed() throws ApplicationException, SystemException {
    MeetingBO meetingBO = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meetingBO);
    changeFirstInstallmentDateToPreviousDate(center.getCustomerAccount());
    center.update();
    StaticHibernateUtil.flushAndClearSession();
    center = TestObjectFactory.getCenter(center.getCustomerId());
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    StaticHibernateUtil.flushAndClearSession();
    center = TestObjectFactory.getCenter(center.getCustomerId());
    java.util.Date nextMeetingDate = center.getCustomerAccount().getNextMeetingDate();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    for (AccountActionDateEntity actionDateEntity : group.getCustomerAccount().getAccountActionDates()) {
        if (actionDateEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(DateUtils.getDateWithoutTimeStamp(actionDateEntity.getActionDate().getTime()), DateUtils.getDateWithoutTimeStamp(nextMeetingDate.getTime()));
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 82 with AccountActionDateEntity

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

the class CustomerAccountBOIntegrationTest method testFailureMakePayment.

@Test
public void testFailureMakePayment() 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("The size of the payments done is", customerAccount.getAccountPayments().size(), 1);
    try {
        // one more for the next meeting
        customerAccount.applyPayment(accountPaymentDataView);
        // and the error one
        customerAccount.applyPayment(accountPaymentDataView);
        Assert.fail("Payment is done even though they are no dues");
    } catch (AccountException ae) {
        Assert.assertTrue("Payment is not allowed when there are no dues", true);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) Date(java.sql.Date) Test(org.junit.Test)

Example 83 with AccountActionDateEntity

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

the class CustomerAccountBOIntegrationTest method testPayPartOfMiscChargePlusWeeklyFeePreviousDay.

@Test
public void testPayPartOfMiscChargePlusWeeklyFeePreviousDay() 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(), "120.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(), "20"), customerScheduleEntity.getMiscFeePaid());
            Assert.assertEquals(new Money(getCurrency(), "100"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmount());
            Assert.assertEquals(new Money(getCurrency(), "100"), 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 84 with AccountActionDateEntity

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

the class CustomerAccountBOIntegrationTest method testApplyUpfrontFee.

// replaced by unit tests in CustomerAccountBOTest. Remove when we're sure that unit tests cover this
// functionality
//    public void testApplyPeriodicFee() 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();
//        FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.ALLCUSTOMERS, "200",
//                RecurrenceType.WEEKLY, Short.valueOf("2"));
//        UserContext uc = TestUtils.makeUser();
//        customerAccountBO.setUserContext(uc);
//
//        // exercise test
//        customerAccountBO.applyCharge(periodicFee.getFeeId(), ((AmountFeeBO) periodicFee).getFeeAmount()
//                .getAmountDoubleValue());
//        StaticHibernateUtil.commitTransaction();
//
//        // verification
//        Date lastAppliedDate = null;
//        for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
//            CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
//            if (customerScheduleEntity.getInstallmentId() % 2 == 0) {
//                //Maintenance fee only applies to installments 2, 4, 6, ...
//                Assert.assertEquals(1, customerScheduleEntity.getAccountFeesActionDetails().size());
//            } else {
//                // Both weekly maintenance fee and weekly periodic fee apply to installments 1, 3, 5, ...
//                Assert.assertEquals(2, customerScheduleEntity.getAccountFeesActionDetails().size());
//            }
//            lastAppliedDate = customerScheduleEntity.getActionDate();
//            for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : customerScheduleEntity
//                    .getAccountFeesActionDetails()) {
//                if (accountFeesActionDetailEntity.getFee().getFeeName().equals("Periodic Fee")) {
//                    Assert.assertEquals(TestUtils.createMoney("200"), accountFeesActionDetailEntity.getFeeAmount());
//                }
//            }
//        }
//        customerAccountBO.getAccountFees();
//        for (AccountFeesEntity accountFee : customerAccountBO.getAccountFees()) {
//            if (accountFee.getFees().getFeeName().equals("Periodic Fee")) {
//                Assert.assertEquals()
//            }
//        }
//        if (customerAccountBO.getCustomerActivitDetails() != null) {
//            CustomerActivityEntity customerActivityEntity = (CustomerActivityEntity) customerAccountBO
//            .getCustomerActivitDetails().toArray()[0];
//            Assert.assertEquals(periodicFee.getFeeName() + " applied", customerActivityEntity.getDescription());
//            Assert.assertEquals(new Money(getCurrency(), "1000"), customerActivityEntity.getAmount());
//            AccountFeesEntity accountFeesEntity = customerAccountBO.getAccountFees(periodicFee.getFeeId());
//            Assert.assertEquals(FeeStatus.ACTIVE.getValue(), accountFeesEntity.getFeeStatus());
//            Assert.assertEquals(DateUtils.getDateWithoutTimeStamp(lastAppliedDate.getTime()), DateUtils
//                    .getDateWithoutTimeStamp(accountFeesEntity.getLastAppliedDate().getTime()));
//        }
//    }
@Test
public void testApplyUpfrontFee() 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();
    FeeBO upfrontFee = TestObjectFactory.createOneTimeAmountFee("Upfront Fee", FeeCategory.ALLCUSTOMERS, "20", FeePayment.UPFRONT);
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(upfrontFee.getFeeId(), ((AmountFeeBO) upfrontFee).getFeeAmount().getAmountDoubleValue());
    StaticHibernateUtil.flushAndClearSession();
    Date lastAppliedDate = null;
    Money amount = new Money(getCurrency(), "20");
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(2, customerScheduleEntity.getAccountFeesActionDetails().size());
            lastAppliedDate = customerScheduleEntity.getActionDate();
        }
    }
    if (customerAccountBO.getCustomerActivitDetails() != null) {
        CustomerActivityEntity customerActivityEntity = (CustomerActivityEntity) customerAccountBO.getCustomerActivitDetails().toArray()[0];
        Assert.assertEquals(upfrontFee.getFeeName() + " applied", customerActivityEntity.getDescription());
        Assert.assertEquals(amount, customerActivityEntity.getAmount());
        AccountFeesEntity accountFeesEntity = customerAccountBO.getAccountFees(upfrontFee.getFeeId());
        Assert.assertEquals(FeeStatus.ACTIVE.getValue(), accountFeesEntity.getFeeStatus());
        Assert.assertEquals(DateUtils.getDateWithoutTimeStamp(lastAppliedDate.getTime()), DateUtils.getDateWithoutTimeStamp(accountFeesEntity.getLastAppliedDate().getTime()));
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Date(java.sql.Date) Test(org.junit.Test)

Example 85 with AccountActionDateEntity

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

the class CustomerAccountBOIntegrationTest method testApplyMiscChargeWithFirstInstallmentPaid.

@Test
public void testApplyMiscChargeWithFirstInstallmentPaid() 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();
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            customerScheduleEntity.setPaymentStatus(PaymentStatus.PAID);
        }
    }
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
    Money amount = new Money(getCurrency());
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("2"))) {
            amount = customerScheduleEntity.getMiscFee();
            Assert.assertEquals(new Money(getCurrency(), "33.0"), customerScheduleEntity.getMiscFee());
        }
    }
    if (customerAccountBO.getCustomerActivitDetails() != null) {
        CustomerActivityEntity customerActivityEntity = (CustomerActivityEntity) customerAccountBO.getCustomerActivitDetails().toArray()[0];
        Assert.assertEquals(AccountConstants.MISC_FEES_APPLIED, customerActivityEntity.getDescription());
        Assert.assertEquals(amount, customerActivityEntity.getAmount());
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

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