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:
017: package org.kuali.module.financial.document;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.LinkedHashMap;
022: import java.util.List;
023:
024: import org.kuali.core.document.AmountTotaling;
025: import org.kuali.core.document.Document;
026: import org.kuali.core.service.DocumentService;
027: import org.kuali.core.util.TypedArrayList;
028: import org.kuali.kfs.KFSPropertyConstants;
029: import org.kuali.kfs.bo.SourceAccountingLine;
030: import org.kuali.kfs.bo.TargetAccountingLine;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.kfs.document.AccountingDocumentBase;
033: import org.kuali.module.financial.bo.ProcurementCardHolder;
034: import org.kuali.module.financial.bo.ProcurementCardSourceAccountingLine;
035: import org.kuali.module.financial.bo.ProcurementCardTargetAccountingLine;
036: import org.kuali.module.financial.bo.ProcurementCardTransactionDetail;
037:
038: import edu.iu.uis.eden.EdenConstants;
039: import edu.iu.uis.eden.clientapp.vo.DocumentRouteStatusChangeVO;
040:
041: /**
042: * This is the Procurement Card Document Class. The procurement cards distributes expenses from clearing accounts. It is a two-sided
043: * document, but only target lines are displayed because source lines cannot be changed. Transaction, Card, and Vendor information
044: * are associated with the document to help better distribute the expense.
045: */
046: public class ProcurementCardDocument extends AccountingDocumentBase
047: implements AmountTotaling {
048: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(ProcurementCardDocument.class);
050:
051: private ProcurementCardHolder procurementCardHolder;
052:
053: private List transactionEntries;
054:
055: /**
056: * Default constructor.
057: */
058: public ProcurementCardDocument() {
059: super ();
060: transactionEntries = new TypedArrayList(
061: ProcurementCardTransactionDetail.class);
062: }
063:
064: /**
065: * @return Returns the transactionEntries.
066: */
067: public List getTransactionEntries() {
068: return transactionEntries;
069: }
070:
071: /**
072: * @param transactionEntries The transactionEntries to set.
073: */
074: public void setTransactionEntries(List transactionEntries) {
075: this .transactionEntries = transactionEntries;
076: }
077:
078: /**
079: * Gets the procurementCardHolder attribute.
080: *
081: * @return Returns the procurementCardHolder.
082: */
083: public ProcurementCardHolder getProcurementCardHolder() {
084: return procurementCardHolder;
085: }
086:
087: /**
088: * Sets the procurementCardHolder attribute value.
089: *
090: * @param procurementCardHolder The procurementCardHolder to set.
091: */
092: public void setProcurementCardHolder(
093: ProcurementCardHolder procurementCardHolder) {
094: this .procurementCardHolder = procurementCardHolder;
095: }
096:
097: /**
098: * Removes the target accounting line at the given index from the transaction detail entry.
099: *
100: * @param index
101: */
102: public void removeTargetAccountingLine(int index) {
103: ProcurementCardTargetAccountingLine line = (ProcurementCardTargetAccountingLine) getTargetAccountingLines()
104: .get(index);
105:
106: for (Iterator iter = transactionEntries.iterator(); iter
107: .hasNext();) {
108: ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter
109: .next();
110: if (transactionEntry
111: .getFinancialDocumentTransactionLineNumber()
112: .equals(
113: line
114: .getFinancialDocumentTransactionLineNumber())) {
115: transactionEntry.getTargetAccountingLines()
116: .remove(line);
117: }
118: }
119: }
120:
121: /**
122: * Override to set the accounting line in the transaction detail object.
123: *
124: * @see org.kuali.kfs.document.AccountingDocument#addSourceAccountingLine(SourceAccountingLine)
125: */
126: @Override
127: public void addSourceAccountingLine(SourceAccountingLine sourceLine) {
128: ProcurementCardSourceAccountingLine line = (ProcurementCardSourceAccountingLine) sourceLine;
129:
130: line.setSequenceNumber(this .getNextSourceLineNumber());
131:
132: for (Iterator iter = transactionEntries.iterator(); iter
133: .hasNext();) {
134: ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter
135: .next();
136: if (transactionEntry
137: .getFinancialDocumentTransactionLineNumber()
138: .equals(
139: line
140: .getFinancialDocumentTransactionLineNumber())) {
141: transactionEntry.getSourceAccountingLines().add(line);
142: }
143: }
144:
145: this .nextSourceLineNumber = new Integer(this
146: .getNextSourceLineNumber().intValue() + 1);
147: }
148:
149: /**
150: * Override to set the accounting line in the transaction detail object.
151: *
152: * @see org.kuali.kfs.document.AccountingDocument#addTargetAccountingLine(TargetAccountingLine)
153: */
154: @Override
155: public void addTargetAccountingLine(TargetAccountingLine targetLine) {
156: ProcurementCardTargetAccountingLine line = (ProcurementCardTargetAccountingLine) targetLine;
157:
158: line.setSequenceNumber(this .getNextTargetLineNumber());
159:
160: for (Iterator iter = transactionEntries.iterator(); iter
161: .hasNext();) {
162: ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter
163: .next();
164: if (transactionEntry
165: .getFinancialDocumentTransactionLineNumber()
166: .equals(
167: line
168: .getFinancialDocumentTransactionLineNumber())) {
169: transactionEntry.getTargetAccountingLines().add(line);
170: }
171: }
172:
173: this .nextTargetLineNumber = new Integer(this
174: .getNextTargetLineNumber().intValue() + 1);
175: }
176:
177: /**
178: * Override to get source accounting lines out of transactions
179: *
180: * @see org.kuali.kfs.document.AccountingDocument#getSourceAccountingLines()
181: */
182: @Override
183: public List getSourceAccountingLines() {
184: List sourceAccountingLines = new ArrayList();
185:
186: for (Iterator iter = transactionEntries.iterator(); iter
187: .hasNext();) {
188: ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter
189: .next();
190: for (Iterator iterator = transactionEntry
191: .getSourceAccountingLines().iterator(); iterator
192: .hasNext();) {
193: SourceAccountingLine sourceLine = (SourceAccountingLine) iterator
194: .next();
195: sourceAccountingLines.add(sourceLine);
196: }
197: }
198:
199: return sourceAccountingLines;
200: }
201:
202: /**
203: * Override to get target accounting lines out of transactions
204: *
205: * @see org.kuali.kfs.document.AccountingDocument#getTargetAccountingLines()
206: */
207: @Override
208: public List getTargetAccountingLines() {
209: List targetAccountingLines = new ArrayList();
210:
211: for (Iterator iter = transactionEntries.iterator(); iter
212: .hasNext();) {
213: ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter
214: .next();
215: for (Iterator iterator = transactionEntry
216: .getTargetAccountingLines().iterator(); iterator
217: .hasNext();) {
218: TargetAccountingLine targetLine = (TargetAccountingLine) iterator
219: .next();
220: targetAccountingLines.add(targetLine);
221: }
222: }
223:
224: return targetAccountingLines;
225: }
226:
227: /**
228: * @see org.kuali.kfs.document.AccountingDocumentBase#getSourceAccountingLineClass()
229: */
230: @Override
231: public Class getSourceAccountingLineClass() {
232: return ProcurementCardSourceAccountingLine.class;
233: }
234:
235: /**
236: * @see org.kuali.kfs.document.AccountingDocumentBase#getTargetAccountingLineClass()
237: */
238: @Override
239: public Class getTargetAccountingLineClass() {
240: return ProcurementCardTargetAccountingLine.class;
241: }
242:
243: /**
244: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
245: */
246: @Override
247: protected LinkedHashMap toStringMapper() {
248: LinkedHashMap m = new LinkedHashMap();
249: m
250: .put(KFSPropertyConstants.DOCUMENT_NUMBER,
251: this .documentNumber);
252: return m;
253: }
254:
255: @Override
256: public void doRouteStatusChange(
257: DocumentRouteStatusChangeVO statusChangeEvent)
258: throws Exception {
259: if (EdenConstants.ROUTE_HEADER_ENROUTE_CD
260: .equals(statusChangeEvent.getNewRouteStatus())) {
261: Document retrievedDocument = SpringContext.getBean(
262: DocumentService.class).getByDocumentHeaderId(
263: statusChangeEvent.getRouteHeaderId().toString());
264: if (EdenConstants.ROUTE_HEADER_ENROUTE_CD
265: .equals(retrievedDocument.getDocumentHeader()
266: .getWorkflowDocument().getRouteHeader()
267: .getDocRouteStatus())
268: && !EdenConstants.ROUTE_HEADER_ENROUTE_CD
269: .equals(retrievedDocument
270: .getDocumentHeader()
271: .getFinancialDocumentStatusCode())) {
272: throw new RuntimeException(
273: "KFS document status is out of sync with Workflow document status");
274: }
275: }
276: }
277:
278: }
|