1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.web.struts;
17
18 import java.io.ByteArrayOutputStream;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.kuali.ole.fp.businessobject.Check;
29 import org.kuali.ole.fp.businessobject.CoinDetail;
30 import org.kuali.ole.fp.businessobject.CurrencyDetail;
31 import org.kuali.ole.fp.document.CashReceiptDocument;
32 import org.kuali.ole.fp.document.service.CashReceiptCoverSheetService;
33 import org.kuali.ole.fp.document.service.CashReceiptService;
34 import org.kuali.ole.fp.document.validation.event.AddCheckEvent;
35 import org.kuali.ole.fp.document.validation.event.DeleteCheckEvent;
36 import org.kuali.ole.fp.document.validation.event.UpdateCheckEvent;
37 import org.kuali.ole.sys.OLEConstants;
38 import org.kuali.ole.sys.OLEKeyConstants;
39 import org.kuali.ole.sys.OLEPropertyConstants;
40 import org.kuali.ole.sys.context.SpringContext;
41 import org.kuali.rice.core.api.config.property.ConfigurationService;
42 import org.kuali.rice.kew.api.exception.WorkflowException;
43 import org.kuali.rice.kns.util.KNSGlobalVariables;
44 import org.kuali.rice.kns.util.WebUtils;
45 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
46 import org.kuali.rice.krad.service.DocumentService;
47 import org.kuali.rice.krad.service.KualiRuleService;
48 import org.kuali.rice.krad.util.GlobalVariables;
49
50
51
52
53 public class CashReceiptAction extends CapitalAccountingLinesActionBase {
54
55
56
57
58
59
60 @Override
61 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
62 CashReceiptForm cform = (CashReceiptForm) form;
63
64 if (cform.hasDocumentId()) {
65 CashReceiptDocument cdoc = cform.getCashReceiptDocument();
66
67
68 processCheckEntryMode(cform, cdoc);
69
70
71 if (CashReceiptDocument.CHECK_ENTRY_DETAIL.equals(cdoc.getCheckEntryMode())) {
72 cdoc.setTotalCheckAmount(cdoc.calculateCheckTotal());
73 cdoc.setTotalConfirmedCheckAmount(cdoc.calculateConfirmedCheckTotal());
74 processChecks(cdoc, cform);
75 }
76
77
78 SpringContext.getBean(CashReceiptService.class).areCashTotalsInvalid(cdoc);
79 }
80
81
82 ActionForward result = super.execute(mapping, form, request, response);
83 return result;
84
85 }
86
87
88
89
90
91
92
93
94
95
96
97 public ActionForward printCoverSheet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
98 CashReceiptForm crForm = (CashReceiptForm) form;
99
100
101 String directory = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_HELP_URL_KEY);
102
103
104 String documentNumber = request.getParameter(OLEPropertyConstants.DOCUMENT_NUMBER);
105
106 CashReceiptDocument document = (CashReceiptDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentNumber);
107
108
109
110
111 crForm.setDocument(document);
112
113 ByteArrayOutputStream baos = new ByteArrayOutputStream();
114 CashReceiptCoverSheetService coverSheetService = SpringContext.getBean(CashReceiptCoverSheetService.class);
115 coverSheetService.generateCoverSheet(document, directory, baos);
116 String fileName = documentNumber + "_cover_sheet.pdf";
117 WebUtils.saveMimeOutputStreamAsFile(response, "application/pdf", baos, fileName);
118
119 return null;
120 }
121
122
123
124
125
126
127
128
129 protected void processCheckEntryMode(CashReceiptForm crForm, CashReceiptDocument crDoc) {
130 String formMode = crForm.getCheckEntryMode();
131 String docMode = crDoc.getCheckEntryMode();
132
133 if (CashReceiptDocument.CHECK_ENTRY_DETAIL.equals(formMode) || CashReceiptDocument.CHECK_ENTRY_TOTAL.equals(formMode)) {
134 if (!formMode.equals(docMode)) {
135 if (formMode.equals(CashReceiptDocument.CHECK_ENTRY_DETAIL)) {
136
137 crForm.setCheckTotal(crDoc.getTotalCheckAmount());
138
139
140 crDoc.setCheckEntryMode(formMode);
141 crDoc.setTotalCheckAmount(crDoc.calculateCheckTotal());
142
143
144 KNSGlobalVariables.getMessageList().add(OLEKeyConstants.CashReceipt.MSG_CHECK_ENTRY_INDIVIDUAL);
145 }
146 else {
147
148 crDoc.setTotalCheckAmount(crForm.getCheckTotal());
149
150
151 crDoc.setCheckEntryMode(formMode);
152
153
154 KNSGlobalVariables.getMessageList().add(OLEKeyConstants.CashReceipt.MSG_CHECK_ENTRY_TOTAL);
155 }
156 }
157 }
158 }
159
160
161
162
163
164
165
166 protected void processChecks(CashReceiptDocument cdoc, CashReceiptForm cform) {
167 List formChecks = cdoc.getChecks();
168
169 int index = 0;
170 Iterator i = formChecks.iterator();
171 while (i.hasNext()) {
172 Check formCheck = (Check) i.next();
173
174
175 String methodToCall = cform.getMethodToCall();
176 if (UPDATE_EVENT_ACTIONS.contains(methodToCall)) {
177 SpringContext.getBean(KualiRuleService.class).applyRules(new UpdateCheckEvent(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.CHECK + "[" + index + "]", cdoc, formCheck));
178 }
179 index++;
180 }
181 }
182
183
184
185
186
187
188
189
190
191
192
193 public ActionForward addCheck(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
194 CashReceiptForm crForm = (CashReceiptForm) form;
195 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
196
197 Check newCheck = crForm.getNewCheck();
198 newCheck.setDocumentNumber(crDoc.getDocumentNumber());
199
200
201 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddCheckEvent(OLEConstants.NEW_CHECK_PROPERTY_NAME, crDoc, newCheck));
202 if (rulePassed) {
203
204 crDoc.addCheck(newCheck);
205
206
207 crForm.setNewCheck(crDoc.createNewCheck());
208 }
209
210 return mapping.findForward(OLEConstants.MAPPING_BASIC);
211 }
212
213
214
215
216
217
218
219
220
221
222
223 public ActionForward addConfirmedCheck(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
224 CashReceiptForm crForm = (CashReceiptForm) form;
225 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
226
227 Check newCheck = crForm.getNewConfirmedCheck();
228 newCheck.setDocumentNumber(crDoc.getDocumentNumber());
229
230
231 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddCheckEvent(OLEConstants.NEW_CHECK_PROPERTY_NAME, crDoc, newCheck));
232 if (rulePassed) {
233
234 crDoc.addConfirmedCheck(newCheck);
235
236
237 crForm.setNewConfirmedCheck(crDoc.createNewConfirmedCheck());
238 }
239
240 return mapping.findForward(OLEConstants.MAPPING_BASIC);
241 }
242
243
244
245
246
247
248
249
250
251
252
253 public ActionForward deleteCheck(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
254 CashReceiptForm crForm = (CashReceiptForm) form;
255 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
256
257 int deleteIndex = getLineToDelete(request);
258 Check oldCheck = crDoc.getCheck(deleteIndex);
259
260
261 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new DeleteCheckEvent(OLEConstants.EXISTING_CHECK_PROPERTY_NAME, crDoc, oldCheck));
262
263 if (rulePassed) {
264
265 crDoc.removeCheck(deleteIndex);
266
267
268 if (crForm.hasBaselineCheck(deleteIndex)) {
269 crForm.getBaselineChecks().remove(deleteIndex);
270 }
271 }
272 else {
273 GlobalVariables.getMessageMap().putError("document.check[" + deleteIndex + "]", OLEKeyConstants.Check.ERROR_CHECK_DELETERULE, Integer.toString(deleteIndex));
274 }
275
276 return mapping.findForward(OLEConstants.MAPPING_BASIC);
277 }
278
279
280
281
282
283
284
285
286
287
288
289 public ActionForward deleteConfirmedCheck(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
290 CashReceiptForm crForm = (CashReceiptForm) form;
291 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
292
293 int deleteIndex = getLineToDelete(request);
294 Check oldCheck = crDoc.getConfirmedCheck(deleteIndex);
295
296
297 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new DeleteCheckEvent(OLEConstants.EXISTING_CHECK_PROPERTY_NAME, crDoc, oldCheck));
298
299 if (rulePassed) {
300
301 crDoc.removeConfirmedCheck(deleteIndex);
302
303
304 if (crForm.hasBaselineCheck(deleteIndex)) {
305 crForm.getBaselineChecks().remove(deleteIndex);
306 }
307 }
308 else {
309 GlobalVariables.getMessageMap().putError("document.confirmedCheck[" + deleteIndex + "]", OLEKeyConstants.Check.ERROR_CHECK_DELETERULE, Integer.toString(deleteIndex));
310 }
311
312 return mapping.findForward(OLEConstants.MAPPING_BASIC);
313 }
314
315
316
317
318
319
320
321
322
323
324
325
326 public ActionForward changeCheckEntryMode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
327
328 CashReceiptForm crForm = (CashReceiptForm) form;
329 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
330
331 String formMode = crForm.getCheckEntryMode();
332 String docMode = crDoc.getCheckEntryMode();
333
334 if (CashReceiptDocument.CHECK_ENTRY_DETAIL.equals(formMode) || CashReceiptDocument.CHECK_ENTRY_TOTAL.equals(formMode)) {
335 if (!formMode.equals(docMode)) {
336
337 if (formMode.equals(CashReceiptDocument.CHECK_ENTRY_DETAIL)) {
338
339 crForm.setCheckTotal(crDoc.getTotalCheckAmount());
340
341
342 crDoc.setCheckEntryMode(formMode);
343 crDoc.setTotalCheckAmount(crDoc.calculateCheckTotal());
344
345
346 KNSGlobalVariables.getMessageList().add(OLEKeyConstants.CashReceipt.MSG_CHECK_ENTRY_INDIVIDUAL);
347 }
348 else {
349
350 crDoc.setTotalCheckAmount(crForm.getCheckTotal());
351
352
353 crDoc.setCheckEntryMode(formMode);
354
355
356 KNSGlobalVariables.getMessageList().add(OLEKeyConstants.CashReceipt.MSG_CHECK_ENTRY_TOTAL);
357 }
358 }
359 }
360
361 return mapping.findForward(OLEConstants.MAPPING_BASIC);
362 }
363
364
365
366
367
368 @Override
369 protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
370 super.createDocument(kualiDocumentFormBase);
371
372 CashReceiptForm crForm = (CashReceiptForm) kualiDocumentFormBase;
373 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
374
375 CashReceiptService crs = SpringContext.getBean(CashReceiptService.class);
376 crDoc.initializeCampusLocationCode();
377
378
379 CurrencyDetail currencyDetail = new CurrencyDetail();
380 currencyDetail.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_RECEIPTS);
381 currencyDetail.setFinancialDocumentTypeCode(CashReceiptDocument.DOCUMENT_TYPE);
382 currencyDetail.setDocumentNumber(crDoc.getDocumentNumber());
383 crDoc.setCurrencyDetail(currencyDetail);
384
385 CoinDetail coinDetail = new CoinDetail();
386 coinDetail.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_RECEIPTS);
387 coinDetail.setFinancialDocumentTypeCode(CashReceiptDocument.DOCUMENT_TYPE);
388 coinDetail.setDocumentNumber(crDoc.getDocumentNumber());
389 crDoc.setCoinDetail(coinDetail);
390
391 CurrencyDetail confirmedCurrencyDetail = new CurrencyDetail();
392 confirmedCurrencyDetail.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_MANAGEMENT_IN);
393 confirmedCurrencyDetail.setFinancialDocumentTypeCode(CashReceiptDocument.DOCUMENT_TYPE);
394 confirmedCurrencyDetail.setDocumentNumber(crDoc.getDocumentNumber());
395 crDoc.setConfirmedCurrencyDetail(confirmedCurrencyDetail);
396
397 CoinDetail confirmedCoinDetail = new CoinDetail();
398 confirmedCoinDetail.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_MANAGEMENT_IN);
399 confirmedCoinDetail.setFinancialDocumentTypeCode(CashReceiptDocument.DOCUMENT_TYPE);
400 confirmedCoinDetail.setDocumentNumber(crDoc.getDocumentNumber());
401 crDoc.setConfirmedCoinDetail(confirmedCoinDetail);
402
403 initDerivedCheckValues(crForm);
404 }
405
406
407
408
409 @Override
410 protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
411 super.loadDocument(kualiDocumentFormBase);
412
413 initDerivedCheckValues((CashReceiptForm) kualiDocumentFormBase);
414 }
415
416
417
418
419
420
421
422
423
424
425
426 public ActionForward copyAllChecks(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
427 CashReceiptForm crForm = (CashReceiptForm) form;
428 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
429
430 Check c, confirmedCheck;
431 for (Iterator<Check> i = crDoc.getChecks().iterator(); i.hasNext();) {
432 c = i.next();
433 confirmedCheck = crForm.getNewConfirmedCheck();
434 confirmedCheck.setDocumentNumber(c.getDocumentNumber());
435 confirmedCheck.setCheckDate(c.getCheckDate());
436 confirmedCheck.setCheckNumber(c.getCheckNumber());
437 confirmedCheck.setAmount(c.getAmount());
438 confirmedCheck.setDescription(c.getDescription());
439
440 crDoc.addConfirmedCheck(confirmedCheck);
441
442 crForm.setNewConfirmedCheck(crDoc.createNewConfirmedCheck());
443 }
444
445 return mapping.findForward(OLEConstants.MAPPING_BASIC);
446 }
447
448
449
450
451
452
453
454
455
456
457
458 public ActionForward copyAllCurrencyAndCoin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
459 CashReceiptForm crForm = (CashReceiptForm) form;
460 CashReceiptDocument crDoc = crForm.getCashReceiptDocument();
461 CurrencyDetail currencyDetail = crDoc.getCurrencyDetail();
462 CoinDetail coinDetail = crDoc.getCoinDetail();
463
464
465 CurrencyDetail confCurrencyDetail = new CurrencyDetail();
466 confCurrencyDetail.setDocumentNumber(crDoc.getDocumentNumber());
467 confCurrencyDetail.setFinancialDocumentTypeCode(CashReceiptDocument.DOCUMENT_TYPE);
468 confCurrencyDetail.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_MANAGEMENT_IN);
469 confCurrencyDetail.setFinancialDocumentHundredDollarAmount(currencyDetail.getFinancialDocumentHundredDollarAmount());
470 confCurrencyDetail.setFinancialDocumentFiftyDollarAmount(currencyDetail.getFinancialDocumentFiftyDollarAmount());
471 confCurrencyDetail.setFinancialDocumentTwentyDollarAmount(currencyDetail.getFinancialDocumentTwentyDollarAmount());
472 confCurrencyDetail.setFinancialDocumentTenDollarAmount(currencyDetail.getFinancialDocumentTenDollarAmount());
473 confCurrencyDetail.setFinancialDocumentFiveDollarAmount(currencyDetail.getFinancialDocumentFiveDollarAmount());
474 confCurrencyDetail.setFinancialDocumentTwoDollarAmount(currencyDetail.getFinancialDocumentTwoDollarAmount());
475 confCurrencyDetail.setFinancialDocumentOneDollarAmount(currencyDetail.getFinancialDocumentOneDollarAmount());
476 confCurrencyDetail.setFinancialDocumentOtherDollarAmount(currencyDetail.getFinancialDocumentOtherDollarAmount());
477
478
479 CoinDetail confCoinDetail = new CoinDetail();
480 confCoinDetail.setDocumentNumber(crDoc.getDocumentNumber());
481 confCoinDetail.setFinancialDocumentTypeCode(CashReceiptDocument.DOCUMENT_TYPE);
482 confCoinDetail.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_MANAGEMENT_IN);
483 confCoinDetail.setFinancialDocumentHundredCentAmount(coinDetail.getFinancialDocumentHundredCentAmount());
484 confCoinDetail.setFinancialDocumentFiftyCentAmount(coinDetail.getFinancialDocumentFiftyCentAmount());
485 confCoinDetail.setFinancialDocumentTwentyFiveCentAmount(coinDetail.getFinancialDocumentTwentyFiveCentAmount());
486 confCoinDetail.setFinancialDocumentTenCentAmount(coinDetail.getFinancialDocumentTenCentAmount());
487 confCoinDetail.setFinancialDocumentFiveCentAmount(coinDetail.getFinancialDocumentFiveCentAmount());
488 confCoinDetail.setFinancialDocumentOneCentAmount(coinDetail.getFinancialDocumentOneCentAmount());
489 confCoinDetail.setFinancialDocumentOtherCentAmount(coinDetail.getFinancialDocumentOtherCentAmount());
490
491 crDoc.setConfirmedCurrencyDetail(confCurrencyDetail);
492 crDoc.setConfirmedCoinDetail(confCoinDetail);
493
494 return mapping.findForward(OLEConstants.MAPPING_BASIC);
495 }
496
497
498
499
500
501
502
503
504 protected void initDerivedCheckValues(CashReceiptForm cform) {
505 CashReceiptDocument cdoc = cform.getCashReceiptDocument();
506
507 cform.setCheckEntryMode(cdoc.getCheckEntryMode());
508 cform.setCheckTotal(cdoc.getTotalCheckAmount());
509
510 cform.getBaselineChecks().clear();
511 cform.getBaselineChecks().addAll(cform.getCashReceiptDocument().getChecks());
512 }
513
514
515
516
517
518 @Override
519 public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
520 ActionForward forward = super.copy(mapping, form, request, response);
521 initDerivedCheckValues((CashReceiptForm)form);
522 return forward;
523 }
524
525 }
526