1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document;
17
18 import org.apache.commons.lang.ArrayUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.ole.module.purap.PurapConstants;
21 import org.kuali.ole.module.purap.PurapParameterConstants;
22 import org.kuali.ole.module.purap.PurapPropertyConstants;
23 import org.kuali.ole.module.purap.businessobject.*;
24 import org.kuali.ole.module.purap.document.service.PurapService;
25 import org.kuali.ole.module.purap.service.PurapAccountingService;
26 import org.kuali.ole.module.purap.service.SensitiveDataService;
27 import org.kuali.ole.module.purap.util.PurApRelatedViews;
28 import org.kuali.ole.select.businessobject.OleLicensingRequirement;
29 import org.kuali.ole.select.document.OleInvoiceDocument;
30 import org.kuali.ole.select.service.OleUrlResolver;
31 import org.kuali.ole.sys.OLEConstants.AdHocPaymentIndicator;
32 import org.kuali.ole.sys.businessobject.AccountingLine;
33 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
34 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
35 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.ole.sys.document.AccountingDocumentBase;
38 import org.kuali.ole.sys.document.AmountTotaling;
39 import org.kuali.ole.sys.service.UniversityDateService;
40 import org.kuali.ole.vnd.businessobject.VendorAddress;
41 import org.kuali.ole.vnd.businessobject.VendorDetail;
42 import org.kuali.ole.vnd.document.service.VendorService;
43 import org.kuali.rice.core.api.config.property.ConfigContext;
44 import org.kuali.rice.core.api.util.type.KualiDecimal;
45 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
46 import org.kuali.rice.kew.api.WorkflowDocument;
47 import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
48 import org.kuali.rice.krad.rules.rule.event.DocumentEvent;
49 import org.kuali.rice.krad.rules.rule.event.RouteDocumentEvent;
50 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
51 import org.kuali.rice.krad.service.KualiModuleService;
52 import org.kuali.rice.krad.service.ModuleService;
53 import org.kuali.rice.krad.util.NoteType;
54 import org.kuali.rice.krad.util.ObjectUtils;
55 import org.kuali.rice.location.api.LocationConstants;
56 import org.kuali.rice.location.framework.country.CountryEbo;
57
58 import java.math.BigDecimal;
59 import java.text.MessageFormat;
60 import java.util.*;
61
62
63
64
65 public abstract class PurchasingAccountsPayableDocumentBase extends AccountingDocumentBase implements PurchasingAccountsPayableDocument, AmountTotaling {
66
67 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchasingAccountsPayableDocumentBase.class);
68
69
70 protected Integer purapDocumentIdentifier;
71 protected Integer vendorHeaderGeneratedIdentifier;
72 protected Integer vendorDetailAssignedIdentifier;
73 protected String vendorCustomerNumber;
74 protected String vendorName;
75 protected String vendorLine1Address;
76 protected String vendorLine2Address;
77 protected String vendorCityName;
78 protected String vendorStateCode;
79 protected String vendorAddressInternationalProvinceName;
80 protected String vendorPostalCode;
81 protected String vendorCountryCode;
82 protected Integer accountsPayablePurchasingDocumentLinkIdentifier;
83 protected boolean useTaxIndicator;
84 protected String vendorAttentionName;
85 protected String accountDistributionMethod;
86
87
88
89 protected BigDecimal purchaseOrderTypeId;
90
91
92
93 protected String statusCode;
94
95
96 protected String vendorNumber;
97 protected Integer vendorAddressGeneratedIdentifier;
98 protected Boolean overrideWorkflowButtons = null;
99 protected transient PurApRelatedViews relatedViews;
100 protected boolean sensitive;
101
102 protected boolean calculated;
103
104
105 protected List<PurApItem> items;
106 protected List<SourceAccountingLine> accountsForRouting;
107
108
109 protected VendorDetail vendorDetail;
110 protected CountryEbo vendorCountry;
111 protected PurchaseOrderType orderType;
112 protected OleLicensingRequirement licenseReqmt;
113
114
115 public transient String[] belowTheLineTypes;
116
117
118 public boolean allowDeleteAwareCollection = true;
119
120
121 private boolean overviewFlag;
122 private boolean deliveryFlag;
123 private boolean vendorFlag;
124 private boolean titlesFlag;
125 private boolean paymentInfoFlag;
126 private boolean additionalInstitutionalInfoFlag;
127 private boolean accountSummaryFlag;
128 private boolean relatedDocumentsFlag;
129 private boolean paymentHistoryFlag;
130 private boolean notesAndAttachmentFlag;
131 private boolean adHocRecipientsFlag;
132 private boolean routeLogFlag;
133
134 private boolean invoiceInfoFlag;
135 private boolean processItemsFlag;
136 private boolean generalEntriesFlag;
137 private boolean creditMemoInfoFlag;
138
139
140
141
142 private transient OleUrlResolver oleUrlResolver;
143
144
145
146
147
148
149
150
151
152
153
154
155
156 public PurchasingAccountsPayableDocumentBase() {
157 items = new ArrayList();
158 }
159
160 protected GeneralLedgerPendingEntry getFirstPendingGLEntry() {
161 if (ObjectUtils.isNotNull(getGeneralLedgerPendingEntries()) && !getGeneralLedgerPendingEntries().isEmpty()) {
162 return getGeneralLedgerPendingEntries().get(0);
163 }
164 return null;
165 }
166
167 public Integer getPostingYearFromPendingGLEntries() {
168 GeneralLedgerPendingEntry glpe = getFirstPendingGLEntry();
169 if (ObjectUtils.isNotNull(glpe)) {
170 return glpe.getUniversityFiscalYear();
171 }
172 return null;
173 }
174
175 public String getPostingPeriodCodeFromPendingGLEntries() {
176 GeneralLedgerPendingEntry glpe = getFirstPendingGLEntry();
177 if (ObjectUtils.isNotNull(glpe)) {
178 return glpe.getUniversityFiscalPeriodCode();
179 }
180 return null;
181 }
182
183 public List<SourceAccountingLine> getAccountsForRouting() {
184 if (accountsForRouting == null) {
185 populateAccountsForRouting();
186 }
187 return accountsForRouting;
188 }
189
190 public void setAccountsForRouting(List<SourceAccountingLine> accountsForRouting) {
191 this.accountsForRouting = accountsForRouting;
192 }
193
194
195
196
197 protected void populateAccountsForRouting() {
198 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
199 setAccountsForRouting(SpringContext.getBean(PurapAccountingService.class).generateSummary(getItems()));
200
201
202 refreshNonUpdateableReferences();
203 for (SourceAccountingLine sourceLine : getAccountsForRouting()) {
204 sourceLine.refreshNonUpdateableReferences();
205 }
206 }
207
208 public boolean isSensitive() {
209 List<SensitiveData> sensitiveData = SpringContext.getBean(SensitiveDataService.class).getSensitiveDatasAssignedByRelatedDocId(getAccountsPayablePurchasingDocumentLinkIdentifier());
210 if (ObjectUtils.isNotNull(sensitiveData) && !sensitiveData.isEmpty()) {
211 return true;
212 }
213 return false;
214 }
215
216
217
218
219 @Override
220 public boolean isInquiryRendered() {
221 return isPostingYearPrior();
222 }
223
224
225
226
227 @Override
228 public boolean isPostingYearNext() {
229 Integer currentFY = SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
230 return (getPostingYear().compareTo(currentFY) > 0);
231 }
232
233
234
235
236 @Override
237 public boolean isPostingYearPrior() {
238 Integer currentFY = SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
239 return (getPostingYear().compareTo(currentFY) < 0);
240 }
241
242
243
244
245 @Override
246 public Integer getPostingYearNextOrCurrent() {
247 if (isPostingYearNext()) {
248
249 return getPostingYear();
250 }
251
252 return SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
253 }
254
255
256
257
258 @Override
259 @SuppressWarnings("rawtypes")
260 public abstract Class getItemClass();
261
262 @SuppressWarnings("rawtypes")
263 public abstract Class getItemUseTaxClass();
264
265
266
267
268 @Override
269 public abstract PurchasingAccountsPayableDocument getPurApSourceDocumentIfPossible();
270
271
272
273
274 @Override
275 public abstract String getPurApSourceDocumentLabelIfPossible();
276
277
278
279
280 @Override
281 public void prepareForSave(DocumentEvent event) {
282 customPrepareForSave(event);
283 super.prepareForSave(event);
284 fixItemReferences();
285 }
286
287
288
289
290
291
292
293
294 @Override
295 public boolean documentPerformsSufficientFundsCheck() {
296 return false;
297 }
298
299
300 @Override
301 public boolean isDocumentStoppedInRouteNode(String nodeName) {
302 WorkflowDocument workflowDocument = this.getFinancialSystemDocumentHeader().getWorkflowDocument();
303
304 Set<String> names = workflowDocument.getCurrentNodeNames();
305 List<String> currentRouteLevels = new ArrayList<String>(names);
306 if (currentRouteLevels.contains(nodeName) && workflowDocument.isApprovalRequested()) {
307 return true;
308 }
309 return false;
310 }
311
312
313
314
315
316
317 protected void logAndThrowRuntimeException(String errorMessage) {
318 this.logAndThrowRuntimeException(errorMessage, null);
319 }
320
321
322
323
324
325
326
327 protected void logAndThrowRuntimeException(String errorMessage, Exception e) {
328 if (ObjectUtils.isNotNull(e)) {
329 LOG.error(errorMessage, e);
330 throw new RuntimeException(errorMessage, e);
331 } else {
332 LOG.error(errorMessage);
333 throw new RuntimeException(errorMessage);
334 }
335 }
336
337
338
339
340
341
342
343
344 public void customPrepareForSave(DocumentEvent event) {
345
346 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
347
348 if (event instanceof RouteDocumentEvent || event instanceof ApproveDocumentEvent) {
349
350
351
352
353
354
355 SpringContext.getBean(PurapService.class).calculateTax(this);
356 }
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373 }
374
375
376
377
378 @Override
379 public List buildListOfDeletionAwareLists() {
380 List managedLists = new ArrayList<List>();
381 managedLists.add(getDeletionAwareAccountingLines());
382 if (allowDeleteAwareCollection) {
383
384
385
386
387 List<PurApItemBase> subManageList = this.getItems();
388 List useTaxItems = new ArrayList();
389 for (PurApItemBase subManage : subManageList) {
390 useTaxItems.addAll(subManage.getUseTaxItems());
391 }
392
393 managedLists.add(this.getItems());
394 managedLists.add(useTaxItems);
395 }
396 return managedLists;
397 }
398
399
400
401
402
403
404 @SuppressWarnings("rawtypes")
405 protected List getDeletionAwareAccountingLines() {
406 List<PurApAccountingLine> deletionAwareAccountingLines = new ArrayList<PurApAccountingLine>();
407 for (Object itemAsObject : this.getItems()) {
408 final PurApItem item = (PurApItem) itemAsObject;
409 for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
410 deletionAwareAccountingLines.add(accountingLine);
411 }
412 }
413 return deletionAwareAccountingLines;
414 }
415
416
417
418
419
420
421
422
423
424
425 @Override
426 public void processAfterRetrieve() {
427 super.processAfterRetrieve();
428
429 refreshNonUpdateableReferences();
430 }
431
432
433
434
435 @Override
436 public void addItem(PurApItem item) {
437 int itemLinePosition = getItemLinePosition();
438 if (ObjectUtils.isNotNull(item.getItemLineNumber()) && (item.getItemLineNumber() > 0) && (item.getItemLineNumber() <= itemLinePosition)) {
439 itemLinePosition = item.getItemLineNumber().intValue() - 1;
440 }
441
442 item.setPurapDocumentIdentifier(this.purapDocumentIdentifier);
443
444
445 items.add(itemLinePosition, item);
446 renumberItems(itemLinePosition);
447 }
448
449
450
451
452 @Override
453 public void deleteItem(int lineNum) {
454 if (items.remove(lineNum) == null) {
455
456 }
457 renumberItems(lineNum);
458 }
459
460
461
462
463 @Override
464 public void renumberItems(int start) {
465 for (int i = start; i < items.size(); i++) {
466 PurApItem item = items.get(i);
467
468 if (item.getItemType().isLineItemIndicator()) {
469 item.setItemLineNumber(new Integer(i + 1));
470 }
471 }
472 }
473
474
475
476
477 @Override
478 public void itemSwap(int positionFrom, int positionTo) {
479
480 if ((positionTo < 0) || (positionTo >= getItemLinePosition())) {
481 return;
482 }
483 PurApItem item1 = this.getItem(positionFrom);
484 PurApItem item2 = this.getItem(positionTo);
485 Integer oldFirstPos = item1.getItemLineNumber();
486
487 item1.setItemLineNumber(item2.getItemLineNumber());
488 item2.setItemLineNumber(oldFirstPos);
489
490 items.remove(positionFrom);
491 items.add(positionTo, item1);
492 }
493
494
495
496
497 @Override
498 public int getItemLinePosition() {
499 int belowTheLineCount = 0;
500 for (PurApItem item : items) {
501 if (item.getItemType().isAdditionalChargeIndicator()) {
502 belowTheLineCount++;
503 }
504 }
505 return items.size() - belowTheLineCount;
506 }
507
508
509
510
511 @Override
512 public PurApItem getItem(int pos) {
513 return items.get(pos);
514 }
515
516
517
518
519
520
521
522
523 @SuppressWarnings("rawtypes")
524 public PurApItem getItemByLineNumber(int lineNumber) {
525 for (Object element : items) {
526 PurApItem item = (PurApItem) element;
527 if (item.getItemLineNumber().intValue() == lineNumber) {
528 return item;
529 }
530 }
531 return null;
532 }
533
534
535
536
537
538
539
540 @SuppressWarnings("rawtypes")
541 public PurApItem getItemByStringIdentifier(String itemStrID) {
542 for (Object element : items) {
543 PurApItem item = (PurApItem) element;
544 if (StringUtils.equalsIgnoreCase(item.getItemIdentifierString(), itemStrID)) {
545 return item;
546 }
547 }
548 return null;
549 }
550
551
552
553
554
555
556
557 @SuppressWarnings("rawtypes")
558 public PurApItem getItemByItemIdentifier(Integer itemID) {
559 for (Object element : items) {
560 PurApItem item = (PurApItem) element;
561 if (item.getItemIdentifier() == itemID) {
562 return item;
563 }
564 }
565 return null;
566 }
567
568
569
570
571
572
573
574 @Override
575 public void setPostingYear(Integer postingYear) {
576 this.postingYear = postingYear;
577 }
578
579
580
581
582 @Override
583 public KualiDecimal getTotalDollarAmount() {
584 return getTotalDollarAmountAllItems(null);
585 }
586
587
588
589
590 @Override
591 public void setTotalDollarAmount(KualiDecimal amount) {
592
593 }
594
595
596
597
598
599 @Override
600 public KualiDecimal getTotalDollarAmountAllItems(String[] excludedTypes) {
601 return getTotalDollarAmountWithExclusions(excludedTypes, true);
602 }
603
604
605
606
607
608
609 @Override
610 public KualiDecimal getTotalDollarAmountAboveLineItems() {
611 return getTotalDollarAmountAboveLineItems(null);
612 }
613
614
615
616
617
618
619
620 public KualiDecimal getTotalDollarAmountAboveLineItems(String[] excludedTypes) {
621 return getTotalDollarAmountWithExclusions(excludedTypes, false);
622 }
623
624
625
626
627
628
629
630
631 public KualiDecimal getTotalDollarAmountWithExclusions(String[] excludedTypes, boolean includeBelowTheLine) {
632 List<PurApItem> itemsForTotal = getItems();
633
634 return getTotalDollarAmountWithExclusionsSubsetItems(excludedTypes, includeBelowTheLine, itemsForTotal);
635 }
636
637
638
639
640
641
642
643
644
645 protected KualiDecimal getTotalDollarAmountWithExclusionsSubsetItems(String[] excludedTypes, boolean includeBelowTheLine, List<PurApItem> itemsForTotal) {
646 if (excludedTypes == null) {
647 excludedTypes = new String[]{};
648 }
649
650 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
651 for (PurApItem item : itemsForTotal) {
652 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
653 ItemType it = item.getItemType();
654 if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
655 KualiDecimal totalAmount = item.getTotalAmount();
656 KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
657 total = total.add(itemTotal);
658 }
659 }
660 return total;
661 }
662
663 @Override
664 public KualiDecimal getTotalDollarAmountForTradeIn() {
665 List<PurApItem> tradeInItems = getTradeInItems();
666 return getTotalDollarAmountWithExclusionsSubsetItems(null, false, tradeInItems);
667 }
668
669
670
671
672
673
674 @Override
675 public List<PurApItem> getTradeInItems() {
676 List<PurApItem> tradeInItems = new ArrayList<PurApItem>();
677 for (PurApItem purApItem : (List<PurApItem>) getItems()) {
678 if (purApItem.getItemAssignedToTradeInIndicator()) {
679 tradeInItems.add(purApItem);
680 }
681 }
682 return tradeInItems;
683 }
684
685
686
687
688 @Override
689 public KualiDecimal getTotalPreTaxDollarAmount() {
690 return getTotalPreTaxDollarAmountAllItems(null);
691 }
692
693
694
695
696 @Override
697 public void setTotalPreTaxDollarAmount(KualiDecimal amount) {
698
699 }
700
701
702
703
704 @Override
705 public KualiDecimal getTotalPreTaxDollarAmountAllItems(String[] excludedTypes) {
706 return getTotalPreTaxDollarAmountWithExclusions(excludedTypes, true);
707 }
708
709
710
711
712
713
714 public KualiDecimal getTotalPreTaxDollarAmountAboveLineItems() {
715 return getTotalPreTaxDollarAmountAboveLineItems(null);
716 }
717
718
719
720
721
722
723
724 public KualiDecimal getTotalPreTaxDollarAmountAboveLineItems(String[] excludedTypes) {
725 return getTotalPreTaxDollarAmountWithExclusions(excludedTypes, false);
726 }
727
728
729
730
731
732
733
734
735 public KualiDecimal getTotalPreTaxDollarAmountWithExclusions(String[] excludedTypes, boolean includeBelowTheLine) {
736 if (excludedTypes == null) {
737 excludedTypes = new String[]{};
738 }
739
740 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
741 for (PurApItem item : (List<PurApItem>) getItems()) {
742 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
743 ItemType it = item.getItemType();
744 if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
745 KualiDecimal extendedPrice = item.getExtendedPrice();
746 KualiDecimal itemTotal = (extendedPrice != null) ? extendedPrice : KualiDecimal.ZERO;
747 total = total.add(itemTotal);
748 }
749 }
750 return total;
751 }
752
753 @Override
754 public KualiDecimal getTotalTaxAmount() {
755 return getTotalTaxAmountAllItems(null);
756 }
757
758 @Override
759 public void setTotalTaxAmount(KualiDecimal amount) {
760
761 }
762
763 @Override
764 public KualiDecimal getTotalTaxAmountAllItems(String[] excludedTypes) {
765 return getTotalTaxAmountWithExclusions(excludedTypes, true);
766 }
767
768 @Override
769 public KualiDecimal getTotalTaxAmountAboveLineItems() {
770 return getTotalTaxAmountAboveLineItems(null);
771 }
772
773 @Override
774 public KualiDecimal getTotalTaxAmountAboveLineItems(String[] excludedTypes) {
775 return getTotalTaxAmountWithExclusions(excludedTypes, false);
776 }
777
778 @Override
779 public KualiDecimal getTotalTaxAmountWithExclusions(String[] excludedTypes, boolean includeBelowTheLine) {
780 if (excludedTypes == null) {
781 excludedTypes = new String[]{};
782 }
783
784 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
785 for (PurApItem item : (List<PurApItem>) getItems()) {
786 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
787 ItemType it = item.getItemType();
788 if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
789 KualiDecimal taxAmount = item.getItemTaxAmount();
790 KualiDecimal itemTotal = (taxAmount != null) ? taxAmount : KualiDecimal.ZERO;
791 total = total.add(itemTotal);
792 }
793 }
794 return total;
795 }
796
797 @Override
798 public boolean isUseTaxIndicator() {
799 return useTaxIndicator;
800 }
801
802 @Override
803 public void setUseTaxIndicator(boolean useTaxIndicator) {
804 this.useTaxIndicator = useTaxIndicator;
805 }
806
807
808
809
810 @Override
811 public void templateVendorAddress(VendorAddress vendorAddress) {
812 if (vendorAddress == null) {
813 return;
814 }
815 this.setVendorLine1Address(vendorAddress.getVendorLine1Address());
816 this.setVendorLine2Address(vendorAddress.getVendorLine2Address());
817 this.setVendorCityName(vendorAddress.getVendorCityName());
818 this.setVendorStateCode(vendorAddress.getVendorStateCode());
819 this.setVendorPostalCode(vendorAddress.getVendorZipCode());
820 this.setVendorCountryCode(vendorAddress.getVendorCountryCode());
821 }
822
823
824
825
826
827
828
829 @Override
830 public String getVendorNumber() {
831 if (StringUtils.isNotEmpty(vendorNumber)) {
832 return vendorNumber;
833 } else if (ObjectUtils.isNotNull(vendorDetail)) {
834 return vendorDetail.getVendorNumber();
835 } else {
836 return "";
837 }
838 }
839
840 @Override
841 public void setVendorNumber(String vendorNumber) {
842 this.vendorNumber = vendorNumber;
843 }
844
845 public Boolean getOverrideWorkflowButtons() {
846 return overrideWorkflowButtons;
847 }
848
849 public void setOverrideWorkflowButtons(Boolean overrideWorkflowButtons) {
850 this.overrideWorkflowButtons = overrideWorkflowButtons;
851 }
852
853 @Override
854 public Integer getVendorHeaderGeneratedIdentifier() {
855 return vendorHeaderGeneratedIdentifier;
856 }
857
858 @Override
859 public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
860 this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
861 }
862
863 @Override
864 public Integer getVendorDetailAssignedIdentifier() {
865 return vendorDetailAssignedIdentifier;
866 }
867
868 @Override
869 public void setVendorDetailAssignedIdentifier(Integer vendorDetailAssignedIdentifier) {
870 this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
871 }
872
873 @Override
874 public String getVendorCustomerNumber() {
875 return vendorCustomerNumber;
876 }
877
878 @Override
879 public void setVendorCustomerNumber(String vendorCustomerNumber) {
880 this.vendorCustomerNumber = vendorCustomerNumber;
881 }
882
883 @Override
884 public Integer getPurapDocumentIdentifier() {
885 return purapDocumentIdentifier;
886 }
887
888 @Override
889 public void setPurapDocumentIdentifier(Integer identifier) {
890 this.purapDocumentIdentifier = identifier;
891 }
892
893 @Override
894 public VendorDetail getVendorDetail() {
895 return vendorDetail;
896 }
897
898 public void setVendorDetail(VendorDetail vendorDetail) {
899 this.vendorDetail = vendorDetail;
900 }
901
902 @Override
903 @SuppressWarnings("rawtypes")
904 public List getItems() {
905 return items;
906 }
907
908 @Override
909 @SuppressWarnings("rawtypes")
910 public void setItems(List items) {
911 this.items = items;
912 }
913
914 @Override
915 public String getVendorCityName() {
916 return vendorCityName;
917 }
918
919 @Override
920 public void setVendorCityName(String vendorCityName) {
921 this.vendorCityName = vendorCityName;
922 }
923
924 @Override
925 public String getVendorCountryCode() {
926 return vendorCountryCode;
927 }
928
929 @Override
930 public void setVendorCountryCode(String vendorCountryCode) {
931 this.vendorCountryCode = vendorCountryCode;
932 }
933
934 @Override
935 public String getVendorLine1Address() {
936 return vendorLine1Address;
937 }
938
939 @Override
940 public void setVendorLine1Address(String vendorLine1Address) {
941 this.vendorLine1Address = vendorLine1Address;
942 }
943
944 @Override
945 public String getVendorLine2Address() {
946 return vendorLine2Address;
947 }
948
949 @Override
950 public void setVendorLine2Address(String vendorLine2Address) {
951 this.vendorLine2Address = vendorLine2Address;
952 }
953
954 @Override
955 public String getVendorName() {
956 return vendorName;
957 }
958
959 @Override
960 public void setVendorName(String vendorName) {
961 this.vendorName = vendorName;
962 }
963
964 @Override
965 public String getVendorPostalCode() {
966 return vendorPostalCode;
967 }
968
969 @Override
970 public void setVendorPostalCode(String vendorPostalCode) {
971 this.vendorPostalCode = vendorPostalCode;
972 }
973
974 @Override
975 public String getVendorStateCode() {
976 return vendorStateCode;
977 }
978
979 @Override
980 public void setVendorStateCode(String vendorStateCode) {
981 this.vendorStateCode = vendorStateCode;
982 }
983
984 @Override
985 public String getVendorAddressInternationalProvinceName() {
986 return vendorAddressInternationalProvinceName;
987 }
988
989 @Override
990 public void setVendorAddressInternationalProvinceName(String vendorAddressInternationalProvinceName) {
991 this.vendorAddressInternationalProvinceName = vendorAddressInternationalProvinceName;
992 }
993
994 @Override
995 public Integer getVendorAddressGeneratedIdentifier() {
996 return vendorAddressGeneratedIdentifier;
997 }
998
999 @Override
1000 public void setVendorAddressGeneratedIdentifier(Integer vendorAddressGeneratedIdentifier) {
1001 this.vendorAddressGeneratedIdentifier = vendorAddressGeneratedIdentifier;
1002 }
1003
1004 @Override
1005 public Integer getAccountsPayablePurchasingDocumentLinkIdentifier() {
1006 return accountsPayablePurchasingDocumentLinkIdentifier;
1007 }
1008
1009 @Override
1010 public void setAccountsPayablePurchasingDocumentLinkIdentifier(Integer accountsPayablePurchasingDocumentLinkIdentifier) {
1011 this.accountsPayablePurchasingDocumentLinkIdentifier = accountsPayablePurchasingDocumentLinkIdentifier;
1012 }
1013
1014 @Override
1015 public String[] getBelowTheLineTypes() {
1016 if (this.belowTheLineTypes == null) {
1017 this.belowTheLineTypes = SpringContext.getBean(PurapService.class).getBelowTheLineForDocument(this);
1018 }
1019 return belowTheLineTypes;
1020 }
1021
1022 @Override
1023 public CountryEbo getVendorCountry() {
1024 if (StringUtils.isBlank(vendorCountryCode)) {
1025 vendorCountry = null;
1026 } else {
1027 if (vendorCountry == null || !StringUtils.equals(vendorCountry.getCode(), vendorCountryCode)) {
1028 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
1029 if (moduleService != null) {
1030 Map<String, Object> keys = new HashMap<String, Object>(1);
1031 keys.put(LocationConstants.PrimaryKeyConstants.CODE, vendorCountryCode);
1032 vendorCountry = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
1033 } else {
1034 throw new RuntimeException("CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed.");
1035 }
1036 }
1037 }
1038 return vendorCountry;
1039 }
1040
1041
1042
1043
1044
1045
1046 @Deprecated
1047 public void setVendorCountry(CountryEbo vendorCountry) {
1048 this.vendorCountry = vendorCountry;
1049 }
1050
1051 public String getVendorAttentionName() {
1052 return vendorAttentionName;
1053 }
1054
1055 public void setVendorAttentionName(String vendorAttentionName) {
1056 this.vendorAttentionName = vendorAttentionName;
1057 }
1058
1059
1060
1061
1062
1063
1064
1065 public String getAccountDistributionMethod() {
1066 return accountDistributionMethod;
1067 }
1068
1069
1070
1071
1072
1073
1074 public void setAccountDistributionMethod(String accountDistributionMethod) {
1075 this.accountDistributionMethod = accountDistributionMethod;
1076 }
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087 @Override
1088 public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) {
1089 return false;
1090 }
1091
1092 public PurApRelatedViews getRelatedViews() {
1093 if (relatedViews == null) {
1094 relatedViews = new PurApRelatedViews(this.documentNumber, this.getAccountsPayablePurchasingDocumentLinkIdentifier());
1095 }
1096 return relatedViews;
1097 }
1098
1099 public void setRelatedViews(PurApRelatedViews relatedViews) {
1100 this.relatedViews = relatedViews;
1101 }
1102
1103 @Override
1104 public void refreshNonUpdateableReferences() {
1105 super.refreshNonUpdateableReferences();
1106
1107 for (PurApItem item : (List<PurApItem>) this.getItems()) {
1108
1109 for (PurApAccountingLine account : item.getSourceAccountingLines()) {
1110 account.refreshNonUpdateableReferences();
1111 }
1112 }
1113
1114 fixItemReferences();
1115 }
1116
1117
1118
1119
1120 @Override
1121 public void fixItemReferences() {
1122
1123 if (ObjectUtils.isNull(this.purapDocumentIdentifier)) {
1124 for (PurApItem item : (List<PurApItem>) this.getItems()) {
1125
1126 item.fixAccountReferences();
1127 }
1128 }
1129 }
1130
1131
1132
1133
1134
1135
1136 @Override
1137 public PurApItem getTradeInItem() {
1138 for (PurApItem item : (List<PurApItem>) getItems()) {
1139 if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
1140 return item;
1141 }
1142 }
1143 return null;
1144 }
1145
1146
1147
1148
1149 @Override
1150 public boolean getIsATypeOfPurAPRecDoc() {
1151 return true;
1152 }
1153
1154
1155
1156
1157 @Override
1158 public boolean getIsATypeOfPurDoc() {
1159 if (this instanceof PurchasingDocumentBase) {
1160 return true;
1161 } else {
1162 return false;
1163 }
1164 }
1165
1166
1167
1168
1169 @Override
1170 public boolean getIsATypeOfPODoc() {
1171
1172
1173
1174
1175
1176 return true;
1177
1178 }
1179
1180
1181
1182
1183 @Override
1184 public boolean getIsPODoc() {
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198 return true;
1199
1200 }
1201
1202
1203
1204
1205 @Override
1206 public boolean getIsReqsDoc() {
1207
1208
1209
1210
1211
1212 return true;
1213
1214 }
1215
1216
1217
1218
1219
1220
1221
1222 protected String buildDocumentTitle(String title) {
1223 if (this.getVendorDetail() == null) {
1224 return title;
1225 }
1226
1227 Integer vendorHeaderGeneratedIdentifier = this.getVendorDetail().getVendorHeaderGeneratedIdentifier();
1228 VendorService vendorService = SpringContext.getBean(VendorService.class);
1229
1230 Object[] indicators = new String[2];
1231
1232 boolean isEmployeeVendor = vendorService.isVendorInstitutionEmployee(vendorHeaderGeneratedIdentifier);
1233 indicators[0] = isEmployeeVendor ? AdHocPaymentIndicator.EMPLOYEE_VENDOR : AdHocPaymentIndicator.OTHER;
1234
1235 boolean isVendorForeign = vendorService.isVendorForeign(vendorHeaderGeneratedIdentifier);
1236 indicators[1] = isVendorForeign ? AdHocPaymentIndicator.ALIEN_VENDOR : AdHocPaymentIndicator.OTHER;
1237
1238 for (Object indicator : indicators) {
1239 if (!AdHocPaymentIndicator.OTHER.equals(indicator)) {
1240 String titlePattern = title + " [{0}:{1}]";
1241 return MessageFormat.format(titlePattern, indicators);
1242 }
1243 }
1244
1245 return title;
1246 }
1247
1248
1249
1250
1251
1252
1253 @SuppressWarnings("rawtypes")
1254 @Override
1255 public List getSourceAccountingLines() {
1256 if (ObjectUtils.isNotNull(sourceAccountingLines) && !sourceAccountingLines.isEmpty()) {
1257
1258 return sourceAccountingLines;
1259 } else {
1260
1261
1262
1263
1264 List<AccountingLine> sourceAccountingLines = new ArrayList<AccountingLine>();
1265 for (Object itemAsObject : this.getItems()) {
1266 final PurApItem item = (PurApItem) itemAsObject;
1267 for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
1268
1269
1270 if (!isDuplicateAccountingLine(sourceAccountingLines, accountingLine)) {
1271 sourceAccountingLines.add(accountingLine);
1272 }
1273 }
1274 }
1275 return sourceAccountingLines;
1276 }
1277 }
1278
1279
1280
1281
1282
1283
1284
1285
1286 protected boolean isDuplicateAccountingLine(List<AccountingLine> sourceAccountingLines,
1287 PurApAccountingLine accountingLine) {
1288 for (AccountingLine sourceLine : sourceAccountingLines) {
1289 PurApAccountingLine purapAccountLine = (PurApAccountingLine) sourceLine;
1290
1291 if (purapAccountLine.accountStringsAreEqual(accountingLine)) {
1292 return true;
1293 }
1294 }
1295 return false;
1296 }
1297
1298
1299
1300
1301
1302
1303
1304 protected KualiDecimal getAccountTotalGLEntryAmount(AccountingLine matchingAccountingLine) {
1305 KualiDecimal accountTotalGLEntryAmount = KualiDecimal.ZERO;
1306
1307 for (Object itemAsObject : this.getItems()) {
1308 final PurApItem item = (PurApItem) itemAsObject;
1309 for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
1310
1311 if (accountingLine.accountStringsAreEqual((SourceAccountingLine) matchingAccountingLine)) {
1312 accountTotalGLEntryAmount = accountTotalGLEntryAmount.add(accountingLine.getAmount());
1313 }
1314 }
1315 }
1316
1317 return accountTotalGLEntryAmount;
1318 }
1319
1320
1321
1322
1323
1324
1325
1326 public boolean getNeedWarningRelatedPOs() {
1327 List<PurchaseOrderView> poViews = getRelatedViews().getRelatedPurchaseOrderViews();
1328 for (PurchaseOrderView poView : poViews) {
1329 if (poView.getNeedWarning()) {
1330 return true;
1331 }
1332 }
1333 return false;
1334 }
1335
1336
1337
1338
1339
1340
1341 @SuppressWarnings("rawtypes")
1342 @Override
1343 protected List getPersistedSourceAccountingLinesForComparison() {
1344 LOG.debug("Checking persisted source accounting lines for read-only fields");
1345 List<String> restrictedItemTypesList = new ArrayList<String>();
1346 try {
1347 restrictedItemTypesList = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.getClass(), PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT));
1348 } catch (IllegalArgumentException iae) {
1349
1350 }
1351
1352 PurapAccountingService purApAccountingService = SpringContext.getBean(PurapAccountingService.class);
1353 List persistedSourceLines = new ArrayList();
1354
1355 for (PurApItem item : (List<PurApItem>) this.getItems()) {
1356
1357 if (ObjectUtils.isNotNull(item.getItemIdentifier())) {
1358
1359 final boolean isNotReadOnly = !((restrictedItemTypesList != null) && restrictedItemTypesList.contains(item.getItemTypeCode()));
1360 if (isNotReadOnly) {
1361 persistedSourceLines.addAll(purApAccountingService.getAccountsFromItem(item));
1362 }
1363 }
1364 }
1365 return persistedSourceLines;
1366 }
1367
1368
1369
1370
1371
1372
1373 @SuppressWarnings("rawtypes")
1374 @Override
1375 protected List getSourceAccountingLinesForComparison() {
1376 LOG.debug("Checking source accounting lines for read-only fields");
1377 List<String> restrictedItemTypesList = new ArrayList<String>();
1378 try {
1379 restrictedItemTypesList = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.getClass(), PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT));
1380 } catch (IllegalArgumentException iae) {
1381
1382 }
1383 PurapAccountingService purApAccountingService = SpringContext.getBean(PurapAccountingService.class);
1384 List currentSourceLines = new ArrayList();
1385 for (PurApItem item : (List<PurApItem>) this.getItems()) {
1386
1387 final boolean isNotReadOnly = !((restrictedItemTypesList != null) && restrictedItemTypesList.contains(item.getItemTypeCode()));
1388 if (isNotReadOnly) {
1389 currentSourceLines.addAll(item.getSourceAccountingLines());
1390 }
1391 }
1392 return currentSourceLines;
1393 }
1394
1395
1396
1397
1398
1399
1400
1401 public String getStatusCode() {
1402 return statusCode;
1403 }
1404
1405
1406
1407
1408
1409
1410 public void setStatusCode(String statusCode) {
1411 this.statusCode = statusCode;
1412 }
1413
1414
1415
1416
1417
1418
1419
1420 @Override
1421 public boolean isCalculated() {
1422 return calculated;
1423 }
1424
1425
1426
1427
1428
1429
1430 @Override
1431 public void setCalculated(boolean calculated) {
1432 this.calculated = calculated;
1433 }
1434
1435
1436
1437
1438 public BigDecimal getPurchaseOrderTypeId() {
1439 return purchaseOrderTypeId;
1440 }
1441
1442 public void setPurchaseOrderTypeId(BigDecimal purchaseOrderTypeId) {
1443 this.purchaseOrderTypeId = purchaseOrderTypeId;
1444 }
1445
1446 public void setPurchaseOrderTypeId(String purchaseOrderType) {
1447 Map orderTypeMap = new HashMap();
1448 String orderType = null;
1449 if (purchaseOrderType.equalsIgnoreCase("firm_fixed_ybp")) {
1450 orderType = PurapConstants.ORDER_TYPE_FIRM;
1451 } else if (purchaseOrderType.equalsIgnoreCase("standing")) {
1452 orderType = PurapConstants.ORDER_TYPE_STANDING;
1453 ;
1454 } else if (purchaseOrderType.equalsIgnoreCase("approval")) {
1455 orderType = PurapConstants.ORDER_TYPE_APPROVAL;
1456 ;
1457 } else if (purchaseOrderType.equalsIgnoreCase("subscription")) {
1458 orderType = PurapConstants.ORDER_TYPE_SUBSCRIPTION;
1459 ;
1460 }
1461
1462 if (orderType != null) {
1463 orderTypeMap.put("purchaseOrderType", orderType);
1464 Collection<PurchaseOrderType> purchaseOrderTypeCollection = KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(PurchaseOrderType.class, orderTypeMap);
1465 for (PurchaseOrderType purchaseOrderTypeValue : purchaseOrderTypeCollection) {
1466 BigDecimal id = purchaseOrderTypeValue.getPurchaseOrderTypeId();
1467 this.purchaseOrderTypeId = id;
1468 }
1469 } else {
1470 this.purchaseOrderTypeId = new BigDecimal(purchaseOrderType);
1471 }
1472
1473 }
1474
1475
1476 public PurchaseOrderType getOrderType() {
1477 return orderType;
1478 }
1479
1480 public void setOrderType(PurchaseOrderType orderType) {
1481 this.orderType = orderType;
1482 }
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564 public String getLicenseURL() {
1565 return ConfigContext.getCurrentContextConfig().getProperty("license.web.service.url");
1566
1567
1568
1569
1570 }
1571
1572 public void setOleUrlResolver(OleUrlResolver oleUrlResolver) {
1573 this.oleUrlResolver = oleUrlResolver;
1574 }
1575
1576
1577 @Override
1578 public NoteType getNoteType() {
1579 return NoteType.BUSINESS_OBJECT;
1580 }
1581
1582
1583
1584
1585
1586 public boolean isOverviewFlag() {
1587 return overviewFlag;
1588 }
1589
1590
1591
1592
1593
1594 public void setOverviewFlag(boolean overviewFlag) {
1595 this.overviewFlag = overviewFlag;
1596 }
1597
1598
1599
1600
1601
1602 public boolean isDeliveryFlag() {
1603 return deliveryFlag;
1604 }
1605
1606
1607
1608
1609
1610 public void setDeliveryFlag(boolean deliveryFlag) {
1611 this.deliveryFlag = deliveryFlag;
1612 }
1613
1614
1615
1616
1617
1618 public boolean isVendorFlag() {
1619 return vendorFlag;
1620 }
1621
1622
1623
1624
1625
1626 public void setVendorFlag(boolean vendorFlag) {
1627 this.vendorFlag = vendorFlag;
1628 }
1629
1630
1631
1632
1633
1634 public boolean isTitlesFlag() {
1635 return titlesFlag;
1636 }
1637
1638
1639
1640
1641
1642 public void setTitlesFlag(boolean titlesFlag) {
1643 this.titlesFlag = titlesFlag;
1644 }
1645
1646
1647
1648
1649
1650 public boolean isPaymentInfoFlag() {
1651 return paymentInfoFlag;
1652 }
1653
1654
1655
1656
1657
1658 public void setPaymentInfoFlag(boolean paymentInfoFlag) {
1659 this.paymentInfoFlag = paymentInfoFlag;
1660 }
1661
1662
1663
1664
1665
1666 public boolean isAdditionalInstitutionalInfoFlag() {
1667 return additionalInstitutionalInfoFlag;
1668 }
1669
1670
1671
1672
1673
1674 public void setAdditionalInstitutionalInfoFlag(boolean additionalInstitutionalInfoFlag) {
1675 this.additionalInstitutionalInfoFlag = additionalInstitutionalInfoFlag;
1676 }
1677
1678
1679
1680
1681
1682 public boolean isAccountSummaryFlag() {
1683 return accountSummaryFlag;
1684 }
1685
1686
1687
1688
1689
1690 public void setAccountSummaryFlag(boolean accountSummaryFlag) {
1691 this.accountSummaryFlag = accountSummaryFlag;
1692 }
1693
1694
1695
1696
1697
1698 public boolean isRelatedDocumentsFlag() {
1699 return relatedDocumentsFlag;
1700 }
1701
1702
1703
1704
1705
1706 public void setRelatedDocumentsFlag(boolean relatedDocumentsFlag) {
1707 this.relatedDocumentsFlag = relatedDocumentsFlag;
1708 }
1709
1710
1711
1712
1713
1714 public boolean isPaymentHistoryFlag() {
1715 return paymentHistoryFlag;
1716 }
1717
1718
1719
1720
1721
1722 public void setPaymentHistoryFlag(boolean paymentHistoryFlag) {
1723 this.paymentHistoryFlag = paymentHistoryFlag;
1724 }
1725
1726
1727
1728
1729
1730 public boolean isNotesAndAttachmentFlag() {
1731 return notesAndAttachmentFlag;
1732 }
1733
1734
1735
1736
1737
1738 public void setNotesAndAttachmentFlag(boolean notesAndAttachmentFlag) {
1739 this.notesAndAttachmentFlag = notesAndAttachmentFlag;
1740 }
1741
1742
1743
1744
1745
1746 public boolean isAdHocRecipientsFlag() {
1747 return adHocRecipientsFlag;
1748 }
1749
1750
1751
1752
1753
1754 public void setAdHocRecipientsFlag(boolean adHocRecipientsFlag) {
1755 this.adHocRecipientsFlag = adHocRecipientsFlag;
1756 }
1757
1758
1759
1760
1761
1762 public boolean isRouteLogFlag() {
1763 return routeLogFlag;
1764 }
1765
1766
1767
1768
1769
1770 public void setRouteLogFlag(boolean routeLogFlag) {
1771 this.routeLogFlag = routeLogFlag;
1772 }
1773
1774
1775
1776
1777
1778 public boolean isInvoiceInfoFlag() {
1779 return invoiceInfoFlag;
1780 }
1781
1782
1783
1784
1785
1786 public void setInvoiceInfoFlag(boolean invoiceInfoFlag) {
1787 this.invoiceInfoFlag = invoiceInfoFlag;
1788 }
1789
1790
1791
1792
1793
1794 public boolean isProcessItemsFlag() {
1795 return processItemsFlag;
1796 }
1797
1798
1799
1800
1801
1802 public void setProcessItemsFlag(boolean processItemsFlag) {
1803 this.processItemsFlag = processItemsFlag;
1804 }
1805
1806
1807
1808
1809
1810 public boolean isGeneralEntriesFlag() {
1811 return generalEntriesFlag;
1812 }
1813
1814
1815
1816
1817
1818 public void setGeneralEntriesFlag(boolean generalEntriesFlag) {
1819 this.generalEntriesFlag = generalEntriesFlag;
1820 }
1821
1822
1823
1824
1825
1826 public boolean isCreditMemoInfoFlag() {
1827 return creditMemoInfoFlag;
1828 }
1829
1830
1831
1832
1833
1834 public void setCreditMemoInfoFlag(boolean creditMemoInfoFlag) {
1835 this.creditMemoInfoFlag = creditMemoInfoFlag;
1836 }
1837 }