Search in sources :

Example 46 with AccountActionDateEntity

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

the class LoanBO method getTotalInterestAmountInArrears.

public Money getTotalInterestAmountInArrears() {
    Money amount = new Money(getCurrency());
    List<AccountActionDateEntity> actionDateList = getDetailsOfInstallmentsInArrears();
    for (AccountActionDateEntity accountActionDateEntity : actionDateList) {
        LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity;
        amount = amount.add(loanScheduleEntity.getInterest().subtract(loanScheduleEntity.getInterestPaid()));
    }
    return amount;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity)

Example 47 with AccountActionDateEntity

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

the class LoanBO method makeWriteOffOrReschedulePaymentForFutureInstallments.

private void makeWriteOffOrReschedulePaymentForFutureInstallments(final AccountPaymentEntity accountPaymentEntity, final String comments, final AccountActionTypes accountActionTypes, final PersonnelBO currentUser) {
    List<AccountActionDateEntity> futureInstallmentsList = getApplicableIdsForFutureInstallmentsForWriteOffOrReschedule();
    for (AccountActionDateEntity accountActionDateEntity : futureInstallmentsList) {
        LoanScheduleEntity loanSchedule = (LoanScheduleEntity) accountActionDateEntity;
        Money principal = loanSchedule.getPrincipalDue();
        Money interest = loanSchedule.getInterestDue();
        Money fees = loanSchedule.getTotalFeeDueWithMiscFeeDue();
        Money penalty = loanSchedule.getPenaltyDue();
        LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPaymentEntity, accountActionTypes, loanSchedule.getInstallmentId(), loanSchedule.getActionDate(), currentUser, accountPaymentEntity.getPaymentDate(), principal, comments, null, principal, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
        accountPaymentEntity.addAccountTrxn(loanTrxnDetailEntity);
        loanSchedule.makeEarlyRepaymentEntries(LoanConstants.DONOT_PAY_FEES_PENALTY_INTEREST, loanSchedule.getInterestDue(), accountPaymentEntity.getPaymentDate());
        loanSummary.decreaseBy(null, interest, penalty, fees);
        updatePaymentDetails(accountActionTypes, principal, null, null, null);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money)

Example 48 with AccountActionDateEntity

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

the class LoanBO method applyPeriodicFee.

/**
     * The fee (new or to be updated) is applied to the given list of AccountActionDateEntity(s). Note that the entities
     * are the actual entity objects referenced by the loan, so this method acts by side-effect, adding fees to the
     * given entities.
     *
     * @param fee
     *            the periodic FeeBO to apply to the given AccountActionDateEntity(s)
     * @param charge
     *            the
     * @param dueInstallments
     * @throws AccountException
     * @throws PersistenceException
     */
private void applyPeriodicFee(final FeeBO fee, final Double charge, final List<AccountActionDateEntity> dueInstallments) throws AccountException {
    // Create an AccountFeesEntity linking the loan to the given fee fee and charge if the fee hasn't been applied,
    // or
    // update the applied fee's AccountFeesEntity.feeAmount with the given charge. Then set the
    // AccountFeeEntity.accountFeeAmount to this loan's originalInterest.
    AccountFeesEntity accountFee = getAccountFee(fee, charge);
    Set<AccountFeesEntity> accountFeeSet = new HashSet<AccountFeesEntity>();
    accountFeeSet.add(accountFee);
    populateAccountFeeAmount(accountFeeSet, loanSummary.getOriginalInterest());
    // Extract the list of InstallmentDate(s) from the given AccountActionDateEntity(s). Note that
    // the installmentId(s) likely do not start with 1 since the fee may be applied after some
    // installment dates have passed.
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    for (AccountActionDateEntity accountActionDateEntity : dueInstallments) {
        installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
    }
    // Get the full list of all loan InstallmentDate(s), past, present and future, without adjusting for holidays.
    // This will work correctly only if adjusting periodic fees is done when no installments have been paid
    //        boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    //        List<InstallmentDate> nonAdjustedInstallmentDates = getInstallmentDates(getLoanMeeting(), noOfInstallments,
    //                getInstallmentSkipToStartRepayment(), isRepaymentIndepOfMeetingEnabled,
    //                false);
    // Use handlePeriodic to adjust fee installments for holiday periods and combine multiple fee installments due
    // for the
    // same loan installment. Finally, apply these updated fees to the given dueInstallments list and update
    // loan summary and activity tables.
    /*
         * old way List<FeeInstallment> feeInstallmentList = mergeFeeInstallments(handlePeriodic(accountFee,
         * installmentDates, nonAdjustedInstallmentDates));
         */
    // new way
    ScheduledEvent loanScheduledEvent = ScheduledEventFactory.createScheduledEventFrom(this.getMeetingForAccount());
    List<FeeInstallment> feeInstallmentList = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(loanScheduledEvent, accountFee, dueInstallments.size(), dueInstallments.get(0).getInstallmentId());
    Money totalFeeAmountApplied = applyFeeToInstallments(feeInstallmentList, dueInstallments);
    updateLoanSummary(fee.getFeeId(), totalFeeAmountApplied);
    updateLoanActivity(fee.getFeeId(), totalFeeAmountApplied, fee.getFeeName() + AccountConstants.APPLIED);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) ScheduledEvent(org.mifos.schedule.ScheduledEvent) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 49 with AccountActionDateEntity

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

the class LoanBO method getApplicableIdsForLateInstallments.

private List<AccountActionDateEntity> getApplicableIdsForLateInstallments() {
    List<AccountActionDateEntity> lateActionDateList = new ArrayList<AccountActionDateEntity>();
    AccountActionDateEntity nextInstallment = getDetailsOfNextInstallment();
    if (nextInstallment != null) {
        for (AccountActionDateEntity accountActionDate : getAccountActionDates()) {
            if (!accountActionDate.isPaid() && accountActionDate.getInstallmentId() < nextInstallment.getInstallmentId()) {
                lateActionDateList.add(accountActionDate);
            }
        }
    } else {
        lateActionDateList.addAll(getAccountActionDates());
    }
    return lateActionDateList;
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) ArrayList(java.util.ArrayList)

Example 50 with AccountActionDateEntity

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

the class LoanBO method waiveOverdueChargesFromMemberAccounts.

public void waiveOverdueChargesFromMemberAccounts(String chargeType) {
    for (LoanBO member : getMemberAccounts()) {
        List<AccountActionDateEntity> memberAccountActionDateList = member.getApplicableIdsForNextInstallmentAndArrears();
        List<LoanScheduleEntity> overdueMemberAccountActionDateEntities = new ArrayList<LoanScheduleEntity>();
        for (AccountActionDateEntity accountActionDateEntity : memberAccountActionDateList) {
            if (accountActionDateEntity.getActionDate().before(DateUtils.getCurrentDateWithoutTimeStamp())) {
                overdueMemberAccountActionDateEntities.add((LoanScheduleEntity) accountActionDateEntity);
            }
        }
        Money principal = new Money(getCurrency());
        Money interest = new Money(getCurrency());
        Money fee = new Money(getCurrency());
        Money penalty = new Money(getCurrency());
        if (chargeType == LoanConstants.FEE_WAIVED) {
            for (LoanScheduleEntity memberAccountActionDateEntity : overdueMemberAccountActionDateEntities) {
                fee = fee.add(memberAccountActionDateEntity.waiveFeeCharges());
            }
            member.updateTotalFeeAmount(fee);
        } else if (chargeType == LoanConstants.PENALTY_WAIVED) {
            for (LoanScheduleEntity memberAccountActionDateEntity : overdueMemberAccountActionDateEntities) {
                penalty = penalty.add(memberAccountActionDateEntity.waivePenaltyCharges());
            }
            member.updateTotalPenaltyAmount(penalty);
        }
        try {
            member.updateAccountActivity(principal, interest, fee, penalty, userContext.getId(), chargeType);
        } catch (AccountException e) {
            throw new BusinessRuleException(e.getKey());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) ArrayList(java.util.ArrayList)

Aggregations

AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)211 Money (org.mifos.framework.util.helpers.Money)80 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)58 LocalDate (org.joda.time.LocalDate)42 Date (java.util.Date)39 DateTime (org.joda.time.DateTime)33 MeetingBO (org.mifos.application.meeting.business.MeetingBO)33 AccountException (org.mifos.accounts.exceptions.AccountException)24 PaymentData (org.mifos.accounts.util.helpers.PaymentData)24 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)21 Date (java.sql.Date)19 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)15 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)14 UserContext (org.mifos.security.util.UserContext)14 Calendar (java.util.Calendar)13 GregorianCalendar (java.util.GregorianCalendar)13 CenterBuilder (org.mifos.domain.builders.CenterBuilder)13