1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.web.struts;
17
18 import java.io.ByteArrayOutputStream;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import java.util.Properties;
22 import java.util.Set;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.kuali.ole.fp.businessobject.DisbursementVoucherNonEmployeeExpense;
32 import org.kuali.ole.fp.businessobject.DisbursementVoucherNonEmployeeTravel;
33 import org.kuali.ole.fp.businessobject.DisbursementVoucherPreConferenceRegistrant;
34 import org.kuali.ole.fp.businessobject.WireCharge;
35 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
36 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
37 import org.kuali.ole.fp.document.DisbursementVoucherConstants.TabByReasonCode;
38 import org.kuali.ole.fp.document.service.DisbursementVoucherCoverSheetService;
39 import org.kuali.ole.fp.document.service.DisbursementVoucherPayeeService;
40 import org.kuali.ole.fp.document.service.DisbursementVoucherTaxService;
41 import org.kuali.ole.fp.document.service.DisbursementVoucherTravelService;
42 import org.kuali.ole.sys.OLEConstants;
43 import org.kuali.ole.sys.OLEKeyConstants;
44 import org.kuali.ole.sys.OLEPropertyConstants;
45 import org.kuali.ole.sys.context.SpringContext;
46 import org.kuali.ole.sys.service.UniversityDateService;
47 import org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase;
48 import org.kuali.ole.vnd.businessobject.VendorAddress;
49 import org.kuali.ole.vnd.businessobject.VendorDetail;
50 import org.kuali.rice.core.api.config.property.ConfigurationService;
51 import org.kuali.rice.core.api.util.type.KualiDecimal;
52 import org.kuali.rice.kew.api.exception.WorkflowException;
53 import org.kuali.rice.kim.api.identity.Person;
54 import org.kuali.rice.kim.api.identity.PersonService;
55 import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizer;
56 import org.kuali.rice.kns.document.authorization.TransactionalDocumentPresentationController;
57 import org.kuali.rice.kns.service.DictionaryValidationService;
58 import org.kuali.rice.kns.util.WebUtils;
59 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
60 import org.kuali.rice.krad.service.BusinessObjectService;
61 import org.kuali.rice.krad.service.DocumentService;
62 import org.kuali.rice.krad.util.GlobalVariables;
63 import org.kuali.rice.krad.util.KRADConstants;
64 import org.kuali.rice.krad.util.ObjectUtils;
65 import org.kuali.rice.krad.util.UrlFactory;
66
67
68
69
70 public class DisbursementVoucherAction extends KualiAccountingDocumentActionBase {
71 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherAction.class);
72
73
74
75
76 @Override
77 protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
78 super.loadDocument(kualiDocumentFormBase);
79
80 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) kualiDocumentFormBase;
81 DisbursementVoucherDocument dvDoc = (DisbursementVoucherDocument) dvForm.getDocument();
82
83
84 String payeeIdNumber = dvDoc.getDvPayeeDetail().getDisbVchrPayeeIdNumber();
85
86 Person person = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(payeeIdNumber);
87
88
89 if (person != null && person.isActive()) {
90 dvDoc.getDvPayeeDetail().setDisbVchrPayeeEmployeeCode(true);
91 } else {
92 dvDoc.getDvPayeeDetail().setDisbVchrPayeeEmployeeCode(false);
93 }
94 }
95
96
97
98
99
100 @Override
101 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
102 ActionForward dest = super.execute(mapping, form, request, response);
103
104 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
105 if (form != null) {
106 DisbursementVoucherDocument dvDoc = (DisbursementVoucherDocument) dvForm.getDocument();
107 if (dvDoc != null) {
108 DisbursementVoucherNonEmployeeTravel dvNet = dvDoc.getDvNonEmployeeTravel();
109 if (dvNet != null) {
110
111 Integer amount = dvNet.getDvPersonalCarMileageAmount();
112 if ((amount == null) || (amount.intValue() == 0)) {
113 clearTravelMileageAmount(dvNet);
114 }
115
116
117 KualiDecimal rate = dvNet.getDisbVchrPerdiemRate();
118 if ((rate == null) || rate.isZero()) {
119 clearTravelPerDiem(dvNet);
120 }
121 }
122 }
123 }
124
125 return dest;
126 }
127
128
129
130
131
132 @Override
133 public ActionForward approve(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
134 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
135 SpringContext.getBean(DisbursementVoucherPayeeService.class).checkPayeeAddressForChanges((DisbursementVoucherDocument) dvForm.getDocument());
136
137 return super.approve(mapping, form, request, response);
138 }
139
140
141
142
143
144
145 @Override
146 protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
147 super.createDocument(kualiDocumentFormBase);
148 ((DisbursementVoucherDocument) kualiDocumentFormBase.getDocument()).initiateDocument();
149
150
151
152 }
153
154
155
156
157 public ActionForward printDisbursementVoucherCoverSheet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
158 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
159
160
161 String directory = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_HELP_URL_KEY);
162
163 DisbursementVoucherDocument document = (DisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(request.getParameter(OLEPropertyConstants.DOCUMENT_NUMBER));
164
165
166
167
168 dvForm.getDocument().getDocumentHeader().setWorkflowDocument(document.getDocumentHeader().getWorkflowDocument());
169
170 ByteArrayOutputStream baos = new ByteArrayOutputStream();
171 DisbursementVoucherCoverSheetService coverSheetService = SpringContext.getBean(DisbursementVoucherCoverSheetService.class);
172
173 coverSheetService.generateDisbursementVoucherCoverSheet(directory, DisbursementVoucherConstants.DV_COVER_SHEET_TEMPLATE_NM, document, baos);
174 String fileName = document.getDocumentNumber() + "_cover_sheet.pdf";
175 WebUtils.saveMimeOutputStreamAsFile(response, "application/pdf", baos, fileName);
176
177 return (null);
178 }
179
180
181
182
183 public ActionForward calculateTravelPerDiem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
184 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
185
186 try {
187
188 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
189 KualiDecimal perDiemAmount = SpringContext.getBean(DisbursementVoucherTravelService.class).calculatePerDiemAmount(dvDocument.getDvNonEmployeeTravel().getDvPerdiemStartDttmStamp(), dvDocument.getDvNonEmployeeTravel().getDvPerdiemEndDttmStamp(), dvDocument.getDvNonEmployeeTravel().getDisbVchrPerdiemRate());
190
191 dvDocument.getDvNonEmployeeTravel().setDisbVchrPerdiemCalculatedAmt(perDiemAmount);
192 dvDocument.getDvNonEmployeeTravel().setDisbVchrPerdiemActualAmount(perDiemAmount);
193 }
194 catch (RuntimeException e) {
195 String errorMessage = e.getMessage();
196
197 if (StringUtils.isBlank(errorMessage)) {
198 errorMessage = "The per diem amount could not be calculated. Please ensure all required per diem fields are filled in before attempting to calculate the per diem amount.";
199 }
200
201 LOG.error("Error in calculating travel per diem: " + errorMessage);
202 GlobalVariables.getMessageMap().putError("DVNonEmployeeTravelErrors", OLEKeyConstants.ERROR_CUSTOM, errorMessage);
203 }
204
205 return mapping.findForward(OLEConstants.MAPPING_BASIC);
206 }
207
208
209
210
211 public ActionForward clearTravelPerDiem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
212 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
213 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
214
215 DisbursementVoucherNonEmployeeTravel dvNet = dvDocument.getDvNonEmployeeTravel();
216 if (dvNet != null) {
217 clearTravelPerDiem(dvNet);
218 }
219
220 return mapping.findForward(OLEConstants.MAPPING_BASIC);
221 }
222
223
224
225
226 protected void clearTravelPerDiem(DisbursementVoucherNonEmployeeTravel dvNet) {
227 dvNet.setDisbVchrPerdiemCalculatedAmt(null);
228 dvNet.setDisbVchrPerdiemActualAmount(null);
229 }
230
231
232
233
234 public ActionForward calculateTravelMileageAmount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
235 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
236 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
237
238 if (dvDocument.getDvNonEmployeeTravel().getDvPersonalCarMileageAmount() == null) {
239 LOG.error("Total Mileage must be given");
240 GlobalVariables.getMessageMap().putError("DVNonEmployeeTravelErrors", OLEKeyConstants.ERROR_REQUIRED, "Total Mileage");
241 }
242
243 if (dvDocument.getDvNonEmployeeTravel().getDvPerdiemStartDttmStamp() == null) {
244 LOG.error("Travel Start Date must be given");
245 GlobalVariables.getMessageMap().putError("DVNonEmployeeTravelErrors", OLEKeyConstants.ERROR_REQUIRED, "Travel Start Date");
246 }
247
248 if (!GlobalVariables.getMessageMap().hasErrors()) {
249
250 KualiDecimal mileageAmount = SpringContext.getBean(DisbursementVoucherTravelService.class).calculateMileageAmount(dvDocument.getDvNonEmployeeTravel().getDvPersonalCarMileageAmount(), dvDocument.getDvNonEmployeeTravel().getDvPerdiemStartDttmStamp());
251
252 dvDocument.getDvNonEmployeeTravel().setDisbVchrMileageCalculatedAmt(mileageAmount);
253 dvDocument.getDvNonEmployeeTravel().setDisbVchrPersonalCarAmount(mileageAmount);
254 }
255
256 return mapping.findForward(OLEConstants.MAPPING_BASIC);
257 }
258
259
260
261
262 public ActionForward clearTravelMileageAmount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
263 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
264 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
265
266 DisbursementVoucherNonEmployeeTravel dvNet = dvDocument.getDvNonEmployeeTravel();
267 if (dvNet != null) {
268 clearTravelMileageAmount(dvNet);
269 }
270
271 return mapping.findForward(OLEConstants.MAPPING_BASIC);
272 }
273
274
275
276
277 protected void clearTravelMileageAmount(DisbursementVoucherNonEmployeeTravel dvNet) {
278 dvNet.setDisbVchrMileageCalculatedAmt(null);
279 dvNet.setDisbVchrPersonalCarAmount(null);
280 }
281
282
283
284
285 public ActionForward addNonEmployeeExpenseLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
286 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
287 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
288
289 DisbursementVoucherNonEmployeeExpense newExpenseLine = dvForm.getNewNonEmployeeExpenseLine();
290
291
292 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.NEW_NONEMPLOYEE_EXPENSE_LINE);
293 SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(newExpenseLine);
294
295
296 if (StringUtils.isBlank(newExpenseLine.getDisbVchrPrePaidExpenseCode())) {
297 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.DISB_VCHR_EXPENSE_CODE, OLEKeyConstants.ERROR_DV_EXPENSE_CODE);
298 }
299 if (StringUtils.isBlank(newExpenseLine.getDisbVchrPrePaidExpenseCompanyName())) {
300 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.DISB_VCHR_EXPENSE_COMPANY_NAME, OLEKeyConstants.ERROR_DV_EXPENSE_COMPANY_NAME);
301 }
302 if (ObjectUtils.isNull(newExpenseLine.getDisbVchrExpenseAmount())) {
303 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.DISB_VCHR_EXPENSE_AMOUNT, OLEKeyConstants.ERROR_DV_EXPENSE_AMOUNT);
304 }
305
306 GlobalVariables.getMessageMap().removeFromErrorPath(OLEPropertyConstants.NEW_NONEMPLOYEE_EXPENSE_LINE);
307
308
309
310
311
312 if (!GlobalVariables.getMessageMap().hasErrors()) {
313 newExpenseLine.setDocumentNumber(dvDocument.getDocumentNumber());
314 dvDocument.getDvNonEmployeeTravel().addDvNonEmployeeExpenseLine(newExpenseLine);
315 DisbursementVoucherNonEmployeeExpense newNewNonEmployeeExpenseLine = new DisbursementVoucherNonEmployeeExpense();
316 newNewNonEmployeeExpenseLine.setFinancialDocumentLineNumber(newExpenseLine.getFinancialDocumentLineNumber() + 1);
317 dvForm.setNewNonEmployeeExpenseLine(newNewNonEmployeeExpenseLine);
318 }
319
320 return mapping.findForward(OLEConstants.MAPPING_BASIC);
321 }
322
323
324
325
326 public ActionForward addPrePaidNonEmployeeExpenseLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
327 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
328 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
329
330 DisbursementVoucherNonEmployeeExpense newExpenseLine = dvForm.getNewPrePaidNonEmployeeExpenseLine();
331
332
333 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.NEW_PREPAID_EXPENSE_LINE);
334 SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(newExpenseLine);
335
336
337 if (StringUtils.isBlank(newExpenseLine.getDisbVchrPrePaidExpenseCode())) {
338 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.DISB_VCHR_PRE_PAID_EXPENSE_CODE, OLEKeyConstants.ERROR_DV_PREPAID_EXPENSE_CODE);
339 }
340 if (StringUtils.isBlank(newExpenseLine.getDisbVchrPrePaidExpenseCompanyName())) {
341 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.DISB_VCHR_PRE_PAID_EXPENSE_COMPANY_NAME, OLEKeyConstants.ERROR_DV_PREPAID_EXPENSE_COMPANY_NAME);
342 }
343 if (ObjectUtils.isNull(newExpenseLine.getDisbVchrExpenseAmount())) {
344 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.DISB_VCHR_EXPENSE_AMOUNT, OLEKeyConstants.ERROR_DV_PREPAID_EXPENSE_AMOUNT);
345 }
346 GlobalVariables.getMessageMap().removeFromErrorPath(OLEPropertyConstants.NEW_PREPAID_EXPENSE_LINE);
347
348
349
350
351
352 if (!GlobalVariables.getMessageMap().hasErrors()) {
353 newExpenseLine.setDocumentNumber(dvDocument.getDocumentNumber());
354 dvDocument.getDvNonEmployeeTravel().addDvPrePaidEmployeeExpenseLine(newExpenseLine);
355 DisbursementVoucherNonEmployeeExpense newNewNonEmployeeExpenseLine = new DisbursementVoucherNonEmployeeExpense();
356 newNewNonEmployeeExpenseLine.setFinancialDocumentLineNumber(newExpenseLine.getFinancialDocumentLineNumber() + 1);
357 dvForm.setNewPrePaidNonEmployeeExpenseLine(newNewNonEmployeeExpenseLine);
358 }
359
360 return mapping.findForward(OLEConstants.MAPPING_BASIC);
361 }
362
363
364
365
366 public ActionForward deleteNonEmployeeExpenseLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
367 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
368 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
369
370 int deleteIndex = getLineToDelete(request);
371 dvDocument.getDvNonEmployeeTravel().getDvNonEmployeeExpenses().remove(deleteIndex);
372
373 return mapping.findForward(OLEConstants.MAPPING_BASIC);
374 }
375
376
377
378
379 public ActionForward deletePrePaidEmployeeExpenseLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
380 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
381 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
382
383 int deleteIndex = getLineToDelete(request);
384 dvDocument.getDvNonEmployeeTravel().getDvPrePaidEmployeeExpenses().remove(deleteIndex);
385
386 return mapping.findForward(OLEConstants.MAPPING_BASIC);
387 }
388
389
390
391
392 public ActionForward addPreConfRegistrantLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
393 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
394 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
395
396 DisbursementVoucherPreConferenceRegistrant newRegistrantLine = dvForm.getNewPreConferenceRegistrantLine();
397
398
399 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.NEW_PRECONF_REGISTRANT_LINE);
400 SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(newRegistrantLine);
401 GlobalVariables.getMessageMap().removeFromErrorPath(OLEPropertyConstants.NEW_PRECONF_REGISTRANT_LINE);
402
403 if (!GlobalVariables.getMessageMap().hasErrors()) {
404 dvDocument.addDvPrePaidRegistrantLine(newRegistrantLine);
405 dvForm.setNewPreConferenceRegistrantLine(new DisbursementVoucherPreConferenceRegistrant());
406 }
407
408 return mapping.findForward(OLEConstants.MAPPING_BASIC);
409 }
410
411
412
413
414 public ActionForward deletePreConfRegistrantLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
415 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
416 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) dvForm.getDocument();
417
418 int deleteIndex = getLineToDelete(request);
419 dvDocument.getDvPreConferenceDetail().getDvPreConferenceRegistrants().remove(deleteIndex);
420
421 return mapping.findForward(OLEConstants.MAPPING_BASIC);
422 }
423
424
425
426
427 public ActionForward generateNonResidentAlienTaxLines(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
428 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
429 DisbursementVoucherDocument document = (DisbursementVoucherDocument) dvForm.getDocument();
430
431 DisbursementVoucherTaxService taxService = SpringContext.getBean(DisbursementVoucherTaxService.class);
432
433
434 GlobalVariables.getMessageMap().addToErrorPath("document");
435 taxService.processNonResidentAlienTax(document);
436 GlobalVariables.getMessageMap().removeFromErrorPath("document");
437
438 return mapping.findForward(OLEConstants.MAPPING_BASIC);
439 }
440
441
442
443
444 public ActionForward clearNonResidentAlienTaxLines(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
445 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
446 DisbursementVoucherDocument document = (DisbursementVoucherDocument) dvForm.getDocument();
447
448 DisbursementVoucherTaxService taxService = SpringContext.getBean(DisbursementVoucherTaxService.class);
449
450
451 taxService.clearNRATaxLines(document);
452
453 return mapping.findForward(OLEConstants.MAPPING_BASIC);
454 }
455
456
457
458
459 public ActionForward clearNonResidentAlienTaxInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
460 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
461 DisbursementVoucherDocument document = (DisbursementVoucherDocument) dvForm.getDocument();
462
463 DisbursementVoucherTaxService taxService = SpringContext.getBean(DisbursementVoucherTaxService.class);
464
465
466 taxService.clearNRATaxInfo(document);
467
468 return mapping.findForward(OLEConstants.MAPPING_BASIC);
469 }
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494 @Override
495 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
496 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
497
498 ActionForward actionAfterPayeeLookup = this.refreshAfterPayeeSelection(mapping, dvForm, request);
499 if (actionAfterPayeeLookup != null) {
500 return actionAfterPayeeLookup;
501 }
502
503 return super.refresh(mapping, form, request, response);
504 }
505
506
507 protected ActionForward refreshAfterPayeeSelection(ActionMapping mapping, DisbursementVoucherForm dvForm, HttpServletRequest request) {
508 String refreshCaller = dvForm.getRefreshCaller();
509
510 DisbursementVoucherDocument document = (DisbursementVoucherDocument) dvForm.getDocument();
511
512 boolean isPayeeLookupable = OLEConstants.KUALI_DISBURSEMENT_PAYEE_LOOKUPABLE_IMPL.equals(refreshCaller);
513 boolean isAddressLookupable = OLEConstants.KUALI_VENDOR_ADDRESS_LOOKUPABLE_IMPL.equals(refreshCaller);
514
515
516 if (refreshCaller == null && hasFullEdit(document)) {
517 dvForm.setPayeeIdNumber(dvForm.getTempPayeeIdNumber());
518 dvForm.setHasMultipleAddresses(false);
519 document.getDvPayeeDetail().setDisbVchrPayeeIdNumber(dvForm.getTempPayeeIdNumber());
520 document.getDvPayeeDetail().setDisbursementVoucherPayeeTypeCode(dvForm.getOldPayeeType());
521
522 return null;
523 }
524
525
526 if (!isPayeeLookupable && !isAddressLookupable) {
527 return null;
528 }
529
530
531 String payeeIdNumber = document.getDvPayeeDetail().getDisbVchrPayeeIdNumber();
532 if (payeeIdNumber == null) {
533 return null;
534 }
535
536 dvForm.setPayeeIdNumber(payeeIdNumber);
537 dvForm.setHasMultipleAddresses(false);
538
539
540 if (isPayeeLookupable && dvForm.isVendor()) {
541 VendorDetail refreshVendorDetail = new VendorDetail();
542 refreshVendorDetail.setVendorNumber(payeeIdNumber);
543 refreshVendorDetail = (VendorDetail) SpringContext.getBean(BusinessObjectService.class).retrieve(refreshVendorDetail);
544
545 VendorAddress defaultVendorAddress = null;
546 if (refreshVendorDetail != null) {
547 List<VendorAddress> vendorAddresses = refreshVendorDetail.getVendorAddresses();
548 boolean hasMultipleAddresses = vendorAddresses != null && vendorAddresses.size() > 1;
549 dvForm.setHasMultipleAddresses(hasMultipleAddresses);
550
551 if (vendorAddresses != null) {
552 defaultVendorAddress = vendorAddresses.get(0);
553 }
554 }
555
556 if (dvForm.hasMultipleAddresses()) {
557 return renderVendorAddressSelection(mapping, request, dvForm);
558 }
559 else if (defaultVendorAddress != null) {
560 setupPayeeAsVendor(dvForm, payeeIdNumber, defaultVendorAddress.getVendorAddressGeneratedIdentifier().toString());
561 }
562
563 return null;
564 }
565
566 if (isPayeeLookupable && dvForm.isEmployee()) {
567 this.setupPayeeAsEmployee(dvForm, payeeIdNumber);
568 }
569
570 String payeeAddressIdentifier = request.getParameter(OLEPropertyConstants.VENDOR_ADDRESS_GENERATED_ID);
571 if (isAddressLookupable && StringUtils.isNotBlank(payeeAddressIdentifier)) {
572 setupPayeeAsVendor(dvForm, payeeIdNumber, payeeAddressIdentifier);
573 }
574
575 String paymentReasonCode = document.getDvPayeeDetail().getDisbVchrPaymentReasonCode();
576
577
578
579 return null;
580 }
581
582
583
584
585
586
587 protected boolean hasFullEdit(DisbursementVoucherDocument document) {
588 final Person user = GlobalVariables.getUserSession().getPerson();
589 final TransactionalDocumentPresentationController documentPresentationController = (TransactionalDocumentPresentationController)getDocumentHelperService().getDocumentPresentationController(document);
590 final TransactionalDocumentAuthorizer documentAuthorizer = (TransactionalDocumentAuthorizer)getDocumentHelperService().getDocumentAuthorizer(document);
591 Set<String> documentActions = documentPresentationController.getDocumentActions(document);
592 documentActions = documentAuthorizer.getDocumentActions(document, user, documentActions);
593
594 if (getDataDictionaryService().getDataDictionary().getDocumentEntry(document.getClass().getName()).getUsePessimisticLocking()) {
595 documentActions = getPessimisticLockService().getDocumentActions(document, user, documentActions);
596 }
597
598 Set<String> editModes = documentPresentationController.getEditModes(document);
599 editModes = documentAuthorizer.getEditModes(document, user, editModes);
600
601 return documentActions.contains(KRADConstants.KUALI_ACTION_CAN_EDIT) && editModes.contains("fullEntry");
602 }
603
604
605
606
607 @Override
608 public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
609 DisbursementVoucherForm dvForm = (DisbursementVoucherForm) form;
610 DisbursementVoucherDocument document = (DisbursementVoucherDocument) dvForm.getDocument();
611
612 return super.performLookup(mapping, form, request, response);
613 }
614
615
616
617
618 protected ActionForward renderVendorAddressSelection(ActionMapping mapping, HttpServletRequest request, DisbursementVoucherForm dvForm) {
619 Properties props = new Properties();
620
621 props.put(KRADConstants.SUPPRESS_ACTIONS, Boolean.toString(true));
622 props.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorAddress.class.getName());
623 props.put(KRADConstants.LOOKUP_ANCHOR, KRADConstants.ANCHOR_TOP_OF_FORM);
624 props.put(KRADConstants.LOOKED_UP_COLLECTION_NAME, OLEPropertyConstants.VENDOR_ADDRESSES);
625
626 String conversionPatttern = "{0}" + OLEConstants.FIELD_CONVERSION_PAIR_SEPERATOR + "{0}";
627 StringBuilder filedConversion = new StringBuilder();
628 filedConversion.append(MessageFormat.format(conversionPatttern, OLEPropertyConstants.VENDOR_ADDRESS_GENERATED_ID)).append(OLEConstants.FIELD_CONVERSIONS_SEPERATOR);
629 filedConversion.append(MessageFormat.format(conversionPatttern, OLEPropertyConstants.VENDOR_HEADER_GENERATED_ID)).append(OLEConstants.FIELD_CONVERSIONS_SEPERATOR);
630 filedConversion.append(MessageFormat.format(conversionPatttern, OLEPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID));
631 props.put(KRADConstants.CONVERSION_FIELDS_PARAMETER, filedConversion);
632
633 props.put(OLEPropertyConstants.VENDOR_HEADER_GENERATED_ID, dvForm.getVendorHeaderGeneratedIdentifier());
634 props.put(OLEPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, dvForm.getVendorDetailAssignedIdentifier());
635 props.put(OLEPropertyConstants.ACTIVE, OLEConstants.ACTIVE_INDICATOR);
636
637 props.put(KRADConstants.RETURN_LOCATION_PARAMETER, this.getReturnLocation(request, mapping));
638 props.put(KRADConstants.BACK_LOCATION, this.getReturnLocation(request, mapping));
639
640 props.put(KRADConstants.LOOKUP_AUTO_SEARCH, "Yes");
641 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.SEARCH_METHOD);
642
643 props.put(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(dvForm));
644 props.put(KRADConstants.DOC_NUM, dvForm.getDocument().getDocumentNumber());
645
646
647 String url = UrlFactory.parameterizeUrl(getApplicationBaseUrl() + "/kr/" + KRADConstants.LOOKUP_ACTION, props);
648
649 dvForm.registerEditableProperty("methodToCall");
650
651 return new ActionForward(url, true);
652 }
653
654
655
656
657 protected void setupPayeeAsEmployee(DisbursementVoucherForm dvForm, String payeeIdNumber) {
658 Person person = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(payeeIdNumber);
659 if (person != null) {
660 ((DisbursementVoucherDocument) dvForm.getDocument()).templateEmployee(person);
661 dvForm.setTempPayeeIdNumber(payeeIdNumber);
662 dvForm.setOldPayeeType(DisbursementVoucherConstants.DV_PAYEE_TYPE_EMPLOYEE);
663
664 }
665 else {
666 LOG.error("Exception while attempting to retrieve universal user by universal user id " + payeeIdNumber);
667 }
668 }
669
670
671
672
673 protected void setupPayeeAsVendor(DisbursementVoucherForm dvForm, String payeeIdNumber, String payeeAddressIdentifier) {
674 VendorDetail vendorDetail = new VendorDetail();
675 vendorDetail.setVendorNumber(payeeIdNumber);
676 vendorDetail = (VendorDetail) SpringContext.getBean(BusinessObjectService.class).retrieve(vendorDetail);
677
678 VendorAddress vendorAddress = new VendorAddress();
679 if (StringUtils.isNotBlank(payeeAddressIdentifier)) {
680 try {
681 vendorAddress.setVendorAddressGeneratedIdentifier(new Integer(payeeAddressIdentifier));
682 vendorAddress = (VendorAddress) SpringContext.getBean(BusinessObjectService.class).retrieve(vendorAddress);
683 dvForm.setTempPayeeIdNumber(payeeIdNumber);
684 dvForm.setOldPayeeType(DisbursementVoucherConstants.DV_PAYEE_TYPE_VENDOR);
685
686 }
687 catch (Exception e) {
688 LOG.error("Exception while attempting to retrieve vendor address for vendor address id " + payeeAddressIdentifier + ": " + e);
689 }
690 }
691
692 ((DisbursementVoucherDocument) dvForm.getDocument()).templateVendor(vendorDetail, vendorAddress);
693 }
694
695
696
697
698 protected void addPaymentCodeWarningMessage(DisbursementVoucherForm dvForm, String paymentReasonCode) {
699
700 for (String tabKey : TabByReasonCode.getAllTabKeys()) {
701 dvForm.getTabStates().remove(tabKey);
702 }
703
704 for (String propertyKey : TabByReasonCode.getAllDocumentPropertyKeys()) {
705 GlobalVariables.getMessageMap().removeAllWarningMessagesForProperty(propertyKey);
706 }
707
708 String reasonCodeProperty = OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYMENT_REASON_CODE;
709 GlobalVariables.getMessageMap().removeAllWarningMessagesForProperty(reasonCodeProperty);
710
711
712 TabByReasonCode tab = TabByReasonCode.getTabByReasonCode(paymentReasonCode);
713 if (tab != null) {
714 dvForm.getTabStates().put(tab.tabKey, "OPEN");
715 GlobalVariables.getMessageMap().putWarning(reasonCodeProperty, tab.messageKey);
716 GlobalVariables.getMessageMap().putWarning(tab.getDocumentPropertyKey(), tab.messageKey);
717 }
718 }
719 }