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.ACCOUNTING_LINE_ERRORS;
19 import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_PC_TRANSACTION_TOTAL_ACCTING_LINE_TOTAL_NOT_EQUAL;
20
21 import java.util.List;
22 import java.util.Set;
23
24 import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
25 import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
26 import org.kuali.ole.fp.document.ProcurementCardDocument;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.businessobject.TargetAccountingLine;
29 import org.kuali.ole.sys.document.validation.GenericValidation;
30 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
31 import org.kuali.rice.core.api.util.type.KualiDecimal;
32 import org.kuali.rice.kew.api.WorkflowDocument;
33 import org.kuali.rice.krad.util.GlobalVariables;
34
35
36
37
38 public class ProcurementCardAccountAccessibilityValidation extends GenericValidation {
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardAccountAccessibilityValidation.class);
40
41 protected ProcurementCardDocument accountingDocumentForValidation;
42
43
44
45
46
47
48 @Override
49 public boolean validate(AttributedDocumentEvent event) {
50 boolean isValid = false;
51 ProcurementCardDocument pcDocument = getAccountingDocumentForValidation();
52
53 WorkflowDocument workflowDocument = pcDocument.getDocumentHeader().getWorkflowDocument();
54
55 Set<String> activeNodes = workflowDocument.getCurrentNodeNames();
56 if (workflowDocument.isEnroute() && activeNodes.contains(OLEConstants.RouteLevelNames.ACCOUNT_REVIEW_FULL_EDIT)) {
57 isValid = true;
58 }
59 return isValid;
60 }
61
62
63
64
65
66
67
68
69
70 protected boolean isTransactionBalanceValid(ProcurementCardTransactionDetail pcTransactionDetail) {
71 boolean inBalance = true;
72 KualiDecimal transAmount = pcTransactionDetail.getTransactionTotalAmount();
73 List<ProcurementCardTargetAccountingLine> targetAcctingLines = pcTransactionDetail.getTargetAccountingLines();
74
75 KualiDecimal targetLineTotal = KualiDecimal.ZERO;
76
77 for (TargetAccountingLine targetLine : targetAcctingLines) {
78 targetLineTotal = targetLineTotal.add(targetLine.getAmount());
79 }
80
81
82
83 inBalance = transAmount.abs().equals(targetLineTotal.abs());
84
85 if (!inBalance) {
86 GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_PC_TRANSACTION_TOTAL_ACCTING_LINE_TOTAL_NOT_EQUAL, new String[] { transAmount.toString(), targetLineTotal.toString() });
87 }
88
89 return inBalance;
90 }
91
92 public ProcurementCardDocument getAccountingDocumentForValidation() {
93 return accountingDocumentForValidation;
94 }
95
96 public void setAccountingDocumentForValidation(ProcurementCardDocument accountingDocumentForValidation) {
97 this.accountingDocumentForValidation = accountingDocumentForValidation;
98 }
99 }