1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.fp.businessobject;
18
19 import static org.kuali.ole.sys.OLEKeyConstants.AccountingLineParser.ERROR_INVALID_PROPERTY_VALUE;
20 import static org.kuali.ole.sys.OLEPropertyConstants.ACCOUNT_NUMBER;
21 import static org.kuali.ole.sys.OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE;
22 import static org.kuali.ole.sys.OLEPropertyConstants.CREDIT;
23 import static org.kuali.ole.sys.OLEPropertyConstants.DEBIT;
24 import static org.kuali.ole.sys.OLEPropertyConstants.FINANCIAL_OBJECT_CODE;
25 import static org.kuali.ole.sys.OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE;
26 import static org.kuali.ole.sys.OLEPropertyConstants.ORGANIZATION_REFERENCE_ID;
27 import static org.kuali.ole.sys.OLEPropertyConstants.PROJECT_CODE;
28 import static org.kuali.ole.sys.OLEPropertyConstants.SUB_ACCOUNT_NUMBER;
29
30 import java.util.Map;
31
32 import org.apache.commons.lang.StringUtils;
33 import org.kuali.ole.sys.OLEConstants;
34 import org.kuali.ole.sys.businessobject.AccountingLineParserBase;
35 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
36 import org.kuali.ole.sys.exception.AccountingLineParserException;
37 import org.kuali.rice.core.api.util.type.KualiDecimal;
38
39
40
41
42 public class AuxiliaryVoucherAccountingLineParser extends AccountingLineParserBase {
43 protected static final String[] AV_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT };
44
45
46
47
48 public AuxiliaryVoucherAccountingLineParser() {
49 super();
50 }
51
52
53
54
55
56
57 @Override
58 protected void performCustomSourceAccountingLinePopulation(Map<String, String> attributeValueMap, SourceAccountingLine sourceAccountingLine, String accountingLineAsString) {
59 super.performCustomSourceAccountingLinePopulation(attributeValueMap, sourceAccountingLine, accountingLineAsString);
60
61
62 String debitValue = attributeValueMap.remove(DEBIT);
63 String creditValue = attributeValueMap.remove(CREDIT);
64 KualiDecimal debitAmount = null;
65 try {
66 if (StringUtils.isNotBlank(debitValue)) {
67 debitAmount = new KualiDecimal(debitValue);
68 }
69 }
70 catch (NumberFormatException e) {
71 String[] errorParameters = { debitValue, retrieveAttributeLabel(sourceAccountingLine.getClass(), DEBIT), accountingLineAsString };
72 throw new AccountingLineParserException("invalid (NaN) '" + DEBIT + "=" + debitValue + " for " + accountingLineAsString, ERROR_INVALID_PROPERTY_VALUE, errorParameters);
73 }
74 KualiDecimal creditAmount = null;
75 try {
76 if (StringUtils.isNotBlank(creditValue)) {
77 creditAmount = new KualiDecimal(creditValue);
78 }
79 }
80 catch (NumberFormatException e) {
81 String[] errorParameters = { creditValue, retrieveAttributeLabel(sourceAccountingLine.getClass(), CREDIT), accountingLineAsString };
82 throw new AccountingLineParserException("invalid (NaN) '" + CREDIT + "=" + creditValue + " for " + accountingLineAsString, ERROR_INVALID_PROPERTY_VALUE, errorParameters);
83 }
84
85 KualiDecimal amount = null;
86 String debitCreditCode = null;
87 if (debitAmount != null && debitAmount.isNonZero()) {
88 amount = debitAmount;
89 debitCreditCode = OLEConstants.GL_DEBIT_CODE;
90 }
91
92 if (creditAmount != null && creditAmount.isNonZero()) {
93 amount = creditAmount;
94 debitCreditCode = OLEConstants.GL_CREDIT_CODE;
95 }
96
97 sourceAccountingLine.setAmount(amount);
98 sourceAccountingLine.setDebitCreditCode(debitCreditCode);
99 }
100
101
102
103
104 @Override
105 public String[] getSourceAccountingLineFormat() {
106 return removeChartFromFormatIfNeeded(AV_FORMAT);
107 }
108 }