tax

package
v0.67.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 19 Imported by: 14

Documentation

Overview

Package tax encapsulates models related to taxation.

Index

Constants

View Source
const (
	CategoryST  cbc.Code = "ST"  // Sales Tax
	CategoryVAT cbc.Code = "VAT" // Value Added Tax
	CategoryGST cbc.Code = "GST" // Goods and Services Tax
)

Standard tax categories that may be shared between countries.

View Source
const (
	RateExempt       cbc.Key = "exempt"
	RateZero         cbc.Key = "zero"
	RateStandard     cbc.Key = "standard"
	RateIntermediate cbc.Key = "intermediate"
	RateReduced      cbc.Key = "reduced"
	RateSuperReduced cbc.Key = "super-reduced"
	RateSpecial      cbc.Key = "special"
)

Most commonly used keys. Local regions may add their own rate keys.

View Source
const (
	TagSimplified    cbc.Key = "simplified"
	TagReverseCharge cbc.Key = "reverse-charge"
	TagCustomerRates cbc.Key = "customer-rates"
	TagSelfBilled    cbc.Key = "self-billed"
	TagPartial       cbc.Key = "partial"
)

Standard tax tags

View Source
const (
	// KeyRegime is used in the context to store the tax regime during validation.
	KeyRegime cbc.Key = "tax-regime"
)

Variables

View Source
var (
	ErrIdentityCodeInvalid = errors.New("invalid tax identity code")
)

Standard error responses to be used by regimes.

View Source
var IdentityTypeIn = func(keys ...cbc.Key) validation.Rule {
	out := make([]interface{}, len(keys))
	for i, l := range keys {
		out[i] = l
	}
	return validateTaxID{typeIn: out}
}

IdentityTypeIn checks that the identity code is within one of the acceptable keys.

View Source
var RequireIdentityCode = validateTaxID{/* contains filtered or unexported fields */}

RequireIdentityCode is an additional check to use alongside regular validation that will ensure the tax ID has a code value set.

View Source
var RequireIdentityType = validateTaxID{/* contains filtered or unexported fields */}

RequireIdentityType ensures that the identity type is set.

Functions

func ExtMapHas added in v0.65.0

func ExtMapHas(keys ...cbc.Key) validation.Rule

ExtMapHas returns a validation rule that ensures the extension map's keys match those provided.

func ExtMapRequires added in v0.65.0

func ExtMapRequires(keys ...cbc.Key) validation.Rule

ExtMapRequires returns a validation rule that ensures all the extension map's keys match those provided in the list.

func InKeyDefs added in v0.57.0

func InKeyDefs(list []*KeyDefinition) validation.Rule

InKeyDefs prepares a validation to provide a rule that will determine if the keys are in the provided set.

func RegisterRegime added in v0.34.0

func RegisterRegime(regime *Regime)

RegisterRegime adds a new regime to the shared global list of tax regimes.

func SetHasCategory added in v0.67.4

func SetHasCategory(categories ...cbc.Code) validation.Rule

SetHasCategory validates that the set contains the given category.

func ValidateInRegime added in v0.50.0

func ValidateInRegime(ctx context.Context, obj interface{}) error

ValidateInRegime ensures that the object is valid in the context of the regime.

func ValidateStructWithRegime added in v0.51.2

func ValidateStructWithRegime(ctx context.Context, obj interface{}, fields ...*validation.FieldRules) error

ValidateStructWithRegime wraps around the standard validation.ValidateStructWithContext method to add an additional check for the tax regime.

func ZoneIn added in v0.59.0

func ZoneIn(store *ZoneStore) validation.Rule

ZoneIn returns a validation rule that checks to see if the provided zone is in the store.

Types

type Category

type Category struct {
	// Code to be used in documents
	Code cbc.Code `json:"code" jsonschema:"title=Code"`

	// Short name of the category to be used instead of code in output
	Name i18n.String `json:"name" jsonschema:"title=Name"`

	// Human name for the code to use for titles
	Title i18n.String `json:"title,omitempty" jsonschema:"title=Title"`

	// Useful description of the category.
	Description *i18n.String `json:"desc,omitempty" jsonschema:"title=Description"`

	// Retained when true implies that the tax amount will be retained
	// by the buyer on behalf of the supplier, and thus subtracted from
	// the invoice taxable base total. Typically used for taxes related to
	// income.
	Retained bool `json:"retained,omitempty" jsonschema:"title=Retained"`

	// RateRequired when true implies that when a tax combo is defined using
	// this category that one of the rate's keys must be defined. This is
	// normally needed for regimes that categorize taxes in local document
	// formats as opposed to grouping by percentage values.
	RateRequired bool `json:"rate_required,omitempty" jsonschema:"title=Rate Required"`

	// Specific tax definitions inside this category.
	Rates []*Rate `json:"rates,omitempty" jsonschema:"title=Rates"`

	// Extensions defines a list of extension keys that may be used or required
	// as an alternative or alongside choosing a rate for the tax category.
	// Every key must be defined in the Regime's extensions table.
	Extensions []cbc.Key `json:"extensions,omitempty" jsonschema:"title=Extensions"`

	// Map defines a set of regime specific code mappings.
	Map cbc.CodeMap `json:"map,omitempty" jsonschema:"title=Map"`

	// List of sources for the information contained in this category.
	Sources []*Source `json:"sources,omitempty" jsonschema:"title=Sources"`

	// Meta contains additional information about the category that is relevant
	// for local frequently used formats.
	Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Category contains the definition of a general type of tax inside a region.

func (*Category) Rate added in v0.20.0

func (c *Category) Rate(key cbc.Key) *Rate

Rate provides the rate definition with a matching key for the category.

func (*Category) ValidateWithContext added in v0.65.0

func (c *Category) ValidateWithContext(ctx context.Context) error

ValidateWithContext ensures the Category's contents are correct.

type CategoryTotal

type CategoryTotal struct {
	Code      cbc.Code     `json:"code" jsonschema:"title=Code"`
	Retained  bool         `json:"retained,omitempty" jsonschema:"title=Retained"`
	Rates     []*RateTotal `json:"rates" jsonschema:"title=Rates"`
	Amount    num.Amount   `json:"amount" jsonschema:"title=Amount"`
	Surcharge *num.Amount  `json:"surcharge,omitempty" jsonschema:"title=Surcharge"`
	// contains filtered or unexported fields
}

CategoryTotal groups together all rates inside a given category.

func (*CategoryTotal) PreciseAmount added in v0.65.1

func (ct *CategoryTotal) PreciseAmount() num.Amount

PreciseAmount contains the intermediary amount generated from the calculator with the original precision. This is useful when a Category Total needs to be used for further calculations, such as when an invoice includes taxes.

type CodeDefinition added in v0.54.0

type CodeDefinition struct {
	// Code for which the definition is for.
	Code cbc.Code `json:"code" jsonschema:"title=Code"`
	// Short name for the code, if relevant.
	Name i18n.String `json:"name,omitempty" jsonschema:"title=Name"`
	// Description offering more details about when the code should be used.
	Desc i18n.String `json:"desc,omitempty" jsonschema:"title=Description"`
}

CodeDefinition describes a specific code and how it maps to a human name and description if appropriate. Regimes shouldn't typically do any additional conversion of codes, for that, regular keys should be used.

type Combo added in v0.21.0

type Combo struct {
	// Tax category code from those available inside a region.
	Category cbc.Code `json:"cat" jsonschema:"title=Category"`
	// Rate within a category to apply.
	Rate cbc.Key `json:"rate,omitempty" jsonschema:"title=Rate"`
	// Percent defines the percentage set manually or determined from the rate key (calculated if rate present).
	Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent" jsonschema_extras:"calculated=true"`
	// Some countries require an additional surcharge (calculated if rate present).
	Surcharge *num.Percentage `json:"surcharge,omitempty" jsonschema:"title=Surcharge" jsonschema_extras:"calculated=true"`
	// Local codes that apply for a given rate or percentage that need to be identified and validated.
	Ext ExtMap `json:"ext,omitempty" jsonschema:"title=Ext"`
	// contains filtered or unexported fields
}

Combo represents the tax combination of a category code and rate key. The percent and retained attributes will be determined automatically from the Rate key if set during calculation.

func (*Combo) UnmarshalJSON added in v0.50.0

func (c *Combo) UnmarshalJSON(data []byte) error

UnmarshalJSON is a temporary migration helper that will move the first of the "tags" array used in earlier versions of GOBL into the rate field.

func (*Combo) ValidateWithContext added in v0.38.0

func (c *Combo) ValidateWithContext(ctx context.Context) error

ValidateWithContext ensures the Combo has the correct details.

type CorrectionDefinition added in v0.57.0

type CorrectionDefinition struct {
	// Partial or complete schema URL for the document type supported by correction.
	Schema string `json:"schema" jsonschema:"title=Schema"`
	// The types of sub-documents supported by the regime
	Types []cbc.Key `json:"types,omitempty" jsonschema:"title=Types"`
	// Extension keys that can be included
	Extensions []cbc.Key `json:"extensions,omitempty" jsonschema:"title=Extensions"`
	// ReasonRequired when true implies that a reason must be provided
	ReasonRequired bool `json:"reason_required,omitempty" jsonschema:"title=Reason Required"`
	// Stamps that must be copied from the preceding document.
	Stamps []cbc.Key `json:"stamps,omitempty" jsonschema:"title=Stamps"`
}

CorrectionDefinition contains details about what can be defined in .

func (*CorrectionDefinition) HasExtension added in v0.67.0

func (cd *CorrectionDefinition) HasExtension(key cbc.Key) bool

HasExtension returns true if the correction definition has the change key provided.

func (*CorrectionDefinition) HasType added in v0.57.0

func (cd *CorrectionDefinition) HasType(t cbc.Key) bool

HasType returns true if the correction definition has a type that matches the one provided.

func (*CorrectionDefinition) Validate added in v0.57.0

func (cd *CorrectionDefinition) Validate() error

Validate ensures the key definition looks correct in the context of the regime.

type Error added in v0.22.1

type Error cbc.Key

Error is a general wrapper around tax errors produced during run time, typically during calculations. Not to be confused with errors produced from definition validation.

const (
	ErrMissingRegime        Error = "missing-regime"
	ErrInvalidCategory      Error = "invalid-category"
	ErrInvalidTag           Error = "invalid-tag"
	ErrInvalidRate          Error = "invalid-rate"
	ErrInvalidDate          Error = "invalid-date"
	ErrInvalidPricesInclude Error = "invalid-prices-include"
)

Standard list of tax errors

func (Error) Error added in v0.22.1

func (e Error) Error() string

Error serializes the error's message.

func (Error) WithMessage added in v0.22.1

func (e Error) WithMessage(msg string, s ...interface{}) error

WithMessage wraps around the original error so we can use if for matching and adds a human message.

type ExtMap added in v0.65.0

type ExtMap map[cbc.Key]cbc.KeyOrCode

ExtMap is a map of extension keys to either a code or a key.

func (ExtMap) Equals added in v0.65.0

func (em ExtMap) Equals(other ExtMap) bool

Equals returns true if the code map has the same keys and values as the provided map.

func (ExtMap) Has added in v0.65.0

func (em ExtMap) Has(keys ...cbc.Key) bool

Has returns true if the code map has values for all the provided keys.

func (ExtMap) JSONSchemaExtend added in v0.65.0

func (ExtMap) JSONSchemaExtend(schema *jsonschema.Schema)

JSONSchemaExtend provides extra details about the extension map which are not automatically determined. In this case we add validation for the map's keys.

func (ExtMap) ValidateWithContext added in v0.65.0

func (em ExtMap) ValidateWithContext(ctx context.Context) error

ValidateWithContext ensures the extension map data looks correct.

type Identity added in v0.34.0

type Identity struct {
	// Unique universal identity code for this tax identity.
	UUID *uuid.UUID `json:"uuid,omitempty" jsonschema:"title=UUID"`

	// ISO country code for Where the tax identity was issued.
	Country l10n.CountryCode `json:"country" jsonschema:"title=Country Code"`

	// Where inside the country the tax identity holder is based for tax purposes
	// like a village, town, district, city, county, state or province. For some
	// areas, this could be a regular post or zip code. See the regime packages
	// for specific validation rules.
	Zone l10n.Code `json:"zone,omitempty" jsonschema:"title=Zone Code"`

	// Type is set according the requirements of each regime, some have a single
	// tax document type code, others require a choice to be made.
	Type cbc.Key `json:"type,omitempty" jsonschema:"title=Type"`

	// Normalized code shown on the original identity document.
	Code cbc.Code `json:"code,omitempty" jsonschema:"title=Code"`

	// Additional details that may be required.
	Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Identity stores the details required to identify an entity for tax purposes. There are two levels of accuracy that may be used to describe where an entity is located: Country and Locality. Country is a required field, but locality is optional according to rules of a given tax jurisdiction.

func (*Identity) Calculate added in v0.34.0

func (id *Identity) Calculate() error

Calculate will attempt to perform a regional tax normalization on the tax identity.

func (*Identity) Regime added in v0.34.0

func (id *Identity) Regime() *Regime

Regime provides the regime object for this tax identity.

func (*Identity) String added in v0.35.1

func (id *Identity) String() string

String provides a string representation of the tax identity.

func (*Identity) Validate added in v0.34.0

func (id *Identity) Validate() error

Validate checks to ensure the tax ID contains all the required fields and performs any regime specific validation based on the ID's country and zone properties.

type KeyDefinition added in v0.38.0

type KeyDefinition struct {
	// Actual key value.
	Key cbc.Key `json:"key" jsonschema:"title=Key"`
	// Short name for the key.
	Name i18n.String `json:"name" jsonschema:"title=Name"`
	// Description offering more details about when the key should be used.
	Desc i18n.String `json:"desc,omitempty" jsonschema:"title=Description"`
	// Codes describes the list of codes that can be used alongside the Key,
	// for example with identities.
	Codes []*CodeDefinition `json:"codes,omitempty" jsonschema:"title=Codes"`
	// Keys is used instead of codes to define a further sub-set of keys that
	// can be used alongside this one.
	Keys []*KeyDefinition `json:"keys,omitempty" jsonschema:"title=Keys"`
	// Map helps map local keys to specific codes, useful for converting the
	// described key into a local code.
	Map cbc.CodeMap `json:"map,omitempty" jsonschema:"title=Map"`
}

KeyDefinition defines properties of a key that is specific for a regime.

func (*KeyDefinition) HasCode added in v0.55.0

func (kd *KeyDefinition) HasCode(code cbc.Code) bool

HasCode loops through the key definitions codes and determines if there is a match.

func (*KeyDefinition) HasKey added in v0.65.0

func (kd *KeyDefinition) HasKey(key cbc.Key) bool

HasKey loops through the key definitions keys and determines if there is a match.

func (*KeyDefinition) Validate added in v0.50.0

func (kd *KeyDefinition) Validate() error

Validate ensures the key definition looks correct in the context of the regime.

type Rate

type Rate struct {
	// Key identifies this rate within the system
	Key cbc.Key `json:"key" jsonschema:"title=Key"`

	// Human name of the rate
	Name i18n.String `json:"name" jsonschema:"title=Name"`
	// Useful description of the rate.
	Description i18n.String `json:"desc,omitempty" jsonschema:"title=Description"`

	// Exempt when true implies that the rate when used in a tax Combo should
	// not define a percent value.
	Exempt bool `json:"exempt,omitempty" jsonschema:"title=Exempt"`

	// Values contains a list of Value objects that contain the
	// current and historical percentage values for the rate and
	// additional filters.
	// Order is important, newer values should come before
	// older values.
	Values []*RateValue `json:"values,omitempty" jsonschema:"title=Values"`

	// Extensions defines a list of keys for codes that can or must be associated with the
	// tax rate for it to be validated. Every key must be defined in the Regime's
	// extensions.
	Extensions []cbc.Key `json:"extensions,omitempty" jsonschema:"title=Extensions"`

	// Map is used to associate specific codes with the chosen rate.
	Map cbc.CodeMap `json:"map,omitempty" jsonschema:"title=Map"`

	// Meta contains additional information about the rate that is relevant
	// for local frequently used implementations.
	Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Rate defines a single rate inside a category

func (*Rate) ValidateWithContext added in v0.65.0

func (r *Rate) ValidateWithContext(ctx context.Context) error

ValidateWithContext checks that our tax definition is valid. This is only really meant to be used when testing new regional tax definitions.

func (*Rate) Value added in v0.35.0

func (r *Rate) Value(date cal.Date, zone l10n.Code) *RateValue

Value determines the tax rate value for the provided date and zone, if applicable.

type RateTotal

type RateTotal struct {
	// Optional rate key is required when grouping.
	Key cbc.Key `json:"key,omitempty" jsonschema:"title=Key"`
	// If the rate is defined with extensions, they'll be used to group by also.
	Ext ExtMap `json:"ext,omitempty" jsonschema:"title=Ext"`
	// Base amount that the percentage is applied to.
	Base num.Amount `json:"base" jsonschema:"title=Base"`
	// Percentage of the rate, which may be nil for exempt rates.
	Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"`
	// Surcharge applied to the rate.
	Surcharge *RateTotalSurcharge `json:"surcharge,omitempty" jsonschema:"title=Surcharge"`
	// Total amount of rate, excluding surcharges
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
}

RateTotal contains a sum of all the tax rates in the document with a matching category and rate. The Key is optional as we may be using the percentage to group rates.

type RateTotalSurcharge added in v0.25.0

type RateTotalSurcharge struct {
	Percent num.Percentage `json:"percent" jsonschema:"title=Percent"`
	Amount  num.Amount     `json:"amount" jsonschema:"title=Amount"`
}

RateTotalSurcharge reflects the sum surcharges inside the rate.

type RateValue added in v0.20.0

type RateValue struct {
	// Only use this value if one of the zones matches.
	Zones []l10n.Code `json:"zones,omitempty" jsonschema:"title=Zones"`
	// Date from which this value should be applied.
	Since *cal.Date `json:"since,omitempty" jsonschema:"title=Since"`
	// Percent rate that should be applied
	Percent num.Percentage `json:"percent" jsonschema:"title=Percent"`
	// An additional surcharge to apply.
	Surcharge *num.Percentage `json:"surcharge,omitempty" jsonschema:"title=Surcharge"`
	// When true, this value should no longer be used.
	Disabled bool `json:"disabled,omitempty" jsonschema:"title=Disabled"`
}

RateValue contains a percentage rate or fixed amount for a given date range. Fiscal policy changes mean that rates are not static so we need to be able to apply the correct rate for a given period.

func (*RateValue) HasZone added in v0.35.0

func (rv *RateValue) HasZone(zone l10n.Code) bool

HasZone returns true if the rate value has a zone that matches the one provided.

func (*RateValue) Validate added in v0.20.0

func (rv *RateValue) Validate() error

Validate ensures the tax rate contains all the required fields.

type Regime added in v0.34.0

type Regime struct {
	// Name of the country
	Name i18n.String `json:"name" jsonschema:"title=Name"`

	// Introductory details about the regime.
	Description i18n.String `json:"description,omitempty" jsonschema:"title=Description"`

	// Location name for the country's central time zone. Accepted
	// values from IANA Time Zone Database (https://iana.org/time-zones).
	TimeZone string `json:"time_zone" jsonschema:"title=Time Zone"`

	// Country code for the region
	Country l10n.CountryCode `json:"country" jsonschema:"title=Code"`

	// Specific Locality, region, city, province, county, or similar code inside
	// the country, if needed.
	Zone l10n.Code `json:"zone,omitempty" jsonschema:"title=Zone"`

	// Currency used by the country.
	Currency currency.Code `json:"currency" jsonschema:"title=Currency"`

	// Tags that can be applied at the document level to identify additional
	// considerations.
	Tags []*KeyDefinition `json:"tags,omitempty" jsonschema:"title=Tags"`

	// Identity types specific for the regime and may be validated
	// against.
	IdentityTypeKeys []*KeyDefinition `json:"identity_types,omitempty" jsonschema:"title=Identity Types"`

	// Extensions defines the keys that can be used for extended or extra data inside the regime that
	// is specific to the regime and cannot be easily determined from other GOBL structures.
	// Typically these are used to define local codes for suppliers, customers, products, or tax rates.
	Extensions []*KeyDefinition `json:"extensions,omitempty" jsonschema:"title=Extensions"`

	// Charge types specific for the regime and may be validated or used in the UI as suggestions
	ChargeKeys []*KeyDefinition `json:"charge_types,omitempty" jsonschema:"title=Charge Types"`

	// PaymentMeansKeys specific for the regime that extend the original
	// base payment means keys.
	PaymentMeansKeys []*KeyDefinition `json:"payment_means,omitempty" jsonschema:"title=Payment Means"`

	// InboxKeys specific to the regime that can be used to identify where a document
	// should be forwarded to.
	InboxKeys []*KeyDefinition `json:"inbox_keys,omitempty" jsonschema:"title=Inbox Keys"`

	Scenarios []*ScenarioSet `json:"scenarios,omitempty" jsonschema:"title=Scenarios"`

	// Configuration details for corrections to be used with correction options.
	Corrections []*CorrectionDefinition `json:"corrections,omitempty" jsonschema:"title=Corrections"`

	// List of tax categories.
	Categories []*Category `json:"categories" jsonschema:"title=Categories"`

	// List of zones to identify specific areas, regions, or provinces inside a country
	// tha may be required for tax purposes.
	Zones *ZoneStore `json:"zones,omitempty"`

	// Validator is a method to use to validate a document in a given region.
	Validator func(doc interface{}) error `json:"-"`

	// Calculator is used to performs regime specific calculations on data,
	// including any normalization that might need to take place such as
	// with tax codes and removing white-space.
	Calculator func(doc interface{}) error `json:"-"`
}

Regime defines the holding structure for the definitions of taxes inside a country or territory.

func AllRegimes added in v0.34.0

func AllRegimes() []*Regime

AllRegimes provides an array of all the regime codes to definitions.

func RegimeFor added in v0.34.0

func RegimeFor(country l10n.CountryCode, locality l10n.Code) *Regime

RegimeFor returns the regime definition for country and locality combination or nil if no match was found.

func RegimeFromContext added in v0.38.0

func RegimeFromContext(ctx context.Context) *Regime

RegimeFromContext returns the regime from the given context, or nil.

func (*Regime) CalculateObject added in v0.37.0

func (r *Regime) CalculateObject(obj interface{}) error

CalculateObject performs any regime specific calculations on the provided object.

func (*Regime) Category added in v0.34.0

func (r *Regime) Category(code cbc.Code) *Category

Category provides the requested category by its code.

func (*Regime) Code added in v0.58.1

func (r *Regime) Code() cbc.Code

Code provides a unique code for this tax regime based on the country.

func (*Regime) CorrectionDefinitionFor added in v0.57.0

func (r *Regime) CorrectionDefinitionFor(schema string) *CorrectionDefinition

CorrectionDefinitionFor provides the correction definition for the matching schema.

func (*Regime) CurrencyDef added in v0.34.0

func (r *Regime) CurrencyDef() *currency.Def

CurrencyDef provides the currency definition object for the region.

func (*Regime) ExtensionDef added in v0.55.0

func (r *Regime) ExtensionDef(key cbc.Key) *KeyDefinition

ExtensionDef provides the extension definition with a matching key.

func (*Regime) InCategories added in v0.38.0

func (r *Regime) InCategories() validation.Rule

InCategories returns a validation rule to ensure the category code is inside the list of known codes.

func (*Regime) InCategoryRates added in v0.50.0

func (r *Regime) InCategoryRates(cat cbc.Code) validation.Rule

InCategoryRates is used to provide a validation rule that will ensure a rate key is defined inside a category.

func (*Regime) InTags added in v0.38.0

func (r *Regime) InTags() validation.Rule

InTags returns a validation rule to ensure the tag key is inside the list of known tags.

func (*Regime) Rate added in v0.50.0

func (r *Regime) Rate(cat cbc.Code, key cbc.Key) *Rate

Rate provides the rate definition for the provided category code and rate key.

func (*Regime) ScenarioSet added in v0.38.0

func (r *Regime) ScenarioSet(schema string) *ScenarioSet

ScenarioSet returns a single scenario set instance for the provided document schema.

func (*Regime) Tag added in v0.38.0

func (r *Regime) Tag(key cbc.Key) *KeyDefinition

Tag returns the KeyDefinition for the provided tag key

func (*Regime) TimeLocation added in v0.52.4

func (r *Regime) TimeLocation() *time.Location

TimeLocation returns the time.Location for the regime.

func (*Regime) Validate added in v0.34.0

func (r *Regime) Validate() error

Validate enures the region definition is valid, including all subsequent categories.

func (*Regime) ValidateObject added in v0.37.0

func (r *Regime) ValidateObject(value interface{}) error

ValidateObject performs validation on the provided object in the context of the regime.

func (*Regime) ValidateWithContext added in v0.65.0

func (r *Regime) ValidateWithContext(ctx context.Context) error

ValidateWithContext enures the region definition is valid, including all subsequent categories, and passes through the context.

func (*Regime) WithContext added in v0.38.0

func (r *Regime) WithContext(ctx context.Context) context.Context

WithContext adds this regime to the given context.

type RegimeCollection added in v0.34.0

type RegimeCollection struct {
	// contains filtered or unexported fields
}

RegimeCollection defines how to access details about all the regimes currently stored.

func Regimes added in v0.34.0

func Regimes() *RegimeCollection

Regimes provides the current global regime collection object.

func (*RegimeCollection) All added in v0.34.0

func (c *RegimeCollection) All() []*Regime

All provides a list of all the registered Regimes.

func (*RegimeCollection) For added in v0.34.0

func (c *RegimeCollection) For(country l10n.CountryCode, zone l10n.Code) *Regime

For provides a single matching regime from the collection, or nil if no match is found.

type Scenario added in v0.38.0

type Scenario struct {
	// Type of document, if present.
	Types []cbc.Key `json:"type,omitempty" jsonschema:"title=Type"`

	// Tag that was applied to the document
	Tags []cbc.Key `json:"tags,omitempty" jsonschema:"title=Tag"`

	// Name of the scenario for further information.
	Name i18n.String `json:"name,omitempty" jsonschema:"title=Name"`

	// A note to be added to the document if the scenario is applied.
	Note *cbc.Note `json:"note,omitempty" jsonschema:"title=Note"`

	// Codes is used to define additional codes for regime specific
	// situations.
	Codes cbc.CodeMap `json:"codes,omitempty" jsonschema:"title=Codes"`

	// Any additional local meta data that may be useful in integrations.
	Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Scenario is used to describe a tax scenario of a document based on the combination of document type and tag used.

func (*Scenario) ValidateWithContext added in v0.65.0

func (s *Scenario) ValidateWithContext(ctx context.Context) error

ValidateWithContext checks the scenario for errors, using the regime in the context to validate the list of tags.

type ScenarioSet added in v0.38.0

type ScenarioSet struct {
	// Partial or complete schema URL for the document type
	Schema string `json:"schema" jsonschema:"title=Schema"`
	// List of scenarios for the schema
	List []*Scenario `json:"list" jsonschema:"title=List"`
}

ScenarioSet is a collection of tax scenarios for a given schema that can be used to determine special codes or notes that need to be included in the final document.

func (*ScenarioSet) SummaryFor added in v0.38.0

func (ss *ScenarioSet) SummaryFor(docType cbc.Key, docTags []cbc.Key) *ScenarioSummary

SummaryFor returns a summary by applying the scenarios to the supplied document.

func (*ScenarioSet) ValidateWithContext added in v0.65.0

func (ss *ScenarioSet) ValidateWithContext(ctx context.Context) error

ValidateWithContext checks the scenario set for errors.

type ScenarioSummary added in v0.38.0

type ScenarioSummary struct {
	Notes []*cbc.Note
	Codes cbc.CodeMap
	Meta  cbc.Meta
}

ScenarioSummary is the result after running through a set of scenarios and determining which combinations of Notes and Meta are viable.

type Set added in v0.21.0

type Set []*Combo

Set defines a list of tax categories and their rates to be used alongside taxable items.

func (Set) Equals added in v0.21.0

func (s Set) Equals(s2 Set) bool

Equals returns true if the sets match, regardless of order.

func (Set) Get added in v0.21.0

func (s Set) Get(cat cbc.Code) *Combo

Get the Rate key for the given category

func (Set) Rate added in v0.21.0

func (s Set) Rate(cat cbc.Code) cbc.Key

Rate returns the rate from the matching category, if set.

func (Set) ValidateWithContext added in v0.38.0

func (s Set) ValidateWithContext(ctx context.Context) error

ValidateWithContext ensures the set of tax combos looks correct

type Source added in v0.56.0

type Source struct {
	// Title of the linked source to help distinguish between this and other links.
	Title i18n.String `json:"title,omitempty" jsonschema:"title=Title"`
	// URL for the website.
	URL string `json:"url" jsonschema:"title=URL,format=uri"`
}

Source describes where the information for the taxes comes from.

func (*Source) Validate added in v0.56.0

func (s *Source) Validate() error

Validate ensures the Source's contents are correct.

type TaxableLine

type TaxableLine interface {
	GetTaxes() Set
	GetTotal() num.Amount
}

TaxableLine defines what we expect from a line in order to subsequently calculate the taxes that need to be added or retained.

type Total

type Total struct {
	// Grouping of all the taxes by their category
	Categories []*CategoryTotal `json:"categories,omitempty" jsonschema:"title=Categories"`
	// Total value of all the taxes applied.
	Sum num.Amount `json:"sum" jsonschema:"title=Sum"`
	// contains filtered or unexported fields
}

Total contains a set of Category Totals which in turn contain all the accumulated taxes contained in the document. The resulting `sum` is that value that should be added to the payable total.

func (*Total) Category added in v0.13.0

func (t *Total) Category(code cbc.Code) *CategoryTotal

Category provides the category total for the matching code.

func (*Total) PreciseSum added in v0.57.0

func (t *Total) PreciseSum() num.Amount

PreciseSum contains an intermediary sum generated from the calculator with the original precision. If no calculations were made on the totals, such as when loading, the original sum will be provided instead.

type TotalCalculator added in v0.35.0

type TotalCalculator struct {
	Regime   *Regime
	Zone     l10n.Code
	Zero     num.Amount
	Date     cal.Date
	Lines    []TaxableLine
	Includes cbc.Code // Tax included in price
}

TotalCalculator defines the base structure with the available data for calculating tax totals.

func (*TotalCalculator) Calculate added in v0.35.0

func (tc *TotalCalculator) Calculate(t *Total) error

Calculate the totals

type Zone added in v0.34.0

type Zone struct {
	// Unique zone code.
	Code l10n.Code `json:"code" jsonschema:"title=Code"`
	// Name of the zone to be use if a locality or region is not applicable.
	Name i18n.String `json:"name,omitempty" jsonschema:"title=Name"`
	// Village, town, district, or city name which should coincide with
	// address data.
	Locality i18n.String `json:"locality,omitempty" jsonschema:"title=Locality"`
	// Province, county, or state which should match address data.
	Region i18n.String `json:"region,omitempty" jsonschema:"title=Region"`
	// Codes defines a set of regime specific code mappings.
	Codes cbc.CodeMap `json:"codes,omitempty" jsonschema:"title=Codes"`
	// Any additional information
	Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Zone represents an area inside a country, like a province or a state, which shares the basic definitions of the country, but may vary in some validation rules.

func (*Zone) Validate added in v0.34.0

func (z *Zone) Validate() error

Validate ensures that the zone looks correct.

type ZoneStore added in v0.59.0

type ZoneStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ZoneStore makes it easier to load zone information dynamically from source data.

func NewZoneStore added in v0.62.0

func NewZoneStore(fs embed.FS, filename string) *ZoneStore

NewZoneStore instantiates a new zone store that will use and embedded file system for loading the data.

func (*ZoneStore) Codes added in v0.62.0

func (s *ZoneStore) Codes() []l10n.Code

Codes provides the list of available zone codes.

func (*ZoneStore) Get added in v0.59.0

func (s *ZoneStore) Get(code l10n.Code) *Zone

Get will load the zone object from the JSON data.

func (ZoneStore) JSONSchemaAlias added in v0.62.0

func (ZoneStore) JSONSchemaAlias() any

JSONSchemaAlias provides the real object that should be defined in the schemas.

func (*ZoneStore) List added in v0.62.0

func (s *ZoneStore) List() []*Zone

List provides the complete zone list.

func (*ZoneStore) MarshalJSON added in v0.62.0

func (s *ZoneStore) MarshalJSON() ([]byte, error)

MarshalJSON ensures the zone data is loaded before marshaling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL