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 java.util.Iterator;
19 import java.util.Map;
20
21 import org.kuali.ole.fp.document.BudgetAdjustmentDocument;
22 import org.kuali.ole.sys.OLEConstants;
23 import org.kuali.ole.sys.OLEKeyConstants;
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.core.api.util.type.KualiInteger;
28 import org.kuali.rice.krad.util.GlobalVariables;
29 import org.kuali.rice.krad.util.MessageMap;
30
31
32
33
34 public class BudgetAdjustmentDocumentBalancedValidation extends GenericValidation {
35 public BudgetAdjustmentDocument accountingDocumentForValidation;
36
37
38
39
40
41
42 public boolean validate(AttributedDocumentEvent event) {
43 MessageMap errors = GlobalVariables.getMessageMap();
44
45 boolean balanced = true;
46
47
48
49 KualiInteger sourceBaseBudgetTotal = getAccountingDocumentForValidation().getSourceBaseBudgetIncomeTotal().subtract( getAccountingDocumentForValidation().getSourceBaseBudgetExpenseTotal());
50 KualiInteger targetBaseBudgetTotal = getAccountingDocumentForValidation().getTargetBaseBudgetIncomeTotal().subtract( getAccountingDocumentForValidation().getTargetBaseBudgetExpenseTotal());
51 if (sourceBaseBudgetTotal.compareTo(targetBaseBudgetTotal) != 0) {
52 GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_BA_BASE_AMOUNTS_BALANCED);
53 balanced = false;
54 }
55
56
57 Map incomeStreamMap = getAccountingDocumentForValidation().buildIncomeStreamBalanceMapForDocumentBalance();
58 KualiDecimal totalCurrentAmount = new KualiDecimal(0);
59 for (Iterator iter = incomeStreamMap.values().iterator(); iter.hasNext();) {
60 KualiDecimal streamAmount = (KualiDecimal) iter.next();
61 totalCurrentAmount = totalCurrentAmount.add(streamAmount);
62 }
63
64 if (totalCurrentAmount.isNonZero()) {
65 GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_BA_CURRENT_AMOUNTS_BALANCED);
66 balanced = false;
67 }
68
69 return balanced;
70 }
71
72
73
74
75
76 public BudgetAdjustmentDocument getAccountingDocumentForValidation() {
77 return accountingDocumentForValidation;
78 }
79
80
81
82
83
84 public void setAccountingDocumentForValidation(BudgetAdjustmentDocument accountingDocumentForValidation) {
85 this.accountingDocumentForValidation = accountingDocumentForValidation;
86 }
87 }