use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerServiceImpl method generateSavingSchedulesForGroupAndCenterSavingAccounts.
private void generateSavingSchedulesForGroupAndCenterSavingAccounts(ClientBO client) {
try {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> holidays = new ArrayList<Holiday>();
UserContext userContext = client.getUserContext();
CustomerBO group = client.getParentCustomer();
if (group != null) {
List<SavingsBO> groupSavingAccounts = new CustomerPersistence().retrieveSavingsAccountForCustomer(group.getCustomerId());
CustomerBO center = group.getParentCustomer();
if (center != null) {
List<SavingsBO> centerSavingAccounts = new CustomerPersistence().retrieveSavingsAccountForCustomer(center.getCustomerId());
groupSavingAccounts.addAll(centerSavingAccounts);
}
for (SavingsBO savings : groupSavingAccounts) {
savings.setUserContext(userContext);
if (client.getCustomerMeetingValue() != null) {
if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
DateTime today = new DateTime().toDateMidnight().toDateTime();
savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), workingDays, holidays, today);
}
}
}
}
} catch (PersistenceException pe) {
throw new MifosRuntimeException(pe);
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerServiceImpl method removeGroupMembership.
@Override
public void removeGroupMembership(ClientBO client, PersonnelBO loanOfficer, CustomerNoteEntity accountNotesEntity, Short localeId) {
if (client.hasActiveLoanAccounts()) {
throw new BusinessRuleException(CustomerConstants.CLIENT_HAS_ACTIVE_ACCOUNTS_EXCEPTION);
}
if (client.getParentCustomer() != null) {
boolean glimEnabled = getConfigurationPersistence().isGlimEnabled();
if (glimEnabled) {
if (customerIsMemberOfAnyExistingGlimLoanAccount(client, client.getParentCustomer())) {
throw new BusinessRuleException(CustomerConstants.GROUP_HAS_ACTIVE_ACCOUNTS_EXCEPTION);
}
} else if (client.getParentCustomer().hasActiveLoanAccounts()) {
// not glim - then disallow removing client from group with active account
throw new BusinessRuleException(CustomerConstants.GROUP_HAS_ACTIVE_ACCOUNTS_EXCEPTION);
}
//Recalculate Group Savings schedules
for (SavingsBO savingAccount : client.getParentCustomer().getOpenSavingAccounts()) {
if (savingAccount.isMandatory() && savingAccount.isGroupModelWithIndividualAccountability()) {
//Get all schedule accounts and set their deposits to zero
this.savingsServiceFacade.updateCustomerSchedules(savingAccount.getAccountId(), client.getCustomerId());
}
}
}
try {
this.hibernateTransactionHelper.startTransaction();
this.hibernateTransactionHelper.beginAuditLoggingFor(client);
client.addCustomerNotes(accountNotesEntity);
client.resetPositions(client.getParentCustomer());
client.getParentCustomer().updateDetails(client.getUserContext());
this.customerDao.save(client.getParentCustomer());
this.hibernateTransactionHelper.flushSession();
client.setPersonnel(loanOfficer);
client.setParentCustomer(null);
client.removeGroupMembership();
client.generateSearchId();
this.customerDao.save(client);
this.hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsClosureAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
actionForm.clearForm();
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
Long savingsId = Long.valueOf(savings.getAccountId());
savings = this.savingsDao.findById(savingsId);
savings.setUserContext(uc);
// NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
// use within Tag library in jsp.
new SavingsPersistence().initialize(savings);
LocalDate accountCloseDate = new LocalDate();
SavingsAccountClosureDto closureDetails = this.savingsServiceFacade.retrieveClosingDetails(savingsId, accountCloseDate);
LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
Money interestAmountDue = new Money(savings.getCurrency(), closureDetails.getInterestAmountAtClosure());
Money endOfAccountBalance = new Money(savings.getCurrency(), closureDetails.getBalance());
Date transactionDate = closureDetails.getClosureDate().toDateMidnight().toDate();
Money withdrawalAmountAtClosure = endOfAccountBalance.add(interestAmountDue);
AccountPaymentEntity payment = new AccountPaymentEntity(savings, withdrawalAmountAtClosure, null, null, null, transactionDate);
actionForm.setAmount(withdrawalAmountAtClosure.toString());
actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
return mapping.findForward("load_success");
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsDepositWithdrawalAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
clearActionForm(actionForm);
Long savingsId = savings.getAccountId().longValue();
Integer customerId = savings.getCustomer().getCustomerId();
if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
customerId = Integer.valueOf(actionForm.getCustomerId());
}
DepositWithdrawalReferenceDto depositWithdrawalReferenceDto = this.savingsServiceFacade.retrieveDepositWithdrawalReferenceData(savingsId, customerId);
savings = this.savingsDao.findById(savingsId);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
if (savings.isGroupModelWithIndividualAccountability()) {
List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savings.getCustomer().getSearchId(), savings.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
SessionUtils.setCollectionAttribute(SavingsConstants.CLIENT_LIST, activeAndOnHoldClients, request);
} else {
SessionUtils.setAttribute(SavingsConstants.CLIENT_LIST, new ArrayList<CustomerBO>(), request);
}
LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_deposit.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
trxnTypes.add(getAccountsService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), uc.getLocaleId()));
trxnTypes.add(getAccountsService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), uc.getLocaleId()));
SessionUtils.setCollectionAttribute(AccountConstants.TRXN_TYPES, trxnTypes, request);
SessionUtils.setAttribute(SavingsConstants.IS_BACKDATED_TRXN_ALLOWED, depositWithdrawalReferenceDto.isBackDatedTransactionsAllowed(), request);
AccountPaymentEntity lastPayment = savings.findMostRecentDepositOrWithdrawalByDate();
if (lastPayment != null) {
actionForm.setLastTrxnDate(lastPayment.getPaymentDate());
}
actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
return mapping.findForward(ActionForwards.load_success.toString());
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsAction method get.
@TransactionDemarcate(saveToken = true)
public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsActionForm actionForm = (SavingsActionForm) form;
actionForm.setInput(null);
String globalAccountNum = actionForm.getGlobalAccountNum();
if (StringUtils.isBlank(actionForm.getGlobalAccountNum())) {
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
globalAccountNum = savings.getGlobalAccountNum();
}
logger.debug(" Retrieving for globalAccountNum: " + globalAccountNum);
SavingsBO savings = this.savingsDao.findBySystemId(globalAccountNum);
savings.setUserContext(uc);
SavingsAccountDetailDto savingsAccountDto;
try {
savingsAccountDto = this.savingsServiceFacade.retrieveSavingsAccountDetails(savings.getAccountId().longValue());
} catch (MifosRuntimeException e) {
if (e.getCause() instanceof ApplicationException) {
throw (ApplicationException) e.getCause();
}
throw e;
}
List<AdminDocumentBO> allAdminDocuments = legacyAdminDocumentDao.getAllActiveAdminDocuments();
List<AdminDocumentBO> savingsAdminDocuments = new ArrayList();
for (AdminDocumentBO adminDocumentBO : allAdminDocuments) {
List<AdminDocAccStateMixBO> admindoclist = legacyAdminDocAccStateMixDao.getMixByAdminDocuments(adminDocumentBO.getAdmindocId());
if (!savingsAdminDocuments.contains(adminDocumentBO) && admindoclist.size() > 0 && admindoclist.get(0).getAccountStateID().getPrdType().getProductTypeID().equals(Short.valueOf("2"))) {
savingsAdminDocuments.add(adminDocumentBO);
}
}
SessionUtils.setCollectionAttribute("administrativeDocumentsList", savingsAdminDocuments, request);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
SessionUtils.setCollectionAttribute(MasterConstants.SAVINGS_TYPE, legacyMasterDao.findMasterDataEntitiesWithLocale(SavingsTypeEntity.class), request);
SessionUtils.setCollectionAttribute(MasterConstants.RECOMMENDED_AMOUNT_UNIT, legacyMasterDao.findMasterDataEntitiesWithLocale(RecommendedAmntUnitEntity.class), request);
List<CustomFieldDefinitionEntity> customFieldDefinitions = new ArrayList<CustomFieldDefinitionEntity>();
SessionUtils.setCollectionAttribute(SavingsConstants.CUSTOM_FIELDS, customFieldDefinitions, request);
SessionUtils.setAttribute(SavingsConstants.PRDOFFERING, savings.getSavingsOffering(), request);
actionForm.setRecommendedAmount(savingsAccountDto.getRecommendedOrMandatoryAmount());
actionForm.clear();
SessionUtils.setCollectionAttribute(SavingsConstants.RECENTY_ACTIVITY_DETAIL_PAGE, savingsAccountDto.getRecentActivity(), request);
SessionUtils.setCollectionAttribute(SavingsConstants.NOTES, savings.getRecentAccountNotes(), request);
logger.info(" Savings object retrieved successfully");
setCurrentPageUrl(request, savings);
setQuestionGroupInstances(request, savings);
request.getSession().setAttribute("backPageUrl", request.getAttribute("currentPageUrl"));
return mapping.findForward("get_success");
}
Aggregations