1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.fp.document;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import org.kuali.ole.fp.businessobject.ProcurementCardHolder;
24 import org.kuali.ole.fp.businessobject.ProcurementCardSourceAccountingLine;
25 import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
26 import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
27 import org.kuali.ole.integration.cam.CapitalAssetManagementModuleService;
28 import org.kuali.ole.sys.businessobject.AccountingLine;
29 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
30 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
31 import org.kuali.ole.sys.businessobject.TargetAccountingLine;
32 import org.kuali.ole.sys.context.SpringContext;
33 import org.kuali.ole.sys.document.AmountTotaling;
34 import org.kuali.ole.sys.document.service.DebitDeterminerService;
35 import org.kuali.rice.kew.api.KewApiConstants;
36 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
37 import org.kuali.rice.kns.service.DataDictionaryService;
38 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
39 import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
40
41
42
43
44
45
46 public class ProcurementCardDocument extends CapitalAccountingLinesDocumentBase implements AmountTotaling, CapitalAssetEditable {
47 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardDocument.class);
48
49 protected ProcurementCardHolder procurementCardHolder;
50
51 protected List transactionEntries;
52 protected ProcurementCardTargetAccountingLine newTargetLine;
53 protected transient CapitalAssetManagementModuleService capitalAssetManagementModuleService;
54
55
56
57
58 public ProcurementCardDocument() {
59 super();
60 transactionEntries = new ArrayList<ProcurementCardTransactionDetail>();
61 }
62
63
64
65
66 public List getTransactionEntries() {
67 return transactionEntries;
68 }
69
70
71
72
73 public void setTransactionEntries(List transactionEntries) {
74 this.transactionEntries = transactionEntries;
75 }
76
77
78
79
80
81
82 public ProcurementCardHolder getProcurementCardHolder() {
83 return procurementCardHolder;
84 }
85
86
87
88
89
90
91 public void setProcurementCardHolder(ProcurementCardHolder procurementCardHolder) {
92 this.procurementCardHolder = procurementCardHolder;
93 }
94
95
96
97
98
99
100 public void removeTargetAccountingLine(int index) {
101 ProcurementCardTargetAccountingLine line = (ProcurementCardTargetAccountingLine) getTargetAccountingLines().get(index);
102
103 for (Iterator iter = transactionEntries.iterator(); iter.hasNext();) {
104 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter.next();
105 if (transactionEntry.getFinancialDocumentTransactionLineNumber().equals(line.getFinancialDocumentTransactionLineNumber())) {
106 transactionEntry.getTargetAccountingLines().remove(line);
107 }
108 }
109 }
110
111
112
113
114
115
116
117 public void addSourceAccountingLine(SourceAccountingLine sourceLine) {
118 ProcurementCardSourceAccountingLine line = (ProcurementCardSourceAccountingLine) sourceLine;
119
120 line.setSequenceNumber(this.getNextSourceLineNumber());
121
122 for (Iterator iter = transactionEntries.iterator(); iter.hasNext();) {
123 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter.next();
124 if (transactionEntry.getFinancialDocumentTransactionLineNumber().equals(line.getFinancialDocumentTransactionLineNumber())) {
125 transactionEntry.getSourceAccountingLines().add(line);
126 }
127 }
128
129 this.nextSourceLineNumber = new Integer(this.getNextSourceLineNumber().intValue() + 1);
130 }
131
132
133
134
135
136
137 @Override
138 public void addTargetAccountingLine(TargetAccountingLine targetLine) {
139 ProcurementCardTargetAccountingLine line = (ProcurementCardTargetAccountingLine) targetLine;
140
141 line.setSequenceNumber(this.getNextTargetLineNumber());
142
143 for (Iterator iter = transactionEntries.iterator(); iter.hasNext();) {
144 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter.next();
145 if (transactionEntry.getFinancialDocumentTransactionLineNumber().equals(line.getFinancialDocumentTransactionLineNumber())) {
146 transactionEntry.getTargetAccountingLines().add(line);
147 }
148 }
149
150 this.nextTargetLineNumber = new Integer(this.getNextTargetLineNumber().intValue() + 1);
151 }
152
153
154
155
156
157
158 @Override
159 public List getSourceAccountingLines() {
160 List sourceAccountingLines = new ArrayList();
161
162 for (Iterator iter = transactionEntries.iterator(); iter.hasNext();) {
163 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter.next();
164 for (Iterator iterator = transactionEntry.getSourceAccountingLines().iterator(); iterator.hasNext();) {
165 SourceAccountingLine sourceLine = (SourceAccountingLine) iterator.next();
166 sourceAccountingLines.add(sourceLine);
167 }
168 }
169
170 return sourceAccountingLines;
171 }
172
173
174
175
176
177
178 @Override
179 public List getTargetAccountingLines() {
180 List targetAccountingLines = new ArrayList();
181
182 for (Iterator iter = transactionEntries.iterator(); iter.hasNext();) {
183 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter.next();
184 for (Iterator iterator = transactionEntry.getTargetAccountingLines().iterator(); iterator.hasNext();) {
185 TargetAccountingLine targetLine = (TargetAccountingLine) iterator.next();
186 targetAccountingLines.add(targetLine);
187 }
188 }
189
190 return targetAccountingLines;
191 }
192
193
194
195
196 @Override
197 public Class getSourceAccountingLineClass() {
198 return ProcurementCardSourceAccountingLine.class;
199 }
200
201
202
203
204 @Override
205 public Class getTargetAccountingLineClass() {
206 return ProcurementCardTargetAccountingLine.class;
207 }
208
209 @Override
210 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
211 super.doRouteStatusChange(statusChangeEvent);
212
213
214
215
216 if (!KewApiConstants.ACTION_TAKEN_SAVED_CD.equals(statusChangeEvent.getDocumentEventCode())) {
217 this.getCapitalAssetManagementModuleService().deleteDocumentAssetLocks(this);
218 }
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) throws IllegalStateException {
235
236 DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
237 isDebitUtils.disallowErrorCorrectionDocumentCheck(this);
238 return isDebitUtils.isDebitConsideringSection(this, (AccountingLine) postable);
239 }
240
241
242
243
244 @Override
245 public void postProcessSave(KualiDocumentEvent event) {
246 super.postProcessSave(event);
247 if (!(event instanceof SaveDocumentEvent)) {
248 String documentTypeName = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass());
249 this.getCapitalAssetManagementModuleService().generateCapitalAssetLock(this, documentTypeName);
250 }
251 }
252
253
254
255
256 protected CapitalAssetManagementModuleService getCapitalAssetManagementModuleService() {
257 if (capitalAssetManagementModuleService == null) {
258 capitalAssetManagementModuleService = SpringContext.getBean(CapitalAssetManagementModuleService.class);
259 }
260 return capitalAssetManagementModuleService;
261 }
262
263 }