View Javadoc
1   /*
2    * Copyright 2005 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.web.struts;
17  
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import javax.servlet.http.HttpServletRequest;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.ole.fp.businessobject.DisbursementVoucherNonEmployeeExpense;
27  import org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
28  import org.kuali.ole.fp.businessobject.DisbursementVoucherPreConferenceRegistrant;
29  import org.kuali.ole.fp.businessobject.TravelPerDiem;
30  import org.kuali.ole.fp.document.DisbursementVoucherConstants;
31  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
32  import org.kuali.ole.fp.document.service.DisbursementVoucherCoverSheetService;
33  import org.kuali.ole.pdp.PdpPropertyConstants;
34  import org.kuali.ole.pdp.businessobject.PurchasingPaymentDetail;
35  import org.kuali.ole.sys.OLEConstants;
36  import org.kuali.ole.sys.OLEParameterKeyConstants;
37  import org.kuali.ole.sys.OLEPropertyConstants;
38  import org.kuali.ole.sys.context.SpringContext;
39  import org.kuali.ole.sys.service.UniversityDateService;
40  import org.kuali.ole.sys.service.impl.OleParameterConstants;
41  import org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase;
42  import org.kuali.rice.core.api.config.property.ConfigurationService;
43  import org.kuali.rice.core.web.format.SimpleBooleanFormatter;
44  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
45  import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
46  import org.kuali.rice.krad.service.KeyValuesService;
47  import org.kuali.rice.krad.util.KRADConstants;
48  import org.kuali.rice.krad.util.UrlFactory;
49  /**
50   * This class is the action form for the Disbursement Voucher.
51   */
52  public class DisbursementVoucherForm extends KualiAccountingDocumentFormBase {
53      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherForm.class);
54  
55      protected static final long serialVersionUID = 1L;
56  
57      protected String payeeIdNumber;
58      protected String vendorHeaderGeneratedIdentifier = StringUtils.EMPTY;
59      protected String vendorDetailAssignedIdentifier = StringUtils.EMPTY;
60      protected String vendorAddressGeneratedIdentifier;
61      
62      protected String tempPayeeIdNumber;
63      protected String tempVendorHeaderGeneratedIdentifier = StringUtils.EMPTY;
64      protected String tempVendorDetailAssignedIdentifier = StringUtils.EMPTY;
65      protected String tempVendorAddressGeneratedIdentifier;
66      protected String oldPayeeType = StringUtils.EMPTY;
67      
68      protected boolean hasMultipleAddresses = false;
69  
70      protected DisbursementVoucherNonEmployeeExpense newNonEmployeeExpenseLine;
71      protected DisbursementVoucherNonEmployeeExpense newPrePaidNonEmployeeExpenseLine;
72      protected DisbursementVoucherPreConferenceRegistrant newPreConferenceRegistrantLine;
73      protected String wireChargeMessage;
74      
75      protected boolean canExport = false;
76  
77      /**
78       * Constructs a DisbursementVoucherForm.java.
79       */
80      public DisbursementVoucherForm() {
81          super();
82          setFormatterType("canPrintCoverSheet", SimpleBooleanFormatter.class);
83      }
84  
85      @Override
86      protected String getDefaultDocumentTypeName() {
87          return "OLE_DV";
88      }
89      
90      /**
91       * @return Returns the newNonEmployeeExpenseLine.
92       */
93      public DisbursementVoucherNonEmployeeExpense getNewNonEmployeeExpenseLine() {
94          return newNonEmployeeExpenseLine;
95      }
96  
97      /**
98       * @param newNonEmployeeExpenseLine The newNonEmployeeExpenseLine to set.
99       */
100     public void setNewNonEmployeeExpenseLine(DisbursementVoucherNonEmployeeExpense newNonEmployeeExpenseLine) {
101         this.newNonEmployeeExpenseLine = newNonEmployeeExpenseLine;
102     }
103 
104     /**
105      * @return Returns the newPreConferenceRegistrantLine.
106      */
107     public DisbursementVoucherPreConferenceRegistrant getNewPreConferenceRegistrantLine() {
108         return newPreConferenceRegistrantLine;
109     }
110 
111     /**
112      * @param newPreConferenceRegistrantLine The newPreConferenceRegistrantLine to set.
113      */
114     public void setNewPreConferenceRegistrantLine(DisbursementVoucherPreConferenceRegistrant newPreConferenceRegistrantLine) {
115         this.newPreConferenceRegistrantLine = newPreConferenceRegistrantLine;
116     }
117 
118     /**
119      * @return Returns the newPrePaidNonEmployeeExpenseLine.
120      */
121     public DisbursementVoucherNonEmployeeExpense getNewPrePaidNonEmployeeExpenseLine() {
122         return newPrePaidNonEmployeeExpenseLine;
123     }
124 
125     /**
126      * @param newPrePaidNonEmployeeExpenseLine The newPrePaidNonEmployeeExpenseLine to set.
127      */
128     public void setNewPrePaidNonEmployeeExpenseLine(DisbursementVoucherNonEmployeeExpense newPrePaidNonEmployeeExpenseLine) {
129         this.newPrePaidNonEmployeeExpenseLine = newPrePaidNonEmployeeExpenseLine;
130     }
131 
132     /**
133      * @return Returns the wireChargeMessage.
134      */
135     public String getWireChargeMessage() {
136         return wireChargeMessage;
137     }
138 
139     /**
140      * @param wireChargeMessage The wireChargeMessage to set.
141      */
142     public void setWireChargeMessage(String wireChargeMessage) {
143         this.wireChargeMessage = wireChargeMessage;
144     }
145 
146     /**
147      * determines if the DV document is in a state that allows printing of the cover sheet
148      * 
149      * @return true if the DV document is in a state that allows printing of the cover sheet; otherwise, return false
150      */
151     public boolean getCanPrintCoverSheet() {
152         DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) this.getDocument();
153         return SpringContext.getBean(DisbursementVoucherCoverSheetService.class).isCoverSheetPrintable(disbursementVoucherDocument);
154     }
155 
156     /**
157      * @return a list of available travel expense type codes for rendering per diem link page.
158      */
159     public List<TravelPerDiem> getTravelPerDiemCategoryCodes() {
160         Map<String, Object> criteria = new HashMap<String, Object>();
161         criteria.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
162 
163         return (List<TravelPerDiem>) SpringContext.getBean(KeyValuesService.class).findMatching(TravelPerDiem.class, criteria);
164     }
165 
166     /**
167      * @return the per diem link message from the parameters table.
168      */
169   //Commented for the jira issue OLE-3415
170     /*public String getTravelPerDiemLinkPageMessage() {
171         return SpringContext.getBean(ParameterService.class).getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.TRAVEL_PER_DIEM_MESSAGE_PARM_NM);
172     }*/
173 
174     /**
175      * Gets the payeeIdNumber attribute.
176      * 
177      * @return Returns the payeeIdNumber.
178      */
179     public String getPayeeIdNumber() {
180         return payeeIdNumber;
181     }
182 
183     /**
184      * Sets the payeeIdNumber attribute value.
185      * 
186      * @param payeeIdNumber The payeeIdNumber to set.
187      */
188     public void setPayeeIdNumber(String payeeIdNumber) {
189         String separator = "-";
190         if (this.isVendor() && StringUtils.contains(payeeIdNumber, separator)) {
191             this.vendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, separator);
192             this.vendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, separator);
193         }
194 
195         this.payeeIdNumber = payeeIdNumber;
196     }
197     
198     /**
199      * Gets the payeeIdNumber attribute.
200      * 
201      * @return Returns the payeeIdNumber.
202      */
203     public String getTempPayeeIdNumber() {
204         return tempPayeeIdNumber;
205     }
206 
207     /**
208      * Sets the payeeIdNumber attribute value.
209      * 
210      * @param payeeIdNumber The payeeIdNumber to set.
211      */
212     public void setTempPayeeIdNumber(String payeeIdNumber) {
213         String separator = "-";
214         if (this.isVendor() && StringUtils.contains(payeeIdNumber, separator)) {
215             this.tempVendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, separator);
216             this.tempVendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, separator);
217         }
218 
219         this.tempPayeeIdNumber = payeeIdNumber;
220     }
221     
222 
223     /**
224      * Gets the hasMultipleAddresses attribute.
225      * 
226      * @return Returns the hasMultipleAddresses.
227      */
228     public boolean hasMultipleAddresses() {
229         return hasMultipleAddresses;
230     }
231 
232     /**
233      * Gets the hasMultipleAddresses attribute.
234      * 
235      * @return Returns the hasMultipleAddresses.
236      */
237     public boolean getHasMultipleAddresses() {
238         return hasMultipleAddresses;
239     }
240 
241     /**
242      * Sets the hasMultipleAddresses attribute value.
243      * 
244      * @param hasMultipleAddresses The hasMultipleAddresses to set.
245      */
246     public void setHasMultipleAddresses(boolean hasMultipleAddresses) {
247         this.hasMultipleAddresses = hasMultipleAddresses;
248     }
249 
250     /**
251      * Gets the vendorHeaderGeneratedIdentifier attribute.
252      * 
253      * @return Returns the vendorHeaderGeneratedIdentifier.
254      */
255     public String getVendorHeaderGeneratedIdentifier() {
256         return vendorHeaderGeneratedIdentifier;
257     }
258 
259     /**
260      * Sets the vendorHeaderGeneratedIdentifier attribute value.
261      * 
262      * @param vendorHeaderGeneratedIdentifier The vendorHeaderGeneratedIdentifier to set.
263      */
264     public void setVendorHeaderGeneratedIdentifier(String vendorHeaderGeneratedIdentifier) {
265         this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
266     }
267 
268     /**
269      * Gets the vendorDetailAssignedIdentifier attribute.
270      * 
271      * @return Returns the vendorDetailAssignedIdentifier.
272      */
273     public String getVendorDetailAssignedIdentifier() {
274         return vendorDetailAssignedIdentifier;
275     }
276 
277     /**
278      * Sets the vendorDetailAssignedIdentifier attribute value.
279      * 
280      * @param vendorDetailAssignedIdentifier The vendorDetailAssignedIdentifier to set.
281      */
282     public void setVendorDetailAssignedIdentifier(String vendorDetailAssignedIdentifier) {
283         this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
284     }
285 
286     /**
287      * Gets the vendorAddressGeneratedIdentifier attribute.
288      * 
289      * @return Returns the vendorAddressGeneratedIdentifier.
290      */
291     public String getVendorAddressGeneratedIdentifier() {
292         return vendorAddressGeneratedIdentifier;
293     }
294 
295     /**
296      * Sets the vendorAddressGeneratedIdentifier attribute value.
297      * 
298      * @param vendorAddressGeneratedIdentifier The vendorAddressGeneratedIdentifier to set.
299      */
300     public void setVendorAddressGeneratedIdentifier(String vendorAddressGeneratedIdentifier) {
301         this.vendorAddressGeneratedIdentifier = vendorAddressGeneratedIdentifier;
302     }
303     
304     public DisbursementVoucherDocument getDisbursementVoucherDocument() {
305        return (DisbursementVoucherDocument) getDocument();
306      
307        }
308     /** 
309      * @see org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
310      */
311     @Override
312     public void populate(HttpServletRequest request) {
313         super.populate(request);
314         DisbursementVoucherPayeeDetail payeeDetail = getDisbursementVoucherDocument().getDvPayeeDetail();
315         SpringContext.getBean(BusinessObjectDictionaryService.class).performForceUppercase(payeeDetail);
316         }
317    
318 
319     
320 
321     /**
322      * Gets the tempVendorHeaderGeneratedIdentifier attribute. 
323      * @return Returns the tempVendorHeaderGeneratedIdentifier.
324      */
325     public String getTempVendorHeaderGeneratedIdentifier() {
326         return tempVendorHeaderGeneratedIdentifier;
327     }
328 
329     /**
330      * Sets the tempVendorHeaderGeneratedIdentifier attribute value.
331      * @param tempVendorHeaderGeneratedIdentifier The tempVendorHeaderGeneratedIdentifier to set.
332      */
333     public void setTempVendorHeaderGeneratedIdentifier(String tempVendorHeaderGeneratedIdentifier) {
334         this.tempVendorHeaderGeneratedIdentifier = tempVendorHeaderGeneratedIdentifier;
335     }
336 
337     /**
338      * Gets the tempVendorDetailAssignedIdentifier attribute. 
339      * @return Returns the tempVendorDetailAssignedIdentifier.
340      */
341     public String getTempVendorDetailAssignedIdentifier() {
342         return tempVendorDetailAssignedIdentifier;
343     }
344 
345     /**
346      * Sets the tempVendorDetailAssignedIdentifier attribute value.
347      * @param tempVendorDetailAssignedIdentifier The tempVendorDetailAssignedIdentifier to set.
348      */
349     public void setTempVendorDetailAssignedIdentifier(String tempVendorDetailAssignedIdentifier) {
350         this.tempVendorDetailAssignedIdentifier = tempVendorDetailAssignedIdentifier;
351     }
352 
353     /**
354      * Gets the tempVendorAddressGeneratedIdentifier attribute. 
355      * @return Returns the tempVendorAddressGeneratedIdentifier.
356      */
357     public String getTempVendorAddressGeneratedIdentifier() {
358         return tempVendorAddressGeneratedIdentifier;
359     }
360 
361     /**
362      * Sets the tempVendorAddressGeneratedIdentifier attribute value.
363      * @param tempVendorAddressGeneratedIdentifier The tempVendorAddressGeneratedIdentifier to set.
364      */
365     public void setTempVendorAddressGeneratedIdentifier(String tempVendorAddressGeneratedIdentifier) {
366         this.tempVendorAddressGeneratedIdentifier = tempVendorAddressGeneratedIdentifier;
367     }
368     
369     
370 
371     /**
372      * Gets the oldPayeeType attribute. 
373      * @return Returns the oldPayeeType.
374      */
375     public String getOldPayeeType() {
376         return oldPayeeType;
377     }
378 
379     /**
380      * Sets the oldPayeeType attribute value.
381      * @param oldPayeeType The oldPayeeType to set.
382      */
383     public void setOldPayeeType(String oldPayeeType) {
384         this.oldPayeeType = oldPayeeType;
385     }
386 
387     /**
388      * determine whether the selected payee is an employee
389      */
390     public boolean isEmployee() {
391         DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) this.getDocument();
392         return disbursementVoucherDocument.getDvPayeeDetail().isEmployee();
393     }
394 
395     /**
396      * determine whether the selected payee is a vendor
397      */
398     public boolean isVendor() {
399         DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) this.getDocument();
400         return disbursementVoucherDocument.getDvPayeeDetail().isVendor();
401     }
402 
403     /**
404      * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String,
405      *      java.lang.String, javax.servlet.http.HttpServletRequest)
406      */
407     @Override
408     public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
409         if (StringUtils.equals(methodToCallParameterName, KRADConstants.DISPATCH_REQUEST_PARAMETER)) {
410             if (this.getExcludedmethodToCall().contains(methodToCallParameterValue)) {
411                 return true;
412             }
413         }
414         return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
415     }
416 
417     /**
418      * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase#getExcludedmethodToCall()
419      */
420     protected List<String> getExcludedmethodToCall() {
421         List<String> execludedMethodToCall = super.getExcludedmethodToCall();
422         execludedMethodToCall.add("printDisbursementVoucherCoverSheet");
423         execludedMethodToCall.add("showTravelPerDiemLinks");
424 
425         return execludedMethodToCall;
426     }
427     
428     /**
429      * Gets the canExport attribute. 
430      * @return Returns the canExport.
431      */
432     public boolean isCanExport() {
433         return canExport;
434     }
435 
436     /**
437      * Sets the canExport attribute value.
438      * @param canExport The canExport to set.
439      */
440     public void setCanExport(boolean canExport) {
441         this.canExport = canExport;
442     }
443     
444    //MSU Contribution AER:RQ_AP_0760 OLEMI-8876 OLECNTRB-980 
445     /**
446      * RQ_AP_0760 : Ability to view disbursement information on the
447      * Disbursement Voucher Document.
448      * 
449      * This method composes the url to be used when we want to look up
450      * the payment details from the disbursementInfo.tag.
451      * 
452      * @return
453      */
454     public String getDisbursementInfoUrl() {
455         String basePath = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.APPLICATION_URL_KEY);
456         ParameterService parameterService = SpringContext.getBean(ParameterService.class);
457 
458         String orgCode = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_ORG_CODE);
459 
460         Properties parameters = new Properties();
461         parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.SEARCH_METHOD);
462         parameters.put(OLEConstants.BACK_LOCATION, basePath + "/" + OLEConstants.MAPPING_PORTAL + ".do");
463         parameters.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, PurchasingPaymentDetail.class.getName());
464         parameters.put(OLEConstants.HIDE_LOOKUP_RETURN_LINK, "true");
465         parameters.put(OLEConstants.SUPPRESS_ACTIONS, "false");
466         parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_UNIT_CODE, orgCode);
467 
468         String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + OLEConstants.LOOKUP_ACTION, parameters);
469 
470         return lookupUrl;
471     }
472 }