use of org.mifos.accounts.financial.business.FinancialTransactionBO in project head by mifos.
the class FinancialBusinessServiceIntegrationTest method testLoanAdjustmentAccountingEntries.
@Test
public void testLoanAdjustmentAccountingEntries() throws Exception {
Date currentDate = new Date(System.currentTimeMillis());
loan = getLoanAccount();
loan.setUserContext(TestUtils.makeUser());
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
FinancialBusinessService financialBusinessService = new FinancialBusinessService();
AccountTrxnEntity accountTrxnEntity = getAccountTrxnObj(accountPaymentEntity);
accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
financialBusinessService.buildAccountingEntries(accountTrxnEntity);
TestObjectFactory.updateObject(loan);
for (FinancialTransactionBO finTrxn : accountTrxnEntity.getFinancialTransactions()) {
if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("1")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("1")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("2")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("2")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("43"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("3")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("3")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("52"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("4")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("4")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("52"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("6")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("6")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("44"));
} else {
//--fail("There should not be any other entry");
}
}
}
use of org.mifos.accounts.financial.business.FinancialTransactionBO in project head by mifos.
the class InterestPostingAccountingEntryTest method testBuildAccountEntryForAction.
@Test
public void testBuildAccountEntryForAction() throws FinancialException {
// setup
DateMidnight savingsTrxnDetailActionDate = new DateMidnight(2009, 9, 9);
DateMidnight savingsTrxnDetailCreationDate = new DateMidnight(2009, 1, 1);
MifosCurrency currency = TestUtils.RUPEE;
// stubbing
when(savingsTrxnDetail.getAccount()).thenReturn(savingsBO);
when(savingsTrxnDetail.getInterestAmount()).thenReturn(new Money(currency, interestAmount));
when(savingsTrxnDetail.getActionDate()).thenReturn(savingsTrxnDetailActionDate.toDate());
when(savingsTrxnDetail.getTrxnCreatedDate()).thenReturn(new Timestamp(savingsTrxnDetailCreationDate.getMillis()));
when(savingsTrxnDetail.getPersonnel()).thenReturn(transactionCreator);
when(savingsBO.getSavingsOffering()).thenReturn(savingsOffering);
when(savingsOffering.getInterestGLCode()).thenReturn(coaSavingsInterestPayable.getAssociatedGlcode());
when(savingsOffering.getDepositGLCode()).thenReturn(coaClientsSavings.getAssociatedGlcode());
SavingsInterestPostingFinancialActivity financialActivity = new SavingsInterestPostingFinancialActivity(savingsTrxnDetail);
// exercise test
interestPostingAccountingEntry.buildAccountEntryForAction(financialActivity);
// verification
List<FinancialTransactionBO> transactions = financialActivity.getFinanacialTransaction();
assertThat(transactions.size(), is(2));
/*
* Sort by GLCode strings so "22100" (interest payable tran) should be first, followed by "22200" (client
* savings tran)
*/
Collections.sort(transactions, new GLCodeComparator());
Iterator<FinancialTransactionBO> it = transactions.iterator();
FinancialTransactionBO interestPostingTrans = it.next();
assertThat(interestPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
assertThat(interestPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
assertThat(interestPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
assertThat(interestPostingTrans.getGlcode().getGlcode(), is(coaSavingsInterestPayable.getGlCode()));
assertThat(interestPostingTrans.getDebitCreditFlag(), is(FinancialConstants.DEBIT.getValue()));
assertThat(interestPostingTrans.getPostedBy(), is(transactionCreator));
FinancialTransactionBO savingsPostingTrans = it.next();
assertThat(savingsPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
assertThat(savingsPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
assertThat(savingsPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
assertThat(savingsPostingTrans.getGlcode().getGlcode(), is(coaClientsSavings.getGlCode()));
assertThat(savingsPostingTrans.getDebitCreditFlag(), is(FinancialConstants.CREDIT.getValue()));
assertThat(savingsPostingTrans.getPostedBy(), is(transactionCreator));
}
use of org.mifos.accounts.financial.business.FinancialTransactionBO in project head by mifos.
the class AccountBOIntegrationTest method testGetTransactionHistoryView.
@Test
public void testGetTransactionHistoryView() throws Exception {
Date currentDate = new Date(System.currentTimeMillis());
LoanBO loan = groupLoan;
loan.setUserContext(TestUtils.makeUser());
List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
accntActionDates.addAll(loan.getAccountActionDates());
PaymentData accountPaymentDataView = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(100), null, loan.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate);
IntegrationTestObjectMother.applyAccountPayment(loan, accountPaymentDataView);
loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
List<Integer> ids = new ArrayList<Integer>();
for (AccountPaymentEntity accountPaymentEntity : loan.getAccountPayments()) {
for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
for (FinancialTransactionBO financialTransactionBO : accountTrxnEntity.getFinancialTransactions()) {
ids.add(financialTransactionBO.getTrxnId());
}
}
}
loan.setUserContext(TestUtils.makeUser());
List<TransactionHistoryDto> trxnHistlist = loan.getTransactionHistoryView();
Assert.assertNotNull("Account TrxnHistoryView list object should not be null", trxnHistlist);
Assert.assertTrue("Account TrxnHistoryView list object Size should be greater than zero", trxnHistlist.size() > 0);
Assert.assertEquals(ids.size(), trxnHistlist.size());
int i = 0;
for (TransactionHistoryDto transactionHistoryDto : trxnHistlist) {
Assert.assertEquals(ids.get(i), transactionHistoryDto.getAccountTrxnId());
i++;
}
StaticHibernateUtil.flushSession();
groupLoan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
}
use of org.mifos.accounts.financial.business.FinancialTransactionBO in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveTransactionHistory.
@Override
public List<SavingsTransactionHistoryDto> retrieveTransactionHistory(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
CustomerBO customerBO = savingsAccount.getCustomer();
savingsAccount.updateDetails(userContext);
try {
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
List<SavingsTransactionHistoryDto> savingsTransactionHistoryViewList = new ArrayList<SavingsTransactionHistoryDto>();
// Check for order-by clause in AccountBO.hbm.xml,
// AccountPayment.hbm.xml and AccountTrxnEntity.hbm.xml for
// accountPaymentSet ,
// accountTrxnSet and financialBoSet. They all should be set for their
// primay key column desc in both. If stated is not there, the code
// below will behave abnormally.
List<AccountPaymentEntity> accountPaymentSet = savingsAccount.getAccountPayments();
for (AccountPaymentEntity accountPaymentEntity : accountPaymentSet) {
Set<AccountTrxnEntity> accountTrxnEntitySet = accountPaymentEntity.getAccountTrxns();
for (AccountTrxnEntity accountTrxnEntity : accountTrxnEntitySet) {
Set<FinancialTransactionBO> financialTransactionBOSet = accountTrxnEntity.getFinancialTransactions();
for (FinancialTransactionBO financialTransactionBO : financialTransactionBOSet) {
SavingsTransactionHistoryDto savingsTransactionHistoryDto = new SavingsTransactionHistoryDto();
savingsTransactionHistoryDto.setTransactionDate(financialTransactionBO.getActionDate());
String preferredTransactionDate = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), financialTransactionBO.getActionDate().toString());
savingsTransactionHistoryDto.setUserPrefferedTransactionDate(preferredTransactionDate);
savingsTransactionHistoryDto.setPaymentId(accountTrxnEntity.getAccountPayment().getPaymentId());
savingsTransactionHistoryDto.setAccountTrxnId(accountTrxnEntity.getAccountTrxnId());
savingsTransactionHistoryDto.setType(financialTransactionBO.getFinancialAction().getName());
savingsTransactionHistoryDto.setGlcode(financialTransactionBO.getGlcode().getGlcode());
savingsTransactionHistoryDto.setGlname(financialTransactionBO.getGlcode().getAssociatedCOA().getAccountName());
if (financialTransactionBO.isDebitEntry()) {
savingsTransactionHistoryDto.setDebit(String.valueOf(removeSign(financialTransactionBO.getPostedAmount())));
} else if (financialTransactionBO.isCreditEntry()) {
savingsTransactionHistoryDto.setCredit(String.valueOf(removeSign(financialTransactionBO.getPostedAmount())));
}
savingsTransactionHistoryDto.setBalance(String.valueOf(removeSign(((SavingsTrxnDetailEntity) accountTrxnEntity).getBalance())));
savingsTransactionHistoryDto.setClientName(accountTrxnEntity.getCustomer().getDisplayName());
savingsTransactionHistoryDto.setPostedDate(financialTransactionBO.getPostedDate());
String preferredDate = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), financialTransactionBO.getPostedDate().toString());
savingsTransactionHistoryDto.setUserPrefferedPostedDate(preferredDate);
if (accountTrxnEntity.getPersonnel() != null) {
savingsTransactionHistoryDto.setPostedBy(accountTrxnEntity.getPersonnel().getDisplayName());
}
if (financialTransactionBO.getNotes() != null && !financialTransactionBO.getNotes().equals("")) {
savingsTransactionHistoryDto.setNotes(financialTransactionBO.getNotes());
}
savingsTransactionHistoryViewList.add(savingsTransactionHistoryDto);
}
}
}
return savingsTransactionHistoryViewList;
}
use of org.mifos.accounts.financial.business.FinancialTransactionBO in project head by mifos.
the class TestObjectFactory method deleteAccountPayment.
private static void deleteAccountPayment(final AccountPaymentEntity accountPayment, final Session session) {
Set<AccountTrxnEntity> loanTrxns = accountPayment.getAccountTrxns();
for (AccountTrxnEntity accountTrxn : loanTrxns) {
if (accountTrxn instanceof LoanTrxnDetailEntity) {
LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) accountTrxn;
for (FeesTrxnDetailEntity feesTrxn : loanTrxn.getFeesTrxnDetails()) {
session.delete(feesTrxn);
}
for (FinancialTransactionBO financialTrxn : loanTrxn.getFinancialTransactions()) {
session.delete(financialTrxn);
}
session.delete(loanTrxn);
}
}
session.delete(accountPayment);
}
Aggregations