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);
}
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);
}
}
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);
}
}
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);
}
Aggregations