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.authorization;
017
018 import java.util.Set;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.kfs.sys.KFSConstants;
022 import org.kuali.kfs.sys.businessobject.AccountingLine;
023 import org.kuali.kfs.sys.context.SpringContext;
024 import org.kuali.kfs.sys.document.AccountingDocument;
025 import org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase;
026 import org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.APPLICATION_PARAMETER;
027 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
028 import org.kuali.rice.kim.bo.Person;
029 import org.kuali.rice.kns.service.DataDictionaryService;
030 import org.kuali.rice.kns.service.ParameterEvaluator;
031 import org.kuali.rice.kns.service.ParameterService;
032
033 /**
034 * Authorizer which deals with financial processing document issues, specifically sales tax lines on documents
035 */
036 public class FinancialProcessingAccountingLineAuthorizer extends AccountingLineAuthorizerBase {
037 private final static String SALES_TAX_DOCUMENT_TYPES_PARAMETER_NAME = "SALES_TAX_APPLICABLE_DOCUMENT_TYPES";
038 private final static String SALES_TAX_LINE_ACCOUNT_OBJECT_CODES_PARAMETER_NAME = "SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES";
039
040 /**
041 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getUnviewableBlocks(org.kuali.kfs.sys.document.AccountingDocument, org.kuali.kfs.sys.businessobject.AccountingLine, boolean, org.kuali.rice.kim.bo.Person)
042 */
043 @Override
044 public Set<String> getUnviewableBlocks(AccountingDocument accountingDocument, AccountingLine accountingLine, boolean newLine, Person currentUser) {
045 Set unviewableBlocks = super.getUnviewableBlocks(accountingDocument, accountingLine, newLine, currentUser);
046 if (salesTaxUnviewable(accountingDocument, accountingLine)) {
047 unviewableBlocks.add(KFSConstants.AccountingLineViewStandardBlockNames.SALES_TAX_BLOCK);
048 }
049 return unviewableBlocks;
050 }
051
052 /**
053 * Determines if the given line on the given document should not show any sales tax block it has
054 * @param document the document the line lives on (or will live on)
055 * @param line the accounting line which perhaps should be hiding any sales tax information
056 * @return true if sales tax should not be seen for the line, false otherwise
057 */
058 protected boolean salesTaxUnviewable(AccountingDocument document, AccountingLine line) {
059 ParameterService parameterService = SpringContext.getBean(ParameterService.class);
060 String docTypeCode = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(document.getClass());
061 ParameterEvaluator docTypeEvaluator = parameterService.getParameterEvaluator(KfsParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, FinancialProcessingAccountingLineAuthorizer.SALES_TAX_DOCUMENT_TYPES_PARAMETER_NAME, docTypeCode);
062 if (!docTypeEvaluator.evaluationSucceeds()) return true;
063 if (!StringUtils.isEmpty(line.getFinancialObjectCode()) && !StringUtils.isEmpty(line.getAccountNumber())) {
064 String compare = line.getAccountNumber() + ":" + line.getFinancialObjectCode();
065 ParameterEvaluator salesTaxApplicableAccountAndObjectEvaluator = parameterService.getParameterEvaluator(KfsParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES, compare);
066 if (!salesTaxApplicableAccountAndObjectEvaluator.evaluationSucceeds()) return true;
067 return false;
068 }
069 return true;
070 }
071 }
072