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