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.OLEKeyConstants.ERROR_DOCUMENT_FUND_GROUP_SET_DOES_NOT_BALANCE;
19
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.kuali.ole.fp.document.TransferOfFundsDocument;
25 import org.kuali.ole.sys.businessobject.AccountingLine;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.AccountingDocument;
28 import org.kuali.ole.sys.document.validation.GenericValidation;
29 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30 import org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants;
31 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
32 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
33 import org.kuali.rice.core.api.util.type.KualiDecimal;
34 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35 import org.kuali.rice.krad.util.GlobalVariables;
36
37
38
39
40 public class TransferOfFundsFundGroupsBalancedValidation extends GenericValidation {
41 private AccountingDocument accountingDocumentForValidation;
42 private ParameterService parameterService;
43
44
45
46
47
48
49 public boolean validate(AttributedDocumentEvent event) {
50 return isFundGroupSetBalanceValid(accountingDocumentForValidation, TransferOfFundsDocument.class, AccountingDocumentRuleBaseConstants.APPLICATION_PARAMETER.FUND_GROUP_BALANCING_SET);
51 }
52
53
54
55
56
57
58
59
60
61 protected boolean isFundGroupSetBalanceValid(AccountingDocument tranDoc, Class componentClass, String parameterName) {
62
63 if (!getParameterService().parameterExists(componentClass, parameterName)) {
64 return true;
65 }
66
67 List lines = new ArrayList();
68
69 lines.addAll(tranDoc.getSourceAccountingLines());
70 lines.addAll(tranDoc.getTargetAccountingLines());
71
72 KualiDecimal sourceLinesTotal = KualiDecimal.ZERO;
73 KualiDecimal targetLinesTotal = KualiDecimal.ZERO;
74
75
76
77 for (Iterator i = lines.iterator(); i.hasNext();) {
78 AccountingLine line = (AccountingLine) i.next();
79 String fundGroupCode = line.getAccount().getSubFundGroup().getFundGroupCode();
80
81 ParameterEvaluator evaluator =
82 if (evaluator.evaluationSucceeds()) {
83 KualiDecimal glpeLineAmount = tranDoc.getGeneralLedgerPendingEntryAmountForDetail(line);
84 if (line.isSourceAccountingLine()) {
85 sourceLinesTotal = sourceLinesTotal.add(glpeLineAmount);
86 }
87 else {
88 targetLinesTotal = targetLinesTotal.add(glpeLineAmount);
89 }
90 }
91 }
92
93
94 boolean isValid = true;
95
96 if (sourceLinesTotal.compareTo(targetLinesTotal) != 0) {
97 isValid = false;
98
99
100 ParameterEvaluator evaluator =
101 GlobalVariables.getMessageMap().putError("document.sourceAccountingLines", ERROR_DOCUMENT_FUND_GROUP_SET_DOES_NOT_BALANCE, new String[] { tranDoc.getSourceAccountingLinesSectionTitle(), tranDoc.getTargetAccountingLinesSectionTitle(), evaluator.getParameterValuesForMessage() });
102 }
103
104 return isValid;
105 }
106
107
108
109
110
111 public AccountingDocument getAccountingDocumentForValidation() {
112 return accountingDocumentForValidation;
113 }
114
115
116
117
118
119 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
120 this.accountingDocumentForValidation = accountingDocumentForValidation;
121 }
122
123
124
125
126
127 public ParameterService getParameterService() {
128 return parameterService;
129 }
130
131
132
133
134
135 public void setParameterService(ParameterService parameterService) {
136 this.parameterService = parameterService;
137 }
138 }