Search in sources :

Example 1 with SavingsDepositWithdrawalActionForm

use of org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm in project head by mifos.

the class SavingsDepositWithdrawalAction method makePayment.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward makePayment(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    SavingsBO savedAccount = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SavingsBO savings = savingsDao.findById(savedAccount.getAccountId());
    checkVersionMismatch(savedAccount.getVersionNo(), savings.getVersionNo());
    savings.setVersionNo(savedAccount.getVersionNo());
    SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    Date trxnDate = getDateFromString(actionForm.getTrxnDate(), uc.getPreferredLocale());
    monthClosingServiceFacade.validateTransactionDate(trxnDate);
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled)) {
        throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
    }
    Long savingsId = Long.valueOf(savings.getAccountId());
    Long customerId = Long.valueOf(savings.getCustomer().getCustomerId());
    if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
        customerId = Long.valueOf(actionForm.getCustomerId());
    }
    Locale preferredLocale = uc.getPreferredLocale();
    LocalDate dateOfDepositOrWithdrawalTransaction = new LocalDate(trxnDate);
    Double amount = Double.valueOf(actionForm.getAmount());
    Integer modeOfPayment = Integer.valueOf(actionForm.getPaymentTypeId());
    String receiptId = actionForm.getReceiptId();
    LocalDate dateOfReceipt = null;
    if (StringUtils.isNotBlank(actionForm.getReceiptDate())) {
        dateOfReceipt = new LocalDate(getDateFromString(actionForm.getReceiptDate(), preferredLocale));
    }
    try {
        Short trxnTypeId = Short.valueOf(actionForm.getTrxnTypeId());
        if (trxnTypeId.equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
            SavingsDepositDto savingsDeposit = new SavingsDepositDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
            this.savingsServiceFacade.deposit(savingsDeposit);
        } else if (trxnTypeId.equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue())) {
            SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
            this.savingsServiceFacade.withdraw(savingsWithdrawal);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessageKey(), e);
    }
    return mapping.findForward(ActionForwards.account_details_page.toString());
}
Also used : Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SavingsDepositWithdrawalActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with SavingsDepositWithdrawalActionForm

use of org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm 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 SavingsDepositWithdrawalActionForm

use of org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm 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 SavingsDepositWithdrawalActionForm (org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm)3 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)3 UserContext (org.mifos.security.util.UserContext)3 LegacyAcceptedPaymentTypeDao (org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao)2 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)2 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)2 DepositWithdrawalReferenceDto (org.mifos.dto.screen.DepositWithdrawalReferenceDto)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Locale (java.util.Locale)1 LocalDate (org.joda.time.LocalDate)1 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 SavingsDepositDto (org.mifos.dto.domain.SavingsDepositDto)1 SavingsWithdrawalDto (org.mifos.dto.domain.SavingsWithdrawalDto)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1