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.Timestamp;
019: import java.util.Date;
020:
021: import org.kuali.core.service.BusinessObjectService;
022: import org.kuali.core.util.KualiDecimal;
023: import org.kuali.kfs.KFSConstants;
024: import org.kuali.module.gl.batch.poster.PostTransaction;
025: import org.kuali.module.gl.bo.Transaction;
026: import org.kuali.module.labor.LaborConstants;
027: import org.kuali.module.labor.bo.LaborTransaction;
028: import org.kuali.module.labor.bo.LedgerBalance;
029: import org.kuali.module.labor.service.LaborLedgerBalanceService;
030: import org.springframework.transaction.annotation.Transactional;
031:
032: /**
033: * This class is used to post a transaction into Labor Ledger Balance Table
034: */
035: @Transactional
036: public class LaborLedgerBalancePoster implements PostTransaction {
037: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
038: .getLogger(LaborLedgerBalancePoster.class);
039: private BusinessObjectService businessObjectService;
040: private LaborLedgerBalanceService laborLedgerBalanceService;
041:
042: /**
043: * @see org.kuali.module.gl.batch.poster.PostTransaction#post(org.kuali.module.gl.bo.Transaction, int, java.util.Date)
044: */
045: public String post(Transaction transaction, int mode, Date postDate) {
046: String operationType = KFSConstants.OperationType.INSERT;
047: LedgerBalance ledgerBalance = new LedgerBalance(
048: (LaborTransaction) transaction);
049: // ObjectUtil.buildObject(ledgerBalance, transaction);
050:
051: LedgerBalance tempLedgerBalance = (LedgerBalance) businessObjectService
052: .retrieve(ledgerBalance);
053: if (tempLedgerBalance != null) {
054: ledgerBalance = tempLedgerBalance;
055: operationType = KFSConstants.OperationType.UPDATE;
056: }
057: String debitCreditCode = transaction
058: .getTransactionDebitCreditCode();
059: KualiDecimal amount = transaction
060: .getTransactionLedgerEntryAmount();
061: amount = debitCreditCode.equals(KFSConstants.GL_CREDIT_CODE) ? amount
062: .negated()
063: : amount;
064:
065: ledgerBalance.addAmount(transaction
066: .getUniversityFiscalPeriodCode(), amount);
067: ledgerBalance.setTransactionDateTimeStamp(new Timestamp(
068: postDate.getTime()));
069:
070: laborLedgerBalanceService.save(ledgerBalance);
071: return operationType;
072: }
073:
074: /**
075: * @see org.kuali.module.gl.batch.poster.PostTransaction#getDestinationName()
076: */
077: public String getDestinationName() {
078: return LaborConstants.DestinationNames.LEDGER_BALANCE;
079: }
080:
081: /**
082: * Sets the businessObjectService attribute value.
083: *
084: * @param businessObjectService The businessObjectService to set.
085: */
086: public void setBusinessObjectService(
087: BusinessObjectService businessObjectService) {
088: this .businessObjectService = businessObjectService;
089: }
090:
091: /**
092: * Sets the laborLedgerBalanceService attribute value.
093: *
094: * @param laborLedgerBalanceService The laborLedgerBalanceService to set.
095: */
096: public void setLaborLedgerBalanceService(
097: LaborLedgerBalanceService laborLedgerBalanceService) {
098: this.laborLedgerBalanceService = laborLedgerBalanceService;
099: }
100: }
|