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.ar.document.validation.impl; 017 018 import org.kuali.kfs.module.ar.ArConstants; 019 import org.kuali.kfs.module.ar.ArKeyConstants; 020 import org.kuali.kfs.module.ar.ArPropertyConstants; 021 import org.kuali.kfs.module.ar.document.CustomerCreditMemoDocument; 022 import org.kuali.kfs.sys.context.SpringContext; 023 import org.kuali.rice.kns.document.Document; 024 import org.kuali.rice.kns.rules.PromptBeforeValidationBase; 025 import org.kuali.rice.kns.service.KualiConfigurationService; 026 027 public class CustomerCreditMemoDocumentPreRules extends PromptBeforeValidationBase { 028 029 /** 030 * @see org.kuali.rice.kns.rules.PromptBeforeValidationBase#doRules(org.kuali.rice.kns.document.Document) 031 */ 032 @Override 033 public boolean doPrompts(Document document) { 034 boolean preRulesOK = conditionallyAskQuestion(document); 035 return preRulesOK; 036 } 037 038 /** 039 * This method checks if there is at least one discount applied to the invoice and generates yes/no question 040 * 041 * @param document the maintenance document 042 * @return 043 */ 044 protected boolean conditionallyAskQuestion(Document document) { 045 CustomerCreditMemoDocument customerCreditMemoDocument = (CustomerCreditMemoDocument) document; 046 boolean shouldAskQuestion = customerCreditMemoDocument.getInvoice().hasAtLeastOneDiscount(); 047 if (shouldAskQuestion) { 048 String questionText = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(ArKeyConstants.WARNING_CUSTOMER_CREDIT_MEMO_DOCUMENT_INVOICE_HAS_DISCOUNT); 049 boolean confirm = super.askOrAnalyzeYesNoQuestion(ArConstants.CustomerCreditMemoConstants.GENERATE_CUSTOMER_CREDIT_MEMO_DOCUMENT_QUESTION_ID, questionText); 050 if (!confirm) { 051 super.abortRulesCheck(); 052 } 053 } 054 return true; 055 } 056 057 }