1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.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.select.businessobject.OleCreditMemoItem;
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 OleVendorCreditMemoItemExtendedPriceValidation extends GenericValidation {
30
31 private DataDictionaryService dataDictionaryService;
32 private OleCreditMemoItem itemForValidation;
33
34 @Override
35 public boolean validate(AttributedDocumentEvent event) {
36 boolean valid = true;
37 OleVendorCreditMemoDocument cmDocument = (OleVendorCreditMemoDocument) event.getDocument();
38
39 String errorKeyPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + (itemForValidation.getItemLineNumber() - 1) + "].";
40 String errorKey = errorKeyPrefix + PurapPropertyConstants.EXTENDED_PRICE;
41
42 if (itemForValidation.getExtendedPrice() != null) {
43 if (itemForValidation.getExtendedPrice().isNegative() && cmDocument.getInvoiceIdentifier() == null) {
44 String label = dataDictionaryService.getAttributeErrorLabel(OleCreditMemoItem.class, PurapPropertyConstants.EXTENDED_PRICE);
45 GlobalVariables.getMessageMap().putError(errorKey, PurapKeyConstants.ERROR_CREDIT_MEMO_ITEM_AMOUNT_NONPOSITIVE, label);
46 valid = false;
47 }
48 if (!cmDocument.isSourceVendor()) {
49
50 KualiDecimal invoicedAmount = null;
51 if (cmDocument.isSourceDocumentPurchaseOrder()) {
52 invoicedAmount = itemForValidation.getPoTotalAmount();
53 } else {
54 invoicedAmount = itemForValidation.getPreqTotalAmount();
55 }
56
57 if (invoicedAmount == null) {
58 invoicedAmount = KualiDecimal.ZERO;
59 }
60
61 if (itemForValidation.getTotalAmount().isGreaterThan(invoicedAmount) && (itemForValidation.getItemSurcharge() == null)) {
62 GlobalVariables.getMessageMap().putError(errorKey, PurapKeyConstants.ERROR_CREDIT_MEMO_ITEM_EXTENDEDPRICE_TOOMUCH);
63 valid = false;
64 }
65 }
66
67 }
68
69 return valid;
70 }
71
72 public DataDictionaryService getDataDictionaryService() {
73 return dataDictionaryService;
74 }
75
76 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
77 this.dataDictionaryService = dataDictionaryService;
78 }
79
80 public OleCreditMemoItem getItemForValidation() {
81 return itemForValidation;
82 }
83
84 public void setItemForValidation(OleCreditMemoItem itemForValidation) {
85 this.itemForValidation = itemForValidation;
86 }
87
88
89 }