1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.integration.purap.CapitalAssetLocation;
20 import org.kuali.ole.module.purap.PurapAuthorizationConstants;
21 import org.kuali.ole.module.purap.PurapConstants;
22 import org.kuali.ole.module.purap.PurapConstants.PaymentRequestStatuses;
23 import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
24 import org.kuali.ole.module.purap.PurapPropertyConstants;
25 import org.kuali.ole.module.purap.businessobject.*;
26 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
27 import org.kuali.ole.module.purap.document.PurchaseOrderAmendmentDocument;
28 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
29 import org.kuali.ole.module.purap.document.PurchaseOrderSplitDocument;
30 import org.kuali.ole.module.purap.document.service.PaymentRequestService;
31 import org.kuali.ole.module.purap.document.service.PurapService;
32 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
33 import org.kuali.ole.module.purap.document.service.ReceivingService;
34 import org.kuali.ole.module.purap.util.PurApItemUtils;
35 import org.kuali.ole.sys.OLEConstants;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.rice.core.api.datetime.DateTimeService;
38 import org.kuali.rice.kew.api.WorkflowDocument;
39 import org.kuali.rice.kew.api.document.DocumentStatusCategory;
40 import org.kuali.rice.kim.api.KimConstants;
41 import org.kuali.rice.kim.api.services.IdentityManagementService;
42 import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
43 import org.kuali.rice.kns.service.DataDictionaryService;
44 import org.kuali.rice.kns.service.DocumentHelperService;
45 import org.kuali.rice.kns.web.ui.ExtraButton;
46 import org.kuali.rice.kns.web.ui.HeaderField;
47 import org.kuali.rice.krad.util.GlobalVariables;
48 import org.kuali.rice.krad.util.KRADConstants;
49 import org.kuali.rice.krad.util.ObjectUtils;
50
51 import javax.servlet.http.HttpServletRequest;
52 import java.math.BigDecimal;
53 import java.util.Arrays;
54 import java.util.HashMap;
55 import java.util.List;
56 import java.util.Map;
57
58
59
60
61 public class PurchaseOrderForm extends PurchasingFormBase {
62 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderForm.class);
63
64 protected PurchaseOrderVendorStipulation newPurchaseOrderVendorStipulationLine;
65 protected PurchaseOrderVendorQuote newPurchaseOrderVendorQuote;
66 protected Long awardedVendorNumber;
67
68
69 protected String[] retransmitItemsSelected = {};
70 protected String retransmitTransmissionMethod;
71 protected String retransmitFaxNumber;
72 protected String retransmitHeader;
73
74
75 protected Map accountingLineEditingMode;
76
77 protected String splitNoteText;
78
79
80 protected String sensitiveDataAssignmentReason = null;
81 protected SensitiveDataAssignment lastSensitiveDataAssignment = null;
82 protected SensitiveData newSensitiveDataLine = null;
83 protected List<SensitiveData> sensitiveDatasAssigned = null;
84
85 protected final String PURCHASING_PROCESSOR_ROLE_NAME = "Purchasing Processor";
86
87
88
89
90 public PurchaseOrderForm() {
91 super();
92
93 setNewPurchaseOrderVendorStipulationLine(new PurchaseOrderVendorStipulation());
94 setNewPurchaseOrderVendorQuote(new PurchaseOrderVendorQuote());
95 this.accountingLineEditingMode = new HashMap();
96
97 setReadOnlyAccountDistributionMethod(true);
98 }
99
100 @Override
101 protected String getDefaultDocumentTypeName() {
102 return "OLE_PO";
103 }
104
105 public Map getAccountingLineEditingMode() {
106 return accountingLineEditingMode;
107 }
108
109 public void setAccountingLineEditingMode(Map accountingLineEditingMode) {
110 this.accountingLineEditingMode = accountingLineEditingMode;
111 }
112
113 public Long getAwardedVendorNumber() {
114 return awardedVendorNumber;
115 }
116
117 public void setAwardedVendorNumber(Long awardedVendorNumber) {
118 this.awardedVendorNumber = awardedVendorNumber;
119 }
120
121 public PurchaseOrderVendorStipulation getNewPurchaseOrderVendorStipulationLine() {
122 return newPurchaseOrderVendorStipulationLine;
123 }
124
125 public void setNewPurchaseOrderVendorStipulationLine(PurchaseOrderVendorStipulation newPurchaseOrderVendorStipulationLine) {
126 this.newPurchaseOrderVendorStipulationLine = newPurchaseOrderVendorStipulationLine;
127 }
128
129 public PurchaseOrderVendorQuote getNewPurchaseOrderVendorQuote() {
130 return newPurchaseOrderVendorQuote;
131 }
132
133 public void setNewPurchaseOrderVendorQuote(PurchaseOrderVendorQuote newPurchaseOrderVendorQuote) {
134 this.newPurchaseOrderVendorQuote = newPurchaseOrderVendorQuote;
135 }
136
137 public String[] getRetransmitItemsSelected() {
138 return retransmitItemsSelected;
139 }
140
141 public void setRetransmitItemsSelected(String[] retransmitItemsSelected) {
142 this.retransmitItemsSelected = retransmitItemsSelected;
143 }
144
145 public PurchaseOrderDocument getPurchaseOrderDocument() {
146 return (PurchaseOrderDocument) getDocument();
147 }
148
149 public void setPurchaseOrderDocument(PurchaseOrderDocument purchaseOrderDocument) {
150 setDocument(purchaseOrderDocument);
151 }
152
153 public String getSplitNoteText() {
154 return splitNoteText;
155 }
156
157 public void setSplitNoteText(String splitNoteText) {
158 this.splitNoteText = splitNoteText;
159 }
160
161 public String getSensitiveDataAssignmentReason() {
162 return sensitiveDataAssignmentReason;
163 }
164
165 public void setSensitiveDataAssignmentReason(String sensitiveDataAssignmentReason) {
166 this.sensitiveDataAssignmentReason = sensitiveDataAssignmentReason;
167 }
168
169 public SensitiveDataAssignment getLastSensitiveDataAssignment() {
170 return lastSensitiveDataAssignment;
171 }
172
173 public void setLastSensitiveDataAssignment(SensitiveDataAssignment lastSensitiveDataAssignment) {
174 this.lastSensitiveDataAssignment = lastSensitiveDataAssignment;
175 }
176
177 public SensitiveData getNewSensitiveDataLine() {
178 return newSensitiveDataLine;
179 }
180
181 public void setNewSensitiveDataLine(SensitiveData newSensitiveDataLine) {
182 this.newSensitiveDataLine = newSensitiveDataLine;
183 }
184
185 public List<SensitiveData> getSensitiveDatasAssigned() {
186 return sensitiveDatasAssigned;
187 }
188
189 public void setSensitiveDatasAssigned(List<SensitiveData> poSensitiveData) {
190 this.sensitiveDatasAssigned = poSensitiveData;
191 }
192
193 @Override
194 public Class getCapitalAssetLocationClass() {
195 return PurchaseOrderCapitalAssetLocation.class;
196 }
197
198 @Override
199 public Class getItemCapitalAssetClass() {
200 return PurchaseOrderItemCapitalAsset.class;
201 }
202
203 @Override
204 public CapitalAssetLocation setupNewPurchasingCapitalAssetLocationLine() {
205 CapitalAssetLocation location = new RequisitionCapitalAssetLocation();
206 return location;
207 }
208
209
210
211
212 @Override
213 public PurApItem setupNewPurchasingItemLine() {
214 return new PurchaseOrderItem();
215 }
216
217
218
219
220 @Override
221 public PurchaseOrderAccount setupNewPurchasingAccountingLine() {
222 return new PurchaseOrderAccount();
223 }
224
225
226
227
228 @Override
229 public PurchaseOrderAccount setupNewAccountDistributionAccountingLine() {
230 PurchaseOrderAccount account = setupNewPurchasingAccountingLine();
231 account.setAccountLinePercent(new BigDecimal(100));
232 return account;
233 }
234
235 public boolean isReadOnlyReceivingRequired() {
236
237 PurchaseOrderDocument poDoc = getPurchaseOrderDocument();
238
239 if (poDoc instanceof PurchaseOrderAmendmentDocument) {
240 if (!poDoc.isReceivingDocumentRequiredIndicator()) {
241 if (GlobalVariables.getMessageMap().hasNoErrors()) {
242
243
244
245
246
247 return SpringContext.getBean(PaymentRequestService.class).hasActivePaymentRequestsForPurchaseOrder(poDoc.getPurapDocumentIdentifier());
248 } else {
249 return true;
250 }
251 }
252 }
253
254 return false;
255 }
256
257
258
259
260
261
262 public PurchaseOrderVendorStipulation getAndResetNewPurchaseOrderVendorStipulationLine() {
263 PurchaseOrderVendorStipulation aPurchaseOrderVendorStipulationLine = getNewPurchaseOrderVendorStipulationLine();
264 setNewPurchaseOrderVendorStipulationLine(new PurchaseOrderVendorStipulation());
265
266 aPurchaseOrderVendorStipulationLine.setDocumentNumber(getPurchaseOrderDocument().getDocumentNumber());
267 aPurchaseOrderVendorStipulationLine.setVendorStipulationAuthorEmployeeIdentifier(GlobalVariables.getUserSession().getPerson().getPrincipalId());
268 aPurchaseOrderVendorStipulationLine.setVendorStipulationCreateDate(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate());
269
270 return aPurchaseOrderVendorStipulationLine;
271 }
272
273 public String getStatusChange() {
274 if (StringUtils.isNotEmpty(getPurchaseOrderDocument().getStatusChange())) {
275 return getPurchaseOrderDocument().getStatusChange();
276 } else {
277 if (StringUtils.equals(getPurchaseOrderDocument().getApplicationDocumentStatus(), PurchaseOrderStatuses.APPDOC_IN_PROCESS)) {
278 return PurchaseOrderStatuses.APPDOC_IN_PROCESS;
279 } else if (StringUtils.equals(getPurchaseOrderDocument().getApplicationDocumentStatus(), PurchaseOrderStatuses.APPDOC_WAITING_FOR_DEPARTMENT)) {
280 return PurchaseOrderStatuses.APPDOC_WAITING_FOR_DEPARTMENT;
281 } else if (StringUtils.equals(getPurchaseOrderDocument().getApplicationDocumentStatus(), PurchaseOrderStatuses.APPDOC_WAITING_FOR_VENDOR)) {
282 return PurchaseOrderStatuses.APPDOC_WAITING_FOR_VENDOR;
283 } else {
284 return null;
285 }
286 }
287 }
288
289 public void setStatusChange(String statusChange) {
290 getPurchaseOrderDocument().setStatusChange(statusChange);
291 }
292
293
294
295
296 @Override
297 public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
298 List<String> methodToCallList = Arrays.asList(new String[]{"printPurchaseOrderPDFOnly", "printingRetransmitPoOnly", "printPoQuoteListOnly"});
299
300 if (KRADConstants.DISPATCH_REQUEST_PARAMETER.equals(methodToCallParameterName) && methodToCallList.contains(methodToCallParameterValue)) {
301 return true;
302 }
303 return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
304 }
305
306 @Override
307 public void populateHeaderFields(WorkflowDocument workflowDocument) {
308 super.populateHeaderFields(workflowDocument);
309
310 String poIDstr = getPurchaseOrderDocument().getPurapDocumentIdentifier().toString();
311
312
313
314 if (!workflowDocument.getStatus().getCategory().equals(DocumentStatusCategory.SUCCESSFUL)) {
315 String principalId = GlobalVariables.getUserSession().getPerson().getPrincipalId();
316 String namespaceCode = OLEConstants.ParameterNamespaces.KNS;
317 String permissionTemplateName = KimConstants.PermissionTemplateNames.FULL_UNMASK_FIELD;
318
319 Map<String, String> roleQualifiers = new HashMap<String, String>();
320
321 Map<String, String> permissionDetails = new HashMap<String, String>();
322 permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, PurchaseOrderDocument.class.getSimpleName());
323 permissionDetails.put(KimConstants.AttributeConstants.PROPERTY_NAME, PurapPropertyConstants.PURAP_DOC_ID);
324
325 IdentityManagementService identityManagementService = SpringContext.getBean(IdentityManagementService.class);
326 Boolean isAuthorized = identityManagementService.isAuthorizedByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails, roleQualifiers);
327
328
329 if (!isAuthorized) {
330 DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
331 if (ObjectUtils.isNotNull(getPurchaseOrderDocument().getPurapDocumentIdentifier())) {
332 poIDstr = "";
333 int strLength = dataDictionaryService.getAttributeMaxLength(PurApGenericAttributes.class.getName(), PurapPropertyConstants.PURAP_DOC_ID);
334 for (int i = 0; i < strLength; i++) {
335 poIDstr = poIDstr.concat("*");
336 }
337 }
338 }
339 }
340
341 if (ObjectUtils.isNotNull(getPurchaseOrderDocument().getPurapDocumentIdentifier())) {
342 getDocInfo().add(new HeaderField("DataDictionary.PurchaseOrderDocument.attributes.purapDocumentIdentifier", poIDstr));
343 } else {
344 getDocInfo().add(new HeaderField("DataDictionary.PurchaseOrderDocument.attributes.purapDocumentIdentifier", PurapConstants.PURAP_APPLICATION_DOCUMENT_ID_NOT_AVAILABLE));
345 }
346 if (ObjectUtils.isNotNull(getPurchaseOrderDocument().getApplicationDocumentStatus())) {
347 getDocInfo().add(new HeaderField("DataDictionary.PurchaseOrderDocument.attributes.applicationDocumentStatus", getPurchaseOrderDocument().getApplicationDocumentStatus()));
348 } else {
349 getDocInfo().add(new HeaderField("DataDictionary.PurchaseOrderDocument.attributes.applicationDocumentStatus", PurapConstants.PURAP_APPLICATION_DOCUMENT_STATUS_NOT_AVAILABLE));
350 }
351 }
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381 protected boolean processPaymentRequestRulesForCanClose(PurchaseOrderDocument document) {
382 boolean valid = true;
383
384 Integer poDocId = document.getPurapDocumentIdentifier();
385 List<PaymentRequestDocument> pReqs = SpringContext.getBean(PaymentRequestService.class).getPaymentRequestsByPurchaseOrderId(poDocId);
386 if (ObjectUtils.isNotNull(pReqs)) {
387 if (pReqs.size() == 0) {
388 valid = false;
389 } else {
390 boolean checkInProcess = true;
391 boolean hasInProcess = false;
392
393 for (PaymentRequestDocument pReq : pReqs) {
394
395 if (pReq.getDocumentHeader().getWorkflowDocument().isException()) {
396 continue;
397 }
398
399
400
401
402 if (StringUtils.equalsIgnoreCase(pReq.getApplicationDocumentStatus(), PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW) && !StringUtils.equalsIgnoreCase(pReq.getDocumentHeader().getWorkflowDocument().getCurrentNodeNames().toString(), PurapConstants.PaymentRequestStatuses.NODE_ACCOUNT_REVIEW)) {
403
404
405 checkInProcess = false;
406 break;
407 }
408 if (!SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(pReq)) {
409 hasInProcess = true;
410 }
411 }
412 if (checkInProcess && hasInProcess) {
413 valid = false;
414 }
415 }
416 }
417
418 return valid;
419 }
420
421
422
423
424
425
426
427
428
429 protected boolean canAmend() {
430 boolean can = SpringContext.getBean(PurchaseOrderService.class).isPurchaseOrderOpenForProcessing(getPurchaseOrderDocument());
431
432
433 if (can) {
434 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPurchaseOrderDocument());
435 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT, GlobalVariables.getUserSession().getPerson());
436 }
437
438 return can;
439 }
440
441
442
443
444
445
446
447
448
449 protected boolean canVoid() {
450 LOG.debug("Inside canVoid method >>>>>>>>>>>>>>>>>");
451
452
453 boolean can = getPurchaseOrderDocument().isPurchaseOrderCurrentIndicator() && !getPurchaseOrderDocument().isPendingActionIndicator();
454
455 if (can) {
456 boolean pendingPrint = PurchaseOrderStatuses.APPDOC_PENDING_PRINT.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
457 boolean open = PurchaseOrderStatuses.APPDOC_OPEN.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
458 boolean errorCxml = PurchaseOrderStatuses.APPDOC_CXML_ERROR.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
459 boolean errorFax = PurchaseOrderStatuses.APPDOC_FAX_ERROR.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
460
461 List<PaymentRequestView> preqViews = getPurchaseOrderDocument().getRelatedViews().getRelatedPaymentRequestViews();
462 List<InvoiceView> invViews = getPurchaseOrderDocument().getRelatedViews().getRelatedInvoiceViews();
463
464 boolean hasPaymentRequest = preqViews != null && preqViews.size() > 0;
465 boolean hasInvoice = invViews != null && invViews.size() > 0;
466
467 can = pendingPrint || (open && !hasPaymentRequest) || (open && !hasInvoice) || errorCxml || errorFax;
468
469 }
470
471
472
473
474
475
476 if (can) {
477 String documentTypeName = OLEConstants.OlePurchaseOrder.POV_DOCUMENT_TYPE;
478 String nameSpaceCode = OLEConstants.OlePurchaseOrder.PO_NAMESPACE;
479 if (LOG.isDebugEnabled()) {
480 LOG.debug("Inside canVoid documentTypeName >>>>>>>>>>>>>>>>>" + documentTypeName);
481 LOG.debug("Inside canVoid nameSpaceCode >>>>>>>>>>>>>>>>>" + nameSpaceCode);
482 }
483 can = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
484 OLEConstants.OlePurchaseOrder.EDIT_VOID_DOCUMENT);
485 if (LOG.isDebugEnabled()) {
486 LOG.debug("Inside canVoid hasPermission >>>>>>>>>>>>>>>>>" + can);
487 }
488
489 }
490 return can;
491 }
492
493
494
495
496
497
498
499
500
501 protected boolean canClose() {
502 LOG.debug("Inside canClose method >>>>>>>>>>>>>>>>>");
503
504
505 boolean can = PurchaseOrderStatuses.APPDOC_OPEN.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
506 can = can && getPurchaseOrderDocument().isPurchaseOrderCurrentIndicator() && !getPurchaseOrderDocument().isPendingActionIndicator();
507 can = can && processPaymentRequestRulesForCanClose(getPurchaseOrderDocument());
508
509
510 if (can) {
511 String documentTypeName = OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_CLOSE;
512 String nameSpaceCode = OLEConstants.CoreModuleNamespaces.SELECT;
513 if (LOG.isDebugEnabled()) {
514 LOG.debug("Inside canClose documentTypeName >>>>>>>>>>>>>>>>>" + documentTypeName);
515 LOG.debug("Inside canClose nameSpaceCode >>>>>>>>>>>>>>>>>" + nameSpaceCode);
516 }
517
518 can = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
519 OLEConstants.OlePaymentRequest.CAN_CLOSE_PO);
520 if (LOG.isDebugEnabled()) {
521 LOG.debug("Inside canClose hasPermission >>>>>>>>>>>>>>>>>" + can);
522 }
523
524 }
525
526 return can;
527 }
528
529
530
531
532
533
534
535 protected boolean canReopen() {
536 LOG.info("Inside canReopen method >>>>>>>>>>>>>>>>>");
537
538
539 boolean can = PurchaseOrderStatuses.APPDOC_CLOSED.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
540 can = can && getPurchaseOrderDocument().isPurchaseOrderCurrentIndicator() && !getPurchaseOrderDocument().isPendingActionIndicator();
541
542
543
544
545
546
547
548 if (can) {
549 String documentTypeName = OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_REOPEN;
550 String nameSpaceCode = OLEConstants.OlePurchaseOrder.PO_NAMESPACE;
551 LOG.info("Inside canReopen documentTypeName >>>>>>>>>>>>>>>>>" + documentTypeName);
552 LOG.info("Inside canReopen nameSpaceCode >>>>>>>>>>>>>>>>>" + nameSpaceCode);
553 can = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
554 OLEConstants.OlePurchaseOrder.EDIT_REOPEN_DOCUMENT);
555 LOG.info("Inside canReopen hasPermission >>>>>>>>>>>>>>>>>" + can);
556
557 }
558
559 return can;
560 }
561
562
563
564
565
566
567
568 protected boolean canHoldPayment() {
569
570 boolean can = PurchaseOrderStatuses.APPDOC_OPEN.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
571 can = can && getPurchaseOrderDocument().isPurchaseOrderCurrentIndicator() && !getPurchaseOrderDocument().isPendingActionIndicator();
572
573
574 if (can) {
575 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPurchaseOrderDocument());
576 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_PAYMENT_HOLD, GlobalVariables.getUserSession().getPerson());
577 }
578
579 return can;
580 }
581
582
583
584
585
586
587
588 protected boolean canRemoveHold() {
589
590 boolean can = PurchaseOrderStatuses.APPDOC_PAYMENT_HOLD.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
591 can = can && getPurchaseOrderDocument().isPurchaseOrderCurrentIndicator() && !getPurchaseOrderDocument().isPendingActionIndicator();
592
593
594 if (can) {
595 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPurchaseOrderDocument());
596 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_REMOVE_HOLD, GlobalVariables.getUserSession().getPerson());
597 }
598
599 return can;
600 }
601
602
603
604
605
606
607
608
609
610 protected boolean canRetransmit() {
611
612 boolean can = PurchaseOrderStatuses.APPDOC_OPEN.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
613 can = can && getPurchaseOrderDocument().isPurchaseOrderCurrentIndicator() && !getPurchaseOrderDocument().isPendingActionIndicator();
614 can = can && getPurchaseOrderDocument().getPurchaseOrderLastTransmitTimestamp() != null;
615 can = can && !PurapConstants.RequisitionSources.B2B.equals(getPurchaseOrderDocument().getRequisitionSourceCode());
616 can = can && !editingMode.containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.DISPLAY_RETRANSMIT_TAB);
617
618 if (!can) {
619 return false;
620 }
621
622
623 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPurchaseOrderDocument());
624 if (getPurchaseOrderDocument().getPurchaseOrderAutomaticIndicator()) {
625
626 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_RETRANSMIT, GlobalVariables.getUserSession().getPerson());
627 } else {
628
629 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER, GlobalVariables.getUserSession().getPerson());
630 }
631
632 return can;
633 }
634
635
636
637
638
639
640
641
642
643 protected boolean canPrintRetransmit() {
644
645 boolean can = getPurchaseOrderDocument().getDocumentHeader().getWorkflowDocument().getDocumentTypeName().equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT);
646 can = can && editingMode.containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.DISPLAY_RETRANSMIT_TAB);
647
648 if (can) {
649
650 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPurchaseOrderDocument());
651 if (getPurchaseOrderDocument().getPurchaseOrderAutomaticIndicator()) {
652
653 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_RETRANSMIT, GlobalVariables.getUserSession().getPerson());
654 } else {
655
656 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER, GlobalVariables.getUserSession().getPerson());
657 }
658 }
659
660 return can;
661 }
662
663
664
665
666
667
668
669
670 protected boolean canSplitPo() {
671 LOG.info("Inside canSplitPo method >>>>>>>>>>>>>>>>>");
672
673
674 boolean can = PurchaseOrderStatuses.APPDOC_IN_PROCESS.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
675 can = can && !getPurchaseOrderDocument().getDocumentHeader().getWorkflowDocument().isEnroute();
676 can = can || PurchaseOrderStatuses.APPDOC_AWAIT_PURCHASING_REVIEW.equals(getPurchaseOrderDocument().getApplicationDocumentStatus());
677
678
679 can = can && !(getPurchaseOrderDocument() instanceof PurchaseOrderSplitDocument);
680
681
682 can = can && !editingMode.containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.SPLITTING_ITEM_SELECTION);
683
684
685 can = can && !getPurchaseOrderDocument().getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B);
686
687
688 if (can) {
689 List<PurApItem> items = getPurchaseOrderDocument().getItems();
690 int itemsBelowTheLine = PurApItemUtils.countBelowTheLineItems(items);
691 can = items.size() - itemsBelowTheLine > 1;
692 }
693
694
695
696
697
698
699
700 if (can) {
701 String documentTypeName = OLEConstants.OlePurchaseOrder.POSP_DOCUMENT_TYPE;
702 String nameSpaceCode = OLEConstants.OlePurchaseOrder.PO_NAMESPACE;
703 HashMap<String, String> permissionDetails = new HashMap<String, String>();
704 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, documentTypeName);
705 LOG.info("Inside canSplitPo documentTypeName >>>>>>>>>>>>>>>>>" + documentTypeName);
706 LOG.info("Inside canSplitPo nameSpaceCode >>>>>>>>>>>>>>>>>" + nameSpaceCode);
707 can = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
708 OLEConstants.OlePurchaseOrder.EDIT_SPLIT_DOCUMENT);
709 LOG.info("Inside canSplitPo hasPermission >>>>>>>>>>>>>>>>>" + can);
710
711 }
712
713 return can;
714 }
715
716
717
718
719
720
721 protected boolean canContinuePoSplit() {
722 LOG.info("Inside canContinuePoSplit method >>>>>>>>>>>>>>>>>");
723
724 boolean can = editingMode.containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.SPLITTING_ITEM_SELECTION);
725
726
727
728
729
730
731
732 if (can) {
733 String documentTypeName = OLEConstants.OlePurchaseOrder.POSP_DOCUMENT_TYPE;
734 String nameSpaceCode = OLEConstants.OlePurchaseOrder.PO_NAMESPACE;
735 LOG.info("Inside canContinuePoSplit documentTypeName >>>>>>>>>>>>>>>>>" + documentTypeName);
736 LOG.info("Inside canContinuePoSplit nameSpaceCode >>>>>>>>>>>>>>>>>" + nameSpaceCode);
737 can = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
738 OLEConstants.OlePurchaseOrder.EDIT_SPLIT_DOCUMENT);
739 LOG.info("Inside canContinuePoSplit hasPermission >>>>>>>>>>>>>>>>>" + can);
740
741 }
742
743 return can;
744 }
745
746 protected boolean canCancel() {
747 String documentTypeName = OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT;
748 String nameSpaceCode = OLEConstants.CoreModuleNamespaces.SELECT;
749
750 boolean can = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
751 OLEConstants.MAPPING_CANCEL);
752 return can;
753 }
754
755
756
757
758
759
760 protected boolean canCreateReceiving() {
761 LOG.info("Inside canCreateReceiving method >>>>>>>>>>>>>>>>>");
762
763
764 boolean can = SpringContext.getBean(ReceivingService.class).canCreateLineItemReceivingDocument(getPurchaseOrderDocument());
765
766
767 if (can) {
768 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(getPurchaseOrderDocument());
769
770 can = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING, GlobalVariables.getUserSession().getPerson());
771
772 }
773
774 return can;
775 }
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800 protected Map<String, ExtraButton> createButtonsMap() {
801 HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>();
802
803
804 ExtraButton retransmitButton = new ExtraButton();
805 retransmitButton.setExtraButtonProperty("methodToCall.retransmitPo");
806 retransmitButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_retransmit.gif");
807 retransmitButton.setExtraButtonAltText("Retransmit");
808
809
810 ExtraButton printingRetransmitButton = new ExtraButton();
811 printingRetransmitButton.setExtraButtonProperty("methodToCall.printingRetransmitPo");
812 printingRetransmitButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_retransmit.gif");
813 printingRetransmitButton.setExtraButtonAltText("PrintingRetransmit");
814
815
816 ExtraButton printingPreviewButton = new ExtraButton();
817 printingPreviewButton.setExtraButtonProperty("methodToCall.printingPreviewPo");
818 printingPreviewButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_previewpf.gif");
819 printingPreviewButton.setExtraButtonAltText("PrintingPreview");
820
821
822 ExtraButton printButton = new ExtraButton();
823 printButton.setExtraButtonProperty("methodToCall.firstTransmitPrintPo");
824 printButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_print.gif");
825 printButton.setExtraButtonAltText("Print");
826
827
828 ExtraButton reopenButton = new ExtraButton();
829 reopenButton.setExtraButtonProperty("methodToCall.reopenPo");
830 reopenButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_openorder.gif");
831 reopenButton.setExtraButtonAltText("Reopen");
832
833
834 ExtraButton closeButton = new ExtraButton();
835 closeButton.setExtraButtonProperty("methodToCall.closePo");
836 closeButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_closeorder.gif");
837 closeButton.setExtraButtonAltText("Close PO");
838
839
840 ExtraButton voidButton = new ExtraButton();
841 voidButton.setExtraButtonProperty("methodToCall.voidPo");
842 voidButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_voidorder.gif");
843 voidButton.setExtraButtonAltText("Void PO");
844
845
846 ExtraButton paymentHoldButton = new ExtraButton();
847 paymentHoldButton.setExtraButtonProperty("methodToCall.paymentHoldPo");
848 paymentHoldButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_paymenthold.gif");
849 paymentHoldButton.setExtraButtonAltText("Payment Hold");
850
851
852 ExtraButton amendButton = new ExtraButton();
853 amendButton.setExtraButtonProperty("methodToCall.amendPo");
854 amendButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_amend.gif");
855 amendButton.setExtraButtonAltText("Amend");
856
857
858 ExtraButton removeHoldButton = new ExtraButton();
859 removeHoldButton.setExtraButtonProperty("methodToCall.removeHoldPo");
860 removeHoldButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_removehold.gif");
861 removeHoldButton.setExtraButtonAltText("Remove Hold");
862
863
864 ExtraButton resendPoCxmlButton = new ExtraButton();
865 resendPoCxmlButton.setExtraButtonProperty("methodToCall.resendPoCxml");
866 resendPoCxmlButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_resendpo.gif");
867 resendPoCxmlButton.setExtraButtonAltText("Resend PO CXML");
868
869
870 ExtraButton receivingButton = new ExtraButton();
871 receivingButton.setExtraButtonProperty("methodToCall.createReceivingLine");
872 receivingButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_receiving.gif");
873 receivingButton.setExtraButtonAltText("Receiving");
874
875
876 ExtraButton splitPoButton = new ExtraButton();
877 splitPoButton.setExtraButtonProperty("methodToCall.splitPo");
878 splitPoButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_splitorder.gif");
879 splitPoButton.setExtraButtonAltText("Split this PO");
880
881
882 ExtraButton continueButton = new ExtraButton();
883 continueButton.setExtraButtonProperty("methodToCall.continuePurchaseOrderSplit");
884 continueButton.setExtraButtonSource("${" + OLEConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_continue.gif");
885 continueButton.setExtraButtonAltText("Continue");
886
887
888 ExtraButton cancelSplitButton = new ExtraButton();
889 cancelSplitButton.setExtraButtonProperty("methodToCall.cancelPurchaseOrderSplit");
890 cancelSplitButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_cancelsplit.gif");
891 cancelSplitButton.setExtraButtonAltText("Cancel Splitting the PO");
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912 ExtraButton cancelButton = new ExtraButton();
913 cancelButton.setExtraButtonProperty("methodToCall.cancel");
914 cancelButton.setExtraButtonSource("${" + OLEConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_cancel.gif");
915 cancelButton.setExtraButtonAltText("Cancel");
916
917 result.put(retransmitButton.getExtraButtonProperty(), retransmitButton);
918 result.put(printingRetransmitButton.getExtraButtonProperty(), printingRetransmitButton);
919 result.put(printingPreviewButton.getExtraButtonProperty(), printingPreviewButton);
920 result.put(printButton.getExtraButtonProperty(), printButton);
921 result.put(reopenButton.getExtraButtonProperty(), reopenButton);
922 result.put(closeButton.getExtraButtonProperty(), closeButton);
923 result.put(voidButton.getExtraButtonProperty(), voidButton);
924 result.put(paymentHoldButton.getExtraButtonProperty(), paymentHoldButton);
925 result.put(amendButton.getExtraButtonProperty(), amendButton);
926 result.put(removeHoldButton.getExtraButtonProperty(), removeHoldButton);
927 result.put(receivingButton.getExtraButtonProperty(), receivingButton);
928 result.put(splitPoButton.getExtraButtonProperty(), splitPoButton);
929 result.put(continueButton.getExtraButtonProperty(), continueButton);
930 result.put(cancelSplitButton.getExtraButtonProperty(), cancelSplitButton);
931
932
933
934 result.put(resendPoCxmlButton.getExtraButtonProperty(), resendPoCxmlButton);
935 result.put(cancelButton.getExtraButtonProperty(), cancelButton);
936
937
938 return result;
939 }
940
941
942
943
944
945
946
947 @Override
948 public List<ExtraButton> getExtraButtons() {
949 super.getExtraButtons();
950 Map buttonsMap = createButtonsMap();
951
952 if (getEditingMode().containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.ASSIGN_SENSITIVE_DATA)) {
953 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.assignSensitiveData"));
954 if (getPurchaseOrderDocument().getAssigningSensitiveData()) {
955
956
957 extraButtons.clear();
958 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.submitSensitiveData"));
959 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.cancelSensitiveData"));
960 return extraButtons;
961 }
962 }
963
964 if (getEditingMode().containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.PREVIEW_PRINT_PURCHASE_ORDER)) {
965
966 LOG.info("Inside PREVIEW_PRINT_PURCHASE_ORDER >>>>>>>>>>>>>>>>>" + PurapAuthorizationConstants.PurchaseOrderEditMode.PREVIEW_PRINT_PURCHASE_ORDER);
967
968 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.printingPreviewPo"));
969 }
970
971 if (getEditingMode().containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.PRINT_PURCHASE_ORDER)) {
972
973 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.firstTransmitPrintPo"));
974 }
975
976 if (getEditingMode().containsKey(PurapAuthorizationConstants.PurchaseOrderEditMode.RESEND_PURCHASE_ORDER)) {
977 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.resendPoCxml"));
978 }
979
980 if (canRetransmit()) {
981 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.retransmitPo"));
982 }
983
984 if (canPrintRetransmit()) {
985 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.printingRetransmitPo"));
986 }
987
988 if (canReopen()) {
989 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.reopenPo"));
990 }
991
992 if (canClose()) {
993 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.closePo"));
994 }
995
996 if (canHoldPayment()) {
997 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.paymentHoldPo"));
998 }
999
1000 if (canAmend()) {
1001 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.amendPo"));
1002 }
1003
1004 if (canVoid()) {
1005 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.voidPo"));
1006 }
1007
1008 if (canRemoveHold()) {
1009 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.removeHoldPo"));
1010 }
1011
1012 if (canCreateReceiving()) {
1013 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.createReceivingLine"));
1014 }
1015
1016 if (canSplitPo()) {
1017 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.splitPo"));
1018 }
1019
1020 if (canContinuePoSplit()) {
1021 extraButtons.clear();
1022 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.continuePurchaseOrderSplit"));
1023 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.cancelPurchaseOrderSplit"));
1024 }
1025
1026 if (canCancel()) {
1027 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.cancel"));
1028 }
1029
1030 return extraButtons;
1031 }
1032
1033 }
1034