View Javadoc
1   /*
2    * Copyright 2005-2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.web.struts;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.servlet.http.HttpServletRequest;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.struts.util.LabelValueBean;
25  import org.kuali.ole.fp.businessobject.CapitalAssetInformation;
26  import org.kuali.ole.fp.businessobject.CashDrawer;
27  import org.kuali.ole.fp.businessobject.Check;
28  import org.kuali.ole.fp.document.CapitalAssetEditable;
29  import org.kuali.ole.fp.document.CashManagementDocument;
30  import org.kuali.ole.fp.document.CashReceiptDocument;
31  import org.kuali.ole.fp.document.service.CashManagementService;
32  import org.kuali.ole.fp.document.service.CashReceiptCoverSheetService;
33  import org.kuali.ole.fp.service.CashDrawerService;
34  import org.kuali.ole.sys.OLEConstants;
35  import org.kuali.ole.sys.OLEConstants.DocumentStatusCodes.CashReceipt;
36  import org.kuali.ole.sys.OLEKeyConstants;
37  import org.kuali.ole.sys.context.SpringContext;
38  import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
39  import org.kuali.rice.core.api.config.property.ConfigurationService;
40  import org.kuali.rice.core.api.util.type.KualiDecimal;
41  import org.kuali.rice.core.web.format.SimpleBooleanFormatter;
42  import org.kuali.rice.krad.util.GlobalVariables;
43  
44  /**
45   * This class is the action form for Cash Receipts.
46   */
47  public class CashReceiptForm extends CapitalAccountingLinesFormBase implements CapitalAssetEditable{
48      protected static final long serialVersionUID = 1L;
49      protected static final String CAN_PRINT_COVERSHEET_SIG_STR = "isCoverSheetPrintingAllowed";
50  
51      protected Check newCheck;
52      protected Check newConfirmedCheck;
53  
54      protected KualiDecimal checkTotal;
55  
56      protected String checkEntryMode;
57      protected List checkEntryModes;
58  
59      protected List baselineChecks;
60      
61      protected List<CapitalAssetInformation> capitalAssetInformation;
62  
63      /**
64       * Constructs a CashReceiptForm.java.
65       */
66      public CashReceiptForm() {
67          super();
68          setFormatterType(CAN_PRINT_COVERSHEET_SIG_STR, SimpleBooleanFormatter.class);
69          setNewCheck(getCashReceiptDocument().createNewCheck());
70          setNewConfirmedCheck(getCashReceiptDocument().createNewConfirmedCheck());
71  
72          checkEntryModes = new ArrayList();
73          checkEntryModes.add(new LabelValueBean("Individual Checks/Batches", CashReceiptDocument.CHECK_ENTRY_DETAIL));
74          checkEntryModes.add(new LabelValueBean("Total Only", CashReceiptDocument.CHECK_ENTRY_TOTAL));
75          
76          baselineChecks = new ArrayList();
77          capitalAssetInformation = new ArrayList<CapitalAssetInformation>();
78          this.capitalAccountingLine.setCanCreateAsset(false); //This document can only edit asset information
79      }
80  
81      @Override
82      protected String getDefaultDocumentTypeName() {
83          return "OLE_CR";
84      }
85      
86      @Override
87      public void populate(HttpServletRequest request) {
88          super.populate(request);
89  
90          setCheckEntryMode(getCashReceiptDocument().getCheckEntryMode());
91      }
92  
93      /**
94       * @return CashReceiptDocument
95       */
96      public CashReceiptDocument getCashReceiptDocument() {
97          return (CashReceiptDocument) getDocument();
98      }
99  
100     /**
101      * @return Check
102      */
103     public Check getNewCheck() {
104         return newCheck;
105     }
106 
107     /**
108      * @param newCheck
109      */
110     public void setNewCheck(Check newCheck) {
111         this.newCheck = newCheck;
112     }
113     
114     /**
115      * @return Confirmed Check
116      */
117     public Check getNewConfirmedCheck() {
118         return newConfirmedCheck;
119     }
120 
121     /**
122      * @param newConfirmedCheck
123      */
124     public void setNewConfirmedCheck(Check newConfirmedCheck) {
125         this.newConfirmedCheck = newConfirmedCheck;
126     }
127 
128     /**
129      * @param checkTotal
130      */
131     public void setCheckTotal(KualiDecimal checkTotal) {
132         this.checkTotal = checkTotal;
133     }
134 
135     /**
136      * @return KualiDecimal
137      */
138     public KualiDecimal getCheckTotal() {
139         return checkTotal;
140     }
141 
142     /**
143      * @return List of LabelValueBeans representing all available check entry modes
144      */
145     public List getCheckEntryModes() {
146         return checkEntryModes;
147     }
148 
149     /**
150      * @return String
151      */
152     public String getCheckEntryMode() {
153         return checkEntryMode;
154     }
155 
156     /**
157      * @param checkEntryMode
158      */
159     public void setCheckEntryMode(String checkEntryMode) {
160         this.checkEntryMode = checkEntryMode;
161     }
162 
163     /**
164      * @return boolean
165      */
166     public boolean isCheckEntryDetailMode() {
167         return CashReceiptDocument.CHECK_ENTRY_DETAIL.equals(getCheckEntryMode());
168     }
169 
170     /**
171      * @return current List of baseline checks for use in update detection
172      */
173     public List getBaselineChecks() {
174         return baselineChecks;
175     }
176 
177     /**
178      * Sets the current List of baseline checks to the given List
179      * 
180      * @param baselineChecks
181      */
182     public void setBaselineChecks(List baselineChecks) {
183         this.baselineChecks = baselineChecks;
184     }
185 
186     /**
187      * @param index
188      * @return true if a baselineCheck with the given index exists
189      */
190     public boolean hasBaselineCheck(int index) {
191         boolean has = false;
192 
193         if ((index >= 0) && (index < baselineChecks.size())) {
194             has = true;
195         }
196 
197         return has;
198     }
199 
200     /**
201      * Implementation creates empty Checks as a side-effect, so that Struts' efforts to set fields of lines which haven't been
202      * created will succeed rather than causing a NullPointerException.
203      * 
204      * @param index
205      * @return baseline Check at the given index
206      */
207     public Check getBaselineCheck(int index) {
208         while (baselineChecks.size() <= index) {
209             baselineChecks.add(getCashReceiptDocument().createNewCheck());
210         }
211         return (Check) baselineChecks.get(index);
212     }
213 
214     /**
215      * Gets the financialDocumentStatusMessage which is dependent upon document state.
216      * 
217      * @return Returns the financialDocumentStatusMessage.
218      */
219     public String getFinancialDocumentStatusMessage() {
220         String financialDocumentStatusMessage = "";
221         CashReceiptDocument crd = getCashReceiptDocument();
222         String financialDocumentStatusCode = crd.getFinancialSystemDocumentHeader().getFinancialDocumentStatusCode();
223         if (financialDocumentStatusCode.equals(CashReceipt.VERIFIED)) {
224             financialDocumentStatusMessage = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashReceipt.MSG_VERIFIED_BUT_NOT_AWAITING_DEPOSIT);
225         }
226         else if (financialDocumentStatusCode.equals(CashReceipt.INTERIM) || financialDocumentStatusCode.equals(CashReceipt.FINAL)) {
227             CashManagementDocument cmd = SpringContext.getBean(CashManagementService.class).getCashManagementDocumentForCashReceiptId(crd.getDocumentNumber());
228             if (cmd != null) {
229                 String cmdFinancialDocNbr = cmd.getDocumentNumber();
230 
231                 String loadCMDocUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashManagement.URL_LOAD_DOCUMENT_CASH_MGMT);
232                 loadCMDocUrl = StringUtils.replace(loadCMDocUrl, "{0}", cmdFinancialDocNbr);
233 
234                 financialDocumentStatusMessage = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashReceipt.MSG_VERIFIED_AND_AWAITING_DEPOSIT);
235                 financialDocumentStatusMessage = StringUtils.replace(financialDocumentStatusMessage, "{0}", loadCMDocUrl);
236             }
237         }
238         else if (financialDocumentStatusCode.equals(OLEConstants.DocumentStatusCodes.APPROVED)) {
239             CashManagementDocument cmd = SpringContext.getBean(CashManagementService.class).getCashManagementDocumentForCashReceiptId(crd.getDocumentNumber());
240             if (cmd != null) {
241                 String cmdFinancialDocNbr = cmd.getDocumentNumber();
242 
243                 String loadCMDocUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashManagement.URL_LOAD_DOCUMENT_CASH_MGMT);
244                 loadCMDocUrl = StringUtils.replace(loadCMDocUrl, "{0}", cmdFinancialDocNbr);
245 
246                 financialDocumentStatusMessage = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashReceipt.MSG_VERIFIED_AND_DEPOSITED);
247                 financialDocumentStatusMessage = StringUtils.replace(financialDocumentStatusMessage, "{0}", loadCMDocUrl);
248             }
249         }
250         return financialDocumentStatusMessage;
251     }
252 
253     /**
254      * This method will build out a message in the case the document is ENROUTE and the cash drawer is closed.
255      * 
256      * @return String
257      */
258     public String getCashDrawerStatusMessage() {
259         String cashDrawerStatusMessage = "";
260         CashReceiptDocument crd = getCashReceiptDocument();
261 
262         // first check to see if the document is in the appropriate state for this message
263         if (crd != null
264                 && crd.getDocumentHeader() != null
265                 && crd.getDocumentHeader().getWorkflowDocument() != null) {
266             if (crd.getDocumentHeader().getWorkflowDocument().isEnroute()) {
267                 CashDrawer cd = SpringContext.getBean(CashDrawerService.class).getByCampusCode(crd.getCampusLocationCode());
268                 if ( cd != null ) {
269                     if (crd.getDocumentHeader().getWorkflowDocument().isApprovalRequested()
270                             && cd.isClosed()
271                             && !SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(crd.getDocumentHeader().getWorkflowDocument(), GlobalVariables.getUserSession().getPrincipalId())) {
272                         cashDrawerStatusMessage = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashReceipt.MSG_CASH_DRAWER_CLOSED_VERIFICATION_NOT_ALLOWED);
273                     cashDrawerStatusMessage = StringUtils.replace(cashDrawerStatusMessage, "{0}", crd.getCampusLocationCode());
274                 }
275             }
276         }
277         }
278 
279         return cashDrawerStatusMessage;
280     }
281 
282     /**
283      * determines if the <code>{@link CashReceiptDocument}</code> is in a state that allows printing of the cover sheet.
284      * 
285      * @return boolean
286      */
287     public boolean isCoverSheetPrintingAllowed() {
288         return SpringContext.getBean(CashReceiptCoverSheetService.class).isCoverSheetPrintingAllowed(getCashReceiptDocument());
289     }
290 
291     /**
292      * @see org.kuali.ole.fp.document.CapitalAssetEditable#getCapitalAssetInformation()
293      */
294     @Override
295     public List<CapitalAssetInformation> getCapitalAssetInformation() {
296         return this.capitalAssetInformation;
297     }
298 
299     /**
300      * @see org.kuali.ole.fp.document.CapitalAssetEditable#setCapitalAssetInformation(org.kuali.ole.fp.businessobject.CapitalAssetInformation)
301      */
302     @Override
303     public void setCapitalAssetInformation(List<CapitalAssetInformation> capitalAssetInformation) {
304         this.capitalAssetInformation = capitalAssetInformation;        
305     }
306     
307     /**
308      * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase#getExcludedmethodToCall()
309      */
310     @Override
311     protected List<String> getExcludedmethodToCall() {
312         List<String> execludedMethodToCall = super.getExcludedmethodToCall();
313         execludedMethodToCall.add("printCoverSheet");
314         
315         return execludedMethodToCall;
316     } 
317 }