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.Basic;
023import io.konik.validator.annotation.Extended;
024import io.konik.validator.annotation.NotBlank;
025import io.konik.validator.annotation.NotEmpty;
026import io.konik.zugferd.unece.codes.DocumentCode;
027import io.konik.zugferd.unqualified.Indicator;
028import io.konik.zugferd.unqualified.ZfDate;
029
030import java.util.ArrayList;
031import java.util.List;
032
033import javax.validation.Valid;
034import javax.validation.constraints.NotNull;
035import javax.xml.bind.annotation.XmlAccessType;
036import javax.xml.bind.annotation.XmlAccessorType;
037import javax.xml.bind.annotation.XmlElement;
038import javax.xml.bind.annotation.XmlType;
039import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
040import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
041
042import com.neovisionaries.i18n.LanguageCode;
043
044/**
045 * = The Invoice Document Header
046 */
047@XmlAccessorType(XmlAccessType.FIELD)
048@XmlType(name = "HeaderExchangedDocument", propOrder = { "invoiceNumber", "name", "code", "issued", "copy",
049      "languages", "notes", "contractualDueDate" })
050public class Header {
051
052   @XmlElement(name = "ID")
053   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
054   private String invoiceNumber;
055
056   @XmlElement(name = "Name")
057   private String name;
058
059   @XmlElement(name = "TypeCode")
060   private DocumentCode code;
061
062   @XmlElement(name = "IssueDateTime")
063   private ZfDate issued;
064
065   @XmlElement(name = "CopyIndicator")
066   private Indicator copy;
067
068   @XmlElement(name = "LanguageID")
069   private List<LanguageCode> languages;
070
071   @XmlElement(name = "IncludedNote")
072   private List<Note> notes;
073
074   @XmlElement(name = "EffectiveSpecifiedPeriod")
075   @XmlJavaTypeAdapter(value = PeriodCompleteToDateTimeAdapter.class)
076   private ZfDate contractualDueDate;
077
078   /**
079    * Gets the invoice number.
080    * 
081    * Example:: {@code 2012-12345}
082    *
083    * @return the invoice number
084    */
085   @Basic
086   @NotBlank
087   public String getInvoiceNumber() {
088      return invoiceNumber;
089   }
090
091   /**
092    * Sets the invoice number.
093    * 
094    * Example:: {@code 2012-12345}
095    *
096    * @param invoiceNumber the invoice number
097    * @return the header document
098    */
099   public Header setInvoiceNumber(String invoiceNumber) {
100      this.invoiceNumber = invoiceNumber;
101      return this;
102   }
103
104   /**
105    * Gets the free text invoice name.
106    * 
107    * Example:: {@code invoice, credit advice, debit note, pro forma invoice}
108    * 
109    * @return the invoice name
110    */
111   @Basic
112   @NotBlank
113   public String getName() {
114      return this.name;
115   }
116
117   /**
118    * Adds a free text invoice name.
119    * 
120    * Example:: {@code invoice, credit advice, debit note, pro forma invoice}
121    *
122    * @param name the new name
123    * @return the exchanged document
124    * @see #getName()
125    */
126   public Header setName(String name) {
127      this.name = name;
128      return this;
129   }
130
131   /**
132    * Gets +UNCL 1001+ Document Name Code.
133    * 
134    * Example:: {@code 380, 381, 383, 389, 261}
135    * 
136    * @return the document name code
137    * @see http://www.unece.org/trade/untdid/d13b/tred/tred1001.htm[UN/EDIFACT 1001 Document name coe^]
138    */
139   @Basic
140   @NotNull
141   public DocumentCode getCode() {
142      return code;
143   }
144
145   /**
146    * Sets the +UNCL 1001+ Document Name Code.
147    * 
148    * Example:: {@code 380, 381, 383, 389, 261}
149    *
150    * @param code the new document name code
151    * @return the header document
152    * @see http://www.unece.org/trade/untdid/d13b/tred/tred1001.htm[UN/EDIFACT 1001 Document name coe^]
153    */
154
155   public Header setCode(DocumentCode code) {
156      this.code = code;
157      return this;
158   }
159
160   /**
161    * Gets the invoice issue date time.
162    * 
163    * @return the issue date time
164    */
165   @Basic
166   @Valid
167   @NotNull
168   public ZfDate getIssued() {
169      return issued;
170   }
171
172   /**
173    * Sets the invoice issue date time.
174    * 
175    * 
176    * @param issued the new issue date time
177    * @return the exchanged document
178    */
179   public Header setIssued(ZfDate issued) {
180      this.issued = issued;
181      return this;
182   }
183
184   /**
185    * Checks if is copy.
186    *
187    * @return the indicator
188    */
189   @Extended
190   public boolean isCopy() {
191      return copy == null?false:copy.getIndicator();
192   }
193
194   /**
195    * Sets the copy.
196    *
197    * @param copy the new copy
198    */
199   public void setCopy(boolean copy) {
200      this.copy = new Indicator(copy);
201   }
202
203   /**
204    * Gets the languages.
205    *
206    * @return the languages
207    */
208   @Extended
209   public List<LanguageCode> getLanguages() {
210      if (languages == null) {
211         languages = new ArrayList<LanguageCode>();
212      }
213      return languages;
214   }
215
216   /**
217    * Adds the language.
218    *
219    * @param language the language
220    */
221   public void addLanguage(LanguageCode language) {
222      getLanguages().add(language);
223   }
224
225   /**
226    * Gets the invoice header notes.
227    * 
228    * Example::
229    * - {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.} -
230    * - {@code note subject code as UNCL 4451: }{@link Note#getSubjectCode() AAK}
231    * 
232    * @return the included note
233    */
234   @Basic
235   @Valid
236   @NotEmpty
237   public List<Note> getNotes() {
238      if (notes == null) {
239         notes = new ArrayList<Note>();
240      }
241      return this.notes;
242   }
243
244   /**
245    * Adds a invoice header note.
246    * 
247    * Example::
248    * - {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.} -
249    * - {@code note subject code as UNCL 4451: }{@link Note#getSubjectCode() AAK}
250    *
251    * @param additionalNote the additional note
252    * @return the header
253    */
254   public Header addNote(Note... additionalNote) {
255      addAll(getNotes(), additionalNote);
256      return this;
257   }
258
259   /**
260    * Gets the contractual due date.
261    *
262    * @return the contractual due date
263    */
264   @Extended
265   public ZfDate getContractualDueDate() {
266      return contractualDueDate;
267   }
268
269   /**
270    * Sets the contractual due date.
271    *
272    * @param contractualDueDate the contractual due date
273    * @return the header
274    */
275   public Header setContractualDueDate(ZfDate contractualDueDate) {
276      this.contractualDueDate = contractualDueDate;
277      return this;
278   }
279
280}