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