1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.ole.docstore.common.client.*;
21 import org.kuali.ole.docstore.common.client.impl.DocstoreClientLocatorServiceImpl;
22 import org.kuali.ole.docstore.common.document.Bib;
23 import org.kuali.ole.docstore.common.document.BibMarc;
24 import org.kuali.ole.DocumentUniqueIDPrefix;
25 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
26 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
27 import org.kuali.ole.docstore.model.bo.WorkItemDocument;
28 import org.kuali.ole.docstore.model.enums.DocType;
29 import org.kuali.ole.gl.service.SufficientFundsService;
30 import org.kuali.ole.module.purap.PurapWorkflowConstants;
31 import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
32 import org.kuali.ole.module.purap.document.PurchaseOrderAmendmentDocument;
33 import org.kuali.ole.module.purap.document.RequisitionDocument;
34 import org.kuali.ole.module.purap.document.service.OlePurapService;
35 import org.kuali.ole.module.purap.service.PurapAccountingService;
36 import org.kuali.ole.select.OleSelectConstant;
37 import org.kuali.ole.select.businessobject.*;
38 import org.kuali.ole.select.document.service.*;
39 import org.kuali.ole.sys.OLEConstants;
40 import org.kuali.ole.sys.OLEPropertyConstants;
41 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
42 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
43 import org.kuali.ole.sys.businessobject.SufficientFundsItem;
44 import org.kuali.ole.sys.context.SpringContext;
45 import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
46 import org.kuali.ole.sys.service.UniversityDateService;
47 import org.kuali.ole.vnd.businessobject.VendorAlias;
48 import org.kuali.rice.core.api.util.type.KualiDecimal;
49 import org.kuali.rice.core.api.util.type.KualiInteger;
50 import org.kuali.rice.kew.api.action.RoutingReportCriteria;
51 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
52 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
53 import org.kuali.rice.krad.bo.Note;
54 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
55 import org.kuali.rice.krad.service.BusinessObjectService;
56 import org.kuali.rice.krad.service.DocumentService;
57
58 import java.math.BigDecimal;
59 import java.util.*;
60
61 public class OlePurchaseOrderAmendmentDocument extends PurchaseOrderAmendmentDocument {
62 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderAmendmentDocument.class);
63
64 private String vendorPoNumber;
65 private static transient OlePatronRecordHandler olePatronRecordHandler;
66 private static transient OlePatronDocumentList olePatronDocumentList;
67 private static transient OleSelectDocumentService oleSelectDocumentService;
68 private static transient OlePurapService olePurapService;
69 private static transient OleCopyHelperService oleCopyHelperService;
70 private String vendorAliasName;
71 private DocstoreClientLocator docstoreClientLocator;
72
73 public DocstoreClientLocator getDocstoreClientLocator() {
74 if (docstoreClientLocator == null) {
75 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
76 }
77 return docstoreClientLocator;
78 }
79
80 public static OleSelectDocumentService getOleSelectDocumentService() {
81 if (oleSelectDocumentService == null) {
82 oleSelectDocumentService = SpringContext.getBean(OleSelectDocumentService.class);
83 }
84 return oleSelectDocumentService;
85 }
86
87 public static void setOleSelectDocumentService(OleSelectDocumentService oleSelectDocumentService) {
88 OlePurchaseOrderAmendmentDocument.oleSelectDocumentService = oleSelectDocumentService;
89 }
90
91 public static OlePatronDocumentList getOlePatronDocumentList() {
92 if (olePatronDocumentList == null) {
93 olePatronDocumentList = SpringContext.getBean(OlePatronDocumentList.class);
94 }
95 return olePatronDocumentList;
96 }
97
98 public static void setOlePatronDocumentList(OlePatronDocumentList olePatronDocumentList) {
99 OlePurchaseOrderAmendmentDocument.olePatronDocumentList = olePatronDocumentList;
100 }
101
102
103 public OlePatronRecordHandler getOlePatronRecordHandler() {
104 if (null == olePatronRecordHandler) {
105 olePatronRecordHandler = new OlePatronRecordHandler();
106 }
107 return olePatronRecordHandler;
108 }
109
110 public void setOlePatronRecordHandler(OlePatronRecordHandler olePatronRecordHandler) {
111 this.olePatronRecordHandler = olePatronRecordHandler;
112 }
113
114 public String getVendorAliasName() {
115 return vendorAliasName;
116 }
117
118 public void setVendorAliasName(String vendorAliasName) {
119 this.vendorAliasName = vendorAliasName;
120 }
121
122 public static OlePurapService getOlePurapService() {
123 if (olePurapService == null) {
124 olePurapService = SpringContext.getBean(OlePurapService.class);
125 }
126 return olePurapService;
127 }
128
129 public static void setOlePurapService(OlePurapService olePurapService) {
130 OlePurchaseOrderAmendmentDocument.olePurapService = olePurapService;
131 }
132
133 public static OleCopyHelperService getOleCopyHelperService() {
134 if(oleCopyHelperService == null){
135 oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
136 }
137 return oleCopyHelperService;
138 }
139
140 public static void setOleCopyHelperService(OleCopyHelperService oleCopyHelperService) {
141 OlePurchaseOrderAmendmentDocument.oleCopyHelperService = oleCopyHelperService;
142 }
143
144 @Override
145 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
146 super.doRouteStatusChange(statusChangeEvent);
147 if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
148 SpringContext.getBean(OlePurchaseOrderService.class).setStatusCompletePurchaseOrderAmendment(this);
149 }
150 }
151
152
153
154
155
156
157 @Override
158 public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
159
160 LOG.debug("Inside populatePurchaseOrderFromRequisition of OlePurchaseOrderAmendmentDocument");
161 SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
162
163
164 }
165
166
167
168
169
170
171 @Override
172 public void prepareForSave(KualiDocumentEvent event) {
173
174 LOG.debug("Inside prepareForSave of OlePurchaseOrderAmendmentDocument");
175
176 OleDocstoreHelperService oleDocstoreHelperService = SpringContext
177 .getBean(OleDocstoreHelperService.class);
178 List<OlePurchaseOrderItem> purItem = this.getItems();
179 for (int i = 0; purItem.size() > i; i++) {
180 OlePurchaseOrderItem item = (OlePurchaseOrderItem) this.getItem(i);
181 if (item.isItemLocationChangeFlag()) {
182 oleDocstoreHelperService.updateItemLocation(this, item);
183 }
184 }
185 SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
186 super.prepareForSave(event);
187 }
188
189
190
191
192
193
194 @Override
195 public void processAfterRetrieve() {
196 LOG.debug("Inside processAfterRetrieve of OlePurchaseOrderAmendmentDocument");
197 if (this.getVendorAliasName() == null) {
198 populateVendorAliasName();
199 }
200 try {
201 PurchaseOrderType purchaseOrderTypeDoc = getOlePurapService().getPurchaseOrderType(this.getPurchaseOrderTypeId());
202 if(purchaseOrderTypeDoc != null){
203 this.setOrderType(purchaseOrderTypeDoc);
204 }
205 } catch (Exception e) {
206 LOG.error("Error in OlePurchaseOrderDocument:processAfterRetrieve for OleRequisitionItem " + e.getMessage());
207 throw new RuntimeException(e);
208 }
209 try {
210 List<OlePurchaseOrderItem> items = this.getItems();
211 Iterator iterator = items.iterator();
212 while (iterator.hasNext()) {
213 Object object = iterator.next();
214 if (object instanceof OlePurchaseOrderItem) {
215 OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) object;
216 setItemDetailWhileProcessAfterRetrive(singleItem);
217 }
218 }
219 } catch (Exception e) {
220 LOG.error("Exception in OlePurchaseOrderDocument:processAfterRetrieve for OlePurchaseOrderItem " + e.getMessage());
221 throw new RuntimeException(e);
222 }
223 }
224
225
226
227
228
229 private void setItemDetailWhileProcessAfterRetrive(OlePurchaseOrderItem olePurchaseOrderItem)throws Exception{
230 if (olePurchaseOrderItem.getRequestorId() != null) {
231 olePurchaseOrderItem.setRequestorFirstName(getOlePurapService().getPatronName(olePurchaseOrderItem.getRequestorId()));
232 }
233 olePurchaseOrderItem.setPreviousItemQuantity(olePurchaseOrderItem.getItemQuantity());
234 olePurchaseOrderItem.setPreviousItemNoOfParts(olePurchaseOrderItem.getItemNoOfParts());
235
236 if (olePurchaseOrderItem.getBibInfoBean() == null) {
237 olePurchaseOrderItem.setBibInfoBean(new BibInfoBean());
238 }
239 if ((!StringUtils.isEmpty(olePurchaseOrderItem.getInternalRequestorId()) || !StringUtils.isEmpty(olePurchaseOrderItem
240 .getRequestorId())) && olePurchaseOrderItem.getBibInfoBean().getRequestorType() == null) {
241 String requestorType = OleSelectConstant.REQUESTOR_TYPE_STAFF;
242 Map<String, Object> criteria = new HashMap<String, Object>();
243 criteria.put(OleSelectConstant.REQUESTOR_TYPE, requestorType);
244 Collection<OleRequestorType> requestorTypeList = SpringContext.getBean(BusinessObjectService.class).findMatching(OleRequestorType.class, criteria);
245 LOG.debug("###########inside prepareForSave getting requestor type###########");
246 olePurchaseOrderItem.setRequestorTypeId(requestorTypeList.iterator().next().getRequestorTypeId());
247 }
248 if(olePurchaseOrderItem.getItemUnitPrice()!=null){
249 olePurchaseOrderItem.setItemUnitPrice(olePurchaseOrderItem.getItemUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP));
250 }
251 if (olePurchaseOrderItem.getItemTitleId() != null) {
252 LOG.debug("###########inside processAfterRetrieve OlePurchaseOrderAmendmentDocument ###########");
253 Bib bib = new BibMarc();
254 if (olePurchaseOrderItem.getItemTitleId() != null && olePurchaseOrderItem.getItemTitleId() != "") {
255 bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(olePurchaseOrderItem.getItemTitleId());
256 olePurchaseOrderItem.setBibUUID(bib.getId());
257 }
258 olePurchaseOrderItem.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(olePurchaseOrderItem.getItemTitleId()));
259 olePurchaseOrderItem.setBibInfoBean(new BibInfoBean());
260 olePurchaseOrderItem.setItemDescription(getOlePurapService().getItemDescription(bib));
261 }
262 if (olePurchaseOrderItem.getItemType() != null && olePurchaseOrderItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
263 populateCopiesSection(olePurchaseOrderItem);
264 }
265 if(olePurchaseOrderItem.getCopyList().size() > 0 && olePurchaseOrderItem.getItemTitleId()!=null) {
266
267 getOlePurapService().setInvoiceDocumentsForPO(this,olePurchaseOrderItem);
268 }
269 }
270
271
272
273
274
275 private void populateCopiesSection(OlePurchaseOrderItem singleItem) {
276 if (singleItem.getCopies().size() > 0) {
277 List<OleCopy> copyList = getOleCopyHelperService().setCopyValuesForList(singleItem.getCopies(), singleItem.getItemTitleId(), null, null);
278 if (copyList.size() >= singleItem.getCopyList().size()) {
279 int copyCount = 0;
280 for (OleCopy oleCopy : singleItem.getCopyList()) {
281 OleCopy copy = copyList.get(copyCount);
282 oleCopy.setLocation(copy.getLocation());
283 oleCopy.setEnumeration(copy.getEnumeration());
284 oleCopy.setCopyNumber(copy.getCopyNumber());
285 oleCopy.setPartNumber(copy.getPartNumber());
286 copyCount++;
287 }
288 for(int i = copyCount ; i<copyList.size() ; i++){
289 singleItem.getCopyList().add(copyList.get(copyCount));
290 copyCount++;
291 }
292 }
293 }
294 else {
295 if (singleItem.getItemQuantity() != null && singleItem.getItemNoOfParts() != null && (singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
296 || singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
297 singleItem.setCopies(getOleCopyHelperService().setCopiesToLineItem(singleItem.getCopyList(), singleItem.getItemNoOfParts(), singleItem.getItemTitleId()));
298 }
299 }
300 if (singleItem.getItemQuantity() != null && singleItem.getItemNoOfParts() != null && !singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
301 && !singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))&&singleItem.getCopyList().size()>0) {
302 singleItem.setSingleCopyNumber(singleItem.getCopyList().get(0).getCopyNumber());
303 }
304 }
305
306
307
308
309
310
311
312
313
314
315 public List<OleCopies> setCopiesToLineItem(OlePurchaseOrderItem singleItem, WorkBibDocument workBibDocument) {
316 List<WorkInstanceDocument> instanceDocuments = workBibDocument.getWorkInstanceDocumentList();
317 List<OleCopies> copies = new ArrayList<OleCopies>();
318 for (WorkInstanceDocument workInstanceDocument : instanceDocuments) {
319 List<WorkItemDocument> itemDocuments = workInstanceDocument.getItemDocumentList();
320 StringBuffer enumeration = new StringBuffer();
321 for (int itemDocs = 0; itemDocs < itemDocuments.size(); itemDocs++) {
322 if (itemDocs + 1 == itemDocuments.size()) {
323 enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration());
324 } else {
325 enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration() + ",");
326 }
327
328 }
329 int startingCopy = 0;
330 if (singleItem.getItemNoOfParts().intValue() != 0 && null != enumeration) {
331 String enumerationSplit = enumeration.substring(1, 2);
332 boolean isint = checkIsEnumerationSplitIsIntegerOrNot(enumerationSplit);
333 if (isint) {
334 startingCopy = Integer.parseInt(enumerationSplit);
335 }
336 }
337 if (singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
338 || singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
339 boolean isValid = checkForEnumeration(enumeration);
340 if (isValid) {
341 int noOfCopies = workInstanceDocument.getItemDocumentList().size()
342 / singleItem.getItemNoOfParts().intValue();
343 OleRequisitionCopies copy = new OleRequisitionCopies();
344 copy.setParts(singleItem.getItemNoOfParts());
345 copy.setLocationCopies(workInstanceDocument.getHoldingsDocument().getLocationName());
346 copy.setItemCopies(new KualiDecimal(noOfCopies));
347 copy.setPartEnumeration(enumeration.toString());
348 copy.setStartingCopyNumber(new KualiInteger(startingCopy));
349 copies.add(copy);
350 }
351 }
352 }
353 return copies;
354 }
355
356 public boolean checkForEnumeration(StringBuffer enumeration) {
357 if (null != enumeration && !(enumeration.equals("")) && !(enumeration.toString().equals("null"))) {
358 return true;
359 } else {
360 return false;
361 }
362 }
363
364 public boolean checkIsEnumerationSplitIsIntegerOrNot(String enumerationSplit) {
365 try {
366 int startingCopy = Integer.parseInt(enumerationSplit);
367 } catch (NumberFormatException e) {
368 return false;
369 }
370 return true;
371 }
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401 @Override
402 public List getItemsActiveOnly() {
403 LOG.debug("Inside getItemsActiveOnly of OlePurchaseOrderReopenDocument");
404 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnly(this);
405 }
406
407
408
409
410
411
412 @Override
413 public List getItemsActiveOnlySetupAlternateAmount() {
414 LOG.debug("Inside getItemsActiveOnlySetupAlternateAmount of OlePurchaseOrderReopenDocument");
415 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnlySetupAlternateAmount(this);
416 }
417
418 @Override
419 public boolean getAdditionalChargesExist() {
420 LOG.debug("Inside getAdditionalChargesExist of OlePurchaseOrderReopenDocument");
421 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getAdditionalChargesExist(this);
422 }
423
424
425
426
427
428
429 public boolean getIsFinalReqs() {
430 LOG.debug("Inside getIsFinalReqs of OlePurchaseOrderAmendmentDocument");
431
432 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsFinalReqs(this);
433 }
434
435 public boolean getIsSplitPO() {
436 LOG.debug("Inside getIsSplitPO of OlePurchaseOrderAmendmentDocument");
437 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsSplitPO(this);
438 }
439
440 public boolean getIsReOpenPO() {
441 LOG.debug("Inside getIsReOpenPO of OlePurchaseOrderAmendmentDocument");
442 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsReOpenPO(this);
443 }
444
445
446
447
448
449
450 public String getBibeditorCreateURL() {
451 LOG.debug("Inside getBibeditorCreateURL of OlePurchaseOrderAmendmentDocument");
452 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
453 }
454
455 public String getBibSearchURL() {
456 LOG.debug("Inside getBibSearchURL of OlePurchaseOrderAmendmentDocument");
457 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
458 }
459
460
461
462
463
464
465 public String getBibeditorEditURL() {
466 LOG.debug("Inside getBibeditorEditURL of OlePurchaseOrderAmendmentDocument");
467 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
468 }
469
470
471
472
473
474
475 public String getDublinEditorEditURL() {
476 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
477 }
478
479
480
481
482
483 public String getInstanceEditorURL() {
484 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getInstanceEditorURL();
485 }
486
487
488
489
490
491
492 public String getBibeditorViewURL() {
493 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
494 }
495
496
497
498
499
500 public String getDublinEditorViewURL() {
501 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
502 }
503
504
505
506
507
508 public String getMarcXMLFileDirLocation() throws Exception {
509 LOG.debug("Inside getMarcXMLFileDirLocation of OlePurchaseOrderAmendmentDocument");
510 return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
511 }
512
513 @Override
514 public Class getItemClass() {
515 return OlePurchaseOrderItem.class;
516 }
517
518
519 @Override
520 public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
521 if (nodeName.equals(PurapWorkflowConstants.HAS_NEW_UNORDERED_ITEMS)) {
522 return isNewUnorderedItem();
523 }
524 if (nodeName.equals(PurapWorkflowConstants.CONTRACT_MANAGEMENT_REVIEW_REQUIRED)) {
525 return isContractManagementReviewRequired();
526 }
527 if (nodeName.equals(PurapWorkflowConstants.AWARD_REVIEW_REQUIRED)) {
528 return isAwardReviewRequired();
529 }
530 if (nodeName.equals(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED)) {
531 return isBudgetReviewRequired();
532 }
533 if (nodeName.equals(PurapWorkflowConstants.VENDOR_IS_EMPLOYEE_OR_NON_RESIDENT_ALIEN)) {
534 return isVendorEmployeeOrNonResidentAlien();
535 }
536
537 if (nodeName.equals(PurapWorkflowConstants.NOTIFY_BUDGET_REVIEW)) {
538 return isNotificationRequired();
539 }
540 throw new UnsupportedOperationException("Cannot answer split question for this node you call \"" + nodeName + "\"");
541 }
542
543 public String getVendorPoNumber() {
544 return vendorPoNumber;
545 }
546
547 public void setVendorPoNumber(String vendorPoNumber) {
548 this.vendorPoNumber = vendorPoNumber;
549 }
550
551
552
553
554
555
556 public boolean getIsSaved() {
557 if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
558 return true;
559 }
560 return false;
561 }
562
563 public boolean getIsATypeOfRCVGDoc() {
564 return false;
565 }
566
567 public boolean getIsATypeOfCORRDoc() {
568 return false;
569 }
570
571
572 @Override
573 public void doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) {
574 super.doRouteLevelChange(levelChangeEvent);
575 try {
576 String newNodeName = levelChangeEvent.getNewNodeName();
577 String documentId = this.getDocumentNumber();
578 if (!OLEConstants.PO_NOTE_MAP.containsKey(documentId)
579 && newNodeName != null
580 && (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || newNodeName
581 .equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET))) {
582 addPurchaseOrderNote(levelChangeEvent);
583 OLEConstants.PO_NOTE_MAP.put(documentId, true);
584
585 }
586 } catch (Exception e) {
587 String errorMsg = "Workflow Error found checking actions requests on document with id "
588 + getDocumentNumber() + ". *** WILL NOT UPDATE PURAP STATUS ***";
589 LOG.error(errorMsg, e);
590 }
591 }
592
593 public void addPurchaseOrderNote(DocumentRouteLevelChange levelChangeEvent) {
594
595 String newNodeName = levelChangeEvent.getNewNodeName();
596 RoutingReportCriteria.Builder reportCriteria = RoutingReportCriteria.Builder
597 .createByDocumentIdAndTargetNodeName(getDocumentNumber(), newNodeName);
598 if (newNodeName != null
599 && (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || newNodeName
600 .equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET))) {
601 String note = "";
602 if(newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE)){
603 note = OLEConstants.SufficientFundCheck.POA_NOTE;
604 }
605 if(newNodeName.equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET)){
606 note = OLEConstants.SufficientFundCheck.FYI_NOTE;
607 }
608 DocumentService documentService = SpringContext.getBean(DocumentService.class);
609 Note apoNote = documentService.createNoteFromDocument(this, note);
610 this.addNote(apoNote);
611 String documentTypeName = this.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
612 if (documentTypeName != null
613 && documentTypeName.equals(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT)) {
614 documentService.saveDocumentNotes(this);
615 }
616
617 }
618
619 }
620
621
622
623
624
625 @Override
626 protected void populateAccountsForRouting() {
627 List<SufficientFundsItem> fundsItems = new ArrayList<SufficientFundsItem>();
628 String documentId = this.getDocumentNumber();
629 try {
630 String nodeName = getFinancialSystemDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator()
631 .next();
632 if (nodeName != null
633 && (nodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || nodeName
634 .equalsIgnoreCase(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED))) {
635 if (SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear()
636 .compareTo(getPostingYear()) >= 0) {
637 List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
638 for (GeneralLedgerPendingEntry glpe : pendingEntries) {
639 glpe.getChartOfAccountsCode();
640 }
641 SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
642 fundsItems = SpringContext.getBean(SufficientFundsService.class).checkSufficientFunds(
643 pendingEntries);
644 SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(
645 this);
646 SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());
647 }
648 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
649 accountsForRouting = (SpringContext.getBean(PurapAccountingService.class).generateSummary(getItems()));
650 String documentFiscalYearString = this.getPostingYear().toString();
651 List<String> fundsItemList = new ArrayList<String>();
652 List<String> accountsList = new ArrayList<String>();
653 for (SufficientFundsItem fundsItem : fundsItems) {
654 fundsItemList.add(fundsItem.getAccount().getChartOfAccountsCode());
655 }
656 setAccountsForRouting(accountsForRouting);
657 refreshNonUpdateableReferences();
658 for (SourceAccountingLine sourceLine : getAccountsForRouting()) {
659 sourceLine.refreshNonUpdateableReferences();
660 }
661 } else {
662 super.populateAccountsForRouting();
663 }
664 } catch (Exception e) {
665 logAndThrowRuntimeException("Error in populateAccountsForRouting while submitting document with id "
666 + getDocumentNumber(), e);
667 }
668 }
669
670
671 @Override
672 protected boolean isBudgetReviewRequired() {
673 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
674 .getBean("oleRequisitionDocumentService");
675 boolean sufficientFundCheck = false;
676 List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
677 for (SourceAccountingLine accLine : sourceAccountingLineList) {
678 Map searchMap = new HashMap();
679 String notificationOption = null;
680 Map<String, Object> key = new HashMap<String, Object>();
681 String chartCode = accLine.getChartOfAccountsCode();
682 String accNo = accLine.getAccountNumber();
683 String objectCd = accLine.getFinancialObjectCode();
684 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
685 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
686 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
687 OleSufficientFundCheck.class, key);
688 if (account != null) {
689 notificationOption = account.getNotificationOption();
690 }
691 if (notificationOption != null
692 && (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW))) {
693 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
694 if (sufficientFundCheck) {
695 return true;
696 }
697 }
698 }
699 return sufficientFundCheck;
700 }
701
702 private boolean isNotificationRequired() {
703 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
704 .getBean("oleRequisitionDocumentService");
705 List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
706 boolean sufficientFundCheck = false;
707 for (SourceAccountingLine accLine : sourceAccountingLineList) {
708 Map searchMap = new HashMap();
709 String notificationOption = null;
710 Map<String, Object> key = new HashMap<String, Object>();
711 String chartCode = accLine.getChartOfAccountsCode();
712 String accNo = accLine.getAccountNumber();
713 String objectCd = accLine.getFinancialObjectCode();
714 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
715 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
716 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
717 OleSufficientFundCheck.class, key);
718 if (account != null) {
719 notificationOption = account.getNotificationOption();
720 }
721 if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.NOTIFICATION)) {
722 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
723 if (sufficientFundCheck) {
724 return true;
725 }
726 }
727 }
728 return sufficientFundCheck;
729 }
730
731 private void populateVendorAliasName() {
732 Map vendorDetailMap = new HashMap();
733 vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
734 vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
735 List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
736 if (vendorDetailList != null && vendorDetailList.size() > 0) {
737 this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
738 }
739 }
740
741 }