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.service.impl;
017:
018: import java.sql.Date;
019: import java.util.Collection;
020: import java.util.Iterator;
021:
022: import org.kuali.core.service.BusinessObjectService;
023: import org.kuali.core.service.DateTimeService;
024: import org.kuali.kfs.KFSConstants;
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.OriginEntryGroupService;
029: import org.kuali.module.labor.bo.LaborGeneralLedgerEntry;
030: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
031: import org.kuali.module.labor.bo.LaborOriginEntry;
032: import org.kuali.module.labor.service.LaborLedgerPendingEntryService;
033: import org.kuali.module.labor.service.LaborNightlyOutService;
034: import org.kuali.module.labor.service.LaborReportService;
035: import org.kuali.module.labor.util.ObjectUtil;
036: import org.kuali.module.labor.util.ReportRegistry;
037: import org.springframework.transaction.annotation.Transactional;
038:
039: /**
040: * The class implements loading and cleanup methods for nightly batch jobs
041: */
042: @Transactional
043: public class LaborNightlyOutServiceImpl implements
044: LaborNightlyOutService {
045: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
046: .getLogger(LaborNightlyOutServiceImpl.class);
047:
048: private LaborLedgerPendingEntryService laborLedgerPendingEntryService;
049: private OriginEntryGroupService originEntryGroupService;
050: private LaborReportService laborReportService;
051:
052: private BusinessObjectService businessObjectService;
053: private DateTimeService dateTimeService;
054:
055: /**
056: * @see org.kuali.module.labor.service.LaborNightlyOutService#deleteCopiedPendingLedgerEntries()
057: */
058: public void deleteCopiedPendingLedgerEntries() {
059: laborLedgerPendingEntryService
060: .deleteByFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.PROCESSED);
061: }
062:
063: /**
064: * @see org.kuali.module.labor.service.LaborNightlyOutService#copyApprovedPendingLedgerEntries()
065: */
066: public void copyApprovedPendingLedgerEntries() {
067: Date runDate = dateTimeService.getCurrentSqlDate();
068: String reportDirectory = ReportRegistry.getReportsDirectory();
069: OriginEntryGroup group = originEntryGroupService
070: .createGroup(runDate, OriginEntrySource.LABOR_EDOC,
071: true, true, true);
072:
073: Iterator<LaborLedgerPendingEntry> pendingEntries = laborLedgerPendingEntryService
074: .findApprovedPendingLedgerEntries();
075: while (pendingEntries != null && pendingEntries.hasNext()) {
076: LaborLedgerPendingEntry pendingEntry = pendingEntries
077: .next();
078:
079: // copy the pending entry to labor origin entry table
080: boolean isSaved = saveAsLaborOriginEntry(pendingEntry,
081: group);
082: if (isSaved) {
083: // update the pending entry to indicate it has been copied
084: pendingEntry
085: .setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.PROCESSED);
086: pendingEntry.setTransactionDate(runDate);
087: businessObjectService.save(pendingEntry);
088: }
089: }
090: laborReportService.generateInputSummaryReport(group,
091: ReportRegistry.LABOR_PENDING_ENTRY_SUMMARY,
092: reportDirectory, runDate);
093: }
094:
095: /**
096: * @see org.kuali.module.labor.service.LaborNightlyOutService#deleteCopiedLaborGenerealLedgerEntries()
097: */
098: public void deleteCopiedLaborGenerealLedgerEntries() {
099: Collection<LaborGeneralLedgerEntry> generalLedgerEntries = businessObjectService
100: .findAll(LaborGeneralLedgerEntry.class);
101: for (LaborGeneralLedgerEntry entry : generalLedgerEntries) {
102: businessObjectService.delete(entry);
103: }
104: }
105:
106: /**
107: * @see org.kuali.module.labor.service.LaborNightlyOutService#copyLaborGenerealLedgerEntries()
108: */
109: public void copyLaborGenerealLedgerEntries() {
110: Date runDate = dateTimeService.getCurrentSqlDate();
111: String reportDirectory = ReportRegistry.getReportsDirectory();
112: OriginEntryGroup group = originEntryGroupService.createGroup(
113: runDate, OriginEntrySource.LABOR_LEDGER_GENERAL_LEDGER,
114: true, true, true);
115:
116: // copy the labor general ledger entry to origin entry table
117: Collection<LaborGeneralLedgerEntry> generalLedgerEntries = businessObjectService
118: .findAll(LaborGeneralLedgerEntry.class);
119: int numberOfGLEntries = generalLedgerEntries.size();
120:
121: for (LaborGeneralLedgerEntry entry : generalLedgerEntries) {
122: boolean isSaved = saveAsGLOriginEntry(entry, group);
123: }
124:
125: laborReportService.generateGLSummaryReport(group,
126: ReportRegistry.LABOR_GL_SUMMARY, reportDirectory,
127: runDate);
128: }
129:
130: /*
131: * save the given pending ledger entry as a labor origin entry
132: */
133: private boolean saveAsLaborOriginEntry(
134: LaborLedgerPendingEntry pendingEntry, OriginEntryGroup group) {
135: try {
136: LaborOriginEntry originEntry = new LaborOriginEntry();
137: ObjectUtil.buildObject(originEntry, pendingEntry);
138:
139: originEntry.setTransactionPostingDate(group.getDate());
140: originEntry.setEntryGroupId(group.getId());
141:
142: businessObjectService.save(originEntry);
143: } catch (Exception e) {
144: LOG.debug("Fail to copy the pending entry as origin entry"
145: + e);
146: return false;
147: }
148: return true;
149: }
150:
151: /*
152: * save the given pending ledger entry as a labor origin entry
153: */
154: private boolean saveAsGLOriginEntry(LaborGeneralLedgerEntry entry,
155: OriginEntryGroup group) {
156: try {
157: OriginEntryFull originEntry = new OriginEntryFull();
158: ObjectUtil.buildObject(originEntry, entry);
159:
160: originEntry.setEntryGroupId(group.getId());
161: businessObjectService.save(originEntry);
162: } catch (Exception e) {
163: LOG
164: .debug("Fail to copy the labor GL entry as an origin entry"
165: + e);
166: return false;
167: }
168: return true;
169: }
170:
171: /**
172: * Sets the businessObjectService attribute value.
173: *
174: * @param businessObjectService The businessObjectService to set.
175: */
176: public void setBusinessObjectService(
177: BusinessObjectService businessObjectService) {
178: this .businessObjectService = businessObjectService;
179: }
180:
181: /**
182: * Sets the dateTimeService attribute value.
183: *
184: * @param dateTimeService The dateTimeService to set.
185: */
186: public void setDateTimeService(DateTimeService dateTimeService) {
187: this .dateTimeService = dateTimeService;
188: }
189:
190: /**
191: * Sets the laborLedgerPendingEntryService attribute value.
192: *
193: * @param laborLedgerPendingEntryService The laborLedgerPendingEntryService to set.
194: */
195: public void setLaborLedgerPendingEntryService(
196: LaborLedgerPendingEntryService laborLedgerPendingEntryService) {
197: this .laborLedgerPendingEntryService = laborLedgerPendingEntryService;
198: }
199:
200: /**
201: * Sets the laborReportService attribute value.
202: *
203: * @param laborReportService The laborReportService to set.
204: */
205: public void setLaborReportService(
206: LaborReportService laborReportService) {
207: this .laborReportService = laborReportService;
208: }
209:
210: /**
211: * Sets the originEntryGroupService attribute value.
212: *
213: * @param originEntryGroupService The originEntryGroupService to set.
214: */
215: public void setOriginEntryGroupService(
216: OriginEntryGroupService originEntryGroupService) {
217: this.originEntryGroupService = originEntryGroupService;
218: }
219: }
|