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.document;
017:
018: import java.util.Iterator;
019:
020: import org.kuali.core.document.AmountTotaling;
021: import org.kuali.core.service.BusinessObjectService;
022: import org.kuali.core.service.DateTimeService;
023: import org.kuali.kfs.KFSConstants;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.gl.bo.OriginEntryGroup;
026: import org.kuali.module.gl.bo.OriginEntrySource;
027: import org.kuali.module.gl.document.CorrectionDocument;
028: import org.kuali.module.gl.service.OriginEntryGroupService;
029: import org.kuali.module.labor.bo.LaborOriginEntry;
030: import org.kuali.module.labor.service.LaborCorrectionDocumentService;
031: import org.kuali.module.labor.service.LaborOriginEntryService;
032: import org.kuali.module.labor.service.LaborReportService;
033: import org.kuali.module.labor.service.LaborScrubberService;
034: import org.kuali.module.labor.util.ReportRegistry;
035:
036: import edu.iu.uis.eden.clientapp.vo.DocumentRouteLevelChangeVO;
037:
038: /**
039: * labor Document class for the Labor Ledger Correction Process.
040: */
041: public class LaborCorrectionDocument extends CorrectionDocument
042: implements AmountTotaling {
043: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(LaborCorrectionDocument.class);
045:
046: /**
047: * Constructs a LaborCorrectionDocument.java.
048: */
049: public LaborCorrectionDocument() {
050: super ();
051: }
052:
053: /**
054: * Constant for the workgroup approval routing level
055: */
056: private static final Integer WORKGROUP_APPROVAL_ROUTE_LEVEL = new Integer(
057: 1);
058:
059: /**
060: * @param change
061: * @see org.kuali.core.document.DocumentBase#handleRouteLevelChange(edu.iu.uis.eden.clientapp.vo.DocumentRouteLevelChangeVO)
062: */
063: @Override
064: public void handleRouteLevelChange(DocumentRouteLevelChangeVO change) {
065:
066: if (WORKGROUP_APPROVAL_ROUTE_LEVEL.equals(change
067: .getNewRouteLevel())) {
068: String correctionType = getCorrectionTypeCode();
069: if (LaborCorrectionDocumentService.CORRECTION_TYPE_MANUAL
070: .equals(correctionType)
071: || LaborCorrectionDocumentService.CORRECTION_TYPE_CRITERIA
072: .equals(correctionType)) {
073: String docId = getDocumentHeader().getDocumentNumber();
074: // this code is performed asynchronously
075: // First, save the origin entries to the origin entry table
076: DateTimeService dateTimeService = SpringContext
077: .getBean(DateTimeService.class);
078: LaborOriginEntryService laborOriginEntryService = SpringContext
079: .getBean(LaborOriginEntryService.class);
080: LaborCorrectionDocumentService laborCorrectionDocumentService = SpringContext
081: .getBean(LaborCorrectionDocumentService.class);
082: Iterator<LaborOriginEntry> outputEntries = laborCorrectionDocumentService
083: .retrievePersistedOutputOriginEntriesAsIterator(this );
084: // Create output group
085: java.sql.Date today = dateTimeService
086: .getCurrentSqlDate();
087: // Scrub is set to false when the document is initiated. When the document is final, it will be changed to true
088: OriginEntryGroup oeg = laborOriginEntryService
089: .copyEntries(
090: today,
091: OriginEntrySource.LABOR_CORRECTION_PROCESS_EDOC,
092: true, false, true, outputEntries);
093: // Now, run the reports
094: LaborReportService reportService = SpringContext
095: .getBean(LaborReportService.class);
096: LaborScrubberService laborScrubberService = SpringContext
097: .getBean(LaborScrubberService.class);
098: setCorrectionOutputGroupId(oeg.getId());
099: // not using the document service to save because it touches workflow, just save the doc BO as a regular BO
100: SpringContext.getBean(BusinessObjectService.class)
101: .save(this );
102: LOG.debug("handleRouteStatusChange() Run reports");
103: String reportsDirectory = ReportRegistry
104: .getReportsDirectory();
105: reportService.generateCorrectionOnlineReport(this ,
106: reportsDirectory, today);
107: // Run the scrubber on this group to generate a bunch of reports. The scrubber won't save anything when running it
108: // this way.
109: laborScrubberService.scrubGroupReportOnly(oeg, docId);
110: }
111: }
112: }
113:
114: /**
115: * If the document final, change the process flag on the output origin entry group (if necessary)
116: *
117: * @see org.kuali.core.document.DocumentBase#handleRouteStatusChange()
118: */
119: @Override
120: public void handleRouteStatusChange() {
121: LOG.debug("handleRouteStatusChange() started");
122: if (getDocumentHeader().getWorkflowDocument().stateIsCanceled()) {
123: getDocumentHeader().setFinancialDocumentStatusCode(
124: KFSConstants.DocumentStatusCodes.CANCELLED);
125: } else if (getDocumentHeader().getWorkflowDocument()
126: .stateIsEnroute()) {
127: getDocumentHeader().setFinancialDocumentStatusCode(
128: KFSConstants.DocumentStatusCodes.ENROUTE);
129: }
130: if (getDocumentHeader().getWorkflowDocument()
131: .stateIsDisapproved()) {
132: getDocumentHeader().setFinancialDocumentStatusCode(
133: KFSConstants.DocumentStatusCodes.DISAPPROVED);
134: }
135: if (getDocumentHeader().getWorkflowDocument()
136: .stateIsProcessed()) {
137: getDocumentHeader().setFinancialDocumentStatusCode(
138: KFSConstants.DocumentStatusCodes.APPROVED);
139: }
140:
141: LaborCorrectionDocumentService laborCorrectionDocumentService = SpringContext
142: .getBean(LaborCorrectionDocumentService.class);
143: OriginEntryGroupService originEntryGroupService = SpringContext
144: .getBean(OriginEntryGroupService.class);
145:
146: String docId = getDocumentHeader().getDocumentNumber();
147: LaborCorrectionDocument doc = laborCorrectionDocumentService
148: .findByCorrectionDocumentHeaderId(docId);
149:
150: if (getDocumentHeader().getWorkflowDocument().stateIsFinal()) {
151: String correctionType = doc.getCorrectionTypeCode();
152: if (LaborCorrectionDocumentService.CORRECTION_TYPE_REMOVE_GROUP_FROM_PROCESSING
153: .equals(correctionType)) {
154: SpringContext.getBean(OriginEntryGroupService.class)
155: .dontProcessGroup(
156: doc.getCorrectionInputGroupId());
157: } else if (LaborCorrectionDocumentService.CORRECTION_TYPE_MANUAL
158: .equals(correctionType)
159: || LaborCorrectionDocumentService.CORRECTION_TYPE_CRITERIA
160: .equals(correctionType)) {
161: OriginEntryGroup outputGroup = originEntryGroupService
162: .getExactMatchingEntryGroup(doc
163: .getCorrectionOutputGroupId()
164: .intValue());
165: if (!doc.getCorrectionFileDelete()) {
166: LOG
167: .debug("handleRouteStatusChange() Mark group as to be processed");
168: outputGroup.setProcess(true);
169: originEntryGroupService.save(outputGroup);
170: }
171: } else {
172: LOG.error("GLCP doc " + doc.getDocumentNumber()
173: + " has an unknown correction type code: "
174: + correctionType);
175: }
176: }
177: }
178: }
|