001/*
002 * Copyright (C) 2014 konik.io
003 *
004 * This file is part of Konik library.
005 *
006 * Konik library is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Konik library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with Konik library.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package io.konik.zugferd.entity;
020
021import static io.konik.util.Strings.isNotEmpty;
022import io.konik.validator.annotation.NotBlank;
023import io.konik.zugferd.unece.codes.Reference;
024import io.konik.zugferd.unqualified.ID;
025
026import javax.validation.constraints.NotNull;
027import javax.xml.bind.annotation.XmlElement;
028import javax.xml.bind.annotation.XmlType;
029
030/**
031 * = The Tax Registration
032 * 
033 * Represents the tax number and its type.
034 * The {@link ID#getValue()} is value added tax identification number
035 * The {@link ID#getSchemeId()} is the Tax payer's number or VAT number according to (UNCL 1153) eg. FC or VA
036 */
037@XmlType(name = "TaxRegistrationType", propOrder = { "id" })
038public class TaxRegistration {
039
040   @XmlElement(name = "ID")
041   private ID id;
042
043   /** Instantiates a new tax registration. */
044   public TaxRegistration() {
045      this.id = new ID();
046   }
047
048   /**
049    * Instantiates a new tax registration without a type.
050    * 
051    * @param taxNumber the id
052    */
053   public TaxRegistration(String taxNumber) {
054      this.id = new ID(taxNumber);
055   }
056
057   /**
058    * Instantiates a new tax registration.
059    * 
060    * @param taxNumber the tax id
061    * @param typeOfTax the scheme id
062    */
063   public TaxRegistration(String taxNumber, Reference typeOfTax) {
064      this.id = new ID(taxNumber, typeOfTax.getCode());
065   }
066
067   /**
068    * Gets the tax number.
069    * 
070    * Example:: {@code DE234567891}
071    * 
072    * @return the number
073    */
074   @NotBlank
075   public String getTaxNumber() {
076      return id.getValue();
077   }
078
079   /**
080    * Sets the tax number.
081    * 
082    * Example:: {@code DE234567891}
083    *
084    * @param taxNumber the new value
085    * @return the tax registration
086    */
087   public TaxRegistration setTaxNumber(String taxNumber) {
088      if (isNotEmpty(taxNumber)) {
089         this.id.setValue(taxNumber);
090      }
091      return this;
092   }
093
094   /**
095    * Gets the tax type. The UNCL 1153 tax type.
096    * 
097    * Example:: {@code VA}
098    *
099    * @return the type
100    */
101   @NotNull
102   public Reference getType() {
103      return Reference.getByCode(id.getSchemeId());
104   }
105
106   /**
107    * Sets the UNCL 1153 tax type.
108    * 
109    * Example:: {@code VA}
110    *
111    * @param taxType the new type
112    * @return the tax registration
113    */
114   public TaxRegistration setType(Reference taxType) {
115      if (taxType != null) {
116         this.id.setSchemeId(taxType.getCode());
117      }
118      return this;
119   }
120
121}