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