001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.fp.document.web.struts;
017    
018    import java.util.HashMap;
019    import java.util.List;
020    import java.util.Map;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    import org.apache.commons.beanutils.PropertyUtils;
025    import org.apache.commons.lang.StringUtils;
026    import org.apache.struts.action.ActionMapping;
027    import org.kuali.kfs.fp.businessobject.DisbursementVoucherNonEmployeeExpense;
028    import org.kuali.kfs.fp.businessobject.DisbursementVoucherPreConferenceRegistrant;
029    import org.kuali.kfs.fp.businessobject.TravelPerDiem;
030    import org.kuali.kfs.fp.document.DisbursementVoucherConstants;
031    import org.kuali.kfs.fp.document.DisbursementVoucherDocument;
032    import org.kuali.kfs.fp.document.service.DisbursementVoucherCoverSheetService;
033    import org.kuali.kfs.sys.KFSPropertyConstants;
034    import org.kuali.kfs.sys.context.SpringContext;
035    import org.kuali.kfs.sys.service.UniversityDateService;
036    import org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase;
037    import org.kuali.rice.kns.service.KeyValuesService;
038    import org.kuali.rice.kns.service.ParameterService;
039    import org.kuali.rice.kns.util.KNSConstants;
040    import org.kuali.rice.kns.web.format.SimpleBooleanFormatter;
041    
042    /**
043     * This class is the action form for the Disbursement Voucher.
044     */
045    public class DisbursementVoucherForm extends KualiAccountingDocumentFormBase {
046        protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherForm.class);
047    
048        protected static final long serialVersionUID = 1L;
049    
050        protected String payeeIdNumber;
051        protected String vendorHeaderGeneratedIdentifier = StringUtils.EMPTY;
052        protected String vendorDetailAssignedIdentifier = StringUtils.EMPTY;
053        protected String vendorAddressGeneratedIdentifier;
054        
055        protected String tempPayeeIdNumber;
056        protected String tempVendorHeaderGeneratedIdentifier = StringUtils.EMPTY;
057        protected String tempVendorDetailAssignedIdentifier = StringUtils.EMPTY;
058        protected String tempVendorAddressGeneratedIdentifier;
059        protected String oldPayeeType = StringUtils.EMPTY;
060        
061        protected boolean hasMultipleAddresses = false;
062    
063        protected DisbursementVoucherNonEmployeeExpense newNonEmployeeExpenseLine;
064        protected DisbursementVoucherNonEmployeeExpense newPrePaidNonEmployeeExpenseLine;
065        protected DisbursementVoucherPreConferenceRegistrant newPreConferenceRegistrantLine;
066        protected String wireChargeMessage;
067        
068        protected boolean canExport = false;
069    
070        /**
071         * Constructs a DisbursementVoucherForm.java.
072         */
073        public DisbursementVoucherForm() {
074            super();
075            setFormatterType("canPrintCoverSheet", SimpleBooleanFormatter.class);
076        }
077    
078        @Override
079        protected String getDefaultDocumentTypeName() {
080            return "DV";
081        }
082        
083        /**
084         * @return Returns the newNonEmployeeExpenseLine.
085         */
086        public DisbursementVoucherNonEmployeeExpense getNewNonEmployeeExpenseLine() {
087            return newNonEmployeeExpenseLine;
088        }
089    
090        /**
091         * @param newNonEmployeeExpenseLine The newNonEmployeeExpenseLine to set.
092         */
093        public void setNewNonEmployeeExpenseLine(DisbursementVoucherNonEmployeeExpense newNonEmployeeExpenseLine) {
094            this.newNonEmployeeExpenseLine = newNonEmployeeExpenseLine;
095        }
096    
097        /**
098         * @return Returns the newPreConferenceRegistrantLine.
099         */
100        public DisbursementVoucherPreConferenceRegistrant getNewPreConferenceRegistrantLine() {
101            return newPreConferenceRegistrantLine;
102        }
103    
104        /**
105         * @param newPreConferenceRegistrantLine The newPreConferenceRegistrantLine to set.
106         */
107        public void setNewPreConferenceRegistrantLine(DisbursementVoucherPreConferenceRegistrant newPreConferenceRegistrantLine) {
108            this.newPreConferenceRegistrantLine = newPreConferenceRegistrantLine;
109        }
110    
111        /**
112         * @return Returns the newPrePaidNonEmployeeExpenseLine.
113         */
114        public DisbursementVoucherNonEmployeeExpense getNewPrePaidNonEmployeeExpenseLine() {
115            return newPrePaidNonEmployeeExpenseLine;
116        }
117    
118        /**
119         * @param newPrePaidNonEmployeeExpenseLine The newPrePaidNonEmployeeExpenseLine to set.
120         */
121        public void setNewPrePaidNonEmployeeExpenseLine(DisbursementVoucherNonEmployeeExpense newPrePaidNonEmployeeExpenseLine) {
122            this.newPrePaidNonEmployeeExpenseLine = newPrePaidNonEmployeeExpenseLine;
123        }
124    
125        /**
126         * @return Returns the wireChargeMessage.
127         */
128        public String getWireChargeMessage() {
129            return wireChargeMessage;
130        }
131    
132        /**
133         * @param wireChargeMessage The wireChargeMessage to set.
134         */
135        public void setWireChargeMessage(String wireChargeMessage) {
136            this.wireChargeMessage = wireChargeMessage;
137        }
138    
139        /**
140         * determines if the DV document is in a state that allows printing of the cover sheet
141         * 
142         * @return true if the DV document is in a state that allows printing of the cover sheet; otherwise, return false
143         */
144        public boolean getCanPrintCoverSheet() {
145            DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) this.getDocument();
146            return SpringContext.getBean(DisbursementVoucherCoverSheetService.class).isCoverSheetPrintable(disbursementVoucherDocument);
147        }
148    
149        /**
150         * @return a list of available travel expense type codes for rendering per diem link page.
151         */
152        public List<TravelPerDiem> getTravelPerDiemCategoryCodes() {
153            Map<String, Object> criteria = new HashMap<String, Object>();
154            criteria.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
155    
156            return (List<TravelPerDiem>) SpringContext.getBean(KeyValuesService.class).findMatching(TravelPerDiem.class, criteria);
157        }
158    
159        /**
160         * @return the per diem link message from the parameters table.
161         */
162        public String getTravelPerDiemLinkPageMessage() {
163            return SpringContext.getBean(ParameterService.class).getParameterValue(DisbursementVoucherDocument.class, DisbursementVoucherConstants.TRAVEL_PER_DIEM_MESSAGE_PARM_NM);
164        }
165    
166        /**
167         * Gets the payeeIdNumber attribute.
168         * 
169         * @return Returns the payeeIdNumber.
170         */
171        public String getPayeeIdNumber() {
172            return payeeIdNumber;
173        }
174    
175        /**
176         * Sets the payeeIdNumber attribute value.
177         * 
178         * @param payeeIdNumber The payeeIdNumber to set.
179         */
180        public void setPayeeIdNumber(String payeeIdNumber) {
181            String separator = "-";
182            if (this.isVendor() && StringUtils.contains(payeeIdNumber, separator)) {
183                this.vendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, separator);
184                this.vendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, separator);
185            }
186    
187            this.payeeIdNumber = payeeIdNumber;
188        }
189        
190        /**
191         * Gets the payeeIdNumber attribute.
192         * 
193         * @return Returns the payeeIdNumber.
194         */
195        public String getTempPayeeIdNumber() {
196            return tempPayeeIdNumber;
197        }
198    
199        /**
200         * Sets the payeeIdNumber attribute value.
201         * 
202         * @param payeeIdNumber The payeeIdNumber to set.
203         */
204        public void setTempPayeeIdNumber(String payeeIdNumber) {
205            String separator = "-";
206            if (this.isVendor() && StringUtils.contains(payeeIdNumber, separator)) {
207                this.tempVendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, separator);
208                this.tempVendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, separator);
209            }
210    
211            this.tempPayeeIdNumber = payeeIdNumber;
212        }
213        
214    
215        /**
216         * Gets the hasMultipleAddresses attribute.
217         * 
218         * @return Returns the hasMultipleAddresses.
219         */
220        public boolean hasMultipleAddresses() {
221            return hasMultipleAddresses;
222        }
223    
224        /**
225         * Gets the hasMultipleAddresses attribute.
226         * 
227         * @return Returns the hasMultipleAddresses.
228         */
229        public boolean getHasMultipleAddresses() {
230            return hasMultipleAddresses;
231        }
232    
233        /**
234         * Sets the hasMultipleAddresses attribute value.
235         * 
236         * @param hasMultipleAddresses The hasMultipleAddresses to set.
237         */
238        public void setHasMultipleAddresses(boolean hasMultipleAddresses) {
239            this.hasMultipleAddresses = hasMultipleAddresses;
240        }
241    
242        /**
243         * Gets the vendorHeaderGeneratedIdentifier attribute.
244         * 
245         * @return Returns the vendorHeaderGeneratedIdentifier.
246         */
247        public String getVendorHeaderGeneratedIdentifier() {
248            return vendorHeaderGeneratedIdentifier;
249        }
250    
251        /**
252         * Sets the vendorHeaderGeneratedIdentifier attribute value.
253         * 
254         * @param vendorHeaderGeneratedIdentifier The vendorHeaderGeneratedIdentifier to set.
255         */
256        public void setVendorHeaderGeneratedIdentifier(String vendorHeaderGeneratedIdentifier) {
257            this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
258        }
259    
260        /**
261         * Gets the vendorDetailAssignedIdentifier attribute.
262         * 
263         * @return Returns the vendorDetailAssignedIdentifier.
264         */
265        public String getVendorDetailAssignedIdentifier() {
266            return vendorDetailAssignedIdentifier;
267        }
268    
269        /**
270         * Sets the vendorDetailAssignedIdentifier attribute value.
271         * 
272         * @param vendorDetailAssignedIdentifier The vendorDetailAssignedIdentifier to set.
273         */
274        public void setVendorDetailAssignedIdentifier(String vendorDetailAssignedIdentifier) {
275            this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
276        }
277    
278        /**
279         * Gets the vendorAddressGeneratedIdentifier attribute.
280         * 
281         * @return Returns the vendorAddressGeneratedIdentifier.
282         */
283        public String getVendorAddressGeneratedIdentifier() {
284            return vendorAddressGeneratedIdentifier;
285        }
286    
287        /**
288         * Sets the vendorAddressGeneratedIdentifier attribute value.
289         * 
290         * @param vendorAddressGeneratedIdentifier The vendorAddressGeneratedIdentifier to set.
291         */
292        public void setVendorAddressGeneratedIdentifier(String vendorAddressGeneratedIdentifier) {
293            this.vendorAddressGeneratedIdentifier = vendorAddressGeneratedIdentifier;
294        }
295        
296        
297    
298        /**
299         * Gets the tempVendorHeaderGeneratedIdentifier attribute. 
300         * @return Returns the tempVendorHeaderGeneratedIdentifier.
301         */
302        public String getTempVendorHeaderGeneratedIdentifier() {
303            return tempVendorHeaderGeneratedIdentifier;
304        }
305    
306        /**
307         * Sets the tempVendorHeaderGeneratedIdentifier attribute value.
308         * @param tempVendorHeaderGeneratedIdentifier The tempVendorHeaderGeneratedIdentifier to set.
309         */
310        public void setTempVendorHeaderGeneratedIdentifier(String tempVendorHeaderGeneratedIdentifier) {
311            this.tempVendorHeaderGeneratedIdentifier = tempVendorHeaderGeneratedIdentifier;
312        }
313    
314        /**
315         * Gets the tempVendorDetailAssignedIdentifier attribute. 
316         * @return Returns the tempVendorDetailAssignedIdentifier.
317         */
318        public String getTempVendorDetailAssignedIdentifier() {
319            return tempVendorDetailAssignedIdentifier;
320        }
321    
322        /**
323         * Sets the tempVendorDetailAssignedIdentifier attribute value.
324         * @param tempVendorDetailAssignedIdentifier The tempVendorDetailAssignedIdentifier to set.
325         */
326        public void setTempVendorDetailAssignedIdentifier(String tempVendorDetailAssignedIdentifier) {
327            this.tempVendorDetailAssignedIdentifier = tempVendorDetailAssignedIdentifier;
328        }
329    
330        /**
331         * Gets the tempVendorAddressGeneratedIdentifier attribute. 
332         * @return Returns the tempVendorAddressGeneratedIdentifier.
333         */
334        public String getTempVendorAddressGeneratedIdentifier() {
335            return tempVendorAddressGeneratedIdentifier;
336        }
337    
338        /**
339         * Sets the tempVendorAddressGeneratedIdentifier attribute value.
340         * @param tempVendorAddressGeneratedIdentifier The tempVendorAddressGeneratedIdentifier to set.
341         */
342        public void setTempVendorAddressGeneratedIdentifier(String tempVendorAddressGeneratedIdentifier) {
343            this.tempVendorAddressGeneratedIdentifier = tempVendorAddressGeneratedIdentifier;
344        }
345        
346        
347    
348        /**
349         * Gets the oldPayeeType attribute. 
350         * @return Returns the oldPayeeType.
351         */
352        public String getOldPayeeType() {
353            return oldPayeeType;
354        }
355    
356        /**
357         * Sets the oldPayeeType attribute value.
358         * @param oldPayeeType The oldPayeeType to set.
359         */
360        public void setOldPayeeType(String oldPayeeType) {
361            this.oldPayeeType = oldPayeeType;
362        }
363    
364        /**
365         * determine whether the selected payee is an employee
366         */
367        public boolean isEmployee() {
368            DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) this.getDocument();
369            return disbursementVoucherDocument.getDvPayeeDetail().isEmployee();
370        }
371    
372        /**
373         * determine whether the selected payee is a vendor
374         */
375        public boolean isVendor() {
376            DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) this.getDocument();
377            return disbursementVoucherDocument.getDvPayeeDetail().isVendor();
378        }
379    
380        /**
381         * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String,
382         *      java.lang.String, javax.servlet.http.HttpServletRequest)
383         */
384        @Override
385        public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
386            if (StringUtils.equals(methodToCallParameterName, KNSConstants.DISPATCH_REQUEST_PARAMETER)) {
387                if (this.getExcludedmethodToCall().contains(methodToCallParameterValue)) {
388                    return true;
389                }
390            }
391            return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
392        }
393    
394        /**
395         * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase#getExcludedmethodToCall()
396         */
397        protected List<String> getExcludedmethodToCall() {
398            List<String> execludedMethodToCall = super.getExcludedmethodToCall();
399            execludedMethodToCall.add("printDisbursementVoucherCoverSheet");
400            execludedMethodToCall.add("showTravelPerDiemLinks");
401    
402            return execludedMethodToCall;
403        }
404        
405        /**
406         * Gets the canExport attribute. 
407         * @return Returns the canExport.
408         */
409        public boolean isCanExport() {
410            return canExport;
411        }
412    
413        /**
414         * Sets the canExport attribute value.
415         * @param canExport The canExport to set.
416         */
417        public void setCanExport(boolean canExport) {
418            this.canExport = canExport;
419        }
420    }