1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.web;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.kuali.ole.batch.service.OLEClaimNoticeService;
22 import org.kuali.ole.select.OleSelectConstant;
23 import org.kuali.ole.select.businessobject.OleLineItemReceivingItem;
24 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
25 import org.kuali.ole.select.businessobject.OleReceiptStatus;
26 import org.kuali.ole.select.document.OleLineItemReceivingDocument;
27 import org.kuali.ole.select.document.OleReceivingQueueSearchDocument;
28 import org.kuali.ole.select.document.service.OleLineItemReceivingService;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEKeyConstants;
31 import org.kuali.ole.sys.context.SpringContext;
32 import org.kuali.rice.core.api.config.property.ConfigurationService;
33 import org.kuali.rice.core.api.datetime.DateTimeService;
34 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
35 import org.kuali.rice.core.api.util.RiceConstants;
36 import org.kuali.rice.kew.actionlist.service.ActionListService;
37 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
38 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
39 import org.kuali.rice.kew.api.KewApiConstants;
40 import org.kuali.rice.kew.api.exception.WorkflowException;
41 import org.kuali.rice.kew.service.KEWServiceLocator;
42 import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase;
43 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
44 import org.kuali.rice.krad.document.Document;
45 import org.kuali.rice.krad.service.BusinessObjectService;
46 import org.kuali.rice.krad.service.KRADServiceLocator;
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 javax.servlet.http.HttpServletResponse;
53 import java.sql.Timestamp;
54 import java.text.ParseException;
55 import java.text.SimpleDateFormat;
56 import java.util.*;
57 import java.util.regex.Matcher;
58 import java.util.regex.Pattern;
59
60 public class OleReceivingQueueSearchAction extends KualiTransactionalDocumentActionBase {
61
62 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleReceivingQueueSearchAction.class);
63 protected Document document;
64 private static transient OleLineItemReceivingService oleLineItemReceivingService;
65
66
67
68
69 public OleReceivingQueueSearchAction() {
70 super();
71 }
72
73
74
75
76
77
78
79
80
81
82
83 public ActionForward valueSearch(ActionMapping mapping, ActionForm form,
84 HttpServletRequest request, HttpServletResponse response) throws Exception {
85 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
86 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument();
87 oleReceivingQueueSearchDocument.setReceivingDocumentsList(new ArrayList<String>());
88 String purchaseOrderString = oleReceivingQueueSearchDocument.getPurchaseOrderNumber();
89 String purchaseOrderStatus=oleReceivingQueueSearchDocument.getPurchaseOrderStatusDescription()!=null?oleReceivingQueueSearchDocument.getPurchaseOrderStatusDescription():"";
90 String datePattern = "\\d{2}/\\d{2}/\\d{4}";
91 boolean isValid = true;
92 if ((oleReceivingQueueSearchDocument.getEndDate() != null && !oleReceivingQueueSearchDocument.getEndDate().equalsIgnoreCase(""))) {
93 if (!oleReceivingQueueSearchDocument.getEndDate().matches(datePattern)) {
94 oleReceivingQueueSearchDocument.getPurchaseOrderItems().clear();
95 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_INVALID_DATE, new String[]{"PO To Date"});
96 isValid = false;
97 }
98 try {
99 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
100 sdf.setLenient(false);
101 Date date = sdf.parse(oleReceivingQueueSearchDocument.getEndDate());
102
103 } catch (ParseException e) {
104 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_INVALID_DATE, new String[]{"PO To Date"});
105 isValid = false;
106 }
107 }
108 if ((oleReceivingQueueSearchDocument.getBeginDate() != null && !oleReceivingQueueSearchDocument.getBeginDate().equalsIgnoreCase(""))) {
109 if (!oleReceivingQueueSearchDocument.getBeginDate().matches(datePattern)) {
110 oleReceivingQueueSearchDocument.getPurchaseOrderItems().clear();
111 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_INVALID_DATE, new String[]{"PO From Date"});
112 isValid = false;
113 }
114 try {
115 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
116 sdf.setLenient(false);
117 Date date = sdf.parse(oleReceivingQueueSearchDocument.getBeginDate());
118 } catch (ParseException e) {
119 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_INVALID_DATE, new String[]{"PO From Date"});
120 isValid = false;
121 }
122 }
123 if (!isValid) {
124 return mapping.findForward(RiceConstants.MAPPING_BASIC);
125 }
126 if (purchaseOrderString != null) {
127 boolean isValidSting = true;
128 String[] purchaseOrderNumbers = purchaseOrderString.split(",");
129 for (String purchaseOrderNumber : purchaseOrderNumbers) {
130 if (!validate(purchaseOrderNumber)) {
131 isValidSting = false;
132 break;
133 }
134 }
135 if (!isValidSting) {
136 oleReceivingQueueSearchDocument.getPurchaseOrderItems().clear();
137 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_PO_ITM_FORMAT);
138 return mapping.findForward(RiceConstants.MAPPING_BASIC);
139 }
140 }
141 if(purchaseOrderStatus.equalsIgnoreCase(OleSelectConstant.CLOSED)){
142 oleReceivingQueueSearchDocument.getPurchaseOrderItems().clear();
143 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
144 OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_CLOSED);
145
146
147 }else{
148
149 oleReceivingQueueSearchDocument.receiveingQueueRecordSearchs();
150 }
151
152 return mapping.findForward(RiceConstants.MAPPING_BASIC);
153 }
154
155 public boolean validate(final String hex) {
156 Pattern pattern = Pattern.compile("[0-9]+");
157 Matcher matcher = pattern.matcher(hex);
158 return matcher.matches();
159
160 }
161
162 @Override
163 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
164 ActionForward actionForward = null;
165 if(((OleReceivingQueueSearchForm) form).getMethodToCall() != null) {
166 if(((OleReceivingQueueSearchForm) form).getMethodToCall().equalsIgnoreCase("docHandler")){
167 ((OleReceivingQueueSearchForm) form).setDocId(null);
168 }
169 }
170 return super.execute(mapping, form, request, response);
171 }
172
173
174
175
176
177
178
179
180
181
182
183 public ActionForward valueClear(ActionMapping mapping, ActionForm form,
184 HttpServletRequest request, HttpServletResponse response) throws Exception {
185 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
186 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument();
187 oleReceivingQueueSearchDocument.setPurchaseOrderItems(null);
188 oleReceivingQueueSearchDocument.setPurchaseOrderNumber(null);
189 oleReceivingQueueSearchDocument.setVendorName(null);
190
191
192 oleReceivingQueueSearchDocument.setPurchaseOrderStatusDescription(null);
193 oleReceivingQueueSearchDocument.setMonograph(false);
194 oleReceivingQueueSearchDocument.setPurchaseOrderType(null);
195 oleReceivingQueueSearchDocument.setBeginDate(null);
196 oleReceivingQueueSearchDocument.setEndDate(null);
197 oleReceivingQueueSearchDocument.setStandardNumber(null);
198 oleReceivingQueueSearchDocument.setTitle(null);
199 oleReceivingQueueSearchDocument.setClaimFilter(false);
200 oleReceivingQueueSearchDocument.setReceivingDocumentsList(new ArrayList<String>());
201
202
203 return mapping.findForward(RiceConstants.MAPPING_BASIC);
204 }
205
206
207
208
209
210
211
212 public Document getDocument() {
213 return document;
214 }
215
216
217
218
219
220
221 public void setDocument(Document document) {
222 this.document = document;
223 }
224
225
226
227
228
229
230
231
232
233
234
235 public ActionForward selectAll(ActionMapping mapping, ActionForm form,
236 HttpServletRequest request, HttpServletResponse response) throws Exception {
237 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
238 List<OlePurchaseOrderItem> items = ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument()).getPurchaseOrderItems();
239 List<OlePurchaseOrderItem> refreshItems = new ArrayList<OlePurchaseOrderItem>(0);
240
241 for (OlePurchaseOrderItem item : items) {
242 if(item.isClaimFilter()){
243 item.setClaimPoAdded(true);
244 }
245 item.setPoAdded(true);
246 refreshItems.add(item);
247 }
248
249 ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument()).setPurchaseOrderItems(refreshItems);
250
251 return mapping.findForward(RiceConstants.MAPPING_BASIC);
252 }
253
254
255
256
257
258
259
260
261
262
263
264 public ActionForward unselectAll(ActionMapping mapping, ActionForm form,
265 HttpServletRequest request, HttpServletResponse response) throws Exception {
266 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
267 List<OlePurchaseOrderItem> items = ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument()).getPurchaseOrderItems();
268 List<OlePurchaseOrderItem> refreshItems = new ArrayList<OlePurchaseOrderItem>(0);
269
270 for (OlePurchaseOrderItem item : items) {
271 if(item.isClaimFilter()){
272 item.setClaimPoAdded(false);
273 }
274 item.setPoAdded(false);
275 refreshItems.add(item);
276 }
277
278 ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument()).setPurchaseOrderItems(refreshItems);
279
280 return mapping.findForward(RiceConstants.MAPPING_BASIC);
281 }
282
283
284
285
286
287
288
289 protected OleLineItemReceivingDocument createLineItemReceivingDocument() throws WorkflowException {
290 Document doc = getDocumentService().getNewDocument("OLE_RCVL");
291 return (OleLineItemReceivingDocument) doc;
292 }
293
294
295
296
297
298
299
300
301
302
303
304 public ActionForward completeReceiving(ActionMapping mapping, ActionForm form,
305 HttpServletRequest request, HttpServletResponse response) throws Exception {
306 LOG.debug("Inside completeReceiving of OleReceivingQueueSearchDocument");
307 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
308 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument();
309 OleLineItemReceivingDocument rlDoc = null;
310
311 List<OlePurchaseOrderItem> olePurchaseOrderItems = new ArrayList<OlePurchaseOrderItem>();
312 HashMap<Integer, OlePurchaseOrderItem> selectedPOs = getSelectedPurchaseOrders(oleReceivingQueueSearchDocument.getPurchaseOrderItems());
313 if (selectedPOs.size() == 0) {
314 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_PO_ITM);
315 return mapping.findForward(RiceConstants.MAPPING_BASIC);
316 }
317 boolean isReceivingExist = false;
318 List<String> errorCreatingReceivingForPoIdList = new ArrayList<String>();
319 for (OlePurchaseOrderItem olePurchaseOrderItem : oleReceivingQueueSearchDocument.getPurchaseOrderItems()) {
320 if (olePurchaseOrderItem.isPoAdded()) {
321
322 if (validateReceivingForProcess(olePurchaseOrderItem)) {
323 isReceivingExist = true;
324 olePurchaseOrderItem.setPoAdded(false);
325 if (!errorCreatingReceivingForPoIdList.contains(olePurchaseOrderItem.getPurchaseOrder().getPurapDocumentIdentifier().toString())) {
326 errorCreatingReceivingForPoIdList.add(olePurchaseOrderItem.getPurchaseOrder().getPurapDocumentIdentifier().toString());
327 }
328 }
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354 }
355 }
356 selectedPOs = getSelectedPurchaseOrders(oleReceivingQueueSearchDocument.getPurchaseOrderItems());
357
358 HashMap<Integer, Boolean> receivePOStatus = new HashMap<Integer, Boolean>();
359 oleReceivingQueueSearchDocument.getReceivingDocumentsList().clear();
360 boolean isInfoMsg = false;
361 for (Map.Entry<Integer, OlePurchaseOrderItem> entry : selectedPOs.entrySet()) {
362 if (LOG.isDebugEnabled()) {
363 LOG.debug("Creating Line Item Receiving Document for PO ID - " + entry.getKey());
364 }
365 rlDoc = createLineItemReceivingDocument();
366 boolean receivePOSuccess = oleReceivingQueueSearchDocument.receivePO(rlDoc, entry.getKey(), false);
367 if (receivePOSuccess) {
368 oleReceivingQueueSearchDocument.getReceivingDocumentsList().add(rlDoc.getDocumentNumber());
369
370 isInfoMsg = true;
371 }
372 receivePOStatus.put(entry.getKey(), receivePOSuccess);
373 if (LOG.isDebugEnabled()) {
374 LOG.debug("Creating Line Item Receiving Document for PO ID - " + entry.getKey() + " completed successfully");
375 }
376 }
377 List<OlePurchaseOrderItem> refreshedPOList = new ArrayList<OlePurchaseOrderItem>();
378 for (OlePurchaseOrderItem poItem : oleReceivingQueueSearchDocument.getPurchaseOrderItems()) {
379 Integer poId = poItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier();
380 refreshedPOList.add(poItem);
381
382
383
384
385
386
387
388 }
389
390 ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument()).setPurchaseOrderItems(refreshedPOList);
391
392 LOG.debug("Leaving completeReceiving of OleReceivingQueueSearchDocument");
393 String errorCreatingReceivingForPoIds = "";
394 for (String string : errorCreatingReceivingForPoIdList) {
395 errorCreatingReceivingForPoIds = errorCreatingReceivingForPoIds + string + ",";
396 }
397 if (isReceivingExist) {
398 errorCreatingReceivingForPoIds = errorCreatingReceivingForPoIds.substring(0, errorCreatingReceivingForPoIds.length() - 1);
399 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_RECEIVING_EXIST, errorCreatingReceivingForPoIds);
400 }
401
402 return unselectAll(mapping, oleReceivingQueueSearchForm, request, response);
403 }
404
405
406 public ActionForward claiming(ActionMapping mapping, ActionForm form,
407 HttpServletRequest request, HttpServletResponse response) throws Exception {
408 LOG.debug("Inside completeReceiving of OleReceivingQueueSearchDocument");
409 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
410 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument();
411
412 List<OlePurchaseOrderItem> olePurchaseOrderItems = new ArrayList<OlePurchaseOrderItem>();
413 for (OlePurchaseOrderItem poItem : oleReceivingQueueSearchDocument.getPurchaseOrderItems()) {
414 if (poItem.isPoAdded()) {
415 olePurchaseOrderItems.add(poItem);
416 }
417 }
418 if (olePurchaseOrderItems.size() == 0) {
419 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_PO_ITM);
420 return mapping.findForward(RiceConstants.MAPPING_BASIC);
421 }
422 OLEClaimNoticeService oleClaimNoticeService = GlobalResourceLoader.getService("oleClaimNoticeService");
423 oleClaimNoticeService.generateClaimReportFromPO(olePurchaseOrderItems,false);
424 return unselectAll(mapping, oleReceivingQueueSearchForm, request, response);
425 }
426
427
428
429
430
431
432
433
434
435
436
437
438 public ActionForward createReceiving(ActionMapping mapping, ActionForm form, HttpServletRequest request,
439 HttpServletResponse response) throws Exception {
440 LOG.debug("Inside completereceiving of OleReceivingQueueSearchDocument");
441 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
442 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm
443 .getDocument();
444 OleLineItemReceivingDocument rlDoc = null;
445 HashMap<Integer, OlePurchaseOrderItem> selectedPOs = getSelectedPurchaseOrders(oleReceivingQueueSearchDocument
446 .getPurchaseOrderItems());
447 List<OlePurchaseOrderItem> olePurchaseOrderItems = new ArrayList<OlePurchaseOrderItem>();
448 if (selectedPOs.size() == 0) {
449 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECT_PO_ITM);
450 return mapping.findForward(RiceConstants.MAPPING_BASIC);
451 }
452 boolean isReceivingExist = false;
453 List<String> errorCreatingReceivingForPoIdList = new ArrayList<String>();
454 for (OlePurchaseOrderItem olePurchaseOrderItem : oleReceivingQueueSearchDocument.getPurchaseOrderItems()) {
455 if (olePurchaseOrderItem.isPoAdded()) {
456 if (validateReceivingForProcess(olePurchaseOrderItem)) {
457 isReceivingExist = true;
458 olePurchaseOrderItem.setPoAdded(false);
459 if (!errorCreatingReceivingForPoIdList.contains(olePurchaseOrderItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier().toString())) {
460 errorCreatingReceivingForPoIdList.add(olePurchaseOrderItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier().toString());
461 }
462 }
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485 }
486 }
487 selectedPOs = getSelectedPurchaseOrders(oleReceivingQueueSearchDocument.getPurchaseOrderItems());
488
489 HashMap<Integer, Boolean> receivePOStatus = new HashMap<Integer, Boolean>();
490 boolean isInfoMsg = false;
491 for (Map.Entry<Integer, OlePurchaseOrderItem> entry : selectedPOs.entrySet()) {
492 if (LOG.isDebugEnabled()) {
493 LOG.debug("Creating Line Item Receiving Document for PO ID - " + entry.getKey());
494 }
495 rlDoc = createLineItemReceivingDocument();
496 getOleLineItemReceivingService().getInitialCollapseSections(rlDoc);
497 boolean receivePOSuccess = oleReceivingQueueSearchDocument.receivePO(rlDoc, entry.getKey(), true);
498 if (receivePOSuccess) {
499 oleReceivingQueueSearchDocument.getReceivingDocumentsList().add(rlDoc.getDocumentNumber());
500 isInfoMsg = true;
501 }
502 receivePOStatus.put(entry.getKey(), receivePOSuccess);
503 if (LOG.isDebugEnabled()) {
504 LOG.debug("Creating Line Item Receiving Document for PO ID - " + entry.getKey()
505 + " completed successfully");
506 }
507 }
508 List<OlePurchaseOrderItem> refreshedPOList = new ArrayList<OlePurchaseOrderItem>();
509 for (OlePurchaseOrderItem poItem : oleReceivingQueueSearchDocument.getPurchaseOrderItems()) {
510 Integer poId = poItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier();
511 refreshedPOList.add(poItem);
512
513
514
515
516
517
518
519
520 }
521 if (oleReceivingQueueSearchDocument.getReceivingDocumentsList().size() == 1) {
522 ActionForward dest = returnToReceiving(oleReceivingQueueSearchDocument.getReceivingDocumentsList().get(0));
523 return dest;
524 }
525 ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument())
526 .setPurchaseOrderItems(refreshedPOList);
527
528 LOG.debug("Leaving completeReceiving of OleReceivingQueueSearchDocument");
529 String errorCreatingReceivingForPoIds = "";
530 for (String string : errorCreatingReceivingForPoIdList) {
531 errorCreatingReceivingForPoIds = errorCreatingReceivingForPoIds + string + ",";
532 }
533 if (isReceivingExist) {
534 errorCreatingReceivingForPoIds = errorCreatingReceivingForPoIds.substring(0, errorCreatingReceivingForPoIds.length() - 1);
535 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_RECEIVING_EXIST, errorCreatingReceivingForPoIds);
536 }
537
538 return mapping.findForward(RiceConstants.MAPPING_BASIC);
539 }
540
541
542
543
544
545
546
547
548 private HashMap<Integer, OlePurchaseOrderItem> getSelectedPurchaseOrders(List<OlePurchaseOrderItem> purchaseOrders) {
549 LOG.debug("Inside getSelectedPurchaseOrders of OleReceivingQueueSearchDocument");
550 HashMap<Integer, OlePurchaseOrderItem> poItemMap = new HashMap<Integer, OlePurchaseOrderItem>();
551 for (OlePurchaseOrderItem poItem : purchaseOrders) {
552 if (poItem.isPoAdded()) {
553 if (ObjectUtils.isNull(poItemMap.get(poItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier()))) {
554 poItemMap.put(poItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier(), poItem);
555 }
556 }
557 }
558 if (LOG.isDebugEnabled()) {
559 LOG.debug("Number of actual PO selected in OleReceivingQueueSearchDocument.getSelectedPurchaseOrders - " + poItemMap.size());
560 LOG.debug("Leaving getSelectedPurchaseOrders of OleReceivingQueueSearchDocument");
561 }
562
563 return poItemMap;
564 }
565
566
567
568
569
570 @Override
571 public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
572 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
573 return returnToSender(request, mapping, kualiDocumentFormBase);
574 }
575
576
577
578
579
580
581
582
583 private ActionForward returnToReceiving(String rcvDocId) {
584 String receivingUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
585 OLEConstants.WORKFLOW_URL_KEY)
586 + "/DocHandler.do?docId=" + rcvDocId + "&command=displayDocSearchView";
587 return new ActionForward(receivingUrl, true);
588 }
589
590
591
592
593
594
595
596
597
598 private ActionForward returnToPayment(String purchaseOrderId) {
599 String paymentUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
600 OLEConstants.WORKFLOW_URL_KEY)
601 + "/selectOlePaymentRequest.do?purchaseOrderIdentifier=" + purchaseOrderId
602 + "&methodToCall=docHandler&command=initiate&docTypeName=OLE_PREQ";
603 return new ActionForward(paymentUrl, true);
604 }
605
606
607
608
609
610
611
612
613
614
615
616 public ActionForward createPaymentRequestDocument(ActionMapping mapping, ActionForm form,
617 HttpServletRequest request, HttpServletResponse response) throws Exception {
618
619 return mapping.findForward(RiceConstants.MAPPING_BASIC);
620 }
621
622
623
624
625
626
627
628
629
630
631
632 public ActionForward receiveAndPay(ActionMapping mapping, ActionForm form, HttpServletRequest request,
633 HttpServletResponse response) throws Exception {
634 LOG.debug("Inside receiveAndPay of OleReceivingQueueSearchDocument");
635 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) form;
636 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument();
637 OleLineItemReceivingDocument rlDoc = null;
638
639 HashMap<Integer, OlePurchaseOrderItem> selectedPOs = getSelectedPurchaseOrders(oleReceivingQueueSearchDocument.getPurchaseOrderItems());
640
641 HashMap<Integer, Boolean> receivePOStatus = new HashMap<Integer, Boolean>();
642 boolean isInfoMsg = false;
643 for (Map.Entry<Integer, OlePurchaseOrderItem> entry : selectedPOs.entrySet()) {
644 if (LOG.isDebugEnabled()) {
645 LOG.debug("Creating Line Item Receiving Document for PO ID - " + entry.getKey());
646 }
647 rlDoc = createLineItemReceivingDocument();
648 boolean receivePOSuccess = oleReceivingQueueSearchDocument.receivePO(rlDoc, entry.getKey(), false);
649 if (receivePOSuccess) {
650 oleReceivingQueueSearchDocument.getReceivingDocumentsList().add(rlDoc.getDocumentNumber());
651
652 isInfoMsg = true;
653 }
654 receivePOStatus.put(entry.getKey(), receivePOSuccess);
655 if (LOG.isDebugEnabled()) {
656 LOG.debug("Creating Line Item Receiving Document for PO ID - " + entry.getKey() + " completed successfully");
657 }
658 }
659 List<OlePurchaseOrderItem> refreshedPOList = new ArrayList<OlePurchaseOrderItem>();
660 for (OlePurchaseOrderItem poItem : oleReceivingQueueSearchDocument.getPurchaseOrderItems()) {
661 Integer poId = poItem.getOlePurchaseOrderDocument().getPurapDocumentIdentifier();
662 if (ObjectUtils.isNull(receivePOStatus.get(poId))) {
663 refreshedPOList.add(poItem);
664 } else {
665 if (receivePOStatus.get(poId) == false) {
666 refreshedPOList.add(poItem);
667 }
668 }
669 }
670
671 ((OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm.getDocument()).setPurchaseOrderItems(refreshedPOList);
672
673 LOG.debug("Leaving receiveAndPay of OleReceivingQueueSearchDocument");
674
675 return mapping.findForward(RiceConstants.MAPPING_BASIC);
676 }
677
678 @Override
679 protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
680 super.loadDocument(kualiDocumentFormBase);
681 OleReceivingQueueSearchForm oleReceivingQueueSearchForm = (OleReceivingQueueSearchForm) kualiDocumentFormBase;
682 OleReceivingQueueSearchDocument oleReceivingQueueSearchDocument = (OleReceivingQueueSearchDocument) oleReceivingQueueSearchForm
683 .getDocument();
684 oleReceivingQueueSearchDocument.setReceivingDocumentsList(new ArrayList<String>());
685 }
686
687
688
689
690 private void assignActionRequests(String routeHeaderId) {
691 LOG.debug("Inside assignActionRequests of OleOrderQueueDocument");
692 Timestamp currentTime = SpringContext.getBean(DateTimeService.class).getCurrentTimestamp();
693 ActionListService actionListSrv = KEWServiceLocator.getActionListService();
694 ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
695 ActionRequestValue actionRequest = new ActionRequestValue();
696 actionRequest.setActionRequested(KewApiConstants.ACTION_REQUEST_FYI_REQ);
697 actionRequest.setPrincipalId("OLE10003");
698 actionRequest.setCreateDate(currentTime);
699 actionRequest.setForceAction(true);
700 actionReqSrv.saveActionRequest(actionRequest);
701
702
703
704
705
706
707
708
709
710 LOG.debug("Leaving assignActionRequests of OleOrderQueueDocument");
711 }
712
713 public boolean validateReceivingForProcess(OlePurchaseOrderItem purchaseOrderItem) {
714 boolean isValid = false;
715 Map<String, String> map = new HashMap<String, String>();
716 map.put("purchaseOrderIdentifier", purchaseOrderItem.getItemIdentifier().toString());
717 List<OleLineItemReceivingItem> oleLineItemReceivingItems = (List<OleLineItemReceivingItem>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLineItemReceivingItem.class, map);
718
719 if (oleLineItemReceivingItems.size() > 0) {
720 OleLineItemReceivingItem oleLineItemReceivingItem = oleLineItemReceivingItems.get(0);
721 if (oleLineItemReceivingItem.getReceiptStatusId() != null) {
722 if (oleLineItemReceivingItem.getReceiptStatusId().toString().equalsIgnoreCase(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED) + "")) {
723 isValid = true;
724 }
725 }
726 }
727 return isValid;
728 }
729
730 public int getReceiptStatusDetails(String receiptStatusCd) {
731 int receiptStatusId = 0;
732 Map<String, String> receiptStatusCdMap = new HashMap<String, String>();
733 receiptStatusCdMap.put(OLEConstants.RCPT_STATUS_CD, receiptStatusCd);
734 List<OleReceiptStatus> oleReceiptStatusList = (List) SpringContext.getBean(BusinessObjectService.class)
735 .findMatching(OleReceiptStatus.class, receiptStatusCdMap);
736 for (OleReceiptStatus oleReceiptStatus : oleReceiptStatusList) {
737 receiptStatusId = oleReceiptStatus.getReceiptStatusId().intValue();
738 }
739 return receiptStatusId;
740 }
741
742 public static OleLineItemReceivingService getOleLineItemReceivingService() {
743 if (oleLineItemReceivingService == null) {
744 oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingService.class);
745 }
746 return oleLineItemReceivingService;
747 }
748
749 }