use of org.mifos.accounts.financial.business.GLCodeEntity 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.financial.business.GLCodeEntity 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.financial.business.GLCodeEntity in project head by mifos.
the class LegacyAccountDao method updateLedgerAccount.
public void updateLedgerAccount(COABO coaBo, String accountName, String glCode, String parentGlCode) throws PersistenceException {
Session session = StaticHibernateUtil.getSessionTL();
Transaction transaction = session.beginTransaction();
try {
Short newParentId = getAccountIdFromGlCode(parentGlCode);
coaBo.setAccountName(accountName);
GLCodeEntity glCodeEntity = coaBo.getAssociatedGlcode();
createOrUpdate(coaBo);
glCodeEntity.setGlcode(glCode);
createOrUpdate(glCodeEntity);
Query query = session.getNamedQuery(NamedQueryConstants.SET_COA_PARENT);
query.setShort("parentId", newParentId);
query.setShort("id", coaBo.getAccountId());
query.executeUpdate();
transaction.commit();
} catch (HibernateException ex) {
transaction.rollback();
throw new PersistenceException(ex);
}
}
use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.
the class SavingsProductAssembler method fromDto.
public SavingsOfferingBO fromDto(MifosUser user, SavingsProductDto savingsProductRequest) {
try {
// FIXME - keithw - this is general assembler common to both savings and loans i.e. all products. so
// ProductDao and ProductAssembler
ProductDetailsDto productDetails = savingsProductRequest.getProductDetails();
String name = productDetails.getName();
String shortName = productDetails.getShortName();
String description = productDetails.getDescription();
Integer category = productDetails.getCategory();
ProductCategoryBO productCategory = this.loanProductDao.findActiveProductCategoryById(category);
DateTime startDate = productDetails.getStartDate();
DateTime endDate = productDetails.getEndDate();
ApplicableTo applicableTo = ApplicableTo.fromInt(productDetails.getApplicableFor());
PrdApplicableMasterEntity applicableToEntity = this.loanProductDao.findApplicableProductType(applicableTo);
PrdStatusEntity activeStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_ACTIVE);
PrdStatusEntity inActiveStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_INACTIVE);
PrdStatusEntity selectedStatus = activeStatus;
if (productDetails.getStatus() != null && inActiveStatus.getOfferingStatusId().equals(productDetails.getStatus().shortValue())) {
selectedStatus = inActiveStatus;
}
String globalNum = generateProductGlobalNum(user);
// savings specific
SavingsType savingsType = SavingsType.fromInt(savingsProductRequest.getDepositType());
SavingsTypeEntity savingsTypeEntity = this.loanProductDao.retrieveSavingsType(savingsType);
RecommendedAmntUnitEntity recommendedAmntUnitEntity = null;
if (savingsProductRequest.getGroupMandatorySavingsType() != null) {
RecommendedAmountUnit recommendedAmountType = RecommendedAmountUnit.fromInt(savingsProductRequest.getGroupMandatorySavingsType());
recommendedAmntUnitEntity = this.loanProductDao.retrieveRecommendedAmountType(recommendedAmountType);
}
Money amountForDeposit = new Money(Money.getDefaultCurrency(), BigDecimal.valueOf(savingsProductRequest.getAmountForDeposit()));
Money maxWithdrawal = new Money(Money.getDefaultCurrency(), BigDecimal.valueOf(savingsProductRequest.getMaxWithdrawal()));
// interest specific
BigDecimal interestRate = savingsProductRequest.getInterestRate();
InterestCalcType interestCalcType = InterestCalcType.fromInt(savingsProductRequest.getInterestCalculationType());
InterestCalcTypeEntity interestCalcTypeEntity = this.savingsProductDao.retrieveInterestCalcType(interestCalcType);
RecurrenceType recurrence = RecurrenceType.fromInt(savingsProductRequest.getInterestCalculationFrequencyPeriod().shortValue());
Integer every = savingsProductRequest.getInterestCalculationFrequency();
MeetingBO interestCalculationMeeting = new MeetingBO(recurrence, every.shortValue(), new Date(), MeetingType.SAVINGS_INTEREST_CALCULATION_TIME_PERIOD);
Integer interestPostingEveryMonthFreq = savingsProductRequest.getInterestPostingFrequency();
RecurrenceType interestPostingRecurrenceType = null;
if (savingsProductRequest.isDailyPosting()) {
interestPostingRecurrenceType = RecurrenceType.DAILY;
} else {
interestPostingRecurrenceType = RecurrenceType.MONTHLY;
}
MeetingBO interestPostingMeeting = new MeetingBO(interestPostingRecurrenceType, interestPostingEveryMonthFreq.shortValue(), new Date(), MeetingType.SAVINGS_INTEREST_POSTING);
Money minAmountForCalculation = new Money(Money.getDefaultCurrency(), savingsProductRequest.getMinBalanceForInterestCalculation());
GLCodeEntity depositGlEntity = this.generalLedgerDao.findGlCodeById(savingsProductRequest.getDepositGlCode().shortValue());
GLCodeEntity interestGlEntity = this.generalLedgerDao.findGlCodeById(savingsProductRequest.getInterestGlCode().shortValue());
MifosCurrency currency = Money.getDefaultCurrency();
return SavingsOfferingBO.createNew(user.getUserId(), globalNum, name, shortName, description, productCategory, startDate, endDate, applicableToEntity, currency, selectedStatus, savingsTypeEntity, recommendedAmntUnitEntity, amountForDeposit, maxWithdrawal, interestRate, interestCalcTypeEntity, interestCalculationMeeting, interestPostingMeeting, minAmountForCalculation, depositGlEntity, interestGlEntity);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
} catch (MeetingException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.
the class PenaltyBOIntegrationTest method testCreateAmountPenalty.
@Test
public void testCreateAmountPenalty() throws Exception {
String name = "Amount Penalty Test";
PenaltyCategoryEntity categoryEntity = new PenaltyCategoryEntity(PenaltyCategory.LOAN);
PenaltyPeriodEntity periodEntity = new PenaltyPeriodEntity(PenaltyPeriod.DAYS);
int duration = 10;
double min = 1.0;
double max = 15.0;
PenaltyFrequencyEntity frequencyEntity = new PenaltyFrequencyEntity(PenaltyFrequency.MONTHLY);
GLCodeEntity glCode = getGLCode("42");
Money amount = TestUtils.createMoney(587.6);
penalty = new AmountPenaltyBO(TestUtils.makeUser(), name, categoryEntity, periodEntity, duration, min, max, frequencyEntity, glCode, amount);
penalty.save();
StaticHibernateUtil.flushSession();
penalty = (PenaltyBO) TestObjectFactory.getObject(PenaltyBO.class, penalty.getPenaltyId());
Assert.assertEquals(name, penalty.getPenaltyName());
Assert.assertEquals(categoryEntity.getId(), penalty.getCategoryType().getId());
Assert.assertEquals(duration, penalty.getPeriodDuration().intValue());
Assert.assertEquals(min, penalty.getMinimumLimit().doubleValue());
Assert.assertEquals(max, penalty.getMaximumLimit().doubleValue());
Assert.assertEquals(frequencyEntity.getId(), penalty.getPenaltyFrequency().getId());
Assert.assertEquals(glCode.getGlcodeId(), penalty.getGlCode().getGlcodeId());
Assert.assertEquals(amount.getAmount(), ((AmountPenaltyBO) penalty).getAmount().getAmount());
StaticHibernateUtil.flushSession();
}
Aggregations