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.PurApItem;
21 import org.kuali.ole.module.purap.document.PurchasingDocument;
22 import org.kuali.ole.sys.document.validation.GenericValidation;
23 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24 import org.kuali.rice.krad.util.GlobalVariables;
25
26 import java.util.List;
27
28 public class PurchasingReceivingValidation extends GenericValidation {
29
30 public boolean validate(AttributedDocumentEvent event) {
31 boolean valid = true;
32
33 PurchasingDocument purDoc = (PurchasingDocument) event.getDocument();
34
35 if (!purDoc.isReceivingDocumentRequiredIndicator()) {
36 return true;
37 }
38
39 GlobalVariables.getMessageMap().clearErrorPath();
40
41
42 List<PurApItem> items = purDoc.getItems();
43
44 boolean containsQtyTypeItem = false;
45 for (PurApItem item : items) {
46 if (item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
47 containsQtyTypeItem = true;
48 break;
49 }
50 }
51
52 if (!containsQtyTypeItem) {
53 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_RECEIVING_REQUIRED);
54 valid &= false;
55 }
56
57 GlobalVariables.getMessageMap().clearErrorPath();
58
59 return valid;
60 }
61
62 }