Search in sources :

Example 6 with ApplyAdjustmentActionForm

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

the class ApplyAdjustment method loadAdjustment.

@TransactionDemarcate(joinToken = true)
public ActionForward loadAdjustment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    request.setAttribute("method", "loadAdjustment");
    UserContext userContext = getUserContext(request);
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
    AccountPaymentEntity payment = null;
    if (request.getParameter(Constants.ADJ_TYPE_KEY) != null && request.getParameter(Constants.ADJ_TYPE_KEY).equals(Constants.ADJ_SPECIFIC)) {
        Integer paymentId = appAdjustActionForm.getPaymentId();
        payment = accnt.findPaymentById(paymentId);
        AccountPaymentEntity previous = null;
        AccountPaymentEntity next = null;
        boolean getPrevious = false;
        for (AccountPaymentEntity p : accnt.getAccountPayments()) {
            if (!p.getAmount().equals(Money.zero())) {
                if (getPrevious) {
                    previous = p;
                    break;
                } else if (p.getPaymentId().equals(payment.getPaymentId())) {
                    getPrevious = true;
                } else {
                    next = p;
                }
            }
        }
        Date previousPaymentDate = (previous == null) ? null : previous.getPaymentDate();
        Date nextPaymentDate = (next == null) ? null : next.getPaymentDate();
        appAdjustActionForm.setPreviousPaymentDate(previousPaymentDate);
        appAdjustActionForm.setNextPaymentDate(nextPaymentDate);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, payment.getAmount().getAmount(), request);
        Short transferPaymentTypeId = legacyAcceptedPaymentTypeDao.getSavingsTransferId();
        if (payment.getPaymentType().getId().equals(transferPaymentTypeId)) {
            List<ListItem<Short>> paymentTypeList = this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId());
            for (Iterator<ListItem<Short>> it = paymentTypeList.iterator(); it.hasNext(); ) {
                ListItem<Short> listItem = it.next();
                if (!listItem.getId().equals(transferPaymentTypeId)) {
                    it.remove();
                }
            }
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, paymentTypeList, request);
        } else {
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
        }
    } else {
        SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
        payment = accnt.getLastPmntToBeAdjusted();
        appAdjustActionForm.setPaymentId(null);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, accnt.getLastPmntAmntToBeAdjusted(), request);
    }
    if (accnt.isParentGroupLoanAccount()) {
        SessionUtils.setAttribute(Constants.TYPE_OF_GROUP_LOAN, "parentAcc", request);
    } else if (accnt.isGroupLoanAccountMember()) {
        appAdjustActionForm.setGroupLoanMember(Boolean.TRUE);
    }
    populateForm(appAdjustActionForm, payment);
    return mapping.findForward("loadadjustment_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ListItem(org.mifos.application.servicefacade.ListItem) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 7 with ApplyAdjustmentActionForm

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

the class ApplyAdjustment method cancelAdjustment.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward cancelAdjustment(ActionMapping mapping, ActionForm form, @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    resetActionFormFields(appAdjustActionForm);
    return mapping.findForward("canceladj_success");
}
Also used : ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 8 with ApplyAdjustmentActionForm

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

the class ApplyAdjustment method loadAdjustmentWhenObligationMet.

/*
     * This method do the same thing as loadAdjustment, but added to allow
     * handling permission : can adjust payment when account is closed
     * obligation met
     */
@TransactionDemarcate(joinToken = true)
public ActionForward loadAdjustmentWhenObligationMet(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    request.setAttribute("method", "loadAdjustmentWhenObligationMet");
    AccountPaymentEntity payment = null;
    if (request.getParameter(Constants.ADJ_TYPE_KEY) != null && request.getParameter(Constants.ADJ_TYPE_KEY).equals(Constants.ADJ_SPECIFIC)) {
        Integer paymentId = appAdjustActionForm.getPaymentId();
        payment = accnt.findPaymentById(paymentId);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, payment.getAmount().getAmount(), request);
    } else {
        payment = accnt.getLastPmntToBeAdjusted();
        appAdjustActionForm.setPaymentId(null);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, accnt.getLastPmntAmntToBeAdjusted(), request);
    }
    appAdjustActionForm.setAdjustData(false);
    populateForm(appAdjustActionForm, payment);
    return mapping.findForward("loadadjustment_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

ApplyAdjustmentActionForm (org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm)8 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)8 AccountBO (org.mifos.accounts.business.AccountBO)3 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 ListItem (org.mifos.application.servicefacade.ListItem)2 UserContext (org.mifos.security.util.UserContext)2 Date (java.util.Date)1 List (java.util.List)1 AdjustablePaymentDto (org.mifos.accounts.business.AdjustablePaymentDto)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 AdjustedPaymentDto (org.mifos.dto.domain.AdjustedPaymentDto)1 GroupLoanMemberAdjustmentDto (org.mifos.dto.screen.GroupLoanMemberAdjustmentDto)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1