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.OLEConstants.GL_CREDIT_CODE;
20  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_BALANCE;
21  
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
24  import org.kuali.ole.sys.document.AccountingDocument;
25  import org.kuali.ole.sys.document.validation.GenericValidation;
26  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27  import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
28  import org.kuali.rice.core.api.util.type.KualiDecimal;
29  import org.kuali.rice.krad.exception.ValidationException;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  
32  
33  
34  
35  
36  public class AuxiliaryVoucherGeneralLedgerPendingEntriesBalanceValdiation extends GenericValidation {
37      private AccountingDocument accountingDocumentForValidation;
38      private GeneralLedgerPendingEntryService generalLedgerPendingEntryService;
39  
40      
41  
42  
43  
44      public boolean validate(AttributedDocumentEvent event) {
45  
46          if (!getGeneralLedgerPendingEntryService().generateGeneralLedgerPendingEntries(getAccountingDocumentForValidation())) {
47              throw new ValidationException("general ledger GLPE generation failed");
48          }
49  
50          
51          KualiDecimal creditAmount = KualiDecimal.ZERO;
52          KualiDecimal debitAmount = KualiDecimal.ZERO;
53  
54          for (GeneralLedgerPendingEntry glpe : getAccountingDocumentForValidation().getGeneralLedgerPendingEntries()) {
55              
56              if (!glpe.isTransactionEntryOffsetIndicator() && !glpe.getFinancialDocumentTypeCode().equals(OLEConstants.FinancialDocumentTypeCodes.DISTRIBUTION_OF_INCOME_AND_EXPENSE)) {
57                  if (GL_CREDIT_CODE.equals(glpe.getTransactionDebitCreditCode())) {
58                      creditAmount = creditAmount.add(glpe.getTransactionLedgerEntryAmount());
59                  }
60                  else { 
61                      debitAmount = debitAmount.add(glpe.getTransactionLedgerEntryAmount());
62                  }
63              }
64          }
65  
66          boolean balanced = debitAmount.equals(creditAmount);
67          if (!balanced) {
68              String errorParams[] = { creditAmount.toString(), debitAmount.toString() };
69              GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_BALANCE, errorParams);
70          }
71          return balanced;
72      }
73  
74      
75  
76  
77  
78      public AccountingDocument getAccountingDocumentForValidation() {
79          return accountingDocumentForValidation;
80      }
81  
82      
83  
84  
85  
86      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
87          this.accountingDocumentForValidation = accountingDocumentForValidation;
88      }
89  
90      
91  
92  
93  
94      public GeneralLedgerPendingEntryService getGeneralLedgerPendingEntryService() {
95          return generalLedgerPendingEntryService;
96      }
97  
98      
99  
100 
101 
102     public void setGeneralLedgerPendingEntryService(GeneralLedgerPendingEntryService generalLedgerPendingEntryService) {
103         this.generalLedgerPendingEntryService = generalLedgerPendingEntryService;
104     }
105 }