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.document.PurchasingAccountsPayableDocument;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 public class PurchasingProcessTradeInValidation extends GenericValidation {
28
29
30
31
32
33
34
35 public boolean validate(AttributedDocumentEvent event) {
36 boolean isAssignedToTradeInItemFound = false;
37 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
38 for (PurApItem item : purapDocument.getItems()) {
39
40 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
41
42 if (item.getItemType().isLineItemIndicator()) {
43 if (item.getItemAssignedToTradeInIndicator()) {
44 isAssignedToTradeInItemFound = true;
45 break;
46 }
47 }
48 }
49 if (!isAssignedToTradeInItemFound) {
50 PurApItem tradeInItem = purapDocument.getTradeInItem();
51 if (tradeInItem != null && tradeInItem.getItemUnitPrice() != null) {
52 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_TRADE_IN_NEEDS_TO_BE_ASSIGNED);
53 return false;
54 }
55 }
56 return true;
57 }
58 }