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 io.konik.validator.annotation.NotBlank;
022import io.konik.zugferd.unece.codes.Reference;
023import io.konik.zugferd.unqualified.ID;
024
025import javax.validation.constraints.NotNull;
026import javax.xml.bind.annotation.XmlElement;
027import javax.xml.bind.annotation.XmlType;
028import java.io.Serializable;
029
030import static io.konik.util.Strings.isNotEmpty;
031
032/**
033 * = The Tax Registration
034 * 
035 * Represents the tax number and its type.
036 * The {@link ID#getValue()} is value added tax identification number
037 * The {@link ID#getSchemeId()} is the Tax payer's number or VAT number according to (UNCL 1153) eg. FC or VA
038 */
039@XmlType(name = "TaxRegistrationType", propOrder = { "id" })
040public class TaxRegistration implements Serializable {
041
042   @XmlElement(name = "ID")
043   private ID id;
044
045   /** Instantiates a new tax registration. */
046   public TaxRegistration() {
047      this.id = new ID();
048   }
049
050   /**
051    * Instantiates a new tax registration without a type.
052    * 
053    * @param taxNumber the id
054    */
055   public TaxRegistration(String taxNumber) {
056      this.id = new ID(taxNumber);
057   }
058
059   /**
060    * Instantiates a new tax registration.
061    * 
062    * @param taxNumber the tax id
063    * @param typeOfTax the scheme id
064    */
065   public TaxRegistration(String taxNumber, Reference typeOfTax) {
066      this.id = new ID(taxNumber, typeOfTax.getCode());
067   }
068
069   /**
070    * Gets the tax number.
071    * 
072    * Example:: {@code DE234567891}
073    * 
074    * @return the number
075    */
076   @NotBlank
077   public String getTaxNumber() {
078      return id.getValue();
079   }
080
081   /**
082    * Sets the tax number.
083    * 
084    * Example:: {@code DE234567891}
085    *
086    * @param taxNumber the new value
087    * @return the tax registration
088    */
089   public TaxRegistration setTaxNumber(String taxNumber) {
090      if (isNotEmpty(taxNumber)) {
091         this.id.setValue(taxNumber);
092      }
093      return this;
094   }
095
096   /**
097    * Gets the tax type. The UNCL 1153 tax type.
098    * 
099    * Example:: {@code VA}
100    *
101    * @return the type
102    */
103   @NotNull
104   public Reference getType() {
105      return Reference.getByCode(id.getSchemeId());
106   }
107
108   /**
109    * Sets the UNCL 1153 tax type.
110    * 
111    * Example:: {@code VA}
112    *
113    * @param taxType the new type
114    * @return the tax registration
115    */
116   public TaxRegistration setType(Reference taxType) {
117      if (taxType != null) {
118         this.id.setSchemeId(taxType.getCode());
119      }
120      return this;
121   }
122
123}