1 package org.kuali.ole.deliver.bo;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.processor.LoanProcessor;
6 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
7 import org.kuali.ole.docstore.common.document.Bib;
8 import org.kuali.ole.docstore.common.document.ItemOleml;
9 import org.kuali.ole.docstore.common.document.content.instance.Item;
10 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
11 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
12 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
13 import org.kuali.ole.docstore.common.search.SearchResponse;
14 import org.kuali.ole.docstore.common.search.SearchResult;
15 import org.kuali.ole.docstore.common.search.SearchResultField;
16
17 import org.kuali.ole.service.impl.OlePatronBillMaintenanceDocumentServiceImpl;
18 import org.kuali.ole.sys.context.SpringContext;
19 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20 import org.kuali.rice.core.api.util.type.KualiDecimal;
21 import org.kuali.rice.krad.bo.PersistableAttachment;
22 import org.kuali.rice.krad.bo.PersistableBusinessObject;
23 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
24 import org.kuali.rice.krad.maintenance.MaintenanceUtils;
25 import org.kuali.rice.krad.service.BusinessObjectService;
26 import org.kuali.rice.krad.service.DataObjectAuthorizationService;
27 import org.kuali.rice.krad.service.KRADServiceLocator;
28 import org.kuali.rice.krad.service.MaintenanceDocumentService;
29 import org.kuali.rice.krad.uif.UifParameters;
30 import org.kuali.rice.krad.uif.container.CollectionGroup;
31 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
32 import org.kuali.rice.krad.uif.view.View;
33 import org.kuali.rice.krad.util.GlobalVariables;
34 import org.kuali.rice.krad.util.KRADConstants;
35 import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
36 import org.kuali.rice.krad.web.form.DocumentFormBase;
37 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
38 import org.kuali.rice.krad.web.form.UifFormBase;
39 import org.springframework.stereotype.Controller;
40 import org.springframework.validation.BindingResult;
41 import org.springframework.web.bind.annotation.ModelAttribute;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RequestMethod;
44 import org.springframework.web.servlet.ModelAndView;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48 import java.math.BigDecimal;
49 import java.util.*;
50
51
52
53
54
55
56
57
58 @Controller
59 @RequestMapping(value = "/patronBillMaintenance")
60 public class PatronBillMaintenanceDocumentController extends MaintenanceDocumentController {
61
62 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(org.kuali.ole.deliver.bo.PatronBillMaintenanceDocumentController.class);
63 private BusinessObjectService businessObjectService;
64 private DocstoreClientLocator docstoreClientLocator;
65
66 public DocstoreClientLocator getDocstoreClientLocator() {
67
68 if (docstoreClientLocator == null) {
69 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
70
71 }
72 return docstoreClientLocator;
73 }
74
75
76
77
78
79
80 public BusinessObjectService getBusinessObjectService() {
81 if (null == businessObjectService) {
82 businessObjectService = KRADServiceLocator.getBusinessObjectService();
83 }
84 return businessObjectService;
85 }
86
87
88
89
90
91 @RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_NEW)
92 @Override
93 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
94 HttpServletRequest request, HttpServletResponse response) {
95 Date billDate = new Date();
96 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
97 setupMaintenance(maintenanceForm, request, KRADConstants.MAINTENANCE_NEW_ACTION);
98 MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
99 if (document.getDocumentHeader() != null) {
100 document.getDocumentHeader().setDocumentDescription("New Patron Bill");
101 }
102 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getDocumentDataObject();
103 Map patronMap = new HashMap();
104 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, request.getParameter(OLEConstants.PTRN_ID));
105 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
106 if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
107 patronBillPayment.setOlePatron(olePatronDocumentList.get(0));
108 }
109 patronBillPayment.setPatronId(request.getParameter(OLEConstants.PTRN_ID));
110 patronBillPayment.setFirstName(request.getParameter(OLEConstants.PTRN_FN));
111 patronBillPayment.setLastName(request.getParameter(OLEConstants.PTRN_LN));
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 patronBillPayment.setBillDate(new java.sql.Date(billDate.getTime()));
131 return getUIFModelAndView(maintenanceForm);
132 }
133
134
135
136
137
138
139
140 @Override
141 protected MaintenanceDocumentService getMaintenanceDocumentService() {
142 return GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PTRN_BILL_MAIN_DOC_SER);
143 }
144
145
146
147
148
149
150
151
152
153 @RequestMapping(params = "methodToCall=addToTotalAmount")
154 public ModelAndView addToTotalAmount(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
155 HttpServletRequest request, HttpServletResponse response) throws Exception {
156 LOG.debug("Initialized addToTotalAmount method");
157 ModelAndView modelAndView = super.addLine(uifForm, result, request, response);
158 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
159 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
160 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
161 BigDecimal amount = new BigDecimal(0.0);
162 if (patronBillPayment.getFeeType() != null) {
163 List<FeeType> feeTypes = patronBillPayment.getFeeType();
164 for (int i = 0; i < feeTypes.size(); i++) {
165 amount = amount.add(feeTypes.get(i).getFeeAmount().bigDecimalValue());
166 }
167 patronBillPayment.setTotalAmount(new KualiDecimal(amount));
168
169 }
170 return modelAndView;
171 }
172
173
174
175
176
177
178
179
180 @RequestMapping(params = "methodToCall=addFeeType")
181 public ModelAndView addFeeType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
182 HttpServletRequest request, HttpServletResponse response) {
183 LOG.debug("Initialized addFeeType method");
184 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
185 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
186 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
187 patronBillPayment.setZeroFeeAmount(false);
188 patronBillPayment.setRequiredFeeAmount(false);
189 LoanProcessor loanProcessor = new LoanProcessor();
190 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
191 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
192 selectedCollectionPath);
193 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
194 Object eventObject = ObjectPropertyUtils.getPropertyValue(form, addLinePath);
195 FeeType feeType = (FeeType) eventObject;
196 if(form.getMaintenanceAction().equalsIgnoreCase("New")){
197 Map<String,String> map=new HashMap<String,String>();
198 map.put("paymentStatusCode","PAY_OUTSTN");
199 OlePaymentStatus olePaymentStatus=(OlePaymentStatus)KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePaymentStatus.class,map);
200 if(olePaymentStatus!=null){
201 feeType.setOlePaymentStatus(olePaymentStatus);
202 feeType.setPaymentStatus(olePaymentStatus.getPaymentStatusId());
203 }
204 }
205 String itemBarcode = feeType.getItemBarcode();
206 String itemUUID = feeType.getItemUuid();
207 String itemType = feeType.getItemType();
208 String itemTitle = feeType.getItemTitle();
209 String feeAmount = feeType.getFeeAmount() != null ? feeType.getFeeAmount().toString() : "";
210 if (feeAmount.isEmpty()) {
211 patronBillPayment.setRequiredFeeAmount(true);
212 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_PATRON_BILL_FEE_TYPE_SECTION_ID, OLEConstants.FEE_AMOUNT_REQUIRED, "FeeAmount Field");
213 return getUIFModelAndView(form);
214 }
215 if(feeType.getFeeAmount()!=null && feeType.getFeeAmount().bigDecimalValue().compareTo(OLEConstants.BIGDECIMAL_DEF_VALUE)<=0){
216 patronBillPayment.setZeroFeeAmount(true);
217 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_PATRON_BILL_FEE_TYPE_SECTION_ID, OLEConstants.FEE_AMOUNT_ZERO_NOT_ALLOWED);
218 return getUIFModelAndView(form);
219 }
220 feeType.setBalFeeAmount(feeType.getFeeAmount());
221 String operatorId = GlobalVariables.getUserSession().getPrincipalId();
222 feeType.setFeeSource(operatorId);
223 if(feeType.getFeeTypes()!=null){
224 feeType.getFeeTypes().add(feeType);
225 }
226 View view = form.getPostedView();
227 patronBillPayment.setErrorMessage(null);
228
229 if ((itemBarcode != null && !itemBarcode.isEmpty()) && (itemUUID == null || itemUUID.isEmpty())) {
230
231 try {
232
233 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
234 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
235 SearchResponse searchResponse = null;
236 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("phrase", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, itemBarcode), ""));
237
238
239 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
240 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "title"));
241 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "author"));
242 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "itemType"));
243
244 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "Enumeration"));
245 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "Chronology"));
246 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "copyNumber"));
247 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "callNumber"));
248
249
250
251 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
252
253
254 for (SearchResult searchResult : searchResponse.getSearchResults()) {
255 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
256 String fieldName = searchResultField.getFieldName();
257 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
258
259 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
260
261
262 feeType.setItemUuid(fieldValue);
263
264
265 } else if (fieldName.equalsIgnoreCase("title") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
266 feeType.setItemTitle(fieldValue);
267 } else if (fieldName.equalsIgnoreCase("author") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
268 feeType.setItemAuthor(fieldValue);
269 } else if (fieldName.equalsIgnoreCase("itemChronology") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
270 feeType.setItemChronologyOwnLocation(fieldValue);
271 } else if (fieldName.equalsIgnoreCase("itemEnumration") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
272 feeType.setItemEnumeration(fieldValue);
273 } else if (fieldName.equalsIgnoreCase("callnumber") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
274 feeType.setItemCallNumber(fieldValue);
275 } else if (StringUtils.isEmpty(feeType.getItemCallNumber()) && fieldName.equalsIgnoreCase("callnumber") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
276 feeType.setItemCallNumber(fieldValue);
277 } else if (fieldName.equalsIgnoreCase("copynumber") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
278 feeType.setItemCopyNumber(fieldValue);
279 } else if (fieldName.equalsIgnoreCase("TemporaryItemTypeCodeValue_search") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
280 feeType.setItemType(fieldValue);
281 } else if (StringUtils.isEmpty(feeType.getItemType()) && fieldName.equalsIgnoreCase("itemType") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
282 feeType.setItemType(fieldValue);
283 }
284
285 }
286 }
287
288
289 } catch (Exception ex) {
290 LOG.error("Exception while adding fee type", ex);
291 patronBillPayment.setErrorMessage(OLEConstants.OlePatron.INV_ITEM_BAR);
292 return getUIFModelAndView(form);
293 }
294 }
295
296 patronBillPayment.setErrorMessage(null);
297 view.getViewHelperService().processCollectionAddLine(view, form, selectedCollectionPath);
298 return getUIFModelAndView(form);
299 }
300
301 @Override
302 @RequestMapping(params = "methodToCall=maintenanceEdit")
303 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
304 HttpServletRequest request, HttpServletResponse response) throws Exception {
305
306 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
307 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
308
309 MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
310 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getOldMaintainableObject().getDataObject();
311 List<FeeType> feeTypes=patronBillPayment.getFeeType();
312 for(FeeType feeType:feeTypes){
313 if (feeType.getItemUuid() != null) {
314 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(feeType.getItemUuid());
315 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
316 Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
317 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(item.getHolding().getContent());
318 if (feeType.getItemUuid().equals(item.getId())) {
319 feeType.setItemTitle(item.getHolding().getBib().getTitle());
320 feeType.setItemAuthor(item.getHolding().getBib().getAuthor());
321
322
323
324
325
326 feeType.setItemCallNumber((new LoanProcessor()).getItemCallNumber(itemContent.getCallNumber(),oleHoldings.getCallNumber()));
327 feeType.setItemCopyNumber(itemContent.getCopyNumber());
328 feeType.setItemChronologyOwnLocation(itemContent.getChronology());
329 feeType.setItemEnumeration(itemContent.getEnumeration());
330 if(itemContent.getTemporaryItemType()!=null && itemContent.getTemporaryItemType().getCodeValue()!=null){
331 feeType.setItemType(itemContent.getTemporaryItemType().getCodeValue());
332 }else{
333 feeType.setItemType(itemContent.getItemType().getCodeValue());
334 }
335 }
336 }
337 if(feeType.getFeeTypes()!=null){
338 feeType.getFeeTypes().add(feeType);
339 }
340
341 }
342 patronBillPayment.setFeeType(feeTypes);
343 return super.maintenanceEdit(form, result, request, response);
344 }
345
346 @Override
347 @RequestMapping(params = "methodToCall=maintenanceCopy")
348 public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
349 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
350 setupMaintenance(form, request, KRADConstants.MAINTENANCE_COPY_ACTION);
351 super.maintenanceCopy(form,result,request, response);
352 MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
353 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getOldMaintainableObject().getDataObject();
354 PatronBillPayment newpatronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
355 List<FeeType> feeTypes=patronBillPayment.getFeeType();
356 for(FeeType feeType:feeTypes){
357 if (feeType.getItemUuid() != null) {
358 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(feeType.getItemUuid());
359 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
360 Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
361 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(item.getHolding().getContent());
362 if (feeType.getItemUuid().equals(item.getId())) {
363 feeType.setItemTitle(item.getHolding().getBib().getTitle());
364 feeType.setItemAuthor(item.getHolding().getBib().getAuthor());
365
366
367
368
369
370 feeType.setItemCallNumber((new LoanProcessor()).getItemCallNumber(itemContent.getCallNumber(),oleHoldings.getCallNumber()));
371 feeType.setItemCopyNumber(itemContent.getCopyNumber());
372 feeType.setItemChronologyOwnLocation(itemContent.getChronology());
373 feeType.setItemEnumeration(itemContent.getEnumeration());
374 if(itemContent.getTemporaryItemType()!=null && itemContent.getTemporaryItemType().getCodeValue()!=null){
375 feeType.setItemType(itemContent.getTemporaryItemType().getCodeValue());
376 }else{
377 feeType.setItemType(itemContent.getItemType().getCodeValue());
378 }
379 }
380 }
381 if(feeType.getFeeTypes()!=null){
382 feeType.getFeeTypes().add(feeType);
383 }
384 }
385 newpatronBillPayment.setFeeType(feeTypes);
386 newpatronBillPayment.setBillNumber(null);
387 return getUIFModelAndView(form);
388 }
389
390
391
392
393
394
395
396
397
398
399
400 @RequestMapping(params = "methodToCall=deleteFromTotalAmount")
401 public ModelAndView deleteFromTotalAmount(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
402 HttpServletRequest request, HttpServletResponse response) {
403
404 ModelAndView modelAndView = super.deleteLine(uifForm, result, request, response);
405 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
406 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
407 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
408 BigDecimal amount = new BigDecimal(0.0);
409 String billNumber = "";
410 Map feeTypeId = new HashMap();
411 if (patronBillPayment.getFeeType() != null) {
412 List<FeeType> feeTypes = patronBillPayment.getFeeType();
413 for (int i = 0; i < feeTypes.size(); i++) {
414 amount = amount.add(feeTypes.get(i).getFeeAmount().bigDecimalValue());
415 billNumber = feeTypes.get(i).getBillNumber();
416 feeTypeId.put(OLEConstants.OlePatron.BILL_PAYMENT_ID, billNumber);
417 }
418 patronBillPayment.setTotalAmount(new KualiDecimal(amount));
419
420
421 }
422 return modelAndView;
423 }
424
425
426
427
428
429
430 @RequestMapping(params = "methodToCall=calculateTotal")
431 public ModelAndView calculateTotal(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
432 HttpServletRequest request, HttpServletResponse response) throws Exception {
433
434 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
435 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
436 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
437 BigDecimal amount = new BigDecimal(0.0);
438 BigDecimal balAmount = new BigDecimal(0.0);
439 if (patronBillPayment.getFeeType() != null) {
440 List<FeeType> feeTypes = patronBillPayment.getFeeType();
441 for (FeeType feeType : feeTypes) {
442 amount = amount.add(feeType.getFeeAmount().bigDecimalValue());
443 balAmount = balAmount.add(feeType.getBalFeeAmount().bigDecimalValue());
444 }
445 patronBillPayment.setTotalAmount(new KualiDecimal(amount));
446 patronBillPayment.setUnPaidBalance(new KualiDecimal(balAmount));
447 }
448 if (patronBillPayment.isRequiredFeeAmount()) {
449 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_PATRON_BILL_FEE_TYPE_SECTION_ID, OLEConstants.FEE_AMOUNT_REQUIRED, "FeeAmount Field");
450 return getUIFModelAndView(form);
451 }
452 if(patronBillPayment.isZeroFeeAmount()){
453 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_PATRON_BILL_FEE_TYPE_SECTION_ID, OLEConstants.FEE_AMOUNT_ZERO_NOT_ALLOWED);
454 return getUIFModelAndView(form);
455 }
456 patronBillPayment.setZeroFeeAmount(false);
457 patronBillPayment.setRequiredFeeAmount(false);
458 return getUIFModelAndView(form);
459 }
460
461
462 @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
463 public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
464 HttpServletRequest request, HttpServletResponse response) throws Exception {
465 setupMaintenanceForDelete(form, request, OLEConstants.OlePatron.OLE_PATRON_BILL_DELETE);
466 return getUIFModelAndView(form);
467 }
468
469
470 @RequestMapping(params = "methodToCall=" + "deleteDocument")
471 public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
472 HttpServletRequest request, HttpServletResponse response) throws Exception {
473 MaintenanceDocument document = form.getDocument();
474 PatronBillPayment patronBillPayment = new PatronBillPayment();
475
476
477 if (document.getDocumentDataObject() != null) {
478 patronBillPayment = (PatronBillPayment) document.getDocumentDataObject();
479 if (patronBillPayment != null && patronBillPayment.getPatronId() != null) {
480 KRADServiceLocator.getBusinessObjectService().delete(patronBillPayment);
481 GlobalVariables.getMessageMap().putInfoWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS,
482 OLEConstants.OleLicenseRequest.MSG_DELETE_DOC);
483 } else {
484 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OleLicenseRequest.ERROR_CHECKLIST_NOT_FOUND);
485 return getUIFModelAndView(form);
486 }
487 }
488 return back(form, result, request, response);
489 }
490
491
492
493
494
495
496
497
498
499 protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request, String maintenanceAction) {
500 MaintenanceDocument document = form.getDocument();
501 if (document == null) {
502 document = getMaintenanceDocumentService()
503 .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
504 maintenanceAction);
505
506 form.setDocument(document);
507 form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
508 }
509
510
511 form.setMaintenanceAction(maintenanceAction);
512 OlePatronBillMaintenanceDocumentServiceImpl olePatronBillMaintenanceDocumentService = (OlePatronBillMaintenanceDocumentServiceImpl) getMaintenanceDocumentService();
513 olePatronBillMaintenanceDocumentService.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
514 MaintenanceUtils.checkForLockingDocument(document, false);
515 }
516
517
518
519
520
521
522 @Override
523 @RequestMapping(params = "methodToCall=route")
524 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
525 HttpServletRequest request, HttpServletResponse response) {
526 ModelAndView modelAndView;
527 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
528
529 try {
530 calculateTotal(form, result, request, response);
531 } catch (Exception e) {
532 LOG.error("Exception while calculating total", e);
533 }
534 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
535 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
536
537 if (patronBillPayment.getFeeType() != null) {
538 List<FeeType> feeTypes = patronBillPayment.getFeeType();
539 if (feeTypes.size() == 0) {
540 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ADD_FEE_TYPE);
541 return getUIFModelAndView(maintenanceForm);
542 }
543 }
544 if (document.getNewMaintainableObject().getDataObject() instanceof PersistableAttachment) {
545 PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService()
546 .retrieve((PersistableBusinessObject) document.getNewMaintainableObject().getDataObject());
547 request.setAttribute(OLEConstants.OlePatron.FILE_NAME, bo.getFileName());
548 }
549
550 if (LOG.isDebugEnabled()){
551 LOG.debug("****************************** Patron Id" + patronBillPayment.getBillNumber());
552 }
553 if (patronBillPayment.getBillNumber() != null) {
554 Map<String, String> map = new HashMap<String, String>();
555 map.put("billNumber", patronBillPayment.getBillNumber());
556 List<PatronBillPayment> patronBillPaymentdblist = (List<PatronBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(PatronBillPayment.class, map);
557 if (patronBillPaymentdblist.size() > 0) {
558 PatronBillPayment patronBillPaymentdb = patronBillPaymentdblist.get(0);
559 List<FeeType> feeTypesdb = patronBillPaymentdb.getFeeType();
560 for (FeeType feeTypedb : feeTypesdb) {
561 boolean isFound = false;
562 List<FeeType> feeTypesuser = patronBillPayment.getFeeType();
563 for (FeeType userfeeType : feeTypesuser) {
564 if (feeTypedb.getId().equals(userfeeType.getId())) {
565 isFound = true;
566 }
567 }
568 if (!isFound) {
569 Map<String, String> deleteItemHistoryMap = new HashMap<String, String>();
570 deleteItemHistoryMap.put("lineItemId", feeTypedb.getId());
571 List<OleItemLevelBillPayment> oleItemLevelBillPaymentsDB = (List<OleItemLevelBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(OleItemLevelBillPayment.class, deleteItemHistoryMap);
572 if (oleItemLevelBillPaymentsDB.size() > 0) {
573 KRADServiceLocator.getBusinessObjectService().deleteMatching(OleItemLevelBillPayment.class, deleteItemHistoryMap);
574 }
575 Map<String, String> deleteFeeTypeMap = new HashMap<String, String>();
576 deleteFeeTypeMap.put("id", feeTypedb.getId());
577 KRADServiceLocator.getBusinessObjectService().deleteMatching(FeeType.class, deleteFeeTypeMap);
578 }
579 }
580 }
581 }
582 patronBillPayment.setErrorMessage(null);
583 modelAndView = super.route(maintenanceForm, result, request, response);
584 return modelAndView;
585 }
586 }