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 if(itemContent.getCallNumber()!=null && !StringUtils.isEmpty(itemContent.getCallNumber().getNumber())){
322 feeType.setItemCallNumber(itemContent.getCallNumber().getNumber());
323 }else {
324 feeType.setItemCallNumber((new LoanProcessor()).getItemCallNumber(oleHoldings.getCallNumber()));
325 }
326 feeType.setItemCopyNumber(itemContent.getCopyNumber());
327 feeType.setItemChronologyOwnLocation(itemContent.getChronology());
328 feeType.setItemEnumeration(itemContent.getEnumeration());
329 if(itemContent.getTemporaryItemType()!=null && itemContent.getTemporaryItemType().getCodeValue()!=null){
330 feeType.setItemType(itemContent.getTemporaryItemType().getCodeValue());
331 }else{
332 feeType.setItemType(itemContent.getItemType().getCodeValue());
333 }
334 }
335 }
336 if(feeType.getFeeTypes()!=null){
337 feeType.getFeeTypes().add(feeType);
338 }
339
340 }
341 patronBillPayment.setFeeType(feeTypes);
342 return super.maintenanceEdit(form, result, request, response);
343 }
344
345 @Override
346 @RequestMapping(params = "methodToCall=maintenanceCopy")
347 public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
348 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
349 setupMaintenance(form, request, KRADConstants.MAINTENANCE_COPY_ACTION);
350 super.maintenanceCopy(form,result,request, response);
351 MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
352 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getOldMaintainableObject().getDataObject();
353 PatronBillPayment newpatronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
354 List<FeeType> feeTypes=patronBillPayment.getFeeType();
355 for(FeeType feeType:feeTypes){
356 if (feeType.getItemUuid() != null) {
357 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(feeType.getItemUuid());
358 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
359 Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
360 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(item.getHolding().getContent());
361 if (feeType.getItemUuid().equals(item.getId())) {
362 feeType.setItemTitle(item.getHolding().getBib().getTitle());
363 feeType.setItemAuthor(item.getHolding().getBib().getAuthor());
364 if(itemContent.getCallNumber()!=null && !StringUtils.isEmpty(itemContent.getCallNumber().getNumber())){
365 feeType.setItemCallNumber(itemContent.getCallNumber().getNumber());
366 }else {
367 feeType.setItemCallNumber((new LoanProcessor()).getItemCallNumber(oleHoldings.getCallNumber()));
368 }
369 feeType.setItemCopyNumber(itemContent.getCopyNumber());
370 feeType.setItemChronologyOwnLocation(itemContent.getChronology());
371 feeType.setItemEnumeration(itemContent.getEnumeration());
372 if(itemContent.getTemporaryItemType()!=null && itemContent.getTemporaryItemType().getCodeValue()!=null){
373 feeType.setItemType(itemContent.getTemporaryItemType().getCodeValue());
374 }else{
375 feeType.setItemType(itemContent.getItemType().getCodeValue());
376 }
377 }
378 }
379 if(feeType.getFeeTypes()!=null){
380 feeType.getFeeTypes().add(feeType);
381 }
382 }
383 newpatronBillPayment.setFeeType(feeTypes);
384 newpatronBillPayment.setBillNumber(null);
385 return getUIFModelAndView(form);
386 }
387
388
389
390
391
392
393
394
395
396
397
398 @RequestMapping(params = "methodToCall=deleteFromTotalAmount")
399 public ModelAndView deleteFromTotalAmount(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
400 HttpServletRequest request, HttpServletResponse response) {
401
402 ModelAndView modelAndView = super.deleteLine(uifForm, result, request, response);
403 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
404 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
405 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
406 BigDecimal amount = new BigDecimal(0.0);
407 String billNumber = "";
408 Map feeTypeId = new HashMap();
409 if (patronBillPayment.getFeeType() != null) {
410 List<FeeType> feeTypes = patronBillPayment.getFeeType();
411 for (int i = 0; i < feeTypes.size(); i++) {
412 amount = amount.add(feeTypes.get(i).getFeeAmount().bigDecimalValue());
413 billNumber = feeTypes.get(i).getBillNumber();
414 feeTypeId.put(OLEConstants.OlePatron.BILL_PAYMENT_ID, billNumber);
415 }
416 patronBillPayment.setTotalAmount(new KualiDecimal(amount));
417
418
419 }
420 return modelAndView;
421 }
422
423
424
425
426
427
428 @RequestMapping(params = "methodToCall=calculateTotal")
429 public ModelAndView calculateTotal(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
430 HttpServletRequest request, HttpServletResponse response) throws Exception {
431
432 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
433 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
434 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
435 BigDecimal amount = new BigDecimal(0.0);
436 BigDecimal balAmount = new BigDecimal(0.0);
437 if (patronBillPayment.getFeeType() != null) {
438 List<FeeType> feeTypes = patronBillPayment.getFeeType();
439 for (FeeType feeType : feeTypes) {
440 amount = amount.add(feeType.getFeeAmount().bigDecimalValue());
441 balAmount = balAmount.add(feeType.getBalFeeAmount().bigDecimalValue());
442 }
443 patronBillPayment.setTotalAmount(new KualiDecimal(amount));
444 patronBillPayment.setUnPaidBalance(new KualiDecimal(balAmount));
445 }
446 if (patronBillPayment.isRequiredFeeAmount()) {
447 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_PATRON_BILL_FEE_TYPE_SECTION_ID, OLEConstants.FEE_AMOUNT_REQUIRED, "FeeAmount Field");
448 return getUIFModelAndView(form);
449 }
450 if(patronBillPayment.isZeroFeeAmount()){
451 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_PATRON_BILL_FEE_TYPE_SECTION_ID, OLEConstants.FEE_AMOUNT_ZERO_NOT_ALLOWED);
452 return getUIFModelAndView(form);
453 }
454 patronBillPayment.setZeroFeeAmount(false);
455 patronBillPayment.setRequiredFeeAmount(false);
456 return getUIFModelAndView(form);
457 }
458
459
460 @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
461 public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
462 HttpServletRequest request, HttpServletResponse response) throws Exception {
463 setupMaintenanceForDelete(form, request, OLEConstants.OlePatron.OLE_PATRON_BILL_DELETE);
464 return getUIFModelAndView(form);
465 }
466
467
468 @RequestMapping(params = "methodToCall=" + "deleteDocument")
469 public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
470 HttpServletRequest request, HttpServletResponse response) throws Exception {
471 MaintenanceDocument document = form.getDocument();
472 PatronBillPayment patronBillPayment = new PatronBillPayment();
473
474
475 if (document.getDocumentDataObject() != null) {
476 patronBillPayment = (PatronBillPayment) document.getDocumentDataObject();
477 if (patronBillPayment != null && patronBillPayment.getPatronId() != null) {
478 KRADServiceLocator.getBusinessObjectService().delete(patronBillPayment);
479 GlobalVariables.getMessageMap().putInfoWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS,
480 OLEConstants.OleLicenseRequest.MSG_DELETE_DOC);
481 } else {
482 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OleLicenseRequest.ERROR_CHECKLIST_NOT_FOUND);
483 return getUIFModelAndView(form);
484 }
485 }
486 return back(form, result, request, response);
487 }
488
489
490
491
492
493
494
495
496
497 protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request, String maintenanceAction) {
498 MaintenanceDocument document = form.getDocument();
499 if (document == null) {
500 document = getMaintenanceDocumentService()
501 .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
502 maintenanceAction);
503
504 form.setDocument(document);
505 form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
506 }
507
508
509 form.setMaintenanceAction(maintenanceAction);
510 OlePatronBillMaintenanceDocumentServiceImpl olePatronBillMaintenanceDocumentService = (OlePatronBillMaintenanceDocumentServiceImpl) getMaintenanceDocumentService();
511 olePatronBillMaintenanceDocumentService.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
512 MaintenanceUtils.checkForLockingDocument(document, false);
513 }
514
515
516
517
518
519
520 @Override
521 @RequestMapping(params = "methodToCall=route")
522 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
523 HttpServletRequest request, HttpServletResponse response) {
524 ModelAndView modelAndView;
525 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
526
527 try {
528 calculateTotal(form, result, request, response);
529 } catch (Exception e) {
530 LOG.error("Exception while calculating total", e);
531 }
532 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
533 PatronBillPayment patronBillPayment = (PatronBillPayment) document.getNewMaintainableObject().getDataObject();
534
535 if (patronBillPayment.getFeeType() != null) {
536 List<FeeType> feeTypes = patronBillPayment.getFeeType();
537 if (feeTypes.size() == 0) {
538 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ADD_FEE_TYPE);
539 return getUIFModelAndView(maintenanceForm);
540 }
541 }
542 if (document.getNewMaintainableObject().getDataObject() instanceof PersistableAttachment) {
543 PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService()
544 .retrieve((PersistableBusinessObject) document.getNewMaintainableObject().getDataObject());
545 request.setAttribute(OLEConstants.OlePatron.FILE_NAME, bo.getFileName());
546 }
547
548 if (LOG.isDebugEnabled()){
549 LOG.debug("****************************** Patron Id" + patronBillPayment.getBillNumber());
550 }
551 if (patronBillPayment.getBillNumber() != null) {
552 Map<String, String> map = new HashMap<String, String>();
553 map.put("billNumber", patronBillPayment.getBillNumber());
554 List<PatronBillPayment> patronBillPaymentdblist = (List<PatronBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(PatronBillPayment.class, map);
555 if (patronBillPaymentdblist.size() > 0) {
556 PatronBillPayment patronBillPaymentdb = patronBillPaymentdblist.get(0);
557 List<FeeType> feeTypesdb = patronBillPaymentdb.getFeeType();
558 for (FeeType feeTypedb : feeTypesdb) {
559 boolean isFound = false;
560 List<FeeType> feeTypesuser = patronBillPayment.getFeeType();
561 for (FeeType userfeeType : feeTypesuser) {
562 if (feeTypedb.getId().equals(userfeeType.getId())) {
563 isFound = true;
564 }
565 }
566 if (!isFound) {
567 Map<String, String> deleteItemHistoryMap = new HashMap<String, String>();
568 deleteItemHistoryMap.put("lineItemId", feeTypedb.getId());
569 List<OleItemLevelBillPayment> oleItemLevelBillPaymentsDB = (List<OleItemLevelBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(OleItemLevelBillPayment.class, deleteItemHistoryMap);
570 if (oleItemLevelBillPaymentsDB.size() > 0) {
571 KRADServiceLocator.getBusinessObjectService().deleteMatching(OleItemLevelBillPayment.class, deleteItemHistoryMap);
572 }
573 Map<String, String> deleteFeeTypeMap = new HashMap<String, String>();
574 deleteFeeTypeMap.put("id", feeTypedb.getId());
575 KRADServiceLocator.getBusinessObjectService().deleteMatching(FeeType.class, deleteFeeTypeMap);
576 }
577 }
578 }
579 }
580 patronBillPayment.setErrorMessage(null);
581 modelAndView = super.route(maintenanceForm, result, request, response);
582 return modelAndView;
583 }
584 }