001/* Copyright (C) 2014 konik.io
002 *
003 * This file is part of the Konik library.
004 *
005 * The Konik library is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * The Konik library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with the Konik library. If not, see <http://www.gnu.org/licenses/>.
017 */
018package io.konik.zugferd.entity;
019
020import static java.util.Collections.addAll;
021import io.konik.jaxb.adapter.PeriodCompleteToDateTimeAdapter;
022import io.konik.validator.annotation.Extended;
023import io.konik.validator.annotation.NotEmpty;
024import io.konik.validator.annotation.NullableNotBlank;
025import io.konik.zugferd.unece.codes.DocumentCode;
026import io.konik.zugferd.unqualified.Indicator;
027import io.konik.zugferd.unqualified.ZfDate;
028
029import java.util.ArrayList;
030import java.util.List;
031
032import javax.validation.Valid;
033import javax.validation.constraints.NotNull;
034import javax.xml.bind.annotation.XmlAccessType;
035import javax.xml.bind.annotation.XmlAccessorType;
036import javax.xml.bind.annotation.XmlElement;
037import javax.xml.bind.annotation.XmlType;
038import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
039import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
040
041import com.neovisionaries.i18n.LanguageCode;
042
043/**
044 * = The Invoice Document Header
045 */
046@XmlAccessorType(XmlAccessType.FIELD)
047@XmlType(name = "HeaderExchangedDocument", propOrder = { "invoiceNumber", "name", "code", "issued", "copy", "languages",
048      "notes", "contractualDueDate" })
049public class Header {
050
051   @NotNull
052   @NullableNotBlank
053   @XmlElement(name = "ID")
054   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
055   private String invoiceNumber;
056
057   @NotNull
058   @NullableNotBlank
059   @XmlElement(name = "Name")
060   private String name;
061
062   @NotNull
063   @XmlElement(name = "TypeCode")
064   private DocumentCode code;
065
066   @XmlElement(name = "IssueDateTime")
067   @NotNull
068   @Valid
069   private ZfDate issued;
070
071   @XmlElement(name = "CopyIndicator")
072   private Indicator copy;
073
074   @XmlElement(name = "LanguageID")
075   private List<LanguageCode> languages;
076
077   @Valid
078   @NotEmpty
079   @XmlElement(name = "IncludedNote")
080   private List<Note> notes;
081
082   @Valid
083   @Extended
084   @XmlElement(name = "EffectiveSpecifiedPeriod")
085   @XmlJavaTypeAdapter(value = PeriodCompleteToDateTimeAdapter.class)
086   private ZfDate contractualDueDate;
087
088   /**
089    * Gets the invoice number.
090    * 
091    * Profile:: BASIC
092    * 
093    * Example:: {@code 2012-12345}
094    *
095    * @return the invoice number
096    */
097   public String getInvoiceNumber() {
098      return invoiceNumber;
099   }
100
101   /**
102    * Sets the invoice number.
103    * 
104    * Profile:: BASIC
105    * 
106    * Example:: {@code 2012-12345}
107    *
108    * @param invoiceNumber the invoice number
109    * @return the header document
110    */
111   public Header setInvoiceNumber(String invoiceNumber) {
112      this.invoiceNumber = invoiceNumber;
113      return this;
114   }
115
116   /**
117    * Gets the free text invoice name.
118    * 
119    * Profile:: BASIC
120    * 
121    * Example:: {@code invoice, credit advice, debit note, pro forma invoice}
122    * 
123    * @return the invoice name
124    */
125   public String getName() {
126      return this.name;
127   }
128
129   /**
130    * Adds a free text invoice name.
131    * 
132    * Profile:: BASIC
133    * 
134    * Example:: {@code invoice, credit advice, debit note, pro forma invoice}
135    *
136    * @param name the new name
137    * @return the exchanged document
138    * @see #getName()
139    */
140   public Header setName(String name) {
141      this.name = name;
142      return this;
143   }
144
145   /**
146    * Gets +UNCL 1001+ Document Name Code.
147    * 
148    * Profile:: BASIC
149    * 
150    * Example:: {@code 380, 381, 383, 389, 261}
151    * 
152    * @return the document name code
153    * @see http://www.unece.org/trade/untdid/d13b/tred/tred1001.htm[UN/EDIFACT 1001 Document name coe^]
154    */
155   public DocumentCode getCode() {
156      return code;
157   }
158
159   /**
160    * Sets the +UNCL 1001+ Document Name Code.
161    * 
162    * Profile:: BASIC
163    * 
164    * Example:: {@code 380, 381, 383, 389, 261}
165    *
166    * @param code the new document name code
167    * @return the header document
168    * @see http://www.unece.org/trade/untdid/d13b/tred/tred1001.htm[UN/EDIFACT 1001 Document name coe^]
169    */
170
171   public Header setCode(DocumentCode code) {
172      this.code = code;
173      return this;
174   }
175
176   /**
177    * Gets the invoice issue date time.
178    * 
179    * Profile:: BASIC
180    * 
181    * 
182    * @return the issue date time
183    */
184   public ZfDate getIssued() {
185      return issued;
186   }
187
188   /**
189    * Sets the invoice issue date time.
190    * 
191    * Profile:: BASIC
192    * 
193    * 
194    * @param issued the new issue date time
195    * @return the exchanged document
196    */
197   public Header setIssued(ZfDate issued) {
198      this.issued = issued;
199      return this;
200   }
201
202   /**
203    * Checks if is copy.
204    *
205    * @return the indicator
206    */
207   public boolean isCopy() {
208      return copy.getIndicator();
209   }
210
211   /**
212    * Sets the copy.
213    *
214    * @param copy the new copy
215    */
216   public void setCopy(boolean copy) {
217      this.copy = new Indicator(copy);
218   }
219
220   /**
221    * Gets the languages.
222    *
223    * @return the languages
224    */
225   public List<LanguageCode> getLanguages() {
226      if (languages == null) {
227         languages = new ArrayList<LanguageCode>();
228      }
229      return languages;
230   }
231
232   /**
233    * Adds the language.
234    *
235    * @param language the language
236    */
237   public void addLanguage(LanguageCode language) {
238      getLanguages().add(language);
239   }
240
241   /**
242    * Gets the invoice header notes.
243    * 
244    * Profile::
245    * - {@link Note#getContent()}: BASIC
246    * - {@link Note#getSubjectCode()}: COMFORT
247    * 
248    * Example:: {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.}
249    * 
250    * Example::
251    * - {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.} -
252    * {@code note subject code as UNCL 4451: }{@link Note#getSubjectCode() AAK}
253    * 
254    * @return the included note
255    */
256   public List<Note> getNotes() {
257      if (notes == null) {
258         notes = new ArrayList<Note>();
259      }
260      return this.notes;
261   }
262
263   /**
264    * Adds a invoice header note.
265    * 
266    * Profile::
267    * - {@link Note#getContent()}: BASIC
268    * - {@link Note#getSubjectCode()}: COMFORT
269    * 
270    * Example::
271    * - {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.} -
272    * {@code note subject code as UNCL 4451: }{@link Note#getSubjectCode() AAK}
273    *
274    * @param additionalNote the additional note
275    * @return the header
276    */
277   public Header addNote(Note... additionalNote) {
278      addAll(getNotes(), additionalNote);
279      return this;
280   }
281
282   /**
283    * Gets the contractual due date.
284    *
285    * @return the contractual due date
286    */
287   public ZfDate getContractualDueDate() {
288      return contractualDueDate;
289   }
290
291   /**
292    * Sets the contractual due date.
293    *
294    * @param contractualDueDate the contractual due date
295    * @return the header
296    */
297   public Header setContractualDueDate(ZfDate contractualDueDate) {
298      this.contractualDueDate = contractualDueDate;
299      return this;
300   }
301
302}