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.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.businessobject.PurApItem;
22 import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
23 import org.kuali.ole.module.purap.businessobject.PurchasingItemBase;
24 import org.kuali.ole.module.purap.document.PurchaseOrderAmendmentDocument;
25 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.rice.core.api.util.type.KualiDecimal;
28 import org.kuali.rice.kew.api.WorkflowDocument;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31 public class PurchaseOrderAmendmentNewIndividualItemValidation extends PurchaseOrderNewIndividualItemValidation {
32
33 private PurchaseOrderService purchaseOrderService;
34
35
36
37
38
39
40 @Override
41 public boolean validate(AttributedDocumentEvent event) {
42 boolean valid = super.validate(event);
43 PurchaseOrderItem item = (PurchaseOrderItem) getItemForValidation();
44 String identifierString = item.getItemIdentifierString();
45 if ((item.getItemInvoicedTotalQuantity() != null) && (!(item.getItemInvoicedTotalQuantity()).isZero())) {
46 if (item.getItemQuantity() == null) {
47 valid = false;
48 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_AMND_NULL, "Item Quantity", identifierString);
49 } else if (item.getItemQuantity().compareTo(item.getItemInvoicedTotalQuantity()) < 0) {
50 valid = false;
51 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_AMND_INVALID, "Item Quantity", identifierString);
52 }
53 }
54
55 if (item.getItemInvoicedTotalAmount() != null) {
56 KualiDecimal total = item.getTotalAmount().abs();
57 if ((total == null) || total.compareTo(item.getItemInvoicedTotalAmount().abs()) < 0) {
58 valid = false;
59 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_AMND_INVALID_AMT, "Item Extended Price", identifierString);
60 }
61 }
62
63 PurchaseOrderAmendmentDocument document = (PurchaseOrderAmendmentDocument) event.getDocument();
64 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
65
66
67 if (!(workflowDocument.isInitiated() || workflowDocument.isSaved()) && purchaseOrderService.isNewUnorderedItem(item)) {
68
69
70 if (item.getSourceAccountingLines() == null || item.getSourceAccountingLines().size() == 0) {
71 valid = false;
72 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_INCOMPLETE, identifierString, identifierString);
73 }
74 }
75
76 return valid;
77 }
78
79
80
81
82
83
84 @Override
85 protected boolean validateCommodityCodes(PurApItem item, boolean commodityCodeRequired) {
86
87 if (!((PurchaseOrderItem) item).isItemActiveIndicator()) {
88 return true;
89 } else {
90 return super.validateCommodityCodes(item, commodityCodeRequired);
91 }
92 }
93
94
95
96
97
98
99
100
101
102
103
104 protected boolean validateThatCommodityCodeIsActive(PurApItem item) {
105 if (item.getVersionNumber() != null) {
106 return true;
107 } else {
108 if (!((PurchasingItemBase) item).getCommodityCode().isActive()) {
109 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_COMMODITY_CODE, PurapKeyConstants.PUR_COMMODITY_CODE_INACTIVE, " in " + item.getItemIdentifierString());
110 return false;
111 }
112 return true;
113 }
114 }
115
116 public PurchaseOrderService getPurchaseOrderService() {
117 return purchaseOrderService;
118 }
119
120 public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
121 this.purchaseOrderService = purchaseOrderService;
122 }
123 }