Search in sources :

Example 11 with RateFeeBO

use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.

the class LoanPrdActionFormTest method shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct.

@Test
public void shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct() {
    String PERIODIC_FEE_2 = "2";
    String NON_PERIODIC_FEE = "3";
    final FeeDto feeDto = Mockito.mock(FeeDto.class);
    loanPrdActionForm = new LoanPrdActionForm() {

        @Override
        FeeDto getFeeDto(@SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") FeeBO fee) {
            return feeDto;
        }
    };
    FeeFrequencyEntity feeFrequencyEntity = Mockito.mock(FeeFrequencyEntity.class);
    MeetingBO meetingBo = Mockito.mock(MeetingBO.class);
    MeetingDetailsEntity meetingDetailsEntity = Mockito.mock(MeetingDetailsEntity.class);
    when(periodicFeeRate.isPeriodic()).thenReturn(true);
    when(periodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(periodicFeeRate.getFeeId()).thenReturn(Short.valueOf(PERIODIC_FEE_2));
    when(periodicFeeRate.getFeeName()).thenReturn("periodic fee2");
    when((periodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
    when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
    when(periodicFeeRate.getFeeFrequency()).thenReturn(feeFrequencyEntity);
    when(nonPeriodicFeeRate.isPeriodic()).thenReturn(false);
    when(nonPeriodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(nonPeriodicFeeRate.getFeeId()).thenReturn(Short.valueOf(NON_PERIODIC_FEE));
    when(nonPeriodicFeeRate.getFeeName()).thenReturn("non Periodic fee");
    when(((RateFeeBO) nonPeriodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
    when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
    List<FeeBO> allPrdFees = new ArrayList<FeeBO>();
    allPrdFees.add(periodicFeeRate);
    allPrdFees.add(nonPeriodicFeeRate);
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    when(session.getAttribute(ProductDefinitionConstants.LOANPRDFEE)).thenReturn(allPrdFees);
    Flow flow = new Flow();
    try {
        when(flowManager.getFromFlow(Mockito.anyString(), Mockito.anyString())).thenReturn(allPrdFees);
        when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    } catch (PageExpiredException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    loanPrdActionForm.setCanConfigureVariableInstallments(false);
    loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE });
    loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors);
    Mockito.verifyZeroInteractions(errors);
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) FeeDto(org.mifos.accounts.fees.business.FeeDto) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Flow(org.mifos.framework.util.helpers.Flow) HttpServletRequest(javax.servlet.http.HttpServletRequest) MeetingDetailsEntity(org.mifos.application.meeting.business.MeetingDetailsEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) FeeFrequencyEntity(org.mifos.accounts.fees.business.FeeFrequencyEntity) Test(org.junit.Test)

Example 12 with RateFeeBO

use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.

the class LoanBO method populateAccountFeeAmount.

/**
     * @deprecated - see {@link InstallmentFeeCalculator}.
     */
@Deprecated
private void populateAccountFeeAmount(final Set<AccountFeesEntity> accountFees, final Money loanInterest) {
    for (AccountFeesEntity accountFeesEntity : accountFees) {
        Money accountFeeAmount1 = new Money(getCurrency());
        Double feeAmount = accountFeesEntity.getFeeAmount();
        if (accountFeesEntity.getFees().getFeeType() == RateAmountFlag.AMOUNT) {
            accountFeeAmount1 = new Money(getCurrency(), feeAmount.toString());
        } else if (accountFeesEntity.getFees().getFeeType() == RateAmountFlag.RATE) {
            RateFeeBO rateFeeBO = (RateFeeBO) getFeeDao().findById(accountFeesEntity.getFees().getFeeId());
            FeeFormulaEntity formula = rateFeeBO.getFeeFormula();
            Money amountToCalculateOn = new Money(getCurrency(), "1.0");
            if (formula.getId().equals(FeeFormula.AMOUNT.getValue())) {
                amountToCalculateOn = loanAmount;
            } else if (formula.getId().equals(FeeFormula.AMOUNT_AND_INTEREST.getValue())) {
                amountToCalculateOn = loanAmount.add(loanInterest);
            } else if (formula.getId().equals(FeeFormula.INTEREST.getValue())) {
                amountToCalculateOn = loanInterest;
            }
            Double rateAmount = amountToCalculateOn.multiply(feeAmount).divide(100).getAmountDoubleValue();
            String rateBasedOnFormula = rateAmount.toString();
            accountFeeAmount1 = new Money(getCurrency(), rateBasedOnFormula);
        }
        Money accountFeeAmount = accountFeeAmount1;
        accountFeesEntity.setAccountFeeAmount(accountFeeAmount);
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Money(org.mifos.framework.util.helpers.Money) FeeFormulaEntity(org.mifos.accounts.fees.business.FeeFormulaEntity) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

Example 13 with RateFeeBO

use of org.mifos.accounts.fees.business.RateFeeBO 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 14 with RateFeeBO

use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.

the class RateInstalmentFeeCalculator method calculate.

@Override
public Money calculate(Double feeRate, Money loanAmount, Money loanInterest, FeeBO fee) {
    // make sure that we are not using a proxied object when we cast
    RateFeeBO rateFeeBO = (RateFeeBO) feeDao.initializeAndUnproxy(fee);
    FeeFormulaEntity formula = rateFeeBO.getFeeFormula();
    Money amountToCalculateOn = new Money(loanAmount.getCurrency(), "1.0");
    if (formula.getId().equals(FeeFormula.AMOUNT.getValue())) {
        amountToCalculateOn = loanAmount;
    } else if (formula.getId().equals(FeeFormula.AMOUNT_AND_INTEREST.getValue())) {
        amountToCalculateOn = loanAmount.add(loanInterest);
    } else if (formula.getId().equals(FeeFormula.INTEREST.getValue())) {
        amountToCalculateOn = loanInterest;
    }
    return amountToCalculateOn.multiply(feeRate).divide(100);
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Money(org.mifos.framework.util.helpers.Money) FeeFormulaEntity(org.mifos.accounts.fees.business.FeeFormulaEntity)

Aggregations

RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)14 FeeBO (org.mifos.accounts.fees.business.FeeBO)8 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)6 FeeFormulaEntity (org.mifos.accounts.fees.business.FeeFormulaEntity)6 Money (org.mifos.framework.util.helpers.Money)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)3 UserContext (org.mifos.security.util.UserContext)3 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)2 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)2 CategoryTypeEntity (org.mifos.accounts.fees.business.CategoryTypeEntity)2 FeeDto (org.mifos.accounts.fees.business.FeeDto)2 FeeFrequencyTypeEntity (org.mifos.accounts.fees.business.FeeFrequencyTypeEntity)2 FeePaymentEntity (org.mifos.accounts.fees.business.FeePaymentEntity)2 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)2 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)2