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