1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.validation.impl;
17
18 import static org.kuali.ole.sys.OLEConstants.AMOUNT_PROPERTY_NAME;
19 import static org.kuali.ole.sys.OLEKeyConstants.ERROR_INVALID_NEGATIVE_AMOUNT_NON_CORRECTION;
20 import static org.kuali.ole.sys.OLEKeyConstants.ERROR_ZERO_AMOUNT;
21
22 import org.kuali.ole.sys.businessobject.AccountingLine;
23 import org.kuali.ole.sys.document.AccountingDocument;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.core.api.util.type.KualiDecimal;
27 import org.kuali.rice.krad.util.GlobalVariables;
28
29
30
31
32 public class AccountingLineAmountPositiveValidation extends GenericValidation {
33 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountingLineAmountPositiveValidation.class);
34
35 private AccountingDocument accountingDocumentForValidation;
36 private AccountingLine accountingLineForValidation;
37
38
39
40
41
42
43
44 @Override
45 public boolean validate(AttributedDocumentEvent event) {
46 KualiDecimal amount = accountingLineForValidation.getAmount();
47 String correctsDocumentId = accountingDocumentForValidation.getFinancialSystemDocumentHeader().getFinancialDocumentInErrorNumber();
48
49 if (amount != null) {
50 if (KualiDecimal.ZERO.compareTo(amount) == 0) {
51 GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_ZERO_AMOUNT, "an accounting line");
52 return false;
53 }
54 else {
55 if (null == correctsDocumentId && KualiDecimal.ZERO.compareTo(amount) == 1) {
56 GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_INVALID_NEGATIVE_AMOUNT_NON_CORRECTION);
57 return false;
58 }
59 }
60 }
61
62 return true;
63 }
64
65
66
67
68
69 public AccountingDocument getAccountingDocumentForValidation() {
70 return accountingDocumentForValidation;
71 }
72
73
74
75
76
77 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
78 this.accountingDocumentForValidation = accountingDocumentForValidation;
79 }
80
81
82
83
84
85 public AccountingLine getAccountingLineForValidation() {
86 return accountingLineForValidation;
87 }
88
89
90
91
92
93 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
94 this.accountingLineForValidation = accountingLineForValidation;
95 }
96 }