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 017 package org.kuali.kfs.fp.businessobject; 018 019 import static org.kuali.kfs.sys.KFSPropertyConstants.ACCOUNT_NUMBER; 020 import static org.kuali.kfs.sys.KFSPropertyConstants.AMOUNT; 021 import static org.kuali.kfs.sys.KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE; 022 import static org.kuali.kfs.sys.KFSPropertyConstants.CREDIT; 023 import static org.kuali.kfs.sys.KFSPropertyConstants.DEBIT; 024 import static org.kuali.kfs.sys.KFSPropertyConstants.FINANCIAL_OBJECT_CODE; 025 import static org.kuali.kfs.sys.KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE; 026 import static org.kuali.kfs.sys.KFSPropertyConstants.OBJECT_TYPE_CODE; 027 import static org.kuali.kfs.sys.KFSPropertyConstants.ORGANIZATION_REFERENCE_ID; 028 import static org.kuali.kfs.sys.KFSPropertyConstants.PROJECT_CODE; 029 import static org.kuali.kfs.sys.KFSPropertyConstants.REFERENCE_NUMBER; 030 import static org.kuali.kfs.sys.KFSPropertyConstants.REFERENCE_ORIGIN_CODE; 031 import static org.kuali.kfs.sys.KFSPropertyConstants.REFERENCE_TYPE_CODE; 032 import static org.kuali.kfs.sys.KFSPropertyConstants.SUB_ACCOUNT_NUMBER; 033 034 import java.util.Map; 035 036 import org.apache.commons.lang.StringUtils; 037 import org.kuali.kfs.coa.service.BalanceTypeService; 038 import org.kuali.kfs.sys.KFSConstants; 039 import org.kuali.kfs.sys.businessobject.SourceAccountingLine; 040 import org.kuali.kfs.sys.context.SpringContext; 041 042 /** 043 * This class represents a <code>JournalVoucherDocument</code> accounting line parser. 044 */ 045 public class JournalVoucherAccountingLineParser extends AuxiliaryVoucherAccountingLineParser { 046 private String balanceTypeCode; 047 protected static final String[] NON_OFFSET_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, AMOUNT }; 048 protected static final String[] OFFSET_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT }; 049 protected static final String[] ENCUMBRANCE_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, REFERENCE_ORIGIN_CODE, REFERENCE_TYPE_CODE, REFERENCE_NUMBER, DEBIT, CREDIT }; 050 051 /** 052 * Constructs a JournalVoucherAccountingLineParser.java. 053 * 054 * @param balanceTypeCode 055 */ 056 public JournalVoucherAccountingLineParser(String balanceTypeCode) { 057 super(); 058 this.balanceTypeCode = balanceTypeCode; 059 } 060 061 /** 062 * @see org.kuali.rice.kns.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map, 063 * org.kuali.rice.kns.bo.SourceAccountingLine, java.lang.String) 064 */ 065 @Override 066 protected void performCustomSourceAccountingLinePopulation(Map<String, String> attributeValueMap, SourceAccountingLine sourceAccountingLine, String accountingLineAsString) { 067 068 boolean isFinancialOffsetGeneration = SpringContext.getBean(BalanceTypeService.class).getBalanceTypeByCode(balanceTypeCode).isFinancialOffsetGenerationIndicator(); 069 if (isFinancialOffsetGeneration || StringUtils.equals(balanceTypeCode, KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) { 070 super.performCustomSourceAccountingLinePopulation(attributeValueMap, sourceAccountingLine, accountingLineAsString); 071 } 072 sourceAccountingLine.setBalanceTypeCode(balanceTypeCode); 073 } 074 075 /** 076 * @see org.kuali.rice.kns.bo.AccountingLineParserBase#getSourceAccountingLineFormat() 077 */ 078 @Override 079 public String[] getSourceAccountingLineFormat() { 080 return removeChartFromFormatIfNeeded(selectFormat()); 081 } 082 083 /** 084 * chooses line format based on balance type code 085 * 086 * @return String [] 087 */ 088 private String[] selectFormat() { 089 if (StringUtils.equals(balanceTypeCode, KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) { 090 return ENCUMBRANCE_FORMAT; 091 } 092 else if (SpringContext.getBean(BalanceTypeService.class).getBalanceTypeByCode(balanceTypeCode).isFinancialOffsetGenerationIndicator()) { 093 return OFFSET_FORMAT; 094 } 095 else { 096 return NON_OFFSET_FORMAT; 097 } 098 } 099 }