View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package org.kuali.kfs.fp.businessobject;
21  
22  import static org.kuali.kfs.sys.KFSPropertyConstants.ACCOUNT_NUMBER;
23  import static org.kuali.kfs.sys.KFSPropertyConstants.AMOUNT;
24  import static org.kuali.kfs.sys.KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE;
25  import static org.kuali.kfs.sys.KFSPropertyConstants.CREDIT;
26  import static org.kuali.kfs.sys.KFSPropertyConstants.DEBIT;
27  import static org.kuali.kfs.sys.KFSPropertyConstants.ENCUMBRANCE_UPDATE_CODE;
28  import static org.kuali.kfs.sys.KFSPropertyConstants.FINANCIAL_DOCUMENT_LINE_DESCRIPTION;
29  import static org.kuali.kfs.sys.KFSPropertyConstants.FINANCIAL_OBJECT_CODE;
30  import static org.kuali.kfs.sys.KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE;
31  import static org.kuali.kfs.sys.KFSPropertyConstants.OBJECT_TYPE_CODE;
32  import static org.kuali.kfs.sys.KFSPropertyConstants.ORGANIZATION_REFERENCE_ID;
33  import static org.kuali.kfs.sys.KFSPropertyConstants.PROJECT_CODE;
34  import static org.kuali.kfs.sys.KFSPropertyConstants.REFERENCE_NUMBER;
35  import static org.kuali.kfs.sys.KFSPropertyConstants.REFERENCE_ORIGIN_CODE;
36  import static org.kuali.kfs.sys.KFSPropertyConstants.REFERENCE_TYPE_CODE;
37  import static org.kuali.kfs.sys.KFSPropertyConstants.SUB_ACCOUNT_NUMBER;
38  
39  import java.util.Map;
40  
41  import org.apache.commons.lang.StringUtils;
42  import org.kuali.kfs.coa.service.BalanceTypeService;
43  import org.kuali.kfs.sys.KFSConstants;
44  import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
45  import org.kuali.kfs.sys.context.SpringContext;
46  
47  /**
48   * This class represents a <code>JournalVoucherDocument</code> accounting line parser.
49   */
50  public class JournalVoucherAccountingLineParser extends AuxiliaryVoucherAccountingLineParser {
51      private String balanceTypeCode;
52      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, FINANCIAL_DOCUMENT_LINE_DESCRIPTION, ORGANIZATION_REFERENCE_ID, AMOUNT };
53      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, FINANCIAL_DOCUMENT_LINE_DESCRIPTION, ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT };
54      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, ENCUMBRANCE_UPDATE_CODE, FINANCIAL_DOCUMENT_LINE_DESCRIPTION, REFERENCE_ORIGIN_CODE, REFERENCE_TYPE_CODE, REFERENCE_NUMBER, DEBIT, CREDIT };
55  
56      /**
57       * Constructs a JournalVoucherAccountingLineParser.java.
58       *
59       * @param balanceTypeCode
60       */
61      public JournalVoucherAccountingLineParser(String balanceTypeCode) {
62          super();
63          this.balanceTypeCode = balanceTypeCode;
64      }
65  
66      /**
67       * @see org.kuali.rice.krad.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map,
68       *      org.kuali.rice.krad.bo.SourceAccountingLine, java.lang.String)
69       */
70      @Override
71      protected void performCustomSourceAccountingLinePopulation(Map<String, String> attributeValueMap, SourceAccountingLine sourceAccountingLine, String accountingLineAsString) {
72  
73          boolean isFinancialOffsetGeneration = SpringContext.getBean(BalanceTypeService.class).getBalanceTypeByCode(balanceTypeCode).isFinancialOffsetGenerationIndicator();
74          if (isFinancialOffsetGeneration || StringUtils.equals(balanceTypeCode, KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
75              super.performCustomSourceAccountingLinePopulation(attributeValueMap, sourceAccountingLine, accountingLineAsString);
76          }
77          sourceAccountingLine.setBalanceTypeCode(balanceTypeCode);
78      }
79  
80      /**
81       * @see org.kuali.rice.krad.bo.AccountingLineParserBase#getSourceAccountingLineFormat()
82       */
83      @Override
84      public String[] getSourceAccountingLineFormat() {
85          return removeChartFromFormatIfNeeded(selectFormat());
86      }
87  
88      /**
89       * chooses line format based on balance type code
90       *
91       * @return String []
92       */
93      private String[] selectFormat() {
94          if (StringUtils.equals(balanceTypeCode, KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
95              return ENCUMBRANCE_FORMAT;
96          }
97          else if (SpringContext.getBean(BalanceTypeService.class).getBalanceTypeByCode(balanceTypeCode).isFinancialOffsetGenerationIndicator()) {
98              return OFFSET_FORMAT;
99          }
100         else {
101             return NON_OFFSET_FORMAT;
102         }
103     }
104 }