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    
017    package org.kuali.kfs.fp.businessobject;
018    
019    import java.text.MessageFormat;
020    import java.util.HashMap;
021    import java.util.LinkedHashMap;
022    import java.util.Map;
023    
024    import org.apache.commons.lang.StringUtils;
025    import org.kuali.kfs.fp.document.DisbursementVoucherConstants;
026    import org.kuali.kfs.fp.document.service.DisbursementVoucherPayeeService;
027    import org.kuali.kfs.sys.KFSConstants;
028    import org.kuali.kfs.sys.KFSPropertyConstants;
029    import org.kuali.kfs.sys.context.SpringContext;
030    import org.kuali.kfs.vnd.VendorConstants;
031    import org.kuali.kfs.vnd.VendorPropertyConstants;
032    import org.kuali.kfs.vnd.businessobject.VendorDetail;
033    import org.kuali.rice.kim.bo.Person;
034    import org.kuali.rice.kim.util.KIMPropertyConstants;
035    import org.kuali.rice.kns.bo.Inactivateable;
036    import org.kuali.rice.kns.bo.TransientBusinessObjectBase;
037    import org.kuali.rice.kns.util.KNSPropertyConstants;
038    
039    public class DisbursementPayee extends TransientBusinessObjectBase implements Inactivateable {
040        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementPayee.class);
041    
042        private String payeeIdNumber;
043        private String payeeTypeCode;
044        private String payeeTypeDescription;
045        private String payeeName;
046    
047        private String paymentReasonCode;
048        private String taxNumber;
049        private String employeeId;
050        private String firstName;
051        private String lastName;
052        private String vendorName;
053        private String vendorNumber;
054        private String address;
055        private boolean active;
056        
057        private String principalId;
058        
059        public final static String addressPattern = "{0}, {1}, {2} {3}";
060    
061        /**
062         * Constructs a DisbursementPayee.java.
063         */
064        public DisbursementPayee() {
065            super();
066        }
067    
068        /**
069         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
070         */
071        @Override
072        protected LinkedHashMap toStringMapper() {
073            LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
074            map.put(KFSPropertyConstants.PAYEE_ID_NUMBER, this.payeeIdNumber);
075            map.put(KFSPropertyConstants.PAYEE_TYPE_CODE, this.payeeTypeCode);
076            map.put(KFSPropertyConstants.PAYEE_NAME, this.payeeName);
077    
078            return map;
079        }
080    
081        /**
082         * convert the field names between Payee and Vendor
083         * 
084         * @return a field name map of Payee and Vendor. The map key is a field name of Payee, and its value is a field name of Vendor
085         */
086        public static Map<String, String> getFieldConversionBetweenPayeeAndVendor() {
087            Map<String, String> fieldConversionMap = new HashMap<String, String>();
088    
089            fieldConversionMap.put(KFSPropertyConstants.TAX_NUMBER, VendorPropertyConstants.VENDOR_TAX_NUMBER);
090    
091            fieldConversionMap.put(KFSPropertyConstants.VENDOR_NAME, KFSPropertyConstants.VENDOR_NAME);
092            fieldConversionMap.put(KFSPropertyConstants.VENDOR_NUMBER, KFSPropertyConstants.VENDOR_NUMBER);
093    
094            fieldConversionMap.put(KFSPropertyConstants.PERSON_FIRST_NAME, VendorPropertyConstants.VENDOR_FIRST_NAME);
095            fieldConversionMap.put(KFSPropertyConstants.PERSON_LAST_NAME, VendorPropertyConstants.VENDOR_LAST_NAME);
096    
097            fieldConversionMap.put(KNSPropertyConstants.ACTIVE, KFSPropertyConstants.ACTIVE_INDICATOR);
098    
099            return fieldConversionMap;
100        }
101    
102        /**
103         * convert the field names between Payee and Person
104         * 
105         * @return a field name map of Payee and Person. The map key is a field name of Payee, and its value is a field name of Person
106         */
107        public static Map<String, String> getFieldConversionBetweenPayeeAndPerson() {
108            Map<String, String> fieldConversionMap = new HashMap<String, String>();
109    
110        //    fieldConversionMap.put(KFSPropertyConstants.TAX_NUMBER, KIMPropertyConstants.Person.EXTERNAL_ID);
111    
112            fieldConversionMap.put(KFSPropertyConstants.PERSON_FIRST_NAME, KIMPropertyConstants.Person.FIRST_NAME);
113            fieldConversionMap.put(KFSPropertyConstants.PERSON_LAST_NAME, KIMPropertyConstants.Person.LAST_NAME);
114    
115            fieldConversionMap.put(KFSPropertyConstants.EMPLOYEE_ID, KIMPropertyConstants.Person.EMPLOYEE_ID);
116            fieldConversionMap.put(KNSPropertyConstants.ACTIVE, KNSPropertyConstants.ACTIVE);
117    
118            return fieldConversionMap;
119        }
120    
121        /**
122         * build a payee object from the given vendor object
123         * 
124         * @param vendorDetail the given vendor object
125         * @return a payee object built from the given vendor object
126         */
127        public static DisbursementPayee getPayeeFromVendor(VendorDetail vendorDetail) {
128            DisbursementPayee disbursementPayee = new DisbursementPayee();
129    
130            disbursementPayee.setActive(vendorDetail.isActiveIndicator());
131    
132            disbursementPayee.setPayeeIdNumber(vendorDetail.getVendorNumber());
133            disbursementPayee.setPayeeName(vendorDetail.getAltVendorName());
134            disbursementPayee.setTaxNumber(vendorDetail.getVendorHeader().getVendorTaxNumber());
135    
136            String vendorTypeCode = vendorDetail.getVendorHeader().getVendorTypeCode();
137            String payeeTypeCode = getVendorPayeeTypeCodeMapping().get(vendorTypeCode);
138            disbursementPayee.setPayeeTypeCode(payeeTypeCode);
139    
140            String vendorAddress = MessageFormat.format(addressPattern, vendorDetail.getDefaultAddressLine1(), vendorDetail.getDefaultAddressCity(), vendorDetail.getDefaultAddressStateCode(), vendorDetail.getDefaultAddressCountryCode());
141            disbursementPayee.setAddress(vendorAddress);
142    
143            return disbursementPayee;
144        }
145    
146        /**
147         * build a payee object from the given person object
148         * 
149         * @param person the given person object
150         * @return a payee object built from the given person object
151         */
152        public static DisbursementPayee getPayeeFromPerson(Person person) {
153            DisbursementPayee disbursementPayee = new DisbursementPayee();
154    
155            disbursementPayee.setActive(person.isActive());
156    
157            disbursementPayee.setPayeeIdNumber(person.getEmployeeId());
158            disbursementPayee.setPrincipalId(person.getPrincipalId());
159            
160            disbursementPayee.setPayeeName(person.getName());
161            disbursementPayee.setTaxNumber(KFSConstants.BLANK_SPACE);
162            
163            disbursementPayee.setPayeeTypeCode(DisbursementVoucherConstants.DV_PAYEE_TYPE_EMPLOYEE);
164    
165            String personAddress = MessageFormat.format(addressPattern, person.getAddressLine1(), person.getAddressCityName(), person.getAddressStateCode(), person.getAddressCountryCode());
166            disbursementPayee.setAddress(personAddress);
167    
168            return disbursementPayee;
169        }
170    
171        /**
172         * Gets the payeeIdNumber attribute.
173         * 
174         * @return Returns the payeeIdNumber.
175         */
176        public String getPayeeIdNumber() {
177            return payeeIdNumber;
178        }
179    
180        /**
181         * Sets the payeeIdNumber attribute value.
182         * 
183         * @param payeeIdNumber The payeeIdNumber to set.
184         */
185        public void setPayeeIdNumber(String payeeIdNumber) {
186            this.payeeIdNumber = payeeIdNumber;
187        }
188    
189        /**
190         * Gets the payeeTypeCode attribute.
191         * 
192         * @return Returns the payeeTypeCode.
193         */
194        public String getPayeeTypeCode() {
195            return payeeTypeCode;
196        }
197    
198        /**
199         * Sets the payeeTypeCode attribute value.
200         * 
201         * @param payeeTypeCode The payeeTypeCode to set.
202         */
203        public void setPayeeTypeCode(String payeeTypeCode) {
204            this.payeeTypeCode = payeeTypeCode;
205        }
206    
207        /**
208         * Gets the payeeName attribute.
209         * 
210         * @return Returns the payeeName.
211         */
212        public String getPayeeName() {
213            return payeeName;
214        }
215    
216        /**
217         * Sets the payeeName attribute value.
218         * 
219         * @param payeeName The payeeName to set.
220         */
221        public void setPayeeName(String payeeName) {
222            this.payeeName = payeeName;
223        }
224    
225        /**
226         * Gets the paymentReasonCode attribute.
227         * 
228         * @return Returns the paymentReasonCode.
229         */
230        public String getPaymentReasonCode() {
231            return paymentReasonCode;
232        }
233    
234        /**
235         * Sets the paymentReasonCode attribute value.
236         * 
237         * @param paymentReasonCode The paymentReasonCode to set.
238         */
239        public void setPaymentReasonCode(String paymentReasonCode) {
240            this.paymentReasonCode = paymentReasonCode;
241        }
242    
243        /**
244         * Gets the taxNumber attribute.
245         * 
246         * @return Returns the taxNumber.
247         */
248        public String getTaxNumber() {
249            return taxNumber;
250        }
251    
252        /**
253         * Sets the taxNumber attribute value.
254         * 
255         * @param taxNumber The taxNumber to set.
256         */
257        public void setTaxNumber(String taxNumber) {
258            this.taxNumber = taxNumber;
259        }
260    
261        /**
262         * Gets the employeeId attribute.
263         * 
264         * @return Returns the employeeId.
265         */
266        public String getEmployeeId() {
267            return employeeId;
268        }
269    
270        /**
271         * Sets the employeeId attribute value.
272         * 
273         * @param employeeId The employeeId to set.
274         */
275        public void setEmployeeId(String employeeId) {
276            this.employeeId = employeeId;
277        }
278    
279        /**
280         * Gets the vendorName attribute.
281         * 
282         * @return Returns the vendorName.
283         */
284        public String getVendorName() {
285            return vendorName;
286        }
287    
288        /**
289         * Sets the vendorName attribute value.
290         * 
291         * @param vendorName The vendorName to set.
292         */
293        public void setVendorName(String vendorName) {
294            this.vendorName = vendorName;
295        }
296    
297        /**
298         * Gets the address attribute.
299         * 
300         * @return Returns the address.
301         */
302        public String getAddress() {
303            return address;
304        }
305    
306        /**
307         * Sets the address attribute value.
308         * 
309         * @param address The address to set.
310         */
311        public void setAddress(String address) {
312            this.address = address;
313        }
314    
315        /**
316         * Gets the vendorNumber attribute.
317         * 
318         * @return Returns the vendorNumber.
319         */
320        public String getVendorNumber() {
321            return vendorNumber;
322        }
323    
324        /**
325         * Sets the vendorNumber attribute value.
326         * 
327         * @param vendorNumber The vendorNumber to set.
328         */
329        public void setVendorNumber(String vendorNumber) {
330            this.vendorNumber = vendorNumber;
331        }
332    
333        /**
334         * Gets the active attribute.
335         * 
336         * @return Returns the active.
337         */
338        public boolean isActive() {
339            return active;
340        }
341    
342        /**
343         * Sets the active attribute value.
344         * 
345         * @param active The active to set.
346         */
347        public void setActive(boolean active) {
348            this.active = active;
349        }
350    
351        /**
352         * Gets the firstName attribute.
353         * 
354         * @return Returns the firstName.
355         */
356        public String getFirstName() {
357            return firstName;
358        }
359    
360        /**
361         * Sets the firstName attribute value.
362         * 
363         * @param firstName The firstName to set.
364         */
365        public void setFirstName(String firstName) {
366            this.firstName = firstName;
367        }
368    
369        /**
370         * Gets the lastName attribute.
371         * 
372         * @return Returns the lastName.
373         */
374        public String getLastName() {
375            return lastName;
376        }
377    
378        /**
379         * Sets the lastName attribute value.
380         * 
381         * @param lastName The lastName to set.
382         */
383        public void setLastName(String lastName) {
384            this.lastName = lastName;
385        }
386    
387        /**
388         * Gets the payeeTypeDescription attribute.
389         * 
390         * @return Returns the payeeTypeDescription.
391         */
392        public String getPayeeTypeDescription() {
393            DisbursementVoucherPayeeService payeeService = SpringContext.getBean(DisbursementVoucherPayeeService.class);
394            
395            return payeeService.getPayeeTypeDescription(payeeTypeCode);
396        }
397    
398        /**
399         * Sets the payeeTypeDescription attribute value.
400         * 
401         * @param payeeTypeDescription The payeeTypeDescription to set.
402         */
403        public void setPayeeTypeDescription(String payeeTypeDescription) {
404            this.payeeTypeDescription = payeeTypeDescription;
405        }
406    
407        /**
408         * Gets the principalId attribute. 
409         * @return Returns the principalId.
410         */
411        public String getPrincipalId() {
412            return principalId;
413        }
414    
415        /**
416         * Sets the principalId attribute value.
417         * @param principalId The principalId to set.
418         */
419        public void setPrincipalId(String principalId) {
420            this.principalId = principalId;
421        }
422    
423        // do mapping between vendor type code and payee type code 
424        private static Map<String, String> getVendorPayeeTypeCodeMapping() {
425            Map<String, String> payeeVendorTypeCodeMapping = new HashMap<String, String>();
426    
427            payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.PURCHASE_ORDER, DisbursementVoucherConstants.DV_PAYEE_TYPE_VENDOR);
428            payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.DISBURSEMENT_VOUCHER, DisbursementVoucherConstants.DV_PAYEE_TYPE_VENDOR);
429            payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.REVOLVING_FUND, DisbursementVoucherConstants.DV_PAYEE_TYPE_REVOLVING_FUND_VENDOR);
430            payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.SUBJECT_PAYMENT, DisbursementVoucherConstants.DV_PAYEE_TYPE_SUBJECT_PAYMENT_VENDOR);
431    
432            return payeeVendorTypeCodeMapping;
433        }
434    }