1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.service.impl;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.fp.businessobject.CashDrawer;
23 import org.kuali.ole.fp.service.CashDrawerService;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.rice.core.api.util.type.KualiDecimal;
26 import org.kuali.rice.krad.service.BusinessObjectService;
27 import org.springframework.transaction.annotation.Transactional;
28
29
30
31
32
33 @Transactional
34 public class CashDrawerServiceImpl implements CashDrawerService {
35 private BusinessObjectService businessObjectService;
36 private static final String CAMPUS_CODE_PROPERTY = "campusCode";
37
38
39
40
41
42
43
44
45 public void closeCashDrawer(String campusCode) {
46 CashDrawer drawer = getByCampusCode(campusCode);
47 this.closeCashDrawer(drawer);
48 }
49
50
51
52
53
54
55
56 public void closeCashDrawer(CashDrawer drawer) {
57 drawer.setStatusCode(OLEConstants.CashDrawerConstants.STATUS_CLOSED);
58 drawer.setReferenceFinancialDocumentNumber(null);
59
60 save(drawer);
61 }
62
63
64
65
66
67
68
69
70
71
72
73 public CashDrawer openCashDrawer(String campusCode, String documentId) {
74 if (StringUtils.isBlank(documentId)) {
75 throw new IllegalArgumentException("invalid (blank) documentId");
76 }
77
78 CashDrawer drawer = getByCampusCode(campusCode);
79 return this.openCashDrawer(drawer, documentId);
80 }
81
82
83
84
85
86
87
88
89
90
91 public CashDrawer openCashDrawer(CashDrawer drawer, String documentId) {
92 if (StringUtils.isBlank(documentId)) {
93 throw new IllegalArgumentException("invalid (blank) documentId");
94 }
95
96 drawer.setStatusCode(OLEConstants.CashDrawerConstants.STATUS_OPEN);
97 drawer.setReferenceFinancialDocumentNumber(documentId);
98
99 save(drawer);
100 return drawer;
101 }
102
103
104
105
106
107
108
109
110
111 public void lockCashDrawer(String campusCode, String documentId) {
112 if (StringUtils.isBlank(documentId)) {
113 throw new IllegalArgumentException("invalid (blank) documentId");
114 }
115
116 CashDrawer drawer = getByCampusCode(campusCode);
117 this.lockCashDrawer(drawer, documentId);
118 }
119
120
121
122
123
124
125
126
127
128 public void lockCashDrawer(CashDrawer drawer, String documentId) {
129 if (StringUtils.isBlank(documentId)) {
130 throw new IllegalArgumentException("invalid (blank) documentId");
131 }
132
133 if (!StringUtils.equals(OLEConstants.CashDrawerConstants.STATUS_OPEN, drawer.getStatusCode())) {
134 throw new IllegalStateException("CashDrawer '" + drawer.getCampusCode() + "' cannot be locked because it is not open");
135 }
136 if (!StringUtils.equals(documentId, drawer.getReferenceFinancialDocumentNumber())) {
137 throw new IllegalStateException("CashDrawer '" + drawer.getCampusCode() + "' cannot be locked because it was opened by document " + drawer.getReferenceFinancialDocumentNumber());
138 }
139
140 drawer.setStatusCode(OLEConstants.CashDrawerConstants.STATUS_LOCKED);
141 drawer.setReferenceFinancialDocumentNumber(documentId);
142
143 save(drawer);
144 }
145
146
147
148
149
150
151
152
153
154 public void unlockCashDrawer(String campusCode, String documentId) {
155 if (StringUtils.isBlank(documentId)) {
156 throw new IllegalArgumentException("invalid (blank) documentId");
157 }
158
159 CashDrawer drawer = getByCampusCode(campusCode);
160 this.unlockCashDrawer(drawer, documentId);
161 }
162
163
164
165
166
167
168
169
170
171 public void unlockCashDrawer(CashDrawer drawer, String documentId) {
172 if (StringUtils.isBlank(documentId)) {
173 throw new IllegalArgumentException("invalid (blank) documentId");
174 }
175
176 if (!StringUtils.equals(OLEConstants.CashDrawerConstants.STATUS_LOCKED, drawer.getStatusCode())) {
177 throw new IllegalStateException("CashDrawer '" + drawer.getCampusCode() + "' cannot be unlocked because it is not locked");
178 }
179 if (!StringUtils.equals(documentId, drawer.getReferenceFinancialDocumentNumber())) {
180 throw new IllegalStateException("CashDrawer '" + drawer.getCampusCode() + "' cannot be unlocked because it was locked by document " + drawer.getReferenceFinancialDocumentNumber());
181 }
182
183 drawer.setStatusCode(OLEConstants.CashDrawerConstants.STATUS_OPEN);
184 drawer.setReferenceFinancialDocumentNumber(documentId);
185
186 save(drawer);
187 }
188
189
190
191
192
193
194
195
196
197
198
199
200
201 public CashDrawer getByCampusCode(String campusCode) {
202 if (StringUtils.isBlank(campusCode)) {
203 throw new IllegalArgumentException("invalid (blank) campusCode");
204 }
205
206 return (CashDrawer)businessObjectService.findByPrimaryKey(CashDrawer.class, buildPrimaryKeyMap(campusCode));
207 }
208
209
210
211
212
213
214
215 protected void save(CashDrawer cashDrawer) {
216 if (cashDrawer == null) {
217 throw new IllegalArgumentException("invalid (null) cashDrawer");
218 }
219
220 businessObjectService.save(cashDrawer);
221 }
222
223
224
225
226
227
228
229
230 protected Map buildPrimaryKeyMap(String campusCode) {
231 Map keyMap = new HashMap();
232 keyMap.put(CAMPUS_CODE_PROPERTY, campusCode);
233 return keyMap;
234 }
235
236
237
238
239
240
241
242
243
244
245
246 public KualiDecimal getCoinTotal(CashDrawer drawer) {
247 KualiDecimal sum = new KualiDecimal(0.0);
248 if (drawer != null) {
249 if (drawer.getFinancialDocumentHundredCentAmount() != null) {
250 sum.add(drawer.getFinancialDocumentHundredCentAmount());
251 }
252 if (drawer.getFinancialDocumentFiftyCentAmount() != null) {
253 sum.add(drawer.getFinancialDocumentFiftyCentAmount());
254 }
255 if (drawer.getFinancialDocumentTwentyFiveCentAmount() != null) {
256 sum.add(drawer.getFinancialDocumentTwentyFiveCentAmount());
257 }
258 if (drawer.getFinancialDocumentTenCentAmount() != null) {
259 sum.add(drawer.getFinancialDocumentTenCentAmount());
260 }
261 if (drawer.getFinancialDocumentFiveCentAmount() != null) {
262 sum.add(drawer.getFinancialDocumentFiveCentAmount());
263 }
264 if (drawer.getFinancialDocumentOneCentAmount() != null) {
265 sum.add(drawer.getFinancialDocumentOneCentAmount());
266 }
267 if (drawer.getFinancialDocumentOtherCentAmount() != null) {
268 sum.add(drawer.getFinancialDocumentOtherCentAmount());
269 }
270 }
271 return sum;
272 }
273
274
275
276
277
278
279
280
281
282
283
284 public KualiDecimal getCurrencyTotal(CashDrawer drawer) {
285 KualiDecimal sum = new KualiDecimal(0.0);
286 if (drawer != null) {
287 if (drawer.getFinancialDocumentHundredDollarAmount() != null) {
288 sum.add(drawer.getFinancialDocumentHundredDollarAmount());
289 }
290 if (drawer.getFinancialDocumentFiftyDollarAmount() != null) {
291 sum.add(drawer.getFinancialDocumentFiftyDollarAmount());
292 }
293 if (drawer.getFinancialDocumentTwentyDollarAmount() != null) {
294 sum.add(drawer.getFinancialDocumentTwentyDollarAmount());
295 }
296 if (drawer.getFinancialDocumentTenDollarAmount() != null) {
297 sum.add(drawer.getFinancialDocumentTenDollarAmount());
298 }
299 if (drawer.getFinancialDocumentFiveDollarAmount() != null) {
300 sum.add(drawer.getFinancialDocumentFiveDollarAmount());
301 }
302 if (drawer.getFinancialDocumentTwoDollarAmount() != null) {
303 sum.add(drawer.getFinancialDocumentTwoDollarAmount());
304 }
305 if (drawer.getFinancialDocumentOneDollarAmount() != null) {
306 sum.add(drawer.getFinancialDocumentOneDollarAmount());
307 }
308 if (drawer.getFinancialDocumentOtherDollarAmount() != null) {
309 sum.add(drawer.getFinancialDocumentOtherDollarAmount());
310 }
311 }
312 return sum;
313 }
314
315
316
317
318
319
320
321 public BusinessObjectService getBusinessObjectService() {
322 return businessObjectService;
323 }
324
325
326
327
328
329
330 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
331 this.businessObjectService = businessObjectService;
332 }
333 }