View Javadoc
1   /*
2    * Copyright 2008 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.validation.impl;
17  
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.ole.module.purap.PurapConstants;
21  import org.kuali.ole.module.purap.businessobject.PurApItem;
22  import org.kuali.ole.module.purap.businessobject.PurchasingItemBase;
23  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
24  import org.kuali.ole.module.purap.document.PurchasingDocumentBase;
25  import org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.rice.krad.document.Document;
28  
29  public abstract class PurchasingDocumentPreRulesBase extends PurapDocumentPreRulesBase {
30  
31      @Override
32      public boolean doPrompts(Document document) {
33          PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) document;
34  
35          boolean preRulesValid = super.doPrompts(document);
36  
37          if (StringUtils.isBlank(event.getQuestionContext()) || StringUtils.equals(question, PurapConstants.FIX_CAPITAL_ASSET_WARNINGS)) {
38              preRulesValid &= confirmFixCapitalAssetWarningConditions(purapDocument);
39          }
40  
41          return preRulesValid;
42      }
43  
44      protected boolean checkForTaxRecalculation(PurchasingAccountsPayableDocument purapDocument) {
45  
46          String initialZipCode = ((PurchasingFormBase) form).getInitialZipCode();
47          if (StringUtils.isNotEmpty(initialZipCode) && !StringUtils.equals(initialZipCode, ((PurchasingDocumentBase) purapDocument).getDeliveryPostalCode())) {
48              for (PurApItem purApItem : purapDocument.getItems()) {
49                  PurchasingItemBase item = (PurchasingItemBase) purApItem;
50                  if (item.getItemTaxAmount() != null) {
51  
52                      StringBuffer questionTextBuffer = new StringBuffer("");
53                      questionTextBuffer.append(PurapConstants.TAX_RECALCULATION_QUESTION);
54  
55                      Boolean proceed = super.askOrAnalyzeYesNoQuestion(PurapConstants.TAX_RECALCULATION_INFO, questionTextBuffer.toString());
56  
57                      //Set a marker to record that this method has been used.
58                      if (proceed && StringUtils.isBlank(event.getQuestionContext())) {
59                          event.setQuestionContext(PurapConstants.TAX_RECALCULATION_INFO);
60                      }
61  
62                      if (!proceed) {
63                          event.setActionForwardName(OLEConstants.MAPPING_BASIC);
64                          return false;
65                      }
66                  }
67              }
68          }
69  
70          return true;
71      }
72  
73  
74  }