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 static org.kuali.ole.sys.OLEConstants.AUXILIARY_LINE_HELPER_PROPERTY_NAME;
19 import static org.kuali.ole.sys.OLEConstants.CREDIT_AMOUNT_PROPERTY_NAME;
20 import static org.kuali.ole.sys.OLEConstants.DEBIT_AMOUNT_PROPERTY_NAME;
21 import static org.kuali.ole.sys.OLEConstants.GL_DEBIT_CODE;
22 import static org.kuali.ole.sys.OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME;
23 import static org.kuali.ole.sys.OLEConstants.SQUARE_BRACKET_LEFT;
24 import static org.kuali.ole.sys.OLEConstants.SQUARE_BRACKET_RIGHT;
25 import static org.kuali.ole.sys.OLEConstants.VOUCHER_LINE_HELPER_CREDIT_PROPERTY_NAME;
26 import static org.kuali.ole.sys.OLEConstants.VOUCHER_LINE_HELPER_DEBIT_PROPERTY_NAME;
27 import static org.kuali.ole.sys.OLEKeyConstants.ERROR_ZERO_OR_NEGATIVE_AMOUNT;
28
29 import org.apache.commons.lang.StringUtils;
30 import org.kuali.ole.sys.businessobject.AccountingLine;
31 import org.kuali.ole.sys.document.validation.GenericValidation;
32 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
33 import org.kuali.rice.core.api.util.type.KualiDecimal;
34 import org.kuali.rice.krad.util.GlobalVariables;
35
36
37
38
39 public class AuxiliaryVoucherAccountingLineAmountValidation extends GenericValidation {
40 private AccountingLine accountingLineForValidation;
41
42
43
44
45
46 public boolean validate(AttributedDocumentEvent event) {
47 boolean retval = true;
48 KualiDecimal amount = accountingLineForValidation.getAmount();
49
50
51 if (KualiDecimal.ZERO.equals(amount)) {
52 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(buildMessageMapKeyPathForDebitCreditAmount(true), ERROR_ZERO_OR_NEGATIVE_AMOUNT, "an accounting line");
53 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(buildMessageMapKeyPathForDebitCreditAmount(false), ERROR_ZERO_OR_NEGATIVE_AMOUNT, "an accounting line");
54
55 retval = false;
56 }
57 else if (amount.isNegative()) {
58 String debitCreditCode = accountingLineForValidation.getDebitCreditCode();
59 if (StringUtils.isNotBlank(debitCreditCode) && GL_DEBIT_CODE.equals(debitCreditCode)) {
60 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(buildMessageMapKeyPathForDebitCreditAmount(true), ERROR_ZERO_OR_NEGATIVE_AMOUNT, "an accounting line");
61 }
62 else {
63 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(buildMessageMapKeyPathForDebitCreditAmount(false), ERROR_ZERO_OR_NEGATIVE_AMOUNT, "an accounting line");
64 }
65
66 retval = false;
67 }
68
69 return retval;
70 }
71
72
73
74
75
76
77
78
79 protected String buildMessageMapKeyPathForDebitCreditAmount(boolean isDebit) {
80
81 boolean isNewLineAdd = GlobalVariables.getMessageMap().getErrorPath().contains(NEW_SOURCE_ACCT_LINE_PROPERTY_NAME);
82 isNewLineAdd |= GlobalVariables.getMessageMap().getErrorPath().contains(NEW_SOURCE_ACCT_LINE_PROPERTY_NAME);
83
84 if (isNewLineAdd) {
85 if (isDebit) {
86 return DEBIT_AMOUNT_PROPERTY_NAME;
87 }
88 else {
89 return CREDIT_AMOUNT_PROPERTY_NAME;
90 }
91 }
92 else {
93 String index = StringUtils.substringBetween(GlobalVariables.getMessageMap().getKeyPath("", true), SQUARE_BRACKET_LEFT, SQUARE_BRACKET_RIGHT);
94 String indexWithParams = SQUARE_BRACKET_LEFT + index + SQUARE_BRACKET_RIGHT;
95 if (isDebit) {
96 return AUXILIARY_LINE_HELPER_PROPERTY_NAME + indexWithParams + VOUCHER_LINE_HELPER_DEBIT_PROPERTY_NAME;
97 }
98 else {
99 return AUXILIARY_LINE_HELPER_PROPERTY_NAME + indexWithParams + VOUCHER_LINE_HELPER_CREDIT_PROPERTY_NAME;
100 }
101 }
102 }
103
104
105
106
107
108 public AccountingLine getAccountingLineForValidation() {
109 return accountingLineForValidation;
110 }
111
112
113
114
115
116 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
117 this.accountingLineForValidation = accountingLineForValidation;
118 }
119 }