001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.module.purap.document.validation.impl;
017    
018    import org.kuali.kfs.module.purap.PurapConstants;
019    import org.kuali.kfs.module.purap.PurapParameterConstants;
020    import org.kuali.kfs.module.purap.document.AccountsPayableDocument;
021    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
022    import org.kuali.kfs.module.purap.document.VendorCreditMemoDocument;
023    import org.kuali.kfs.sys.context.SpringContext;
024    import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
025    import org.kuali.rice.kns.document.Document;
026    import org.kuali.rice.kns.service.ParameterService;
027    import org.kuali.rice.kns.web.format.CurrencyFormatter;
028    
029    /**
030     * Business rule(s) applicable to the Credit Memo document.
031     */
032    public class CreditMemoDocumentPreRules extends AccountsPayableDocumentPreRulesBase {
033    
034        /**
035         * Default constructor
036         */
037        public CreditMemoDocumentPreRules() {
038            super();
039        }
040    
041        /**
042         * @see org.kuali.rice.kns.rules.PromptBeforeValidationBase#doRules(org.kuali.rice.kns.document.Document)
043         */
044        @Override
045        public boolean doPrompts(Document document) {
046            return super.doPrompts(document);
047        }
048    
049        /**
050         * @see org.kuali.kfs.module.purap.document.validation.impl.AccountsPayableDocumentPreRulesBase#getDocumentName()
051         */
052        @Override
053        public String getDocumentName() {
054            return "Credit Memo";
055        }
056        
057        /** 
058         * @see org.kuali.kfs.module.purap.document.validation.impl.AccountsPayableDocumentPreRulesBase#createInvoiceNoMatchQuestionText(org.kuali.kfs.module.purap.document.AccountsPayableDocument)
059         */
060        @Override
061        public String createInvoiceNoMatchQuestionText(AccountsPayableDocument accountsPayableDocument){
062            
063            String questionText = super.createInvoiceNoMatchQuestionText(accountsPayableDocument);                
064            
065            CurrencyFormatter cf = new CurrencyFormatter();
066            VendorCreditMemoDocument cm = (VendorCreditMemoDocument) accountsPayableDocument;
067            StringBuffer questionTextBuffer = new StringBuffer("");
068            questionTextBuffer.append(questionText);
069            
070            questionTextBuffer.append("[br][br][b]Summary Detail Below[/b][br][br][table questionTable]");
071            questionTextBuffer.append("[tr][td leftTd]Credit Memo Amount entered on start screen:[/td][td rightTd]").append((String)cf.format(cm.getInitialAmount())).append("[/td][/tr]");
072            questionTextBuffer.append("[tr][td leftTd]Total credit processed prior to restocking fee:[/td][td rightTd]").append((String)cf.format(cm.getLineItemTotal())).append("[/td][/tr]");
073            
074            //if sales tax is enabled, show additional summary lines
075            boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getIndicatorParameter(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);                
076            if(salesTaxInd){
077                questionTextBuffer.append("[tr][td leftTd]Grand Total Prior to Tax:[/td][td rightTd]").append((String)cf.format(cm.getGrandPreTaxTotal())).append("[/td][/tr]");
078                questionTextBuffer.append("[tr][td leftTd]Grand Total Tax:[/td][td rightTd]").append((String)cf.format(cm.getGrandTaxAmount())).append("[/td][/tr]");
079            }
080            
081            questionTextBuffer.append("[tr][td leftTd]Grand Total:[/td][td rightTd]").append((String)cf.format(cm.getGrandTotal())).append("[/td][/tr][/table]");
082    
083            return questionTextBuffer.toString();
084            
085        }
086        
087        @Override
088        protected boolean checkCAMSWarningStatus(PurchasingAccountsPayableDocument purapDocument) {
089            return PurapConstants.CAMSWarningStatuses.CREDIT_MEMO_STATUS_WARNING_NO_CAMS_DATA.contains(purapDocument.getStatusCode());
090        }
091        
092    }