View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.tem.document.authorization;
20  
21  import org.kuali.kfs.module.tem.TemConstants;
22  import org.kuali.kfs.module.tem.document.TravelAuthorizationDocument;
23  import org.kuali.kfs.module.tem.document.service.TravelDocumentService;
24  import org.kuali.kfs.sys.context.SpringContext;
25  
26  /**
27   * Abstract document presentation controller which will be a base of methods shared among presentation controllers used by the travel authorization,
28   * travel authorization amendment, and travel authorization close documents
29   */
30  public abstract class TravelAuthorizationFamilyDocumentPresentationController extends TravelDocumentPresentationController {
31      protected TravelDocumentService travelDocumentService; // not volatile because this object should never be accessible to more than one thread
32  
33      /**
34       * Determines if the vendor can be paid for this authorization
35       * @param document the authorization to check
36       * @return true if the vendor can be paid, false otherwise
37       */
38      public boolean canPayVendor(TravelAuthorizationDocument document) {
39          if (getTravelDocumentService().isUnsuccessful(document)) {
40              return false;
41          }
42          boolean enablePayments = getParameterService().getParameterValueAsBoolean(TravelAuthorizationDocument.class, TemConstants.TravelAuthorizationParameters.VENDOR_PAYMENT_ALLOWED_BEFORE_FINAL_APPROVAL_IND);
43          if (enablePayments) {
44              return !isRetired(document) && !isCancelled(document) && (document.getDocumentHeader() != null && !(document.getDocumentHeader().getWorkflowDocument().isCanceled() || document.getDocumentHeader().getWorkflowDocument().isInitiated() || document.getDocumentHeader().getWorkflowDocument().isException() || document.getDocumentHeader().getWorkflowDocument().isDisapproved() || document.getDocumentHeader().getWorkflowDocument().isSaved()));
45          } else {
46              return isOpen(document) && isFinalOrProcessed(document);
47          }
48      }
49  
50      /**
51       * Determines if the travel authorization is open for reimbursement or amendment
52       * @param document the authorization to check
53       * @return true if the authorization is open, false otherwise
54       */
55      protected boolean isOpen(TravelAuthorizationDocument document) {
56          return TemConstants.TravelAuthorizationStatusCodeKeys.OPEN_REIMB.equals(document.getAppDocStatus());
57      }
58  
59      /**
60       * Determines if the document is in processed workflow state
61       * @param document the document to check
62       * @return true if the document is in processed workflow state, false otherwise
63       */
64      protected boolean isFinalOrProcessed(TravelAuthorizationDocument document) {
65          return document.getDocumentHeader().getWorkflowDocument().isProcessed() || document.getDocumentHeader().getWorkflowDocument().isFinal();
66      }
67  
68      /**
69       * Determines if the document is in retired mode or not
70       * @param document the document to check
71       * @return true if the document is retired, false otherwise
72       */
73      protected boolean isRetired(TravelAuthorizationDocument document) {
74          return TemConstants.TravelAuthorizationStatusCodeKeys.RETIRED_VERSION.equals(document.getAppDocStatus());
75      }
76  
77      /**
78       * Determines if the document has been cancelled as a TA or not
79       * @param document the document to check
80       * @return true if the document is TA cancelled, false otherwise
81       */
82      protected boolean isCancelled(TravelAuthorizationDocument document) {
83          return TemConstants.TravelAuthorizationStatusCodeKeys.CANCELLED.equals(document.getAppDocStatus());
84      }
85  
86      /**
87       * @return the default implementation of the TravelDocumentService
88       */
89      protected TravelDocumentService getTravelDocumentService() {
90          if (travelDocumentService == null) {
91              travelDocumentService = SpringContext.getBean(TravelDocumentService.class);
92          }
93          return travelDocumentService;
94      }
95  }