1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.select.document.validation.impl;
17  
18  import org.kuali.ole.select.OleSelectConstant;
19  import org.kuali.ole.select.businessobject.OleDisbursementVoucherAccountingLine;
20  import org.kuali.ole.sys.OLEConstants;
21  import org.kuali.ole.sys.document.AccountingDocument;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  import java.math.BigDecimal;
27  import java.util.List;
28  
29  public class OleDVAccountingLinesPercentValidation extends GenericValidation {
30      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDVAccountingLinesPercentValidation.class);
31  
32      private AccountingDocument accountingDocumentForValidation;
33  
34      @Override
35      public boolean validate(AttributedDocumentEvent event) {
36          boolean valid = true;
37          
38          if (valid) {
39              
40              BigDecimal sourceTotalPercent = BigDecimal.ZERO;
41              BigDecimal desiredPercent = new BigDecimal("100");
42              List sourceAccounts = getAccountingDocumentForValidation().getSourceAccountingLines();
43              for (Object account : sourceAccounts) {
44                  if (((OleDisbursementVoucherAccountingLine) account).getAccountLinePercent() != null) {
45                      sourceTotalPercent = sourceTotalPercent.add(((OleDisbursementVoucherAccountingLine) account).getAccountLinePercent());
46                  } else {
47                      sourceTotalPercent = sourceTotalPercent.add(BigDecimal.ZERO);
48                  }
49              }
50              if ((sourceAccounts.size() > 0 && desiredPercent.compareTo(sourceTotalPercent) != 0)) {
51                  GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNTING_LINE_ERRORS, OleSelectConstant.ERROR_DI_ACCOUNTING_TOTAL, "");
52                  valid = false;
53              }
54          }
55          return valid;
56      }
57  
58  
59      
60  
61  
62  
63  
64      public AccountingDocument getAccountingDocumentForValidation() {
65          return accountingDocumentForValidation;
66      }
67  
68      
69  
70  
71  
72  
73      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
74          this.accountingDocumentForValidation = accountingDocumentForValidation;
75      }
76  }
77