View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package org.kuali.kfs.fp.businessobject;
21  
22  import java.text.MessageFormat;
23  import java.util.HashMap;
24  import java.util.LinkedHashMap;
25  import java.util.Map;
26  
27  import org.kuali.kfs.fp.document.service.DisbursementVoucherPayeeService;
28  import org.kuali.kfs.integration.ar.AccountsReceivableCustomer;
29  import org.kuali.kfs.sys.KFSConstants;
30  import org.kuali.kfs.sys.KFSPropertyConstants;
31  import org.kuali.kfs.sys.context.SpringContext;
32  import org.kuali.kfs.vnd.VendorConstants;
33  import org.kuali.kfs.vnd.VendorPropertyConstants;
34  import org.kuali.kfs.vnd.businessobject.VendorDetail;
35  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
36  import org.kuali.rice.kim.api.identity.Person;
37  import org.kuali.rice.kim.impl.KIMPropertyConstants;
38  import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
39  
40  public class DisbursementPayee extends TransientBusinessObjectBase implements MutableInactivatable {
41      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementPayee.class);
42  
43      private String payeeIdNumber;
44      private String payeeTypeCode;
45      private String payeeTypeDescription;
46      private String payeeName;
47  
48      private String paymentReasonCode;
49      private String taxNumber;
50      private String employeeId;
51      private String firstName;
52      private String lastName;
53      private String vendorName;
54      private String vendorNumber;
55      private String address;
56      private boolean active;
57  
58      private String principalId;
59  
60      public final static String addressPattern = "{0}, {1}, {2} {3}";
61  
62      /**
63       * Constructs a DisbursementPayee.java.
64       */
65      public DisbursementPayee() {
66          super();
67      }
68  
69      /**
70       * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
71       */
72  
73      protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
74          LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
75          map.put(KFSPropertyConstants.PAYEE_ID_NUMBER, this.payeeIdNumber);
76          map.put(KFSPropertyConstants.PAYEE_TYPE_CODE, this.payeeTypeCode);
77          map.put(KFSPropertyConstants.PAYEE_NAME, this.payeeName);
78  
79          return map;
80      }
81  
82      /**
83       * convert the field names between Payee and Vendor
84       *
85       * @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
86       */
87      public static Map<String, String> getFieldConversionBetweenPayeeAndVendor() {
88          Map<String, String> fieldConversionMap = new HashMap<String, String>();
89  
90          fieldConversionMap.put(KFSPropertyConstants.TAX_NUMBER, VendorPropertyConstants.VENDOR_TAX_NUMBER);
91  
92          fieldConversionMap.put(KFSPropertyConstants.VENDOR_NAME, KFSPropertyConstants.VENDOR_NAME);
93          fieldConversionMap.put(KFSPropertyConstants.VENDOR_NUMBER, KFSPropertyConstants.VENDOR_NUMBER);
94  
95          fieldConversionMap.put(KFSPropertyConstants.PERSON_FIRST_NAME, VendorPropertyConstants.VENDOR_FIRST_NAME);
96          fieldConversionMap.put(KFSPropertyConstants.PERSON_LAST_NAME, VendorPropertyConstants.VENDOR_LAST_NAME);
97  
98          fieldConversionMap.put(KFSPropertyConstants.ACTIVE, KFSPropertyConstants.ACTIVE_INDICATOR);
99  
100         return fieldConversionMap;
101     }
102 
103     /**
104      * convert the field names between Payee and Person
105      *
106      * @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
107      */
108     public static Map<String, String> getFieldConversionBetweenPayeeAndPerson() {
109         Map<String, String> fieldConversionMap = new HashMap<String, String>();
110 
111     //    fieldConversionMap.put(KFSPropertyConstants.TAX_NUMBER, KIMPropertyConstants.Person.EXTERNAL_ID);
112 
113         fieldConversionMap.put(KFSPropertyConstants.PERSON_FIRST_NAME, KIMPropertyConstants.Person.FIRST_NAME);
114         fieldConversionMap.put(KFSPropertyConstants.PERSON_LAST_NAME, KIMPropertyConstants.Person.LAST_NAME);
115 
116         fieldConversionMap.put(KFSPropertyConstants.EMPLOYEE_ID, KIMPropertyConstants.Person.EMPLOYEE_ID);
117         fieldConversionMap.put(KFSPropertyConstants.ACTIVE, KFSPropertyConstants.ACTIVE);
118 
119         return fieldConversionMap;
120     }
121 
122     /**
123      * build a payee object from the given vendor object
124      *
125      * @param vendorDetail the given vendor object
126      * @return a payee object built from the given vendor object
127      */
128     public static DisbursementPayee getPayeeFromVendor(VendorDetail vendorDetail) {
129         DisbursementPayee disbursementPayee = new DisbursementPayee();
130 
131         disbursementPayee.setActive(vendorDetail.isActiveIndicator());
132 
133         disbursementPayee.setPayeeIdNumber(vendorDetail.getVendorNumber());
134         disbursementPayee.setPayeeName(vendorDetail.getAltVendorName());
135         disbursementPayee.setTaxNumber(vendorDetail.getVendorHeader().getVendorTaxNumber());
136 
137         String vendorTypeCode = vendorDetail.getVendorHeader().getVendorTypeCode();
138         String payeeTypeCode = getVendorPayeeTypeCodeMapping().get(vendorTypeCode);
139         disbursementPayee.setPayeeTypeCode(payeeTypeCode);
140 
141         String vendorAddress = MessageFormat.format(addressPattern, vendorDetail.getDefaultAddressLine1(), vendorDetail.getDefaultAddressCity(), vendorDetail.getDefaultAddressStateCode(), vendorDetail.getDefaultAddressCountryCode());
142         disbursementPayee.setAddress(vendorAddress);
143 
144         return disbursementPayee;
145     }
146 
147     /**
148      * build a payee object from the given person object
149      *
150      * @param person the given person object
151      * @return a payee object built from the given person object
152      */
153     public static DisbursementPayee getPayeeFromPerson(Person person) {
154         DisbursementPayee disbursementPayee = new DisbursementPayee();
155 
156         disbursementPayee.setActive(person.isActive());
157 
158         disbursementPayee.setPayeeIdNumber(person.getEmployeeId());
159         disbursementPayee.setPrincipalId(person.getPrincipalId());
160 
161         disbursementPayee.setPayeeName(person.getName());
162         disbursementPayee.setTaxNumber(KFSConstants.BLANK_SPACE);
163 
164         disbursementPayee.setPayeeTypeCode(KFSConstants.PaymentPayeeTypes.EMPLOYEE);
165 
166         String personAddress = MessageFormat.format(addressPattern, person.getAddressLine1(), person.getAddressCity(), person.getAddressStateProvinceCode(), person.getAddressCountryCode());
167         disbursementPayee.setAddress(personAddress);
168 
169         return disbursementPayee;
170     }
171 
172     /**
173      * build a payee object from the given customer object
174      *
175      * @param customer the given customer object
176      * @return a payee object built from the given customer object
177      */
178     public static DisbursementPayee getPayeeFromCustomer(AccountsReceivableCustomer customer) {
179         DisbursementPayee disbursementPayee = new DisbursementPayee();
180 
181         disbursementPayee.setActive(customer.isActive());
182 
183         disbursementPayee.setPayeeIdNumber(customer.getCustomerNumber());
184         disbursementPayee.setPayeeName(customer.getCustomerName());
185         disbursementPayee.setTaxNumber(customer.getCustomerTaxNbr());
186 
187         disbursementPayee.setPayeeTypeCode(KFSConstants.PaymentPayeeTypes.CUSTOMER);
188 
189         String vendorAddress = MessageFormat.format(addressPattern, customer.getPrimaryAddress().getCustomerLine1StreetAddress(),
190                 customer.getPrimaryAddress().getCustomerCityName(), customer.getPrimaryAddress().getCustomerStateCode(), customer.getPrimaryAddress().getCustomerCountryCode());
191         disbursementPayee.setAddress(vendorAddress);
192 
193         return disbursementPayee;
194     }
195 
196     /**
197      * Gets the payeeIdNumber attribute.
198      *
199      * @return Returns the payeeIdNumber.
200      */
201     public String getPayeeIdNumber() {
202         return payeeIdNumber;
203     }
204 
205     /**
206      * Sets the payeeIdNumber attribute value.
207      *
208      * @param payeeIdNumber The payeeIdNumber to set.
209      */
210     public void setPayeeIdNumber(String payeeIdNumber) {
211         this.payeeIdNumber = payeeIdNumber;
212     }
213 
214     /**
215      * Gets the payeeTypeCode attribute.
216      *
217      * @return Returns the payeeTypeCode.
218      */
219     public String getPayeeTypeCode() {
220         return payeeTypeCode;
221     }
222 
223     /**
224      * Sets the payeeTypeCode attribute value.
225      *
226      * @param payeeTypeCode The payeeTypeCode to set.
227      */
228     public void setPayeeTypeCode(String payeeTypeCode) {
229         this.payeeTypeCode = payeeTypeCode;
230     }
231 
232     /**
233      * Gets the payeeName attribute.
234      *
235      * @return Returns the payeeName.
236      */
237     public String getPayeeName() {
238         return payeeName;
239     }
240 
241     /**
242      * Sets the payeeName attribute value.
243      *
244      * @param payeeName The payeeName to set.
245      */
246     public void setPayeeName(String payeeName) {
247         this.payeeName = payeeName;
248     }
249 
250     /**
251      * Gets the paymentReasonCode attribute.
252      *
253      * @return Returns the paymentReasonCode.
254      */
255     public String getPaymentReasonCode() {
256         return paymentReasonCode;
257     }
258 
259     /**
260      * Sets the paymentReasonCode attribute value.
261      *
262      * @param paymentReasonCode The paymentReasonCode to set.
263      */
264     public void setPaymentReasonCode(String paymentReasonCode) {
265         this.paymentReasonCode = paymentReasonCode;
266     }
267 
268     /**
269      * Gets the taxNumber attribute.
270      *
271      * @return Returns the taxNumber.
272      */
273     public String getTaxNumber() {
274         return taxNumber;
275     }
276 
277     /**
278      * Sets the taxNumber attribute value.
279      *
280      * @param taxNumber The taxNumber to set.
281      */
282     public void setTaxNumber(String taxNumber) {
283         this.taxNumber = taxNumber;
284     }
285 
286     /**
287      * Gets the employeeId attribute.
288      *
289      * @return Returns the employeeId.
290      */
291     public String getEmployeeId() {
292         return employeeId;
293     }
294 
295     /**
296      * Sets the employeeId attribute value.
297      *
298      * @param employeeId The employeeId to set.
299      */
300     public void setEmployeeId(String employeeId) {
301         this.employeeId = employeeId;
302     }
303 
304     /**
305      * Gets the vendorName attribute.
306      *
307      * @return Returns the vendorName.
308      */
309     public String getVendorName() {
310         return vendorName;
311     }
312 
313     /**
314      * Sets the vendorName attribute value.
315      *
316      * @param vendorName The vendorName to set.
317      */
318     public void setVendorName(String vendorName) {
319         this.vendorName = vendorName;
320     }
321 
322     /**
323      * Gets the address attribute.
324      *
325      * @return Returns the address.
326      */
327     public String getAddress() {
328         return address;
329     }
330 
331     /**
332      * Sets the address attribute value.
333      *
334      * @param address The address to set.
335      */
336     public void setAddress(String address) {
337         this.address = address;
338     }
339 
340     /**
341      * Gets the vendorNumber attribute.
342      *
343      * @return Returns the vendorNumber.
344      */
345     public String getVendorNumber() {
346         return vendorNumber;
347     }
348 
349     /**
350      * Sets the vendorNumber attribute value.
351      *
352      * @param vendorNumber The vendorNumber to set.
353      */
354     public void setVendorNumber(String vendorNumber) {
355         this.vendorNumber = vendorNumber;
356     }
357 
358     /**
359      * Gets the active attribute.
360      *
361      * @return Returns the active.
362      */
363     @Override
364     public boolean isActive() {
365         return active;
366     }
367 
368     /**
369      * Sets the active attribute value.
370      *
371      * @param active The active to set.
372      */
373     @Override
374     public void setActive(boolean active) {
375         this.active = active;
376     }
377 
378     /**
379      * Gets the firstName attribute.
380      *
381      * @return Returns the firstName.
382      */
383     public String getFirstName() {
384         return firstName;
385     }
386 
387     /**
388      * Sets the firstName attribute value.
389      *
390      * @param firstName The firstName to set.
391      */
392     public void setFirstName(String firstName) {
393         this.firstName = firstName;
394     }
395 
396     /**
397      * Gets the lastName attribute.
398      *
399      * @return Returns the lastName.
400      */
401     public String getLastName() {
402         return lastName;
403     }
404 
405     /**
406      * Sets the lastName attribute value.
407      *
408      * @param lastName The lastName to set.
409      */
410     public void setLastName(String lastName) {
411         this.lastName = lastName;
412     }
413 
414     /**
415      * Gets the payeeTypeDescription attribute.
416      *
417      * @return Returns the payeeTypeDescription.
418      */
419     public String getPayeeTypeDescription() {
420         DisbursementVoucherPayeeService payeeService = SpringContext.getBean(DisbursementVoucherPayeeService.class);
421 
422         return payeeService.getPayeeTypeDescription(payeeTypeCode);
423     }
424 
425     /**
426      * Sets the payeeTypeDescription attribute value.
427      *
428      * @param payeeTypeDescription The payeeTypeDescription to set.
429      */
430     public void setPayeeTypeDescription(String payeeTypeDescription) {
431         this.payeeTypeDescription = payeeTypeDescription;
432     }
433 
434     /**
435      * Gets the principalId attribute.
436      * @return Returns the principalId.
437      */
438     public String getPrincipalId() {
439         return principalId;
440     }
441 
442     /**
443      * Sets the principalId attribute value.
444      * @param principalId The principalId to set.
445      */
446     public void setPrincipalId(String principalId) {
447         this.principalId = principalId;
448     }
449 
450     // do mapping between vendor type code and payee type code
451     private static Map<String, String> getVendorPayeeTypeCodeMapping() {
452         Map<String, String> payeeVendorTypeCodeMapping = new HashMap<String, String>();
453 
454         payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.PURCHASE_ORDER, KFSConstants.PaymentPayeeTypes.VENDOR);
455         payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.DISBURSEMENT_VOUCHER, KFSConstants.PaymentPayeeTypes.VENDOR);
456         payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.REVOLVING_FUND, KFSConstants.PaymentPayeeTypes.REVOLVING_FUND_VENDOR);
457         payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.SUBJECT_PAYMENT, KFSConstants.PaymentPayeeTypes.SUBJECT_PAYMENT_VENDOR);
458         payeeVendorTypeCodeMapping.put(VendorConstants.VendorTypes.REFUND_PAYMENT, KFSConstants.PaymentPayeeTypes.REFUND_VENDOR);
459 
460         return payeeVendorTypeCodeMapping;
461     }
462 }