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.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.core.bo.DocumentType;
022: import org.kuali.core.document.AmountTotaling;
023: import org.kuali.core.exceptions.ValidationException;
024: import org.kuali.core.rule.event.KualiDocumentEvent;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.kfs.bo.AccountingLineParser;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.financial.document.JournalVoucherDocument;
029: import org.kuali.module.labor.LaborConstants.JournalVoucherOffsetType;
030: import org.kuali.module.labor.bo.LaborJournalVoucherAccountingLineParser;
031: import org.kuali.module.labor.bo.LaborJournalVoucherDetail;
032: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
033: import org.kuali.module.labor.service.LaborLedgerPendingEntryService;
034:
035: // @latex.ClassSignatureStart
036: /**
037: * Labor Document class for the Labor Ledger Journal Voucher.
038: */
039: public class LaborJournalVoucherDocument extends JournalVoucherDocument
040: implements LaborLedgerPostingDocument, AmountTotaling {
041: // @latex.ClassSignatureStop
042: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(LaborJournalVoucherDocument.class);
044: private String offsetTypeCode = JournalVoucherOffsetType.NO_OFFSET.typeCode;
045: private List<LaborLedgerPendingEntry> laborLedgerPendingEntries;
046: private DocumentType documentType;
047:
048: /**
049: * Constructs a LaborJournalVoucherDocument.java.
050: */
051: public LaborJournalVoucherDocument() {
052: super ();
053: setLaborLedgerPendingEntries(new ArrayList<LaborLedgerPendingEntry>());
054: }
055:
056: /**
057: * @see org.kuali.kfs.document.AccountingDocumentBase#getSourceAccountingLineClass()
058: */
059: @Override
060: public Class getSourceAccountingLineClass() {
061: return LaborJournalVoucherDetail.class;
062: }
063:
064: /**
065: * @see org.kuali.module.labor.document.LaborLedgerPostingDocument#getLaborLedgerPendingEntry(int)
066: */
067: public LaborLedgerPendingEntry getLaborLedgerPendingEntry(int index) {
068: while (laborLedgerPendingEntries.size() <= index) {
069: laborLedgerPendingEntries
070: .add(new LaborLedgerPendingEntry());
071: }
072: return laborLedgerPendingEntries.get(index);
073: }
074:
075: /**
076: * @see org.kuali.kfs.document.AccountingDocumentBase#prepareForSave(org.kuali.core.rule.event.KualiDocumentEvent)
077: */
078: @Override
079: public void prepareForSave(KualiDocumentEvent event) {
080: super .prepareForSave(event);
081: if (!SpringContext
082: .getBean(LaborLedgerPendingEntryService.class)
083: .generateLaborLedgerPendingEntries(this )) {
084: logErrors();
085: throw new ValidationException(
086: "labor ledger LLPE generation failed");
087: }
088: }
089:
090: /**
091: * Gets the offsetTypeCode attribute.
092: *
093: * @return Returns the offsetTypeCode.
094: */
095: public String getOffsetTypeCode() {
096: return offsetTypeCode;
097: }
098:
099: /**
100: * Sets the offsetTypeCode attribute value.
101: *
102: * @param offsetTypeCode The offsetTypeCode to set.
103: */
104: public void setOffsetTypeCode(String offsetTypeCode) {
105: this .offsetTypeCode = offsetTypeCode;
106: }
107:
108: /**
109: * Gets the laborLedgerPendingEntries attribute.
110: *
111: * @return Returns the laborLedgerPendingEntries.
112: */
113: public List<LaborLedgerPendingEntry> getLaborLedgerPendingEntries() {
114: return laborLedgerPendingEntries;
115: }
116:
117: /**
118: * Sets the laborLedgerPendingEntries attribute value.
119: *
120: * @param laborLedgerPendingEntries The laborLedgerPendingEntries to set.
121: */
122: public void setLaborLedgerPendingEntries(
123: List<LaborLedgerPendingEntry> laborLedgerPendingEntries) {
124: this .laborLedgerPendingEntries = laborLedgerPendingEntries;
125: }
126:
127: /**
128: * Gets the documentType attribute.
129: *
130: * @return Returns the documentType.
131: */
132: public DocumentType getDocumentType() {
133: return documentType;
134: }
135:
136: /**
137: * Sets the documentType attribute value.
138: *
139: * @param documentType The documentType to set.
140: */
141: public void setDocumentType(DocumentType documentType) {
142: this .documentType = documentType;
143: }
144:
145: /**
146: * Used to get the appropriate <code>{@link AccountingLineParser}</code> for the <code>Document</code>
147: *
148: * @return AccountingLineParser
149: */
150: @Override
151: public AccountingLineParser getAccountingLineParser() {
152: return new LaborJournalVoucherAccountingLineParser(
153: getBalanceTypeCode());
154: }
155:
156: /**
157: * Override to call super and then iterate over all GLPEs and update the approved code appropriately.
158: *
159: * @see Document#handleRouteStatusChange()
160: */
161: @Override
162: public void handleRouteStatusChange() {
163: super .handleRouteStatusChange();
164: if (getDocumentHeader().getWorkflowDocument()
165: .stateIsProcessed()) {
166: changeLedgerPendingEntriesApprovedStatusCode();
167: } else if (getDocumentHeader().getWorkflowDocument()
168: .stateIsCanceled()
169: || getDocumentHeader().getWorkflowDocument()
170: .stateIsDisapproved()) {
171: removeLedgerPendingEntries();
172: }
173: }
174:
175: /**
176: * This method iterates over all of the pending entries for a document and sets their approved status code to APPROVED "A".
177: */
178: private void changeLedgerPendingEntriesApprovedStatusCode() {
179: for (LaborLedgerPendingEntry pendingEntry : laborLedgerPendingEntries) {
180: pendingEntry
181: .setFinancialDocumentApprovedCode(KFSConstants.DocumentStatusCodes.APPROVED);
182: }
183: }
184:
185: /**
186: * This method calls the service to remove all of the pending entries associated with this document
187: */
188: private void removeLedgerPendingEntries() {
189: LaborLedgerPendingEntryService laborLedgerPendingEntryService = SpringContext
190: .getBean(LaborLedgerPendingEntryService.class);
191: laborLedgerPendingEntryService.delete(getDocumentHeader()
192: .getDocumentNumber());
193: }
194: }
|