use of org.mifos.accounts.penalties.business.RatePenaltyBO in project head by mifos.
the class WebTierPenaltyServiceFacade method updatePenalty.
@Override
public void updatePenalty(PenaltyFormDto dto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(dto.getId());
penaltyBO.updateDetails(userContext);
try {
PenaltyFrequency penaltyFrequency = dto.getPenaltyFrequency() != null ? PenaltyFrequency.getPenaltyFrequencyType(dto.getPenaltyFrequency()) : null;
PenaltyPeriod penaltyPeriod = dto.getPenaltyPeriod() != null ? PenaltyPeriod.getPenaltyPeriod(dto.getPenaltyPeriod()) : null;
PenaltyFormula penaltyFormula = dto.getPenaltyFormula() != null ? PenaltyFormula.getPenaltyFormula(dto.getPenaltyFormula()) : null;
PenaltyStatus penaltyStatus = dto.getPenaltyStatus() != null ? PenaltyStatus.getPenaltyStatus(dto.getPenaltyStatus()) : null;
penaltyBO.setPeriodType(this.penaltyDao.findPenaltyPeriodEntityByType(penaltyPeriod));
penaltyBO.setPenaltyFrequency(this.penaltyDao.findPenaltyFrequencyEntityByType(penaltyFrequency));
penaltyBO.setPenaltyName(dto.getPenaltyName());
penaltyBO.setPeriodDuration(dto.getDuration());
penaltyBO.setMinimumLimit(dto.getMin());
penaltyBO.setMaximumLimit(dto.getMax());
penaltyBO.setStatus(this.penaltyDao.findPenaltyStatusEntityByType(penaltyStatus));
penaltyBO.setGlCode(this.generalLedgerDao.findGlCodeById(dto.getGlCode()));
if (dto.isRatePenalty()) {
RatePenaltyBO ratePenaltyBO = (RatePenaltyBO) penaltyBO;
ratePenaltyBO.setRate(dto.getRate());
ratePenaltyBO.setFormula(this.penaltyDao.findPenaltyFormulaEntityByType(penaltyFormula));
} else {
AmountPenaltyBO amountPenaltyBO = (AmountPenaltyBO) penaltyBO;
amountPenaltyBO.setAmount(new Money(getCurrency(dto.getCurrencyId()), dto.getAmount()));
}
try {
StaticHibernateUtil.startTransaction();
this.penaltyDao.save(penaltyBO);
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.accounts.penalties.business.RatePenaltyBO in project head by mifos.
the class LoanBusinessService method populaleApplicableCharge.
private void populaleApplicableCharge(List<ApplicableCharge> applicableChargeList, List<PenaltyBO> penaltyList, UserContext userContext) {
for (PenaltyBO penalty : penaltyList) {
ApplicableCharge applicableCharge = new ApplicableCharge();
applicableCharge.setFeeId(penalty.getPenaltyId().toString());
applicableCharge.setFeeName(penalty.getPenaltyName());
applicableCharge.setIsPenaltyType(true);
if (penalty instanceof RatePenaltyBO) {
applicableCharge.setAmountOrRate(new LocalizationConverter().getDoubleStringForInterest(((RatePenaltyBO) penalty).getRate()));
applicableCharge.setFormula(((RatePenaltyBO) penalty).getFormula().getFormulaStringThatHasName());
applicableCharge.setIsRateType(true);
} else {
applicableCharge.setAmountOrRate(((AmountPenaltyBO) penalty).getAmount().toString());
applicableCharge.setIsRateType(false);
}
if (!penalty.isOneTime()) {
applicableCharge.setPeriodicity("true");
applicableCharge.setFormula(penalty.getPenaltyFrequency().getName());
}
applicableChargeList.add(applicableCharge);
}
}
Aggregations