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.PurapKeyConstants;
19 import org.kuali.ole.module.purap.PurapPropertyConstants;
20 import org.kuali.ole.module.purap.businessobject.CreditMemoItem;
21 import org.kuali.ole.select.document.OleVendorCreditMemoDocument;
22 import org.kuali.ole.sys.OLEPropertyConstants;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.core.api.util.type.KualiDecimal;
26 import org.kuali.rice.kns.service.DataDictionaryService;
27 import org.kuali.rice.krad.util.GlobalVariables;
28
29 public class VendorCreditMemoItemExtendedPriceValidation extends GenericValidation {
30
31 private DataDictionaryService dataDictionaryService;
32 private CreditMemoItem itemForValidation;
33
34 public boolean validate(AttributedDocumentEvent event) {
35 boolean valid = true;
36 OleVendorCreditMemoDocument cmDocument = (OleVendorCreditMemoDocument) event.getDocument();
37
38 String errorKeyPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + (itemForValidation.getItemLineNumber() - 1) + "].";
39 String errorKey = errorKeyPrefix + PurapPropertyConstants.EXTENDED_PRICE;
40
41 if (itemForValidation.getExtendedPrice() != null) {
42 if (itemForValidation.getExtendedPrice().isNegative() && cmDocument.getInvoiceIdentifier() == null) {
43 String label = dataDictionaryService.getAttributeErrorLabel(CreditMemoItem.class, PurapPropertyConstants.EXTENDED_PRICE);
44 GlobalVariables.getMessageMap().putError(errorKey, PurapKeyConstants.ERROR_CREDIT_MEMO_ITEM_AMOUNT_NONPOSITIVE, label);
45 valid = false;
46 }
47 if (!cmDocument.isSourceVendor()) {
48
49 KualiDecimal invoicedAmount = null;
50 if (cmDocument.isSourceDocumentPurchaseOrder()) {
51 invoicedAmount = itemForValidation.getPoTotalAmount();
52 } else {
53 invoicedAmount = itemForValidation.getPreqTotalAmount();
54 }
55
56 if (invoicedAmount == null) {
57 invoicedAmount = KualiDecimal.ZERO;
58 }
59
60 if (itemForValidation.getTotalAmount().isGreaterThan(invoicedAmount)) {
61 GlobalVariables.getMessageMap().putError(errorKey, PurapKeyConstants.ERROR_CREDIT_MEMO_ITEM_EXTENDEDPRICE_TOOMUCH);
62 valid = false;
63 }
64 }
65
66 }
67
68 return valid;
69 }
70
71 public DataDictionaryService getDataDictionaryService() {
72 return dataDictionaryService;
73 }
74
75 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
76 this.dataDictionaryService = dataDictionaryService;
77 }
78
79 public CreditMemoItem getItemForValidation() {
80 return itemForValidation;
81 }
82
83 public void setItemForValidation(CreditMemoItem itemForValidation) {
84 this.itemForValidation = itemForValidation;
85 }
86
87 }