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: package org.kuali.module.labor.batch.poster.impl;
017:
018: import java.sql.Date;
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.kuali.core.service.DataDictionaryService;
024: import org.kuali.core.util.KualiDecimal;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.kfs.KFSPropertyConstants;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.gl.batch.poster.PostTransaction;
029: import org.kuali.module.gl.bo.Entry;
030: import org.kuali.module.gl.bo.Transaction;
031: import org.kuali.module.labor.LaborConstants;
032: import org.kuali.module.labor.bo.LaborGeneralLedgerEntry;
033: import org.kuali.module.labor.service.LaborGeneralLedgerEntryService;
034: import org.kuali.module.labor.util.DebitCreditUtil;
035: import org.kuali.module.labor.util.ObjectUtil;
036: import org.springframework.transaction.annotation.Transactional;
037:
038: /**
039: * This class is used to post a transaction into labor GL entry table
040: */
041: @Transactional
042: public class LaborGLLedgerEntryPoster implements PostTransaction {
043: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(LaborGLLedgerEntryPoster.class);
045: private LaborGeneralLedgerEntryService laborGeneralLedgerEntryService;
046:
047: /**
048: * @see org.kuali.module.gl.batch.poster.PostTransaction#post(org.kuali.module.gl.bo.Transaction, int, java.util.Date)
049: */
050: public String post(Transaction transaction, int mode,
051: java.util.Date postDate) {
052: String operationType = KFSConstants.OperationType.INSERT;
053: LaborGeneralLedgerEntry laborGeneralLedgerEntry = new LaborGeneralLedgerEntry();
054: ObjectUtil.buildObject(laborGeneralLedgerEntry, transaction);
055:
056: laborGeneralLedgerEntry.setTransactionDate(new Date(postDate
057: .getTime()));
058:
059: laborGeneralLedgerEntry.setTransactionDebitCreditCode(this
060: .getDebitCreditCode(transaction));
061: laborGeneralLedgerEntry.setTransactionLedgerEntryAmount(this
062: .getTransactionAmount(transaction));
063:
064: laborGeneralLedgerEntry
065: .setTransactionLedgerEntryDescription(getTransactionDescription(transaction));
066:
067: laborGeneralLedgerEntry
068: .setTransactionEncumbranceUpdateCode(this
069: .getEncumbranceUpdateCode(transaction));
070:
071: Integer sequenceNumber = laborGeneralLedgerEntryService
072: .getMaxSequenceNumber(laborGeneralLedgerEntry) + 1;
073: laborGeneralLedgerEntry
074: .setTransactionLedgerEntrySequenceNumber(sequenceNumber);
075:
076: laborGeneralLedgerEntryService.save(laborGeneralLedgerEntry);
077: return operationType;
078: }
079:
080: /**
081: * @return the debit credit code
082: */
083: private String getDebitCreditCode(Transaction transaction) {
084: KualiDecimal transactionAmount = transaction
085: .getTransactionLedgerEntryAmount();
086: return DebitCreditUtil.getDebitCreditCode(transactionAmount,
087: false);
088: }
089:
090: /**
091: * @return the transaction amount
092: */
093: private KualiDecimal getTransactionAmount(Transaction transaction) {
094: KualiDecimal transactionAmount = transaction
095: .getTransactionLedgerEntryAmount();
096: return transactionAmount.abs();
097: }
098:
099: /**
100: * @return the encumbrance update code
101: */
102: private String getEncumbranceUpdateCode(Transaction transaction) {
103: String encumbranceUpdateCode = transaction
104: .getTransactionEncumbranceUpdateCode();
105: if (KFSConstants.ENCUMB_UPDT_DOCUMENT_CD
106: .equals(encumbranceUpdateCode)
107: || KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD
108: .equals(encumbranceUpdateCode)) {
109: return encumbranceUpdateCode;
110: }
111: return null;
112: }
113:
114: /**
115: * @return the transaction description
116: */
117: private String getTransactionDescription(Transaction transaction) {
118: String documentTypeCode = transaction
119: .getFinancialDocumentTypeCode();
120: String description = getDescriptionMap().get(documentTypeCode);
121: description = StringUtils.isNotEmpty(description) ? description
122: : transaction.getTransactionLedgerEntryDescription();
123:
124: // make sure the length of the description cannot excess the specified maximum
125: int transactionDescriptionMaxLength = SpringContext.getBean(
126: DataDictionaryService.class).getAttributeMaxLength(
127: Entry.class,
128: KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)
129: .intValue();
130: if (StringUtils.isNotEmpty(description)
131: && description.length() > transactionDescriptionMaxLength) {
132: description = StringUtils.left(description,
133: transactionDescriptionMaxLength);
134: }
135:
136: return description;
137: }
138:
139: /**
140: * @return the description dictionary that can be used to look up approperite description
141: */
142: public static Map<String, String> getDescriptionMap() {
143: Map<String, String> descriptionMap = new HashMap<String, String>();
144:
145: descriptionMap.put(
146: LaborConstants.PayrollDocumentTypeCode.NORMAL_PAY,
147: "NORMAL PAYROLL ACTIVITY");
148: descriptionMap
149: .put(
150: LaborConstants.PayrollDocumentTypeCode.ACCRUALS_REVERSAL,
151: "PAYROLL ACCRUAL REVERSAL");
152: descriptionMap.put(
153: LaborConstants.PayrollDocumentTypeCode.ACCRUALS,
154: "PAYROLL ACCRUALS");
155: descriptionMap
156: .put(
157: LaborConstants.PayrollDocumentTypeCode.CHECK_CANCELLATION,
158: "PAYROLL CHECK CANCELLATIONS");
159: descriptionMap.put(
160: LaborConstants.PayrollDocumentTypeCode.ENCUMBRANCE,
161: "PAYROLL ENCUMBRANCES");
162: descriptionMap
163: .put(
164: LaborConstants.PayrollDocumentTypeCode.EXPENSE_TRANSFER_ET,
165: "PAYROLL EXPENSE TRANSFERS");
166: descriptionMap
167: .put(
168: LaborConstants.PayrollDocumentTypeCode.EXPENSE_TRANSFER_SACH,
169: "PAYROLL EXPENSE TRANSFERS");
170: descriptionMap
171: .put(
172: LaborConstants.PayrollDocumentTypeCode.HAND_DRAWN_CHECK,
173: "PAYROLL HAND DRAWN CHECK PAYMENTS");
174: descriptionMap.put(
175: LaborConstants.PayrollDocumentTypeCode.OVERPAYMENT,
176: "PAYROLL OVERPAYMENT COLLECTIONS");
177: descriptionMap
178: .put(
179: LaborConstants.PayrollDocumentTypeCode.RETROACTIVE_ADJUSTMENT,
180: "PAYROLL RETROACTIVE ADJUSTMENTS");
181:
182: return descriptionMap;
183: }
184:
185: /**
186: * @see org.kuali.module.gl.batch.poster.PostTransaction#getDestinationName()
187: */
188: public String getDestinationName() {
189: return LaborConstants.DestinationNames.LABOR_GL_ENTRY;
190: }
191:
192: /**
193: * Sets the laborGeneralLedgerEntryService attribute value.
194: *
195: * @param laborGeneralLedgerEntryService The laborGeneralLedgerEntryService to set.
196: */
197: public void setLaborGeneralLedgerEntryService(
198: LaborGeneralLedgerEntryService laborGeneralLedgerEntryService) {
199: this.laborGeneralLedgerEntryService = laborGeneralLedgerEntryService;
200: }
201: }
|