1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.purap.document;
20
21 import java.math.BigDecimal;
22 import java.text.MessageFormat;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29
30 import org.apache.commons.collections.CollectionUtils;
31 import org.apache.commons.lang.ArrayUtils;
32 import org.apache.commons.lang.StringUtils;
33 import org.kuali.kfs.module.purap.PurapConstants;
34 import org.kuali.kfs.module.purap.PurapParameterConstants;
35 import org.kuali.kfs.module.purap.PurapPropertyConstants;
36 import org.kuali.kfs.module.purap.businessobject.ItemType;
37 import org.kuali.kfs.module.purap.businessobject.PurApAccountingLine;
38 import org.kuali.kfs.module.purap.businessobject.PurApItem;
39 import org.kuali.kfs.module.purap.businessobject.PurApItemBase;
40 import org.kuali.kfs.module.purap.businessobject.PurApItemUseTax;
41 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderView;
42 import org.kuali.kfs.module.purap.businessobject.SensitiveData;
43 import org.kuali.kfs.module.purap.document.service.PurapService;
44 import org.kuali.kfs.module.purap.document.service.impl.PurapServiceImpl;
45 import org.kuali.kfs.module.purap.service.PurapAccountingService;
46 import org.kuali.kfs.module.purap.service.SensitiveDataService;
47 import org.kuali.kfs.module.purap.util.PurApRelatedViews;
48 import org.kuali.kfs.sys.KFSConstants.AdHocPaymentIndicator;
49 import org.kuali.kfs.sys.businessobject.AccountingLine;
50 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry;
51 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
52 import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
53 import org.kuali.kfs.sys.context.SpringContext;
54 import org.kuali.kfs.sys.document.AccountingDocumentBase;
55 import org.kuali.kfs.sys.document.AmountTotaling;
56 import org.kuali.kfs.sys.service.UniversityDateService;
57 import org.kuali.kfs.vnd.businessobject.VendorAddress;
58 import org.kuali.kfs.vnd.businessobject.VendorDetail;
59 import org.kuali.kfs.vnd.document.service.VendorService;
60 import org.kuali.rice.core.api.util.type.KualiDecimal;
61 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
62 import org.kuali.rice.kew.api.WorkflowDocument;
63 import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
64 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
65 import org.kuali.rice.krad.rules.rule.event.RouteDocumentEvent;
66 import org.kuali.rice.krad.service.KualiModuleService;
67 import org.kuali.rice.krad.service.ModuleService;
68 import org.kuali.rice.krad.util.NoteType;
69 import org.kuali.rice.krad.util.ObjectUtils;
70 import org.kuali.rice.location.api.LocationConstants;
71 import org.kuali.rice.location.framework.country.CountryEbo;
72
73
74
75
76 public abstract class PurchasingAccountsPayableDocumentBase extends AccountingDocumentBase implements PurchasingAccountsPayableDocument, AmountTotaling {
77
78 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchasingAccountsPayableDocumentBase.class);
79
80
81 protected Integer purapDocumentIdentifier;
82 protected Integer vendorHeaderGeneratedIdentifier;
83 protected Integer vendorDetailAssignedIdentifier;
84 protected String vendorCustomerNumber;
85 protected String vendorName;
86 protected String vendorLine1Address;
87 protected String vendorLine2Address;
88 protected String vendorCityName;
89 protected String vendorStateCode;
90 protected String vendorAddressInternationalProvinceName;
91 protected String vendorPostalCode;
92 protected String vendorCountryCode;
93 protected Integer accountsPayablePurchasingDocumentLinkIdentifier;
94 protected boolean useTaxIndicator;
95 protected String vendorAttentionName;
96 protected String accountDistributionMethod;
97
98
99 protected String vendorNumber;
100 protected Integer vendorAddressGeneratedIdentifier;
101 protected Boolean overrideWorkflowButtons = null;
102 protected transient PurApRelatedViews relatedViews;
103 protected boolean sensitive;
104
105 protected boolean calculated;
106
107
108 protected List<PurApItem> items;
109 protected List<SourceAccountingLine> accountsForRouting;
110
111
112 protected VendorDetail vendorDetail;
113 protected CountryEbo vendorCountry;
114
115
116 public transient String[] belowTheLineTypes;
117
118
119 public boolean allowDeleteAwareCollection = true;
120
121
122
123
124 public PurchasingAccountsPayableDocumentBase() {
125 items = new ArrayList();
126 }
127
128 protected GeneralLedgerPendingEntry getFirstPendingGLEntry() {
129 if (ObjectUtils.isNotNull(getGeneralLedgerPendingEntries()) && !getGeneralLedgerPendingEntries().isEmpty()) {
130 return getGeneralLedgerPendingEntries().get(0);
131 }
132 return null;
133 }
134
135 public Integer getPostingYearFromPendingGLEntries() {
136 GeneralLedgerPendingEntry glpe = getFirstPendingGLEntry();
137 if (ObjectUtils.isNotNull(glpe)) {
138 return glpe.getUniversityFiscalYear();
139 }
140 return null;
141 }
142
143 public String getPostingPeriodCodeFromPendingGLEntries() {
144 GeneralLedgerPendingEntry glpe = getFirstPendingGLEntry();
145 if (ObjectUtils.isNotNull(glpe)) {
146 return glpe.getUniversityFiscalPeriodCode();
147 }
148 return null;
149 }
150
151 public List<SourceAccountingLine> getAccountsForRouting() {
152 if (accountsForRouting == null) {
153 populateAccountsForRouting();
154 }
155 return accountsForRouting;
156 }
157
158 public void setAccountsForRouting(List<SourceAccountingLine> accountsForRouting) {
159 this.accountsForRouting = accountsForRouting;
160 }
161
162
163
164
165 protected void populateAccountsForRouting() {
166 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
167 setAccountsForRouting(SpringContext.getBean(PurapAccountingService.class).generateSummary(getItems()));
168
169
170 refreshNonUpdateableReferences();
171 for (SourceAccountingLine sourceLine : getAccountsForRouting()) {
172 sourceLine.refreshNonUpdateableReferences();
173 }
174 }
175
176 public boolean isSensitive() {
177 List<SensitiveData> sensitiveData = SpringContext.getBean(SensitiveDataService.class).getSensitiveDatasAssignedByRelatedDocId(getAccountsPayablePurchasingDocumentLinkIdentifier());
178 if (ObjectUtils.isNotNull(sensitiveData) && !sensitiveData.isEmpty()) {
179 return true;
180 }
181 return false;
182 }
183
184
185
186
187 @Override
188 public boolean isInquiryRendered() {
189 return isPostingYearPrior();
190 }
191
192
193
194
195 @Override
196 public boolean isPostingYearNext() {
197 Integer currentFY = SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
198 return (getPostingYear().compareTo(currentFY) > 0);
199 }
200
201
202
203
204 @Override
205 public boolean isPostingYearPrior() {
206 Integer currentFY = SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
207 return (getPostingYear().compareTo(currentFY) < 0);
208 }
209
210
211
212
213 @Override
214 public Integer getPostingYearNextOrCurrent() {
215 if (isPostingYearNext()) {
216
217 return getPostingYear();
218 }
219
220 return SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
221 }
222
223
224
225
226 @Override
227 @SuppressWarnings("rawtypes")
228 public abstract Class getItemClass();
229
230 @SuppressWarnings("rawtypes")
231 public abstract Class getItemUseTaxClass();
232
233
234
235
236 @Override
237 public abstract PurchasingAccountsPayableDocument getPurApSourceDocumentIfPossible();
238
239
240
241
242 @Override
243 public abstract String getPurApSourceDocumentLabelIfPossible();
244
245
246
247
248
249 @Override
250 public void prepareForSave(KualiDocumentEvent event) {
251 customPrepareForSave(event);
252 super.prepareForSave(event);
253 fixItemReferences();
254 }
255
256
257
258
259
260
261
262
263 @Override
264 public boolean documentPerformsSufficientFundsCheck() {
265 return false;
266 }
267
268
269 @Override
270 public boolean isDocumentStoppedInRouteNode(String nodeName) {
271 WorkflowDocument workflowDocument = this.getFinancialSystemDocumentHeader().getWorkflowDocument();
272
273 Set<String> names = workflowDocument.getCurrentNodeNames();
274 if (CollectionUtils.isNotEmpty(names)) {
275 List<String> currentRouteLevels = new ArrayList<String>(names);
276 if (currentRouteLevels.contains(nodeName) && workflowDocument.isApprovalRequested()) {
277 return true;
278 }
279 }
280 return false;
281 }
282
283
284
285
286
287
288 protected void logAndThrowRuntimeException(String errorMessage) {
289 this.logAndThrowRuntimeException(errorMessage, null);
290 }
291
292
293
294
295
296
297
298 protected void logAndThrowRuntimeException(String errorMessage, Exception e) {
299 if (ObjectUtils.isNotNull(e)) {
300 LOG.error(errorMessage, e);
301 throw new RuntimeException(errorMessage, e);
302 }
303 else {
304 LOG.error(errorMessage);
305 throw new RuntimeException(errorMessage);
306 }
307 }
308
309
310
311
312
313
314
315
316 public void customPrepareForSave(KualiDocumentEvent event) {
317
318 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
319
320 if (event instanceof RouteDocumentEvent || event instanceof ApproveDocumentEvent) {
321 if (this instanceof VendorCreditMemoDocument && ((VendorCreditMemoDocument)this).isSourceVendor()){
322 return;
323 }
324 SpringContext.getBean(PurapServiceImpl.class).calculateTax(this);
325 }
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341 }
342
343
344
345
346 @SuppressWarnings("rawtypes")
347 @Override
348 public List buildListOfDeletionAwareLists() {
349 List managedLists = new ArrayList<List>();
350 managedLists.add(getDeletionAwareAccountingLines());
351 if (allowDeleteAwareCollection) {
352
353
354
355
356 managedLists.add(this.getItems());
357 managedLists.add(getDeletionAwareUseTaxItems());
358 }
359 return managedLists;
360 }
361
362
363
364
365
366
367 @SuppressWarnings("rawtypes")
368 protected List getDeletionAwareAccountingLines() {
369 List<PurApAccountingLine> deletionAwareAccountingLines = new ArrayList<PurApAccountingLine>();
370 for (Object itemAsObject : this.getItems()) {
371 final PurApItem item = (PurApItem)itemAsObject;
372 for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
373 deletionAwareAccountingLines.add(accountingLine);
374 }
375 }
376 return deletionAwareAccountingLines;
377 }
378
379
380
381
382
383
384 @SuppressWarnings("rawtypes")
385 protected List getDeletionAwareUseTaxItems() {
386 List<PurApItemUseTax> deletionAwareUseTaxItems = new ArrayList<PurApItemUseTax>();
387
388 List<PurApItemBase> subManageList = this.getItems();
389 for (PurApItemBase subManage : subManageList) {
390 deletionAwareUseTaxItems.addAll(subManage.getUseTaxItems());
391 }
392
393 return deletionAwareUseTaxItems;
394 }
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415 @Override
416 public void processAfterRetrieve() {
417 super.processAfterRetrieve();
418
419 refreshNonUpdateableReferences();
420 }
421
422
423
424
425 @Override
426 public void addItem(PurApItem item) {
427 int itemLinePosition = getItemLinePosition();
428 if (ObjectUtils.isNotNull(item.getItemLineNumber()) && (item.getItemLineNumber() > 0) && (item.getItemLineNumber() <= itemLinePosition)) {
429 itemLinePosition = item.getItemLineNumber().intValue() - 1;
430 }
431
432 item.setPurapDocumentIdentifier(this.purapDocumentIdentifier);
433 item.setPurapDocument(this);
434
435 items.add(itemLinePosition, item);
436 renumberItems(itemLinePosition);
437 }
438
439
440
441
442 @Override
443 public void deleteItem(int lineNum) {
444 if (items.remove(lineNum) == null) {
445
446 }
447 renumberItems(lineNum);
448 }
449
450
451
452
453 @Override
454 public void renumberItems(int start) {
455 for (int i = start; i < items.size(); i++) {
456 PurApItem item = items.get(i);
457 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
458
459
460 if (item.getItemType().isLineItemIndicator()) {
461 item.setItemLineNumber(new Integer(i + 1));
462 }
463 }
464 }
465
466
467
468
469 @Override
470 public void itemSwap(int positionFrom, int positionTo) {
471
472 if ((positionTo < 0) || (positionTo >= getItemLinePosition())) {
473 return;
474 }
475 PurApItem item1 = this.getItem(positionFrom);
476 PurApItem item2 = this.getItem(positionTo);
477 Integer oldFirstPos = item1.getItemLineNumber();
478
479 item1.setItemLineNumber(item2.getItemLineNumber());
480 item2.setItemLineNumber(oldFirstPos);
481
482 items.remove(positionFrom);
483 items.add(positionTo, item1);
484 }
485
486
487
488
489 @Override
490 public int getItemLinePosition() {
491 int belowTheLineCount = 0;
492 for (PurApItem item : items) {
493 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
494 if (item.getItemType().isAdditionalChargeIndicator()) {
495 belowTheLineCount++;
496 }
497 }
498 return items.size() - belowTheLineCount;
499 }
500
501
502
503
504 @Override
505 public PurApItem getItem(int pos) {
506 return items.get(pos);
507 }
508
509
510
511
512
513
514
515
516 @SuppressWarnings("rawtypes")
517 public PurApItem getItemByLineNumber(int lineNumber) {
518 for (Iterator iter = items.iterator(); iter.hasNext();) {
519 PurApItem item = (PurApItem) iter.next();
520 if (item.getItemLineNumber().intValue() == lineNumber) {
521 return item;
522 }
523 }
524 return null;
525 }
526
527
528
529
530
531
532 @SuppressWarnings("rawtypes")
533 public PurApItem getItemByStringIdentifier(String itemStrID) {
534 for (Iterator iter = items.iterator(); iter.hasNext();) {
535 PurApItem item = (PurApItem) iter.next();
536 if (StringUtils.equalsIgnoreCase(item.getItemIdentifierString(), itemStrID)) {
537 return item;
538 }
539 }
540 return null;
541 }
542
543
544
545
546
547
548 @SuppressWarnings("rawtypes")
549 public PurApItem getItemByItemIdentifier(Integer itemID) {
550 for (Iterator iter = items.iterator(); iter.hasNext();) {
551 PurApItem item = (PurApItem) iter.next();
552 if (item.getItemIdentifier() == itemID) {
553 return item;
554 }
555 }
556 return null;
557 }
558
559
560
561
562
563
564
565 @Override
566 public void setPostingYear(Integer postingYear) {
567 this.postingYear = postingYear;
568 }
569
570
571
572
573 @Override
574 public KualiDecimal getTotalDollarAmount() {
575 return getTotalDollarAmountAllItems(null);
576 }
577
578
579
580
581 @Override
582 public void setTotalDollarAmount(KualiDecimal amount) {
583
584 }
585
586
587
588
589 @Override
590 public KualiDecimal getTotalDollarAmountAllItems(String[] excludedTypes) {
591 return getTotalDollarAmountWithExclusions(excludedTypes, true);
592 }
593
594
595
596
597
598
599 @Override
600 public KualiDecimal getTotalDollarAmountAboveLineItems() {
601 return getTotalDollarAmountAboveLineItems(null);
602 }
603
604
605
606
607
608
609
610 public KualiDecimal getTotalDollarAmountAboveLineItems(String[] excludedTypes) {
611 return getTotalDollarAmountWithExclusions(excludedTypes, false);
612 }
613
614
615
616
617
618
619
620
621 public KualiDecimal getTotalDollarAmountWithExclusions(String[] excludedTypes, boolean includeBelowTheLine) {
622 List<PurApItem> itemsForTotal = getItems();
623
624 return getTotalDollarAmountWithExclusionsSubsetItems(excludedTypes, includeBelowTheLine, itemsForTotal);
625 }
626
627
628
629
630
631
632
633
634 protected KualiDecimal getTotalDollarAmountWithExclusionsSubsetItems(String[] excludedTypes, boolean includeBelowTheLine, List<PurApItem> itemsForTotal) {
635 if (excludedTypes == null) {
636 excludedTypes = new String[] {};
637 }
638
639 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
640 for (PurApItem item : itemsForTotal) {
641 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
642 ItemType it = item.getItemType();
643 if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
644 KualiDecimal totalAmount = item.getTotalAmount();
645 KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
646 total = total.add(itemTotal);
647 }
648 }
649 return total;
650 }
651
652 @Override
653 public KualiDecimal getTotalDollarAmountForTradeIn() {
654 List<PurApItem> tradeInItems = getTradeInItems();
655 return getTotalDollarAmountWithExclusionsSubsetItems(null,false,tradeInItems);
656 }
657
658
659
660
661
662 @Override
663 public List<PurApItem> getTradeInItems() {
664 List<PurApItem> tradeInItems = new ArrayList<PurApItem>();
665 for (PurApItem purApItem : (List<PurApItem>)getItems()) {
666 if(purApItem.getItemAssignedToTradeInIndicator()) {
667 tradeInItems.add(purApItem);
668 }
669 }
670 return tradeInItems;
671 }
672
673
674
675
676 @Override
677 public KualiDecimal getTotalPreTaxDollarAmount() {
678 return getTotalPreTaxDollarAmountAllItems(null);
679 }
680
681
682
683
684 @Override
685 public void setTotalPreTaxDollarAmount(KualiDecimal amount) {
686
687 }
688
689
690
691
692 @Override
693 public KualiDecimal getTotalPreTaxDollarAmountAllItems(String[] excludedTypes) {
694 return getTotalPreTaxDollarAmountWithExclusions(excludedTypes, true);
695 }
696
697
698
699
700
701
702 public KualiDecimal getTotalPreTaxDollarAmountAboveLineItems() {
703 return getTotalPreTaxDollarAmountAboveLineItems(null);
704 }
705
706
707
708
709
710
711
712 public KualiDecimal getTotalPreTaxDollarAmountAboveLineItems(String[] excludedTypes) {
713 return getTotalPreTaxDollarAmountWithExclusions(excludedTypes, false);
714 }
715
716
717
718
719
720
721
722
723 public KualiDecimal getTotalPreTaxDollarAmountWithExclusions(String[] excludedTypes, boolean includeBelowTheLine) {
724 if (excludedTypes == null) {
725 excludedTypes = new String[] {};
726 }
727
728 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
729 for (PurApItem item : (List<PurApItem>) getItems()) {
730 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
731 ItemType it = item.getItemType();
732 if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
733 KualiDecimal extendedPrice = item.getExtendedPrice();
734 KualiDecimal itemTotal = (extendedPrice != null) ? extendedPrice : KualiDecimal.ZERO;
735 total = total.add(itemTotal);
736 }
737 }
738 return total;
739 }
740
741 @Override
742 public KualiDecimal getTotalTaxAmount() {
743 return getTotalTaxAmountAllItems(null);
744 }
745
746 @Override
747 public void setTotalTaxAmount(KualiDecimal amount) {
748
749 }
750
751 @Override
752 public KualiDecimal getTotalTaxAmountAllItems(String[] excludedTypes) {
753 return getTotalTaxAmountWithExclusions(excludedTypes, true);
754 }
755
756 @Override
757 public KualiDecimal getTotalTaxAmountAboveLineItems() {
758 return getTotalTaxAmountAboveLineItems(null);
759 }
760
761 @Override
762 public KualiDecimal getTotalTaxAmountAboveLineItems(String[] excludedTypes) {
763 return getTotalTaxAmountWithExclusions(excludedTypes, false);
764 }
765
766 @Override
767 public KualiDecimal getTotalTaxAmountWithExclusions(String[] excludedTypes, boolean includeBelowTheLine) {
768 if (excludedTypes == null) {
769 excludedTypes = new String[] {};
770 }
771
772 KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
773 for (PurApItem item : (List<PurApItem>) getItems()) {
774 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
775 ItemType it = item.getItemType();
776 if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
777 KualiDecimal taxAmount = item.getItemTaxAmount();
778 KualiDecimal itemTotal = (taxAmount != null) ? taxAmount : KualiDecimal.ZERO;
779 total = total.add(itemTotal);
780 }
781 }
782 return total;
783 }
784
785 @Override
786 public boolean isUseTaxIndicator() {
787 return useTaxIndicator;
788 }
789
790 @Override
791 public void setUseTaxIndicator(boolean useTaxIndicator) {
792 this.useTaxIndicator = useTaxIndicator;
793 }
794
795
796
797
798 @Override
799 public void templateVendorAddress(VendorAddress vendorAddress) {
800 if (vendorAddress == null) {
801 return;
802 }
803 this.setVendorLine1Address(vendorAddress.getVendorLine1Address());
804 this.setVendorLine2Address(vendorAddress.getVendorLine2Address());
805 this.setVendorCityName(vendorAddress.getVendorCityName());
806 this.setVendorStateCode(vendorAddress.getVendorStateCode());
807 this.setVendorPostalCode(vendorAddress.getVendorZipCode());
808 this.setVendorCountryCode(vendorAddress.getVendorCountryCode());
809 }
810
811
812
813
814
815
816
817 @Override
818 public String getVendorNumber() {
819 if (StringUtils.isNotEmpty(vendorNumber)) {
820 return vendorNumber;
821 }
822 else if (ObjectUtils.isNotNull(vendorDetail)) {
823 return vendorDetail.getVendorNumber();
824 }
825 else {
826 return "";
827 }
828 }
829
830 @Override
831 public void setVendorNumber(String vendorNumber) {
832 this.vendorNumber = vendorNumber;
833 }
834
835 public Boolean getOverrideWorkflowButtons() {
836 return overrideWorkflowButtons;
837 }
838
839 public void setOverrideWorkflowButtons(Boolean overrideWorkflowButtons) {
840 this.overrideWorkflowButtons = overrideWorkflowButtons;
841 }
842
843 @Override
844 public Integer getVendorHeaderGeneratedIdentifier() {
845 return vendorHeaderGeneratedIdentifier;
846 }
847
848 @Override
849 public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
850 this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
851 }
852
853 @Override
854 public Integer getVendorDetailAssignedIdentifier() {
855 return vendorDetailAssignedIdentifier;
856 }
857
858 @Override
859 public void setVendorDetailAssignedIdentifier(Integer vendorDetailAssignedIdentifier) {
860 this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
861 }
862
863 @Override
864 public String getVendorCustomerNumber() {
865 return vendorCustomerNumber;
866 }
867
868 @Override
869 public void setVendorCustomerNumber(String vendorCustomerNumber) {
870 this.vendorCustomerNumber = vendorCustomerNumber;
871 }
872
873 @Override
874 public Integer getPurapDocumentIdentifier() {
875 return purapDocumentIdentifier;
876 }
877
878 @Override
879 public void setPurapDocumentIdentifier(Integer identifier) {
880 this.purapDocumentIdentifier = identifier;
881 }
882
883 @Override
884 public VendorDetail getVendorDetail() {
885 return vendorDetail;
886 }
887
888 public void setVendorDetail(VendorDetail vendorDetail) {
889 this.vendorDetail = vendorDetail;
890 }
891
892 @Override
893 @SuppressWarnings("rawtypes")
894 public List getItems() {
895 return items;
896 }
897
898 @Override
899 @SuppressWarnings("rawtypes")
900 public void setItems(List items) {
901 this.items = items;
902 }
903
904 @Override
905 public String getVendorCityName() {
906 return vendorCityName;
907 }
908
909 @Override
910 public void setVendorCityName(String vendorCityName) {
911 this.vendorCityName = vendorCityName;
912 }
913
914 @Override
915 public String getVendorCountryCode() {
916 return vendorCountryCode;
917 }
918
919 @Override
920 public void setVendorCountryCode(String vendorCountryCode) {
921 this.vendorCountryCode = vendorCountryCode;
922 }
923
924 @Override
925 public String getVendorLine1Address() {
926 return vendorLine1Address;
927 }
928
929 @Override
930 public void setVendorLine1Address(String vendorLine1Address) {
931 this.vendorLine1Address = vendorLine1Address;
932 }
933
934 @Override
935 public String getVendorLine2Address() {
936 return vendorLine2Address;
937 }
938
939 @Override
940 public void setVendorLine2Address(String vendorLine2Address) {
941 this.vendorLine2Address = vendorLine2Address;
942 }
943
944 @Override
945 public String getVendorName() {
946 return vendorName;
947 }
948
949 @Override
950 public void setVendorName(String vendorName) {
951 this.vendorName = vendorName;
952 }
953
954 @Override
955 public String getVendorPostalCode() {
956 return vendorPostalCode;
957 }
958
959 @Override
960 public void setVendorPostalCode(String vendorPostalCode) {
961 this.vendorPostalCode = vendorPostalCode;
962 }
963
964 @Override
965 public String getVendorStateCode() {
966 return vendorStateCode;
967 }
968
969 @Override
970 public void setVendorStateCode(String vendorStateCode) {
971 this.vendorStateCode = vendorStateCode;
972 }
973
974 @Override
975 public String getVendorAddressInternationalProvinceName() {
976 return vendorAddressInternationalProvinceName;
977 }
978
979 @Override
980 public void setVendorAddressInternationalProvinceName(String vendorAddressInternationalProvinceName) {
981 this.vendorAddressInternationalProvinceName = vendorAddressInternationalProvinceName;
982 }
983
984 @Override
985 public Integer getVendorAddressGeneratedIdentifier() {
986 return vendorAddressGeneratedIdentifier;
987 }
988
989 @Override
990 public void setVendorAddressGeneratedIdentifier(Integer vendorAddressGeneratedIdentifier) {
991 this.vendorAddressGeneratedIdentifier = vendorAddressGeneratedIdentifier;
992 }
993
994 @Override
995 public Integer getAccountsPayablePurchasingDocumentLinkIdentifier() {
996 return accountsPayablePurchasingDocumentLinkIdentifier;
997 }
998
999 @Override
1000 public void setAccountsPayablePurchasingDocumentLinkIdentifier(Integer accountsPayablePurchasingDocumentLinkIdentifier) {
1001 this.accountsPayablePurchasingDocumentLinkIdentifier = accountsPayablePurchasingDocumentLinkIdentifier;
1002 }
1003
1004 @Override
1005 public String[] getBelowTheLineTypes() {
1006 if (this.belowTheLineTypes == null) {
1007 this.belowTheLineTypes = SpringContext.getBean(PurapService.class).getBelowTheLineForDocument(this);
1008 }
1009 return belowTheLineTypes;
1010 }
1011
1012 @Override
1013 public CountryEbo getVendorCountry() {
1014 if ( StringUtils.isBlank(vendorCountryCode) ) {
1015 vendorCountry = null;
1016 } else {
1017 if ( vendorCountry == null || !StringUtils.equals( vendorCountry.getCode(),vendorCountryCode) ) {
1018 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
1019 if ( moduleService != null ) {
1020 Map<String,Object> keys = new HashMap<String, Object>(1);
1021 keys.put(LocationConstants.PrimaryKeyConstants.CODE, vendorCountryCode);
1022 vendorCountry = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
1023 } else {
1024 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
1025 }
1026 }
1027 }
1028 return vendorCountry;
1029 }
1030
1031
1032
1033
1034
1035
1036 @Deprecated
1037 public void setVendorCountry(CountryEbo vendorCountry) {
1038 this.vendorCountry = vendorCountry;
1039 }
1040
1041 public String getVendorAttentionName() {
1042 return vendorAttentionName;
1043 }
1044
1045 public void setVendorAttentionName(String vendorAttentionName) {
1046 this.vendorAttentionName = vendorAttentionName;
1047 }
1048
1049
1050
1051
1052
1053
1054
1055 public String getAccountDistributionMethod() {
1056 return accountDistributionMethod;
1057 }
1058
1059
1060
1061
1062
1063
1064 public void setAccountDistributionMethod(String accountDistributionMethod) {
1065 this.accountDistributionMethod = accountDistributionMethod;
1066 }
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077 @Override
1078 public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) {
1079 return false;
1080 }
1081
1082 public PurApRelatedViews getRelatedViews() {
1083 if (relatedViews == null) {
1084 relatedViews = new PurApRelatedViews(this.documentNumber, this.accountsPayablePurchasingDocumentLinkIdentifier);
1085 }
1086 return relatedViews;
1087 }
1088
1089 public void setRelatedViews(PurApRelatedViews relatedViews) {
1090 this.relatedViews = relatedViews;
1091 }
1092
1093 @Override
1094 public void refreshNonUpdateableReferences() {
1095 super.refreshNonUpdateableReferences();
1096
1097 for (PurApItem item : (List<PurApItem>)this.getItems()) {
1098
1099 for (PurApAccountingLine account : item.getSourceAccountingLines()) {
1100 account.refreshNonUpdateableReferences();
1101 }
1102 }
1103
1104 fixItemReferences();
1105 }
1106
1107
1108
1109
1110 @Override
1111 public void fixItemReferences() {
1112
1113 if(ObjectUtils.isNull(this.purapDocumentIdentifier)) {
1114 for (PurApItem item : (List<PurApItem>)this.getItems()) {
1115 item.setPurapDocument(this);
1116 item.fixAccountReferences();
1117 }
1118 }
1119 }
1120
1121
1122
1123
1124
1125
1126 @Override
1127 public PurApItem getTradeInItem() {
1128 for (PurApItem item : (List<PurApItem>)getItems()) {
1129 if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
1130 return item;
1131 }
1132 }
1133 return null;
1134 }
1135
1136
1137
1138
1139 @Override
1140 public boolean getIsATypeOfPurAPRecDoc() {
1141 return true;
1142 }
1143
1144
1145
1146
1147 @Override
1148 public boolean getIsATypeOfPurDoc() {
1149 if (this instanceof PurchasingDocumentBase) {
1150 return true;
1151 }
1152 else {
1153 return false;
1154 }
1155 }
1156
1157
1158
1159
1160 @Override
1161 public boolean getIsATypeOfPODoc() {
1162 if (this instanceof PurchaseOrderDocument) {
1163 return true;
1164 }
1165 else {
1166 return false;
1167 }
1168 }
1169
1170
1171
1172
1173 @Override
1174 public boolean getIsPODoc() {
1175 if ( (this instanceof PurchaseOrderDocument) &&
1176 !(this instanceof PurchaseOrderAmendmentDocument) &&
1177 !(this instanceof PurchaseOrderCloseDocument) &&
1178 !(this instanceof PurchaseOrderPaymentHoldDocument) &&
1179 !(this instanceof PurchaseOrderRemoveHoldDocument) &&
1180 !(this instanceof PurchaseOrderReopenDocument) &&
1181 !(this instanceof PurchaseOrderRetransmitDocument) &&
1182 !(this instanceof PurchaseOrderSplitDocument) &&
1183 !(this instanceof PurchaseOrderVoidDocument)) {
1184 return true;
1185 }
1186 else {
1187 return false;
1188 }
1189 }
1190
1191
1192
1193
1194 @Override
1195 public boolean getIsReqsDoc() {
1196 if (this instanceof RequisitionDocument) {
1197 return true;
1198 }
1199 else {
1200 return false;
1201 }
1202 }
1203
1204
1205
1206
1207
1208
1209
1210 protected String buildDocumentTitle(String title) {
1211 if(this.getVendorDetail() == null) {
1212 return title;
1213 }
1214
1215 Integer vendorHeaderGeneratedIdentifier = this.getVendorDetail().getVendorHeaderGeneratedIdentifier();
1216 VendorService vendorService = SpringContext.getBean(VendorService.class);
1217
1218 Object[] indicators = new String[2];
1219
1220 boolean isEmployeeVendor = vendorService.isVendorInstitutionEmployee(vendorHeaderGeneratedIdentifier);
1221 indicators[0] = isEmployeeVendor ? AdHocPaymentIndicator.EMPLOYEE_VENDOR : AdHocPaymentIndicator.OTHER;
1222
1223 boolean isVendorForeign = vendorService.isVendorForeign(vendorHeaderGeneratedIdentifier);
1224 indicators[1] = isVendorForeign ? AdHocPaymentIndicator.ALIEN_VENDOR : AdHocPaymentIndicator.OTHER;
1225
1226 for(Object indicator : indicators) {
1227 if(!AdHocPaymentIndicator.OTHER.equals(indicator)) {
1228 String titlePattern = title + " [{0}:{1}]";
1229 return MessageFormat.format(titlePattern, indicators);
1230 }
1231 }
1232
1233 return title;
1234 }
1235
1236
1237
1238
1239
1240 @SuppressWarnings("rawtypes")
1241 @Override
1242 public List getSourceAccountingLines() {
1243 if (ObjectUtils.isNotNull(sourceAccountingLines) && !sourceAccountingLines.isEmpty()) {
1244
1245 return sourceAccountingLines;
1246 }
1247 else {
1248
1249
1250
1251
1252 List<AccountingLine> sourceAccountingLines = new ArrayList<AccountingLine>();
1253 for (Object itemAsObject : this.getItems()) {
1254 final PurApItem item = (PurApItem)itemAsObject;
1255 for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
1256
1257
1258 if (!isDuplicateAccountingLine(sourceAccountingLines, accountingLine)) {
1259 sourceAccountingLines.add(accountingLine);
1260 }
1261 }
1262 }
1263 return sourceAccountingLines;
1264 }
1265 }
1266
1267
1268
1269
1270
1271
1272
1273
1274 protected boolean isDuplicateAccountingLine(List<AccountingLine> sourceAccountingLines, PurApAccountingLine accountingLine) {
1275 for (AccountingLine sourceLine : sourceAccountingLines) {
1276 PurApAccountingLine purapAccountLine = (PurApAccountingLine) sourceLine;
1277
1278 if (purapAccountLine.accountStringsAreEqual(accountingLine)) {
1279 return true;
1280 }
1281 }
1282 return false;
1283 }
1284
1285
1286
1287
1288
1289
1290
1291
1292 protected KualiDecimal getAccountTotalGLEntryAmount(AccountingLine matchingAccountingLine) {
1293 KualiDecimal accountTotalGLEntryAmount = KualiDecimal.ZERO;
1294
1295 for (Object itemAsObject : this.getItems()) {
1296 final PurApItem item = (PurApItem)itemAsObject;
1297 for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
1298
1299 if (accountingLine.accountStringsAreEqual((SourceAccountingLine)matchingAccountingLine)) {
1300 accountTotalGLEntryAmount = accountTotalGLEntryAmount.add(accountingLine.getAmount());
1301 }
1302 }
1303 }
1304
1305 return accountTotalGLEntryAmount;
1306 }
1307
1308
1309
1310
1311
1312 public boolean getNeedWarningRelatedPOs() {
1313 List<PurchaseOrderView> poViews = getRelatedViews().getRelatedPurchaseOrderViews();
1314 for (PurchaseOrderView poView : poViews) {
1315 if (poView.getNeedWarning()) {
1316 return true;
1317 }
1318 }
1319 return false;
1320 }
1321
1322
1323
1324
1325
1326 @SuppressWarnings("rawtypes")
1327 @Override
1328 protected List getPersistedSourceAccountingLinesForComparison() {
1329 LOG.info("Checking persisted source accounting lines for read-only fields");
1330 List<String> restrictedItemTypesList = new ArrayList<String>();
1331 try {
1332 restrictedItemTypesList = new ArrayList<String>( SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.getClass(), PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT) );
1333 } catch (IllegalArgumentException iae) {
1334
1335 }
1336
1337 PurapAccountingService purApAccountingService = SpringContext.getBean(PurapAccountingService.class);
1338 List persistedSourceLines = new ArrayList();
1339
1340 for (PurApItem item : (List<PurApItem>) this.getItems()) {
1341
1342 if (ObjectUtils.isNotNull(item.getItemIdentifier())) {
1343
1344 final boolean isNotReadOnly = !((restrictedItemTypesList != null) && restrictedItemTypesList.contains(item.getItemTypeCode()));
1345 if (isNotReadOnly) {
1346 persistedSourceLines.addAll(purApAccountingService.getAccountsFromItem(item));
1347 }
1348 }
1349 }
1350 return persistedSourceLines;
1351 }
1352
1353
1354
1355
1356
1357 @SuppressWarnings("rawtypes")
1358 @Override
1359 protected List getSourceAccountingLinesForComparison() {
1360 LOG.info("Checking source accounting lines for read-only fields");
1361 List<String> restrictedItemTypesList = new ArrayList<String>();
1362 try {
1363 restrictedItemTypesList = new ArrayList<String>( SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.getClass(), PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT) );
1364 } catch (IllegalArgumentException iae) {
1365
1366 }
1367 PurapAccountingService purApAccountingService = SpringContext.getBean(PurapAccountingService.class);
1368 List currentSourceLines = new ArrayList();
1369 for (PurApItem item : (List<PurApItem>) this.getItems()) {
1370
1371 final boolean isNotReadOnly = !((restrictedItemTypesList != null) && restrictedItemTypesList.contains(item.getItemTypeCode()));
1372 if (isNotReadOnly) {
1373 currentSourceLines.addAll(item.getSourceAccountingLines());
1374 }
1375 }
1376 return currentSourceLines;
1377 }
1378
1379
1380
1381
1382
1383
1384
1385 @Override
1386 public boolean isCalculated() {
1387 return calculated;
1388 }
1389
1390
1391
1392
1393
1394
1395 @Override
1396 public void setCalculated(boolean calculated) {
1397 this.calculated = calculated;
1398 }
1399
1400 @Override
1401 public NoteType getNoteType() {
1402 return NoteType.BUSINESS_OBJECT;
1403 }
1404
1405 }