Search in sources :

Example 11 with TransactionDemarcate

use of org.mifos.framework.util.helpers.TransactionDemarcate in project head by mifos.

the class SavingsClosureAction method close.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    SavingsBO savingsInSession = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savingsInSession.getAccountId());
    SavingsBO savings = this.savingsDao.findById(savingsId);
    checkVersionMismatch(savingsInSession.getVersionNo(), savings.getVersionNo());
    savings.setUserContext(getUserContext(request));
    UserContext userContext = getUserContext(request);
    Long customerId = null;
    if (actionForm.getCustomerId() != null) {
        customerId = Long.valueOf(actionForm.getCustomerId());
    }
    LocalDate dateOfWithdrawal = new LocalDate(payment.getPaymentDate());
    Double amount = payment.getAmount().getAmountDoubleValue();
    Integer modeOfPayment = payment.getPaymentType().getId().intValue();
    String receiptId = payment.getReceiptNumber();
    LocalDate dateOfReceipt = null;
    if (payment.getReceiptDate() != null) {
        dateOfReceipt = new LocalDate(payment.getReceiptDate());
    }
    Locale preferredLocale = userContext.getPreferredLocale();
    SavingsWithdrawalDto closeAccount = new SavingsWithdrawalDto(savingsId, customerId, dateOfWithdrawal, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
    this.savingsServiceFacade.closeSavingsAccount(savingsId, actionForm.getNotes(), closeAccount);
    SessionUtils.removeAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    closeSavingsQuestionnaire.saveResponses(request, actionForm, savingsInSession.getAccountId());
    return mapping.findForward("close_success");
}
Also used : Locale(java.util.Locale) 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) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 12 with TransactionDemarcate

use of org.mifos.framework.util.helpers.TransactionDemarcate 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 13 with TransactionDemarcate

use of org.mifos.framework.util.helpers.TransactionDemarcate 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 14 with TransactionDemarcate

use of org.mifos.framework.util.helpers.TransactionDemarcate in project head by mifos.

the class LoanPrdAction method update.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    LoanPrdActionForm loanPrdActionForm = (LoanPrdActionForm) form;
    logger.debug("start update method of Loan Product Action" + loanPrdActionForm.getPrdOfferingId());
    UserContext userContext = getUserContext(request);
    Locale locale = getLocale(userContext);
    LoanOfferingBO loanOffering = getLoanOffering(loanPrdActionForm.getPrdOfferingIdValue());
    loanOffering.setUserContext(userContext);
    setInitialObjectForAuditLogging(loanOffering);
    mapVariableInstallmentDetails(loanOffering, loanPrdActionForm);
    loanOffering.setFixedRepaymentSchedule(loanPrdActionForm.isFixedRepaymentSchedule());
    loanOffering.setRoundingDifferenceInFirstPayment(loanPrdActionForm.isRoundingDifferenceInFirstPayment());
    mapCashFlowDetail(loanPrdActionForm, loanOffering);
    loanOffering.update(userContext.getId(), loanPrdActionForm.getPrdOfferingName(), loanPrdActionForm.getPrdOfferingShortName(), getProductCategory(((List<ProductCategoryBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRODUCTCATEGORYLIST, request)), loanPrdActionForm.getPrdCategoryValue()), (PrdApplicableMasterEntity) findMasterEntity(request, ProductDefinitionConstants.LOANAPPLFORLIST, loanPrdActionForm.getPrdApplicableMasterEnum().getValue()), loanPrdActionForm.getStartDateValue(locale), loanPrdActionForm.getEndDateValue(locale), loanPrdActionForm.getDescription(), PrdStatus.fromInt(loanPrdActionForm.getPrdStatusValue()), (GracePeriodTypeEntity) findMasterEntity(request, ProductDefinitionConstants.LOANGRACEPERIODTYPELIST, loanPrdActionForm.getGracePeriodTypeValue()), (InterestTypesEntity) findMasterEntity(request, ProductDefinitionConstants.INTERESTTYPESLIST, loanPrdActionForm.getInterestTypesValue()), loanPrdActionForm.getGracePeriodDurationValue(), loanPrdActionForm.getMaxInterestRateValue(), loanPrdActionForm.getMinInterestRateValue(), loanPrdActionForm.getDefInterestRateValue(), loanPrdActionForm.isLoanCounterValue(), loanPrdActionForm.isIntDedAtDisbValue(), loanPrdActionForm.isPrinDueLastInstValue(), getFundsFromList((List<FundBO>) SessionUtils.getAttribute(ProductDefinitionConstants.SRCFUNDSLIST, request), loanPrdActionForm.getLoanOfferingFunds()), getFeeList((List<FeeBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDFEE, request), loanPrdActionForm.getPrdOfferinFees()), getPenaltyList((List<PenaltyBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDPENALTY, request), loanPrdActionForm.getPrdOfferinPenalties()), loanPrdActionForm.getRecurAfterValue(), RecurrenceType.fromInt(loanPrdActionForm.getFreqOfInstallmentsValue()), loanPrdActionForm, loanPrdActionForm.shouldWaiverInterest(), getQuestionGroups(request));
    logger.debug("update method of Loan Product Action called" + loanPrdActionForm.getPrdOfferingId());
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : Locale(java.util.Locale) LoanPrdActionForm(org.mifos.accounts.productdefinition.struts.actionforms.LoanPrdActionForm) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) UserContext(org.mifos.security.util.UserContext) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) List(java.util.List) ArrayList(java.util.ArrayList) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 15 with TransactionDemarcate

use of org.mifos.framework.util.helpers.TransactionDemarcate in project head by mifos.

the class AccountAppAction method removeFees.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward removeFees(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    Integer accountId = getIntegerValue(request.getParameter("accountId"));
    Short feeId = getShortValue(request.getParameter("feeId"));
    this.centerServiceFacade.removeAccountFee(accountId, feeId);
    AccountBO accountBO = getAccountBusinessService().getAccount(accountId);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
    String fromPage = request.getParameter(CenterConstants.FROM_PAGE);
    StringBuilder forward = new StringBuilder();
    forward = forward.append(AccountConstants.REMOVE + "_" + fromPage + "_" + AccountConstants.CHARGES);
    if (fromPage != null) {
        return mapping.findForward(forward.toString());
    }
    return mapping.findForward(AccountConstants.REMOVE_SUCCESS);
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)259 UserContext (org.mifos.security.util.UserContext)72 ArrayList (java.util.ArrayList)41 CloseSession (org.mifos.framework.util.helpers.CloseSession)35 LoanBO (org.mifos.accounts.loan.business.LoanBO)26 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)21 CustomerBO (org.mifos.customers.business.CustomerBO)20 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)19 AccountBO (org.mifos.accounts.business.AccountBO)18 ApplicationException (org.mifos.framework.exceptions.ApplicationException)17 ActionErrors (org.apache.struts.action.ActionErrors)14 LocalDate (org.joda.time.LocalDate)14 AccountApplyPaymentActionForm (org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)14 ClientBO (org.mifos.customers.client.business.ClientBO)14 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)13 List (java.util.List)12 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)12 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)12 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 ActionForward (org.apache.struts.action.ActionForward)11