001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.fp.document.web.struts;
017
018 import javax.servlet.http.HttpServletRequest;
019 import javax.servlet.http.HttpServletResponse;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.apache.struts.action.ActionForm;
023 import org.apache.struts.action.ActionForward;
024 import org.apache.struts.action.ActionMapping;
025 import org.kuali.kfs.fp.document.AuxiliaryVoucherDocument;
026 import org.kuali.kfs.sys.KFSConstants;
027 import org.kuali.kfs.sys.context.SpringContext;
028 import org.kuali.rice.kns.document.Document;
029 import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
030 import org.kuali.rice.kns.service.DocumentHelperService;
031
032
033 /**
034 * This class piggy backs on all of the functionality in the FinancialSystemTransactionalDocumentActionBase but is necessary for this document
035 * type. The Auxiliary Voucher is unique in that it defines several fields that aren't typically used by the other financial
036 * transaction processing eDocs (i.e. external system fields, object type override, credit and debit amounts).
037 */
038 public class AuxiliaryVoucherAction extends VoucherAction {
039 /**
040 * Overrides the parent and then calls the super method after checking to see if the user just changed the voucher type.
041 *
042 * @see org.kuali.rice.kns.web.struts.action.KualiAction#execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
043 * HttpServletResponse response)
044 */
045 @Override
046 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
047 AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
048
049 // now check to see if the voucher type was changed and if so, we want to
050 // set the method to call so that the appropriate action can be invoked
051 // did it this way b/c the changing of the type causes the page to re-submit
052 // and we need to process some stuff if it's changed
053 ActionForward returnForward;
054 if (StringUtils.isNotBlank(avForm.getOriginalVoucherType()) && !avForm.getAuxiliaryVoucherDocument().getTypeCode().equals(avForm.getOriginalVoucherType())) {
055 returnForward = super.dispatchMethod(mapping, form, request, response, KFSConstants.AuxiliaryVoucher.CHANGE_VOUCHER_TYPE);
056 }
057 else { // otherwise call the super
058 returnForward = super.execute(mapping, avForm, request, response);
059 }
060 return returnForward;
061 }
062
063 /**
064 * This action method is responsible for clearing the GLPEs for an AV after the voucher type changes, since a voucher type
065 * change makes any previously generated GLPEs inaccurate.
066 *
067 * @param mapping
068 * @param form
069 * @param request
070 * @param response
071 * @return ActionForward
072 * @throws Exception
073 */
074 public ActionForward changeVoucherType(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
075 AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
076
077 AuxiliaryVoucherDocument avDoc = avForm.getAuxiliaryVoucherDocument();
078
079 // clear the glpes now
080 avDoc.getGeneralLedgerPendingEntries().clear();
081
082 // make sure to set the original type to the new one now
083 avForm.setOriginalVoucherType(avDoc.getTypeCode());
084
085 return mapping.findForward(KFSConstants.MAPPING_BASIC);
086 }
087
088 /**
089 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#docHandler(org.apache.struts.action.ActionMapping,
090 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
091 */
092 @Override
093 public ActionForward docHandler(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
094 ActionForward forward = super.docHandler(mapping, form, request, response);
095
096 // Fix for KULEDOCS-1701, update the original voucher type so that the execute method in
097 // this class will call the right block of code
098 AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
099 AuxiliaryVoucherDocument avDoc = avForm.getAuxiliaryVoucherDocument();
100 avForm.setOriginalVoucherType(avDoc.getTypeCode());
101
102 return forward;
103 }
104 }