com.helger.masterdata.vat.IVATItem Maven / Gradle / Ivy
/**
* Copyright (C) 2014-2018 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.masterdata.vat;
import java.math.BigDecimal;
import java.util.Locale;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.helger.commons.annotation.MustImplementEqualsAndHashcode;
import com.helger.commons.equals.EqualsHelper;
import com.helger.commons.id.IHasID;
import com.helger.commons.math.MathHelper;
import com.helger.commons.text.display.IHasDisplayText;
import com.helger.datetime.period.ILocalDatePeriod;
/**
* Defines a single VAT item valid within a country.
*
* @author Philip Helger
*/
@MustImplementEqualsAndHashcode
public interface IVATItem extends IHasDisplayText, IHasID
{
/**
* @return The non-null
type of this item.
*/
@Nonnull
EVATItemType getType ();
/**
* @return The country for which this VAT item is applicable. May be
* null
for 0% items only!
* @since 5.0.6
*/
@Nullable
Locale getCountry ();
/**
* @return true
if a country is present, false
* otherwise.
* @since 5.0.6
*/
default boolean hasCountry ()
{
return getCountry () != null;
}
/**
* @return The percentage of this VAT type. Must be between 0 and 100.
*/
@Nonnull
@Nonnegative
BigDecimal getPercentage ();
/**
* Check if this VAT item has the passed percentage.
*
* @param aPercentage
* The percentage to be checked. May be null
.
* @return true
if the passed percentage equals the contained
* percentage.
*/
default boolean hasPercentage (@Nullable final BigDecimal aPercentage)
{
return EqualsHelper.equals (getPercentage (), aPercentage);
}
/**
* @return true
if the percentage is 0.
*/
default boolean isZeroPercentage ()
{
return MathHelper.isEQ0 (getPercentage ());
}
/**
* @return true
if the percentage is > 0.
*/
default boolean isNonZeroPercentage ()
{
return MathHelper.isNE0 (getPercentage ());
}
/**
* @return The factor (e.g. 0.2 for 20% or 0.5 for 50%). Always ≥ 0 (for 0%
* VAT) and ≤ 1 (for 100% VAT) (equals
* getPercentage() / 100
)
*/
@Nonnull
@Nonnegative
BigDecimal getPercentageFactor ();
/**
* @return The multiplication factor (e.g. 1.2 for 20% or 1.5 for 50%). Always
* ≥ 1 (for 0% VAT) and ≤ 2 (for 100% VAT). It can also be used
* to calculate the net from the gross price by calling
* gross.divide (factor)
. The result equals
* 1 + getPercentageFactor()
which in turn is
* 1 + getPercentage() / 100
.
*/
@Nonnull
@Nonnegative
BigDecimal getMultiplicationFactorNetToGross ();
/**
* @return true
if this item is deprecated and a new VAT item
* applies now.
*/
boolean isDeprecated ();
/**
* @return The validity period of this item. May not be null
.
*/
@Nonnull
ILocalDatePeriod getPeriod ();
}