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.bindable.unqualified.PercentRoundingAdapter;
021import io.konik.validator.annotation.Comfort;
022import io.konik.zugferd.unece.codes.TaxCategory;
023import io.konik.zugferd.unece.codes.TaxCode;
024import io.konik.zugferd.unqualified.Amount;
025
026import java.math.BigDecimal;
027
028import javax.validation.Valid;
029import javax.validation.constraints.NotNull;
030import javax.xml.bind.annotation.XmlElement;
031import javax.xml.bind.annotation.XmlTransient;
032import javax.xml.bind.annotation.XmlType;
033import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
034
035/**
036 * = The common trade tax
037 * 
038 * 
039 * image::http://yuml.me/0d095a59[Tax Class diagram,link="http://yuml.me/edit/0d095a59"]
040 * 
041 * The complexity of this hierarchy is also result of the validation path, we can not override constraints.
042 */
043@XmlTransient
044@XmlType(name = "TradeTaxType", propOrder = { "calculated", "type", "exemptionReason", "basis", "lineTotal",
045      "allowanceCharge", "category", "percentage" })
046/* 
047HIRACHY TOP DOWN
048as AppliedTradeTax|CategoryTradeTax only   TypeCode, CategoryCode, ApplicablePercent
049   as ApplicableTradeTax in ITEM             +CalculatedAmount, +ExemptionReason
050      as ApplicableTradeTax in TRADE            +BasisAmount, +LineTotalBasisAmount, +AllowanceChargeBasisAmount
051 */
052public abstract class CommonTax {
053
054   @XmlElement(name = "CalculatedAmount")
055   protected Amount calculated;
056
057   @XmlElement(name = "TypeCode")
058   protected TaxCode type;
059
060   @XmlElement(name = "ExemptionReason")
061   protected String exemptionReason;
062
063   @Valid
064   @XmlElement(name = "BasisAmount")
065   protected Amount basis;
066
067   @Valid
068   @XmlElement(name = "LineTotalBasisAmount")
069   protected Amount lineTotal;
070
071   @Valid
072   @XmlElement(name = "AllowanceChargeBasisAmount")
073   protected Amount allowanceCharge;
074
075   @XmlElement(name = "CategoryCode")
076   protected TaxCategory category;
077
078   @XmlElement(name = "ApplicablePercent")
079   @XmlJavaTypeAdapter(PercentRoundingAdapter.class)
080   protected BigDecimal percentage;
081
082   /**
083    * Gets the UNCL 5153 tax type code.
084    * 
085    * @return the type code
086    */
087   public TaxCode getType() {
088      return type;
089   }
090
091   /**
092    * Sets the UNCL 5153 tax type code.
093    * 
094    * @param taxTypeCode the tax type code
095    * @return the tax
096    * @see <a href="http://www.unece.org/trade/untdid/d98b/uncl/uncl5153.htm">UNCL 5153</a>
097    */
098   public CommonTax setType(TaxCode taxTypeCode) {
099      this.type = taxTypeCode;
100      return this;
101   }
102
103   /**
104    * Gets the tax category.
105    * 
106    * @return the category code
107    */
108   public TaxCategory getCategory() {
109      return category;
110   }
111
112   /**
113    * Sets the tax category.
114    * 
115    * @param value the new category code
116    * @return the tax
117    */
118   public CommonTax setCategory(TaxCategory value) {
119      this.category = value;
120      return this;
121   }
122
123   /**
124    * Gets the applicable tax percentage.
125    * 
126    * @return the applicable tax percentage
127    */
128   @NotNull(groups = Comfort.class)
129   public BigDecimal getPercentage() {
130      return percentage;
131   }
132
133   /**
134    * Sets the applicable tax percentage.
135    * 
136    * @param applicablePercentage the new applicable tax percentage
137    * @return the tax
138    */
139   public CommonTax setPercentage(BigDecimal applicablePercentage) {
140      this.percentage = applicablePercentage;
141      return this;
142   }
143}