Search in sources :

Example 1 with SavingsHelper

use of org.mifos.accounts.savings.util.helpers.SavingsHelper in project head by mifos.

the class SavingsApplyAdjustmentAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    clearActionForm(form);
    doCleanUp(request);
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savings.getAccountId());
    savings = this.savingsDao.findById(savingsId);
    savings.setUserContext(uc);
    String paymentIdParam = request.getParameter("paymentId");
    Integer paymentId;
    if (paymentIdParam == null) {
        AccountPaymentEntity payment = savings.getLastPmnt();
        paymentId = (payment == null) ? null : payment.getPaymentId();
    } else {
        paymentId = Integer.valueOf(paymentIdParam);
    }
    SavingsAdjustmentReferenceDto savingsAdjustmentDto = this.savingsServiceFacade.retrieveAdjustmentReferenceData(savingsId, paymentId);
    if (savingsAdjustmentDto.isDepositOrWithdrawal()) {
        AccountPaymentEntity payment = (paymentId == null) ? savings.findMostRecentPaymentByPaymentDate() : savings.findPaymentById(paymentId);
        AccountActionEntity accountAction = legacyMasterDao.getPersistentObject(AccountActionEntity.class, new SavingsHelper().getPaymentActionType(payment));
        Hibernate.initialize(savings.findMostRecentPaymentByPaymentDate().getAccountTrxns());
        SessionUtils.setAttribute(SavingsConstants.ACCOUNT_ACTION, accountAction, request);
        SessionUtils.setAttribute(SavingsConstants.CLIENT_NAME, savingsAdjustmentDto.getClientName(), request);
        SessionUtils.setAttribute(SavingsConstants.IS_LAST_PAYMENT_VALID, Constants.YES, request);
        SessionUtils.setAttribute(SavingsConstants.ADJUSTMENT_AMOUNT, payment.getAmount().getAmount(), request);
        SavingsApplyAdjustmentActionForm actionForm = (SavingsApplyAdjustmentActionForm) form;
        actionForm.setPaymentId(paymentId);
        actionForm.setTrxnDate(new LocalDate(payment.getPaymentDate()));
    } else {
        SessionUtils.setAttribute(SavingsConstants.IS_LAST_PAYMENT_VALID, Constants.NO, request);
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    return mapping.findForward("load_success");
}
Also used : SavingsAdjustmentReferenceDto(org.mifos.dto.screen.SavingsAdjustmentReferenceDto) UserContext(org.mifos.security.util.UserContext) SavingsHelper(org.mifos.accounts.savings.util.helpers.SavingsHelper) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsApplyAdjustmentActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with SavingsHelper

use of org.mifos.accounts.savings.util.helpers.SavingsHelper in project head by mifos.

the class SavingsApplyAdjustmentActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = new ActionErrors();
    if (null == request.getAttribute(Constants.CURRENTFLOWKEY)) {
        request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    }
    try {
        if (method != null && method.equals("preview")) {
            SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
            AccountPaymentEntity payment = savings.findPaymentById(this.paymentId);
            if (payment == null || savings.getLastPmntAmnt() == 0 || !(new SavingsHelper().getPaymentActionType(payment).equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue()) || new SavingsHelper().getPaymentActionType(payment).equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue()))) {
                errors.add(SavingsConstants.INVALID_LAST_PAYMENT, new ActionMessage(SavingsConstants.INVALID_LAST_PAYMENT));
            } else {
                if (StringUtils.isBlank(getLastPaymentAmount())) {
                    errors.add(SavingsConstants.INVALID_ADJUSTMENT_AMOUNT, new ActionMessage(SavingsConstants.INVALID_ADJUSTMENT_AMOUNT));
                }
                if (StringUtils.isNotBlank(getLastPaymentAmount())) {
                    Locale locale = getUserContext(request).getPreferredLocale();
                    validateAmount(errors, locale);
                }
                if (StringUtils.isNotBlank(getNote()) && getNote().length() > CustomerConstants.COMMENT_LENGTH) {
                    errors.add(AccountConstants.MAX_NOTE_LENGTH, new ActionMessage(AccountConstants.MAX_NOTE_LENGTH, AccountConstants.COMMENT_LENGTH));
                }
                validateDate(errors);
                errors.add(super.validate(mapping, request));
            }
        }
    } catch (ApplicationException ae) {
        errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : Locale(java.util.Locale) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SavingsHelper(org.mifos.accounts.savings.util.helpers.SavingsHelper) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ActionMessage(org.apache.struts.action.ActionMessage) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) ActionErrors(org.apache.struts.action.ActionErrors)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 SavingsHelper (org.mifos.accounts.savings.util.helpers.SavingsHelper)2 Locale (java.util.Locale)1 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 LocalDate (org.joda.time.LocalDate)1 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)1 SavingsApplyAdjustmentActionForm (org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm)1 SavingsAdjustmentReferenceDto (org.mifos.dto.screen.SavingsAdjustmentReferenceDto)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 UserContext (org.mifos.security.util.UserContext)1