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.ar.document.web.struts; 017 018 import javax.servlet.http.HttpServletRequest; 019 020 import org.kuali.kfs.module.ar.businessobject.CashControlDetail; 021 import org.kuali.kfs.module.ar.document.CashControlDocument; 022 import org.kuali.kfs.sys.context.SpringContext; 023 import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentFormBase; 024 import org.kuali.rice.kew.exception.WorkflowException; 025 import org.kuali.rice.kns.document.Document; 026 import org.kuali.rice.kns.service.DocumentService; 027 import org.kuali.rice.kns.util.GlobalVariables; 028 import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; 029 030 public class CashControlDocumentForm extends FinancialSystemTransactionalDocumentFormBase { 031 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CashControlDocumentForm.class); 032 033 protected CashControlDetail newCashControlDetail; 034 protected String processingChartOfAccCodeAndOrgCode; 035 036 protected boolean cashPaymentMediumSelected; 037 038 /** 039 * Constructs a CashControlDocumentForm.java. 040 */ 041 public CashControlDocumentForm() { 042 043 super(); 044 045 } 046 047 @Override 048 protected String getDefaultDocumentTypeName() { 049 return "CTRL"; 050 } 051 052 /** 053 * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#populate(javax.servlet.http.HttpServletRequest) 054 */ 055 @Override 056 public void populate(HttpServletRequest request) { 057 058 super.populate(request); 059 060 CashControlDocument ccDoc = getCashControlDocument(); 061 062 if (hasDocumentId()) { 063 064 // apply populate to PaymentApplicationDocuments 065 for (CashControlDetail cashControlDetail : ccDoc.getCashControlDetails()) { 066 067 // populate workflowDocument in documentHeader, if needed 068 try { 069 KualiWorkflowDocument workflowDocument = null; 070 if (GlobalVariables.getUserSession().getWorkflowDocument(cashControlDetail.getReferenceFinancialDocumentNumber()) != null) { 071 workflowDocument = GlobalVariables.getUserSession().getWorkflowDocument(cashControlDetail.getReferenceFinancialDocumentNumber()); 072 } 073 else { 074 // gets the workflow document from doc service, doc service will also set the workflow document in the 075 // user's session 076 Document retrievedDocument = SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(cashControlDetail.getReferenceFinancialDocumentNumber()); 077 if (retrievedDocument == null) { 078 throw new WorkflowException("Unable to get retrieve document # " + cashControlDetail.getReferenceFinancialDocumentNumber() + " from document service getByDocumentHeaderId"); 079 } 080 workflowDocument = retrievedDocument.getDocumentHeader().getWorkflowDocument(); 081 } 082 083 cashControlDetail.getReferenceFinancialDocument().getDocumentHeader().setWorkflowDocument(workflowDocument); 084 } 085 catch (WorkflowException e) { 086 LOG.warn("Error while instantiating workflowDoc", e); 087 throw new RuntimeException("error populating documentHeader.workflowDocument", e); 088 } 089 } 090 } 091 092 } 093 094 /** 095 * This method gets the cash control document 096 * 097 * @return the CashControlDocument 098 */ 099 public CashControlDocument getCashControlDocument() { 100 return (CashControlDocument) getDocument(); 101 } 102 103 /** 104 * This method gets the new cash control detail 105 * 106 * @return cashControlDetail 107 */ 108 public CashControlDetail getNewCashControlDetail() { 109 return newCashControlDetail; 110 } 111 112 /** 113 * This method sets the new cash control detail 114 * 115 * @param newCashControlDetail 116 */ 117 public void setNewCashControlDetail(CashControlDetail newCashControlDetail) { 118 this.newCashControlDetail = newCashControlDetail; 119 } 120 121 /** 122 * This method gets the processingChartOfAccCodeAndOrgCode 123 * 124 * @return processingChartOfAccCodeAndOrgCode 125 */ 126 public String getProcessingChartOfAccCodeAndOrgCode() { 127 return this.getCashControlDocument().getAccountsReceivableDocumentHeader().getProcessingChartOfAccCodeAndOrgCode(); 128 } 129 130 /** 131 * This method sets processingChartOfAccCodeAndOrgCode 132 * 133 * @param processingChartOfAccCodeAndOrgCode 134 */ 135 public void setProcessingChartOfAccCodeAndOrgCode(String processingChartOfAccCodeAndOrgCode) { 136 this.processingChartOfAccCodeAndOrgCode = processingChartOfAccCodeAndOrgCode; 137 } 138 139 /** 140 * This method returns if payment medium is selected 141 * 142 * @return true if payment medium selected, false otherwise 143 */ 144 public boolean isCashPaymentMediumSelected() { 145 return cashPaymentMediumSelected; 146 } 147 148 /** 149 * This method sets if payments medium is selected 150 * 151 * @param cashPaymentMediumSelected 152 */ 153 public void setCashPaymentMediumSelected(boolean cashPaymentMediumSelected) { 154 this.cashPaymentMediumSelected = cashPaymentMediumSelected; 155 } 156 157 }