View Javadoc
1   /*
2    * Copyright 2007 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.web.struts;
17  
18  import org.kuali.ole.module.purap.PurapAuthorizationConstants.PaymentRequestEditMode;
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.module.purap.PurapConstants.PaymentRequestStatuses;
21  import org.kuali.ole.module.purap.businessobject.PurApItem;
22  import org.kuali.ole.module.purap.document.PaymentRequestDocument;
23  import org.kuali.ole.module.purap.document.service.PurapService;
24  import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.core.api.config.property.ConfigurationService;
28  import org.kuali.rice.kew.api.WorkflowDocument;
29  import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
30  import org.kuali.rice.kns.service.DocumentHelperService;
31  import org.kuali.rice.kns.web.ui.ExtraButton;
32  import org.kuali.rice.kns.web.ui.HeaderField;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.KRADConstants;
35  import org.kuali.rice.krad.util.ObjectUtils;
36  
37  import javax.servlet.http.HttpServletRequest;
38  import java.util.List;
39  
40  /**
41   * Struts Action Form for Payment Request document.
42   */
43  public class PaymentRequestForm extends AccountsPayableFormBase {
44  
45      /**
46       * Indicates whether tax has been calculated based on the tax area data.
47       * Tax calculation is enforced before preq can be routed for tax approval.
48       */
49      protected boolean calculatedTax;
50  
51      /**
52       * Constructs a PaymentRequestForm instance and sets up the appropriately casted document.
53       */
54      public PaymentRequestForm() {
55          super();
56          this.setNewPurchasingItemLine(setupNewPurchasingItemLine());
57          //on PO, account distribution should be read only
58          setReadOnlyAccountDistributionMethod(true);
59      }
60  
61      @Override
62      protected String getDefaultDocumentTypeName() {
63          return "OLE_PREQ";
64      }
65  
66      public boolean isCalculatedTax() {
67          return calculatedTax;
68      }
69  
70      public void setCalculatedTax(boolean calculatedTax) {
71          this.calculatedTax = calculatedTax;
72      }
73  
74      public PaymentRequestDocument getPaymentRequestDocument() {
75          return (PaymentRequestDocument) getDocument();
76      }
77  
78      public void setPaymentRequestDocument(PaymentRequestDocument purchaseOrderDocument) {
79          setDocument(purchaseOrderDocument);
80      }
81  
82      @Override
83      public void populateHeaderFields(WorkflowDocument workflowDocument) {
84          super.populateHeaderFields(workflowDocument);
85  
86          if (ObjectUtils.isNotNull(this.getPaymentRequestDocument().getPurapDocumentIdentifier())) {
87              getDocInfo().add(new HeaderField("DataDictionary.PaymentRequestDocument.attributes.purapDocumentIdentifier", ((PaymentRequestDocument) this.getDocument()).getPurapDocumentIdentifier().toString()));
88          } else {
89              getDocInfo().add(new HeaderField("DataDictionary.PaymentRequestDocument.attributes.purapDocumentIdentifier", "Not Available"));
90          }
91  
92          String applicationDocumentStatus = "Not Available";
93  
94          if (ObjectUtils.isNotNull(this.getPaymentRequestDocument().getApplicationDocumentStatus())) {
95              applicationDocumentStatus = workflowDocument.getApplicationDocumentStatus();
96          }
97  
98          getDocInfo().add(new HeaderField("DataDictionary.PaymentRequestDocument.attributes.applicationDocumentStatus", applicationDocumentStatus));
99      }
100 
101     /**
102      * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#setupNewPurchasingItemLine()
103      */
104     @Override
105     public PurApItem setupNewPurchasingItemLine() {
106         return new OlePurchaseOrderItem();
107     }
108 
109     /**
110      * Build additional payment request specific buttons and set extraButtons list.
111      *
112      * @return - list of extra buttons to be displayed to the user
113      *         <p/>
114      *         KRAD Conversion: Performs customization of an extra button.
115      *         <p/>
116      *         No data dictionary is involved.
117      */
118     @Override
119     public List<ExtraButton> getExtraButtons() {
120         extraButtons.clear(); // clear out the extra buttons array
121         PaymentRequestDocument paymentRequestDocument = this.getPaymentRequestDocument();
122         String externalImageURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY);
123         String appExternalImageURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
124 
125         if (canContinue()) {
126             addExtraButton("methodToCall.continuePREQ", externalImageURL + "buttonsmall_continue.gif", "Continue");
127             addExtraButton("methodToCall.clearInitFields", externalImageURL + "buttonsmall_clear.gif", "Clear");
128         } else {
129             if (getEditingMode().containsKey(PaymentRequestEditMode.HOLD)) {
130                 addExtraButton("methodToCall.addHoldOnPayment", appExternalImageURL + "buttonsmall_hold.gif", "Hold");
131             }
132 
133             if (getEditingMode().containsKey(PaymentRequestEditMode.REMOVE_HOLD) && paymentRequestDocument.isHoldIndicator()) {
134                 addExtraButton("methodToCall.removeHoldFromPayment", appExternalImageURL + "buttonsmall_removehold.gif", "Remove");
135             }
136 
137             if (getEditingMode().containsKey(PaymentRequestEditMode.REQUEST_CANCEL)) {
138                 addExtraButton("methodToCall.requestCancelOnPayment", appExternalImageURL + "buttonsmall_requestcancel.gif", "Cancel");
139             }
140 
141             if (getEditingMode().containsKey(PaymentRequestEditMode.REMOVE_REQUEST_CANCEL) && paymentRequestDocument.isPaymentRequestedCancelIndicator()) {
142                 addExtraButton("methodToCall.removeCancelRequestFromPayment", appExternalImageURL + "buttonsmall_remreqcanc.gif", "Remove");
143             }
144 
145             if (canCalculate()) {
146                 addExtraButton("methodToCall.calculate", appExternalImageURL + "buttonsmall_calculate.gif", "Calculate");
147             }
148 
149             if (getEditingMode().containsKey(PaymentRequestEditMode.ACCOUNTS_PAYABLE_PROCESSOR_CANCEL) ||
150                     getEditingMode().containsKey(PaymentRequestEditMode.ACCOUNTS_PAYABLE_MANAGER_CANCEL)) {
151                 if (PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(paymentRequestDocument.getPurchaseOrderDocument().getApplicationDocumentStatus())) {
152                     //if the PO is CLOSED, show the 'open order' button; but only if there are no pending actions on the PO
153                     if (!paymentRequestDocument.getPurchaseOrderDocument().isPendingActionIndicator()) {
154                         addExtraButton("methodToCall.reopenPo", appExternalImageURL + "buttonsmall_openorder.gif", "Reopen PO");
155                     }
156                 } else {
157                     if (!paymentRequestDocument.getFinancialSystemDocumentHeader().getWorkflowDocument().isDisapproved()) {
158                         addExtraButton("methodToCall.cancel", externalImageURL + "buttonsmall_cancel.gif", "Cancel");
159                     }
160                 }
161             }
162         }
163 
164         return extraButtons;
165     }
166 
167     /**
168      * Determines whether the current user can continue creating or clear fields of the payment request in initial status. Conditions:
169      * - the Payment Request must be in the INITIATE state; and
170      * - the user must have the authorization to initiate a Payment Request.
171      *
172      * @return True if the current user can continue creating or clear fields of the initiated Payment Request.
173      */
174     public boolean canContinue() {
175         // preq must be in initiated status
176         boolean can = PaymentRequestStatuses.APPDOC_INITIATE.equals(getPaymentRequestDocument().getApplicationDocumentStatus());
177 
178         // check user authorization
179         if (can) {
180             DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPaymentRequestDocument());
181             can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PAYMENT_REQUEST, GlobalVariables.getUserSession().getPerson());
182         }
183 
184         return can;
185     }
186 
187     /**
188      * Determine whether the current user can calculate the paymentRequest. Conditions:
189      * - Payment Request is not FullDocumentEntryCompleted, and
190      * - current user has the permission to edit the document.
191      *
192      * @return True if the current user can calculate the Payment Request.
193      */
194     public boolean canCalculate() {
195         // preq must not be FullDocumentEntryCompleted
196         boolean can = !SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(getPaymentRequestDocument());
197 
198         // check user authorization: whoever can edit can calculate
199         can = can && documentActions.containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT);
200 
201         //FIXME this is temporary so that calculate will show up at tax
202         can = can || editingMode.containsKey(PaymentRequestEditMode.TAX_AREA_EDITABLE);
203 
204         return can;
205     }
206 
207     /**
208      * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
209      */
210     @Override
211     public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
212         if (KRADConstants.DISPATCH_REQUEST_PARAMETER.equals(methodToCallParameterName) &&
213                 ("changeUseTaxIndicator".equals(methodToCallParameterValue))) {
214             return true;
215         }
216         return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
217     }
218 
219 }
220