1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.kuali.kfs.module.ld.document.validation.impl;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.kuali.kfs.module.ld.LaborConstants;
26  import org.kuali.kfs.module.ld.LaborKeyConstants;
27  import org.kuali.kfs.module.ld.LaborPropertyConstants;
28  import org.kuali.kfs.module.ld.businessobject.ExpenseTransferAccountingLine;
29  import org.kuali.kfs.module.ld.document.LaborExpenseTransferDocumentBase;
30  import org.kuali.kfs.module.ld.service.LaborLedgerPendingEntryService;
31  import org.kuali.kfs.sys.KFSPropertyConstants;
32  import org.kuali.kfs.sys.context.SpringContext;
33  import org.kuali.kfs.sys.document.AccountingDocument;
34  import org.kuali.kfs.sys.document.validation.GenericValidation;
35  import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
36  import org.kuali.rice.core.api.search.SearchOperator;
37  import org.kuali.rice.krad.document.Document;
38  import org.kuali.rice.krad.util.GlobalVariables;
39  
40  
41  
42  
43  
44  public class SalaryExpenseTransferPendingLegerEntryValidation extends GenericValidation {
45      private Document documentForValidation;
46      
47      
48  
49  
50  
51  
52  
53      public boolean validate(AttributedDocumentEvent event) {
54          boolean result = true;
55          
56          Document documentForValidation = getDocumentForValidation();
57          AccountingDocument accountingDocument = (AccountingDocument) documentForValidation;
58          
59          result = !hasPendingLedgerEntry(accountingDocument);
60          return result ;    
61      }
62  
63      
64  
65  
66  
67  
68   
69      protected boolean hasPendingLedgerEntry(AccountingDocument accountingDocument) {
70          boolean entriesExist = false ;
71          
72          LaborExpenseTransferDocumentBase expenseTransferDocument = (LaborExpenseTransferDocumentBase) accountingDocument;
73          List<ExpenseTransferAccountingLine> sourceAccountingLines = expenseTransferDocument.getSourceAccountingLines();
74  
75          Map<String, String> fieldValues = new HashMap<String, String>();
76          for (ExpenseTransferAccountingLine sourceAccountingLine : sourceAccountingLines) {
77              String payPeriodCode = sourceAccountingLine.getPayrollEndDateFiscalPeriodCode();
78              String accountNumber = sourceAccountingLine.getAccountNumber();
79              String objectCode = sourceAccountingLine.getFinancialObjectCode();
80              String emplId = sourceAccountingLine.getEmplid();
81              String documentNumber = accountingDocument.getDocumentNumber();
82  
83              fieldValues.put(LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE, payPeriodCode);
84              fieldValues.put(KFSPropertyConstants.ACCOUNT_NUMBER, accountNumber);
85              fieldValues.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, objectCode);
86              fieldValues.put(KFSPropertyConstants.EMPLID, emplId);
87              fieldValues.put(KFSPropertyConstants.DOCUMENT_NUMBER, SearchOperator.NOT.op() + documentNumber);
88              
89              if (SpringContext.getBean(LaborLedgerPendingEntryService.class).hasPendingLaborLedgerEntry(fieldValues)) {
90                  GlobalVariables.getMessageMap().putError(LaborConstants.EMPLOYEE_LOOKUP_ERRORS, LaborKeyConstants.PENDING_SALARY_TRANSFER_ERROR, emplId, payPeriodCode, accountNumber, objectCode);
91                  return true;
92              }                        
93          }
94          return entriesExist ;
95      }
96  
97      
98  
99  
100 
101     public Document getDocumentForValidation() {
102         return documentForValidation;
103     }
104 
105     
106 
107 
108 
109     public void setDocumentForValidation(Document documentForValidation) {
110         this.documentForValidation = documentForValidation;
111     }    
112 }