1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.validation.impl;
17
18 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
19 import org.kuali.ole.sys.OLEConstants;
20 import org.kuali.ole.sys.OLEKeyConstants;
21 import org.kuali.ole.sys.OLEPropertyConstants;
22 import org.kuali.ole.sys.document.AccountingDocument;
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.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.MessageMap;
28
29 public class DisbursementVoucherDocumentAmountValidation extends GenericValidation {
30 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherDocumentAmountValidation.class);
31
32 private AccountingDocument accountingDocumentForValidation;
33
34
35
36
37 public boolean validate(AttributedDocumentEvent event) {
38 LOG.debug("validate start");
39
40 boolean isValid = true;
41 DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) accountingDocumentForValidation;
42
43 MessageMap errors = GlobalVariables.getMessageMap();
44 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
45
46
47 if (!disbursementVoucherDocument.getDisbVchrCheckTotalAmount().isPositive()) {
48 errors.putError(OLEPropertyConstants.DISB_VCHR_CHECK_TOTAL_AMOUNT, OLEKeyConstants.ERROR_NEGATIVE_OR_ZERO_CHECK_TOTAL);
49 isValid = false;
50 }
51
52
53 if (KualiDecimal.ZERO.compareTo(disbursementVoucherDocument.getSourceTotal()) == 1) {
54 errors.putErrorWithoutFullErrorPath(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.ERROR_NEGATIVE_ACCOUNTING_TOTAL);
55 isValid = false;
56 }
57
58
59 if (disbursementVoucherDocument.getDisbVchrCheckTotalAmount().compareTo(disbursementVoucherDocument.getSourceTotal()) != 0) {
60 errors.putErrorWithoutFullErrorPath(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.ERROR_CHECK_ACCOUNTING_TOTAL);
61 isValid = false;
62 }
63
64 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
65
66 return isValid;
67 }
68
69
70
71
72
73
74 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
75 this.accountingDocumentForValidation = accountingDocumentForValidation;
76 }
77
78
79
80
81
82 public AccountingDocument getAccountingDocumentForValidation() {
83 return accountingDocumentForValidation;
84 }
85
86 }