Search in sources :

Example 6 with CloseSession

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

the class AccountAppAction method removePenalties.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward removePenalties(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    Integer accountId = getIntegerValue(request.getParameter("accountId"));
    Short penaltyId = getShortValue(request.getParameter("penaltyId"));
    AccountBO accountBO = getAccountBusinessService().getAccount(accountId);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
    if (accountBO instanceof LoanBO) {
        this.loanAccountServiceFacade.removeLoanPenalty(accountId, penaltyId);
    }
    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) LoanBO(org.mifos.accounts.loan.business.LoanBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 7 with CloseSession

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

the class SavingsAction method update.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In SavingsAction::update()");
    SavingsActionForm actionForm = (SavingsActionForm) form;
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = savings.getAccountId().longValue();
    savings = this.savingsDao.findById(savingsId);
    Integer version = savings.getVersionNo();
    checkVersionMismatch(version, savings.getVersionNo());
    this.savingsServiceFacade.updateSavingsAccountDetails(savingsId, actionForm.getRecommendedAmount(), actionForm.getAccountCustomFieldSet());
    request.setAttribute(SavingsConstants.GLOBALACCOUNTNUM, savings.getGlobalAccountNum());
    logger.info("In SavingsAction::update(), Savings object updated successfully");
    doCleanUp(actionForm, request);
    return mapping.findForward("update_success");
}
Also used : SavingsActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 8 with CloseSession

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

the class AccountApplyGroupPaymentAction method applyPayment.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward applyPayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    String paymentType = request.getParameter(Constants.INPUT);
    Integer accountId;
    if (actionForm.getAccountId().isEmpty() || actionForm.getAccountId() == null) {
        accountId = loanDao.findByGlobalAccountNum(actionForm.getGlobalAccountNum()).getAccountId();
    } else {
        accountId = Integer.valueOf(actionForm.getAccountId());
    }
    UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountId, paymentType, userContext.getLocaleId(), userReferenceDto, actionForm.getTrxnDate());
    validateAccountPayment(accountPaymentDto, accountId, request);
    validateAmount(accountPaymentDto, actionForm.getAmount());
    PaymentTypeDto paymentTypeDto;
    String amount = actionForm.getAmount();
    if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT) || accountPaymentDto.getAccountType().equals(AccountTypeDto.GROUP_LOAN_ACCOUNT)) {
        paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    } else {
        paymentTypeDto = getFeePaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    }
    AccountPaymentParametersDto accountPaymentParametersDto;
    if (isGroupParentAccount(accountId)) {
        accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto(), actionForm.getIndividualValues());
    } else if (isGroupMemberAccount(accountId)) {
        accountPaymentParametersDto = preparePaymentParametersDto(accountId, userReferenceDto, amount, actionForm, paymentTypeDto, userContext, paymentType);
    } else {
        accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto());
    }
    if (paymentTypeDto.getValue().equals(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId())) {
        this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, actionForm.getAccountForTransfer());
    } else {
        this.accountServiceFacade.makePayment(accountPaymentParametersDto);
    }
    request.getSession().setAttribute("globalAccountNum", ((AccountApplyPaymentActionForm) form).getGlobalAccountNum());
    ActionForward findForward;
    if (actionForm.getPrintReceipt()) {
        findForward = mapping.findForward(getForward("PRINT"));
    } else {
        findForward = mapping.findForward(getForward(((AccountApplyPaymentActionForm) form).getInput()));
    }
    return findForward;
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) ActionForward(org.apache.struts.action.ActionForward) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 9 with CloseSession

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

the class LoanDisbursementAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
    UserContext uc = getUserContext(request);
    Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
    trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
    Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
    Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
    Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
    AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
    Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
    createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
    try {
        String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
        String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
        Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
        Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
        Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
        final String comment = "";
        final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
        CustomerDto customerDto = null;
        PaymentTypeDto paymentType = null;
        AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
        monthClosingServiceFacade.validateTransactionDate(trxnDate);
        // GLIM
        List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
        for (LoanBO individual : individualLoans) {
            if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
                throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
            }
        }
        this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        for (LoanBO individual : individualLoans) {
            loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
            this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        }
        if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
            this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessage());
    } catch (MifosRuntimeException e) {
        if (e.getCause() != null && e.getCause() instanceof AccountException) {
            throw new AccountException(e.getCause().getMessage());
        }
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    } catch (Exception e) {
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    }
    return mapping.findForward(Constants.UPDATE_SUCCESS);
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) DateUtils.getUserLocaleDate(org.mifos.framework.util.helpers.DateUtils.getUserLocaleDate) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) LoanDisbursementActionForm(org.mifos.accounts.loan.struts.actionforms.LoanDisbursementActionForm) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 10 with CloseSession

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

the class PersonnelSettingsAction method update.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PersonnelSettingsActionForm personnelSettingsActionForm = (PersonnelSettingsActionForm) form;
    PersonnelBO personnel = (PersonnelBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    AddressDto address = null;
    if (personnelSettingsActionForm.getAddress() != null) {
        address = Address.toDto(personnelSettingsActionForm.getAddress());
    }
    this.personnelServiceFacade.updateUserSettings(personnel.getPersonnelId(), personnelSettingsActionForm.getEmailId(), personnelSettingsActionForm.getName(), personnelSettingsActionForm.getMaritalStatusValue(), personnelSettingsActionForm.getGenderValue(), address, personnelSettingsActionForm.getPreferredLocaleValue(), personnelSettingsActionForm.getPreferredSiteTypeId());
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    (new SitePreferenceHelper()).setSitePreferenceCookie(personnelServiceFacade.retrieveSitePreference(user.getUserId()), response);
    return mapping.findForward(ActionForwards.updateSettings_success.toString());
}
Also used : SitePreferenceHelper(org.mifos.ui.core.controller.util.helpers.SitePreferenceHelper) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosUser(org.mifos.security.MifosUser) AddressDto(org.mifos.dto.domain.AddressDto) PersonnelSettingsActionForm(org.mifos.customers.personnel.struts.actionforms.PersonnelSettingsActionForm) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

CloseSession (org.mifos.framework.util.helpers.CloseSession)35 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)35 UserContext (org.mifos.security.util.UserContext)13 ClientBO (org.mifos.customers.client.business.ClientBO)7 BusinessRuleException (org.mifos.service.BusinessRuleException)7 CustomerBO (org.mifos.customers.business.CustomerBO)6 BigDecimal (java.math.BigDecimal)5 ActionForward (org.apache.struts.action.ActionForward)5 LocalDate (org.joda.time.LocalDate)5 AccountBO (org.mifos.accounts.business.AccountBO)5 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)4 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)4 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)4 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Locale (java.util.Locale)3 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3