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.DOCUMENT_ERRORS;
19  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_AV_INCORRECT_FISCAL_YEAR_AVRC;
20  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_AV_INCORRECT_POST_PERIOD_AVRC;
21  import static org.kuali.ole.sys.OLEKeyConstants.AuxiliaryVoucher.ERROR_ACCOUNTING_PERIOD_OUT_OF_RANGE;
22  
23  import java.sql.Date;
24  import java.sql.Timestamp;
25  
26  import org.kuali.ole.coa.businessobject.AccountingPeriod;
27  import org.kuali.ole.coa.service.AccountingPeriodService;
28  import org.kuali.ole.fp.document.AuxiliaryVoucherDocument;
29  import org.kuali.ole.sys.document.validation.GenericValidation;
30  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
31  import org.kuali.rice.krad.util.GlobalVariables;
32  
33  
34  
35  
36  
37  public class AuxiliaryVoucherRecodeAccountingPeriodValidation extends GenericValidation {
38      private AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation;
39      private AccountingPeriodService accountingPeriodService;
40  
41      
42  
43  
44  
45  
46  
47  
48  
49      public boolean validate(AttributedDocumentEvent event) {
50          AccountingPeriod acctPeriod = getAccountingPeriodService().getByPeriod(auxiliaryVoucherDocumentForValidation.getPostingPeriodCode(), auxiliaryVoucherDocumentForValidation.getPostingYear());
51          
52          if (auxiliaryVoucherDocumentForValidation.isRecodeType()) {
53              boolean numericPeriod = true;
54              Integer period = null;
55              try {
56                  period = new Integer(auxiliaryVoucherDocumentForValidation.getPostingPeriodCode());
57              }
58              catch (NumberFormatException nfe) {
59                  numericPeriod = false;
60              }
61              Integer year = auxiliaryVoucherDocumentForValidation.getPostingYear();
62              Timestamp ts = new Timestamp(new java.util.Date().getTime());
63              AccountingPeriod currPeriod = getAccountingPeriodService().getByDate(new Date(ts.getTime()));
64              
65              
66              Integer currFiscalYear = currPeriod.getUniversityFiscalYear();
67              if (currFiscalYear > year) {
68                  GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_DOCUMENT_AV_INCORRECT_FISCAL_YEAR_AVRC);
69                  return false;
70              }
71              if (numericPeriod) {
72                  
73                  if (period > 12) {
74                      GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_DOCUMENT_AV_INCORRECT_POST_PERIOD_AVRC);
75                      return false;
76                  }
77                  else if (period < 1) {
78                      GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_ACCOUNTING_PERIOD_OUT_OF_RANGE);
79                      return false;
80                  }
81              }
82              else {
83                  
84                  GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_DOCUMENT_AV_INCORRECT_POST_PERIOD_AVRC);
85                  return false;
86              }
87          }
88          
89          return true;
90      }
91  
92      
93  
94  
95  
96      public AccountingPeriodService getAccountingPeriodService() {
97          return accountingPeriodService;
98      }
99  
100     
101 
102 
103 
104     public void setAccountingPeriodService(AccountingPeriodService accountingPeriodService) {
105         this.accountingPeriodService = accountingPeriodService;
106     }
107 
108     
109 
110 
111 
112     public AuxiliaryVoucherDocument getAuxiliaryVoucherDocumentForValidation() {
113         return auxiliaryVoucherDocumentForValidation;
114     }
115 
116     
117 
118 
119 
120     public void setAuxiliaryVoucherDocumentForValidation(AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation) {
121         this.auxiliaryVoucherDocumentForValidation = auxiliaryVoucherDocumentForValidation;
122     }
123 }