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.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.PurapParameterConstants;
20  import org.kuali.ole.module.purap.document.AccountsPayableDocument;
21  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
22  import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.ole.sys.service.impl.OleParameterConstants;
25  import org.kuali.rice.core.web.format.CurrencyFormatter;
26  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27  import org.kuali.rice.krad.document.Document;
28  
29  /**
30   * Business rule(s) applicable to the Credit Memo document.
31   */
32  public class CreditMemoDocumentPreRules extends AccountsPayableDocumentPreRulesBase {
33  
34      /**
35       * Default constructor
36       */
37      public CreditMemoDocumentPreRules() {
38          super();
39      }
40  
41      /**
42       * @see org.kuali.rice.kns.rules.PromptBeforeValidationBase#doRules(org.kuali.rice.krad.document.Document)
43       */
44      @Override
45      public boolean doPrompts(Document document) {
46          return super.doPrompts(document);
47      }
48  
49      /**
50       * @see org.kuali.ole.module.purap.document.validation.impl.AccountsPayableDocumentPreRulesBase#getDocumentName()
51       */
52      @Override
53      public String getDocumentName() {
54          return "Credit Memo";
55      }
56  
57      /**
58       * @see org.kuali.ole.module.purap.document.validation.impl.AccountsPayableDocumentPreRulesBase#createInvoiceNoMatchQuestionText(org.kuali.ole.module.purap.document.AccountsPayableDocument)
59       */
60      @Override
61      public String createInvoiceNoMatchQuestionText(AccountsPayableDocument accountsPayableDocument) {
62  
63          String questionText = super.createInvoiceNoMatchQuestionText(accountsPayableDocument);
64  
65          CurrencyFormatter cf = new CurrencyFormatter();
66          VendorCreditMemoDocument cm = (VendorCreditMemoDocument) accountsPayableDocument;
67          StringBuffer questionTextBuffer = new StringBuffer("");
68          questionTextBuffer.append(questionText);
69  
70          questionTextBuffer.append("[br][br][b]Summary Detail Below[/b][br][br][table questionTable]");
71          questionTextBuffer.append("[tr][td leftTd]Credit Memo Amount entered on start screen:[/td][td rightTd]").append((String) cf.format(cm.getInitialAmount())).append("[/td][/tr]");
72          questionTextBuffer.append("[tr][td leftTd]Total credit processed prior to restocking fee:[/td][td rightTd]").append((String) cf.format(cm.getLineItemTotal())).append("[/td][/tr]");
73  
74          //if sales tax is enabled, show additional summary lines
75          boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
76          if (salesTaxInd) {
77              questionTextBuffer.append("[tr][td leftTd]Grand Total Prior to Tax:[/td][td rightTd]").append((String) cf.format(cm.getGrandPreTaxTotal())).append("[/td][/tr]");
78              questionTextBuffer.append("[tr][td leftTd]Grand Total Tax:[/td][td rightTd]").append((String) cf.format(cm.getGrandTaxAmount())).append("[/td][/tr]");
79          }
80  
81          questionTextBuffer.append("[tr][td leftTd]Grand Total:[/td][td rightTd]").append((String) cf.format(cm.getGrandTotal())).append("[/td][/tr][/table]");
82  
83          return questionTextBuffer.toString();
84  
85      }
86  
87      @Override
88      protected boolean checkCAMSWarningStatus(PurchasingAccountsPayableDocument purapDocument) {
89          return PurapConstants.CAMSWarningStatuses.CREDIT_MEMO_STATUS_WARNING_NO_CAMS_DATA.contains(purapDocument.getApplicationDocumentStatus());
90      }
91  
92      /**
93       * Determines if the amount entered on the init tab is mismatched with the grand total of the document.
94       *
95       * @param accountsPayableDocument
96       * @return
97       */
98      @Override
99      protected boolean validateInvoiceTotalsAreMismatched(AccountsPayableDocument accountsPayableDocument) {
100         boolean mismatched = false;
101         String[] excludeArray = {PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
102 
103         //  if UseTax is included, then the invoiceInitialAmount should be compared against the 
104         // total amount NOT INCLUDING tax
105         if (accountsPayableDocument.isUseTaxIndicator()) {
106             if (accountsPayableDocument.getTotalPreTaxDollarAmountAllItems(excludeArray).compareTo(accountsPayableDocument.getInitialAmount()) != 0 && !accountsPayableDocument.isUnmatchedOverride()) {
107                 mismatched = true;
108             }
109         }
110         //  if NO UseTax, then the invoiceInitialAmount should be compared against the 
111         // total amount INCLUDING sales tax (since if the vendor invoices with sales tax, then we pay it)
112         else {
113             if (accountsPayableDocument.getTotalDollarAmountAllItems(excludeArray).compareTo(accountsPayableDocument.getInitialAmount()) != 0 && !accountsPayableDocument.isUnmatchedOverride()) {
114                 mismatched = true;
115             }
116         }
117         return mismatched;
118     }
119 }