use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class StandardAccountServiceIntegrationTest method testMakePaymentForSavingsAccountOnDeposit.
@Test
public void testMakePaymentForSavingsAccountOnDeposit() throws Exception {
savingsBO = createClientSavingsAccount();
String deposit = "400";
CustomerDto clientDto = new CustomerDto();
clientDto.setCustomerId(client.getCustomerId());
//FIXME why one day in future payment is allowed
LocalDate paymentDate = new LocalDate().plusDays(1);
LocalDate receiptDate = new LocalDate().minusDays(3);
String receiptNumber = "AA/03/UX-9Q";
Assert.assertEquals(0, savingsBO.getAccountPayments().size());
AccountPaymentParametersDto depositPayment = new AccountPaymentParametersDto(new UserReferenceDto(savingsBO.getPersonnel().getPersonnelId()), new AccountReferenceDto(savingsBO.getAccountId()), new BigDecimal(deposit), paymentDate, defaultPaymentType, "comment", receiptDate, receiptNumber, clientDto);
standardAccountService.makePayment(depositPayment);
TestObjectFactory.updateObject(savingsBO);
Assert.assertEquals("The amount returned for the payment should have been " + deposit, Double.parseDouble(deposit), savingsBO.getLastPmntAmnt());
Assert.assertEquals(1, savingsBO.getAccountPayments().size());
for (AccountPaymentEntity payment : savingsBO.getAccountPayments()) {
Assert.assertEquals(TestUtils.createMoney(deposit), payment.getAmount());
Assert.assertEquals(1, payment.getAccountTrxns().size());
Assert.assertEquals(paymentDate.toDateMidnight().toDate(), payment.getPaymentDate());
Assert.assertEquals(defaultPaymentType.getName(), payment.getPaymentType().getName());
Assert.assertEquals("comment", payment.getComment());
Assert.assertEquals(savingsBO, payment.getAccount());
Assert.assertEquals(savingsBO.getPersonnel(), payment.getCreatedByUser());
Assert.assertEquals(receiptDate.toDateMidnight().toDate(), payment.getReceiptDate());
Assert.assertEquals(receiptNumber, payment.getReceiptNumber());
Assert.assertNull(payment.getCheckNumber());
Assert.assertNull(payment.getBankName());
Assert.assertNull(payment.getVoucherNumber());
Assert.assertTrue(payment.isSavingsDeposit());
Assert.assertFalse(payment.isSavingsWithdrawal());
Assert.assertTrue(payment.isSavingsDepositOrWithdrawal());
for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
Assert.assertEquals(client.getCustomerId(), accountTrxn.getCustomer().getCustomerId());
}
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class CustomerTrxnDetailEntityIntegrationTest method testGenerateReverseTrxn.
@Test
public void testGenerateReverseTrxn() throws Exception {
accountBO = client.getCustomerAccount();
Date currentDate = new Date(System.currentTimeMillis());
CustomerAccountBO customerAccountBO = (CustomerAccountBO) accountBO;
customerAccountBO.setUserContext(userContext);
CustomerScheduleEntity accountAction = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
accountAction.setMiscFeePaid(TestUtils.createMoney(100));
accountAction.setMiscPenaltyPaid(TestUtils.createMoney(100));
accountAction.setPaymentDate(currentDate);
accountAction.setPaymentStatus(PaymentStatus.PAID);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(accountBO, TestUtils.createMoney(100), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
CustomerTrxnDetailEntity accountTrxnEntity = new CustomerTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.PAYMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(userContext.getId()), currentDate, TestUtils.createMoney(200), "payment done", null, TestUtils.createMoney(100), TestUtils.createMoney(100));
for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
CustomerAccountBOTestUtils.setFeeAmountPaid((CustomerFeeScheduleEntity) accountFeesActionDetailEntity, TestUtils.createMoney(100));
FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
accountTrxnEntity.addFeesTrxnDetail(feeTrxn);
}
accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
AccountTestUtils.addAccountPayment(accountPaymentEntity, customerAccountBO);
PersonnelBO loggedInUser = legacyPersonnelDao.getPersonnel(userContext.getId());
for (AccountTrxnEntity accntTrxn : customerAccountBO.findMostRecentPaymentByPaymentDate().getAccountTrxns()) {
AccountTrxnEntity reverseAccntTrxn = ((CustomerTrxnDetailEntity) accntTrxn).generateReverseTrxn(loggedInUser, "adjustment");
Assert.assertEquals(reverseAccntTrxn.getAmount(), accntTrxn.getAmount().negate());
Assert.assertEquals(loggedInUser.getPersonnelId(), reverseAccntTrxn.getPersonnel().getPersonnelId());
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class CustomerAccountBOIntegrationTest method testUpdateInstallmentAfterAdjustment.
@Test
public void testUpdateInstallmentAfterAdjustment() throws Exception {
userContext = TestUtils.makeUser();
createInitialObjects();
applyPayment();
customerAccountBO = TestObjectFactory.getObject(CustomerAccountBO.class, customerAccountBO.getAccountId());
client = customerAccountBO.getCustomer();
customerAccountBO.setUserContext(userContext);
List<AccountTrxnEntity> reversedTrxns = AccountTestUtils.reversalAdjustment("payment adjustment done", customerAccountBO.findMostRecentPaymentByPaymentDate());
PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
customerAccountBO.updateInstallmentAfterAdjustment(reversedTrxns, loggedInUser);
for (AccountTrxnEntity accntTrxn : reversedTrxns) {
CustomerTrxnDetailEntity custTrxn = (CustomerTrxnDetailEntity) accntTrxn;
CustomerScheduleEntity accntActionDate = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(custTrxn.getInstallmentId());
Assert.assertEquals("Misc Fee Adjusted", accntActionDate.getMiscFeePaid(), TestUtils.createMoney());
Assert.assertEquals("Misc Penalty Adjusted", accntActionDate.getMiscPenaltyPaid(), TestUtils.createMoney());
}
for (CustomerActivityEntity customerActivityEntity : customerAccountBO.getCustomerActivitDetails()) {
Assert.assertEquals("Amnt Adjusted", customerActivityEntity.getDescription());
}
}
use of org.mifos.accounts.business.AccountTrxnEntity 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.AccountTrxnEntity 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));
}
}
}
Aggregations