Search in sources :

Example 31 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue.

@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue() throws Exception {
    MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday().build();
    center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
    IntegrationTestObjectMother.createCenter((CenterBO) center, weeklyMeeting);
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    final Money fiftyAmount = new Money(getCurrency(), "50.0");
    final Money seventyAmount = new Money(getCurrency(), "70.0");
    final Money oneHundredTwentyAmount = new Money(getCurrency(), "120.0");
    final Money twoHundredFortyAmount = new Money(getCurrency(), "240.0");
    for (AccountActionDateEntity accountActionDateEntity : customerAccount.getAccountActionDates()) {
        CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerSchedule.getInstallmentId() != 2) {
            customerSchedule.setMiscFee(fiftyAmount);
            customerSchedule.setMiscPenalty(seventyAmount);
        }
    }
    Date transactionDate = incrementCurrentDate(14);
    PaymentData paymentData = PaymentData.createPaymentData(twoHundredFortyAmount, 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");
            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());
                    }
                    Assert.assertEquals(0, customerTrxnDetailEntity.getFeesTrxnDetails().size());
                }
            } 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");
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) CenterBuilder(org.mifos.domain.builders.CenterBuilder) Date(java.sql.Date) SystemException(org.mifos.framework.exceptions.SystemException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 32 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class SavingsPostInterestTest method whenPostingInterestASingleAccountTransactionIsAssociatedWithAccountPayment.

@Test
public void whenPostingInterestASingleAccountTransactionIsAssociatedWithAccountPayment() {
    // setup
    InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
    Money interestToBePosted = TestUtils.createMoney("100");
    DateTime activationDate = new DateTime().withDate(2010, 7, 20);
    DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
    savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
    // pre verification
    assertTrue(savingsAccount.getAccountPayments().isEmpty());
    InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
    InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
    PersonnelBO createdBy = new PersonnelBuilder().build();
    // exercise
    savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
    // verification
    AccountPaymentEntity interestPostingPayment = savingsAccount.getAccountPayments().get(0);
    assertFalse(interestPostingPayment.getAccountTrxns().isEmpty());
    List<AccountTrxnEntity> accountTransactions = new ArrayList<AccountTrxnEntity>(interestPostingPayment.getAccountTrxns());
    SavingsTrxnDetailEntity interestPostingTransaction = (SavingsTrxnDetailEntity) accountTransactions.get(0);
    assertThat(interestPostingTransaction.getAccount(), is((AccountBO) savingsAccount));
    assertThat(interestPostingTransaction.getAmount(), is(interestToBePosted));
    assertThat(interestPostingTransaction.getInterestAmount(), is(interestToBePosted));
    assertThat(interestPostingTransaction.getAccountActionEntity().getId(), is(AccountActionTypes.SAVINGS_INTEREST_POSTING.getValue()));
    assertThat(new LocalDate(interestPostingTransaction.getActionDate()), is(nextInterestPostingDate.toLocalDate()));
    assertThat(new LocalDate(interestPostingTransaction.getDueDate()), is(today()));
    assertThat(datePartOf(interestPostingTransaction.getTrxnCreatedDate()), is(today()));
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) InterestPostingPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ArrayList(java.util.ArrayList) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) InterestCalculationPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder) Test(org.junit.Test)

Example 33 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity 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)

Example 34 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class LoanBO method buildLoanActivity.

private LoanActivityEntity buildLoanActivity(final Collection<AccountTrxnEntity> accountTrxnDetails, final PersonnelBO personnel, String comments, final Date trxnDate) {
    Date activityDate = trxnDate;
    Money principal = new Money(getCurrency());
    Money interest = new Money(getCurrency());
    Money penalty = new Money(getCurrency());
    Money fees = new Money(getCurrency());
    for (AccountTrxnEntity accountTrxn : accountTrxnDetails) {
        if (!accountTrxn.isTrxnForReversalOfLoanDisbursal()) {
            LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) accountTrxn;
            principal = principal.add(removeSign(loanTrxn.getPrincipalAmount()));
            interest = interest.add(removeSign(loanTrxn.getInterestAmount()));
            penalty = penalty.add(removeSign(loanTrxn.getPenaltyAmount())).add(removeSign(loanTrxn.getMiscPenaltyAmount()));
            fees = fees.add(removeSign(loanTrxn.getMiscFeeAmount()));
            for (FeesTrxnDetailEntity feesTrxn : loanTrxn.getFeesTrxnDetails()) {
                fees = fees.add(removeSign(feesTrxn.getFeeAmount()));
            }
        }
        if (accountTrxn.isTrxnForReversalOfLoanDisbursal() || accountTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.LOAN_REVERSAL.getValue())) {
            comments = "Loan Reversal";
        }
    }
    Money interestOutstanding = loanSummary.getOriginalInterest().subtract(loanSummary.getInterestPaid());
    if (isDecliningBalanceInterestRecalculation()) {
        for (LoanScheduleEntity loanScheduleEntity : getLoanScheduleEntities()) {
            interestOutstanding = interestOutstanding.add(loanScheduleEntity.getExtraInterest());
        }
    }
    return new LoanActivityEntity(this, personnel, comments, principal, loanSummary.getOriginalPrincipal().subtract(loanSummary.getPrincipalPaid()), interest, interestOutstanding, fees, loanSummary.getOriginalFees().subtract(loanSummary.getFeesPaid()), penalty, loanSummary.getOriginalPenalty().subtract(loanSummary.getPenaltyPaid()), activityDate);
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Example 35 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity 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)

Aggregations

AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)36 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 Test (org.junit.Test)15 Money (org.mifos.framework.util.helpers.Money)14 LocalDate (org.joda.time.LocalDate)8 Date (java.sql.Date)7 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 PaymentData (org.mifos.accounts.util.helpers.PaymentData)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)6 FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)5 DateTimeService (org.mifos.framework.util.DateTimeService)5 LinkedHashSet (java.util.LinkedHashSet)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)3 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)3 FinancialTransactionBO (org.mifos.accounts.financial.business.FinancialTransactionBO)3