Search in sources :

Example 1 with DepositWithdrawalReferenceDto

use of org.mifos.dto.screen.DepositWithdrawalReferenceDto in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveDepositWithdrawalReferenceData.

@Override
public DepositWithdrawalReferenceDto retrieveDepositWithdrawalReferenceData(Long savingsId, Integer customerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        SavingsBO savingsAccount = savingsDao.findById(savingsId);
        String depositDue = savingsAccount.getTotalPaymentDue(customerId).toString();
        String withdrawalDue = "0";
        List<ListElement> clients = new ArrayList<ListElement>();
        if (savingsAccount.isGroupModelWithIndividualAccountability()) {
            List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
            for (CustomerBO client : activeAndOnHoldClients) {
                clients.add(new ListElement(client.getCustomerId(), client.getDisplayName()));
            }
        }
        List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), userContext.getLocaleId()));
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), userContext.getLocaleId()));
        List<ListElement> transactionTypes = new ArrayList<ListElement>();
        for (AccountActionEntity accountActionEntity : trxnTypes) {
            LookUpValueEntity lookupValue = accountActionEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            transactionTypes.add(new ListElement(accountActionEntity.getId().intValue(), messageText));
        }
        List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
        List<ListElement> withdrawalPaymentTypes = new ArrayList<ListElement>();
        List<PaymentTypeEntity> withdrawalPaymentEntityTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
        for (PaymentTypeEntity paymentTypeEntity : withdrawalPaymentEntityTypes) {
            LookUpValueEntity lookupValue = paymentTypeEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            withdrawalPaymentTypes.add(new ListElement(paymentTypeEntity.getId().intValue(), messageText));
        }
        boolean backDatedTransactionsAllowed = AccountingRules.isBackDatedTxnAllowed();
        LocalDate defaultTransactionDate = new LocalDate();
        return new DepositWithdrawalReferenceDto(transactionTypes, depositPaymentTypes, withdrawalPaymentTypes, clients, backDatedTransactionsAllowed, defaultTransactionDate, depositDue, withdrawalDue);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with DepositWithdrawalReferenceDto

use of org.mifos.dto.screen.DepositWithdrawalReferenceDto in project head by mifos.

the class SavingsDepositWithdrawalAction method reLoad.

@TransactionDemarcate(joinToken = true)
public ActionForward reLoad(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
    SavingsBO savingsInSession = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    if (actionForm.getTrxnTypeId() != null && actionForm.getTrxnTypeId() != Constants.EMPTY_STRING) {
        Long savingsId = savingsInSession.getAccountId().longValue();
        SavingsBO savings = this.savingsDao.findById(savingsId);
        Integer customerId = savings.getCustomer().getCustomerId();
        if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
            customerId = Integer.valueOf(actionForm.getCustomerId());
        }
        DepositWithdrawalReferenceDto depositWithdrawalReferenceDto = this.savingsServiceFacade.retrieveDepositWithdrawalReferenceData(savingsId, customerId);
        Short trxnTypeId = Short.valueOf(actionForm.getTrxnTypeId());
        // added for defect 1587 [start]
        LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
        if (trxnTypeId.equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
            if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
                actionForm.setAmount(depositWithdrawalReferenceDto.getDepositDue());
            }
            List<PaymentTypeEntity> depositPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_deposit.getValue());
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, depositPaymentTypes, request);
        } else {
            actionForm.setAmount(depositWithdrawalReferenceDto.getWithdrawalDue());
            List<PaymentTypeEntity> withdrawalPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, withdrawalPaymentTypes, request);
        }
    }
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) UserContext(org.mifos.security.util.UserContext) SavingsDepositWithdrawalActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with DepositWithdrawalReferenceDto

use of org.mifos.dto.screen.DepositWithdrawalReferenceDto 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)

Aggregations

SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)3 DepositWithdrawalReferenceDto (org.mifos.dto.screen.DepositWithdrawalReferenceDto)3 UserContext (org.mifos.security.util.UserContext)3 ArrayList (java.util.ArrayList)2 LegacyAcceptedPaymentTypeDao (org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao)2 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)2 SavingsDepositWithdrawalActionForm (org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm)2 CustomerBO (org.mifos.customers.business.CustomerBO)2 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 LocalDate (org.joda.time.LocalDate)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)1 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 ListElement (org.mifos.dto.screen.ListElement)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 ServiceException (org.mifos.framework.exceptions.ServiceException)1 MifosUser (org.mifos.security.MifosUser)1