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   @Valid
055   @XmlElement(name = "CalculatedAmount")
056   protected Amount calculated;
057
058   @XmlElement(name = "TypeCode")
059   protected TaxCode type;
060
061   @XmlElement(name = "ExemptionReason")
062   protected String exemptionReason;
063
064   @Valid
065   @XmlElement(name = "BasisAmount")
066   protected Amount basis;
067
068   @Valid
069   @XmlElement(name = "LineTotalBasisAmount")
070   protected Amount lineTotal;
071
072   @Valid
073   @XmlElement(name = "AllowanceChargeBasisAmount")
074   protected Amount allowanceCharge;
075
076   @XmlElement(name = "CategoryCode")
077   protected TaxCategory category;
078
079   @XmlElement(name = "ApplicablePercent")
080   @XmlJavaTypeAdapter(PercentRoundingAdapter.class)
081   protected BigDecimal percentage;
082
083   /**
084    * Gets the UNCL 5153 tax type code.
085    * 
086    * @return the type code
087    */
088   public TaxCode getType() {
089      return type;
090   }
091
092   /**
093    * Sets the UNCL 5153 tax type code.
094    * 
095    * @param taxTypeCode the tax type code
096    * @return the tax
097    * @see <a href="http://www.unece.org/trade/untdid/d98b/uncl/uncl5153.htm">UNCL 5153</a>
098    */
099   public CommonTax setType(TaxCode taxTypeCode) {
100      this.type = taxTypeCode;
101      return this;
102   }
103
104   /**
105    * Gets the tax category.
106    * 
107    * @return the category code
108    */
109   public TaxCategory getCategory() {
110      return category;
111   }
112
113   /**
114    * Sets the tax category.
115    * 
116    * @param value the new category code
117    * @return the tax
118    */
119   public CommonTax setCategory(TaxCategory value) {
120      this.category = value;
121      return this;
122   }
123
124   /**
125    * Gets the applicable tax percentage.
126    * 
127    * @return the applicable tax percentage
128    */
129   @NotNull(groups = Comfort.class)
130   public BigDecimal getPercentage() {
131      return percentage;
132   }
133
134   /**
135    * Sets the applicable tax percentage.
136    * 
137    * @param applicablePercentage the new applicable tax percentage
138    * @return the tax
139    */
140   public CommonTax setPercentage(BigDecimal applicablePercentage) {
141      this.percentage = applicablePercentage;
142      return this;
143   }
144}