Search in sources :

Example 1 with AccountStateEntity

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

the class LoanBO method changeLoanStatus.

private void changeLoanStatus(final AccountState newAccountState, final PersonnelBO personnel) throws AccountException {
    AccountStateEntity accountState = this.getAccountState();
    try {
        setAccountState(legacyMasterDao.getPersistentObject(AccountStateEntity.class, newAccountState.getValue()));
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
    if (newAccountState.isClosedLoanAccountState() || newAccountState.isCancelledLoanAccountState()) {
        changeStateForAllFees(FeeStatus.INACTIVE);
    } else if (newAccountState.isActiveLoanAccountState()) {
        changeStateForAllFees(FeeStatus.ACTIVE);
    }
    this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(accountState, this.getAccountState(), personnel, this));
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity)

Example 2 with AccountStateEntity

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

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

the class LoanBO method approve.

public void approve(PersonnelBO createdBy, String comment, LocalDate approvalDate) {
    AccountStateEntity approvedState = new AccountStateEntity(AccountState.LOAN_APPROVED);
    AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), approvedState, createdBy, this);
    AccountNotesEntity accountNotesEntity = new AccountNotesEntity(approvalDate.toDateMidnight().toDate(), comment, createdBy, this);
    this.addAccountStatusChangeHistory(historyEntity);
    this.setAccountState(approvedState);
    this.addAccountNotes(accountNotesEntity);
}
Also used : AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity)

Example 4 with AccountStateEntity

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

the class LoanBO method disburse.

public void disburse(PersonnelBO createdBy, AccountPaymentEntity disbursalPayment) throws AccountException {
    Date transactionDate = disbursalPayment.getPaymentDate();
    addLoanActivity(buildLoanActivity(getLoanAmount(), createdBy, AccountConstants.LOAN_DISBURSAL, transactionDate));
    final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
    addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newState, createdBy, this));
    setAccountState(newState);
    if (getPerformanceHistory() != null) {
        getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
    }
    // build up account payment related data
    AccountPaymentEntity accountPayment = null;
    // Disbursal process has to create its own accountPayment taking into account any disbursement fees
    Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
    accountPayment = new AccountPaymentEntity(this, getLoanAmount().subtract(feeAmountAtDisbursement), disbursalPayment.getReceiptNumber(), disbursalPayment.getReceiptDate(), getPaymentTypeEntity(disbursalPayment.getPaymentType().getId()), transactionDate);
    accountPayment.setCreatedByUser(createdBy);
    if (feeAmountAtDisbursement.isGreaterThanZero()) {
        processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, disbursalPayment.getOtherTransferPaymentDto().getPaymentTypeId(), disbursalPayment.getOtherTransferPayment().getAccount().getAccountId());
    }
    // create trxn entry for disbursal
    final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, createdBy, transactionDate, getLoanAmount(), "-", null, getLoanAmount(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
    accountPayment.addAccountTrxn(loanTrxnDetailEntity);
    addAccountPayment(accountPayment);
    buildFinancialEntries(accountPayment.getAccountTrxns());
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 5 with AccountStateEntity

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

the class CheckListServiceFacadeWebTier method createAccountChecklist.

@Override
public void createAccountChecklist(Short productId, Short stateId, String checklistName, List<String> checklistDetails) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        ProductTypeEntity productTypeEntity = null;
        for (ProductTypeEntity prdTypeEntity : new ProductCategoryBusinessService().getProductTypes()) {
            if (productId.equals(prdTypeEntity.getProductTypeID())) {
                productTypeEntity = prdTypeEntity;
                break;
            }
        }
        hibernateTransactionHelper.startTransaction();
        AccountStateEntity accountStateEntity = new AccountStateEntity(AccountState.fromShort(stateId));
        AccountCheckListBO accountCheckListBO = new AccountCheckListBO(productTypeEntity, accountStateEntity, checklistName, CheckListConstants.STATUS_ACTIVE, checklistDetails, userContext.getLocaleId(), userContext.getId());
        customerDao.save(accountCheckListBO);
        hibernateTransactionHelper.commitTransaction();
    } catch (ServiceException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (CheckListException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountCheckListBO(org.mifos.customers.checklist.business.AccountCheckListBO) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) ProductTypeEntity(org.mifos.accounts.productdefinition.business.ProductTypeEntity) ProductCategoryBusinessService(org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)49 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)11 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)11 AccountException (org.mifos.accounts.exceptions.AccountException)8 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 Money (org.mifos.framework.util.helpers.Money)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 AdminDocAccStateMixBO (org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO)5 AdminDocumentBO (org.mifos.reports.admindocuments.business.AdminDocumentBO)5 Date (java.util.Date)4 List (java.util.List)4 LocalDate (org.joda.time.LocalDate)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 AccountStateFlagEntity (org.mifos.accounts.business.AccountStateFlagEntity)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 UserContext (org.mifos.security.util.UserContext)4