1 package org.kuali.ole.patron.bill;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.incubator.SolrRequestReponseHandler;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.license.bo.OleEventLogBo;
7 import org.kuali.ole.service.impl.OlePatronBillMaintenanceDocumentServiceImpl;
8 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
9 import org.kuali.rice.krad.bo.PersistableAttachment;
10 import org.kuali.rice.krad.bo.PersistableBusinessObject;
11 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
12 import org.kuali.rice.krad.maintenance.MaintenanceUtils;
13 import org.kuali.rice.krad.service.BusinessObjectService;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15 import org.kuali.rice.krad.service.MaintenanceDocumentService;
16 import org.kuali.rice.krad.uif.UifParameters;
17 import org.kuali.rice.krad.uif.container.CollectionGroup;
18 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
19 import org.kuali.rice.krad.uif.view.View;
20 import org.kuali.rice.krad.util.GlobalVariables;
21 import org.kuali.rice.krad.util.KRADConstants;
22 import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
23 import org.kuali.rice.krad.web.form.DocumentFormBase;
24 import org.kuali.rice.krad.web.form.MaintenanceForm;
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.bind.annotation.RequestMethod;
31 import org.springframework.web.servlet.ModelAndView;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35 import java.math.BigDecimal;
36 import java.util.Date;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41
42
43
44
45
46
47
48 @Controller
49 @RequestMapping(value = "/patronBillMaintenance")
50 public class PatronBillMaintenanceDocumentController extends MaintenanceDocumentController {
51
52 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PatronBillMaintenanceDocumentController.class);
53 private BusinessObjectService businessObjectService;
54
55
56
57
58
59 public BusinessObjectService getBusinessObjectService() {
60 if (null == businessObjectService) {
61 businessObjectService = KRADServiceLocator.getBusinessObjectService();
62 }
63 return businessObjectService;
64 }
65
66
67
68
69 @RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_NEW)
70 @Override
71 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
72 HttpServletRequest request, HttpServletResponse response) {
73 Date billDate = new Date();
74 MaintenanceForm maintenanceForm = (MaintenanceForm) form;
75 setupMaintenance(maintenanceForm, request, KRADConstants.MAINTENANCE_NEW_ACTION);
76 MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
77 PatronBillPayment patronBillPayment=(PatronBillPayment) document.getDocumentDataObject();
78 patronBillPayment.setPatronId(request.getParameter("patronId"));
79 patronBillPayment.setFirstName(request.getParameter("firstName"));
80 patronBillPayment.setLastName(request.getParameter("lastName"));
81 patronBillPayment.setBillDate(billDate);
82 return getUIFModelAndView(maintenanceForm);
83 }
84
85
86
87
88
89
90
91 @Override
92 protected MaintenanceDocumentService getMaintenanceDocumentService() {
93 return GlobalResourceLoader.getService("olePatronBillMaintenanceDocumentService");
94 }
95
96
97
98
99
100
101
102
103
104 @RequestMapping(params = "methodToCall=addToTotalAmount")
105 public ModelAndView addToTotalAmount(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
106 HttpServletRequest request, HttpServletResponse response) throws Exception{
107 ModelAndView modelAndView=super.addLine(uifForm, result, request, response);
108 MaintenanceForm form = (MaintenanceForm) uifForm;
109 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
110 PatronBillPayment patronBillPayment = (PatronBillPayment)document.getNewMaintainableObject().getDataObject();
111 BigDecimal amount = new BigDecimal(0.0);
112 if(patronBillPayment.getFeeType() !=null ) {
113 List<FeeType> feeTypes = patronBillPayment.getFeeType();
114 for (int i=0;i<feeTypes.size();i++) {
115 amount = amount.add(feeTypes.get(i).getFeeAmount());
116 }
117 patronBillPayment.setTotalAmount(amount);
118
119 }
120 return modelAndView;
121 }
122
123
124
125
126
127
128
129 @Override
130 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine")
131 public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
132 HttpServletRequest request, HttpServletResponse response) {
133 MaintenanceForm form = (MaintenanceForm) uifForm;
134 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
135 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
136 selectedCollectionPath);
137 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
138 SolrRequestReponseHandler solrRequestReponseHandler = new SolrRequestReponseHandler();
139 Object eventObject = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath);
140 FeeType feeType = (FeeType) eventObject;
141 String itemBarcode = feeType.getItemBarcode();
142 View view = uifForm.getPostedView();
143 if(itemBarcode=="" || !(itemBarcode.isEmpty())){
144 List<HashMap<String, Object>> documentList= solrRequestReponseHandler.retriveResults("ItemBarcode_display:"+itemBarcode);
145 if(documentList!=null && documentList.size()==0){
146 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BAR_NOT_AVAL );
147 return updateComponent(uifForm, result, request, response);
148 }
149 GlobalVariables.getMessageMap().removeFromErrorPath(KRADConstants.GLOBAL_ERRORS);
150 }
151 view.getViewHelperService().processCollectionAddLine(view, uifForm, selectedCollectionPath);
152 return updateComponent(uifForm, result, request, response);
153 }
154
155
156
157
158
159
160
161
162 @RequestMapping(params = "methodToCall=deleteFromTotalAmount")
163 public ModelAndView deleteFromTotalAmount(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
164 HttpServletRequest request, HttpServletResponse response) {
165
166 ModelAndView modelAndView=super.deleteLine(uifForm, result, request, response);
167 MaintenanceForm form = (MaintenanceForm) uifForm;
168 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
169 PatronBillPayment patronBillPayment = (PatronBillPayment)document.getNewMaintainableObject().getDataObject();
170 BigDecimal amount = new BigDecimal(0.0);
171 String billNumber="";
172 Map feeTypeId = new HashMap();
173 if(patronBillPayment.getFeeType() !=null ) {
174 List<FeeType> feeTypes = patronBillPayment.getFeeType();
175 for (int i=0;i<feeTypes.size();i++) {
176 amount = amount.add(feeTypes.get(i).getFeeAmount());
177 billNumber = feeTypes.get(i).getBillNumber();
178 feeTypeId.put("billNumber",billNumber);
179 }
180 patronBillPayment.setTotalAmount(amount);
181 getBusinessObjectService().deleteMatching(FeeType.class,feeTypeId);
182
183 }
184 return modelAndView;
185 }
186
187
188
189
190
191
192
193
194
195 @RequestMapping(params = "methodToCall=calculateTotal")
196 public ModelAndView calculateTotal(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
197 HttpServletRequest request, HttpServletResponse response) throws Exception{
198
199 MaintenanceForm form = (MaintenanceForm) uifForm;
200 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
201 PatronBillPayment patronBillPayment = (PatronBillPayment)document.getNewMaintainableObject().getDataObject();
202 BigDecimal amount = new BigDecimal(0.0);
203 if(patronBillPayment.getFeeType() !=null ) {
204 List<FeeType> feeTypes = patronBillPayment.getFeeType();
205 for (int i=0;i<feeTypes.size();i++) {
206 amount = amount.add(feeTypes.get(i).getFeeAmount());
207 }
208 patronBillPayment.setTotalAmount(amount);
209 }
210 return getUIFModelAndView(form);
211 }
212
213
214 @RequestMapping(params = "methodToCall=" +"maintenanceDelete")
215 public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result,
216 HttpServletRequest request, HttpServletResponse response) throws Exception {
217 setupMaintenanceForDelete(form, request,"Delete");
218 return getUIFModelAndView(form);
219 }
220
221
222 @RequestMapping(params = "methodToCall=" +"deleteDocument")
223 public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result,
224 HttpServletRequest request, HttpServletResponse response) throws Exception {
225 MaintenanceDocument document = form.getDocument();
226 PatronBillPayment patronBillPayment = new PatronBillPayment();
227
228
229 if(document.getDocumentDataObject() != null) {
230 patronBillPayment = (PatronBillPayment)document.getDocumentDataObject();
231 if(patronBillPayment != null && patronBillPayment.getPatronId() != null) {
232 KRADServiceLocator.getBusinessObjectService().delete(patronBillPayment);
233 GlobalVariables.getMessageMap().putInfoWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS,
234 OLEConstants.OleLicenseRequest.MSG_DELETE_DOC);
235 }
236 else {
237 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OleLicenseRequest.ERROR_CHECKLIST_NOT_FOUND);
238 return getUIFModelAndView(form);
239 }
240 }
241 return close(form, result, request, response);
242 }
243
244
245
246
247
248
249
250
251
252 protected void setupMaintenanceForDelete(MaintenanceForm form, HttpServletRequest request, String maintenanceAction) {
253 MaintenanceDocument document = form.getDocument();
254
255 if (document == null) {
256 document = getMaintenanceDocumentService()
257 .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
258 maintenanceAction);
259
260 form.setDocument(document);
261 form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
262 }
263
264 form.setMaintenanceAction(maintenanceAction);
265 OlePatronBillMaintenanceDocumentServiceImpl olePatronBillMaintenanceDocumentService = (OlePatronBillMaintenanceDocumentServiceImpl)getMaintenanceDocumentService();
266 olePatronBillMaintenanceDocumentService.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
267 MaintenanceUtils.checkForLockingDocument(document, false);
268 }
269
270
271
272
273
274
275 @Override
276 @RequestMapping(params = "methodToCall=route")
277 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
278 HttpServletRequest request, HttpServletResponse response) {
279
280 ModelAndView modelAndView;
281
282 modelAndView = super.route(form, result, request, response);
283 try{
284 calculateTotal(form, result, request, response);
285 }catch(Exception e){
286
287 }
288
289 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
290 if (document.getNewMaintainableObject().getDataObject() instanceof PersistableAttachment) {
291 PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService()
292 .retrieve((PersistableBusinessObject) document.getNewMaintainableObject().getDataObject());
293 request.setAttribute("fileName", bo.getFileName());
294 }
295
296 modelAndView = getUIFModelAndView(form);
297
298 return modelAndView;
299 }
300 }