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