Search in sources :

Example 11 with FeesTrxnDetailEntity

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

the class CustomerApplyAdjustmentActionStrutsTest method applyPayment.

private void applyPayment() throws Exception {
    createInitialObjects();
    accountBO = client.getCustomerAccount();
    Date currentDate = new Date(System.currentTimeMillis());
    CustomerAccountBO customerAccountBO = (CustomerAccountBO) accountBO;
    customerAccountBO.setUserContext(userContext);
    CustomerScheduleEntity accountAction = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
    CustomerAccountBOTestUtils.setMiscFeePaid(accountAction, TestUtils.createMoney(100));
    CustomerAccountBOTestUtils.setMiscPenaltyPaid(accountAction, TestUtils.createMoney(100));
    CustomerAccountBOTestUtils.setPaymentDate(accountAction, 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());
        CustomerBOTestUtils.addFeesTrxnDetail(accountTrxnEntity, feeTrxn);
    // totalFees = accountFeesActionDetailEntity.getFeeAmountPaid();
    }
    accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, customerAccountBO);
    TestObjectFactory.updateObject(customerAccountBO);
    StaticHibernateUtil.flushSession();
    customerAccountBO = TestObjectFactory.getObject(CustomerAccountBO.class, customerAccountBO.getAccountId());
    client = customerAccountBO.getCustomer();
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CustomerTrxnDetailEntity(org.mifos.customers.business.CustomerTrxnDetailEntity) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Example 12 with FeesTrxnDetailEntity

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

the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountFeesAreDue.

@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountFeesAreDue() throws Exception {
    createCenter();
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    Date transactionDate = incrementCurrentDate(14);
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "300"), 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(getCurrency(), "0.0");
            final Money OneHundredAmount = new Money(getCurrency(), "100.0");
            if (accountPaymentEntity.getAccountTrxns() != null && accountPaymentEntity.getAccountTrxns().size() == 3) {
                for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
                    CustomerTrxnDetailEntity customerTrxnDetailEntity = (CustomerTrxnDetailEntity) accountTrxnEntity;
                    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() == 1) {
                        for (FeesTrxnDetailEntity feesTrxnDetailEntity : customerTrxnDetailEntity.getFeesTrxnDetails()) {
                            Assert.assertEquals(OneHundredAmount, feesTrxnDetailEntity.getFeeAmount());
                        }
                    } else {
                        throw new Exception("Expected one FeesTrxnDetailEntity, found none or more than one");
                    }
                }
            } 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) Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) SystemException(org.mifos.framework.exceptions.SystemException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity) Test(org.junit.Test)

Example 13 with FeesTrxnDetailEntity

use of org.mifos.accounts.business.FeesTrxnDetailEntity 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 14 with FeesTrxnDetailEntity

use of org.mifos.accounts.business.FeesTrxnDetailEntity 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 15 with FeesTrxnDetailEntity

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

the class LoanTrxnDetailEntity method generateReverseTrxn.

@Override
protected AccountTrxnEntity generateReverseTrxn(PersonnelBO loggedInUser, String adjustmentComment) throws AccountException {
    logger.debug("Inside generate reverse transaction method of loan trxn detail");
    String comment = null;
    if (null == adjustmentComment) {
        comment = getComments();
    } else {
        comment = adjustmentComment;
    }
    LoanTrxnDetailEntity reverseAccntTrxn;
    reverseAccntTrxn = new LoanTrxnDetailEntity(getAccountPayment(), getReverseTransctionActionType(), getInstallmentId(), getDueDate(), loggedInUser, getActionDate(), getAmount().negate(), comment, this, getPrincipalAmount().negate(), getInterestAmount().negate(), getPenaltyAmount().negate(), getMiscFeeAmount().negate(), getMiscPenaltyAmount().negate(), null, null);
    reverseAccntTrxn.setCalculatedInterestOnPayment(this.getCalculatedInterestOnPayment());
    if (null != getFeesTrxnDetails() && getFeesTrxnDetails().size() > 0) {
        logger.debug("Before generating reverse entries for fees");
        for (FeesTrxnDetailEntity feeTrxnDetail : getFeesTrxnDetails()) {
            reverseAccntTrxn.addFeesTrxnDetail(feeTrxnDetail.generateReverseTrxn(reverseAccntTrxn));
        }
        logger.debug("after generating reverse entries for fees");
    }
    if (null != getPenaltiesTrxnDetails() && getPenaltiesTrxnDetails().size() > 0) {
        logger.debug("Before generating reverse entries for penalties");
        for (PenaltiesTrxnDetailEntity penaltyTrxnDetail : getPenaltiesTrxnDetails()) {
            reverseAccntTrxn.addPenaltiesTrxnDetail(penaltyTrxnDetail.generateReverseTrxn(reverseAccntTrxn));
        }
        logger.debug("after generating reverse entries for penalties");
    }
    return reverseAccntTrxn;
}
Also used : PenaltiesTrxnDetailEntity(org.mifos.accounts.business.PenaltiesTrxnDetailEntity) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Aggregations

FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)16 Date (java.sql.Date)6 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)6 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)6 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)5 FinancialActionTypeEntity (org.mifos.accounts.financial.business.FinancialActionTypeEntity)4 LoanTrxnDetailEntity (org.mifos.accounts.loan.business.LoanTrxnDetailEntity)4 Money (org.mifos.framework.util.helpers.Money)4 Test (org.junit.Test)3 AccountException (org.mifos.accounts.exceptions.AccountException)3 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)3 CustomerTrxnDetailEntity (org.mifos.customers.business.CustomerTrxnDetailEntity)3 PaymentData (org.mifos.accounts.util.helpers.PaymentData)2 ApplicationException (org.mifos.framework.exceptions.ApplicationException)2 SystemException (org.mifos.framework.exceptions.SystemException)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LocalDate (org.joda.time.LocalDate)1 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)1