Search in sources :

Example 1 with AccountPaymentEntity

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

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

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

the class LoanBO method makePayment.

/*
     * PaymentData is the payment information entered in the UI An AccountPaymentEntity is created from the PaymentData
     * passed in.
     */
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
    AccountPaymentEntity accountPaymentEntity = prePayment(paymentData);
    LoanPaymentTypes loanPaymentType = getLoanPaymentType(paymentData.getTotalAmount());
    ApplicationContextProvider.getBean(LoanBusinessService.class).applyPayment(paymentData, this, accountPaymentEntity);
    postPayment(paymentData, accountPaymentEntity, loanPaymentType);
    if (paymentData.getOverpaymentAmount() != null) {
        AccountOverpaymentEntity overpaymentEntity = new AccountOverpaymentEntity(this, accountPaymentEntity, paymentData.getOverpaymentAmount(), OverpaymentStatus.UNCLEARED.getValue());
        addAccountOverpayment(overpaymentEntity);
    }
    // GLIM
    BigDecimal installmentsPaid = findNumberOfPaidInstallments();
    applyPaymentToMemberAccounts(paymentData, installmentsPaid);
    return accountPaymentEntity;
}
Also used : LoanBusinessService(org.mifos.accounts.loan.business.service.LoanBusinessService) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanPaymentTypes(org.mifos.accounts.loan.util.helpers.LoanPaymentTypes) BigDecimal(java.math.BigDecimal) AccountOverpaymentEntity(org.mifos.accounts.business.AccountOverpaymentEntity)

Example 4 with AccountPaymentEntity

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

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

the class LoanBO method applyMifos4948FixPayment.

/*
 * Mifos-4948 specific code
 */
public void applyMifos4948FixPayment(Money totalMissedPayment) throws AccountException {
    String comment = "MIFOS-4948 - Loan: " + this.getGlobalAccountNum() + " - Adding payment: " + totalMissedPayment;
    try {
        PersonnelBO currentUser = legacyPersonnelDao.getPersonnel((short) 1);
        Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
        AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, totalMissedPayment, null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
        addAccountPayment(accountPaymentEntity);
        accountPaymentEntity.setComment(comment);
        AccountActionTypes accountActionTypes;
        String accountConstants;
        if (this.getAccountState().getId().equals(AccountState.LOAN_CLOSED_WRITTEN_OFF.getValue())) {
            accountActionTypes = AccountActionTypes.WRITEOFF;
            accountConstants = AccountConstants.LOAN_WRITTEN_OFF;
        } else {
            accountActionTypes = AccountActionTypes.LOAN_RESCHEDULED;
            accountConstants = AccountConstants.LOAN_RESCHEDULED;
        }
        makeWriteOffOrReschedulePaymentForMifos4948(accountPaymentEntity, accountConstants, accountActionTypes, currentUser);
        addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, accountConstants, transactionDate));
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)113 Money (org.mifos.framework.util.helpers.Money)56 Date (java.util.Date)43 LocalDate (org.joda.time.LocalDate)41 Test (org.junit.Test)36 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)34 AccountException (org.mifos.accounts.exceptions.AccountException)30 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)24 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)23 UserContext (org.mifos.security.util.UserContext)23 ArrayList (java.util.ArrayList)22 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)22 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 PaymentData (org.mifos.accounts.util.helpers.PaymentData)18 CustomerBO (org.mifos.customers.business.CustomerBO)18 AccountBO (org.mifos.accounts.business.AccountBO)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 BigDecimal (java.math.BigDecimal)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 Date (java.sql.Date)13