001: /*
002: * Copyright 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.labor.bo;
018:
019: /**
020: * Labor Base class for parsing serialized AccountingLines for Labor LedgerJournal Voucher
021: */
022:
023: import static org.kuali.kfs.KFSKeyConstants.AccountingLineParser.ERROR_INVALID_PROPERTY_VALUE;
024: import static org.kuali.kfs.KFSPropertyConstants.ACCOUNT_NUMBER;
025: import static org.kuali.kfs.KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE;
026: import static org.kuali.kfs.KFSPropertyConstants.CREDIT;
027: import static org.kuali.kfs.KFSPropertyConstants.DEBIT;
028: import static org.kuali.kfs.KFSPropertyConstants.EMPLID;
029: import static org.kuali.kfs.KFSPropertyConstants.EMPLOYEE_RECORD;
030: import static org.kuali.kfs.KFSPropertyConstants.FINANCIAL_OBJECT_CODE;
031: import static org.kuali.kfs.KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE;
032: import static org.kuali.kfs.KFSPropertyConstants.OBJECT_TYPE_CODE;
033: import static org.kuali.kfs.KFSPropertyConstants.ORGANIZATION_REFERENCE_ID;
034: import static org.kuali.kfs.KFSPropertyConstants.POSITION_NUMBER;
035: import static org.kuali.kfs.KFSPropertyConstants.PROJECT_CODE;
036: import static org.kuali.kfs.KFSPropertyConstants.SUB_ACCOUNT_NUMBER;
037:
038: import java.util.Map;
039:
040: import org.apache.commons.lang.StringUtils;
041: import org.kuali.core.util.KualiDecimal;
042: import org.kuali.kfs.KFSConstants;
043: import org.kuali.kfs.KFSPropertyConstants;
044: import org.kuali.kfs.bo.AccountingLineParserBase;
045: import org.kuali.kfs.bo.SourceAccountingLine;
046: import org.kuali.kfs.context.SpringContext;
047: import org.kuali.kfs.exceptions.AccountingLineParserException;
048: import org.kuali.module.chart.service.BalanceTypService;
049: import org.kuali.module.labor.LaborPropertyConstants;
050:
051: public class LaborJournalVoucherAccountingLineParser extends
052: AccountingLineParserBase {
053: private String balanceTypeCode;
054: protected static final String[] LABOR_LINE_FORMAT = {
055: CHART_OF_ACCOUNTS_CODE,
056: ACCOUNT_NUMBER,
057: SUB_ACCOUNT_NUMBER,
058: FINANCIAL_OBJECT_CODE,
059: OBJECT_TYPE_CODE,
060: FINANCIAL_SUB_OBJECT_CODE,
061: PROJECT_CODE,
062: ORGANIZATION_REFERENCE_ID,
063: POSITION_NUMBER,
064: EMPLID,
065: EMPLOYEE_RECORD,
066: LaborPropertyConstants.EARN_CODE,
067: LaborPropertyConstants.PAY_GROUP,
068: LaborPropertyConstants.SALARY_ADMINISTRATION_PLAN,
069: LaborPropertyConstants.GRADE,
070: LaborPropertyConstants.RUN_IDENTIFIER,
071: LaborPropertyConstants.PAY_PERIOD_END_DATE,
072: LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR,
073: LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE,
074: LaborPropertyConstants.TRANSACTION_TOTAL_HOURS,
075: LaborPropertyConstants.LABORLEDGER_ORIGINAL_CHART_OF_ACCOUNTS_CODE,
076: LaborPropertyConstants.LABORLEDGER_ORIGINAL_ACCOUNT_NUMBER,
077: LaborPropertyConstants.LABORLEDGER_ORIGINAL_SUB_ACCOUNT_NUMBER,
078: LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_OBJECT_CODE,
079: LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_SUB_OBJECT_CODE,
080: LaborPropertyConstants.HRMS_COMPANY,
081: KFSPropertyConstants.ENCUMBRANCE_UPDATE_CODE,
082: LaborPropertyConstants.SET_ID, DEBIT, CREDIT };
083:
084: /**
085: * Constructs a JournalVoucherAccountingLineParser.java.
086: *
087: * @param balanceTypeCode
088: */
089: public LaborJournalVoucherAccountingLineParser(
090: String balanceTypeCode) {
091: super ();
092: this .balanceTypeCode = balanceTypeCode;
093: }
094:
095: /**
096: * @see org.kuali.core.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map,
097: * org.kuali.core.bo.SourceAccountingLine, java.lang.String)
098: */
099: @Override
100: protected void performCustomSourceAccountingLinePopulation(
101: Map<String, String> attributeValueMap,
102: SourceAccountingLine sourceAccountingLine,
103: String accountingLineAsString) {
104: // chose debit/credit
105: String debitValue = attributeValueMap.remove(DEBIT);
106: String creditValue = attributeValueMap.remove(CREDIT);
107: KualiDecimal debitAmount = null;
108: try {
109: if (StringUtils.isNotBlank(debitValue)) {
110: debitAmount = new KualiDecimal(debitValue);
111: }
112: } catch (NumberFormatException e) {
113: String[] errorParameters = {
114: debitValue,
115: retrieveAttributeLabel(sourceAccountingLine
116: .getClass(), DEBIT), accountingLineAsString };
117: throw new AccountingLineParserException("invalid (NaN) '"
118: + DEBIT + "=" + debitValue + " for "
119: + accountingLineAsString,
120: ERROR_INVALID_PROPERTY_VALUE, errorParameters);
121: }
122: KualiDecimal creditAmount = null;
123: try {
124: if (StringUtils.isNotBlank(creditValue)) {
125: creditAmount = new KualiDecimal(creditValue);
126: }
127: } catch (NumberFormatException e) {
128: String[] errorParameters = {
129: creditValue,
130: retrieveAttributeLabel(sourceAccountingLine
131: .getClass(), CREDIT),
132: accountingLineAsString };
133: throw new AccountingLineParserException("invalid (NaN) '"
134: + CREDIT + "=" + creditValue + " for "
135: + accountingLineAsString,
136: ERROR_INVALID_PROPERTY_VALUE, errorParameters);
137: }
138:
139: KualiDecimal amount = null;
140: String debitCreditCode = null;
141: if (debitAmount != null && debitAmount.isNonZero()) {
142: amount = debitAmount;
143: debitCreditCode = KFSConstants.GL_DEBIT_CODE;
144: }
145:
146: if (creditAmount != null && creditAmount.isNonZero()) {
147: amount = creditAmount;
148: debitCreditCode = KFSConstants.GL_CREDIT_CODE;
149: }
150:
151: sourceAccountingLine.setAmount(amount);
152: sourceAccountingLine.setDebitCreditCode(debitCreditCode);
153:
154: boolean isFinancialOffsetGeneration = SpringContext.getBean(
155: BalanceTypService.class).getBalanceTypByCode(
156: balanceTypeCode).isFinancialOffsetGenerationIndicator();
157: if (isFinancialOffsetGeneration
158: || StringUtils.equals(balanceTypeCode,
159: KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
160: super .performCustomSourceAccountingLinePopulation(
161: attributeValueMap, sourceAccountingLine,
162: accountingLineAsString);
163: }
164: sourceAccountingLine.setBalanceTypeCode(balanceTypeCode);
165: }
166:
167: /**
168: * @see org.kuali.core.bo.AccountingLineParserBase#getSourceAccountingLineFormat()
169: */
170: @Override
171: public String[] getSourceAccountingLineFormat() {
172: return selectFormat();
173: }
174:
175: /**
176: * chooses line format based on balance type code
177: *
178: * @return String []
179: */
180: private String[] selectFormat() {
181: return LABOR_LINE_FORMAT;
182: }
183: }
|