View Javadoc
1   /*
2    * Copyright 2008-2009 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.module.purap.document.authorization;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapAuthorizationConstants;
20  import org.kuali.ole.module.purap.PurapAuthorizationConstants.CreditMemoEditMode;
21  import org.kuali.ole.module.purap.PurapConstants;
22  import org.kuali.ole.module.purap.PurapConstants.CreditMemoStatuses;
23  import org.kuali.ole.module.purap.PurapParameterConstants;
24  import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
25  import org.kuali.ole.module.purap.document.service.PurapService;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
29  import org.kuali.ole.sys.service.impl.OleParameterConstants;
30  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
31  import org.kuali.rice.kew.api.WorkflowDocument;
32  import org.kuali.rice.krad.document.Document;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.ObjectUtils;
35  
36  import java.util.Set;
37  
38  
39  public class VendorCreditMemoDocumentPresentationController extends PurchasingAccountsPayableDocumentPresentationController {
40  
41      @Override
42      public boolean canSave(Document document) {
43          VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) document;
44  
45          if (StringUtils.equals(vendorCreditMemoDocument.getApplicationDocumentStatus(), PurapConstants.CreditMemoStatuses.APPDOC_INITIATE)) {
46              return false;
47          }
48  
49          if (canEditPreExtraction(vendorCreditMemoDocument)) {
50              return true;
51          }
52  
53          return super.canSave(document);
54      }
55  
56      @Override
57      public boolean canReload(Document document) {
58          VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) document;
59  
60          if (StringUtils.equals(vendorCreditMemoDocument.getApplicationDocumentStatus(), PurapConstants.CreditMemoStatuses.APPDOC_INITIATE)) {
61              return false;
62          }
63  
64          if (canEditPreExtraction(vendorCreditMemoDocument)) {
65              return true;
66          }
67  
68          return super.canReload(document);
69      }
70  
71      @Override
72      public boolean canCancel(Document document) {
73          //controlling the cancel button through getExtraButtons in CreditMemoForm
74          return false;
75      }
76  
77      @Override
78      public boolean canDisapprove(Document document) {
79          //disapprove is never allowed for Credit Memo
80          return false;
81      }
82  
83      /**
84       * @see org.kuali.rice.krad.document.authorization.DocumentPresentationControllerBase#canEdit(org.kuali.rice.krad.document.Document)
85       */
86      @Override
87      public boolean canEdit(Document document) {
88          if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted((VendorCreditMemoDocument) document)) {
89              return false;
90          }
91  
92          return super.canEdit(document);
93      }
94  
95      /**
96       * @see org.kuali.rice.krad.document.authorization.TransactionalDocumentPresentationControllerBase#getEditModes(org.kuali.rice.krad.document.Document)
97       */
98      @Override
99      public Set<String> getEditModes(Document document) {
100         Set<String> editModes = super.getEditModes(document);
101 
102         VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) document;
103         WorkflowDocument workflowDocument = vendorCreditMemoDocument.getFinancialSystemDocumentHeader().getWorkflowDocument();
104 
105         if (canCancel(vendorCreditMemoDocument)) {
106             editModes.add(CreditMemoEditMode.ACCOUNTS_PAYABLE_PROCESSOR_CANCEL);
107         }
108 
109         if (canHold(vendorCreditMemoDocument)) {
110             editModes.add(CreditMemoEditMode.HOLD);
111         }
112 
113         if (canRemoveHold(vendorCreditMemoDocument)) {
114             editModes.add(CreditMemoEditMode.REMOVE_HOLD);
115         }
116 
117         if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(vendorCreditMemoDocument)) {
118             editModes.add(CreditMemoEditMode.FULL_DOCUMENT_ENTRY_COMPLETED);
119         } else {
120             if (ObjectUtils.isNotNull(vendorCreditMemoDocument.getPurchaseOrderDocument()) &&
121                     !vendorCreditMemoDocument.isSourceVendor() &&
122                     PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(vendorCreditMemoDocument.getPurchaseOrderDocument().getApplicationDocumentStatus())) {
123                 // TODO hjs-is this right? check to see if the checkbox is showing up for non-AP folks
124                 editModes.add(CreditMemoEditMode.ALLOW_REOPEN_PURCHASE_ORDER);
125             }
126         }
127 
128         if (StringUtils.equals(vendorCreditMemoDocument.getApplicationDocumentStatus(), PurapConstants.CreditMemoStatuses.APPDOC_INITIATE)) {
129             editModes.add(CreditMemoEditMode.DISPLAY_INIT_TAB);
130         }
131 
132         if (canEditPreExtraction(vendorCreditMemoDocument)) {
133             editModes.add(CreditMemoEditMode.EDIT_PRE_EXTRACT);
134         }
135 
136         if (!vendorCreditMemoDocument.isSourceDocumentPaymentRequest()) {
137             editModes.add(CreditMemoEditMode.LOCK_VENDOR_ENTRY);
138         }
139 
140         // See if purap tax is enabled
141         boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
142         if (salesTaxInd) {
143             editModes.add(PurapAuthorizationConstants.PURAP_TAX_ENABLED);
144 
145             if (vendorCreditMemoDocument.isUseTaxIndicator()) {
146                 // only allow tax editing if doc is not using use tax
147                 editModes.add(CreditMemoEditMode.LOCK_TAX_AMOUNT_ENTRY);
148             } else {
149                 // display the "clear all taxes" button if doc is not using use tax
150                 editModes.add(CreditMemoEditMode.CLEAR_ALL_TAXES);
151             }
152         }
153 
154         // Remove editBank edit mode if the document has been extracted
155         if (vendorCreditMemoDocument.isExtracted()) {
156             editModes.remove(OLEConstants.BANK_ENTRY_EDITABLE_EDITING_MODE);
157         }
158 
159         return editModes;
160     }
161 
162     /**
163      * Determines if the document can be put on hold. Credit memo not already on hold, extracted date is null, and credit memo
164      * status approved or complete.
165      *
166      * @param cmDocument - credit memo document to hold.
167      * @return boolean - true if hold can occur, false if not allowed.
168      */
169     protected boolean canHold(VendorCreditMemoDocument cmDocument) {
170         return !cmDocument.isHoldIndicator() && !cmDocument.isExtracted() && !PurapConstants.CreditMemoStatuses.STATUSES_DISALLOWING_HOLD.contains(cmDocument.getApplicationDocumentStatus());
171     }
172 
173     /**
174      * Determines if the document can be taken off hold.  Credit memo must be on hold.
175      *
176      * @param cmDocument - credit memo document that is on hold.
177      * @return boolean - true if document can be taken off hold, false if it cannot.
178      */
179     protected boolean canRemoveHold(VendorCreditMemoDocument cmDocument) {
180         return cmDocument.isHoldIndicator();
181     }
182 
183     /**
184      * Determines if the document can be canceled. Document can be canceled if not in canceled status already, extracted date is
185      * null, and hold indicator is false.
186      *
187      * @param cmDocument - credit memo document to cancel.
188      * @return boolean - true if document can be canceled, false if it cannot be.
189      */
190     protected boolean canCancel(VendorCreditMemoDocument cmDocument) {
191         return !CreditMemoStatuses.CANCELLED_STATUSES.contains(cmDocument.getApplicationDocumentStatus()) && !cmDocument.isExtracted() && !cmDocument.isHoldIndicator();
192     }
193 
194     protected boolean canEditPreExtraction(VendorCreditMemoDocument vendorCreditMemoDocument) {
195         return (!vendorCreditMemoDocument.isExtracted() &&
196                 !SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(vendorCreditMemoDocument.getFinancialSystemDocumentHeader().getWorkflowDocument(), GlobalVariables.getUserSession().getPrincipalId()) &&
197                 !PurapConstants.CreditMemoStatuses.CANCELLED_STATUSES.contains(vendorCreditMemoDocument.getApplicationDocumentStatus()));
198     }
199 
200 }