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.purap.service.impl; 017 018 import org.kuali.kfs.coa.businessobject.Account; 019 import org.kuali.kfs.coa.businessobject.ObjectCode; 020 import org.kuali.kfs.coa.businessobject.SubObjectCode; 021 import org.kuali.kfs.coa.service.ObjectCodeService; 022 import org.kuali.kfs.coa.service.SubObjectCodeService; 023 import org.kuali.kfs.module.purap.PurapKeyConstants; 024 import org.kuali.kfs.sys.KFSConstants; 025 import org.kuali.kfs.sys.KFSKeyConstants; 026 import org.kuali.kfs.sys.businessobject.AccountingLine; 027 import org.kuali.kfs.sys.context.SpringContext; 028 import org.kuali.kfs.sys.document.service.impl.AccountingLineRuleHelperServiceImpl; 029 import org.kuali.rice.kns.datadictionary.DataDictionary; 030 import org.kuali.rice.kns.util.GlobalVariables; 031 import org.kuali.rice.kns.util.ObjectUtils; 032 033 public class PurchasingAccountingLineRuleHelperServiceImpl extends PurapAccountingLineRuleHelperServiceImpl { 034 035 /** 036 * @see org.kuali.kfs.module.purap.service.impl.PurapAccountingLineRuleHelperServiceImpl#hasRequiredOverrides(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String) 037 * override the default implementation and throw our own error message for accounts that are expired. 038 */ 039 @Override 040 public boolean hasRequiredOverrides(AccountingLine line, String overrideCode) { 041 boolean retVal = true; 042 Account account = line.getAccount(); 043 if (!ObjectUtils.isNull(account) && account.isExpired()) { 044 GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME, PurapKeyConstants.ERROR_ITEM_ACCOUNT_EXPIRED, account.getAccountNumber()); 045 retVal = false; 046 } 047 return retVal; 048 } 049 050 public boolean isValidObjectCode(ObjectCode objectCode, DataDictionary dataDictionary, String errorPropertyName) { 051 String label = getObjectCodeLabel(); 052 053 // make sure it exists 054 if (ObjectUtils.isNull(objectCode)) { 055 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label); 056 return false; 057 } 058 059 Integer universityFiscalYear = getDocument().getPostingYearNextOrCurrent(); 060 ObjectCode objectCodeForValidation = (SpringContext.getBean(ObjectCodeService.class).getByPrimaryId(universityFiscalYear, objectCode.getChartOfAccountsCode(), objectCode.getFinancialObjectCode())); 061 062 // check active status 063 if (!objectCodeForValidation.isFinancialObjectActiveCode()) { 064 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label); 065 return false; 066 } 067 068 return true; 069 } 070 071 public boolean isValidSubObjectCode(SubObjectCode subObjectCode, DataDictionary dataDictionary, String errorPropertyName) { 072 String label = getSubObjectCodeLabel(); 073 074 // make sure it exists 075 if (ObjectUtils.isNull(subObjectCode)) { 076 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label); 077 return false; 078 } 079 080 Integer universityFiscalYear = getDocument().getPostingYearNextOrCurrent(); 081 SubObjectCode subObjectCodeForValidation = (SpringContext.getBean(SubObjectCodeService.class).getByPrimaryId(universityFiscalYear, subObjectCode.getChartOfAccountsCode(), subObjectCode.getAccountNumber(), subObjectCode.getFinancialObjectCode(), subObjectCode.getFinancialSubObjectCode())); 082 083 084 // check active flag 085 if (!subObjectCodeForValidation.isActive()) { 086 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label); 087 return false; 088 } 089 return true; 090 } 091 092 }