1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
58
59
60
61 public JournalVoucherAccountingLineParser(String balanceTypeCode) {
62 super();
63 this.balanceTypeCode = balanceTypeCode;
64 }
65
66
67
68
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
82
83 @Override
84 public String[] getSourceAccountingLineFormat() {
85 return removeChartFromFormatIfNeeded(selectFormat());
86 }
87
88
89
90
91
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 }