1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document;
17
18 import java.sql.Date;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.coa.businessobject.AccountingPeriod;
22 import org.kuali.ole.coa.service.AccountingPeriodService;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.rice.core.api.datetime.DateTimeService;
25 import org.kuali.rice.kew.api.exception.WorkflowException;
26 import org.kuali.rice.kns.service.DataDictionaryService;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29
30
31
32 public class LedgerPostingDocumentBase extends FinancialSystemTransactionalDocumentBase implements LedgerPostingDocument {
33 static protected transient DateTimeService dateTimeService;
34 static protected transient AccountingPeriodService accountingPeriodService;
35 static protected transient DataDictionaryService dataDictionaryService;
36
37 protected AccountingPeriod accountingPeriod;
38 protected Integer postingYear;
39 protected String postingPeriodCode;
40 protected boolean checkPostingYearForCopy;
41
42
43
44
45 public LedgerPostingDocumentBase() {
46 super();
47 if ( SpringContext.isInitialized() ) {
48 createInitialAccountingPeriod();
49 }
50 }
51
52
53
54
55
56
57
58
59
60 public void createInitialAccountingPeriod() {
61 AccountingPeriod accountingPeriod = retrieveCurrentAccountingPeriod();
62 setAccountingPeriod(accountingPeriod);
63 }
64
65
66
67
68
69 public AccountingPeriod retrieveCurrentAccountingPeriod() {
70
71 try {
72
73 Date date = getDateTimeService().getCurrentSqlDate();
74 return getAccountingPeriodService().getByDate(date);
75
76 } catch ( RuntimeException ex ) {
77
78 return null;
79 }
80
81 }
82
83
84
85
86 public Integer getPostingYear() {
87 return postingYear;
88 }
89
90
91
92
93 public void setPostingYear(Integer postingYear) {
94 this.postingYear = postingYear;
95 }
96
97
98
99
100 public String getPostingPeriodCode() {
101 return postingPeriodCode;
102 }
103
104
105
106
107 public void setPostingPeriodCode(String postingPeriodCode) {
108 this.postingPeriodCode = postingPeriodCode;
109 }
110
111
112
113
114 public AccountingPeriod getAccountingPeriod() {
115 accountingPeriod = getAccountingPeriodService().getByPeriod(postingPeriodCode, postingYear);
116
117 return accountingPeriod;
118 }
119
120
121
122
123 public void setAccountingPeriod(AccountingPeriod accountingPeriod) {
124 this.accountingPeriod = accountingPeriod;
125
126 if(ObjectUtils.isNotNull(accountingPeriod)) {
127 this.setPostingYear(accountingPeriod.getUniversityFiscalYear());
128 this.setPostingPeriodCode(accountingPeriod.getUniversityFiscalPeriodCode());
129 }
130 }
131
132
133
134
135
136 @Override
137 public void toCopy() throws WorkflowException, IllegalStateException {
138 super.toCopy();
139 setAccountingPeriod(retrieveCurrentAccountingPeriod());
140 }
141
142
143
144
145
146 public String getFinancialDocumentTypeCode() {
147 return getDataDictionaryService().getDocumentTypeNameByClass(this.getClass());
148 }
149
150
151 public static DataDictionaryService getDataDictionaryService() {
152 if ( dataDictionaryService == null ) {
153 dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
154 }
155 return dataDictionaryService;
156 }
157
158 public static DateTimeService getDateTimeService() {
159 if ( dateTimeService == null ) {
160 dateTimeService = SpringContext.getBean(DateTimeService.class);
161 }
162 return dateTimeService;
163 }
164
165 public static AccountingPeriodService getAccountingPeriodService() {
166 if ( accountingPeriodService == null ) {
167 accountingPeriodService = SpringContext.getBean(AccountingPeriodService.class);
168 }
169 return accountingPeriodService;
170 }
171
172
173
174
175
176
177
178 public String getAccountingPeriodCompositeString() {
179 return postingPeriodCode + postingYear;
180 }
181
182
183
184
185
186 public void setAccountingPeriodCompositeString(String accountingPeriodString) {
187 if (StringUtils.isNotBlank(accountingPeriodString)) {
188 String period = StringUtils.left(accountingPeriodString, 2);
189 Integer year = new Integer(StringUtils.right(accountingPeriodString, 4));
190 AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year);
191 setAccountingPeriod(accountingPeriod);
192 }
193 }
194
195
196 }