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.sql.Date;
019: import java.util.Iterator;
020:
021: import org.kuali.core.service.DateTimeService;
022: import org.kuali.kfs.KFSConstants;
023: import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
024: import org.kuali.kfs.service.GeneralLedgerPendingEntryService;
025: import org.kuali.module.gl.bo.OriginEntryFull;
026: import org.kuali.module.gl.bo.OriginEntryGroup;
027: import org.kuali.module.gl.bo.OriginEntrySource;
028: import org.kuali.module.gl.service.NightlyOutService;
029: import org.kuali.module.gl.service.OriginEntryGroupService;
030: import org.kuali.module.gl.service.OriginEntryService;
031: import org.kuali.module.gl.service.ReportService;
032: import org.springframework.transaction.annotation.Transactional;
033:
034: /**
035: * This class implements the nightly out batch job.
036: */
037: @Transactional
038: public class NightlyOutServiceImpl implements NightlyOutService {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(NightlyOutServiceImpl.class);
041:
042: private GeneralLedgerPendingEntryService generalLedgerPendingEntryService;
043: private OriginEntryService originEntryService;
044: private DateTimeService dateTimeService;
045: private OriginEntryGroupService originEntryGroupService;
046: private ReportService reportService;
047:
048: /**
049: * Constructs a NightlyOutServiceImpl instance
050: */
051: public NightlyOutServiceImpl() {
052: }
053:
054: /**
055: * Deletes all the pending general ledger entries that have now been copied to origin entries
056: * @see org.kuali.module.gl.service.NightlyOutService#deleteCopiedPendingLedgerEntries()
057: */
058: public void deleteCopiedPendingLedgerEntries() {
059: LOG.debug("deleteCopiedPendingLedgerEntries() started");
060:
061: generalLedgerPendingEntryService
062: .deleteByFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.PROCESSED);
063: }
064:
065: /**
066: * Copies the approved pending ledger entries to orign entry table and generates a report
067: * @see org.kuali.module.gl.service.NightlyOutService#copyApprovedPendingLedgerEntries()
068: */
069: public void copyApprovedPendingLedgerEntries() {
070: LOG.debug("copyApprovedPendingLedgerEntries() started");
071:
072: Iterator pendingEntries = generalLedgerPendingEntryService
073: .findApprovedPendingLedgerEntries();
074:
075: Date today = new Date(dateTimeService.getCurrentTimestamp()
076: .getTime());
077:
078: OriginEntryGroup group = originEntryGroupService.createGroup(
079: today, OriginEntrySource.GENERATE_BY_EDOC, true, true,
080: true);
081:
082: while (pendingEntries.hasNext()) {
083: // get one pending entry
084: GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) pendingEntries
085: .next();
086:
087: // copy the pending entry to origin entry table
088: saveAsOriginEntry(pendingEntry, group);
089:
090: // update the pending entry to indicate it has been copied
091: pendingEntry
092: .setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.PROCESSED);
093: pendingEntry.setTransactionDate(today);
094: generalLedgerPendingEntryService.save(pendingEntry);
095: }
096:
097: // Print reports
098: reportService.generatePendingEntryReport(today, group);
099: reportService.generatePendingEntryLedgerSummaryReport(today,
100: group);
101: }
102:
103: /**
104: * Saves pending ledger entry as origin entry
105: *
106: * @param pendingEntry the pending entry to save as an origin entry
107: * @param group the group to save the new origin entry into
108: */
109: private void saveAsOriginEntry(
110: GeneralLedgerPendingEntry pendingEntry,
111: OriginEntryGroup group) {
112: OriginEntryFull originEntry = new OriginEntryFull(pendingEntry);
113: originEntry.setGroup(group);
114:
115: originEntryService.createEntry(originEntry, group);
116: }
117:
118: public void setGeneralLedgerPendingEntryService(
119: GeneralLedgerPendingEntryService generalLedgerPendingEntryService) {
120: this .generalLedgerPendingEntryService = generalLedgerPendingEntryService;
121: }
122:
123: public void setOriginEntryService(
124: OriginEntryService originEntryService) {
125: this .originEntryService = originEntryService;
126: }
127:
128: public void setOriginEntryGroupService(
129: OriginEntryGroupService originEntryGroupService) {
130: this .originEntryGroupService = originEntryGroupService;
131: }
132:
133: public void setDateTimeService(DateTimeService dateTimeService) {
134: this .dateTimeService = dateTimeService;
135: }
136:
137: public void setReportService(ReportService rs) {
138: this.reportService = rs;
139: }
140: }
|