View Javadoc
1   /*
2    * Copyright 2006-2009 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  /*
17   * Created on Feb 13, 2006
18   *
19   */
20  package org.kuali.ole.module.purap.businessobject;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.commons.lang.builder.ToStringBuilder;
24  import org.kuali.ole.module.purap.util.ElectronicInvoiceUtils;
25  import org.kuali.ole.module.purap.util.cxml.CxmlExtrinsic;
26  import org.kuali.ole.sys.util.KfsDateUtils;
27  
28  import java.util.ArrayList;
29  import java.util.Date;
30  import java.util.Iterator;
31  import java.util.List;
32  
33  public class ElectronicInvoiceDetailRequestHeader {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoiceDetailRequestHeader.class);
35  
36      private String invoiceId;
37      private String purpose = "standard";
38      private String operation = "new";
39      private String invoiceDateString;
40      private java.util.Date invoiceDate;
41  
42      private boolean isInformationOnly;
43      private boolean isHeaderInvoiceIndicator;
44      private boolean isTaxInLine;
45      private boolean isSpecialHandlingInLine;
46      private boolean isShippingInLine;
47      private boolean isDiscountInLine;
48      private String shippingDateString;
49      private java.util.Date shippingDate;
50      private String invoiceCustomerNumber;
51  
52      private List invoicePartnerContacts = new ArrayList();
53      private List invoiceShippingContacts = new ArrayList();  // holds the ship to address information
54      private List extrinsics = new ArrayList();
55  
56      /**
57       * Newly Added
58       */
59      private boolean isAccountingInLine;
60      private String idReferenceCreator;
61      private String idReferenceDescription;
62      private String idReferenceDomain;
63      private String idReferenceIdentifier;
64      private int payInNumberOfDays;
65      private String percentageRate;
66  
67      public ElectronicInvoiceDetailRequestHeader() {
68          super();
69      }
70  
71      /**
72       * @param invoiceId
73       * @param purpose
74       * @param operation
75       * @throws ParseException
76       */
77      public ElectronicInvoiceDetailRequestHeader(String invoiceId, String invoiceDate, String purpose, String operation) {
78          super();
79          this.invoiceId = invoiceId;
80          this.purpose = purpose;
81          this.operation = operation;
82          this.setInvoiceDateString(invoiceDate);
83      }
84  
85      /**
86       * This method returns the first ElectronicInvoicePostalAddress associated with the ElectronicInvoiceContact
87       * that has a roleID matching the given roleID.  If the addressName is given then
88       * the ElectronicInvoicePostalAddress returned must match that... otherwise the first
89       * ElectronicInvoicePostalAddress found is returned
90       *
91       * @param roleID      Valid 'Contact' tag attribute value for 'roleID'
92       * @param addressName Valid 'PostalAddress' tag attribute value for 'name'
93       * @return ElectronicInvoicePostalAddress relating to given info
94       */
95      public ElectronicInvoicePostalAddress getCxmlPostalAddressByRoleID(String roleID, String addressName) {
96          if (roleID != null) {
97              ElectronicInvoiceContact contact = this.getCxmlContactByRoleID(roleID);
98              if (contact != null) {
99                  for (Iterator iterator = contact.getPostalAddresses().iterator(); iterator.hasNext(); ) {
100                     ElectronicInvoicePostalAddress cpa = (ElectronicInvoicePostalAddress) iterator.next();
101                     if (addressName == null) {
102                         return cpa;
103                     } else {
104                         if (addressName.equalsIgnoreCase(cpa.getName())) {
105                             return cpa;
106                         }
107                     }
108                 }
109             }
110         }
111         return null;
112     }
113 
114     /**
115      * This method returns the first ElectronicInvoiceContact associated with the given
116      * roleID.
117      *
118      * @param roleID Valid 'Contact' tag attribute value for 'roleID'
119      * @return ElectronicInvoiceContact relating to given info
120      */
121     public ElectronicInvoiceContact getCxmlContactByRoleID(String roleID) {
122         if (roleID != null) {
123             for (Iterator iter = this.invoicePartnerContacts.iterator(); iter.hasNext(); ) {
124                 ElectronicInvoiceContact contact = (ElectronicInvoiceContact) iter.next();
125                 if (roleID.equalsIgnoreCase(contact.getRole())) {
126                     return contact;
127                 }
128             }
129             for (Iterator shipIter = this.invoiceShippingContacts.iterator(); shipIter.hasNext(); ) {
130                 ElectronicInvoiceContact shipContact = (ElectronicInvoiceContact) shipIter.next();
131                 if (roleID.equalsIgnoreCase(shipContact.getRole())) {
132                     return shipContact;
133                 }
134             }
135         }
136         return null;
137     }
138 
139     /**
140      * @return Returns the invoiceDateString.
141      */
142     public String getInvoiceDateString() {
143         return invoiceDateString;
144     }
145 
146     /**
147      * @param invoiceDateString The invoiceDateString to set.
148      */
149     public void setInvoiceDateString(String invoiceDateString) {
150         this.invoiceDateString = invoiceDateString;
151         setInvoiceDate(ElectronicInvoiceUtils.getDate(invoiceDateString));
152     }
153 
154     /**
155      * @return Returns the shippingDateString.
156      */
157     public String getShippingDateString() {
158         return shippingDateString;
159     }
160 
161     /**
162      * @param shippingDateString The shippingDateString to set.
163      */
164     public void setShippingDateString(String shippingDateString) {
165         this.shippingDateString = shippingDateString;
166 //    if ( (shippingDateString != null) && (!("".equals(shippingDateString))) ) {
167 //      SimpleDateFormat sdf = new SimpleDateFormat(PurapConstants.ElectronicInvoice.CXML_DATE_FORMAT, Locale.US);
168 //      try {
169 //        this.shippingDate = sdf.parse(shippingDateString);
170 //      } catch (ParseException e) {
171 //        // setting shipping date to null to identify problem
172 //        LOG.error("setShippingDateString() SimpleDateFormat parser error attempting to set invalid date string " + shippingDateString + " in ShippingDate field... setting date to null");
173 //        this.shippingDate = null;
174 //      }
175 //    } else {
176 //      this.shippingDate = null;
177 //    }
178         setShippingDate(ElectronicInvoiceUtils.getDate(shippingDateString));
179     }
180 
181     /**
182      * @return Returns the extrinsics.
183      */
184     public List getExtrinsics() {
185         return extrinsics;
186     }
187 
188     /**
189      * @param extrinsics The extrinsics to set.
190      */
191     public void setExtrinsics(List extrinsics) {
192         this.extrinsics = extrinsics;
193     }
194 
195     /**
196      * @return Returns the invoiceCustomerNumber.
197      */
198     public String getInvoiceCustomerNumber() {
199         return invoiceCustomerNumber;
200     }
201 
202     /**
203      * @param invoiceCustomerNumber The invoiceCustomerNumber to set.
204      */
205     public void setInvoiceCustomerNumber(String invoiceCustomerNumber) {
206         this.invoiceCustomerNumber = invoiceCustomerNumber;
207     }
208 
209     /**
210      * @return Returns the invoiceDate.
211      */
212     public java.sql.Date getInvoiceDate() {
213         if (invoiceDate != null) {
214             return KfsDateUtils.convertToSqlDate(invoiceDate);
215         } else {
216             return null;
217         }
218     }
219 
220     /**
221      * @param invoiceDate The invoiceDate to set.
222      */
223     public void setInvoiceDate(Date invoiceDate) {
224         this.invoiceDate = invoiceDate;
225     }
226 
227     /**
228      * @return Returns the invoiceId.
229      */
230     public String getInvoiceId() {
231         return invoiceId;
232     }
233 
234     /**
235      * @param invoiceId The invoiceId to set.
236      */
237     public void setInvoiceId(String invoiceId) {
238         this.invoiceId = invoiceId;
239     }
240 
241     /**
242      * @return Returns the invoicePartnerContacts.
243      */
244     public List getInvoicePartnerContacts() {
245         return invoicePartnerContacts;
246     }
247 
248     /**
249      * @param invoicePartnerContacts The invoicePartnerContacts to set.
250      */
251     public void setInvoicePartnerContacts(List invoicePartnerContacts) {
252         this.invoicePartnerContacts = invoicePartnerContacts;
253     }
254 
255     /**
256      * @return Returns the invoiceShippingContacts.
257      */
258     public List getInvoiceShippingContacts() {
259         return invoiceShippingContacts;
260     }
261 
262     /**
263      * @param invoiceShippingContacts The invoiceShippingContacts to set.
264      */
265     public void setInvoiceShippingContacts(List invoiceShippingContacts) {
266         this.invoiceShippingContacts = invoiceShippingContacts;
267     }
268 
269     /**
270      * @return Returns the isDiscountInLine.
271      */
272     public boolean isDiscountInLine() {
273         return isDiscountInLine;
274     }
275 
276     /**
277      * @param isDiscountInLine The isDiscountInLine to set.
278      */
279     public void setDiscountInfoProvidedIndicator(String isDiscountInLine) {
280         this.isDiscountInLine = StringUtils.equalsIgnoreCase(StringUtils.defaultString(isDiscountInLine), "yes");
281         ;
282     }
283 
284     /**
285      * @return Returns the isHeaderInvoiceIndicator.
286      */
287     public boolean isHeaderInvoiceIndicator() {
288         return isHeaderInvoiceIndicator;
289     }
290 
291     /**
292      * @param isHeaderInvoiceIndicator The isHeaderInvoiceIndicator to set.
293      */
294     public void setHeaderInvoiceInd(String isHeaderInvoiceIndicator) {
295         this.isHeaderInvoiceIndicator = StringUtils.equalsIgnoreCase(StringUtils.defaultString(isHeaderInvoiceIndicator), "yes");
296     }
297 
298     /**
299      * @return Returns the isInformationOnly.
300      */
301     public boolean isInformationOnly() {
302         return isInformationOnly;
303     }
304 
305     /**
306      * @param isInformationOnly The isInformationOnly to set.
307      */
308     public void setbuyerInformationOnlyIndicator(String informationOnly) {
309         /**
310          * It's not possible to have the param as boolean type since yes is not a allowed boolean value in xsd (Allowed ones - true/false/1/0)
311          */
312         this.isInformationOnly = StringUtils.equalsIgnoreCase(StringUtils.defaultString(informationOnly), "yes");
313     }
314 
315     /**
316      * @return Returns the isShippingInLine.
317      */
318     public boolean isShippingInLine() {
319         return isShippingInLine;
320     }
321 
322     /**
323      * @param isShippingInLine The isShippingInLine to set.
324      */
325     public void setShippingInfoProvidedIndicator(String isShippingInLine) {
326         this.isShippingInLine = StringUtils.equalsIgnoreCase(StringUtils.defaultString(isShippingInLine), "yes");
327     }
328 
329     /**
330      * @return Returns the isSpecialHandlingInLine.
331      */
332     public boolean isSpecialHandlingInLine() {
333         return isSpecialHandlingInLine;
334     }
335 
336     /**
337      * @param isSpecialHandlingInLine The isSpecialHandlingInLine to set.
338      */
339     public void setSpecialHandlingInfoProvidedIndicator(String isSpecialHandlingInLine) {
340         this.isSpecialHandlingInLine = StringUtils.equalsIgnoreCase(StringUtils.defaultString(isSpecialHandlingInLine), "yes");
341     }
342 
343     /**
344      * @return Returns the isTaxInLine.
345      */
346     public boolean isTaxInLine() {
347         return isTaxInLine;
348     }
349 
350     /**
351      * @param isTaxInLine The isTaxInLine to set.
352      */
353     public void setTaxInfoProvidedIndicator(String isTaxInLine) {
354         this.isTaxInLine = StringUtils.equalsIgnoreCase(StringUtils.defaultString(isTaxInLine), "yes");
355     }
356 
357     /**
358      * @return Returns the operation.
359      */
360     public String getOperation() {
361         return operation;
362     }
363 
364     /**
365      * @param operation The operation to set.
366      */
367     public void setOperation(String operation) {
368         this.operation = operation;
369     }
370 
371     /**
372      * @return Returns the purpose.
373      */
374     public String getPurpose() {
375         return purpose;
376     }
377 
378     /**
379      * @param purpose The purpose to set.
380      */
381     public void setPurpose(String purpose) {
382         this.purpose = purpose;
383     }
384 
385     /**
386      * @return Returns the shippingDate.
387      */
388     public Date getShippingDate() {
389         return shippingDate;
390     }
391 
392     /**
393      * @param shippingDate The shippingDate to set.
394      */
395     public void setShippingDate(Date shippingDate) {
396         this.shippingDate = shippingDate;
397     }
398 
399     public boolean isAccountingInLine() {
400         return isAccountingInLine;
401     }
402 
403     public void setAccountingInfoProvidedIndicator(String isAccountingInLine) {
404         this.isAccountingInLine = StringUtils.equalsIgnoreCase(StringUtils.defaultString(isAccountingInLine), "yes");
405         ;
406     }
407 
408     public String getIdReferenceCreator() {
409         return idReferenceCreator;
410     }
411 
412     public void setIdReferenceCreator(String idReferenceCreator) {
413         this.idReferenceCreator = idReferenceCreator;
414     }
415 
416     public String getIdReferenceDescription() {
417         return idReferenceDescription;
418     }
419 
420     public void setIdReferenceDescription(String idReferenceDescription) {
421         this.idReferenceDescription = idReferenceDescription;
422     }
423 
424     public String getIdReferenceDomain() {
425         return idReferenceDomain;
426     }
427 
428     public void setIdReferenceDomain(String idReferenceDomain) {
429         this.idReferenceDomain = idReferenceDomain;
430     }
431 
432     public String getIdReferenceIdentifier() {
433         return idReferenceIdentifier;
434     }
435 
436     public void setIdReferenceIdentifier(String idReferenceIdentifier) {
437         this.idReferenceIdentifier = idReferenceIdentifier;
438     }
439 
440     public void addInvoicePartnerContact(ElectronicInvoiceContact electronicInvoiceContact) {
441         if (electronicInvoiceContact != null) {
442             invoicePartnerContacts.add(electronicInvoiceContact);
443         }
444     }
445 
446     public ElectronicInvoiceContact[] getInvoicePartnerContactsAsArray() {
447         if (invoicePartnerContacts.size() > 0) {
448             ElectronicInvoiceContact[] tempContacts = new ElectronicInvoiceContact[invoicePartnerContacts.size()];
449             invoicePartnerContacts.toArray(tempContacts);
450             return tempContacts;
451         }
452         return null;
453     }
454 
455     public void addInvoiceShippingContacts(ElectronicInvoiceContact electronicInvoiceContact) {
456         invoiceShippingContacts.add(electronicInvoiceContact);
457     }
458 
459     public ElectronicInvoiceContact[] getInvoiceShippingContactsAsArray() {
460         if (invoiceShippingContacts.size() > 0) {
461             ElectronicInvoiceContact[] tempContacts = new ElectronicInvoiceContact[invoiceShippingContacts.size()];
462             invoiceShippingContacts.toArray(tempContacts);
463             return tempContacts;
464         }
465         return null;
466     }
467 
468     public void addExtrinsic(CxmlExtrinsic extrinsic) {
469         this.extrinsics.add(extrinsic);
470     }
471 
472     public CxmlExtrinsic[] getExtrinsicAsArray() {
473         if (extrinsics.size() > 0) {
474             CxmlExtrinsic[] extrinsics = new CxmlExtrinsic[this.extrinsics.size()];
475             this.extrinsics.toArray(extrinsics);
476             return extrinsics;
477         }
478         return null;
479     }
480 
481     public int getPayInNumberOfDays() {
482         return payInNumberOfDays;
483     }
484 
485     public void setPayInNumberOfDays(int payInNumberOfDays) {
486         this.payInNumberOfDays = payInNumberOfDays;
487     }
488 
489     public String getPercentageRate() {
490         return percentageRate;
491     }
492 
493     public void setPercentageRate(String percentageRate) {
494         this.percentageRate = percentageRate;
495     }
496 
497     public String toString() {
498 
499         ToStringBuilder toString = new ToStringBuilder(this);
500 
501         toString.append("invoiceID", getInvoiceId());
502         toString.append("purpose", getPurpose());
503         toString.append("operation", getOperation());
504         toString.append("invoiceDate", getInvoiceDateString());
505 
506         toString.append("isInformationOnly", isInformationOnly());
507         toString.append("isHeaderInvoiceIndicator", isHeaderInvoiceIndicator());
508         toString.append("isTaxInLine", isTaxInLine());
509         toString.append("isSpecialHandlingInLine", isSpecialHandlingInLine());
510         toString.append("isShippingInLine", isShippingInLine());
511         toString.append("isDiscountInLine", isDiscountInLine());
512         toString.append("isAccountingInLine", isAccountingInLine());
513 
514         toString.append("idReferenceCreator", getIdReferenceCreator());
515         toString.append("idReferenceDescription", getIdReferenceDescription());
516         toString.append("idReferenceDomain", getIdReferenceDomain());
517         toString.append("idReferenceIdentifier", getIdReferenceIdentifier());
518 
519 
520         toString.append("shippingDate", getShippingDateString());
521         toString.append("invoiceCustomerNumber", getInvoiceCustomerNumber());
522         toString.append("payInNumberOfDays", getPayInNumberOfDays());
523         toString.append("percentageRate", getPercentageRate());
524 
525         toString.append("invoicePartnerContacts", getInvoicePartnerContacts());
526         toString.append("invoiceShippingContacts", getInvoiceShippingContacts());
527         toString.append("extrinsics", getExtrinsics());
528 
529         return toString.toString();
530     }
531 
532 
533 }
534