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
23 import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
24 import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
25 import org.kuali.ole.sys.businessobject.AccountingLine;
26 import org.kuali.ole.sys.businessobject.TargetAccountingLine;
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.rice.core.api.util.type.KualiDecimal;
31 import org.kuali.rice.krad.util.GlobalVariables;
32
33
34
35
36 public class ProcurementCardFixErrorPathValidation extends GenericValidation {
37 private AccountingLine accountingLineForValidation;
38 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardFixErrorPathValidation.class);
39
40
41
42
43
44
45 public boolean validate(AttributedDocumentEvent event) {
46 ProcurementCardErrorPathUtil.fixErrorPath((AccountingDocument)event.getDocument(), accountingLineForValidation);
47 return true;
48 }
49
50
51
52
53
54
55
56
57
58 protected boolean isTransactionBalanceValid(ProcurementCardTransactionDetail pcTransactionDetail) {
59 boolean inBalance = true;
60 KualiDecimal transAmount = pcTransactionDetail.getTransactionTotalAmount();
61 List<ProcurementCardTargetAccountingLine> targetAcctingLines = pcTransactionDetail.getTargetAccountingLines();
62
63 KualiDecimal targetLineTotal = KualiDecimal.ZERO;
64
65 for (TargetAccountingLine targetLine : targetAcctingLines) {
66 targetLineTotal = targetLineTotal.add(targetLine.getAmount());
67 }
68
69
70
71 inBalance = transAmount.abs().equals(targetLineTotal.abs());
72
73 if (!inBalance) {
74 GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_PC_TRANSACTION_TOTAL_ACCTING_LINE_TOTAL_NOT_EQUAL, new String[] { transAmount.toString(), targetLineTotal.toString() });
75 }
76
77 return inBalance;
78 }
79
80
81
82
83
84 public AccountingLine getAccountingLineForValidation() {
85 return accountingLineForValidation;
86 }
87
88
89
90
91
92 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
93 this.accountingLineForValidation = accountingLineForValidation;
94 }
95
96
97 }