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