Search in sources :

Example 6 with FinancialTransactionBO

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");
        }
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 7 with FinancialTransactionBO

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));
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) DateMidnight(org.joda.time.DateMidnight) SavingsInterestPostingFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity) Timestamp(java.sql.Timestamp) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 8 with FinancialTransactionBO

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());
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) Date(java.sql.Date) TransactionHistoryDto(org.mifos.dto.screen.TransactionHistoryDto) Test(org.junit.Test)

Example 9 with FinancialTransactionBO

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;
}
Also used : FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsTransactionHistoryDto(org.mifos.dto.screen.SavingsTransactionHistoryDto) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerBO(org.mifos.customers.business.CustomerBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with FinancialTransactionBO

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);
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Aggregations

FinancialTransactionBO (org.mifos.accounts.financial.business.FinancialTransactionBO)10 Test (org.junit.Test)5 Money (org.mifos.framework.util.helpers.Money)5 Date (java.sql.Date)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 ArrayList (java.util.ArrayList)3 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)3 LoanTrxnDetailEntity (org.mifos.accounts.loan.business.LoanTrxnDetailEntity)3 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)3 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 TransactionHistoryDto (org.mifos.dto.screen.TransactionHistoryDto)2 Timestamp (java.sql.Timestamp)1 DateMidnight (org.joda.time.DateMidnight)1 FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 SavingsInterestPostingFinancialActivity (org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)1 PaymentData (org.mifos.accounts.util.helpers.PaymentData)1