001: /*
002: * Copyright 2006-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.KFSKeyConstants.AccountingLineParser.ERROR_INVALID_PROPERTY_VALUE;
020: import static org.kuali.kfs.KFSPropertyConstants.ACCOUNT_NUMBER;
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.ORGANIZATION_REFERENCE_ID;
027: import static org.kuali.kfs.KFSPropertyConstants.PROJECT_CODE;
028: import static org.kuali.kfs.KFSPropertyConstants.SUB_ACCOUNT_NUMBER;
029:
030: import java.util.Map;
031:
032: import org.apache.commons.lang.StringUtils;
033: import org.kuali.core.util.KualiDecimal;
034: import org.kuali.kfs.KFSConstants;
035: import org.kuali.kfs.bo.AccountingLineParserBase;
036: import org.kuali.kfs.bo.SourceAccountingLine;
037: import org.kuali.kfs.exceptions.AccountingLineParserException;
038:
039: /**
040: * This class is used to parse an <code>AuxiliaryVocherDocument</code> accounting line.
041: */
042: public class AuxiliaryVoucherAccountingLineParser extends
043: AccountingLineParserBase {
044: private static final String[] AV_FORMAT = { CHART_OF_ACCOUNTS_CODE,
045: ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE,
046: FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE,
047: ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT };
048:
049: /**
050: * Constructs a AuxiliaryVoucherAccountingLineParser.java.
051: */
052: public AuxiliaryVoucherAccountingLineParser() {
053: super ();
054: }
055:
056: /**
057: * Populates source accounting lines and sets debit and credit amounts and codes if they exist
058: *
059: * @see org.kuali.kfs.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map, org.kuali.kfs.bo.SourceAccountingLine, java.lang.String)
060: */
061: @Override
062: protected void performCustomSourceAccountingLinePopulation(
063: Map<String, String> attributeValueMap,
064: SourceAccountingLine sourceAccountingLine,
065: String accountingLineAsString) {
066: super .performCustomSourceAccountingLinePopulation(
067: attributeValueMap, sourceAccountingLine,
068: accountingLineAsString);
069:
070: // chose debit/credit
071: String debitValue = attributeValueMap.remove(DEBIT);
072: String creditValue = attributeValueMap.remove(CREDIT);
073: KualiDecimal debitAmount = null;
074: try {
075: if (StringUtils.isNotBlank(debitValue)) {
076: debitAmount = new KualiDecimal(debitValue);
077: }
078: } catch (NumberFormatException e) {
079: String[] errorParameters = {
080: debitValue,
081: retrieveAttributeLabel(sourceAccountingLine
082: .getClass(), DEBIT), accountingLineAsString };
083: throw new AccountingLineParserException("invalid (NaN) '"
084: + DEBIT + "=" + debitValue + " for "
085: + accountingLineAsString,
086: ERROR_INVALID_PROPERTY_VALUE, errorParameters);
087: }
088: KualiDecimal creditAmount = null;
089: try {
090: if (StringUtils.isNotBlank(creditValue)) {
091: creditAmount = new KualiDecimal(creditValue);
092: }
093: } catch (NumberFormatException e) {
094: String[] errorParameters = {
095: creditValue,
096: retrieveAttributeLabel(sourceAccountingLine
097: .getClass(), CREDIT),
098: accountingLineAsString };
099: throw new AccountingLineParserException("invalid (NaN) '"
100: + CREDIT + "=" + creditValue + " for "
101: + accountingLineAsString,
102: ERROR_INVALID_PROPERTY_VALUE, errorParameters);
103: }
104:
105: KualiDecimal amount = null;
106: String debitCreditCode = null;
107: if (debitAmount != null && debitAmount.isNonZero()) {
108: amount = debitAmount;
109: debitCreditCode = KFSConstants.GL_DEBIT_CODE;
110: }
111:
112: if (creditAmount != null && creditAmount.isNonZero()) {
113: amount = creditAmount;
114: debitCreditCode = KFSConstants.GL_CREDIT_CODE;
115: }
116:
117: sourceAccountingLine.setAmount(amount);
118: sourceAccountingLine.setDebitCreditCode(debitCreditCode);
119: }
120:
121: /**
122: * @see org.kuali.core.bo.AccountingLineParserBase#getSourceAccountingLineFormat()
123: */
124: @Override
125: public String[] getSourceAccountingLineFormat() {
126: return AV_FORMAT;
127: }
128: }
|