1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.businessobject.PaymentRequestItem;
21 import org.kuali.ole.module.purap.businessobject.PurApItem;
22 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.core.api.util.type.KualiDecimal;
27 import org.kuali.rice.kns.util.KNSGlobalVariables;
28 import org.kuali.rice.krad.util.GlobalVariables;
29 import org.kuali.rice.krad.util.ObjectUtils;
30
31 import java.util.List;
32
33 public class PaymentRequestTotalsValidation extends GenericValidation {
34
35 @Override
36 public boolean validate(AttributedDocumentEvent event) {
37 PaymentRequestDocument document = (PaymentRequestDocument) event.getDocument();
38 GlobalVariables.getMessageMap().clearErrorPath();
39 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
40
41 String[] excludeArray = {PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
42
43
44 if (ObjectUtils.isNull(document.getVendorInvoiceAmount())) {
45 if (!KNSGlobalVariables.getMessageList().contains(PurapKeyConstants.WARNING_PAYMENT_REQUEST_VENDOR_INVOICE_AMOUNT_INVALID)) {
46 KNSGlobalVariables.getMessageList().add(PurapKeyConstants.WARNING_PAYMENT_REQUEST_VENDOR_INVOICE_AMOUNT_INVALID);
47 }
48 }
49
50
51 else if (document.isUseTaxIndicator()) {
52 if (document.getTotalPreTaxDollarAmountAllItems(excludeArray).compareTo(document.getVendorInvoiceAmount()) != 0
53 && !document.isUnmatchedOverride()) {
54 if (!KNSGlobalVariables.getMessageList().contains(
55 PurapKeyConstants.WARNING_PAYMENT_REQUEST_VENDOR_INVOICE_AMOUNT_INVALID)) {
56 KNSGlobalVariables.getMessageList().add(
57 PurapKeyConstants.WARNING_PAYMENT_REQUEST_VENDOR_INVOICE_AMOUNT_INVALID);
58 }
59 }
60 }
61
62
63 else {
64 if (document.getTotalDollarAmountAllItems(excludeArray).compareTo(document.getVendorInvoiceAmount()) != 0
65 && !document.isUnmatchedOverride()) {
66 if (!KNSGlobalVariables.getMessageList().contains(
67 PurapKeyConstants.WARNING_PAYMENT_REQUEST_VENDOR_INVOICE_AMOUNT_INVALID)) {
68 KNSGlobalVariables.getMessageList().add(
69 PurapKeyConstants.WARNING_PAYMENT_REQUEST_VENDOR_INVOICE_AMOUNT_INVALID);
70 }
71 }
72 }
73
74 flagLineItemTotals(document.getItems());
75
76 GlobalVariables.getMessageMap().clearErrorPath();
77
78
79 return true;
80 }
81
82
83
84
85
86
87
88
89 protected KualiDecimal getTotalExcludingItemTypes(List<PurApItem> itemList, List<String> excludedItemTypes) {
90 KualiDecimal total = KualiDecimal.ZERO;
91 for (PurApItem item : itemList) {
92 if (item.getTotalAmount() != null && item.getTotalAmount().isNonZero()) {
93 boolean skipThisItem = false;
94 if (excludedItemTypes.contains(item.getItemTypeCode())) {
95
96 skipThisItem = true;
97 break;
98 }
99 if (skipThisItem) {
100 continue;
101 }
102 total = total.add(item.getTotalAmount());
103 }
104 }
105 return total;
106 }
107
108
109
110
111
112
113 protected void flagLineItemTotals(List<PurApItem> itemList) {
114 for (PurApItem purApItem : itemList) {
115 PaymentRequestItem item = (PaymentRequestItem) purApItem;
116 if (item.getItemQuantity() != null && item.getExtendedPrice() != null) {
117 if (item.calculateExtendedPrice().compareTo(item.getExtendedPrice()) != 0) {
118 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_PAYMENT_REQUEST_ITEM_TOTAL_NOT_EQUAL, item.getItemIdentifierString());
119 }
120 }
121 }
122 }
123
124 }