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.businessobject.InvoiceItem;
19 import org.kuali.ole.module.purap.document.InvoiceDocument;
20 import org.kuali.ole.sys.document.validation.GenericValidation;
21 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
22
23 import java.math.BigDecimal;
24
25 public class InvoiceReviewValidation extends GenericValidation {
26 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InvoiceReviewValidation.class);
27
28 private InvoiceItem itemForValidation;
29
30 public boolean validate(AttributedDocumentEvent event) {
31 boolean valid = true;
32 InvoiceDocument invoice = (InvoiceDocument) event.getDocument();
33
34
35 boolean containsAccounts = false;
36 int accountLineNbr = 0;
37
38 String identifier = itemForValidation.getItemIdentifierString();
39 BigDecimal total = BigDecimal.ZERO;
40 if (LOG.isDebugEnabled()) {
41 LOG.debug("validateInvoiceReview() The " + identifier + " is getting the total percent field set to " + BigDecimal.ZERO);
42 }
43
44
45
46
47
48
49 if ((itemForValidation.getItemType().isLineItemIndicator() && itemForValidation.getTotalAmount() != null &&
50 itemForValidation.getTotalAmount().isNonZero() &&
51 ((itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator() || (itemForValidation.getItemType().isQuantityBasedGeneralLedgerIndicator()))))) {
52
53
54
55
56 if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) {
57 String error = "Payment Request " + invoice.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "' but outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount();
58 LOG.error("validateInvoiceReview() " + error);
59 } else {
60 String error = "Payment Request " + invoice.getPurapDocumentIdentifier() + ", " + identifier + " has quantity '" + itemForValidation.getItemQuantity() + "' but outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity();
61 LOG.error("validateInvoiceReview() " + error);
62 }
63 } else {
64
65 String error = "Payment Request " + invoice.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "'";
66 if (itemForValidation.getItemType().isLineItemIndicator()) {
67 if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) {
68 error = error + " with outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount();
69 } else {
70 error = error + " with outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity();
71 }
72 }
73 LOG.info("validateInvoiceReview() " + error);
74 }
75
76 return valid;
77 }
78
79
80 public InvoiceItem getItemForValidation() {
81 return itemForValidation;
82 }
83
84 public void setItemForValidation(InvoiceItem itemForValidation) {
85 this.itemForValidation = itemForValidation;
86 }
87
88
89 }