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.SOURCE_ACCOUNTING_LINE_ERRORS;
19 import static org.kuali.ole.sys.OLEConstants.TARGET_ACCOUNTING_LINE_ERRORS;
20 import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_TOTAL_CHANGED;
21
22 import org.kuali.ole.fp.document.BudgetAdjustmentDocument;
23 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24 import org.kuali.ole.sys.document.validation.impl.AccountingLineGroupTotalsUnchangedValidation;
25 import org.kuali.rice.core.api.util.type.KualiDecimal;
26 import org.kuali.rice.core.api.util.type.KualiInteger;
27 import org.kuali.rice.core.web.format.CurrencyFormatter;
28 import org.kuali.rice.krad.util.GlobalVariables;
29
30
31
32
33 public class BudgetAdjustmentAccountingLineTotalsUnchangedValidation extends AccountingLineGroupTotalsUnchangedValidation {
34
35
36
37
38
39 public boolean validate(AttributedDocumentEvent event) {
40 boolean isUnchanged = true;
41
42 BudgetAdjustmentDocument persistedDocument = (BudgetAdjustmentDocument) retrievePersistedDocument(getAccountingDocumentForValidation());
43 BudgetAdjustmentDocument currentDocument = (BudgetAdjustmentDocument)getAccountingDocumentForValidation();
44
45 if (persistedDocument == null) {
46 handleNonExistentDocumentWhenApproving(getAccountingDocumentForValidation());
47 }
48 else {
49
50 KualiDecimal persistedSourceCurrentBudgetTotal = persistedDocument.getSourceCurrentBudgetTotal();
51 KualiInteger persistedSourceBaseBudgetTotal = persistedDocument.getSourceBaseBudgetTotal();
52 KualiDecimal persistedTargetCurrentBudgetTotal = persistedDocument.getTargetCurrentBudgetTotal();
53 KualiInteger persistedTargetBaseBudgetTotal = persistedDocument.getTargetBaseBudgetTotal();
54
55
56 KualiDecimal currentSourceCurrentBudgetTotal = currentDocument.getSourceCurrentBudgetTotal();
57 KualiInteger currentSourceBaseBudgetTotal = currentDocument.getSourceBaseBudgetTotal();
58 KualiDecimal currentTargetCurrentBudgetTotal = currentDocument.getTargetCurrentBudgetTotal();
59 KualiInteger currentTargetBaseBudgetTotal = currentDocument.getTargetBaseBudgetTotal();
60
61
62
63 if (persistedSourceCurrentBudgetTotal.compareTo(currentSourceCurrentBudgetTotal) != 0) {
64 isUnchanged = false;
65 buildTotalChangeErrorMessage(SOURCE_ACCOUNTING_LINE_ERRORS, "source current budget", persistedSourceCurrentBudgetTotal, currentSourceCurrentBudgetTotal);
66 }
67 if (persistedSourceBaseBudgetTotal.compareTo(currentSourceBaseBudgetTotal) != 0) {
68 isUnchanged = false;
69 buildTotalChangeErrorMessage(SOURCE_ACCOUNTING_LINE_ERRORS, "source base budget", persistedSourceBaseBudgetTotal.kualiDecimalValue(), currentSourceBaseBudgetTotal.kualiDecimalValue());
70 }
71 if (persistedTargetCurrentBudgetTotal.compareTo(currentTargetCurrentBudgetTotal) != 0) {
72 isUnchanged = false;
73 buildTotalChangeErrorMessage(TARGET_ACCOUNTING_LINE_ERRORS, "target current budget", persistedTargetCurrentBudgetTotal, currentTargetCurrentBudgetTotal);
74 }
75 if (persistedTargetBaseBudgetTotal.compareTo(currentTargetBaseBudgetTotal) != 0) {
76 isUnchanged = false;
77 buildTotalChangeErrorMessage(TARGET_ACCOUNTING_LINE_ERRORS, "target base budget", persistedTargetBaseBudgetTotal.kualiDecimalValue(), currentTargetBaseBudgetTotal.kualiDecimalValue());
78 }
79 }
80
81 return isUnchanged;
82 }
83
84
85
86
87
88
89
90
91
92 protected void buildTotalChangeErrorMessage(String propertyName, String sectionTitle, KualiDecimal persistedSourceLineTotal, KualiDecimal currentSourceLineTotal) {
93 String persistedTotal = (String) new CurrencyFormatter().format(persistedSourceLineTotal);
94 String currentTotal = (String) new CurrencyFormatter().format(currentSourceLineTotal);
95
96 GlobalVariables.getMessageMap().putError(propertyName, ERROR_DOCUMENT_ACCOUNTING_LINE_TOTAL_CHANGED, new String[] { sectionTitle, persistedTotal, currentTotal });
97 }
98 }