use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments.
/**
* Remove the fee from all unpaid current or future installments, and update the loan accordingly.
*/
@Override
public final void removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(final Short feeId, final Short personnelId) throws AccountException {
List<Short> installmentIds = getApplicableInstallmentIdsForRemoveFees();
Money totalFeeAmount;
if (installmentIds != null && installmentIds.size() != 0 && isFeeActive(feeId)) {
FeeBO fee = getAccountFeesObject(feeId);
if (havePaymentsBeenMade() && fee.doesFeeInvolveFractionalAmounts()) {
throw new AccountException(AccountExceptionConstants.CANT_REMOVE_FEE_EXCEPTION);
}
if (fee.isTimeOfDisbursement()) {
AccountFeesEntity accountFee = getAccountFees(feeId);
totalFeeAmount = accountFee.getAccountFeeAmount();
removeAccountFee(accountFee);
this.delete(accountFee);
} else {
totalFeeAmount = updateAccountActionDateEntity(installmentIds, feeId);
updateAccountFeesEntity(feeId);
}
updateTotalFeeAmount(totalFeeAmount);
String description = fee.getFeeName() + " " + AccountConstants.FEES_REMOVED;
updateAccountActivity(null, null, totalFeeAmount, null, personnelId, description);
if (!havePaymentsBeenMade()) {
LoanScheduleRounderHelper loanScheduleRounderHelper = new DefaultLoanScheduleRounderHelper();
LoanScheduleRounder loanScheduleInstallmentRounder = getLoanScheduleRounder(loanScheduleRounderHelper);
List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
List<LoanScheduleEntity> allExistingLoanSchedules = new ArrayList<LoanScheduleEntity>();
List<AccountActionDateEntity> installmentsToRound = getInstallmentsToRound();
for (AccountActionDateEntity installment : installmentsToRound) {
unroundedLoanSchedules.add((LoanScheduleEntity) installment);
}
List<AccountActionDateEntity> allExistingInstallments = this.getAllInstallments();
for (AccountActionDateEntity installment : allExistingInstallments) {
allExistingLoanSchedules.add((LoanScheduleEntity) installment);
}
List<LoanScheduleEntity> roundedLoanSchedules = loanScheduleInstallmentRounder.round(this.gracePeriodType.asEnum(), this.gracePeriodDuration, this.loanAmount, this.interestType.asEnum(), unroundedLoanSchedules, allExistingLoanSchedules);
// applyRounding_v2();
}
try {
ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method updateLoan.
public void updateLoan(final Boolean interestDeductedAtDisbursement, final Money loanAmount, final Double interestRate, final Short noOfInstallments, final Date disbursementDate, final Short gracePeriodDuration, final Integer businessActivityId, final String collateralNote, final Integer collateralTypeId, final List<CustomFieldDto> customFields, final boolean isRepaymentIndepOfMeetingEnabled, final MeetingBO newMeetingForRepaymentDay, final FundBO fund) throws AccountException {
if (interestDeductedAtDisbursement) {
try {
if (noOfInstallments <= 1) {
throw new AccountException(LoanExceptionConstants.INVALIDNOOFINSTALLMENTS);
}
setGracePeriodType(legacyMasterDao.findMasterDataEntityWithLocale(GracePeriodTypeEntity.class, GraceType.NONE.getValue()));
} catch (PersistenceException e) {
throw new AccountException(e);
}
} else {
setGracePeriodType(getLoanOffering().getGracePeriodType());
}
setLoanAmount(loanAmount);
setInterestRate(interestRate);
setNoOfInstallments(noOfInstallments);
setGracePeriodDuration(gracePeriodDuration);
setInterestDeductedAtDisbursement(interestDeductedAtDisbursement);
setBusinessActivityId(businessActivityId);
setCollateralNote(collateralNote);
setCollateralTypeId(collateralTypeId);
setFund(fund);
if (getAccountState().getId().equals(AccountState.LOAN_APPROVED.getValue()) || getAccountState().getId().equals(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER.getValue()) || getAccountState().getId().equals(AccountState.LOAN_PARTIAL_APPLICATION.getValue()) || getAccountState().getId().equals(AccountState.LOAN_PENDING_APPROVAL.getValue())) {
// only check the disbursement date if it has changed
if (disbursementDate != null && !disbursementDate.equals(getDisbursementDate()) && isDisbursementDateLessThanCurrentDate(disbursementDate)) {
throw new AccountException(LoanExceptionConstants.ERROR_INVALIDDISBURSEMENTDATE);
}
setDisbursementDate(disbursementDate);
regeneratePaymentSchedule(isRepaymentIndepOfMeetingEnabled, newMeetingForRepaymentDay);
}
try {
updateCustomFields(customFields);
} catch (InvalidDateException ide) {
throw new AccountException(ide);
}
loanSummary.setOriginalPrincipal(loanAmount);
update();
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method waiveOverdueChargesFromMemberAccounts.
public void waiveOverdueChargesFromMemberAccounts(String chargeType) {
for (LoanBO member : getMemberAccounts()) {
List<AccountActionDateEntity> memberAccountActionDateList = member.getApplicableIdsForNextInstallmentAndArrears();
List<LoanScheduleEntity> overdueMemberAccountActionDateEntities = new ArrayList<LoanScheduleEntity>();
for (AccountActionDateEntity accountActionDateEntity : memberAccountActionDateList) {
if (accountActionDateEntity.getActionDate().before(DateUtils.getCurrentDateWithoutTimeStamp())) {
overdueMemberAccountActionDateEntities.add((LoanScheduleEntity) accountActionDateEntity);
}
}
Money principal = new Money(getCurrency());
Money interest = new Money(getCurrency());
Money fee = new Money(getCurrency());
Money penalty = new Money(getCurrency());
if (chargeType == LoanConstants.FEE_WAIVED) {
for (LoanScheduleEntity memberAccountActionDateEntity : overdueMemberAccountActionDateEntities) {
fee = fee.add(memberAccountActionDateEntity.waiveFeeCharges());
}
member.updateTotalFeeAmount(fee);
} else if (chargeType == LoanConstants.PENALTY_WAIVED) {
for (LoanScheduleEntity memberAccountActionDateEntity : overdueMemberAccountActionDateEntities) {
penalty = penalty.add(memberAccountActionDateEntity.waivePenaltyCharges());
}
member.updateTotalPenaltyAmount(penalty);
}
try {
member.updateAccountActivity(principal, interest, fee, penalty, userContext.getId(), chargeType);
} catch (AccountException e) {
throw new BusinessRuleException(e.getKey());
}
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class WebTierAccountServiceFacade method applyMemberAccountHistoricalAdjustment.
/**
* adjustment for member account payment has to be handled along with parent account payments and other members payments.
* This method prepares data and run applyHistoricalAdjustment so adjustment will be made for parent payment context.
*/
@Override
@PreAuthorize("isFullyAuthenticated()")
public void applyMemberAccountHistoricalAdjustment(String memberGlobalAccountNum, Integer memberPaymentId, String adjustmentNote, Short personnelId, AdjustedPaymentDto adjustedPaymentDto) {
try {
LoanBO memberAccount = (LoanBO) accountBusinessService.findBySystemId(memberGlobalAccountNum);
LoanBO parentAccount = memberAccount.getParentAccount();
if (parentAccount == null) {
throw new AccountException(LoanExceptionConstants.NO_PARENT_ACCOUNT_EXCEPTION);
}
AccountPaymentEntity parentPaymentEntity = memberAccount.findParentPaymentByMemberPaymentId(memberPaymentId);
List<AdjustedPaymentDto> membersAdjustedPaymentDtoList = new ArrayList<AdjustedPaymentDto>();
for (AccountPaymentEntity memberPayment : parentPaymentEntity.getMemberPayments()) {
if (memberPayment.getAccount().getAccountId().equals(memberAccount.getAccountId())) {
membersAdjustedPaymentDtoList.add(new AdjustedPaymentDto(adjustedPaymentDto.getAmount(), adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), memberAccount.getAccountId()));
} else {
membersAdjustedPaymentDtoList.add(new AdjustedPaymentDto(memberPayment.getAmount().getAmount().toString(), adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), memberPayment.getAccount().getAccountId()));
}
}
BigDecimal parentAmountSubstraction = memberAccount.findPaymentById(memberPaymentId).getAmount().getAmount().subtract((new BigDecimal(adjustedPaymentDto.getAmount())));
String newParentAmount = parentPaymentEntity.getAmount().getAmount().subtract(parentAmountSubstraction).toString();
AdjustedPaymentDto parentAdjustedPaymentDto = new AdjustedPaymentDto(newParentAmount, adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), parentAccount.getAccountId(), membersAdjustedPaymentDtoList);
this.applyHistoricalAdjustment(parentAccount.getGlobalAccountNum(), parentPaymentEntity.getPaymentId(), adjustmentNote, personnelId, parentAdjustedPaymentDto);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
} catch (AccountException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveSavingsAccountDetails.
@Override
public SavingsAccountDetailDto retrieveSavingsAccountDetails(String globalAccountNum) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
savingsAccount.setUserContext(userContext);
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
return savingsAccount.toDto();
}
Aggregations