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.trade;
019
020import java.util.ArrayList;
021import java.util.List;
022
023import javax.validation.Valid;
024import javax.validation.constraints.NotNull;
025import javax.xml.bind.annotation.XmlElement;
026import javax.xml.bind.annotation.XmlType;
027import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
028
029import com.neovisionaries.i18n.CurrencyCode;
030
031import io.konik.jaxb.bindable.entity.AccountingAccountAdapter;
032import io.konik.validator.annotation.Basic;
033import io.konik.validator.annotation.Comfort;
034import io.konik.validator.annotation.Extended;
035import io.konik.zugferd.entity.CommonSettlement;
036import io.konik.zugferd.entity.LogisticsServiceCharge;
037import io.konik.zugferd.entity.PaymentMeans;
038import io.konik.zugferd.entity.PaymentTerm;
039import io.konik.zugferd.entity.Period;
040import io.konik.zugferd.entity.SpecifiedAllowanceCharge;
041import io.konik.zugferd.entity.TradeParty;
042
043/**
044 * = The Trade Settlement
045 * 
046 * Contains trade specific payment and price related informations
047 */
048@XmlType(propOrder = { "paymentReference", "currency", "invoicee", "payee", "paymentMeans", "tradeTax", "billingPeriod",
049      "allowanceCharge", "serviceCharge", "paymentTerms", "monetarySummation", "costCenter" })
050public class Settlement implements CommonSettlement<TradeTax, MonetarySummation> {
051
052   @XmlElement(name = "PaymentReference")
053   private String paymentReference;
054
055   @XmlElement(name = "InvoiceCurrencyCode")
056   private CurrencyCode currency;
057
058   @XmlElement(name = "InvoiceeTradeParty")
059   private TradeParty invoicee;
060
061   @XmlElement(name = "PayeeTradeParty")
062   private TradeParty payee;
063
064   @XmlElement(name = "SpecifiedTradeSettlementPaymentMeans")
065   private List<PaymentMeans> paymentMeans;
066
067   @XmlElement(name = "ApplicableTradeTax")
068   private List<TradeTax> tradeTax;
069
070   @XmlElement(name = "BillingSpecifiedPeriod")
071   private Period billingPeriod;
072
073   @XmlElement(name = "SpecifiedTradeAllowanceCharge")
074   private List<SpecifiedAllowanceCharge> allowanceCharge;
075
076   @XmlElement(name = "SpecifiedLogisticsServiceCharge")
077   private List<LogisticsServiceCharge> serviceCharge;
078
079   @XmlElement(name = "SpecifiedTradePaymentTerms")
080   private List<PaymentTerm> paymentTerms;
081
082   @XmlElement(name = "SpecifiedTradeSettlementMonetarySummation")
083   private MonetarySummation monetarySummation;
084
085   @XmlElement(name = "ReceivableSpecifiedTradeAccountingAccount")
086   @XmlJavaTypeAdapter(AccountingAccountAdapter.class)
087   private String costCenter;
088
089   /**
090    * Gets the payment reference.
091    * 
092    * Can be same as invoice number.
093    * 
094    * @return the payment reference
095    */
096   @Basic
097   public String getPaymentReference() {
098      return paymentReference;
099   }
100
101   /**
102    * Sets the payment reference or note to payee
103    * 
104    * Can be same as invoice number.
105    *
106    * @param referenceText the reference text
107    * @return the trade settlement
108    */
109   public Settlement setPaymentReference(String referenceText) {
110      this.paymentReference = referenceText;
111      return this;
112   }
113
114   /**
115    * Gets the invoice currency code
116    * specifiedBookingReference
117    *
118    * @return the +ISO 4217 3A+ currency code
119    */
120   @Basic
121   @NotNull
122   public CurrencyCode getCurrency() {
123      return currency;
124   }
125
126   /**
127    * Sets the invoice currency code.
128    *
129    * @param currency the new currency
130    * @return the trade settlement
131    */
132   public Settlement setCurrency(CurrencyCode currency) {
133      this.currency = currency;
134      return this;
135   }
136
137   /**
138    * Gets the details on the alternative invoicee. 
139    * 
140    * Additional role, if different from Buyer
141    * 
142    * @return the invoicee trade party
143    */
144   @Valid
145   @Comfort
146   public TradeParty getInvoicee() {
147      return invoicee;
148   }
149
150   /**
151    * Sets the details on the alternative invoicee.
152    * 
153    * Additional role, if different from Buyer
154    * 
155    * @param invoicee the new invoicee trade party
156    * @return the trade settlement
157    */
158   public Settlement setInvoicee(TradeParty invoicee) {
159      this.invoicee = invoicee;
160      return this;
161   }
162
163   /**
164    * Gets the payee.
165    *
166    * @return the payee
167    */
168   @Valid
169   @Extended
170   public TradeParty getPayee() {
171      return payee;
172   }
173
174   /**
175    * Sets the payee.
176    *
177    * @param payee the payee
178    * @return the trade settlement
179    */
180   public Settlement setPayee(TradeParty payee) {
181      this.payee = payee;
182      return this;
183   }
184
185   /**
186    * Gets the specified trade settlement payment means.
187    *
188    * @return the specified trade settlement payment means
189    */
190   @Valid
191   public List<PaymentMeans> getPaymentMeans() {
192      if (paymentMeans == null) {
193         paymentMeans = new ArrayList<PaymentMeans>();
194      }
195      return this.paymentMeans;
196   }
197
198   /**
199    * Adds the payment method.
200    *
201    * @param newPaymentMethod the new payment method
202    * @return the trade settlement
203    */
204   public Settlement addPaymentMeans(PaymentMeans newPaymentMethod) {
205      getPaymentMeans().add(newPaymentMethod);
206      return this;
207   }
208
209   /**
210    * Gets the applicable trade tradeTax.
211    *
212    * @return the applicable trade tradeTax
213    */
214   @Override
215   public List<TradeTax> getTradeTax() {
216      if (tradeTax == null) {
217         tradeTax = new ArrayList<TradeTax>();
218      }
219      return this.tradeTax;
220   }
221
222   /**
223    * Adds a trade tradeTax.
224    *
225    * @param additionalTradeTax the additional trade tradeTax
226    * @return the trade settlement
227    */
228   @Override
229   public Settlement addTradeTax(TradeTax additionalTradeTax) {
230      getTradeTax().add(additionalTradeTax);
231      return this;
232   }
233
234   /**
235    * Gets the billing specified period.
236    * 
237    * @return the billing specified period
238    */
239   @Valid
240   @Comfort
241   @Override
242   public Period getBillingPeriod() {
243      return billingPeriod;
244   }
245
246   /**
247    * Sets the billing specified period.
248    *
249    * @param billingPeriod the new billing specified period
250    * @return the trade settlement
251    */
252   @Override
253   public Settlement setBillingPeriod(Period billingPeriod) {
254      this.billingPeriod = billingPeriod;
255      return this;
256   }
257
258   /**
259    * Gets the trade allowance charge.
260    * 
261    * @return the specified trade allowance charge
262    */
263   @Comfort
264   public List<SpecifiedAllowanceCharge> getAllowanceCharge() {
265      if (allowanceCharge == null) {
266         allowanceCharge = new ArrayList<SpecifiedAllowanceCharge>();
267      }
268      return this.allowanceCharge;
269   }
270
271   /**
272    * Adds the trade allowance charge.
273    *
274    * @param additionalAllowanceCharge an additional allowance charge
275    * @return the trade settlement
276    */
277   @Comfort
278   public Settlement addAllowanceCharge(SpecifiedAllowanceCharge additionalAllowanceCharge) {
279      getAllowanceCharge().add(additionalAllowanceCharge);
280      return this;
281   }
282
283   /**
284    * Gets the specified logistics service charge.
285    * 
286    * @return the specified logistics service charge
287    */
288   @Comfort
289   public List<LogisticsServiceCharge> getServiceCharge() {
290      if (serviceCharge == null) {
291         serviceCharge = new ArrayList<LogisticsServiceCharge>();
292      }
293      return this.serviceCharge;
294   }
295
296   /**
297    * Adds the specified logistics service charge.
298    *
299    * @param logisticsServiceCharge the logistics service charge
300    * @return the trade settlement
301    */
302   @Comfort
303   public Settlement addServiceCharge(LogisticsServiceCharge logisticsServiceCharge) {
304      getServiceCharge().add(logisticsServiceCharge);
305      return this;
306   }
307
308   /**
309    * Gets the specified trade payment terms.
310    * 
311    * @return the specified trade payment terms
312    */
313   @Comfort
314   public List<PaymentTerm> getPaymentTerms() {
315      if (paymentTerms == null) {
316         paymentTerms = new ArrayList<PaymentTerm>();
317      }
318      return this.paymentTerms;
319   }
320
321   /**
322    * Adds a Payment Term.
323    *
324    * @param additionalPaymentTerm the additional payment term
325    * @return the trade settlement
326    */
327   @Comfort
328   public Settlement addPaymentTerm(PaymentTerm additionalPaymentTerm) {
329      getPaymentTerms().add(additionalPaymentTerm);
330      return this;
331   }
332
333   /**
334    * Gets the trade settlement monetary summation.
335    * 
336    * @return the specified trade settlement monetary summation
337    */
338   @Basic
339   @Valid
340   @NotNull
341   @Override
342   public MonetarySummation getMonetarySummation() {
343      return monetarySummation;
344   }
345
346   /**
347    * Sets the trade settlement monetary summation.
348    *
349    * @param monetarySummation the new monetary summation
350    * @return the trade settlement
351    */
352   @Basic
353   @Override
354   public Settlement setMonetarySummation(MonetarySummation monetarySummation) {
355      this.monetarySummation = monetarySummation;
356      return this;
357   }
358
359   /**
360    * Gets the booking reference or cost center account.
361    *
362    * @return the account of the booking reference
363    */
364   @Extended
365   public String getCostCenter() {
366      return costCenter;
367   }
368
369   /**
370    * Sets  the booking reference or cost center account.
371    *
372    * @param costCenter the booking reference or cost center account.
373    * @return the trade settlement
374    */
375   public Settlement setCostCenter(String costCenter) {
376      this.costCenter = costCenter;
377      return this;
378   }
379
380}