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