use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.
the class AccountBusinessService method populaleApplicableCharge.
private void populaleApplicableCharge(List<ApplicableCharge> applicableChargeList, List<FeeBO> feeList, UserContext userContext) {
for (FeeBO fee : feeList) {
ApplicableCharge applicableCharge = new ApplicableCharge();
applicableCharge.setFeeId(fee.getFeeId().toString());
applicableCharge.setFeeName(fee.getFeeName());
applicableCharge.setIsPenaltyType(false);
if (fee.getFeeType().getValue().equals(RateAmountFlag.RATE.getValue())) {
applicableCharge.setAmountOrRate(new LocalizationConverter().getDoubleStringForInterest(((RateFeeBO) fee).getRate()));
applicableCharge.setFormula(((RateFeeBO) fee).getFeeFormula().getFormulaStringThatHasName());
applicableCharge.setIsRateType(true);
} else {
applicableCharge.setAmountOrRate(((AmountFeeBO) fee).getFeeAmount().toString());
applicableCharge.setIsRateType(false);
}
MeetingBO meeting = fee.getFeeFrequency().getFeeMeetingFrequency();
if (meeting != null) {
applicableCharge.setPeriodicity(new MeetingHelper().getDetailMessageWithFrequency(meeting, userContext));
} else {
applicableCharge.setPaymentType(fee.getFeeFrequency().getFeePayment().getName());
}
applicableChargeList.add(applicableCharge);
}
}
use of org.mifos.accounts.fees.business.RateFeeBO 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);
}
}
use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.
the class FeeActionStrutsTest method testSuccessfulCreatePeriodicFeeWithFormula.
@Test
public void testSuccessfulCreatePeriodicFeeWithFormula() throws Exception {
setRequestPathInfo("/feeaction.do");
addRequestParameter("method", "load");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
flowKey = request.getAttribute(Constants.CURRENTFLOWKEY).toString();
setRequestPathInfo("/feeaction.do");
addRequestParameter("method", "preview");
addRequestParameter("categoryType", FeeCategory.LOAN.getValue().toString());
addRequestParameter("currencyId", TestUtils.RUPEE.getCurrencyId().toString());
addRequestParameter("rate", "23");
addRequestParameter("amount", "");
addRequestParameter("feeFormula", FeeFormula.AMOUNT.getValue().toString());
addRequestParameter("feeName", "Loan_Periodic_Fee");
addRequestParameter("customerDefaultFee", "0");
addRequestParameter("feeFrequencyType", FeeFrequencyType.PERIODIC.getValue().toString());
addRequestParameter("feeRecurrenceType", RecurrenceType.WEEKLY.getValue().toString());
addRequestParameter("weekRecurAfter", "2");
addRequestParameter("glCode", GLOCDE_ID);
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyNoActionErrors();
setRequestPathInfo("/feeaction.do");
addRequestParameter("method", "create");
addRequestParameter("org.apache.struts.taglib.html.TOKEN", (String) request.getSession().getAttribute("org.apache.struts.action.TOKEN"));
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyNoActionErrors();
verifyForward(ActionForwards.create_success.toString());
FeeActionForm actionForm = (FeeActionForm) request.getSession().getAttribute("feeactionform");
fee = (FeeBO) TestObjectFactory.getObject(FeeBO.class, actionForm.getFeeIdValue());
Assert.assertEquals("Loan_Periodic_Fee", fee.getFeeName());
Assert.assertEquals(FeeCategory.LOAN.getValue(), fee.getCategoryType().getId());
Assert.assertEquals(RateAmountFlag.RATE, fee.getFeeType());
Assert.assertEquals(23.0, ((RateFeeBO) fee).getRate(), DELTA);
Assert.assertEquals(((RateFeeBO) fee).getFeeFormula().getId(), FeeFormula.AMOUNT.getValue(), DELTA);
Assert.assertTrue(fee.isPeriodic());
Assert.assertTrue(fee.isActive());
}
use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.
the class LoanAccountActionFormTest method createDefaultFees.
private ArrayList<FeeDto> createDefaultFees() {
AmountFeeBO amountFee = createMock(AmountFeeBO.class);
expect(amountFee.getFeeId()).andReturn(Short.valueOf("1"));
expect(amountFee.getFeeType()).andReturn(RateAmountFlag.AMOUNT).times(2);
expect(amountFee.getFeeName()).andReturn("TestAmountFee");
expect(amountFee.getFeeAmount()).andReturn(new Money(TestUtils.RUPEE, "5000.0")).times(2);
expect(amountFee.isPeriodic()).andReturn(false).times(2);
replay(amountFee);
RateFeeBO rateFee = createMock(RateFeeBO.class);
expect(rateFee.getFeeId()).andReturn(Short.valueOf("1"));
expect(rateFee.getFeeType()).andReturn(RateAmountFlag.RATE).times(2);
expect(rateFee.getFeeName()).andReturn("TestRateFee");
expect(rateFee.getRate()).andReturn(2.12345);
expect(rateFee.getFeeFormula()).andReturn(createFeeFormulaEntityMock());
expect(rateFee.isPeriodic()).andReturn(false).times(2);
replay(rateFee);
UserContext userContext = createMock(UserContext.class);
expect(userContext.getLocaleId()).andReturn(Short.valueOf("1")).times(2);
replay(userContext);
ArrayList<FeeDto> defaultFees = new ArrayList<FeeDto>();
defaultFees.add(new FeeDto(userContext, amountFee));
defaultFees.add(new FeeDto(userContext, rateFee));
return defaultFees;
}
use of org.mifos.accounts.fees.business.RateFeeBO in project head by mifos.
the class LoanPrdActionFormTest method shouldNotAllowPeriodicFeeForVariableInstallmentLoanProduct.
@Test
public void shouldNotAllowPeriodicFeeForVariableInstallmentLoanProduct() {
String PERIODIC_FEE_2 = "2";
String NON_PERIODIC_FEE = "3";
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(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();
}
ActionMessageMatcher actionMessageMatcher = new ActionMessageMatcher(ProductDefinitionConstants.PERIODIC_FEE_NOT_APPLICABLE);
loanPrdActionForm.setCanConfigureVariableInstallments(true);
loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE });
loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors);
Mockito.verify(errors, Mockito.times(1)).add(Mockito.anyString(), Mockito.argThat(actionMessageMatcher));
}
Aggregations