1 package org.kuali.ole.deliver.controller;
2
3 import com.lowagie.text.Chunk;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.OLEParameterConstants;
7 import org.kuali.ole.deliver.batch.OleMailer;
8 import org.kuali.ole.deliver.bo.*;
9 import org.kuali.ole.deliver.form.PatronBillForm;
10 import org.kuali.ole.deliver.processor.LoanProcessor;
11 import org.kuali.rice.core.api.mail.EmailBody;
12 import org.kuali.rice.core.api.mail.EmailFrom;
13 import org.kuali.rice.core.api.mail.EmailSubject;
14 import org.kuali.rice.core.api.mail.EmailTo;
15 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
16 import org.kuali.rice.core.api.util.RiceConstants;
17 import org.kuali.rice.core.api.util.type.KualiDecimal;
18 import org.kuali.rice.core.web.format.CurrencyFormatter;
19 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
20 import org.kuali.rice.krad.service.BusinessObjectService;
21 import org.kuali.rice.krad.service.KRADServiceLocator;
22 import org.kuali.rice.krad.util.GlobalVariables;
23 import org.kuali.rice.krad.util.KRADConstants;
24 import org.kuali.rice.krad.web.controller.UifControllerBase;
25 import org.kuali.rice.krad.web.form.UifFormBase;
26 import org.springframework.stereotype.Controller;
27 import org.springframework.validation.BindingResult;
28 import org.springframework.web.bind.annotation.ModelAttribute;
29 import org.springframework.web.bind.annotation.RequestMapping;
30 import org.springframework.web.servlet.ModelAndView;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.text.SimpleDateFormat;
35 import java.util.*;
36
37
38
39
40
41
42
43
44
45 @Controller
46 @RequestMapping(value = "/patronbill")
47 public class PatronBillController extends UifControllerBase {
48
49 private static final Logger LOG = Logger.getLogger(PatronBillController.class);
50
51
52 private BusinessObjectService businessObjectService;
53
54
55
56
57
58
59 private BusinessObjectService getBusinessObjectService() {
60 if (null == businessObjectService) {
61 businessObjectService = KRADServiceLocator.getBusinessObjectService();
62 }
63 return businessObjectService;
64 }
65
66
67
68
69
70
71
72 @Override
73 protected PatronBillForm createInitialForm(HttpServletRequest request) {
74 return new PatronBillForm();
75 }
76
77
78
79
80
81
82
83
84
85
86
87 @Override
88 @RequestMapping(params = "methodToCall=start")
89 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
90 HttpServletRequest request, HttpServletResponse response) {
91 PatronBillForm patronBillForm = (PatronBillForm) form;
92 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
93 if (patronBillForm.getPatronId() == null && patronBillForm.getOlePatronId() == null) {
94 patronBillForm.setOlePatronDocument(patronBillHelperService.getPatronDetails(patronBillForm.getPatronId()));
95 }
96 if (patronBillForm.getPatronId() != null) {
97 patronBillForm.setOlePatronId(patronBillForm.getPatronId());
98 }
99 if (patronBillForm.getOlePatronId() != null) {
100 patronBillForm.setOlePatronDocument(patronBillHelperService.getPatronDetails(patronBillForm.getOlePatronId()));
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 if (patronBillForm.getPatronId() != null) {
117 patronBillForm.setOlePatronId(patronBillForm.getPatronId());
118 }
119
120 LoanProcessor loanProcessor = new LoanProcessor();
121 patronBillForm.setPatronUrl(loanProcessor.patronNameURL(GlobalVariables.getUserSession().getPrincipalId(), patronBillForm.getPatronId()));
122
123 Map patronIdMap = new HashMap();
124 patronIdMap.put("patronId", patronBillForm.getPatronId());
125 List<FeeType> feeTypes = new ArrayList<FeeType>();
126 List<PatronBillPayment> patronBillPayments = (List<PatronBillPayment>) getBusinessObjectService().findMatching(PatronBillPayment.class, patronIdMap);
127 patronBillForm.setPatronBillPaymentList(patronBillHelperService.sortById(patronBillPayments));
128
129
130
131 List<FeeType> feeTypeList = patronBillHelperService.getFeeTypeList(patronBillPayments);
132
133
134 patronBillForm.setFeeTypes(feeTypeList);
135
136 KualiDecimal KualiDecimal = patronBillHelperService.populateGrandTotal(patronBillForm.getPatronBillPaymentList());
137 patronBillForm.setGrandTotal(KualiDecimal);
138 patronBillForm.setPaymentAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
139 patronBillForm.setPaymentMethod("");
140 patronBillForm.setBillWisePayment(OLEConstants.OlePatron.DEFAULT);
141 patronBillForm.setTransactionNumber("");
142 patronBillForm.setTransactionNote("");
143
144 return super.start(patronBillForm, result, request, response);
145 }
146
147
148
149
150
151
152
153
154
155
156 @RequestMapping(params = "methodToCall=accept")
157 public ModelAndView acceptPayment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
158 HttpServletRequest request, HttpServletResponse response) {
159 LOG.debug("Initialized acceptPayment Method");
160 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
161 PatronBillForm patronBillForm = (PatronBillForm) form;
162 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
163 patronBillForm.setMessage("");
164
165 boolean valid = true;
166 if (patronBillForm.getPaymentAmount() == null) {
167 valid = false;
168 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.PAY_AMT_EMPTY);
169 } else {
170 int signum = patronBillForm.getPaymentAmount().bigDecimalValue().signum();
171 if (signum < 0) {
172 valid = false;
173 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.NEGATIVE_NUM);
174 }
175 }
176 if (patronBillForm.getPaymentMethod() == null || patronBillForm.getPaymentMethod().trim().isEmpty()) {
177 valid = false;
178 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.PAY_METHOD_REQUIRED);
179 }
180 if (!valid) {
181 return getUIFModelAndView(patronBillForm);
182 }
183 KualiDecimal paymentAmount = patronBillForm.getPaymentAmount();
184 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
185 List<PatronBillPayment> patronBillPayments = patronBillForm.getPatronBillPaymentList();
186 if (!patronBillHelperService.isSelectedPaidPatronBillFullyPaid(patronBillPayments)) {
187 List<String> billIds = patronBillHelperService.getBillIds();
188 Collections.sort(billIds);
189 String buffer = "";
190 for (String billId : billIds) {
191 buffer = buffer + billId + ",";
192 }
193 if (buffer.length() > 0) {
194 buffer = buffer.substring(0, buffer.length() - 1);
195 }
196 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
197 return getUIFModelAndView(form);
198 }
199 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedPatronBills(patronBillPayments)) > 0) {
200 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
201 return getUIFModelAndView(form);
202 }
203 paymentAmount = patronBillHelperService.billWiseTransaction(patronBillPayments, paymentAmount, patronBillForm.getPaymentMethod(), OLEConstants.FULL_PAID, OLEConstants.PAR_PAID, false, null, patronBillForm.getTransactionNumber(), patronBillForm.getTransactionNote(), patronBillForm.getPaidByUser(), patronBillForm.getCurrentSessionTransactions());
204 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
205 List<FeeType> feeTypes = patronBillForm.getFeeTypes();
206 if (!patronBillHelperService.isSelectedFeeTypeFullyPaid(feeTypes)) {
207 List<String> billIds = patronBillHelperService.getBillIds();
208 Collections.sort(billIds);
209 String buffer = "";
210 for (String billId : billIds) {
211 buffer = buffer + billId + ",";
212 }
213 if (buffer.length() > 0) {
214 buffer = buffer.substring(0, buffer.length() - 1);
215 }
216 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
217 return getUIFModelAndView(form);
218 }
219 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedFeeTypes(feeTypes)) > 0) {
220 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
221 return getUIFModelAndView(form);
222 }
223 paymentAmount = patronBillHelperService.itemWiseTransaction(feeTypes, paymentAmount, patronBillForm.getPaymentMethod(), OLEConstants.FULL_PAID, OLEConstants.PAR_PAID, null, patronBillForm.getTransactionNumber(), patronBillForm.getTransactionNote(), patronBillForm.getPaidByUser(), patronBillForm.getCurrentSessionTransactions());
224 } else {
225 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.SELECT);
226 return getUIFModelAndView(patronBillForm);
227 }
228 if (paymentAmount.compareTo(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE) > 0) {
229 patronBillForm.setMessage(OLEConstants.BAL_AMT + paymentAmount);
230 }
231
232 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
233 patronBillForm.setPaymentAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
234 patronBillForm.setTransactionNumber("");
235 patronBillForm.setTransactionNote("");
236 return start(patronBillForm, result, request, response);
237 }
238
239
240
241
242
243
244
245
246
247
248
249 @RequestMapping(params = "methodToCall=forgive")
250 public ModelAndView forgivePayment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
251 HttpServletRequest request, HttpServletResponse response) {
252 LOG.debug("Initialized forgivePayment Method");
253 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
254 PatronBillForm patronBillForm = (PatronBillForm) form;
255 patronBillForm.setMessage("");
256 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
257 boolean valid = true;
258 if (patronBillForm.getPaymentAmount() == null) {
259 valid = false;
260 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.PAY_AMT_EMPTY);
261 } else {
262 int signum = patronBillForm.getPaymentAmount().bigDecimalValue().signum();
263 if (signum < 0) {
264 valid = false;
265 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.NEGATIVE_NUM);
266 }
267 }
268
269
270
271
272 if (!valid) {
273 return getUIFModelAndView(patronBillForm);
274 }
275 KualiDecimal paymentAmount = patronBillForm.getPaymentAmount();
276 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
277 List<PatronBillPayment> patronBillPayments = patronBillForm.getPatronBillPaymentList();
278 if (!patronBillHelperService.isSelectedPaidPatronBillFullyPaid(patronBillPayments)) {
279 List<String> billIds = patronBillHelperService.getBillIds();
280 Collections.sort(billIds);
281 String buffer = "";
282 for (String billId : billIds) {
283 buffer = buffer + billId + ",";
284 }
285 if (buffer.length() > 0) {
286 buffer = buffer.substring(0, buffer.length() - 1);
287 }
288 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
289 return getUIFModelAndView(form);
290 }
291 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedPatronBills(patronBillPayments)) > 0) {
292 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
293 return getUIFModelAndView(form);
294 }
295 paymentAmount = patronBillHelperService.billWiseTransaction(patronBillPayments, paymentAmount, OLEConstants.FORGIVE, OLEConstants.FORGIVEN, OLEConstants.PAR_PAID, false, patronBillForm.getForgiveNote(), patronBillForm.getTransactionNumber(), patronBillForm.getTransactionNote(), patronBillForm.getPaidByUser(), patronBillForm.getCurrentSessionTransactions());
296 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
297 List<FeeType> feeTypes = patronBillForm.getFeeTypes();
298 if (!patronBillHelperService.isSelectedFeeTypeFullyPaid(feeTypes)) {
299 List<String> billIds = patronBillHelperService.getBillIds();
300 Collections.sort(billIds);
301 String buffer = "";
302 for (String billId : billIds) {
303 buffer = buffer + billId + ",";
304 }
305 if (buffer.length() > 0) {
306 buffer = buffer.substring(0, buffer.length() - 1);
307 }
308 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
309 return getUIFModelAndView(form);
310 }
311 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedFeeTypes(feeTypes)) > 0) {
312 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
313 return getUIFModelAndView(form);
314 }
315 paymentAmount = patronBillHelperService.itemWiseTransaction(feeTypes, paymentAmount, OLEConstants.FORGIVE, OLEConstants.FORGIVEN, OLEConstants.PAR_PAID, patronBillForm.getForgiveNote(), patronBillForm.getTransactionNumber(), patronBillForm.getTransactionNote(), patronBillForm.getPaidByUser(), patronBillForm.getCurrentSessionTransactions());
316
317 } else {
318 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.SELECT);
319 return start(patronBillForm, result, request, response);
320 }
321 if (paymentAmount.compareTo(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE) > 0) {
322 patronBillForm.setMessage(OLEConstants.BAL_AMT + paymentAmount);
323 }
324 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
325 patronBillForm.setTransactionNumber("");
326 patronBillForm.setTransactionNote("");
327 return start(patronBillForm, result, request, response);
328 }
329
330
331
332
333
334
335
336
337
338
339 @RequestMapping(params = "methodToCall=error")
340 public ModelAndView errorPayment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
341 HttpServletRequest request, HttpServletResponse response) {
342 LOG.debug("Initialized forgivePayment Method");
343 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
344 PatronBillForm patronBillForm = (PatronBillForm) form;
345 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
346 patronBillForm.setMessage("");
347 boolean valid = true;
348 if (patronBillForm.getPaymentAmount() == null) {
349 valid = false;
350 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.PAY_AMT_EMPTY);
351 } else {
352 int signum = patronBillForm.getPaymentAmount().bigDecimalValue().signum();
353 if (signum < 0) {
354 valid = false;
355 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.NEGATIVE_NUM);
356 }
357 }
358
359
360
361
362 if (!valid) {
363 return getUIFModelAndView(patronBillForm);
364 }
365 KualiDecimal paymentAmount = patronBillForm.getPaymentAmount();
366 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
367 List<PatronBillPayment> patronBillPayments = patronBillForm.getPatronBillPaymentList();
368 if (!patronBillHelperService.isSelectedPaidPatronBillFullyPaid(patronBillPayments)) {
369 List<String> billIds = patronBillHelperService.getBillIds();
370 Collections.sort(billIds);
371 String buffer = "";
372 for (String billId : billIds) {
373 buffer = buffer + billId + ",";
374 }
375 if (buffer.length() > 0) {
376 buffer = buffer.substring(0, buffer.length() - 1);
377 }
378 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
379 return getUIFModelAndView(form);
380 }
381 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedPatronBills(patronBillPayments)) > 0) {
382 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
383 return getUIFModelAndView(form);
384 }
385 paymentAmount = patronBillHelperService.billWiseTransaction(patronBillPayments, paymentAmount, OLEConstants.ERROR, OLEConstants.IN_ERROR, OLEConstants.PAR_PAID, false, patronBillForm.getErrorNote(), patronBillForm.getTransactionNumber(), patronBillForm.getTransactionNote(), patronBillForm.getPaidByUser(), patronBillForm.getCurrentSessionTransactions());
386 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
387 List<FeeType> feeTypes = patronBillForm.getFeeTypes();
388 if (!patronBillHelperService.isSelectedFeeTypeFullyPaid(feeTypes)) {
389 List<String> billIds = patronBillHelperService.getBillIds();
390 Collections.sort(billIds);
391 String buffer = "";
392 for (String billId : billIds) {
393 buffer = buffer + billId + ",";
394 }
395 if (buffer.length() > 0) {
396 buffer = buffer.substring(0, buffer.length() - 1);
397 }
398 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
399 return getUIFModelAndView(form);
400 }
401 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedFeeTypes(feeTypes)) > 0) {
402 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
403 return getUIFModelAndView(form);
404 }
405 paymentAmount = patronBillHelperService.itemWiseTransaction(feeTypes, paymentAmount, OLEConstants.ERROR, OLEConstants.IN_ERROR, OLEConstants.PAR_PAID, patronBillForm.getErrorNote(), patronBillForm.getTransactionNumber(), patronBillForm.getTransactionNote(), patronBillForm.getPaidByUser(), patronBillForm.getCurrentSessionTransactions());
406
407 } else {
408 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.SELECT);
409 return start(patronBillForm, result, request, response);
410 }
411 if (paymentAmount.compareTo(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE) > 0) {
412 patronBillForm.setMessage(OLEConstants.BAL_AMT + paymentAmount);
413 }
414 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
415 patronBillForm.setTransactionNumber("");
416 patronBillForm.setTransactionNote("");
417 return start(patronBillForm, result, request, response);
418 }
419
420
421
422
423
424
425
426
427
428
429 @RequestMapping(params = "methodToCall=print")
430 public ModelAndView printBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
431 LOG.debug("Initialized printBill Method");
432 PatronBillForm patronBillForm = (PatronBillForm) form;
433 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
434 patronBillForm.setMessage("");
435 PrintBill printBill = new PrintBill();
436 List<PatronBillPayment> patronBillList = new ArrayList<PatronBillPayment>();
437 List<PatronBillPayment> patronBillPaymentList = new ArrayList<PatronBillPayment>();
438 List<FeeType> feeTypes = new ArrayList<FeeType>();
439 OlePatronDocument olePatronDocument = patronBillForm.getOlePatronDocument();
440 String firstName = olePatronDocument.getFirstName();
441 String lastName = olePatronDocument.getLastName();
442 List<String> transactionIds = new ArrayList<>();
443 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
444 for (PatronBillPayment patronBillPayment : patronBillForm.getPatronBillPaymentList()) {
445 if (patronBillPayment.isSelectBill()) {
446 patronBillPaymentList.add(patronBillPayment);
447 feeTypes = patronBillHelperService.getFeeTypeList(patronBillPaymentList);
448 }
449 }
450 printBill.generatePdf(firstName, lastName, patronBillPaymentList, feeTypes, false, transactionIds, response);
451 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
452 patronBillList = patronBillForm.getPatronBillPaymentList();
453 for (FeeType feeType : patronBillForm.getFeeTypes()) {
454 if (feeType.isActiveItem()) {
455 feeTypes.add(feeType);
456 }
457 }
458 printBill.generatePdf(firstName, lastName, patronBillList, feeTypes, false, transactionIds, response);
459 } else {
460 feeTypes.addAll(patronBillForm.getFeeTypes());
461 for (OleItemLevelBillPayment oleItemLevelBillPayment : patronBillForm.getCurrentSessionTransactions()) {
462 transactionIds.add(oleItemLevelBillPayment.getPaymentId());
463 }
464 printBill.generatePdf(firstName, lastName, patronBillList, feeTypes, true, transactionIds, response);
465 }
466 patronBillForm.setTransactionNumber("");
467 patronBillForm.setTransactionNote("");
468 return getUIFModelAndView(patronBillForm, OLEConstants.OlePatron.BILL_VIEW_PAGE);
469 }
470
471
472
473
474
475
476
477
478
479
480 @RequestMapping(params = "methodToCall=payment")
481 public ModelAndView payment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
482 HttpServletRequest request, HttpServletResponse response) {
483 PatronBillForm patronBillForm = (PatronBillForm) form;
484 patronBillForm.setMessage("");
485 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
486 form.setFormPostUrl(form.getFormPostUrl() + "?viewId=BillView&methodToCall=start&patronId=" + patronBillForm.getOlePatronId());
487 return getUIFModelAndView(form, OLEConstants.OlePatron.BILL_VIEW_PAGE);
488 }
489
490
491
492
493 @Override
494 @RequestMapping(params = "methodToCall=back")
495 public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
496 HttpServletRequest request, HttpServletResponse response) {
497 return super.back(form, result, request, response);
498 }
499
500
501
502
503
504
505
506
507
508
509 @RequestMapping(params = "methodToCall=cancellationNote")
510 public ModelAndView cancellationNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
511 HttpServletRequest request, HttpServletResponse response) {
512 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
513 PatronBillForm patronBillForm = (PatronBillForm) form;
514 patronBillForm.setPatronAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
515 patronBillForm.setOlePatronDocument(patronBillHelperService.getPatronDetails(patronBillForm.getPatronId()));
516 KualiDecimal paymentAmount = patronBillForm.getPaymentAmount();
517 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
518 List<PatronBillPayment> patronBillPayments = patronBillForm.getPatronBillPaymentList();
519 if (!patronBillHelperService.isSelectedPaidPatronBillFullyPaid(patronBillPayments)) {
520 List<String> billIds = patronBillHelperService.getBillIds();
521 Collections.sort(billIds);
522 String buffer = "";
523 for (String billId : billIds) {
524 buffer = buffer + billId + ",";
525 }
526 if (buffer.length() > 0) {
527 buffer = buffer.substring(0, buffer.length() - 1);
528 }
529 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
530 return getUIFModelAndView(form);
531 }
532 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedPatronBills(patronBillPayments)) > 0) {
533 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
534 return getUIFModelAndView(form);
535 }
536 patronBillHelperService.billWiseCancellation(patronBillPayments, patronBillForm.getCancellationNote(), patronBillForm.getCurrentSessionTransactions());
537 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
538 List<FeeType> feeTypes = patronBillForm.getFeeTypes();
539 if (!patronBillHelperService.isSelectedFeeTypeFullyPaid(feeTypes)) {
540 List<String> billIds = patronBillHelperService.getBillIds();
541 Collections.sort(billIds);
542 String buffer = "";
543 for (String billId : billIds) {
544 buffer = buffer + billId + ",";
545 }
546 if (buffer.length() > 0) {
547 buffer = buffer.substring(0, buffer.length() - 1);
548 }
549 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_SELECTED_ITEM_FULLY_PAID, new String[]{buffer.toString()});
550 return getUIFModelAndView(form);
551 }
552 if (paymentAmount != null && paymentAmount.compareTo(patronBillHelperService.getSumOfSelectedFeeTypes(feeTypes)) > 0) {
553 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_OVER_PAYMENT);
554 return getUIFModelAndView(form);
555 }
556 patronBillHelperService.itemWiseCancellation(feeTypes, patronBillForm.getCancellationNote(), patronBillForm.getCurrentSessionTransactions());
557 patronBillForm.setPatronBillPaymentList(null);
558 } else {
559 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.SELECT);
560 }
561
562
563
564
565
566 patronBillForm.setPatronBillPaymentList(patronBillHelperService.getBillPayment(patronBillForm.getPatronId()));
567 patronBillForm.setFeeTypes(patronBillHelperService.getFeeTypeList(patronBillForm.getPatronBillPaymentList()));
568 KualiDecimal KualiDecimal = patronBillHelperService.populateGrandTotal(patronBillForm.getPatronBillPaymentList());
569 patronBillForm.setGrandTotal(KualiDecimal);
570 patronBillForm.setTransactionNumber("");
571 patronBillForm.setTransactionNote("");
572 return super.start(patronBillForm, result, request, response);
573 }
574
575
576
577
578
579
580
581
582
583
584 @RequestMapping(params = "methodToCall=printBillPayment")
585 public ModelAndView printBillPayment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
586 HttpServletRequest request, HttpServletResponse response) {
587 LOG.debug("Initialized printBillPayment Method");
588 PatronBillForm patronBillForm = (PatronBillForm) form;
589 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
590 List<PatronBillPayment> patronBillPaymentList = patronBillHelperService.getBillPayment(patronBillForm.getOlePatronId());
591 List<FeeType> feeTypeList = patronBillHelperService.getFeeTypeList(patronBillPaymentList);
592 patronBillForm.setPrintBillReview(true);
593 patronBillForm.setPrintFlag(true);
594 boolean review = false;
595 String reviewBillParameter = patronBillHelperService.getParameter(OLEConstants.OlePatron.PATRON_BILL_REVIEW_PRINT);
596 boolean reviewParameter = reviewBillParameter.equalsIgnoreCase(OLEConstants.TRUE);
597 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.OlePatron.DEFAULT)) {
598 if (patronBillForm.getCurrentSessionTransactions().size() == 0) {
599 patronBillForm.setPrintFlag(false);
600 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_TRANSACTION_SELECT);
601 return getUIFModelAndView(patronBillForm, OLEConstants.OlePatron.BILL_VIEW_PAGE);
602 }
603 }
604 if (patronBillForm.getPatronBillPaymentList().size() > 0) {
605 for (PatronBillPayment patronBill : patronBillForm.getPatronBillPaymentList()) {
606 if (patronBillPaymentList.size() > 0) {
607 for (PatronBillPayment patronBillPayment : patronBillPaymentList) {
608 if (patronBillPayment.getBillNumber().equals(patronBill.getBillNumber())) {
609 if (patronBill.isSelectBill()) {
610 review = patronBillPayment.isReviewed();
611 if ((reviewParameter && !review)) {
612 patronBillForm.setPrintBillReview(false);
613 break;
614 }
615 }
616 }
617 }
618 }
619 }
620 }
621 if (patronBillForm.getFeeTypes().size() > 0) {
622 for (FeeType feeTypeBo : patronBillForm.getFeeTypes()) {
623 if (feeTypeList.size() > 0) {
624 for (FeeType feeType : feeTypeList) {
625 if (feeType.getBillNumber().equals(feeTypeBo.getBillNumber())) {
626 if (feeTypeBo.isActiveItem()) {
627 PatronBillPayment billPayment = feeType.getPatronBillPayment();
628 review = billPayment.isReviewed();
629 if ((reviewParameter && !review)) {
630 patronBillForm.setPrintBillReview(false);
631 break;
632 }
633 }
634 }
635 }
636 }
637 }
638 }
639 if (!patronBillForm.isPrintBillReview()) {
640 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.NOT_REVIEWED);
641 }
642
643 List<FeeType> feeTypes = new ArrayList<FeeType>();
644 List<String> transactionIds = new ArrayList<>();
645 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
646 for (PatronBillPayment patronBillPayment : patronBillForm.getPatronBillPaymentList()) {
647 if (patronBillPayment.isSelectBill()) {
648 feeTypes = patronBillHelperService.getFeeTypeList(patronBillPaymentList);
649 for (FeeType feeType : feeTypes) {
650 for (OleItemLevelBillPayment oleItemLevelBillPayment : feeType.getItemLevelBillPaymentList()) {
651 if(!transactionIds.contains(oleItemLevelBillPayment.getPaymentId())){
652 transactionIds.add(oleItemLevelBillPayment.getPaymentId());
653 }
654 }
655 }
656 }
657 }
658 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
659 for (FeeType feeType : patronBillForm.getFeeTypes()) {
660 if (feeType.isActiveItem()) {
661 for (OleItemLevelBillPayment oleItemLevelBillPayment : feeType.getItemLevelBillPaymentList()) {
662 if(!transactionIds.contains(oleItemLevelBillPayment.getPaymentId())){
663 transactionIds.add(oleItemLevelBillPayment.getPaymentId());
664 }
665 }
666 }
667 }
668 } else {
669 feeTypes.addAll(patronBillForm.getFeeTypes());
670 for (OleItemLevelBillPayment oleItemLevelBillPayment : patronBillForm.getCurrentSessionTransactions()) {
671 transactionIds.add(oleItemLevelBillPayment.getPaymentId());
672 }
673 }
674 if(transactionIds.size()==0){
675 patronBillForm.setPrintFlag(false);
676 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.OUTSTANDING_BILL);
677 }
678
679 String[] formKey = (patronBillForm.getFormKey()).split(",");
680 patronBillForm.setFormKey(formKey[0]);
681 return getUIFModelAndView(patronBillForm, OLEConstants.OlePatron.BILL_VIEW_PAGE);
682 }
683
684 @RequestMapping(params = "methodToCall=mailToPatron")
685 public ModelAndView mailToPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
686 HttpServletRequest request, HttpServletResponse response) {
687 PatronBillForm patronBillForm = (PatronBillForm) form;
688 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
689 List<PatronBillPayment> patronBillPaymentList = patronBillHelperService.getBillPayment(patronBillForm.getOlePatronId());
690 List<FeeType> feeTypeList = patronBillHelperService.getFeeTypeList(patronBillPaymentList);
691 if (patronBillForm.getPatronId() == null && patronBillForm.getOlePatronId() == null) {
692 patronBillForm.setOlePatronDocument(patronBillHelperService.getPatronDetails(patronBillForm.getPatronId()));
693 }
694 List<FeeType> feeTypes = new ArrayList<FeeType>();
695 List<String> transactionIds = new ArrayList<>();
696 KualiDecimal feeAmount = new KualiDecimal(0);
697 KualiDecimal paidAmount = new KualiDecimal(0);
698 boolean isReadyToBuild = false;
699 try {
700 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.OlePatron.DEFAULT)) {
701 feeTypes = feeTypeList;
702 for (OleItemLevelBillPayment oleItemLevelBillPayment : patronBillForm.getCurrentSessionTransactions()) {
703 transactionIds.add(oleItemLevelBillPayment.getPaymentId());
704 }
705 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.ITEM_WISE)) {
706 if (patronBillForm.getFeeTypes() != null) {
707 for (FeeType feeType : patronBillForm.getFeeTypes()) {
708 if (feeType.isActiveItem()) {
709 feeTypes.add(feeType);
710 }
711 }
712 }
713 } else if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.BILL_WISE)) {
714 if (patronBillForm.getPatronBillPaymentList() != null) {
715 for (PatronBillPayment patronBillPayment : patronBillForm.getPatronBillPaymentList()) {
716 if (patronBillPayment != null) {
717 if (patronBillPayment.getFeeType() != null) {
718 feeTypes.addAll(patronBillPayment.getFeeType());
719 } else {
720
721 }
722 }
723 }
724
725 }
726 }
727 if (transactionIds.size() == 0 && feeTypes.size() == 0) {
728 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.OUTSTANDING_BILL);
729 return getUIFModelAndView(form);
730
731 }
732 if (feeTypes.size() > 0) {
733 isReadyToBuild = true;
734 }
735 if (isReadyToBuild) {
736 StringBuffer buffer = new StringBuffer();
737 buffer.append("<TR><TD> </TD><TD> </TD></TR>");
738 buffer.append("<TABLE width=\"100%\">");
739 buffer.append("<TR><TD><CENTER>" + "<b>" + OLEConstants.OlePatronBill.HEADER_PATRON_RECEIPT + "</b>" + "</CENTER></TD></TR>");
740 buffer.append("<TR><TD><p>");
741 buffer.append("<TR><TD> </TD><TD> </TD></TR></TABLE>");
742 buffer.append("<table id=\"PatronDetails\" style=\"text-align: center;\">");
743 SimpleDateFormat df = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" "+RiceConstants.SIMPLE_DATE_FORMAT_FOR_TIME);
744 buffer.append("<tr><td style=\"text-align: left;\">Date </td><td style=\"text-align: left;\"> : " + (df.format(System.currentTimeMillis())) + "</td></tr>");
745 buffer.append("<tr><td style=\"text-align: left;\">First Name </td><td style=\"text-align: left;\"> : " + (patronBillForm.getOlePatronDocument().getFirstName() != null ? patronBillForm.getOlePatronDocument().getFirstName() : " ") + "</td></tr>");
746 buffer.append("<tr><td style=\"text-align: left;\">Last Name </td><td style=\"text-align: left;\"> : " + (patronBillForm.getOlePatronDocument().getLastName() != null ? patronBillForm.getOlePatronDocument().getLastName() : " ") + "</td></tr>");
747 StringBuffer bufferData = new StringBuffer();
748 bufferData.append("</table><BR/><BR/><BR/><BR/>");
749 bufferData.append("<table style=\"width: auto;text-align: center;\" border=\"1\">");
750 if (feeTypes != null) {
751 bufferData.append("<thead><tr>");
752 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_PATRON_RECEIPT_NUMBER + "</b>" + "</td>");
753 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_BILL_NUMBER + "</b>" + "</td>");
754 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_FEE_TYPE + "</b>" + "</td>");
755 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_TRANSACTION_DATE + "</b>" + "</td>");
756 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_OPERATOR_ID + "</b>" + "</td>");
757 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_ITEM_BARCODE + "</b>" + "</td>");
758 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_ITEM_TITLE + "</b>" + "</td>");
759 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_ITEM_AUTHOR + "</b>" + "</td>");
760 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_ITEM_CALL_NUMBER + "</b>" + "</td>");
761 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_TOTAL_AMOUNT + "</b>" + "</td>");
762 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_PAID_AMOUNT + "</b>" + "</td>");
763 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_TRANSACTION_NUMBER + "</b>" + "</td>");
764 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_TRANSACTION_NOTE + "</b>" + "</td>");
765 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_PAYMENT_MODE + "</b>" + "</td>");
766 bufferData.append("<td style=\"text-align: center;\">" + "<b>" + OLEConstants.OlePatronBill.LABEL_NOTE + "</b>" + "</td>");
767 bufferData.append("</tr></thead>");
768 bufferData.append("<tbody>");
769 for (FeeType feeType : feeTypes) {
770
771 List<OleItemLevelBillPayment> oleItemLevelBillPayments = new ArrayList<>();
772 if (feeType.getItemLevelBillPaymentList() != null) {
773 oleItemLevelBillPayments.addAll(feeType.getItemLevelBillPaymentList());
774 } else {
775 Map<String, String> map = new HashMap<String, String>();
776 map.put("lineItemId", feeType.getId());
777 List<OleItemLevelBillPayment> itemLevelBillPayments = (List<OleItemLevelBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(OleItemLevelBillPayment.class, map);
778 if (itemLevelBillPayments != null) {
779 oleItemLevelBillPayments.addAll(itemLevelBillPayments);
780 }
781 }
782 String feeTypeName = "";
783 if (feeType.getOleFeeType() != null && feeType.getOleFeeType().getFeeTypeName() != null) {
784 feeTypeName = feeType.getOleFeeType().getFeeTypeName();
785 }
786 for (OleItemLevelBillPayment oleItemLevelBillPayment : oleItemLevelBillPayments) {
787 boolean isAddContent = false;
788 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.OlePatron.DEFAULT)) {
789 if (transactionIds.contains(oleItemLevelBillPayment.getPaymentId())) {
790 isAddContent = true;
791 }
792 } else {
793 isAddContent = true;
794 }
795 if (isAddContent) {
796 bufferData.append("<tr>");
797 bufferData.append("<td style=\"text-align: center;\">" + (oleItemLevelBillPayment.getPaymentId() != null ? oleItemLevelBillPayment.getPaymentId() : " ") + "</td>");
798 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getBillNumber() != null ? feeType.getBillNumber() : " ") + "</td>");
799 bufferData.append("<td style=\"text-align: center;\">" + feeTypeName + "</td>");
800 bufferData.append("<td style=\"text-align: center;\">" + (oleItemLevelBillPayment.getPaymentDate() != null ? df.format(oleItemLevelBillPayment.getPaymentDate()) : " ") + "</td>");
801 bufferData.append("<td style=\"text-align: center;\">" + (oleItemLevelBillPayment.getCreatedUser() != null ? oleItemLevelBillPayment.getCreatedUser() : " ") + "</td>");
802 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getItemBarcode() != null ? feeType.getItemBarcode() : " ") + "</td>");
803 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getItemTitle() != null ? feeType.getItemTitle() : " ") + "</td>");
804 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getItemAuthor() != null ? feeType.getItemAuthor() : " ") + "</td>");
805 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getItemCallNumber() != null ? feeType.getItemCallNumber() : " ") + "</td>");
806
807 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getFeeAmount() != null ? CurrencyFormatter.getSymbolForCurrencyPattern() + feeType.getFeeAmount() :CurrencyFormatter.getSymbolForCurrencyPattern() +"0") + "</td>");
808 bufferData.append("<td style=\"text-align: center; size:30px;\">" + (oleItemLevelBillPayment.getAmount() != null ? CurrencyFormatter.getSymbolForCurrencyPattern() + oleItemLevelBillPayment.getAmount() : CurrencyFormatter.getSymbolForCurrencyPattern()+"0") + "</td>");
809 bufferData.append("<td style=\"text-align: center;\">" + (oleItemLevelBillPayment.getTransactionNumber() != null ? oleItemLevelBillPayment.getTransactionNumber() : " ") + "</td>");
810 bufferData.append("<td style=\"text-align: center;\">" + (oleItemLevelBillPayment.getTransactionNote() != null ? oleItemLevelBillPayment.getTransactionNote() : " ") + "</td>");
811 bufferData.append("<td style=\"text-align: center;\">" + (oleItemLevelBillPayment.getPaymentMode() != null ? oleItemLevelBillPayment.getPaymentMode() : " ") + "</td>");
812 bufferData.append("<td style=\"text-align: center;\">" + (feeType.getGeneralNote() != null ? feeType.getGeneralNote() : " ") + "</td>");
813 bufferData.append("</tr>");
814 feeAmount = feeAmount.add(feeType.getFeeAmount());
815 paidAmount=paidAmount.add(oleItemLevelBillPayment.getAmount());
816 }
817
818 }
819
820 }
821 String totalAmountDue=feeAmount.subtract(paidAmount)!=null?feeAmount.subtract(paidAmount).toString():"0";
822 bufferData.append("</tbody>");
823 bufferData.append("</table>");
824
825 buffer.append("<tr><td style=\"text-align: left;\">"+OLEConstants.TOT_AMT_PAID+" </td><td style=\"text-align: left;\"> : $" + (paidAmount!=null?paidAmount.toString():"0") + "</td></tr>");
826 buffer.append(bufferData.toString());
827 }
828 buffer.append("</p></TD></TR>");
829 buffer.append("</BODY></HTML>");
830 if (patronBillForm.getOlePatronDocument() != null) {
831 String email = "";
832 if (patronBillForm.getOlePatronDocument().getEmails() != null) {
833 for (EntityEmailBo emailBo : patronBillForm.getOlePatronDocument().getEmails()) {
834 if (emailBo != null && emailBo.isDefaultValue()) {
835 email = emailBo.getEmailAddress();
836 }
837 }
838 }
839 if ((email == null) || (email != null && email.equalsIgnoreCase(""))) {
840 Map<String, String> emailMap = new HashMap<String, String>();
841 if (patronBillForm.getOlePatronId() != null) {
842 emailMap.put("entityId", patronBillForm.getOlePatronId());
843 }
844 if (patronBillForm.getPatronId() != null) {
845 emailMap.put("entityId", patronBillForm.getPatronId());
846 }
847 List<EntityEmailBo> entityEmailBos = (List<EntityEmailBo>) getBusinessObjectService().findMatching(EntityEmailBo.class, emailMap);
848 if (entityEmailBos != null) {
849 for (EntityEmailBo emailBo : entityEmailBos) {
850 if (emailBo != null && emailBo.isDefaultValue()) {
851 email = emailBo.getEmailAddress();
852 }
853 }
854 }
855 }
856 LoanProcessor loanProcessor = new LoanProcessor();
857 String fromAddress = loanProcessor.getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
858 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
859 fromAddress = OLEConstants.KUALI_MAIL;
860 }
861 if (email != null && !email.equalsIgnoreCase("")) {
862 boolean sendMail = true;
863 if (patronBillForm.getBillWisePayment().equalsIgnoreCase(OLEConstants.OlePatron.DEFAULT)) {
864 if (patronBillForm.getCurrentSessionTransactions().size() == 0) {
865 sendMail = false;
866 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_TRANSACTION_SELECT);
867 }
868 }
869 if (sendMail) {
870 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
871 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(email), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(buffer.toString()), true);
872 if (LOG.isInfoEnabled()) {
873 LOG.info("Mail send successfully to " + email);
874 }
875 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.OlePatron.PATRON_SUCCESS_MAIL);
876 }
877 }
878 }
879 }
880 } catch (Exception e) {
881 LOG.error("Exception occured during sending mail" + e);
882 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_SUCCESS_MAIL);
883 }
884 return getUIFModelAndView(patronBillForm);
885 }
886
887
888
889 @RequestMapping(params = "methodToCall=selectAllBill")
890 public ModelAndView selectAllBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
891 HttpServletRequest request, HttpServletResponse response) {
892 LOG.debug("Initialized acceptPayment Method");
893 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
894 PatronBillForm patronBillForm = (PatronBillForm) form;
895 KualiDecimal totalAmount=OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE;
896 for(PatronBillPayment patronBillPayment:patronBillForm.getPatronBillPaymentList()){
897
898
899
900 patronBillPayment.setSelectBill(true);
901 totalAmount=new KualiDecimal(totalAmount.bigDecimalValue().add(patronBillPayment.getUnPaidBalance().bigDecimalValue()));
902 }
903 for(FeeType feeType:patronBillForm.getFeeTypes()){
904 feeType.setActiveItem(false);
905 }
906 patronBillForm.setPaymentAmount(totalAmount);
907 patronBillForm.setBillWisePayment(OLEConstants.BILL_WISE);
908 return getUIFModelAndView(patronBillForm);
909 }
910
911 @RequestMapping(params = "methodToCall=selectAllItem")
912 public ModelAndView selectAllItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
913 HttpServletRequest request, HttpServletResponse response) {
914 LOG.debug("Initialized acceptPayment Method");
915 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
916 PatronBillForm patronBillForm = (PatronBillForm) form;
917 KualiDecimal totalAmount=OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE;
918 for(PatronBillPayment patronBillPayment:patronBillForm.getPatronBillPaymentList()){
919 patronBillPayment.setSelectBill(false);
920 }
921 for(FeeType feeType:patronBillForm.getFeeTypes()){
922
923
924
925 feeType.setActiveItem(true);
926 totalAmount=new KualiDecimal(totalAmount.bigDecimalValue().add(feeType.getBalFeeAmount().bigDecimalValue()));
927 }
928 patronBillForm.setPaymentAmount(totalAmount);
929 patronBillForm.setBillWisePayment(OLEConstants.ITEM_WISE);
930 return getUIFModelAndView(patronBillForm);
931 }
932
933 @RequestMapping(params = "methodToCall=deSelectAll")
934 public ModelAndView deSelectAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
935 HttpServletRequest request, HttpServletResponse response) {
936 LOG.debug("Initialized acceptPayment Method");
937 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
938 PatronBillForm patronBillForm = (PatronBillForm) form;
939 for(FeeType feeType:patronBillForm.getFeeTypes()){
940 feeType.setActiveItem(false);
941 }
942 for(PatronBillPayment patronBillPayment:patronBillForm.getPatronBillPaymentList()){
943 patronBillPayment.setSelectBill(false);
944 }
945 patronBillForm.setPaymentAmount(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE);
946 patronBillForm.setBillWisePayment("default");
947 return getUIFModelAndView(patronBillForm);
948 }
949
950 }