use of org.mifos.accounts.business.AccountFeesEntity 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.business.AccountFeesEntity in project head by mifos.
the class ClientCreationTest method throwsCheckedExceptionWhenValidationForDuplicateSavingsFails.
@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenValidationForDuplicateSavingsFails() throws Exception {
// setup
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
List<SavingsOfferingBO> noSavings = new ArrayList<SavingsOfferingBO>();
// stubbing
doThrow(new CustomerException(ClientConstants.ERRORS_DUPLICATE_OFFERING_SELECTED)).when(mockedClient).validateNoDuplicateSavings(noSavings);
// exercise test
customerService.createClient(mockedClient, meeting, accountFees, noSavings);
// verify
verify(mockedClient).validateNoDuplicateSavings(noSavings);
}
use of org.mifos.accounts.business.AccountFeesEntity 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()));
}
}
use of org.mifos.accounts.business.AccountFeesEntity 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");
}
}
use of org.mifos.accounts.business.AccountFeesEntity in project head by mifos.
the class CenterCreationUsingCustomerServiceIntegrationTest method canNotCreateCenterWithNameOfAlreadyExistingCenter.
@Test(expected = BusinessRuleException.class)
public void canNotCreateCenterWithNameOfAlreadyExistingCenter() throws Exception {
// minimal details
MeetingBuilder aWeeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday();
String centerName = "existingCenterName";
OfficeBO anExistingBranch = sampleBranchOffice();
PersonnelBO existingLoanOfficer = testUser();
DateTime aWeekFromNow = new DateTime().plusWeeks(1);
CenterBO existingCenter = new CenterBuilder().withName(centerName).with(aWeeklyMeeting).with(anExistingBranch).withLoanOfficer(existingLoanOfficer).withMfiJoiningDate(aWeekFromNow).withUserContext().build();
IntegrationTestObjectMother.createCenter(existingCenter, existingCenter.getCustomerMeetingValue());
CenterBO newCenter = new CenterBuilder().withName(existingCenter.getDisplayName()).with(aWeeklyMeeting).with(anExistingBranch).withLoanOfficer(existingLoanOfficer).withMfiJoiningDate(aWeekFromNow).withUserContext().build();
// setup
List<AccountFeesEntity> noCenterAccountFees = new ArrayList<AccountFeesEntity>();
// exercise test
customerService.createCenter(newCenter, newCenter.getCustomerMeetingValue(), noCenterAccountFees);
// verification
assertThat(existingCenter.getGlobalCustNum(), is(not(newCenter.getGlobalCustNum())));
assertThat(existingCenter.getDisplayName(), is(newCenter.getDisplayName()));
}
Aggregations