Search in sources :

Example 71 with SavingsBO

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);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) DateTime(org.joda.time.DateTime) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 72 with SavingsBO

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();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 73 with SavingsBO

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");
}
Also used : SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) SavingsAccountClosureDto(org.mifos.dto.domain.SavingsAccountClosureDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 74 with SavingsBO

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());
}
Also used : UserContext(org.mifos.security.util.UserContext) SavingsDepositWithdrawalActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 75 with SavingsBO

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");
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AdminDocAccStateMixBO(org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO) RecommendedAmntUnitEntity(org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) SavingsActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsActionForm) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) SavingsAccountDetailDto(org.mifos.dto.domain.SavingsAccountDetailDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

SavingsBO (org.mifos.accounts.savings.business.SavingsBO)111 UserContext (org.mifos.security.util.UserContext)43 MifosRuntimeException (org.mifos.core.MifosRuntimeException)30 AccountException (org.mifos.accounts.exceptions.AccountException)28 LocalDate (org.joda.time.LocalDate)27 MifosUser (org.mifos.security.MifosUser)26 Test (org.junit.Test)25 Money (org.mifos.framework.util.helpers.Money)24 ArrayList (java.util.ArrayList)22 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 Date (java.util.Date)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)19 BusinessRuleException (org.mifos.service.BusinessRuleException)18 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)17 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)17 CustomerBO (org.mifos.customers.business.CustomerBO)15 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 ServiceException (org.mifos.framework.exceptions.ServiceException)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12