use of org.mifos.accounts.penalties.business.PenaltyPeriodEntity in project head by mifos.
the class WebTierPenaltyServiceFacade method createPenalty.
@Override
public void createPenalty(PenaltyFormDto dto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
PenaltyCategory penaltyCategory = dto.getCategoryType() != null ? PenaltyCategory.getPenaltyCategory(dto.getCategoryType()) : null;
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;
PenaltyCategoryEntity penaltyCategoryEntity = this.penaltyDao.findPenaltyCategoryEntityByType(penaltyCategory);
PenaltyPeriodEntity penaltyPeriodEntity = this.penaltyDao.findPenaltyPeriodEntityByType(penaltyPeriod);
PenaltyFrequencyEntity penaltyFrequencyEntity = this.penaltyDao.findPenaltyFrequencyEntityByType(penaltyFrequency);
GLCodeEntity glCodeEntity = this.generalLedgerDao.findGlCodeById(dto.getGlCode());
PenaltyBO penaltyBO = null;
String penaltyName = dto.getPenaltyName();
Integer periodDuration = dto.getDuration();
Double min = dto.getMin();
Double max = dto.getMax();
if (dto.isRatePenalty()) {
Double rate = dto.getRate();
PenaltyFormulaEntity formula = this.penaltyDao.findPenaltyFormulaEntityByType(penaltyFormula);
penaltyBO = new RatePenaltyBO(userContext, penaltyName, penaltyCategoryEntity, penaltyPeriodEntity, periodDuration, min, max, penaltyFrequencyEntity, glCodeEntity, formula, rate);
} else {
Money amount = new Money(getCurrency(dto.getCurrencyId()), dto.getAmount());
penaltyBO = new AmountPenaltyBO(userContext, penaltyName, penaltyCategoryEntity, penaltyPeriodEntity, periodDuration, min, max, penaltyFrequencyEntity, glCodeEntity, amount);
}
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.PenaltyPeriodEntity in project head by mifos.
the class WebTierPenaltyServiceFacade method getPenaltyParameters.
@Override
public PenaltyParametersDto getPenaltyParameters() {
try {
List<GLCodeEntity> glCodes = generalLedgerDao.retreiveGlCodesBy(FinancialActionConstants.PENALTYPOSTING, FinancialConstants.CREDIT);
List<PenaltyCategoryEntity> categories = this.penaltyDao.getPenaltiesCategories();
List<PenaltyPeriodEntity> periods = this.penaltyDao.getPenaltiesPeriods();
List<PenaltyFormulaEntity> formulas = this.penaltyDao.getPenaltiesFormulas();
List<PenaltyFrequencyEntity> frequencies = this.penaltyDao.getPenaltiesFrequencies();
List<PenaltyStatusEntity> statuses = this.penaltyDao.getPenaltiesStatuses();
return new PenaltyParametersDto(listToMap(categories), listToMap(statuses), listToMap(periods), listToMap(formulas), listToMap(frequencies), glCodesToMap(glCodes));
} catch (FinancialException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.accounts.penalties.business.PenaltyPeriodEntity in project head by mifos.
the class PenaltyDaoHibernateIntegrationTest method cleanDatabaseTables.
@Before
public void cleanDatabaseTables() throws Exception {
databaseCleaner.clean();
periodEntity = new PenaltyPeriodEntity(PenaltyPeriod.INSTALLMENTS);
statusEntity = new PenaltyStatusEntity(PenaltyStatus.ACTIVE);
categoryEntity = new PenaltyCategoryEntity(PenaltyCategory.LOAN);
frequencyEntity = new PenaltyFrequencyEntity(PenaltyFrequency.NONE);
formulaEntity = new PenaltyFormulaEntity(PenaltyFormula.OUTSTANDING_LOAN_AMOUNT);
glCodeEntity = new GLCodeEntity((short) 42, "31102");
amountPenalty = new AmountPenaltyBO(TestUtils.makeUser(), "Amount Penalty Test", new PenaltyCategoryEntity(PenaltyCategory.SAVING), periodEntity, 6, 1.0, 14.0, frequencyEntity, glCodeEntity, TestUtils.createMoney(158.5));
ratePenalty = new RatePenaltyBO(TestUtils.makeUser(), "Rate Penalty Test", categoryEntity, periodEntity, 6, 1.0, 10.0, frequencyEntity, glCodeEntity, formulaEntity, 10.5);
IntegrationTestObjectMother.createPenalty(amountPenalty);
IntegrationTestObjectMother.createPenalty(ratePenalty);
}
use of org.mifos.accounts.penalties.business.PenaltyPeriodEntity in project head by mifos.
the class PenaltyDaoHibernateIntegrationTest method shouldFindPenaltyPeriodEntityByType.
@Test
public void shouldFindPenaltyPeriodEntityByType() throws Exception {
PenaltyPeriodEntity found = penaltyDao.findPenaltyPeriodEntityByType(periodEntity.getPenaltyPeriod());
assertThat(found.getId(), is(periodEntity.getId()));
}
Aggregations