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.qualified.DateTime;
022import io.konik.zugferd.unece.codes.DocumentNameCode;
023
024import java.util.ArrayList;
025import java.util.List;
026
027import javax.validation.Valid;
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 Invoice Document Header
037 */
038@XmlAccessorType(XmlAccessType.FIELD)
039@XmlType(name = "ExchangedDocumentType", propOrder = { "invoiceNumber", "name", "code", "issued", "notes" })
040public class Header {
041   
042   @XmlElement(name = "ID")
043   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
044   private String invoiceNumber;
045
046   @XmlElement(name = "Name")
047   private List<String> name;
048
049   @XmlElement(name = "TypeCode")
050   private DocumentNameCode code;
051
052   @XmlElement(name = "IssueDateTime")
053   @Valid
054   private DateTime issued;
055
056   @XmlElement(name = "IncludedNote")
057   private List<Note> notes;
058
059   /**
060    * Gets the invoice number.
061    * 
062    * Profile:: BASIC
063    * 
064    * Example:: {@code 2012-12345}
065    *
066    * @return the invoice number
067    */
068   public String getInvoiceNumber() {
069      return invoiceNumber;
070   }
071
072   /**
073    * Sets the invoice number.
074    * 
075    * Profile:: BASIC
076    * 
077    * Example:: {@code 2012-12345}
078    *
079    * @param invoiceNumber the invoice number
080    * @return the header document
081    */
082   public Header setInvoiceNumber(String invoiceNumber) {
083      this.invoiceNumber = invoiceNumber;
084      return this;
085   }
086
087   /**
088    * Gets the free text invoice name.
089    * 
090    * Profile:: BASIC
091    * 
092    * Example:: {@code invoice, credit advice, debit note, pro forma invoice}
093    * 
094    * @return the invoice name
095    */
096   public List<String> getName() {
097      if (name == null) {
098         name = new ArrayList<String>();
099      }
100      return this.name;
101   }
102
103   /**
104    * Adds a free text invoice name.
105    * 
106    * Profile:: BASIC
107    * 
108    * Example:: {@code invoice, credit advice, debit note, pro forma invoice}
109    * 
110    * @param additionalName the additional invoice name
111    * @return the exchanged document
112    * @see #getName()
113    */
114   public Header addName(String additionalName) {
115      getName().add(additionalName);
116      return this;
117   }
118
119
120   /**
121    * Gets +UNCL 1001+ Document Name Code.
122    * 
123    * Profile:: BASIC
124    * 
125    * Example:: {@code 380, 381, 383, 389, 261}
126    * 
127    * @return the document name code
128    * @see http://www.unece.org/trade/untdid/d13b/tred/tred1001.htm[UN/EDIFACT 1001 Document name coe^]
129    */
130   public DocumentNameCode getCode() {
131      return code;
132   }
133   
134   /**
135    * Sets the +UNCL 1001+ Document Name Code.
136    * 
137    * Profile:: BASIC
138    * 
139    * Example:: {@code 380, 381, 383, 389, 261}
140    *
141    * @param code the new document name code
142    * @return the header document
143    * @see http://www.unece.org/trade/untdid/d13b/tred/tred1001.htm[UN/EDIFACT 1001 Document name coe^]
144    */
145
146   public Header setCode(DocumentNameCode code) {
147      this.code = code;
148      return this;
149   }
150   
151
152   /**
153    * Gets the invoice issue date time.
154    * 
155    * Profile:: BASIC
156    * 
157    * 
158    * @return the issue date time
159    */
160   public DateTime getIssued() {
161      return issued;
162   }
163
164   /**
165    * Sets the invoice issue date time.
166    * 
167    * Profile:: BASIC
168    * 
169    * 
170    * @param issued the new issue date time
171    * @return the exchanged document
172    */
173   public Header setIssued(DateTime issued) {
174      this.issued = issued;
175      return this;
176   }
177
178   /**
179    * Gets the invoice header notes.
180    * 
181    * Profile:: 
182    * - {@link Note#getContent()}: BASIC
183    * - {@link Note#getSubjectCode()}: COMFORT
184    * 
185    * Example:: 
186    * {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.}
187    * 
188    * Example:: 
189    * - {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.}
190    * - {@code note subject code as UNCL 4451: }{@link Note#getSubjectCode() AAK}
191    * 
192    * @return the included note
193    */
194   public List<Note> getNotes() {
195      if (notes == null) {
196         notes = new ArrayList<Note>();
197      }
198      return this.notes;
199   }
200
201   /**
202    * Adds a invoice header note.
203    * 
204    * Profile:: 
205    * - {@link Note#getContent()}: BASIC
206    * - {@link Note#getSubjectCode()}: COMFORT
207    * 
208    * Example:: 
209    * - {@code note content: }{@link Note#getContent() Invoice like agreed on the telephone with Mr.X.}
210    * - {@code note subject code as UNCL 4451: }{@link Note#getSubjectCode() AAK}
211    * 
212    * 
213    * @param note the note
214    * @return the exchanged document
215    */
216   public Header addNote(Note note) {
217      getNotes().add(note);
218      return this;
219   }
220
221}