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_ACCOUNTING_TWO_PERIODS;
20
21 import java.sql.Date;
22 import java.sql.Timestamp;
23
24 import org.kuali.ole.coa.businessobject.AccountingPeriod;
25 import org.kuali.ole.coa.service.AccountingPeriodService;
26 import org.kuali.ole.fp.document.AuxiliaryVoucherDocument;
27 import org.kuali.ole.sys.document.validation.GenericValidation;
28 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
29 import org.kuali.ole.sys.service.UniversityDateService;
30 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
31 import org.kuali.rice.krad.util.GlobalVariables;
32
33
34
35
36 public class AuxiliaryVoucherAccountingPeriodWithinGracePeriodValidation extends GenericValidation {
37 private AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation;
38 private AccountingPeriodService accountingPeriodService;
39 private UniversityDateService universityDateService;
40 private ParameterService parameterService;
41
42
43
44
45
46 public boolean validate(AttributedDocumentEvent event) {
47
48
49
50
51 boolean valid = true;
52 AccountingPeriod acctPeriod = getAccountingPeriodService().getByPeriod(getAuxiliaryVoucherDocumentForValidation().getPostingPeriodCode(), getAuxiliaryVoucherDocumentForValidation().getPostingYear());
53
54 Timestamp ts = new Timestamp(new java.util.Date().getTime());
55 AccountingPeriod currPeriod = getAccountingPeriodService().getByDate(new Date(ts.getTime()));
56
57 if (acctPeriod.getUniversityFiscalYear().equals(getUniversityDateService().getCurrentFiscalYear())) {
58 if (getAccountingPeriodService().compareAccountingPeriodsByDate(acctPeriod, currPeriod) < 0) {
59
60
61
62 if (!getAuxiliaryVoucherDocumentForValidation().calculateIfWithinGracePeriod(new Date(ts.getTime()), acctPeriod)) {
63 GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_DOCUMENT_ACCOUNTING_TWO_PERIODS);
64 return false;
65 }
66 }
67 }
68 else {
69
70
71 if (!getAuxiliaryVoucherDocumentForValidation().calculateIfWithinGracePeriod(new Date(ts.getTime()), acctPeriod) && getAuxiliaryVoucherDocumentForValidation().isEndOfPreviousFiscalYear(acctPeriod)) {
72 GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_DOCUMENT_ACCOUNTING_TWO_PERIODS);
73 return false;
74 }
75 }
76
77 return valid;
78 }
79
80
81
82
83
84 public AuxiliaryVoucherDocument getAuxiliaryVoucherDocumentForValidation() {
85 return auxiliaryVoucherDocumentForValidation;
86 }
87
88
89
90
91
92 public void setAuxiliaryVoucherDocumentForValidation(AuxiliaryVoucherDocument accountingDocumentForValidation) {
93 this.auxiliaryVoucherDocumentForValidation = accountingDocumentForValidation;
94 }
95
96
97
98
99
100 public AccountingPeriodService getAccountingPeriodService() {
101 return accountingPeriodService;
102 }
103
104
105
106
107
108 public void setAccountingPeriodService(AccountingPeriodService accountingPeriodService) {
109 this.accountingPeriodService = accountingPeriodService;
110 }
111
112
113
114
115
116 public UniversityDateService getUniversityDateService() {
117 return universityDateService;
118 }
119
120
121
122
123
124 public void setUniversityDateService(UniversityDateService universityDateService) {
125 this.universityDateService = universityDateService;
126 }
127
128
129
130
131
132 public ParameterService getParameterService() {
133 return parameterService;
134 }
135
136
137
138
139
140 public void setParameterService(ParameterService parameterService) {
141 this.parameterService = parameterService;
142 }
143 }