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.module.endow.document.web.struts;
017
018 import static org.kuali.kfs.module.endow.EndowConstants.EXISTING_SOURCE_TRAN_LINE_PROPERTY_NAME;
019
020 import java.util.List;
021
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.http.HttpServletResponse;
024
025 import org.apache.struts.action.ActionForm;
026 import org.apache.struts.action.ActionForward;
027 import org.apache.struts.action.ActionMapping;
028 import org.kuali.kfs.module.endow.businessobject.EndowmentSourceTransactionLine;
029 import org.kuali.kfs.module.endow.businessobject.EndowmentTargetTransactionLine;
030 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine;
031 import org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument;
032 import org.kuali.kfs.module.endow.document.SecurityTransferDocument;
033 import org.kuali.kfs.module.endow.document.service.UpdateSecurityTransferTargetTaxLotsService;
034 import org.kuali.kfs.module.endow.document.service.UpdateTaxLotsBasedOnAccMethodAndTransSubtypeService;
035 import org.kuali.kfs.module.endow.document.validation.event.RefreshTransactionLineEvent;
036 import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
037 import org.kuali.kfs.sys.context.SpringContext;
038 import org.kuali.kfs.sys.document.AmountTotaling;
039 import org.kuali.rice.kns.service.KualiRuleService;
040
041 public class SecurityTransferDocumentAction extends EndowmentTaxLotLinesDocumentActionBase {
042
043
044 /**
045 * @see org.kuali.kfs.module.endow.document.web.struts.EndowmentTaxLotLinesDocumentActionBase#updateTransactionLineTaxLots(boolean, boolean, org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument, org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine)
046 */
047 @Override
048 protected void updateTransactionLineTaxLots(boolean isUpdate, boolean isSource, EndowmentTransactionLinesDocument etlDocument, EndowmentTransactionLine transLine) {
049 SecurityTransferDocument securityTransferDocument = (SecurityTransferDocument) etlDocument;
050
051 if (transLine instanceof EndowmentSourceTransactionLine) {
052 UpdateTaxLotsBasedOnAccMethodAndTransSubtypeService taxLotsService = SpringContext.getBean(UpdateTaxLotsBasedOnAccMethodAndTransSubtypeService.class);
053 taxLotsService.updateTransactionLineTaxLots(isUpdate, securityTransferDocument, transLine);
054 }
055
056 if (transLine instanceof EndowmentTargetTransactionLine) {
057 UpdateSecurityTransferTargetTaxLotsService taxLotsService = SpringContext.getBean(UpdateSecurityTransferTargetTaxLotsService.class);
058 taxLotsService.updateTransactionLineTaxLots(securityTransferDocument, transLine);
059 }
060
061 }
062
063 /**
064 * @see org.kuali.kfs.module.endow.document.web.struts.EndowmentTransactionLinesDocumentActionBase#deleteSourceTransactionLine(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
065 */
066 @Override
067 public ActionForward deleteSourceTransactionLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
068
069 ActionForward actionForward = super.deleteSourceTransactionLine(mapping, form, request, response);
070 EndowmentTransactionLinesDocumentFormBase etlForm = (EndowmentTransactionLinesDocumentFormBase) form;
071
072 // delete target transaction lines as well
073 List<EndowmentTransactionLine> targetTransactionLines = etlForm.getEndowmentTransactionLinesDocumentBase().getTargetTransactionLines();
074 if (targetTransactionLines != null && targetTransactionLines.size() > 0) {
075 for (int i = 0; i < targetTransactionLines.size(); i++) {
076 deleteTransactionLine(false, etlForm, i);
077 }
078 }
079
080 return actionForward;
081 }
082
083
084 /**
085 * @see org.kuali.kfs.module.endow.document.web.struts.EndowmentTaxLotLinesDocumentActionBase#deleteSourceTaxLotLine(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
086 */
087 @Override
088 public ActionForward deleteSourceTaxLotLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
089
090 ActionForward actionForward = super.deleteSourceTaxLotLine(mapping, form, request, response);
091 EndowmentTransactionLinesDocumentFormBase documentForm = (EndowmentTransactionLinesDocumentFormBase) form;
092 EndowmentTransactionLinesDocument endowmentDocument = (EndowmentTransactionLinesDocument) documentForm.getDocument();
093
094 boolean rulePassed = true;
095
096 // if the document has target transaction lines update the related tax lots
097 if (endowmentDocument.getTargetTransactionLines() != null && endowmentDocument.getTargetTransactionLines().size() > 0) {
098 for (int i = 0; i < endowmentDocument.getTargetTransactionLines().size(); i++) {
099
100 EndowmentTransactionLine transLine = endowmentDocument.getTargetTransactionLines().get(i);
101
102 // check any business rules
103 rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new RefreshTransactionLineEvent(EXISTING_SOURCE_TRAN_LINE_PROPERTY_NAME, endowmentDocument, transLine, i));
104
105 if (rulePassed) {
106 updateTransactionLineTaxLots(true, true, endowmentDocument, transLine);
107 }
108
109 if (endowmentDocument instanceof AmountTotaling)
110 ((FinancialSystemDocumentHeader) documentForm.getDocument().getDocumentHeader()).setFinancialDocumentTotalAmount(((AmountTotaling) endowmentDocument).getTotalDollarAmount());
111 }
112
113 }
114
115 return actionForward;
116 }
117
118
119 /**
120 * @see org.kuali.kfs.module.endow.document.web.struts.EndowmentTaxLotLinesDocumentActionBase#getRefreshTaxLotsOnSaveOrSubmit()
121 */
122 @Override
123 protected boolean getRefreshTaxLotsOnSaveOrSubmit() {
124 return false;
125 }
126
127 }