001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.financial.bo;
018:
019: import static org.kuali.kfs.KFSPropertyConstants.ACCOUNT_NUMBER;
020: import static org.kuali.kfs.KFSPropertyConstants.AMOUNT;
021: import static org.kuali.kfs.KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE;
022: import static org.kuali.kfs.KFSPropertyConstants.CREDIT;
023: import static org.kuali.kfs.KFSPropertyConstants.DEBIT;
024: import static org.kuali.kfs.KFSPropertyConstants.FINANCIAL_OBJECT_CODE;
025: import static org.kuali.kfs.KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE;
026: import static org.kuali.kfs.KFSPropertyConstants.OBJECT_TYPE_CODE;
027: import static org.kuali.kfs.KFSPropertyConstants.ORGANIZATION_REFERENCE_ID;
028: import static org.kuali.kfs.KFSPropertyConstants.PROJECT_CODE;
029: import static org.kuali.kfs.KFSPropertyConstants.REFERENCE_NUMBER;
030: import static org.kuali.kfs.KFSPropertyConstants.REFERENCE_ORIGIN_CODE;
031: import static org.kuali.kfs.KFSPropertyConstants.REFERENCE_TYPE_CODE;
032: import static org.kuali.kfs.KFSPropertyConstants.SUB_ACCOUNT_NUMBER;
033:
034: import java.util.Map;
035:
036: import org.apache.commons.lang.StringUtils;
037: import org.kuali.kfs.KFSConstants;
038: import org.kuali.kfs.bo.SourceAccountingLine;
039: import org.kuali.kfs.context.SpringContext;
040: import org.kuali.module.chart.service.BalanceTypService;
041:
042: /**
043: * This class represents a <code>JournalVoucherDocument</code> accounting line parser.
044: */
045: public class JournalVoucherAccountingLineParser extends
046: AuxiliaryVoucherAccountingLineParser {
047: private String balanceTypeCode;
048: private static final String[] NON_OFFSET_ENTRY = {
049: CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER,
050: FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE,
051: FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE,
052: ORGANIZATION_REFERENCE_ID, AMOUNT };
053: private static final String[] OFFSET_ENTRY = {
054: CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER,
055: FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE,
056: FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE,
057: ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT };
058: private static final String[] ENCUMBRANCE_ENTRY = {
059: CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER,
060: FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE,
061: FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE,
062: ORGANIZATION_REFERENCE_ID, REFERENCE_ORIGIN_CODE,
063: REFERENCE_TYPE_CODE, REFERENCE_NUMBER, DEBIT, CREDIT };
064:
065: /**
066: * Constructs a JournalVoucherAccountingLineParser.java.
067: *
068: * @param balanceTypeCode
069: */
070: public JournalVoucherAccountingLineParser(String balanceTypeCode) {
071: super ();
072: this .balanceTypeCode = balanceTypeCode;
073: }
074:
075: /**
076: * @see org.kuali.core.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map,
077: * org.kuali.core.bo.SourceAccountingLine, java.lang.String)
078: */
079: @Override
080: protected void performCustomSourceAccountingLinePopulation(
081: Map<String, String> attributeValueMap,
082: SourceAccountingLine sourceAccountingLine,
083: String accountingLineAsString) {
084:
085: boolean isFinancialOffsetGeneration = SpringContext.getBean(
086: BalanceTypService.class).getBalanceTypByCode(
087: balanceTypeCode).isFinancialOffsetGenerationIndicator();
088: if (isFinancialOffsetGeneration
089: || StringUtils.equals(balanceTypeCode,
090: KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
091: super .performCustomSourceAccountingLinePopulation(
092: attributeValueMap, sourceAccountingLine,
093: accountingLineAsString);
094: }
095: sourceAccountingLine.setBalanceTypeCode(balanceTypeCode);
096: }
097:
098: /**
099: * @see org.kuali.core.bo.AccountingLineParserBase#getSourceAccountingLineFormat()
100: */
101: @Override
102: public String[] getSourceAccountingLineFormat() {
103: return selectFormat();
104: }
105:
106: /**
107: * chooses line format based on balance type code
108: *
109: * @return String []
110: */
111: private String[] selectFormat() {
112: if (StringUtils.equals(balanceTypeCode,
113: KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
114: return ENCUMBRANCE_ENTRY;
115: } else if (SpringContext.getBean(BalanceTypService.class)
116: .getBalanceTypByCode(balanceTypeCode)
117: .isFinancialOffsetGenerationIndicator()) {
118: return OFFSET_ENTRY;
119: } else {
120: return NON_OFFSET_ENTRY;
121: }
122: }
123: }
|