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