Search in sources :

Example 21 with FeeBO

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

the class LoanBO method applyChargeMifos5722.

public void applyChargeMifos5722(final Short feeId, final Double charge) throws AccountException {
    List<AccountActionDateEntity> dueInstallments = getAllInstallments();
    FeeBO fee = getFeeDao().findById(feeId);
    if (fee.getFeeFrequency().getFeePayment() != null) {
        applyOneTimeFee(fee, charge, dueInstallments.get(0));
    } else {
        applyPeriodicFee(fee, charge, dueInstallments);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO)

Example 22 with FeeBO

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

the class WebTierAccountServiceFacade method applyGroupCharge.

@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);
    try {
        AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId())).getParentAccount();
        BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
        BigDecimal membersAmount = BigDecimal.ZERO;
        for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
            LoanBO individual = loanDao.findById(entry.getKey());
            Double chargeAmount = Double.valueOf(entry.getValue());
            if (chargeAmount.equals(0.0)) {
                continue;
            }
            membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
            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 {
                individual.applyCharge(chargeId, chargeAmount);
            }
        }
        boolean isRateCharge = false;
        if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES)) && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
            if (isPenaltyType) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                if (penalty instanceof RatePenaltyBO) {
                    isRateCharge = true;
                }
            } else {
                FeeBO fee = feeDao.findById(chargeId);
                if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
                    isRateCharge = true;
                }
            }
        }
        Double chargeAmount = null;
        if (!isRateCharge) {
            chargeAmount = sumCharge(idsAndValues);
        } else {
            chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
            BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
            membersAmount = membersAmount.multiply(chargeAmountBig);
            int scale = Money.getInternalPrecision();
            chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
            chargeAmount = chargeAmountBig.doubleValue();
        }
        parentAccount.updateDetails(userContext);
        CustomerLevel customerLevel = null;
        if (parentAccount.isCustomerAccount()) {
            customerLevel = parentAccount.getCustomer().getLevel();
        }
        if (parentAccount.getPersonnel() != null) {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        if (isPenaltyType && parentAccount instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) parentAccount).addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
        } else {
            parentAccount.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 : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) 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) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal) 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) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 23 with FeeBO

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

the class ApplyCustomerFeeChangesHelper method execute.

@Override
public void execute(@SuppressWarnings("unused") long timeInMillis) throws BatchJobException {
    List<String> errorList = new ArrayList<String>();
    List<Short> updatedFeeIds = new ArrayList<Short>();
    try {
        updatedFeeIds = getFeeDao().getUpdatedFeesForCustomer();
    } catch (Exception e) {
        errorList.add(e.getMessage());
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
    for (Short feeId : updatedFeeIds) {
        try {
            FeeBO hydratedFee = getFeeDao().findById(feeId);
            if (!hydratedFee.getFeeChangeType().equals(FeeChangeType.NOT_UPDATED)) {
                List<AccountBO> accounts = new CustomerPersistence().getCustomerAccountsForFee(hydratedFee.getFeeId());
                if (accounts != null && accounts.size() > 0) {
                    for (AccountBO account : accounts) {
                        updateAccountFee(account, hydratedFee);
                    }
                }
            }
            hydratedFee.updateFeeChangeType(FeeChangeType.NOT_UPDATED);
            UserContext userContext = new UserContext();
            userContext.setId(PersonnelConstants.SYSTEM_USER);
            hydratedFee.setUserContext(userContext);
            hydratedFee.save();
            StaticHibernateUtil.commitTransaction();
        } catch (Exception e) {
            StaticHibernateUtil.rollbackTransaction();
            errorList.add("feeId: " + feeId);
        }
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException)

Example 24 with FeeBO

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

the class AccountActionDateEntityIntegrationTest method testApplyPeriodicFees.

@Test
public void testApplyPeriodicFees() {
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
    AccountFeesEntity accountFeesEntity = new AccountFeesEntity(group.getCustomerAccount(), periodicFee, ((AmountFeeBO) periodicFee).getFeeAmount().getAmountDoubleValue(), null, null, new Date(System.currentTimeMillis()));
    group.getCustomerAccount().addAccountFees(accountFeesEntity);
    TestObjectFactory.updateObject(group);
    StaticHibernateUtil.flushSession();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    CustomerScheduleEntity accountActionDateEntity = (CustomerScheduleEntity) group.getCustomerAccount().getAccountActionDates().toArray()[0];
    Set<AccountFeesActionDetailEntity> feeDetailsSet = accountActionDateEntity.getAccountFeesActionDetails();
    List<Integer> feeList = new ArrayList<Integer>();
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : feeDetailsSet) {
        feeList.add(accountFeesActionDetailEntity.getAccountFeesActionDetailId());
    }
    Set<AccountFeesEntity> accountFeeSet = group.getCustomerAccount().getAccountFees();
    for (AccountFeesEntity accFeesEntity : accountFeeSet) {
        if (accFeesEntity.getFees().getFeeName().equalsIgnoreCase("Periodic Fee")) {
            CustomerAccountBOTestUtils.applyPeriodicFees(accountActionDateEntity, accFeesEntity.getFees().getFeeId(), new Money(getCurrency(), "100"));
            break;
        }
    }
    TestObjectFactory.updateObject(group);
    StaticHibernateUtil.flushSession();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    CustomerScheduleEntity firstInstallment = (CustomerScheduleEntity) group.getCustomerAccount().getAccountActionDates().toArray()[0];
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : firstInstallment.getAccountFeesActionDetails()) {
        if (!feeList.contains(accountFeesActionDetailEntity.getAccountFeesActionDetailId())) {
            Assert.assertEquals("Periodic Fee", accountFeesActionDetailEntity.getFee().getFeeName());
            break;
        }
    }
    StaticHibernateUtil.flushSession();
    groupLoan = TestObjectFactory.getObject(LoanBO.class, groupLoan.getAccountId());
    group = TestObjectFactory.getGroup(group.getCustomerId());
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Date(java.util.Date) Money(org.mifos.framework.util.helpers.Money) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Test(org.junit.Test)

Example 25 with FeeBO

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

the class AccountBOIntegrationTest method testGetPeriodicFeeList.

@Ignore
@Test
public void testGetPeriodicFeeList() throws PersistenceException {
    FeeBO oneTimeFee = TestObjectFactory.createOneTimeAmountFee("One Time Fee", FeeCategory.LOAN, "20", FeePayment.TIME_OF_DISBURSEMENT);
    AccountFeesEntity accountOneTimeFee = new AccountFeesEntity(groupLoan, oneTimeFee, new Double("1.0"));
    groupLoan.addAccountFees(accountOneTimeFee);
    legacyAccountDao.createOrUpdate(groupLoan);
    StaticHibernateUtil.flushSession();
    groupLoan = TestObjectFactory.getObject(LoanBO.class, groupLoan.getAccountId());
    Assert.assertEquals(1, groupLoan.getPeriodicFeeList().size());
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) FeeBO(org.mifos.accounts.fees.business.FeeBO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FeeBO (org.mifos.accounts.fees.business.FeeBO)89 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)50 ArrayList (java.util.ArrayList)40 Test (org.junit.Test)37 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)25 RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)21 Money (org.mifos.framework.util.helpers.Money)21 MeetingBO (org.mifos.application.meeting.business.MeetingBO)17 Date (java.sql.Date)15 FeeDto (org.mifos.accounts.fees.business.FeeDto)13 MifosRuntimeException (org.mifos.core.MifosRuntimeException)13 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)11 FundBO (org.mifos.accounts.fund.business.FundBO)10 ApplicationException (org.mifos.framework.exceptions.ApplicationException)10 UserContext (org.mifos.security.util.UserContext)10 AccountBO (org.mifos.accounts.business.AccountBO)9 FeeFrequencyTypeEntity (org.mifos.accounts.fees.business.FeeFrequencyTypeEntity)9 FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)9 ScheduledEventBuilder (org.mifos.domain.builders.ScheduledEventBuilder)9 CategoryTypeEntity (org.mifos.accounts.fees.business.CategoryTypeEntity)8