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();
}
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);
}
}
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;
}
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));
}
}
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()));
}
}
Aggregations