@Override public void waiveChargesDue(Integer accountId, Integer waiveType) { MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserContext userContext = toUserContext(user); try { AccountBO account = new AccountBusinessService().getAccount(accountId); account.updateDetails(userContext); PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId()); WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType); if (account.getPersonnel() != null) { new AccountBusinessService() .checkPermissionForWaiveDue( waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId()); } else { new AccountBusinessService() .checkPermissionForWaiveDue( waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId()); } if (account.isLoanAccount()) { ((LoanBO) account).waiveAmountDue(waiveEnum); } else if (account.isSavingsAccount()) { ((SavingsBO) account).waiveNextDepositAmountDue(loggedInUser); } else { try { this.transactionHelper.startTransaction(); ((CustomerAccountBO) account).waiveAmountDue(); this.customerDao.save(account); this.transactionHelper.commitTransaction(); } catch (Exception e) { this.transactionHelper.rollbackTransaction(); throw new BusinessRuleException(account.getAccountId().toString(), e); } finally { this.transactionHelper.closeSession(); } } } catch (ServiceException e) { throw new MifosRuntimeException(e); } catch (ApplicationException e) { throw new BusinessRuleException(e.getKey(), e); } }