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