1 package org.kuali.ole.deliver.loan.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.LoanUtil;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.circulationdesk.keyvalue.CirculationDeskChangeKeyValue;
7 import org.kuali.ole.deliver.loan.LoanProcessor;
8 import org.kuali.ole.deliver.loan.bo.OleLoanDocument;
9 import org.kuali.ole.deliver.loan.bo.OleLoanFastAdd;
10 import org.kuali.ole.deliver.loan.form.OleLoanForm;
11 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
12 import org.kuali.ole.location.bo.OleLocation;
13 import org.kuali.ole.patron.bill.PatronBill;
14 import org.kuali.ole.patron.bill.PatronBillHelperService;
15 import org.kuali.ole.patron.bo.OlePatronDocument;
16 import org.kuali.ole.pojo.bib.BibliographicRecord;
17 import org.kuali.ole.service.OleDeliveryDocstoreService;
18 import org.kuali.ole.service.impl.OleDeliveryDocstoreServiceImpl;
19 import org.kuali.rice.core.api.util.KeyValue;
20 import org.kuali.rice.krad.service.BusinessObjectService;
21 import org.kuali.rice.krad.util.GlobalVariables;
22 import org.kuali.rice.krad.web.controller.UifControllerBase;
23 import org.kuali.rice.krad.web.form.UifFormBase;
24 import org.springframework.stereotype.Controller;
25 import org.springframework.validation.BindingResult;
26 import org.springframework.web.bind.annotation.ModelAttribute;
27 import org.springframework.web.bind.annotation.RequestMapping;
28 import org.springframework.web.servlet.ModelAndView;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.math.BigDecimal;
33 import java.sql.Timestamp;
34 import java.util.*;
35
36
37
38
39
40 @Controller
41 @RequestMapping(value = "/loancontroller")
42 public class LoanController extends UifControllerBase {
43
44 private static final Logger LOG = Logger.getLogger(LoanController.class);
45
46
47
48
49
50
51
52 @Override
53 protected OleLoanForm createInitialForm(HttpServletRequest request) {
54 return new OleLoanForm();
55 }
56
57
58
59
60
61
62
63
64
65 @Override
66 @RequestMapping(params = "methodToCall=start")
67 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
68 HttpServletRequest request, HttpServletResponse response) {
69 LOG.debug("Inside the loan start method");
70 OleLoanForm oleLoanForm = (OleLoanForm) form;
71 oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
72 oleLoanForm.setCurrentDate(new Date());
73 if(oleLoanForm.getCheckInDate()==null){
74 oleLoanForm.setCheckInDate(new Date());
75 }
76 return super.start(oleLoanForm, result, request, response);
77 }
78
79
80
81
82
83
84
85
86
87 @RequestMapping(params = "methodToCall=searchPatron")
88 public ModelAndView searchPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
89 HttpServletRequest request, HttpServletResponse response) {
90 LOG.debug("Inside the search patron method");
91 OleLoanForm oleLoanForm = (OleLoanForm) form;
92 oleLoanForm.setInformation("");
93 oleLoanForm.setReturnInformation("");
94 try{
95
96 if(oleLoanForm.getCirculationDesk() ==null){
97 LOG.error(OLEConstants.CIR_LOC_NULL);
98 throw new Exception(OLEConstants.CIR_LOC_NULL);
99 }
100 List<OlePatronDocument> oleRealPatron= oleLoanForm.getRealPatronList();
101 if(oleRealPatron != null && oleRealPatron.size()>0){
102 for(int realPatron=0;realPatron<oleRealPatron.size();realPatron++){
103 OlePatronDocument olePatronDocument = oleRealPatron.get(realPatron);
104 if(olePatronDocument.isRealPatronCheck()){
105 oleLoanForm.setRealPatronBarcode(olePatronDocument.getBarcode());
106 oleLoanForm.setRealPatronFlag(false);
107 }
108 }
109 }
110
111 OleLoanDocument oleLoanDocument = getLoanProcessor().getLoanDocument(oleLoanForm.getPatronBarcode(),oleLoanForm.getRealPatronBarcode());
112 if(oleLoanDocument.getPatronUserNotes() != null){
113 oleLoanForm.setPatronNoteFlag(true);
114 oleLoanForm.setPatronUserNote(oleLoanDocument.getPatronUserNotes());
115 oleLoanForm.setPatronNoteTypeId(oleLoanDocument.getPatronNoteTypeId());
116 }
117 if(oleLoanDocument.getRealPatron()!=null && oleLoanDocument.getRealPatron().size() > 1){
118 oleLoanForm.setRealPatronList(oleLoanDocument.getRealPatron());
119 oleLoanForm.setRealPatronFlag(true);
120 }
121 oleLoanForm.setBorrowerType(oleLoanDocument.getBorrowerTypeName());
122 oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
123 oleLoanForm.setPatronId(oleLoanDocument.getPatronId());
124 oleLoanForm.setProxyPatronId(oleLoanDocument.getProxyPatronId());
125 oleLoanForm.setRealPatronName(oleLoanDocument.getRealPatronName());
126 oleLoanForm.setRealPatronType(oleLoanDocument.getRealPatronType());
127 oleLoanForm.setBlockLoan(oleLoanDocument.isBlockLoan());
128 oleLoanForm.setBorrowerTypeId(oleLoanDocument.getBorrowerTypeId());
129 oleLoanForm.setPreferredAddress(oleLoanDocument.getPreferredAddress());
130 oleLoanForm.setEmail(oleLoanDocument.getEmail());
131 oleLoanForm.setPhoneNumber(oleLoanDocument.getPhoneNumber());
132 oleLoanForm.setInformation("");
133 oleLoanForm.setExistingLoanList(getLoanProcessor().getPatronLoanedItem(oleLoanDocument.getPatronId()));
134 oleLoanForm.setDummyLoan(oleLoanDocument);
135 if(oleLoanDocument.getErrorMessage()!=null){
136 oleLoanForm.setSuccess(false);
137 oleLoanForm.setInformation("");
138 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
139 oleLoanForm.setPatronName(null);
140 }
141 }catch (Exception e){
142 oleLoanForm.setInformation(e.getMessage());
143 }
144 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
145 }
146
147
148
149
150
151
152
153
154
155 @RequestMapping(params = "methodToCall=addItem")
156 public ModelAndView addItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
157 HttpServletRequest request, HttpServletResponse response) {
158 LOG.debug("Inside the add item method");
159 OleLoanForm oleLoanForm = (OleLoanForm) form;
160
161 oleLoanForm.setInformation("");
162 oleLoanForm.setReturnInformation("");
163 boolean renewalFlag=false;
164 List<OleLoanDocument> existItemList=new ArrayList<OleLoanDocument>();
165 if(oleLoanForm.getExistingLoanList()!=null && !oleLoanForm.getExistingLoanList().isEmpty())
166 existItemList.addAll(oleLoanForm.getExistingLoanList());
167 if(oleLoanForm.getLoanList()!=null && !oleLoanForm.getLoanList().isEmpty())
168 existItemList.addAll(oleLoanForm.getLoanList());
169 String item=oleLoanForm.getItem();
170 for(int i=0;i<existItemList.size();i++) {
171 OleLoanDocument oleLoanDocument=existItemList.get(i);
172 if(oleLoanDocument.getItemId() != null && oleLoanDocument.getItemId().equals(item)){
173 oleLoanForm.setRenewalFlag(true);
174 oleLoanForm.setSuccess(false);
175 oleLoanForm.setMessage(OLEConstants.RENEWAL_ITM_POPUP);
176 renewalFlag=true;
177 break;
178 }
179 }
180
181 if(!renewalFlag) {
182
183 try{
184 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
185
186 OleLoanDocument oleLoanDocument = new OleLoanDocument();
187 oleLoanDocument.setPatronId(oleLoanForm.getPatronId());
188 oleLoanDocument.setProxyPatronId(oleLoanForm.getProxyPatronId());
189 oleLoanDocument.setRealPatronBarcode(oleLoanForm.getRealPatronBarcode());
190 oleLoanDocument.setRealPatronType(oleLoanForm.getRealPatronType());
191 oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
192 oleLoanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
193 oleLoanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
194 oleLoanDocument = getLoanProcessor().addLoan(oleLoanForm.getPatronBarcode(),oleLoanForm.getItem(),oleLoanDocument);
195 oleLoanForm.setItemUuid(oleLoanDocument.getItemUuid());
196 oleLoanForm.setInstanceUuid(oleLoanDocument.getInstanceUuid());
197 oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
198 oleLoanForm.setDueDateMap(oleLoanDocument.getLoanDueDate());
199 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
200 if(oleLoanForm.getPatronName()==null){
201 oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
202 }
203 if(oleLoanDocument.getErrorMessage() == null){
204 existingItemList.add(oleLoanDocument);
205 oleLoanForm.setItem("");
206 oleLoanForm.setInformation("");
207 } else {
208 oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
209 oleLoanForm.setDummyLoan(oleLoanDocument);
210 oleLoanForm.setSuccess(false);
211 oleLoanForm.setInformation("");
212 }
213 if(oleLoanForm.getLoanList()!=null && !oleLoanForm.getLoanList().isEmpty()){
214 existingItemList.addAll(oleLoanForm.getLoanList());
215 }
216 oleLoanForm.setLoanList(existingItemList);
217 }catch (Exception e){
218 oleLoanForm.setInformation(e.getMessage());
219
220 }
221 }
222 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
223 }
224
225
226
227
228
229
230
231
232
233 @RequestMapping(params = "methodToCall=loan")
234 public ModelAndView loanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
235 HttpServletRequest request, HttpServletResponse response) {
236 LOG.debug("Inside the loan patron method");
237 OleLoanForm oleLoanForm = (OleLoanForm) form;
238 oleLoanForm.setInformation("");
239 oleLoanForm.setReturnInformation("");
240 ModelAndView overrideModelView=this.overRide(form,result,request,response);
241 if(overrideModelView==null){
242 try{
243 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
244 OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
245 if(oleLoanDocument!=null){
246 if(oleLoanForm.getDueDateMap()!=null){
247 oleLoanDocument.setLoanDueDate(new java.sql.Timestamp(oleLoanForm.getDueDateMap().getTime()));
248 getLoanProcessor().saveLoan(oleLoanDocument);
249 existingItemList.add(oleLoanDocument);
250 if(oleLoanForm.getLoanList()!=null && !oleLoanForm.getLoanList().isEmpty()){
251 existingItemList.addAll(oleLoanForm.getLoanList());
252 }
253 oleLoanForm.setLoanList(existingItemList);
254 }
255 if(oleLoanForm.getPatronName()==null){
256 oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
257 }
258 oleLoanForm.setSuccess(true);
259 oleLoanForm.setMessage(null);
260 oleLoanForm.setItem("");
261 oleLoanForm.setInformation("");
262 }
263 }catch (Exception e){
264 oleLoanForm.setInformation(e.getMessage());
265 }
266 }
267 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
268 }
269
270
271
272
273
274
275
276
277
278 @RequestMapping(params = "methodToCall=noLoan")
279 public ModelAndView doNotLoanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
280 HttpServletRequest request, HttpServletResponse response) {
281 LOG.debug("Inside the do not loan patron method");
282 OleLoanForm oleLoanForm = (OleLoanForm) form;
283 oleLoanForm.setItem("");
284 oleLoanForm.setInformation("");
285 oleLoanForm.setReturnInformation("");
286 oleLoanForm.setMessage(null);
287 oleLoanForm.setSuccess(true);
288 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
289 }
290
291 @RequestMapping(params = "methodToCall=displayFastAdd")
292 public ModelAndView displayFastAdd(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
293 HttpServletRequest request, HttpServletResponse response) {
294 LOG.debug("Inside the display Fast Add method");
295 OleLoanForm oleLoanForm = (OleLoanForm) form;
296 String locationId = request.getParameter("locationId");
297 oleLoanForm.setInformation("");
298 oleLoanForm.setReturnInformation("");
299 try {
300 OleLocation location = getLoanProcessor().getLocationByLocationId(locationId);
301 if(location != null){
302 OleLoanFastAdd oleLoanFastAdd = new OleLoanFastAdd();
303 oleLoanFastAdd.setCirculationLocation(location.getLocationCode());
304 oleLoanForm.setOleLoanFastAdd(oleLoanFastAdd);
305 }
306 } catch (Exception e) {
307 oleLoanForm.setInformation(e.getMessage());
308 }
309 return getUIFModelAndView(oleLoanForm, "FastAddItemViewPage");
310 }
311
312
313 @RequestMapping(params = "methodToCall=createFastAddItem")
314 public ModelAndView createFastAddItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
315 HttpServletRequest request, HttpServletResponse response) {
316 LOG.debug("Inside the create fast add item method");
317 OleLoanForm oleLoanForm = (OleLoanForm) form;
318 oleLoanForm.setInformation("");
319 oleLoanForm.setReturnInformation("");
320
321 BibliographicRecord bibliographicRecord=getLoanProcessor().getBibliographicRecord(oleLoanForm.getOleLoanFastAdd().getTitle());
322 Item item= getLoanProcessor().getItemRecord(oleLoanForm.getOleLoanFastAdd());
323 OleDeliveryDocstoreService oleDeliveryDocstoreService=new OleDeliveryDocstoreServiceImpl();
324 String responseXML=oleDeliveryDocstoreService.persistNewToDocstoreForIngest(bibliographicRecord,item);
325 if(responseXML==null)
326 oleLoanForm.setInformation(OLEConstants.FAST_ADD_ITM_ERR_INFO);
327 else
328 oleLoanForm.setInformation(OLEConstants.FAST_ADD_ITM_SUCCESS_INFO);
329
330 return getUIFModelAndView(oleLoanForm, "FastAddItemViewPage");
331 }
332
333 @RequestMapping(params = "methodToCall=deletePatronUserNote")
334 public ModelAndView deletePatronUserNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
335 HttpServletRequest request, HttpServletResponse response) {
336 LOG.debug("Inside the delete patron user note method");
337 OleLoanForm oleLoanForm = (OleLoanForm) form;
338 oleLoanForm.setPatronNoteFlag(false);
339
340 try {
341 getLoanProcessor().deletePatronUserNote(oleLoanForm.getPatronId(),oleLoanForm.getPatronNoteTypeId());
342 } catch (Exception e) {
343 oleLoanForm.setInformation(e.getMessage());
344 }
345 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
346 }
347
348
349 @RequestMapping(params = "methodToCall=editDueDate")
350 public ModelAndView editDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
351 HttpServletRequest request, HttpServletResponse response) {
352 LOG.debug("Inside the edit due date method");
353 OleLoanForm oleLoanForm = (OleLoanForm) form;
354 oleLoanForm.setInformation("");
355 oleLoanForm.setReturnInformation("");
356
357 List<OleLoanDocument> alterDueDateList = new ArrayList<OleLoanDocument>();
358 alterDueDateList = getLoanProcessor().setListValues(oleLoanForm.getLoanList(),oleLoanForm.getExistingLoanList(),false,null);
359
360 if(alterDueDateList.size()!=0) {
361 oleLoanForm.setAlterDueDateList(alterDueDateList);
362 oleLoanForm.setInformation("");
363 ModelAndView overrideModelView=this.overRide(form,result,request,response);
364 if(overrideModelView==null)
365 oleLoanForm.setAlterDueDateFlag(true);
366 }
367 else
368 oleLoanForm.setInformation(OLEConstants.ALTER_DUE_DATE_ERR_INFO);
369
370 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
371 }
372
373 @RequestMapping(params = "methodToCall=updateDueDate")
374 public ModelAndView updateDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
375 HttpServletRequest request, HttpServletResponse response) {
376 LOG.debug("Inside the update due date method");
377 OleLoanForm oleLoanForm = (OleLoanForm) form;
378 oleLoanForm.setInformation("");
379 oleLoanForm.setReturnInformation("");
380 try{
381 getLoanProcessor().updateLoan(oleLoanForm.getAlterDueDateList());
382 }catch (Exception e){
383 oleLoanForm.setInformation(e.getMessage());
384 }
385 oleLoanForm.setAlterDueDateFlag(false);
386 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
387 }
388
389 @RequestMapping(params = "methodToCall=closeAlterDueDate")
390 public ModelAndView closeAlterDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
391 HttpServletRequest request, HttpServletResponse response) {
392 LOG.debug("Inside the close Alter due date method");
393 OleLoanForm oleLoanForm = (OleLoanForm) form;
394 List<OleLoanDocument> resetAlterDueDate =oleLoanForm.getAlterDueDateList();
395 if(resetAlterDueDate!=null){
396 for(int restDueDate=0;restDueDate<resetAlterDueDate.size();restDueDate++){
397 OleLoanDocument oleLoanDocument = (OleLoanDocument)resetAlterDueDate.get(restDueDate);
398 oleLoanDocument.setLoanDueDate(new Timestamp(oleLoanDocument.getPastDueDate().getTime()));
399 oleLoanDocument.setPastDueDate(null);
400 }
401 }
402
403 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
404 }
405
406 @RequestMapping(params = "methodToCall=claimsReturn")
407 public ModelAndView claimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
408 HttpServletRequest request, HttpServletResponse response) {
409 LOG.debug("Inside the claims return method");
410 OleLoanForm oleLoanForm = (OleLoanForm) form;
411 oleLoanForm.setInformation("");
412 oleLoanForm.setReturnInformation("");
413 boolean checkedItemsFlag=false;
414 for(int curremtLoan=0;curremtLoan< oleLoanForm.getExistingLoanList().size();curremtLoan++){
415 OleLoanDocument oleLoanDocument = (OleLoanDocument)oleLoanForm.getExistingLoanList().get(curremtLoan);
416 if(oleLoanDocument.isCheckNo()) {
417 checkedItemsFlag=true;
418 break;
419 }
420 }
421 if(checkedItemsFlag){
422 oleLoanForm.setInformation("");
423 ModelAndView overrideModelView=this.overRide(form,result,request,response);
424 if(overrideModelView==null)
425 oleLoanForm.setClaimsReturnFlag(true);
426 }
427 else
428 oleLoanForm.setInformation(OLEConstants.CLAIMS_ITM_ERR_INFO);
429 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
430 }
431
432 @RequestMapping(params = "methodToCall=applyClaimsReturn")
433 public ModelAndView applyClaimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
434 HttpServletRequest request, HttpServletResponse response) {
435 LOG.debug("Inside the apply claims return method");
436 OleLoanForm oleLoanForm = (OleLoanForm) form;
437 oleLoanForm.setInformation("");
438 oleLoanForm.setReturnInformation("");
439 List<OleLoanDocument> claimsList = new ArrayList<OleLoanDocument>();
440 claimsList = getLoanProcessor().setListValues(oleLoanForm.getLoanList(),oleLoanForm.getExistingLoanList(),oleLoanForm.isClaimsReturnFlag(),oleLoanForm.getClaimsReturnMap());
441 try{
442 getLoanProcessor().updateLoan(claimsList);
443 }catch (Exception e){
444 oleLoanForm.setInformation(e.getMessage());
445 }
446 oleLoanForm.setClaimsReturnFlag(false);
447 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
448 }
449
450 @RequestMapping(params = "methodToCall=changeCirculationDeskLocation")
451 public ModelAndView changeCirculationDeskLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
452 HttpServletRequest request, HttpServletResponse response){
453 LOG.debug("Inside the change circulation desk location method");
454 OleLoanForm oleLoanForm = (OleLoanForm) form;
455 oleLoanForm.setConfirmMessage(OLEConstants.CHANGE_LOC_MESS);
456 oleLoanForm.setChangeLocationFlag(true);
457 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
458 }
459
460 @RequestMapping(params = "methodToCall=resetLocation")
461 public ModelAndView resetLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
462 HttpServletRequest request, HttpServletResponse response){
463 LOG.debug("Inside the reset location method");
464 OleLoanForm oleLoanForm = (OleLoanForm) form;
465 CirculationDeskChangeKeyValue circulationDeskChangeKeyValue = new CirculationDeskChangeKeyValue();
466 String defaultCirculationLocation = circulationDeskChangeKeyValue.getDefaultCirculationLocation();
467 if(defaultCirculationLocation!=null){
468 oleLoanForm.setCirculationDesk(defaultCirculationLocation);
469 }
470 oleLoanForm.setChangeLocationFlag(false);
471 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
472 }
473
474
475
476
477
478
479
480
481 @RequestMapping(params = "methodToCall=saveAndClear")
482 public ModelAndView clearPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
483 HttpServletRequest request, HttpServletResponse response) {
484 LOG.debug("Inside the clear patron method");
485 OleLoanForm oleLoanForm = (OleLoanForm) form;
486 oleLoanForm.setInformation("");
487 oleLoanForm.setReturnInformation("");
488 oleLoanForm.setBorrowerType(null);
489 oleLoanForm.setPatronBarcode(null);
490 oleLoanForm.setPatronName(null);
491 oleLoanForm.setProxyPatronId(null);
492 oleLoanForm.setRealPatronBarcode(null);
493 oleLoanForm.setPatronId(null);
494 oleLoanForm.setRealPatronList(null);
495 oleLoanForm.setLoanList(null);
496 oleLoanForm.setDueDateMap(null);
497 oleLoanForm.setExistingLoanList(null);
498 oleLoanForm.setDueDateMap(null);
499 oleLoanForm.setMessage(null);
500 oleLoanForm.setSuccess(true);
501 oleLoanForm.setChangeLocationFlag(false);
502 oleLoanForm.setBlockLoan(false);
503 if(!"".equals(oleLoanForm.getNewPrincipalId())){
504 GlobalVariables.getUserSession().clearBackdoorUser();
505 oleLoanForm.setNewPrincipalId(null);
506 }
507 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
508 }
509
510
511
512
513
514
515
516
517
518 @RequestMapping(params = "methodToCall=overRide")
519 public ModelAndView overRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
520 HttpServletRequest request, HttpServletResponse response) {
521 LOG.debug("Inside the override method");
522 OleLoanForm oleLoanForm = (OleLoanForm) form;
523 oleLoanForm.setInformation("");
524 oleLoanForm.setReturnInformation("");
525 oleLoanForm.setOverideMethodCall(oleLoanForm.getMethodToCall());
526 oleLoanForm.setOverrideFlag(true);
527 String principalId= GlobalVariables.getUserSession().getPrincipalId();
528 if(!"".equals(oleLoanForm.getNewPrincipalId()))
529 principalId=oleLoanForm.getNewPrincipalId();
530
531 Boolean overRideFlag=getLoanProcessor().checkOverRidePermission(principalId);
532
533 if(overRideFlag) {
534 if(!"".equals(oleLoanForm.getNewPrincipalId()) && oleLoanForm.getNewPrincipalId()!=null)
535 GlobalVariables.getUserSession().setBackdoorUser( oleLoanForm.getNewPrincipalId() );
536 oleLoanForm.setOverrideFlag(false);
537 oleLoanForm.setOverideMethodCall("");
538
539 return null;
540 }
541
542 if(!"".equals(oleLoanForm.getNewPrincipalId()))
543 oleLoanForm.setOverrideLoginMessage(OLEConstants.OVERRIDE_LOGIN_ERR_INFO);
544 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
545 }
546
547
548
549
550
551
552
553
554
555
556 @RequestMapping(params = "methodToCall=noOverRide")
557 public ModelAndView noOverRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
558 HttpServletRequest request, HttpServletResponse response) {
559 LOG.debug("Inside the no override method");
560 OleLoanForm oleLoanForm = (OleLoanForm) form;
561 oleLoanForm.setOverrideFlag(false);
562 oleLoanForm.setOverideMethodCall("");
563 oleLoanForm.setOverrideLoginMessage("");
564 oleLoanForm.setInformation("");
565 oleLoanForm.setReturnInformation("");
566 oleLoanForm.setNewPrincipalId(null);
567 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
568 }
569
570
571
572
573
574
575
576
577
578 @RequestMapping(params = "methodToCall=renewalItem")
579 public ModelAndView renewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
580 HttpServletRequest request, HttpServletResponse response) {
581 LOG.debug("Inside the renewal item method");
582 OleLoanForm oleLoanForm = (OleLoanForm) form;
583 oleLoanForm.setInformation("");
584
585
586 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
587 existingItemList.addAll(oleLoanForm.getExistingLoanList());
588 if(oleLoanForm.getLoanList()!=null && !oleLoanForm.getLoanList().isEmpty())
589 existingItemList.addAll(oleLoanForm.getLoanList());
590 OleLoanDocument oleLoanDocument=null;
591 for(int i=0;i<existingItemList.size();i++)
592 {
593 OleLoanDocument loanDocument= existingItemList.get(i);
594 if(loanDocument.getItemId().equals(oleLoanForm.getItem())) {
595 oleLoanDocument=loanDocument;
596 oleLoanDocument.setRenewalItemFlag(true);
597 break;
598 }
599 }
600 try{
601 oleLoanDocument.setPatronId(oleLoanForm.getPatronId());
602 oleLoanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
603 oleLoanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
604 oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
605 oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(),oleLoanDocument.getItemId(),oleLoanDocument);
606 if(oleLoanDocument.getErrorMessage() == null){
607 oleLoanForm.setRenewalFlag(false);
608 oleLoanForm.setSuccess(true);
609 oleLoanForm.setMessage("");
610 oleLoanForm.setInformation(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
611 }else
612 {
613 String errMsg=oleLoanDocument.getErrorMessage().substring(0,oleLoanDocument.getErrorMessage().lastIndexOf("(OR)"));
614 oleLoanForm.setMessage("1. "+errMsg);
615 }
616
617 }
618 catch(Exception e) {
619 oleLoanForm.setInformation(e.getMessage());
620 }
621
622 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
623 }
624
625
626
627
628
629
630
631
632
633 @RequestMapping(params = "methodToCall=doNotRenewalItem")
634 public ModelAndView doNotRenewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
635 HttpServletRequest request, HttpServletResponse response) {
636 LOG.debug("Inside the do not renewal item method");
637 OleLoanForm oleLoanForm = (OleLoanForm) form;
638 oleLoanForm.setInformation("");
639 oleLoanForm.setReturnInformation("");
640 oleLoanForm.setRenewalFlag(false);
641 oleLoanForm.setSuccess(true);
642 oleLoanForm.setMessage("");
643 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
644 }
645
646
647
648
649
650
651
652
653
654 @RequestMapping(params = "methodToCall=renewalItems")
655 public ModelAndView renewalItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
656 HttpServletRequest request, HttpServletResponse response) {
657 LOG.debug("Inside the renewal items method");
658 OleLoanForm oleLoanForm = (OleLoanForm) form;
659 oleLoanForm.setInformation("");
660
661
662 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
663 existingItemList.addAll(oleLoanForm.getExistingLoanList());
664 boolean currentRenewalFlag=true;
665 for(int i=0;i<oleLoanForm.getLoanList().size();i++){
666 OleLoanDocument loanDocument= oleLoanForm.getLoanList().get(i);
667 if(loanDocument.isCheckNo()) {
668 oleLoanForm.setInformation(OLEConstants.RENEWAL_ITM_ERR_INFO);
669 currentRenewalFlag=false;
670 break;
671 }
672 }
673 if(currentRenewalFlag) {
674
675 for(int i=0;i<existingItemList.size();i++)
676 {
677 OleLoanDocument loanDocument= existingItemList.get(i);
678 if(loanDocument.isCheckNo()){
679 currentRenewalFlag=false;
680 try{
681 loanDocument.setPatronId(oleLoanForm.getPatronId());
682 loanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
683 loanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
684 loanDocument.setRenewalItemFlag(true);
685 loanDocument = getLoanProcessor().addLoan(loanDocument.getPatronBarcode(),loanDocument.getItemId(),loanDocument);
686 if(loanDocument.getErrorMessage() == null){
687
688
689
690 oleLoanForm.setInformation(oleLoanForm.getInformation()==null?"":oleLoanForm.getInformation()+"\n"+(i+1)+". "+OLEConstants.RENEWAL_ITM_SUCCESS_INFO+" ("+loanDocument.getItemId()+")<br/>");
691 }else
692 {
693 String errMsg=loanDocument.getErrorMessage().substring(0,loanDocument.getErrorMessage().lastIndexOf("(OR)"));
694 oleLoanForm.setInformation(oleLoanForm.getInformation()==null?"":oleLoanForm.getInformation()+"\n"+(i+1)+". "+errMsg+" ("+loanDocument.getItemId()+")<br/>");
695 }
696 }
697 catch(Exception e) {
698 LOG.error("exception ------"+e);
699 }
700 }
701 }
702 }
703 if(currentRenewalFlag)
704 oleLoanForm.setInformation(OLEConstants.RENEWAL_ITM_ERR_INFO);
705
706 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
707 }
708
709
710
711
712
713
714
715 private LoanProcessor getLoanProcessor() {
716 return new LoanProcessor();
717 }
718
719
720
721
722
723
724
725
726 @RequestMapping(params = "methodToCall=validateItem")
727 public ModelAndView validateItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
728 HttpServletRequest request, HttpServletResponse response) {
729 if(LOG.isDebugEnabled()){
730 LOG.info(" Inside Validate Item ");
731 }
732 OleLoanForm oleLoanForm = (OleLoanForm)form;
733 oleLoanForm.setReturnInformation("");
734 OleLoanDocument oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemBarcode(oleLoanForm.getCheckInItem());
735 if(oleLoanDocument==null){
736 oleLoanDocument = new OleLoanDocument();
737 }
738 try{
739 if(oleLoanForm.getCirculationDesk() ==null){
740 LOG.error(OLEConstants.CIR_LOC_NULL);
741 throw new Exception(OLEConstants.CIR_LOC_NULL);
742 }
743 if(oleLoanDocument.isClaimsReturnedIndicator()){
744 oleLoanForm.setDummyLoan(oleLoanDocument);
745 oleLoanForm.setClaimsReturned(true);
746 oleLoanForm.setReturnSuccess(false);
747 oleLoanForm.setReturnMessage(LoanUtil.getLoanUtil().getProperty("CLAIMS_RETURNED_MESSAGE"));
748 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
749 }
750 oleLoanDocument.setCheckInDate(oleLoanForm.getCheckInDate());
751 oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
752 oleLoanDocument.setDamagedCheckInOption(oleLoanForm.isDamagedCheckInOption());
753 LOG.info("Check-in Item Barcode Number --->"+oleLoanForm.getCheckInItem());
754 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanForm.getCheckInItem(),oleLoanDocument);
755 oleLoanForm.setDummyLoan(oleLoanDocument);
756 if(oleLoanDocument.isNumberOfPieces()){
757 oleLoanForm.setNumberOfPieces(true);
758 oleLoanForm.setReturnSuccess(false);
759 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES+oleLoanDocument.getItemNumberOfPieces()+OLEConstants.PIECES_RETURNED);
760 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
761 }
762 }catch(Exception e){
763 LOG.error("Error in validate Item "+e);
764 oleLoanForm.setReturnInformation(e.getMessage());
765 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
766 }
767 if(oleLoanDocument.getErrorMessage()!=null){
768 if(oleLoanDocument.isCheckOut()){
769 oleLoanForm.setSuccess(false);
770 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
771 } else{
772 oleLoanForm.setReturnSuccess(false);
773 oleLoanForm.setReturnMessage(oleLoanDocument.getErrorMessage());
774 }
775 } else{
776 List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
777 oleLoanDocuments.add(oleLoanDocument);
778 if(oleLoanForm.getItemReturnList()!=null){
779 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
780 }
781 oleLoanForm.setItemReturnList(oleLoanDocuments);
782 oleLoanForm.setCheckInItem("");
783 }
784 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
785 }
786
787
788
789
790
791
792
793
794 @RequestMapping(params = "methodToCall=returnItem")
795 public ModelAndView returnItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
796 HttpServletRequest request, HttpServletResponse response) {
797 if(LOG.isDebugEnabled()){
798 LOG.info(" Inside Return Item ");
799 }
800 OleLoanForm oleLoanForm = (OleLoanForm)form;
801 OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
802 try {
803 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
804 if(oleLoanDocument.isNumberOfPieces()){
805 oleLoanForm.setNumberOfPieces(true);
806 oleLoanForm.setReturnSuccess(false);
807 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES+oleLoanDocument.getItemNumberOfPieces()+OLEConstants.PIECES_RETURNED);
808 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
809 }
810 List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
811 oleLoanDocuments.add(oleLoanDocument);
812 if(oleLoanForm.getItemReturnList()!=null){
813 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
814 }
815 oleLoanForm.setItemReturnList(oleLoanDocuments);
816 } catch (Exception e) {
817 LOG.error("Error in return Item "+e);
818 e.printStackTrace();
819 }
820 oleLoanForm.setReturnSuccess(true);
821 oleLoanForm.setReturnMessage(null);
822 oleLoanForm.setCheckInItem("");
823 oleLoanForm.setReturnInformation("");
824 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
825 }
826
827
828
829
830
831
832
833
834 @RequestMapping(params = "methodToCall=noReturnItem")
835 public ModelAndView doNotReturnItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
836 HttpServletRequest request, HttpServletResponse response) {
837 if(LOG.isDebugEnabled()){
838 LOG.info(" Inside Do Not Return Item ");
839 }
840 OleLoanForm oleLoanForm = (OleLoanForm)form;
841 oleLoanForm.setReturnInformation("");
842 oleLoanForm.setCheckInItem("");
843 oleLoanForm.setReturnMessage(null);
844 oleLoanForm.setReturnSuccess(true);
845 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
846 }
847
848
849
850
851
852
853
854
855
856 @RequestMapping(params = "methodToCall=continueCheckIn")
857 public ModelAndView continueCheckIn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
858 HttpServletRequest request, HttpServletResponse response) {
859 if(LOG.isDebugEnabled()){
860 LOG.info(" Inside Continue Check-in ");
861 }
862 OleLoanForm oleLoanForm = (OleLoanForm)form;
863 String description = oleLoanForm.getDescription();
864 String matchCheck = oleLoanForm.getMatchCheck();
865 OleLoanDocument oleLoanDocument = new OleLoanDocument();
866 oleLoanDocument = oleLoanForm.getDummyLoan();
867 try {
868 if(oleLoanDocument.isClaimsReturnedIndicator()){
869 oleLoanForm.setClaimsReturned(false);
870 oleLoanForm.setReturnSuccess(true);
871 oleLoanForm.setReturnMessage(null);
872 getLoanProcessor().updateClaimsReturnedInLoanDocument(oleLoanDocument,false);
873 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
874 }
875 if(matchCheck.equalsIgnoreCase("true")){
876 oleLoanDocument.setContinueCheckIn(true);
877 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
878 }else {
879 getLoanProcessor().updateItemStatusWithMissingItem(oleLoanDocument);
880 }
881 List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
882 oleLoanDocuments.add(oleLoanDocument);
883 if(oleLoanForm.getItemReturnList()!=null){
884 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
885 }
886 oleLoanForm.setItemReturnList(oleLoanDocuments);
887 } catch (Exception e) {
888 LOG.error("Error in Continue Check-in "+e);
889 e.printStackTrace();
890 }
891 oleLoanForm.setNumberOfPieces(false);
892 oleLoanForm.setReturnSuccess(true);
893 oleLoanForm.setReturnMessage(null);
894 oleLoanForm.setCheckInItem("");
895 oleLoanForm.setReturnInformation("");
896 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
897 }
898
899
900
901
902
903
904
905
906
907 @RequestMapping(params = "methodToCall=endCheckInSession")
908 public ModelAndView endCheckInSession(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
909 HttpServletRequest request, HttpServletResponse response) {
910 if(LOG.isDebugEnabled()){
911 LOG.info(" Inside End Check-in session ");
912 }
913 OleLoanForm oleLoanForm = (OleLoanForm)form;
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928 oleLoanForm.setReturnInformation("");
929 oleLoanForm.setCheckInItem("");
930 oleLoanForm.setReturnMessage(null);
931 oleLoanForm.setReturnSuccess(true);
932 oleLoanForm.setItemReturnList(null);
933 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
934 }
935
936
937
938
939
940
941
942
943 @RequestMapping(params = "methodToCall=accept")
944 public ModelAndView acceptPayment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
945 HttpServletRequest request, HttpServletResponse response) {
946 if(LOG.isDebugEnabled()){
947 LOG.info(" Inside Accept payment ");
948 }
949 OleLoanForm oleLoanForm = (OleLoanForm)form;
950 List<PatronBill> patronBillList = oleLoanForm.getPatronBillList();
951 Iterator itr = patronBillList.iterator();
952 PatronBill patronBill;
953 String billNumber="";
954 String id="";
955 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
956 BigDecimal unPaidAmount = OLEConstants.BIGDECIMAL_DEF_VALUE;
957 BigDecimal feeAmount = OLEConstants.BIGDECIMAL_DEF_VALUE;
958 BigDecimal totalAmount = OLEConstants.BIGDECIMAL_DEF_VALUE;
959 while(itr.hasNext()) {
960 patronBill = (PatronBill)itr.next();
961 boolean isActive = patronBill.isActive();
962 if(isActive){
963 BigDecimal paidAmount = oleLoanForm.getPaymentAmount() != null ? oleLoanForm.getPaymentAmount() : new BigDecimal(0.0);
964 id= patronBill.getId();
965 billNumber = patronBill.getBillNumber();
966 feeAmount = patronBill.getFeeAmount().subtract(paidAmount);
967 unPaidAmount = patronBill.getTotalAmount().subtract(paidAmount);
968 totalAmount = patronBill.getTotalAmount().subtract(paidAmount);
969 patronBillHelperService.updatePatronFeeAmount(id,feeAmount);
970 String paymentStatus = oleLoanForm.getPaymentStatus().equals("")? patronBill.getPaymentStatus() : oleLoanForm.getPaymentStatus();
971 String paymentMethod = oleLoanForm.getPaymentMethod().equals("") ? patronBill.getPaymentMethod() : oleLoanForm.getPaymentMethod();
972 patronBillHelperService.updatePatronBillForAccept(billNumber,paidAmount,unPaidAmount,totalAmount,paymentStatus,paymentMethod);
973 }
974 }
975 oleLoanForm.setPatronBillList(patronBillHelperService.getService(oleLoanForm.getPatronId()));
976 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
977 }
978
979
980
981
982
983
984
985
986
987 @RequestMapping(params = "methodToCall=forgive")
988 public ModelAndView forgivePayment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
989 HttpServletRequest request, HttpServletResponse response) {
990 if(LOG.isDebugEnabled()){
991 LOG.info(" Inside Forgive Payment ");
992 }
993 OleLoanForm oleLoanForm = (OleLoanForm)form;
994 List<PatronBill> patronBillList = oleLoanForm.getPatronBillList();
995 Iterator itr = patronBillList.iterator();
996 PatronBill patronBill;
997 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
998 String billNumber="";
999 String id="";
1000 BigDecimal totalAmount = OLEConstants.BIGDECIMAL_DEF_VALUE;
1001 BigDecimal unPaidAmount = OLEConstants.BIGDECIMAL_DEF_VALUE;
1002 BigDecimal feeAmount = OLEConstants.BIGDECIMAL_DEF_VALUE;
1003 while(itr.hasNext()) {
1004 patronBill = (PatronBill)itr.next();
1005 boolean isDelete = patronBill.isActive();
1006 if(isDelete){
1007 BigDecimal paidAmount = oleLoanForm.getPaymentAmount() != null ? oleLoanForm.getPaymentAmount() : patronBill.getPaymentAmount();
1008 billNumber = patronBill.getBillNumber();
1009 id = patronBill.getId();
1010 unPaidAmount = patronBill.getTotalAmount().subtract(paidAmount);
1011 totalAmount = patronBill.getTotalAmount().subtract(paidAmount);
1012 feeAmount = patronBill.getFeeAmount().subtract(paidAmount);
1013 patronBillHelperService.updatePatronFeeAmount(id,feeAmount);
1014 String paymentStatus = oleLoanForm.getPaymentStatus().equals("")? patronBill.getPaymentStatus() : oleLoanForm.getPaymentStatus();
1015 patronBillHelperService.updatePatronBillForForgive(billNumber,unPaidAmount,totalAmount,paymentStatus);
1016 }
1017 }
1018 oleLoanForm.setPatronBillList(patronBillHelperService.getService(oleLoanForm.getPatronId()));
1019 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1020 }
1021
1022
1023
1024
1025
1026
1027
1028
1029 @RequestMapping(params = "methodToCall=closeBill")
1030 public ModelAndView closeBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1031 HttpServletRequest request, HttpServletResponse response) {
1032 if(LOG.isDebugEnabled()){
1033 LOG.info(" Inside Close Bill ");
1034 }
1035 OleLoanForm oleLoanForm = (OleLoanForm)form;
1036 oleLoanForm.setBillAvailability(false);
1037 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1038 }
1039
1040 }