Search in sources :

Example 6 with RateFeeBO

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);
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) MeetingHelper(org.mifos.application.meeting.util.helpers.MeetingHelper) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO)

Example 7 with RateFeeBO

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);
    }
}
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 8 with RateFeeBO

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());
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) FeeActionForm(org.mifos.accounts.fees.struts.actionforms.FeeActionForm) Test(org.junit.Test)

Example 9 with RateFeeBO

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;
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Money(org.mifos.framework.util.helpers.Money) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) FeeDto(org.mifos.accounts.fees.business.FeeDto) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO)

Example 10 with RateFeeBO

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));
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

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