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.List;
19
20 import org.kuali.ole.fp.businessobject.CapitalAccountingLines;
21 import org.kuali.ole.fp.businessobject.CapitalAssetInformation;
22 import org.kuali.ole.fp.document.CapitalAccountingLinesDocumentBase;
23 import org.kuali.ole.fp.document.CapitalAssetEditable;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.OLEKeyConstants;
26 import org.kuali.ole.sys.document.AccountingDocument;
27 import org.kuali.ole.sys.document.validation.GenericValidation;
28 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
29 import org.kuali.rice.core.api.util.type.KualiDecimal;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33
34
35
36 public class CapitalAccountingLinesValidations extends GenericValidation {
37 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CapitalAccountingLinesValidations.class);
38
39 private AccountingDocument accountingDocumentForValidation;
40
41
42
43
44 public boolean validate(AttributedDocumentEvent event) {
45 return this.validateCapitalAccountingLines(accountingDocumentForValidation);
46 }
47
48
49 protected boolean validateCapitalAccountingLines(AccountingDocument accountingDocumentForValidation) {
50 LOG.debug("validateCapitalAccountingLines - start");
51
52 boolean isValid = true;
53
54 if (accountingDocumentForValidation instanceof CapitalAssetEditable == false) {
55 return true;
56 }
57
58 CapitalAccountingLinesDocumentBase capitalAccountingLinesDocumentBase = (CapitalAccountingLinesDocumentBase) accountingDocumentForValidation;
59 List <CapitalAccountingLines> capitalAccountingLines = capitalAccountingLinesDocumentBase.getCapitalAccountingLines();
60
61 CapitalAssetEditable capitalAssetEditable = (CapitalAssetEditable) accountingDocumentForValidation;
62
63 List<CapitalAssetInformation> capitalAssets = capitalAssetEditable.getCapitalAssetInformation();
64
65 isValid &= allCapitalAccountingLinesProcessed(capitalAccountingLines, capitalAssets);
66 isValid &= capitalAssetExistsForCapitalAccountingLinesProcessed(capitalAccountingLines, capitalAssets);
67 isValid &= totalAmountMatchForCapitalAccountingLinesAndCapitalAssets(capitalAccountingLines, capitalAssets);
68
69 return isValid;
70 }
71
72 protected boolean allCapitalAccountingLinesProcessed(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> capitalAssets) {
73 LOG.debug("allCapitalAccountingLinesProcessed - start");
74
75 boolean processed = true;
76
77 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
78 if (!capitalAccountingLine.isSelectLine()) {
79 processed = false;
80 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_ACCOUNTING_LINES_FOR_CAPITALIZATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_FOR_CAPITALIZATION_NOT_PROCESSED);
81
82 break;
83 }
84 }
85
86 return processed;
87 }
88
89 protected boolean capitalAssetExistsForCapitalAccountingLinesProcessed(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> capitalAssets) {
90 LOG.debug("capitalAssetExistsForCapitalAccountingLinesProcessed - start");
91
92 boolean exists = true;
93
94 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
95 if (!capitalAssetExist(capitalAccountingLine, capitalAssets)) {
96 exists = false;
97 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_ACCOUNTING_LINES_FOR_CAPITALIZATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_FOR_CAPITALIZATION_HAS_NO_CAPITAL_ASSET, capitalAccountingLine.getSequenceNumber().toString(), capitalAccountingLine.getLineType(), capitalAccountingLine.getChartOfAccountsCode(), capitalAccountingLine.getAccountNumber(), capitalAccountingLine.getFinancialObjectCode());
98
99 break;
100 }
101 }
102
103 return exists;
104 }
105
106
107
108
109
110
111
112 protected boolean capitalAssetExist(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetInformation) {
113 boolean exists = false;
114
115 if (ObjectUtils.isNull(capitalAssetInformation) && capitalAssetInformation.size() <= 0) {
116 return exists;
117 }
118
119 for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
120
121
122
123
124
125 return true;
126
127 }
128
129 return exists;
130 }
131
132 protected boolean totalAmountMatchForCapitalAccountingLinesAndCapitalAssets(List<CapitalAccountingLines> capitalAccountingLines, List<CapitalAssetInformation> capitalAssets) {
133 boolean totalAmountMatched = true;
134
135 KualiDecimal capitalAccountingLinesTotals = KualiDecimal.ZERO;
136 KualiDecimal capitalAAssetTotals = KualiDecimal.ZERO;
137
138 for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
139 capitalAccountingLinesTotals = capitalAccountingLinesTotals.add(capitalAccountingLine.getAmount());
140 }
141
142 for (CapitalAssetInformation capitalAsset : capitalAssets) {
143 capitalAAssetTotals = capitalAAssetTotals.add(capitalAsset.getCapitalAssetLineAmount());
144 }
145
146 if (capitalAccountingLinesTotals.isGreaterThan(capitalAAssetTotals)) {
147
148 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_ACCOUNTING_LINES_FOR_CAPITALIZATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINES_NOT_ALL_TOTALS_DISTRIBUTED_TO_CAPITAL_ASSETS);
149 return false;
150 }
151
152 if (capitalAccountingLinesTotals.isLessEqual(capitalAAssetTotals)) {
153
154 GlobalVariables.getMessageMap().putError(OLEConstants.EDIT_ACCOUNTING_LINES_FOR_CAPITALIZATION_ERRORS, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_FOR_CAPITALIZATION_HAS_NO_CAPITAL_ASSET);
155 return false;
156 }
157
158 return totalAmountMatched;
159 }
160
161
162
163
164
165
166
167 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
168 this.accountingDocumentForValidation = accountingDocumentForValidation;
169 }
170 }