Search in sources :

Example 11 with AmountFeeBO

use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.

the class GenerateMeetingsForCustomerAndSavingsBatchJobIntegrationTest method cleanDatabaseTables.

@Before
public void cleanDatabaseTables() {
    databaseCleaner.clean();
    DateTime eightWeeksInPast = new DateTime().minusWeeks(8);
    MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).withStartDate(eightWeeksInPast).build();
    IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
    AmountFeeBO weeklyPeriodicFeeForCenterOnly = new FeeBuilder().appliesToCenterOnly().withFeeAmount("100.0").withName("Center Weekly Periodic Fee").withSameRecurrenceAs(weeklyMeeting).with(sampleBranchOffice()).build();
    IntegrationTestObjectMother.saveFee(weeklyPeriodicFeeForCenterOnly);
    center = new CenterBuilder().withNumberOfExistingCustomersInOffice(3).withName("Center1").with(weeklyMeeting).with(sampleBranchOffice()).withLoanOfficer(testUser()).withActivationDate(eightWeeksInPast).active().build();
    IntegrationTestObjectMother.createCenter(center, weeklyMeeting, weeklyPeriodicFeeForCenterOnly);
    generateMeetingsForCustomerAndSavingsHelper = new GenerateMeetingsForCustomerAndSavingsHelper();
}
Also used : FeeBuilder(org.mifos.domain.builders.FeeBuilder) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Before(org.junit.Before)

Example 12 with AmountFeeBO

use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.

the class TestObjectFactory method createPeriodicAmountFee.

private static FeeBO createPeriodicAmountFee(final String feeName, final FeeCategory feeCategory, final String feeAmnt, final RecurrenceType meetingFrequency, final Short recurAfter, final UserContext userContext, String categoryLookupValue) {
    try {
        GLCodeEntity glCode = ChartOfAccountsCache.get("31301").getAssociatedGlcode();
        MeetingBO meeting = new MeetingBO(meetingFrequency, recurAfter, new DateTimeService().getCurrentJavaDateTime(), MeetingType.PERIODIC_FEE);
        LookUpValueEntity lookUpValue = new LookUpValueEntity();
        lookUpValue.setLookUpName(categoryLookupValue);
        CategoryTypeEntity categoryType = new CategoryTypeEntity(feeCategory);
        categoryType.setLookUpValue(lookUpValue);
        FeeBO fee = new AmountFeeBO(userContext, feeName, categoryType, new FeeFrequencyTypeEntity(FeeFrequencyType.PERIODIC), glCode, TestUtils.createMoney(feeAmnt), false, meeting);
        return testObjectPersistence.createFee(fee);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) FeeFrequencyTypeEntity(org.mifos.accounts.fees.business.FeeFrequencyTypeEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) CategoryTypeEntity(org.mifos.accounts.fees.business.CategoryTypeEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) DateTimeService(org.mifos.framework.util.DateTimeService) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) OfficeException(org.mifos.customers.office.exceptions.OfficeException) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 13 with AmountFeeBO

use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.

the class TestObjectFactory method getFeesWithMakeUser.

public static List<FeeDto> getFeesWithMakeUser() {
    List<FeeDto> fees = new ArrayList<FeeDto>();
    AmountFeeBO maintenanceFee = (AmountFeeBO) createPeriodicAmountFeeWithMakeUser("Maintenance Fee", FeeCategory.ALLCUSTOMERS, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
    FeeDto fee = new FeeDto(getContext(), maintenanceFee);
    fees.add(fee);
    return fees;
}
Also used : ArrayList(java.util.ArrayList) FeeDto(org.mifos.accounts.fees.business.FeeDto) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO)

Example 14 with AmountFeeBO

use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.

the class CenterValidationTest method cannotCreateCenterWithFeeThatHasDifferentPeriod.

@Test
public void cannotCreateCenterWithFeeThatHasDifferentPeriod() {
    // setup
    DateTime today = new DateTime();
    MeetingBuilder aWeeklyMeeting = new MeetingBuilder().customerMeeting().weekly();
    CenterBO center = new CenterBuilder().withName("center1").withLoanOfficer(anyLoanOfficer()).with(aWeeklyMeeting).withMfiJoiningDate(today).build();
    MeetingBuilder aMonthlyMeeting = new MeetingBuilder().periodicFeeMeeting().monthly();
    AmountFeeBO montlyPeriodicFee = new FeeBuilder().appliesToCenterOnly().with(aMonthlyMeeting).build();
    AccountFeesEntity accountFee = new AccountFeesEntity(null, montlyPeriodicFee, montlyPeriodicFee.getFeeAmount().getAmountDoubleValue());
    List<AccountFeesEntity> centerAccountFees = new ArrayList<AccountFeesEntity>();
    centerAccountFees.add(accountFee);
    // exercise test
    try {
        center.validateMeetingAndFees(centerAccountFees);
        fail("cannotCreateCenterWithFeeThatHasDifferentPeriod");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_FEE_FREQUENCY_MISMATCH));
    }
}
Also used : FeeBuilder(org.mifos.domain.builders.FeeBuilder) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTime(org.joda.time.DateTime) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Test(org.junit.Test)

Example 15 with AmountFeeBO

use of org.mifos.accounts.fees.business.AmountFeeBO 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)

Aggregations

AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)41 ArrayList (java.util.ArrayList)24 MeetingBO (org.mifos.application.meeting.business.MeetingBO)18 Test (org.junit.Test)17 FeeBO (org.mifos.accounts.fees.business.FeeBO)17 Money (org.mifos.framework.util.helpers.Money)16 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)14 DateTime (org.joda.time.DateTime)13 FeeBuilder (org.mifos.domain.builders.FeeBuilder)13 CenterBuilder (org.mifos.domain.builders.CenterBuilder)12 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)11 FeeDto (org.mifos.accounts.fees.business.FeeDto)8 CenterBO (org.mifos.customers.center.business.CenterBO)8 CategoryTypeEntity (org.mifos.accounts.fees.business.CategoryTypeEntity)6 FeeFrequencyTypeEntity (org.mifos.accounts.fees.business.FeeFrequencyTypeEntity)6 RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)6 BigDecimal (java.math.BigDecimal)5 Date (java.sql.Date)5 LocalDate (org.joda.time.LocalDate)5 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)5