use of org.mifos.accounts.productdefinition.business.SavingsOfferingBO in project head by mifos.
the class InterestPostingAccountingEntry method applySpecificAccountActionEntry.
@Override
protected void applySpecificAccountActionEntry() throws FinancialException {
SavingsTrxnDetailEntity savingsTrxn = (SavingsTrxnDetailEntity) financialActivity.getAccountTrxn();
FinancialActionTypeEntity finIntPostingAction = getFinancialAction(FinancialActionConstants.SAVINGS_INTERESTPOSTING);
SavingsOfferingBO savingsOffering = ((SavingsBO) savingsTrxn.getAccount()).getSavingsOffering();
addAccountEntryDetails(savingsTrxn.getInterestAmount(), finIntPostingAction, savingsOffering.getInterestGLCode(), FinancialConstants.DEBIT);
addAccountEntryDetails(savingsTrxn.getInterestAmount(), finIntPostingAction, savingsOffering.getDepositGLCode(), FinancialConstants.CREDIT);
}
use of org.mifos.accounts.productdefinition.business.SavingsOfferingBO in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveSavingsProductReferenceData.
@Override
public SavingsProductReferenceDto retrieveSavingsProductReferenceData(Integer productId) {
SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(productId);
List<ListElement> interestCalcTypeOptions = new ArrayList<ListElement>();
List<InterestCalcTypeEntity> interestCalculationTypes = this.savingsProductDao.retrieveInterestCalculationTypes();
for (InterestCalcTypeEntity entity : interestCalculationTypes) {
interestCalcTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
}
boolean savingsPendingApprovalEnabled = ProcessFlowRules.isSavingsPendingApprovalStateEnabled();
return new SavingsProductReferenceDto(interestCalcTypeOptions, savingsProduct.toFullDto(), savingsPendingApprovalEnabled);
}
use of org.mifos.accounts.productdefinition.business.SavingsOfferingBO in project head by mifos.
the class SavingsServiceFacadeWebTier method createSavingsAccount.
@Override
public String createSavingsAccount(OpeningBalanceSavingsAccount openingBalanceSavingsAccount) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
LocalDate createdDate = new LocalDate();
Integer createdById = user.getUserId();
PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
CustomerBO customer = this.customerDao.findCustomerBySystemId(openingBalanceSavingsAccount.getCustomerGlobalId());
SavingsOfferingBO savingsProduct = this.savingsProductDao.findBySystemId(openingBalanceSavingsAccount.getProductGlobalId());
AccountState savingsAccountState = AccountState.fromShort(openingBalanceSavingsAccount.getAccountState());
Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getRecommendedOrMandatoryAmount());
Money openingBalance = new Money(savingsProduct.getCurrency(), new BigDecimal(0));
LocalDate activationDate = openingBalanceSavingsAccount.getActivationDate();
CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
SavingsAccountActivationDetail activationDetails = SavingsBO.generateAccountActivationDetails(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, calendarEvents, activationDate);
SavingsBO savingsAccount = SavingsBO.createOpeningBalanceIndividualSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, activationDetails, createdBy, openingBalance);
savingsAccount.setGlobalAccountNum(openingBalanceSavingsAccount.getAccountNumber());
savingsAccount.setSavingsBalance(openingBalance);
DateTimeService dateTimeService = new DateTimeService();
savingsAccount.setDateTimeService(dateTimeService);
openingBalance = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getOpeningBalance());
if (savingsAccountState.isActiveLoanAccountState()) {
savingsAccount.resetRecommendedAmountOnFutureInstallments();
}
try {
if (openingBalance.isGreaterThanZero()) {
PaymentData paymentData = new PaymentData(openingBalance, createdBy, Short.valueOf("1"), activationDate.toDateMidnight().toDate());
paymentData.setCustomer(customer);
savingsAccount.applyPayment(paymentData);
}
this.transactionHelper.startTransaction();
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
// savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
this.savingsDao.save(savingsAccount);
this.transactionHelper.commitTransaction();
return savingsAccount.getGlobalAccountNum();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.productdefinition.business.SavingsOfferingBO in project head by mifos.
the class SavingsServiceFacadeWebTier method createSavingsAccount.
@Override
public Long createSavingsAccount(SavingsAccountCreationDto savingsAccountCreation, List<QuestionGroupDetail> questionGroups) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
LocalDate createdDate = new LocalDate();
Integer createdById = user.getUserId();
PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
CustomerBO customer = this.customerDao.findCustomerById(savingsAccountCreation.getCustomerId());
SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(savingsAccountCreation.getProductId());
Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), savingsAccountCreation.getRecommendedOrMandatoryAmount());
AccountState savingsAccountState = AccountState.fromShort(savingsAccountCreation.getAccountState());
CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
SavingsAccountTypeInspector savingsAccountWrapper = new SavingsAccountTypeInspector(customer, savingsProduct.getRecommendedAmntUnit());
try {
SavingsBO savingsAccount = null;
if (savingsAccountWrapper.isIndividualSavingsAccount()) {
savingsAccount = SavingsBO.createIndividalSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy);
} else if (savingsAccountWrapper.isJointSavingsAccountWithClientTracking()) {
List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(customer.getSearchId(), customer.getOfficeId(), CustomerLevel.CLIENT);
savingsAccount = SavingsBO.createJointSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy, activeAndOnHoldClients);
}
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.transactionHelper.startTransaction();
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
// save question groups
if (!questionGroups.isEmpty()) {
Integer eventSourceId = questionnaireServiceFacade.getEventSourceId("Create", "Savings");
QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(Integer.valueOf(user.getUserId()).shortValue(), savingsAccount.getAccountId(), eventSourceId, questionGroups);
questionnaireServiceFacade.saveResponses(questionGroupDetails);
}
this.transactionHelper.commitTransaction();
return savingsAccount.getAccountId().longValue();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.productdefinition.business.SavingsOfferingBO in project head by mifos.
the class SavingsProductDaoHibernateIntegrationTest method testShouldFindSavingsProductById.
@Test
public void testShouldFindSavingsProductById() {
// setup
SavingsOfferingBO savingsProduct = new SavingsProductBuilder().appliesToCentersOnly().mandatory().withName("product1").withShortName("1234").withMandatoryAmount("25").buildForIntegrationTests();
IntegrationTestObjectMother.saveSavingsProducts(savingsProduct);
// exercise test
SavingsOfferingBO result = savingsProductDao.findById(savingsProduct.getPrdOfferingId().intValue());
Money recommendedAmount = TestUtils.createMoney("25");
RecommendedAmntUnitEntity recommendedAmntUnit = null;
Money maxAmntWithdrawl = TestUtils.createMoney("100");
Double interestRate = Double.valueOf("12");
Money minAmountRequiredForInterestToBeCalculated = TestUtils.createMoney("100");
LocalDate updateDate = new LocalDate();
result.updateSavingsDetails(recommendedAmount, recommendedAmntUnit, maxAmntWithdrawl, interestRate, minAmountRequiredForInterestToBeCalculated, updateDate);
IntegrationTestObjectMother.saveSavingsProducts(result);
// assertion
assertNotNull(result);
}
Aggregations