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 static org.kuali.kfs.sys.KFSKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_INVALID_ACCT_OBJ_CD;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.kfs.sys.businessobject.AccountingLine;
022 import org.kuali.kfs.sys.document.validation.GenericValidation;
023 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
024 import org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.APPLICATION_PARAMETER;
025 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
026 import org.kuali.rice.kns.service.ParameterEvaluator;
027 import org.kuali.rice.kns.service.ParameterService;
028 import org.kuali.rice.kns.util.GlobalVariables;
029
030 /**
031 * Validation that checks the sales tax account/object code combination on accounting lines of the cash receipt
032 */
033 public class CashReceiptAccountAndObjectCodeValidation extends GenericValidation {
034 private AccountingLine accountingLineForValidation;
035 private ParameterService parameterService;
036
037 /**
038 * This method processes the accounting line to make sure if a sales tax account is used the right object code is used with it
039 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
040 */
041 public boolean validate(AttributedDocumentEvent event) {
042 boolean isValid = true;
043 // not evaluating, just want to retrieve the evaluator to get the values of the parameter
044 // get the object code and account
045 String objCd = getAccountingLineForValidation().getFinancialObjectCode();
046 String account = getAccountingLineForValidation().getAccountNumber();
047 if (!StringUtils.isEmpty(objCd) && !StringUtils.isEmpty(account)) {
048 String[] params = getParameterService().getParameterValues(KfsParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES).toArray(new String[] {});
049 boolean acctsMatched = false;
050 for (int i = 0; i < params.length; i++) {
051 String paramAcct = params[i].split(":")[0];
052 if (account.equalsIgnoreCase(paramAcct)) {
053 acctsMatched = true;
054 }
055 }
056 if (acctsMatched) {
057 String compare = account + ":" + objCd;
058 ParameterEvaluator evaluator = getParameterService().getParameterEvaluator(KfsParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES, compare);
059 if (!evaluator.evaluationSucceeds()) {
060 isValid = false;
061 }
062 }
063
064 }
065 if (!isValid) {
066 GlobalVariables.getMessageMap().putError("accountNumber", ERROR_DOCUMENT_ACCOUNTING_LINE_INVALID_ACCT_OBJ_CD, account, objCd);
067 }
068 return isValid;
069 }
070
071 /**
072 * Gets the accountingLineForValidation attribute.
073 * @return Returns the accountingLineForValidation.
074 */
075 public AccountingLine getAccountingLineForValidation() {
076 return accountingLineForValidation;
077 }
078
079 /**
080 * Sets the accountingLineForValidation attribute value.
081 * @param accountingLineForValidation The accountingLineForValidation to set.
082 */
083 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
084 this.accountingLineForValidation = accountingLineForValidation;
085 }
086
087 /**
088 * Gets the parameterService attribute.
089 * @return Returns the parameterService.
090 */
091 public ParameterService getParameterService() {
092 return parameterService;
093 }
094
095 /**
096 * Sets the parameterService attribute value.
097 * @param parameterService The parameterService to set.
098 */
099 public void setParameterService(ParameterService parameterService) {
100 this.parameterService = parameterService;
101 }
102 }