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 io.konik.zugferd.unqualified.Indicator.falseIndicator;
021import static io.konik.zugferd.unqualified.Indicator.trueIndicator;
022
023import java.math.BigDecimal;
024
025import javax.validation.Valid;
026import javax.validation.constraints.NotNull;
027import javax.xml.bind.annotation.XmlElement;
028import javax.xml.bind.annotation.XmlType;
029import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
030import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
031
032import io.konik.jaxb.adapter.FourDigitRoundingAdapter;
033import io.konik.jaxb.bindable.unqualified.PercentRoundingAdapter;
034import io.konik.validator.annotation.Comfort;
035import io.konik.validator.annotation.Extended;
036import io.konik.zugferd.unqualified.Amount;
037import io.konik.zugferd.unqualified.Indicator;
038import io.konik.zugferd.unqualified.Quantity;
039
040/**
041 * = The Allowance Charge
042 * 
043 * Represents a trade surcharge or discount and contains reason information for that.
044 */
045@XmlType(name = "TradeAllowanceChargeType", propOrder = { "surcharge", "sequence", "calculationPercent", "basis",
046      "basisQuantity", "actual", "reasonCode", "reason" })
047@XmlJavaTypeAdapter(FourDigitRoundingAdapter.class)
048public class AllowanceCharge implements CommonAllowanceCharge {
049
050   @XmlElement(name = "ChargeIndicator")
051   private Indicator surcharge;
052
053   @XmlElement(name = "SequenceNumeric")
054   private BigDecimal sequence;
055
056   @XmlElement(name = "CalculationPercent")
057   @XmlJavaTypeAdapter(PercentRoundingAdapter.class)
058   private BigDecimal calculationPercent;
059
060   @XmlElement(name = "BasisAmount")
061   @XmlJavaTypeAdapter(FourDigitRoundingAdapter.class)
062   private Amount basis;
063
064   @XmlElement(name = "BasisQuantity")
065   private Quantity basisQuantity;
066
067   @XmlElement(name = "ActualAmount")
068   @XmlJavaTypeAdapter(FourDigitRoundingAdapter.class)
069   private Amount actual;
070
071   @XmlElement(name = "ReasonCode")
072   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
073   private String reasonCode;
074
075   @XmlElement(name = "Reason")
076   private String reason;
077
078   /**
079    * Instantiates a new allowance charge.
080    */
081   public AllowanceCharge() {
082      surcharge = Indicator.falseIndicator();
083   }
084
085   /**
086    * Checks if is a surcharge.
087    *
088    * @return true if charge
089    */
090   @Override
091   @NotNull(groups = Comfort.class)
092   public boolean isSurcharge() {
093      return surcharge.getIndicator();
094   }
095
096   /**
097    * Checks if is discount.
098    *
099    * @return true if is discount
100    */
101   @Override
102   @NotNull(groups = Comfort.class)
103   public boolean isDiscount() {
104      return !surcharge.getIndicator();
105   }
106
107   /**
108    * Sets amount to be a surcharge.
109    *
110    * @return the allowance charge to be true
111    */
112   @Override
113   public AllowanceCharge setSurcharge() {
114      this.surcharge = trueIndicator();
115      return this;
116   }
117
118   /**
119    * Sets the amount to be a discount.
120    *
121    * @return the allowance discount to be true
122    */
123   @Override
124   public AllowanceCharge setDiscount() {
125      this.surcharge = falseIndicator();
126      return this;
127   }
128
129   /**
130    * Gets the sequence number of the allowance charge
131    *
132    * @return the sequence
133    */
134   @Override
135   @Extended
136   public BigDecimal getSequence() {
137      return sequence;
138   }
139
140   /**
141    * Sets the sequence number of the allowance charge.
142    *
143    * @param sequence the new sequence
144    * @return the allowance charge
145    */
146   @Override
147   public AllowanceCharge setSequence(BigDecimal sequence) {
148      this.sequence = sequence;
149      return this;
150   }
151
152   /**
153    * Gets the calculation percent of the allowance charge
154    *
155    * @return the calculation percent
156    */
157   @Override
158   @Extended
159   public BigDecimal getCalculationPercent() {
160      return calculationPercent;
161   }
162
163   /**
164    * Sets the calculation percent of the allowance charge.
165    *
166    * @param calculationPercent the new calculation percent
167    * @return the allowance charge
168    */
169   @Override
170   public AllowanceCharge setCalculationPercent(BigDecimal calculationPercent) {
171      this.calculationPercent = calculationPercent;
172      return this;
173   }
174
175   /**
176    * Gets the basis amount of the allowance charge.
177    * 
178    * @return the basis amount
179    */
180   @Override
181   @Valid
182   @Extended
183   public Amount getBasis() {
184      return basis;
185   }
186
187   /**
188    * Sets the basis amount of the allowance charge.
189    *
190    * @param basisAmount the new basis amount
191    * @return the allowance charge
192    */
193   @Override
194   public AllowanceCharge setBasis(Amount basisAmount) {
195      this.basis = basisAmount;
196      return this;
197   }
198
199   /**
200    * Gets the basis quantity.
201    *
202    * @return the basis quantity
203    */
204   @Override
205   @Extended
206   @Valid
207   public Quantity getBasisQuantity() {
208      return basisQuantity;
209   }
210
211   /**
212    * Sets the basis quantity.
213    *
214    * @param basisQuantity the new basis quantity
215    * @return the allowance charge
216    */
217   @Override
218   public AllowanceCharge setBasisQuantity(Quantity basisQuantity) {
219      this.basisQuantity = basisQuantity;
220      return this;
221   }
222
223   /**
224    * Gets the actual amount.
225    * 
226    * @return the actual amount
227    */
228   @Override
229   @Valid
230   @NotNull(groups = Comfort.class)
231   public Amount getActual() {
232      return actual;
233   }
234
235   /**
236    * Sets the actual amount.
237    *
238    * @param actualAmount the new actual amount
239    * @return the allowance charge
240    */
241   @Override
242   public AllowanceCharge setActual(Amount actualAmount) {
243      this.actual = actualAmount;
244      return this;
245   }
246
247   /**
248    * Gets the reason code for the reason content.
249    *
250    * @return the reason code
251    */
252   @Override
253   @Extended
254   public String getReasonCode() {
255      return reasonCode;
256   }
257
258   /**
259    * Sets the reason code for the reason content.
260    *
261    * @param reasonCode the new reason code
262    * @return the allowance charge
263    */
264   @Override
265   public AllowanceCharge setReasonCode(String reasonCode) {
266      this.reasonCode = reasonCode;
267      return this;
268   }
269
270   /**
271    * Gets the reason free text
272    * 
273    * @return the reason
274    */
275   @Override
276   @Comfort
277   public String getReason() {
278      return reason;
279   }
280
281   /**
282    * Sets the reason free text
283    *
284    * @param reason the new reason
285    * @return the allowance charge
286    */
287   @Override
288   public AllowanceCharge setReason(String reason) {
289      this.reason = reason;
290      return this;
291   }
292
293}