Search in sources :

Example 11 with AccountPenaltiesEntity

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

the class LoanAccountServiceFacadeWebTier method assembleAccountPenalties.

private List<AccountPenaltiesEntity> assembleAccountPenalties(List<CreateAccountPenaltyDto> defaultAccountPenalties) {
    List<AccountPenaltiesEntity> accountPenaltyEntities = new ArrayList<AccountPenaltiesEntity>();
    for (CreateAccountPenaltyDto defaultPenalty : defaultAccountPenalties) {
        PenaltyBO penalty = this.penaltyDao.findPenaltyById(defaultPenalty.getPenaltyId().shortValue());
        AccountPenaltiesEntity deafultAccountPenaltyEntity = new AccountPenaltiesEntity(null, penalty, Double.valueOf(defaultPenalty.getAmount()));
        accountPenaltyEntities.add(deafultAccountPenaltyEntity);
    }
    return accountPenaltyEntities;
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) ArrayList(java.util.ArrayList)

Example 12 with AccountPenaltiesEntity

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

the class WebTierAccountServiceFacade method applyCharge.

@Override
public void applyCharge(Integer accountId, Short chargeId, Double chargeAmount, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        if (account instanceof LoanBO && !account.isGroupLoanAccount()) {
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                        PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                        individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
                    } else {
                        FeeBO fee = this.feeDao.findById(chargeId);
                        if (fee instanceof RateFeeBO) {
                            individual.applyCharge(chargeId, chargeAmount);
                        } else {
                            Double radio = individual.getLoanAmount().getAmount().doubleValue() / ((LoanBO) account).getLoanAmount().getAmount().doubleValue();
                            individual.applyCharge(chargeId, chargeAmount * radio);
                        }
                    }
                }
            }
        }
        account.updateDetails(userContext);
        CustomerLevel customerLevel = null;
        if (account.isCustomerAccount()) {
            customerLevel = account.getCustomer().getLevel();
        }
        if (account.getPersonnel() != null) {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        if (isPenaltyType && account instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) account).addAccountPenalty(new AccountPenaltiesEntity(account, penalty, chargeAmount));
        } else {
            account.applyCharge(chargeId, chargeAmount);
        }
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) CustomerLevel(org.mifos.customers.api.CustomerLevel) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 13 with AccountPenaltiesEntity

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

the class LoanBO method updateLoanAccountPenaltiesEntity.

protected void updateLoanAccountPenaltiesEntity(final Short penaltyId) {
    AccountPenaltiesEntity accountPenalty = getAccountPenalty(penaltyId);
    if (accountPenalty != null) {
        accountPenalty.changePenaltyStatus(PenaltyStatus.INACTIVE, getDateTimeService().getCurrentJavaDateTime());
        accountPenalty.setLastAppliedDate(null);
    }
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity)

Example 14 with AccountPenaltiesEntity

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

the class LoanBO method applyMifos5722Fix.

public void applyMifos5722Fix() throws AccountException, PersistenceException {
    if (!validateNoOfInstallments(getMemberAccounts().iterator().next()))
        return;
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel((short) 1);
    UserContext userContext = new UserContext();
    userContext.setId(PersonnelConstants.SYSTEM_USER);
    String comment = "Mifos-5722";
    //clear accounts from previous payments
    for (LoanBO memberAccount : getMemberAccounts()) {
        memberAccount.setUserContext(userContext);
        memberAccount.setAccountState(getAccountState());
        for (AccountPaymentEntity payment : memberAccount.getAccountPayments()) {
            memberAccount.adjustPayment(payment, personnel, comment);
        }
    }
    List<LoanScheduleEntity> parentInstallments = getLoanInstallments();
    for (LoanBO memberAccount : getMemberAccounts()) {
        List<LoanScheduleEntity> memberInstallments = memberAccount.getLoanInstallments();
        for (int i = 0; i < parentInstallments.size(); i++) {
            LoanScheduleEntity parentInstallment = parentInstallments.get(i);
            LoanScheduleEntity memberInstallment = memberInstallments.get(i);
            //remove fees and penalties from installment
            memberInstallment.removeAllFees();
            memberInstallment.removeAllPenalties();
            equalizeMiscFeesAndPenaltiesOnInstallments(parentInstallment, memberInstallment, memberAccount.calcFactorOfEntireLoan());
        }
        //remove fees and penalties from account
        while (memberAccount.getAccountFeesIncludingInactiveFees().iterator().hasNext()) {
            AccountFeesEntity fee = memberAccount.getAccountFeesIncludingInactiveFees().iterator().next();
            memberAccount.getAccountFeesIncludingInactiveFees().remove(fee);
        }
        while (memberAccount.getAccountPenaltiesIncludingInactivePenalties().iterator().hasNext()) {
            AccountPenaltiesEntity penalty = memberAccount.getAccountPenaltiesIncludingInactivePenalties().iterator().next();
            memberAccount.getAccountPenaltiesIncludingInactivePenalties().remove(penalty);
        }
    }
    //apply fees and penalties
    Set<AccountFeesEntity> fees = getAccountFees();
    Set<AccountPenaltiesEntity> penalties = getAccountPenalties();
    for (LoanBO memberAccount : getMemberAccounts()) {
        for (AccountFeesEntity fee : fees) {
            try {
                if (fee.getFees().getFeeType() == RateAmountFlag.RATE) {
                    RateFeeBO fbo = getFeeDao().findRateFeeById(fee.getFees().getFeeId());
                    if (fbo != null) {
                        memberAccount.applyChargeMifos5722(fee.getFees().getFeeId(), fbo.getRate());
                    }
                } else {
                    memberAccount.applyChargeMifos5722(fee.getFees().getFeeId(), fee.getFeeAmount() / memberAccount.calcFactorOfEntireLoan().doubleValue());
                }
            } catch (AccountException e) {
                e.printStackTrace();
            }
            for (AccountPenaltiesEntity penalty : penalties) {
                memberAccount.addAccountPenalty(penalty);
            }
        }
    }
    applyAllPenaltiesToMemberAccounts();
    List<AccountPaymentEntity> parentPayments = getAccountPayments();
    BigDecimal currentAmount = BigDecimal.ZERO;
    for (int i = parentPayments.size() - 2; i >= 0; i--) {
        AccountPaymentEntity currentPayment = parentPayments.get(i);
        currentAmount = currentAmount.add(currentPayment.getAmount().getAmount());
        BigDecimal currentProportion = findNumberOfInstallmentsPaidByAmount(currentAmount);
        PaymentData paymentData = new PaymentData(currentPayment.getAmount(), personnel, currentPayment.getPaymentType().getId(), currentPayment.getPaymentDate());
        applyPaymentToMemberAccounts(paymentData, currentProportion);
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) BigDecimal(java.math.BigDecimal) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

Example 15 with AccountPenaltiesEntity

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

the class LoanBO method getAccountPenalty.

/**
     * If the given {@PenaltyBO} has not yet been applied to this account, build and return a new
     * {@link AccountPenaltiesEntity} linking this account to the penalty; otherwise return the link object with the penalty amount
     * replaced with the charge.
     *
     * @param penalty
     *            the penalty to apply or update
     * @param charge
     *            the amount to charge for the given penalty
     * @return return the new or updated {@link AccountPenaltiesEntity} linking this account to the penalty
     */
protected final AccountPenaltiesEntity getAccountPenalty(final PenaltyBO penalty, final Double charge) {
    AccountPenaltiesEntity accountPenalty = null;
    if (!penalty.isOneTime() && isPenaltyAlreadyApplied(penalty)) {
        accountPenalty = getAccountPenalty(penalty.getPenaltyId());
        accountPenalty.setPenaltyAmount(charge);
        accountPenalty.setPenaltyStatus(PenaltyStatus.ACTIVE);
        accountPenalty.setStatusChangeDate(getDateTimeService().getCurrentJavaDateTime());
    } else {
        accountPenalty = new AccountPenaltiesEntity(this, penalty, charge, PenaltyStatus.ACTIVE.getValue(), null, null);
    }
    return accountPenalty;
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity)

Aggregations

AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)17 ArrayList (java.util.ArrayList)11 UserContext (org.mifos.security.util.UserContext)11 MifosUser (org.mifos.security.MifosUser)10 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)9 LoanBO (org.mifos.accounts.loan.business.LoanBO)9 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)7 LocalDate (org.joda.time.LocalDate)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)6 LoanProductOverridenDetail (org.mifos.clientportfolio.newloan.domain.LoanProductOverridenDetail)6 LoanSchedule (org.mifos.clientportfolio.newloan.domain.LoanSchedule)6 LoanScheduleConfiguration (org.mifos.clientportfolio.newloan.domain.LoanScheduleConfiguration)6 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 Money (org.mifos.framework.util.helpers.Money)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 BigDecimal (java.math.BigDecimal)5 AmountPenaltyBO (org.mifos.accounts.penalties.business.AmountPenaltyBO)5 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5