Search in sources :

Example 1 with AccountTrxnEntity

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

the class LoanBO method updateInstallmentAfterAdjustment.

@Override
protected void updateInstallmentAfterAdjustment(final List<AccountTrxnEntity> reversedTrxns, PersonnelBO loggedInUser) throws AccountException {
    Money increaseInterest = new Money(this.getCurrency());
    Money increaseFees = new Money(this.getCurrency());
    Money increasePenalty = new Money(this.getCurrency());
    int numberOfFullPayments = 0;
    short numberOfInstalments = (short) reversedTrxns.size();
    List<AccountActionDateEntity> allInstallments = this.getAllInstallments();
    if (isNotEmpty(reversedTrxns)) {
        for (AccountTrxnEntity reversedTrxn : reversedTrxns) {
            Short prevInstallmentId = null;
            Short currentInstallmentId = reversedTrxn.getInstallmentId();
            numberOfFullPayments = getIncrementedNumberOfFullPaymentsIfPaid(numberOfFullPayments, allInstallments, prevInstallmentId, currentInstallmentId);
            if (!reversedTrxn.isTrxnForReversalOfLoanDisbursal()) {
                LoanTrxnDetailEntity loanReverseTrxn = (LoanTrxnDetailEntity) reversedTrxn;
                loanSummary.updatePaymentDetails(loanReverseTrxn);
                if (loanReverseTrxn.isNotEmptyTransaction()) {
                    LoanScheduleEntity installment = (LoanScheduleEntity) getAccountActionDate(loanReverseTrxn.getInstallmentId());
                    installment.updatePaymentDetailsForAdjustment(loanReverseTrxn);
                    if (installment.isPaid()) {
                        increaseInterest = increaseInterest.add(installment.getInterestDue().add(installment.getExtraInterestDue())).add(loanReverseTrxn.getInterestAmount());
                        increaseFees = increaseFees.add(installment.getTotalFeesDue());
                        if (!this.noOfInstallments.equals(numberOfInstalments)) {
                            increaseFees = increaseFees.add(installment.getMiscFeeDue()).add(loanReverseTrxn.getMiscFeeAmount());
                            increasePenalty = increasePenalty.add(installment.getPenaltyDue()).add(loanReverseTrxn.getPenaltyAmount());
                        }
                    }
                    installment.recordForAdjustment();
                    if (installment.hasFees()) {
                        for (AccountFeesActionDetailEntity accntFeesAction : installment.getAccountFeesActionDetails()) {
                            loanReverseTrxn.adjustFees(accntFeesAction);
                        }
                    }
                    if (installment.hasPenalties()) {
                        for (LoanPenaltyScheduleEntity entity : installment.getLoanPenaltyScheduleEntities()) {
                            loanReverseTrxn.adjustPenalties(entity);
                        }
                    }
                }
            }
        }
        AccountStateEntity currentAccountState = this.getAccountState();
        AccountStateEntity newAccountState = currentAccountState;
        boolean statusChangeNeeded = false;
        if (isLoanActiveWithStatusChangeHistory()) {
            AccountStatusChangeHistoryEntity lastAccountStatusChange = getLastAccountStatusChange();
            if (lastAccountStatusChange.isLoanActive()) {
                statusChangeNeeded = true;
            } else if (currentAccountState.isLoanClosedObligationsMet()) {
                statusChangeNeeded = true;
                newAccountState = lastAccountStatusChange.getOldStatus();
            }
        }
        boolean accountReOpened = isAccountReOpened(currentAccountState, newAccountState);
        updatePerformanceHistory(accountReOpened);
        /*
             * John W - mifos-1986 - see related comment above
             */
        if (accountReOpened) {
            loanSummary.increaseBy(null, increaseInterest, increasePenalty, increaseFees);
            // fix for MIFOS-3287
            this.setClosedDate(null);
        }
        // Else reverse payments equal to number of transactions reversed.
        if (accountReOpened) {
            updatePerformanceHistoryOnAdjustment(1);
        } else if (reversedTrxns.size() > 0) {
            updatePerformanceHistoryOnAdjustment(numberOfFullPayments);
        }
        if (statusChangeNeeded) {
            Short daysInArrears = getDaysInArrears(accountReOpened);
            if (currentAccountState.isLoanClosedObligationsMet()) {
                AccountState newStatus = AccountState.LOAN_ACTIVE_IN_BAD_STANDING;
                if (daysInArrears == 0) {
                    newStatus = AccountState.LOAN_ACTIVE_IN_GOOD_STANDING;
                }
                changeStatus(newStatus, null, "Account Reopened", loggedInUser);
            } else {
                if (daysInArrears == 0) {
                    if (!currentAccountState.isLoanActiveInGoodStanding()) {
                        changeStatus(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, null, "Account Adjusted", loggedInUser);
                    }
                } else {
                    if (!currentAccountState.isLoanActiveInBadStanding()) {
                        changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "Account Adjusted", loggedInUser);
                        handleArrearsAging();
                    }
                }
            }
        }
        try {
            PersonnelBO personnel = legacyPersonnelDao.getPersonnel(getUserContext().getId());
            addLoanActivity(buildLoanActivity(reversedTrxns, personnel, AccountConstants.LOAN_ADJUSTED, DateUtils.getCurrentDateWithoutTimeStamp()));
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    }
}
Also used : AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) AccountState(org.mifos.accounts.util.helpers.AccountState) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Example 2 with AccountTrxnEntity

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

the class LoanBO method isAdjustPossibleOnLastTrxn.

@Override
public boolean isAdjustPossibleOnLastTrxn() {
    if (!(getAccountState().isLoanActiveInGoodStanding() || getAccountState().isLoanActiveInBadStanding() || getAccountState().isLoanClosedObligationsMet())) {
        logger.debug("State is not active hence adjustment is not possible");
        return false;
    }
    logger.debug("Total payments on this account is  " + getAccountPayments().size());
    AccountPaymentEntity accountPayment = getLastPmntToBeAdjusted();
    if (accountPayment != null) {
        for (AccountTrxnEntity accntTrxn : accountPayment.getAccountTrxns()) {
            LoanTrxnDetailEntity lntrxn = (LoanTrxnDetailEntity) accntTrxn;
            if (lntrxn.getInstallmentId().equals(Short.valueOf("0")) || isAdjustmentForInterestDedAtDisb(lntrxn.getInstallmentId())) {
                return false;
            }
        }
    }
    if (null != getLastPmntToBeAdjusted() && getLastPmntAmntToBeAdjusted() != 0) {
        return true;
    }
    logger.debug("Adjustment is not possible ");
    return false;
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity)

Example 3 with AccountTrxnEntity

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

the class LegacyLoanDao method getLastPaymentAction.

@SuppressWarnings("unchecked")
public Short getLastPaymentAction(final Integer accountId) throws PersistenceException {
    Map<String, Integer> queryParameters = new HashMap<String, Integer>();
    queryParameters.put("accountId", accountId);
    List<AccountPaymentEntity> accountPaymentList = executeNamedQuery(NamedQueryConstants.RETRIEVE_MAX_ACCPAYMENT, queryParameters);
    if (accountPaymentList != null && accountPaymentList.size() > 0) {
        AccountPaymentEntity accountPayment = accountPaymentList.get(0);
        Set<AccountTrxnEntity> accountTrxnSet = accountPayment.getAccountTrxns();
        for (AccountTrxnEntity accountTrxn : accountTrxnSet) {
            if (accountTrxn.getAccountActionEntity().getId().shortValue() == AccountActionTypes.DISBURSAL.getValue()) {
                return accountTrxn.getAccountActionEntity().getId();
            }
        }
    }
    return null;
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) HashMap(java.util.HashMap) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity)

Example 4 with AccountTrxnEntity

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

the class SavingsBOIntegrationTest method testSuccessfulDepositForCenterAccount.

@Test
public void testSuccessfulDepositForCenterAccount() throws AccountException, Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client1 = TestObjectFactory.createClient("Client", CustomerStatus.CLIENT_ACTIVE, group);
    savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1");
    savings = TestObjectFactory.createSavingsAccount("43245434", center, AccountStates.SAVINGS_ACC_APPROVED, new Date(System.currentTimeMillis()), savingsOffering);
    savings.setSavingsBalance(new Money(getCurrency()));
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    Money enteredAmount = new Money(currency, "100.0");
    PaymentData paymentData = PaymentData.createPaymentData(enteredAmount, savings.getPersonnel(), Short.valueOf("1"), new Date(System.currentTimeMillis()));
    paymentData.setCustomer(client1);
    paymentData.setReceiptDate(new Date(System.currentTimeMillis()));
    paymentData.setReceiptNum("34244");
    AccountActionDateEntity accountActionDate = savings.getAccountActionDate(Short.valueOf("1"));
    SavingsPaymentData savingsPaymentData = new SavingsPaymentData(accountActionDate);
    paymentData.addAccountPaymentData(savingsPaymentData);
    IntegrationTestObjectMother.applyAccountPayment(savings, paymentData);
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    Assert.assertEquals(AccountStates.SAVINGS_ACC_APPROVED, savings.getAccountState().getId().shortValue());
    Assert.assertEquals(TestUtils.createMoney(100.0), savings.getSavingsBalance());
    Assert.assertEquals(1, savings.getSavingsActivityDetails().size());
    List<AccountPaymentEntity> payments = savings.getAccountPayments();
    Assert.assertEquals(1, payments.size());
    for (AccountPaymentEntity payment : payments) {
        Assert.assertEquals(1, payment.getAccountTrxns().size());
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            SavingsTrxnDetailEntity trxn = (SavingsTrxnDetailEntity) accountTrxn;
            Assert.assertEquals(enteredAmount, trxn.getBalance());
            Assert.assertEquals(client1.getCustomerId(), trxn.getCustomer().getCustomerId());
        }
    }
    client1 = IntegrationTestObjectMother.findCustomerById(client1.getCustomerId());
}
Also used : SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) Date(java.util.Date) Test(org.junit.Test)

Example 5 with AccountTrxnEntity

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

the class SavingsBOIntegrationTest method testSavingsTrxnDetailsWithZeroAmt.

@Test
public void testSavingsTrxnDetailsWithZeroAmt() throws Exception {
    savings = createSavingsAccountPayment();
    for (AccountPaymentEntity accountPaymentEntity : savings.getAccountPayments()) {
        for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
            SavingsTrxnDetailEntity trxnEntity = (SavingsTrxnDetailEntity) accountTrxnEntity;
            Assert.assertEquals(new Money(getCurrency(), "5500"), trxnEntity.getBalance());
            Assert.assertEquals(new Money(getCurrency()), trxnEntity.getDepositAmount());
            Assert.assertEquals(new Money(getCurrency()), trxnEntity.getInterestAmount());
            Assert.assertEquals(new Money(getCurrency()), trxnEntity.getWithdrawlAmount());
            break;
        }
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) Test(org.junit.Test)

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