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.fp.document.validation.impl; 017 018 import java.text.MessageFormat; 019 020 import org.kuali.kfs.fp.businessobject.AdvanceDepositDetail; 021 import org.kuali.kfs.fp.document.AdvanceDepositDocument; 022 import org.kuali.kfs.fp.document.DisbursementVoucherDocument; 023 import org.kuali.kfs.fp.document.NonCheckDisbursementDocument; 024 import org.kuali.kfs.sys.KFSConstants; 025 import org.kuali.kfs.sys.KFSKeyConstants; 026 import org.kuali.kfs.sys.KFSPropertyConstants; 027 import org.kuali.kfs.sys.businessobject.Bank; 028 import org.kuali.kfs.sys.context.SpringContext; 029 import org.kuali.kfs.sys.service.BankService; 030 import org.kuali.rice.kns.document.Document; 031 import org.kuali.rice.kns.rules.PromptBeforeValidationBase; 032 import org.kuali.rice.kns.service.KualiConfigurationService; 033 034 /** 035 * Performs warning checks and prompts for AdvanceDeposit. 036 */ 037 public class AdvanceDepositDocumentPreRules extends PromptBeforeValidationBase { 038 039 @Override 040 public boolean doPrompts(Document document) { 041 boolean preRulesOK = true; 042 043 AdvanceDepositDocument adDocument = (AdvanceDepositDocument) document; 044 045 preRulesOK &= checkBankCodeActive(adDocument); 046 047 return preRulesOK; 048 } 049 050 /** 051 * If bank specification is enabled, prompts user to use the continuation bank code when the given bank code is inactive 052 * 053 * @param adDocument document containing bank code 054 * @return true 055 */ 056 protected boolean checkBankCodeActive(AdvanceDepositDocument adDocument) { 057 boolean continueRules = true; 058 059 // if bank specification is not enabled, no need to validate bank 060 if (!SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) { 061 return continueRules; 062 } 063 064 int questionIndex = 0; 065 for (AdvanceDepositDetail advanceDeposit : adDocument.getAdvanceDeposits()) { 066 questionIndex++; 067 068 // refresh bank reference so continuation bank can be checked for active status 069 advanceDeposit.refreshReferenceObject(KFSPropertyConstants.BANK); 070 Bank bank = advanceDeposit.getBank(); 071 072 // if bank is inactive and continuation is active, prompt user to use continuation bank 073 if (bank != null && !bank.isActive() && bank.getContinuationBank().isActive()) { 074 String questionText = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.QUESTION_BANK_INACTIVE); 075 questionText = MessageFormat.format(questionText, advanceDeposit.getFinancialDocumentBankCode(), bank.getContinuationBankCode()); 076 077 boolean useContinuation = super.askOrAnalyzeYesNoQuestion(KFSConstants.USE_CONTINUATION_BANK_QUESTION + questionIndex, questionText); 078 if (useContinuation) { 079 advanceDeposit.setFinancialDocumentBankCode(bank.getContinuationBankCode()); 080 } 081 } 082 } 083 084 return continueRules; 085 } 086 087 }