001/*
002 * Copyright (C) 2014 konik.io
003 *
004 * This file is part of Konik library.
005 *
006 * Konik library is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Konik library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with Konik library.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package io.konik.zugferd.entity;
020
021import io.konik.zugferd.unqualified.ID;
022
023import java.util.ArrayList;
024import java.util.List;
025
026import javax.validation.Valid;
027import javax.validation.constraints.NotNull;
028import javax.xml.bind.annotation.XmlAccessType;
029import javax.xml.bind.annotation.XmlAccessorType;
030import javax.xml.bind.annotation.XmlElement;
031import javax.xml.bind.annotation.XmlType;
032import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
033import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
034
035/**
036 * = The Trade Party
037 * 
038 * Applies to a buyer, seller, order recipient or invoice recipient.
039 */
040@XmlAccessorType(XmlAccessType.FIELD)
041@XmlType(name = "TradePartyType", propOrder = { "id", "globalId", "name", "contact", "address", "taxRegistration" })
042public class TradeParty {
043
044   /** The vendor number or customer number */
045   @XmlElement(name = "ID")
046   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
047   private String id;
048
049   /** The global vendor number or customer number id */
050   @XmlElement(name = "GlobalID")
051   private List<ID> globalId;
052
053   /** The name of the trade party. */
054   @NotNull
055   @XmlElement(name = "Name")
056   private String name;
057
058   /** The contact person. */
059   @Valid
060   @XmlElement(name = "DefinedTradeContact")
061   private Contact contact;
062
063   /** The postal address. */
064   @Valid
065   @XmlElement(name = "PostalTradeAddress")
066   private Address address;
067
068   /** The tax registration. */
069   @Valid
070   @XmlElement(name = "SpecifiedTaxRegistration")
071   private List<TaxRegistration> taxRegistration;
072
073   /**
074    * Gets the id.
075    * 
076    * Profile:: COMFORT when part of Trade.agreements.seller
077    * 
078    * Example:: {@code The supplier number given by the customer/buyer }
079    * 
080    * @return the id
081    */
082   public String getId() {
083      return id;
084   }
085
086   /**
087    * Sets the id.
088    * Profile:: COMFORT when part of Trade.agreements.seller
089    * 
090    * Example:: {@code The supplier number given by the customer/buyer }
091    *
092    * @param id the new id
093    * @return the trade party
094    */
095   public TradeParty setId(String id) {
096      this.id = id;
097      return this;
098   }
099
100   /**
101    * Gets the trade party global id. (GLN, DUNS, BIC, ODETTE)
102    * 
103    * Profile:: COMFORT when part of Trade.agreements.seller
104    * 
105    * Example::
106    * - {@link ID#getValue()} {@code  GENODED1SPK, 4000001000005 }
107    * - {@link ID#getSchemeId()} the ISO 6523 code {@code 0021, 0088, 0060, 0177 }
108    * 
109    * @return the global id
110    */
111   public List<ID> getGlobalId() {
112      if (globalId == null) {
113         globalId = new ArrayList<ID>();
114      }
115      return this.globalId;
116   }
117
118   /**
119    * Adds the global id. 
120    * 
121    * Profile:: COMFORT when part of Trade.agreements.seller
122    * 
123    * Example::
124    * - {@link ID#getValue()} {@code  GENODED1SPK, 4000001000005 }
125    * - {@link ID#getSchemeId()} the ISO 6523 code {@code 0021, 0088, 0060, 0177 }
126    * 
127    * @param additionalGlobalId the additional global id
128    * @return the trade party
129    */
130   public TradeParty addGlobalId(ID additionalGlobalId) {
131      getGlobalId().add(additionalGlobalId);
132      return this;
133   }
134
135   /**
136    * Gets the trade party name. Usually the Company name.
137    * 
138    * Profile:: BASIC when part of Trade.agreements.seller/buyer.
139    * 
140    * Example:: {@code  ACME Inc.}
141    * 
142    * @return the name
143    */
144   public String getName() {
145      return name;
146   }
147
148   /**
149    * Sets the trade party name. Usually the Company name.
150    * 
151    * Profile:: BASIC when part of Trade.agreements.seller/buyer.
152    * 
153    * Example:: {@code  ACME Inc.}
154    * 
155    * @param name the name
156    * @return the trade party
157    */
158   public TradeParty setName(String name) {
159      this.name = name;
160      return this;
161   }
162
163   /**
164    * Gets the contact person.
165    * 
166    * Profile:: BASIC when part of Trade.agreements.seller/buyer.
167    * 
168    * 
169    * @return the defined trade contact
170    */
171   public Contact getContact() {
172      return contact;
173   }
174
175   /**
176    * Sets the contact person.
177    * 
178    * Profile:: BASIC when part of Trade.agreements.seller/buyer.
179    * 
180    * 
181    * @param contact the new defined trade contact
182    * @return the trade party
183    */
184   public TradeParty setContact(Contact contact) {
185      this.contact = contact;
186      return this;
187   }
188
189   /**
190    * Gets the postal trade address.
191    * 
192    * Profile:: BASIC when part of Trade.agreements.seller/buyer.
193    * 
194    * 
195    * @return the postal trade address
196    */
197   public Address getAddress() {
198      return address;
199   }
200
201   /**
202    * Sets the postal trade address.
203    * 
204    * Profile:: BASIC when part of Trade.agreements.seller/buyer.
205    * 
206    * 
207    * @param postalAddress the new postal trade address
208    * @return the trade party
209    */
210   public TradeParty setAddress(Address postalAddress) {
211      this.address = postalAddress;
212      return this;
213   }
214
215   /**
216    * Gets the specified tax registration.
217    * 
218    * Profile:: BASIC
219    * 
220    * 
221    * @return the specified tax registration
222    */
223   public List<TaxRegistration> getTaxRegistration() {
224      if (taxRegistration == null) {
225         taxRegistration = new ArrayList<TaxRegistration>();
226      }
227      return this.taxRegistration;
228   }
229
230   /**
231    * Adds the tax registration.
232    * 
233    * Profile:: BASIC
234    * 
235    * 
236    * @param additionalTaxRegistration an additional Tax Registration
237    * @return the trade party
238    */
239   public TradeParty addTaxRegistration(TaxRegistration additionalTaxRegistration) {
240      getTaxRegistration().add(additionalTaxRegistration);
241      return this;
242   }
243
244}