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: package org.kuali.module.gl.service.impl;
017:
018: import java.util.Date;
019: import java.util.Iterator;
020:
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.module.chart.service.AccountingPeriodService;
023: import org.kuali.module.financial.service.UniversityDateService;
024: import org.kuali.module.gl.bo.Reversal;
025: import org.kuali.module.gl.bo.Transaction;
026: import org.kuali.module.gl.dao.ReversalDao;
027: import org.kuali.module.gl.service.ReversalService;
028: import org.kuali.module.gl.util.LedgerEntry;
029: import org.kuali.module.gl.util.LedgerEntryHolder;
030: import org.springframework.transaction.annotation.Transactional;
031:
032: /**
033: * This transactional class provides the default implementation of the services required in ReversalService
034: *
035: * @see org.kuali.module.gl.service.ReversalService
036: */
037: @Transactional
038: public class ReversalServiceImpl implements ReversalService {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(ReversalServiceImpl.class);
041:
042: private ReversalDao reversalDao;
043: private AccountingPeriodService accountingPeriodService;
044: private UniversityDateService universityDateService;
045:
046: /**
047: * Deletes a reversal record
048: *
049: * @param re the reversal to delete, remove, or otherwise expiate from the database
050: * @see org.kuali.module.gl.service.ReversalService#delete(org.kuali.module.gl.bo.Reversal)
051: */
052: public void delete(Reversal re) {
053: LOG.debug("delete() started");
054:
055: reversalDao.delete(re);
056: }
057:
058: /**
059: * Returns all the reversal records set to reverse on or before the given date
060: *
061: * @param before the date to find reversals on or before
062: * @see org.kuali.module.gl.service.ReversalService#getByDate(java.util.Date)
063: */
064: public Iterator getByDate(Date before) {
065: LOG.debug("getByDate() started");
066:
067: return reversalDao.getByDate(before);
068: }
069:
070: public Reversal getByTransaction(Transaction t) {
071: LOG.debug("getByTransaction() started");
072:
073: return reversalDao.getByTransaction(t);
074: }
075:
076: /**
077: * Summarizes all of the reversal records set to reverse before or on the given date
078: * @param before the date reversals summarized should be on or before
079: * @return a LedgerEntryHolder with a summary of
080: * @see org.kuali.module.gl.service.ReversalService#getSummaryByDate(java.util.Date)
081: */
082: public LedgerEntryHolder getSummaryByDate(Date before) {
083: LOG.debug("getSummaryByDate() started");
084:
085: LedgerEntryHolder ledgerEntryHolder = new LedgerEntryHolder();
086:
087: Iterator reversalsIterator = reversalDao.getByDate(before);
088: while (reversalsIterator.hasNext()) {
089: Reversal reversal = (Reversal) reversalsIterator.next();
090: LedgerEntry ledgerEntry = buildLedgerEntryFromReversal(reversal);
091: ledgerEntryHolder.insertLedgerEntry(ledgerEntry, true);
092: }
093: return ledgerEntryHolder;
094: }
095:
096: /**
097: * Creates a LedgerEntry from a reversal, which is proper for summarization (ie, its fiscal year and period code are based off
098: * the reversal date, not off the transaction date or the reversal's current fiscal year and accounting period)
099: *
100: * @param reversal reversal to build LedgerEntry with
101: * @return a new LedgerEntry, populated by the reversal
102: */
103: private LedgerEntry buildLedgerEntryFromReversal(Reversal reversal) {
104: LedgerEntry entry = new LedgerEntry(universityDateService
105: .getFiscalYear(reversal
106: .getFinancialDocumentReversalDate()),
107: accountingPeriodService.getByDate(
108: reversal.getFinancialDocumentReversalDate())
109: .getUniversityFiscalPeriodCode(), reversal
110: .getFinancialBalanceTypeCode(), reversal
111: .getFinancialSystemOriginationCode());
112: if (KFSConstants.GL_CREDIT_CODE.equals(reversal
113: .getTransactionDebitCreditCode())) {
114: entry.setCreditAmount(reversal
115: .getTransactionLedgerEntryAmount());
116: entry.setCreditCount(1);
117: } else if (KFSConstants.GL_DEBIT_CODE.equals(reversal
118: .getTransactionDebitCreditCode())) {
119: entry.setDebitAmount(reversal
120: .getTransactionLedgerEntryAmount());
121: entry.setDebitCount(1);
122: } else {
123: entry.setNoDCAmount(reversal
124: .getTransactionLedgerEntryAmount());
125: entry.setNoDCCount(1);
126: }
127: entry.setRecordCount(1);
128: return entry;
129: }
130:
131: /**
132: * Saves a reversal record
133: *
134: * @param re the reversal to save
135: * @see org.kuali.module.gl.service.ReversalService#save(org.kuali.module.gl.bo.Reversal)
136: */
137: public void save(Reversal re) {
138: LOG.debug("save() started");
139:
140: reversalDao.save(re);
141: }
142:
143: /**
144: * Sets the reversalDao attribute, allowing injection of an implementation of that data access object
145: *
146: * @param reversalDao the reversalDao implementation to set
147: * @see org.kuali.module.gl.dao.ReversalDao
148: */
149: public void setReversalDao(ReversalDao reversalDao) {
150: this .reversalDao = reversalDao;
151: }
152:
153: /**
154: * Sets the accountingPeriodService attribute, allowing injection of an implementation of that service
155: *
156: * @param accountingPeriodService the accountingPeriodService implementation to set
157: * @see org.kuali.module.chart.service.AccountingPeriodService
158: */
159: public void setAccountingPeriodService(
160: AccountingPeriodService accountingPeriodService) {
161: this .accountingPeriodService = accountingPeriodService;
162: }
163:
164: /**
165: * Sets the unversityDateService attribute, allowing injection of an implementation of that service
166: *
167: * @param universityDateService the universityDateService implementation to set
168: * @see org.kuali.module.financial.service.UniversityDateService
169: */
170: public void setUniversityDateService(
171: UniversityDateService universityDateService) {
172: this.universityDateService = universityDateService;
173: }
174: }
|