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.PurApAccountingLine;
21 import org.kuali.ole.module.purap.businessobject.PurApItem;
22 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.ole.sys.document.validation.GenericValidation;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.rice.krad.util.GlobalVariables;
28
29 import java.util.List;
30
31 public class PurchaseOrderAmendmentAccountValidation extends GenericValidation {
32
33 public boolean validate(AttributedDocumentEvent event) {
34
35 boolean valid = true;
36 PurchaseOrderDocument poaDocument = (PurchaseOrderDocument) event.getDocument();
37 List<PurApItem> items = poaDocument.getItemsActiveOnly();
38
39 PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(poaDocument.getPurapDocumentIdentifier());
40 List<PurApItem> poItems = po.getItems();
41
42 for (PurApItem item : items) {
43 String identifierString = item.getItemIdentifierString();
44
45
46 if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) && item.getSourceAccountingLines() != null && item.getSourceAccountingLines().size() > 0) {
47
48
49 if (isItemChanged(item, poItems)) {
50 List<PurApAccountingLine> accountingLines = item.getSourceAccountingLines();
51 for (PurApAccountingLine accountingLine : accountingLines) {
52 if (accountingLine.getAccount().isExpired()) {
53 valid = false;
54 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNT_EXPIRED, accountingLine.getAccount().getAccountNumber());
55 break;
56 }
57 if (!accountingLine.getAccount().isActive()) {
58 valid = false;
59 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNT_INACTIVE, accountingLine.getAccount().getAccountNumber());
60 break;
61 }
62 }
63 }
64 }
65 }
66
67 return valid;
68 }
69
70 private boolean isItemChanged(PurApItem poaItem, List<PurApItem> poItems) {
71
72 boolean changed = false;
73
74 int poaItemId = poaItem.getItemLineNumber().intValue();
75
76 for (PurApItem poItem : poItems) {
77
78 if (poItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) && poaItemId == poItem.getItemLineNumber().intValue()) {
79
80 if (poaItem.getItemQuantity().intValue() != poItem.getItemQuantity().intValue()) {
81 changed = true;
82 }
83 if (!poaItem.getItemUnitOfMeasureCode().equals(poItem.getItemUnitOfMeasureCode())) {
84 changed = true;
85 }
86 if (poaItem.getItemUnitPrice().floatValue() != poItem.getItemUnitPrice().floatValue()) {
87 changed = true;
88 }
89 if (poaItem.getTotalAmount().floatValue() != poItem.getTotalAmount().floatValue()) {
90 changed = true;
91 }
92 if (poaItem.getItemAssignedToTradeInIndicator() != poItem.getItemAssignedToTradeInIndicator()) {
93 changed = true;
94 }
95
96 if ((poaItem.getItemCatalogNumber() != null && !poaItem.getItemCatalogNumber().equals(poItem.getItemCatalogNumber())) ||
97 (poItem.getItemCatalogNumber() != null && !poItem.getItemCatalogNumber().equals(poaItem.getItemCatalogNumber()))) {
98 changed = true;
99 }
100 if ((poaItem.getItemDescription() != null && !poaItem.getItemDescription().equals(poItem.getItemDescription())) ||
101 (poItem.getItemDescription() != null && !poItem.getItemDescription().equals(poaItem.getItemDescription()))) {
102 changed = true;
103 }
104 if ((poaItem.getExtendedPrice() != null && poItem.getExtendedPrice() != null && poaItem.getExtendedPrice().floatValue() != poItem.getExtendedPrice().floatValue()) ||
105 (poaItem.getExtendedPrice() != null && poaItem.getExtendedPrice().floatValue() != 0 && poItem.getExtendedPrice() == null) ||
106 (poaItem.getExtendedPrice() == null && poItem.getExtendedPrice() != null && poItem.getExtendedPrice().floatValue() != 0)) {
107 changed = true;
108 }
109 if ((poaItem.getItemTaxAmount() != null && poItem.getItemTaxAmount() != null && poaItem.getItemTaxAmount().floatValue() != poItem.getItemTaxAmount().floatValue()) ||
110 (poaItem.getItemTaxAmount() != null && poaItem.getItemTaxAmount().floatValue() != 0 && poItem.getItemTaxAmount() != null) ||
111 (poaItem.getItemTaxAmount() == null && poItem.getItemTaxAmount() != null && poItem.getItemTaxAmount().floatValue() != 0)) {
112 changed = true;
113 }
114
115 break;
116 }
117 }
118
119 return changed;
120 }
121 }