1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.authorization;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapAuthorizationConstants.InvoiceEditMode;
20 import org.kuali.ole.module.purap.PurapConstants.InvoiceStatuses;
21 import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
22 import org.kuali.ole.module.purap.PurapParameterConstants;
23 import org.kuali.ole.module.purap.businessobject.InvoiceItem;
24 import org.kuali.ole.module.purap.document.InvoiceDocument;
25 import org.kuali.ole.module.purap.document.service.PurapService;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.OleAuthorizationConstants;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
30 import org.kuali.ole.sys.service.impl.OleParameterConstants;
31 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32 import org.kuali.rice.kew.api.WorkflowDocument;
33 import org.kuali.rice.kew.api.action.ActionType;
34 import org.kuali.rice.kew.api.action.ValidActions;
35 import org.kuali.rice.krad.document.Document;
36 import org.kuali.rice.krad.util.GlobalVariables;
37 import org.kuali.rice.krad.util.ObjectUtils;
38
39 import java.util.ArrayList;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.Set;
43
44
45 public class InvoiceDocumentPresentationController extends PurchasingAccountsPayableDocumentPresentationController {
46
47 Boolean canHold;
48 Boolean canRequestCancel;
49 Boolean canEditPreExtraction;
50
51 @Override
52 public boolean canSave(Document document) {
53 InvoiceDocument invoiceDocument = (InvoiceDocument) document;
54
55 if (!StringUtils.equalsIgnoreCase(invoiceDocument.getDocumentHeader().getWorkflowDocument().getStatus().name(), InvoiceStatuses.APPDOC_INITIATE)
56 && !StringUtils.equalsIgnoreCase(invoiceDocument.getDocumentHeader().getWorkflowDocument().getStatus().name(), OLEConstants.OleInvoice.INVOICE_SAVED)) {
57 return false;
58 }
59
60 if (canEditPreExtraction(invoiceDocument)) {
61 return true;
62 }
63
64 return super.canSave(document);
65 }
66
67 @Override
68 public boolean canReload(Document document) {
69 InvoiceDocument invoiceDocument = (InvoiceDocument) document;
70
71 if (StringUtils.equals(invoiceDocument.getApplicationDocumentStatus(), InvoiceStatuses.APPDOC_INITIATE)) {
72 return false;
73 }
74
75 if (canEditPreExtraction(invoiceDocument)) {
76 return true;
77 }
78
79 return super.canReload(document);
80 }
81
82 @Override
83 public boolean canCancel(Document document) {
84
85 return false;
86 }
87
88 @Override
89 public boolean canApprove(Document document) {
90 InvoiceDocument invoiceDocument = (InvoiceDocument) document;
91
92 if (invoiceDocument.isInvoiceCancelIndicator() || invoiceDocument.isHoldIndicator()) {
93 return false;
94 }
95
96 return super.canApprove(document);
97 }
98
99 @Override
100 public boolean canDisapprove(Document document) {
101
102 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
103 if (workflowDocument.isEnroute()) {
104 ValidActions validActions = workflowDocument.getValidActions();
105 return validActions.getValidActions().contains(ActionType.DISAPPROVE);
106 }
107
108 return super.canDisapprove(document);
109 }
110
111
112
113
114 @Override
115 public boolean canEdit(Document document) {
116 InvoiceDocument invoiceDocument = (InvoiceDocument) document;
117 boolean fullDocEntryCompleted = SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(invoiceDocument);
118
119
120 if (invoiceDocument.isHoldIndicator() || invoiceDocument.isInvoiceCancelIndicator()) {
121 return false;
122 }
123 if (fullDocEntryCompleted) {
124
125 if (invoiceDocument.isDocumentStoppedInRouteNode(InvoiceStatuses.NODE_ACCOUNT_REVIEW)) {
126 return true;
127 }
128 return false;
129 } else {
130
131 return true;
132 }
133 }
134
135
136
137
138 @Override
139 public Set<String> getEditModes(Document document) {
140 Set<String> editModes = super.getEditModes(document);
141
142 InvoiceDocument invoiceDocument = (InvoiceDocument) document;
143
144 if (canProcessorCancel(invoiceDocument)) {
145 editModes.add(InvoiceEditMode.ACCOUNTS_PAYABLE_PROCESSOR_CANCEL);
146 }
147
148 if (canManagerCancel(invoiceDocument)) {
149 editModes.add(InvoiceEditMode.ACCOUNTS_PAYABLE_MANAGER_CANCEL);
150 }
151
152 if (canHold(invoiceDocument)) {
153 editModes.add(InvoiceEditMode.HOLD);
154 }
155
156 if (canRequestCancel(invoiceDocument)) {
157 editModes.add(InvoiceEditMode.REQUEST_CANCEL);
158 }
159
160 if (canRemoveHold(invoiceDocument)) {
161 editModes.add(InvoiceEditMode.REMOVE_HOLD);
162 }
163
164 if (canRemoveRequestCancel(invoiceDocument)) {
165 editModes.add(InvoiceEditMode.REMOVE_REQUEST_CANCEL);
166 }
167
168 if (canProcessorInit(invoiceDocument)) {
169 editModes.add(InvoiceEditMode.DISPLAY_INIT_TAB);
170 }
171
172 if (ObjectUtils.isNotNull(invoiceDocument.getVendorHeaderGeneratedIdentifier())) {
173 editModes.add(InvoiceEditMode.LOCK_VENDOR_ENTRY);
174 }
175
176 if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(invoiceDocument)) {
177 editModes.add(InvoiceEditMode.FULL_DOCUMENT_ENTRY_COMPLETED);
178 }
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 if (canEditPreExtraction(invoiceDocument)) {
197 editModes.add(InvoiceEditMode.EDIT_PRE_EXTRACT);
198 }
199
200
201 boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
202 if (salesTaxInd) {
203 editModes.add(InvoiceEditMode.PURAP_TAX_ENABLED);
204
205 if (invoiceDocument.isUseTaxIndicator()) {
206
207 editModes.add(InvoiceEditMode.LOCK_TAX_AMOUNT_ENTRY);
208 } else {
209
210 editModes.add(InvoiceEditMode.CLEAR_ALL_TAXES);
211
212 }
213 }
214
215
216 if (invoiceDocument.isDocumentStoppedInRouteNode(InvoiceStatuses.NODE_VENDOR_TAX_REVIEW)) {
217 editModes.add(InvoiceEditMode.TAX_AREA_EDITABLE);
218 }
219
220 if (PurchaseOrderStatuses.APPDOC_AWAIT_TAX_REVIEW
221 .equals(invoiceDocument.getApplicationDocumentStatus())) {
222 editModes.add(InvoiceEditMode.TAX_AREA_EDITABLE);
223 }
224
225
226
227 if (InvoiceStatuses.APPDOC_DEPARTMENT_APPROVED.equals(invoiceDocument.getApplicationDocumentStatus()) &&
228
229 !StringUtils.isEmpty(invoiceDocument.getTaxClassificationCode())) {
230 editModes.add(InvoiceEditMode.TAX_INFO_VIEWABLE);
231 }
232
233 if (invoiceDocument.isDocumentStoppedInRouteNode(InvoiceStatuses.NODE_ACCOUNT_REVIEW)) {
234
235 editModes.add(InvoiceEditMode.RESTRICT_FISCAL_ENTRY);
236
237
238 if (!invoiceDocument.isHoldIndicator() && !invoiceDocument.isInvoiceCancelIndicator()) {
239 List lineList = new ArrayList();
240 for (Iterator iter = invoiceDocument.getItems().iterator(); iter.hasNext(); ) {
241 InvoiceItem item = (InvoiceItem) iter.next();
242 lineList.addAll(item.getSourceAccountingLines());
243
244 if (item.getItemType().isLineItemIndicator() && item.getSourceAccountingLines().size() == 0) {
245 editModes.add(OleAuthorizationConstants.TransactionalEditMode.EXPENSE_ENTRY);
246 }
247 }
248 }
249 }
250
251
252 if (invoiceDocument.isExtracted()) {
253 editModes.remove(OLEConstants.BANK_ENTRY_EDITABLE_EDITING_MODE);
254 }
255
256 return editModes;
257 }
258
259 protected boolean canProcessorInit(InvoiceDocument invoiceDocument) {
260
261 String status = invoiceDocument.getApplicationDocumentStatus();
262 if (StringUtils.equals(status, InvoiceStatuses.APPDOC_INITIATE)) {
263 return true;
264 }
265 return false;
266 }
267
268
269 protected boolean canProcessorCancel(InvoiceDocument invoiceDocument) {
270
271 if (canProcessorInit(invoiceDocument)) {
272 return false;
273 }
274
275 String docStatus = invoiceDocument.getApplicationDocumentStatus();
276 boolean requestCancelIndicator = invoiceDocument.getInvoiceCancelIndicator();
277 boolean holdIndicator = invoiceDocument.isHoldIndicator();
278 boolean extracted = invoiceDocument.isExtracted();
279
280 boolean preroute =
281 InvoiceStatuses.APPDOC_IN_PROCESS.equals(docStatus) ||
282 InvoiceStatuses.APPDOC_AWAITING_ACCOUNTS_PAYABLE_REVIEW.equals(docStatus);
283 boolean enroute =
284 InvoiceStatuses.APPDOC_AWAITING_SUB_ACCT_MGR_REVIEW.equals(docStatus) ||
285 InvoiceStatuses.APPDOC_AWAITING_FISCAL_REVIEW.equals(docStatus) ||
286 InvoiceStatuses.APPDOC_AWAITING_ORG_REVIEW.equals(docStatus) ||
287 InvoiceStatuses.APPDOC_AWAITING_PAYMENT_REVIEW.equals(docStatus)
288 ||
289 InvoiceStatuses.APPDOC_AWAITING_TAX_REVIEW.equals(docStatus);
290 boolean postroute =
291 InvoiceStatuses.APPDOC_DEPARTMENT_APPROVED.equals(docStatus) ||
292 InvoiceStatuses.APPDOC_AUTO_APPROVED.equals(docStatus);
293
294 boolean can = false;
295 if (InvoiceStatuses.STATUSES_PREROUTE.contains(docStatus)) {
296 can = true;
297 } else if (InvoiceStatuses.STATUSES_ENROUTE.contains(docStatus)) {
298 can = requestCancelIndicator;
299 } else if (InvoiceStatuses.STATUSES_POSTROUTE.contains(docStatus)) {
300 can = !requestCancelIndicator && !holdIndicator && !extracted;
301 }
302
303 return can;
304 }
305
306 protected boolean canManagerCancel(InvoiceDocument invoiceDocument) {
307
308 if (canProcessorInit(invoiceDocument)) {
309 return false;
310 }
311
312 String docStatus = invoiceDocument.getApplicationDocumentStatus();
313 boolean requestCancelIndicator = invoiceDocument.getInvoiceCancelIndicator();
314 boolean holdIndicator = invoiceDocument.isHoldIndicator();
315 boolean extracted = invoiceDocument.isExtracted();
316
317 boolean preroute =
318 InvoiceStatuses.APPDOC_IN_PROCESS.equals(docStatus) ||
319 InvoiceStatuses.APPDOC_AWAITING_ACCOUNTS_PAYABLE_REVIEW.equals(docStatus);
320 boolean enroute =
321 InvoiceStatuses.APPDOC_AWAITING_SUB_ACCT_MGR_REVIEW.equals(docStatus) ||
322 InvoiceStatuses.APPDOC_AWAITING_FISCAL_REVIEW.equals(docStatus) ||
323 InvoiceStatuses.APPDOC_AWAITING_ORG_REVIEW.equals(docStatus) ||
324 InvoiceStatuses.APPDOC_AWAITING_PAYMENT_REVIEW.equals(docStatus)
325 ||
326 InvoiceStatuses.APPDOC_AWAITING_TAX_REVIEW.equals(docStatus);
327 boolean postroute =
328 InvoiceStatuses.APPDOC_DEPARTMENT_APPROVED.equals(docStatus) ||
329 InvoiceStatuses.APPDOC_AUTO_APPROVED.equals(docStatus);
330
331 boolean can = false;
332 if (InvoiceStatuses.STATUSES_PREROUTE.contains(docStatus) ||
333 InvoiceStatuses.STATUSES_ENROUTE.contains(docStatus)) {
334 can = true;
335 } else if (InvoiceStatuses.STATUSES_POSTROUTE.contains(docStatus)) {
336 can = !requestCancelIndicator && !holdIndicator && !extracted;
337 }
338
339 return can;
340 }
341
342
343
344
345
346
347
348
349
350
351 protected boolean canHold(InvoiceDocument invoiceDocument) {
352 if (canHold == null) {
353
354 boolean can = !invoiceDocument.isHoldIndicator()
355 && !invoiceDocument.isInvoiceCancelIndicator()
356 && !invoiceDocument.isExtracted();
357 if (can) {
358 can = SpringContext.getBean(FinancialSystemWorkflowHelperService.class)
359 .isAdhocApprovalRequestedForPrincipal(
360 invoiceDocument.getFinancialSystemDocumentHeader().getWorkflowDocument(),
361 GlobalVariables.getUserSession().getPrincipalId());
362 can = can
363 || !InvoiceStatuses.STATUSES_DISALLOWING_HOLD.contains(invoiceDocument
364 .getApplicationDocumentStatus());
365 }
366 canHold = can;
367 }
368
369 return canHold;
370 }
371
372
373
374
375
376
377
378
379
380
381 protected boolean canRequestCancel(InvoiceDocument invoiceDocument) {
382 if (canRequestCancel == null) {
383 boolean can = !invoiceDocument.isInvoiceCancelIndicator()
384 && !invoiceDocument.isHoldIndicator() && !invoiceDocument.isExtracted();
385 if (can) {
386 can = SpringContext.getBean(FinancialSystemWorkflowHelperService.class)
387 .isAdhocApprovalRequestedForPrincipal(
388 invoiceDocument.getFinancialSystemDocumentHeader().getWorkflowDocument(),
389 GlobalVariables.getUserSession().getPrincipalId());
390 can = can
391 || !InvoiceStatuses.STATUSES_DISALLOWING_REQUEST_CANCEL.contains(invoiceDocument
392 .getApplicationDocumentStatus());
393 }
394 canRequestCancel = can;
395 }
396 return canRequestCancel;
397 }
398
399
400
401
402
403
404
405
406
407
408
409 protected boolean canRemoveHold(InvoiceDocument invoiceDocument) {
410 return invoiceDocument.isHoldIndicator();
411 }
412
413
414
415
416
417
418
419
420
421
422
423 protected boolean canRemoveRequestCancel(InvoiceDocument invoiceDocument) {
424 return invoiceDocument.isInvoiceCancelIndicator();
425 }
426
427 protected boolean canEditPreExtraction(InvoiceDocument invoiceDocument) {
428 if (canEditPreExtraction == null) {
429 boolean can = (!invoiceDocument.isExtracted()
430 && !SpringContext.getBean(FinancialSystemWorkflowHelperService.class)
431 .isAdhocApprovalRequestedForPrincipal(
432 invoiceDocument.getFinancialSystemDocumentHeader().getWorkflowDocument(),
433 GlobalVariables.getUserSession().getPrincipalId()) && !InvoiceStatuses.CANCELLED_STATUSES
434 .contains(invoiceDocument.getApplicationDocumentStatus()));
435 canEditPreExtraction = can;
436 }
437 return canEditPreExtraction;
438 }
439
440 }