use of org.mifos.accounts.business.AccountPenaltiesEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method assembleAccountPenalties.
private List<AccountPenaltiesEntity> assembleAccountPenalties(List<CreateAccountPenaltyDto> defaultAccountPenalties) {
List<AccountPenaltiesEntity> accountPenaltyEntities = new ArrayList<AccountPenaltiesEntity>();
for (CreateAccountPenaltyDto defaultPenalty : defaultAccountPenalties) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(defaultPenalty.getPenaltyId().shortValue());
AccountPenaltiesEntity deafultAccountPenaltyEntity = new AccountPenaltiesEntity(null, penalty, Double.valueOf(defaultPenalty.getAmount()));
accountPenaltyEntities.add(deafultAccountPenaltyEntity);
}
return accountPenaltyEntities;
}
use of org.mifos.accounts.business.AccountPenaltiesEntity 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);
}
}
use of org.mifos.accounts.business.AccountPenaltiesEntity in project head by mifos.
the class LoanBO method updateLoanAccountPenaltiesEntity.
protected void updateLoanAccountPenaltiesEntity(final Short penaltyId) {
AccountPenaltiesEntity accountPenalty = getAccountPenalty(penaltyId);
if (accountPenalty != null) {
accountPenalty.changePenaltyStatus(PenaltyStatus.INACTIVE, getDateTimeService().getCurrentJavaDateTime());
accountPenalty.setLastAppliedDate(null);
}
}
use of org.mifos.accounts.business.AccountPenaltiesEntity in project head by mifos.
the class LoanBO method applyMifos5722Fix.
public void applyMifos5722Fix() throws AccountException, PersistenceException {
if (!validateNoOfInstallments(getMemberAccounts().iterator().next()))
return;
PersonnelBO personnel = legacyPersonnelDao.getPersonnel((short) 1);
UserContext userContext = new UserContext();
userContext.setId(PersonnelConstants.SYSTEM_USER);
String comment = "Mifos-5722";
//clear accounts from previous payments
for (LoanBO memberAccount : getMemberAccounts()) {
memberAccount.setUserContext(userContext);
memberAccount.setAccountState(getAccountState());
for (AccountPaymentEntity payment : memberAccount.getAccountPayments()) {
memberAccount.adjustPayment(payment, personnel, comment);
}
}
List<LoanScheduleEntity> parentInstallments = getLoanInstallments();
for (LoanBO memberAccount : getMemberAccounts()) {
List<LoanScheduleEntity> memberInstallments = memberAccount.getLoanInstallments();
for (int i = 0; i < parentInstallments.size(); i++) {
LoanScheduleEntity parentInstallment = parentInstallments.get(i);
LoanScheduleEntity memberInstallment = memberInstallments.get(i);
//remove fees and penalties from installment
memberInstallment.removeAllFees();
memberInstallment.removeAllPenalties();
equalizeMiscFeesAndPenaltiesOnInstallments(parentInstallment, memberInstallment, memberAccount.calcFactorOfEntireLoan());
}
//remove fees and penalties from account
while (memberAccount.getAccountFeesIncludingInactiveFees().iterator().hasNext()) {
AccountFeesEntity fee = memberAccount.getAccountFeesIncludingInactiveFees().iterator().next();
memberAccount.getAccountFeesIncludingInactiveFees().remove(fee);
}
while (memberAccount.getAccountPenaltiesIncludingInactivePenalties().iterator().hasNext()) {
AccountPenaltiesEntity penalty = memberAccount.getAccountPenaltiesIncludingInactivePenalties().iterator().next();
memberAccount.getAccountPenaltiesIncludingInactivePenalties().remove(penalty);
}
}
//apply fees and penalties
Set<AccountFeesEntity> fees = getAccountFees();
Set<AccountPenaltiesEntity> penalties = getAccountPenalties();
for (LoanBO memberAccount : getMemberAccounts()) {
for (AccountFeesEntity fee : fees) {
try {
if (fee.getFees().getFeeType() == RateAmountFlag.RATE) {
RateFeeBO fbo = getFeeDao().findRateFeeById(fee.getFees().getFeeId());
if (fbo != null) {
memberAccount.applyChargeMifos5722(fee.getFees().getFeeId(), fbo.getRate());
}
} else {
memberAccount.applyChargeMifos5722(fee.getFees().getFeeId(), fee.getFeeAmount() / memberAccount.calcFactorOfEntireLoan().doubleValue());
}
} catch (AccountException e) {
e.printStackTrace();
}
for (AccountPenaltiesEntity penalty : penalties) {
memberAccount.addAccountPenalty(penalty);
}
}
}
applyAllPenaltiesToMemberAccounts();
List<AccountPaymentEntity> parentPayments = getAccountPayments();
BigDecimal currentAmount = BigDecimal.ZERO;
for (int i = parentPayments.size() - 2; i >= 0; i--) {
AccountPaymentEntity currentPayment = parentPayments.get(i);
currentAmount = currentAmount.add(currentPayment.getAmount().getAmount());
BigDecimal currentProportion = findNumberOfInstallmentsPaidByAmount(currentAmount);
PaymentData paymentData = new PaymentData(currentPayment.getAmount(), personnel, currentPayment.getPaymentType().getId(), currentPayment.getPaymentDate());
applyPaymentToMemberAccounts(paymentData, currentProportion);
}
}
use of org.mifos.accounts.business.AccountPenaltiesEntity in project head by mifos.
the class LoanBO method getAccountPenalty.
/**
* If the given {@PenaltyBO} has not yet been applied to this account, build and return a new
* {@link AccountPenaltiesEntity} linking this account to the penalty; otherwise return the link object with the penalty amount
* replaced with the charge.
*
* @param penalty
* the penalty to apply or update
* @param charge
* the amount to charge for the given penalty
* @return return the new or updated {@link AccountPenaltiesEntity} linking this account to the penalty
*/
protected final AccountPenaltiesEntity getAccountPenalty(final PenaltyBO penalty, final Double charge) {
AccountPenaltiesEntity accountPenalty = null;
if (!penalty.isOneTime() && isPenaltyAlreadyApplied(penalty)) {
accountPenalty = getAccountPenalty(penalty.getPenaltyId());
accountPenalty.setPenaltyAmount(charge);
accountPenalty.setPenaltyStatus(PenaltyStatus.ACTIVE);
accountPenalty.setStatusChangeDate(getDateTimeService().getCurrentJavaDateTime());
} else {
accountPenalty = new AccountPenaltiesEntity(this, penalty, charge, PenaltyStatus.ACTIVE.getValue(), null, null);
}
return accountPenalty;
}
Aggregations