tax

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Code Code        `json:"code" jsonschema:"title=Code"`
	Name i18n.String `json:"name" jsonschema:"title=Name"`
	Desc 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.
	Retained bool `json:"retained,omitempty" jsonschema:"title=Retained,description=This tax should be retained, not added, from the sum."`

	// Rates array
	Defs []Def `json:"defs" jsonschema:"title=Definitions,descriptions=Specific tax definitions inside this category."`
}

Category

func (Category) Def

func (c Category) Def(code Code) (Def, bool)

Def provides the rate definition with a matching code for the category.

func (Category) Validate

func (c Category) Validate() error

Validate ensures the Category's contents are correct.

type CategoryTotal

type CategoryTotal struct {
	Code     Code         `json:"code" jsonschema:"title=Code"`
	Retained bool         `json:"retained,omitempty" jsonschema:"title=Retained"`
	Rates    []*RateTotal `json:"rates" jsonschema:"title=Rates"`
	Base     num.Amount   `json:"base" jsonschema:"title=Base"`
	Value    num.Amount   `json:"value" jsonschema:"title=Value"`
}

CategoryTotal groups together all rates inside a given category.

func NewCategoryTotal

func NewCategoryTotal(code Code, retained bool, zero num.Amount) *CategoryTotal

NewCategoryTotal prepares a category total calculation.

type Code

type Code string

Code represents a string used to uniquely identify the data we're looking at. We use "code" instead of "id", to reenforce the fact that codes should be more easily set and used by humans within definitions than IDs or UUIDs. Codes are standardised so that when validated they must contain between 2 and 6 inclusive upper-case letters or numbers.

func (Code) Validate

func (c Code) Validate() error

Validate ensures that the code complies with the expected rules.

type Def

type Def struct {
	// Code identifies this rate within the system
	Code Code `json:"code" jsonschema:"title=Code"`

	Name i18n.String `json:"name" jsonschema:"title=Name"`
	Desc i18n.String `json:"desc,omitempty" jsonschema:"title=Description"`

	// Values contains a list of Value objects that contain the
	// current and historical percentage values for the rate.
	// Order is important, newer values should come before
	// older values.
	Values []Value `` /* 128-byte string literal not displayed */
}

Def defines a tax combination of category and rate.

func (Def) On

func (d Def) On(date org.Date) (Value, bool)

On determines the tax rate value for the provided date.

func (Def) Validate

func (d Def) Validate() error

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

type Rate

type Rate struct {
	Category Code `json:"cat" jsonschema:"title=Category Code,description=From the available options for the region."`
	Code     Code `json:"code" jsonschema:"title=Code,description=As defined for the region and category."`
}

Rate references the tax category and rate code that should be applied to this line item when calculating the final taxes.

func (*Rate) Validate

func (r *Rate) Validate() error

Validate ensures the Rate contains all the details required.

type RateTotal

type RateTotal struct {
	Code    Code           `json:"code" jsonschema:"title=Code"`
	Base    num.Amount     `json:"base" jsonschema:"title=Base"`
	Percent num.Percentage `json:"percent" jsonschema:"title=Percent"`
	Value   num.Amount     `json:"value" jsonschema:"title=Value"`
	// contains filtered or unexported fields
}

RateTotal contains a sum of all the tax rates in the document with a matching category and definition.

func NewRateTotal

func NewRateTotal(code Code, percent num.Percentage, zero num.Amount) *RateTotal

type Rates

type Rates []*Rate

Rates contains a list of taxes, usually applied to an invoice line or item.

func (Rates) Equals

func (rs Rates) Equals(rs2 Rates) bool

Equals returns true if the array of rates match, regardless of order.

func (Rates) Validate

func (rs Rates) Validate() error

Validate ensures the rates array looks correct.

type Region

type Region struct {
	Code       Code        `json:"code" jsonschema:"title=Code"`
	Name       i18n.String `json:"name" jsonschema:"title=Name"`
	Categories []Category  `json:"categories" jsonschema:"title=Categories"`
}

Region defines the holding structure for a regions categories and subsequent Rates and Values.

func (Region) Category

func (r Region) Category(code Code) (Category, bool)

Category provides the requested category by its code.

func (Region) Validate

func (r Region) Validate() error

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

type TaxableLine

type TaxableLine interface {
	GetTaxRates() Rates
	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 {
	Categories []*CategoryTotal `json:"categories,omitempty" jsonschema:"title=Categories"`
	Sum        num.Amount       `json:"sum" jsonschema:"title=Sum,description=Total value of all the taxes to be added or retained."`
}

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 NewTotal

func NewTotal(zero num.Amount) *Total

NewTotal initiates a new total instance.

func (*Total) Calculate

func (t *Total) Calculate(reg *Region, lines []TaxableLine, taxIncluded bool, date org.Date, zero num.Amount) error

Calculate figures out the total taxes for the set of `TaxableLine`s provided.

type Value

type Value struct {
	Since    *org.Date      `json:"since,omitempty" jsonschema:"title=Since,description=Date from which this value should be applied."`
	Percent  num.Percentage `json:"percent" jsonschema:"title=Percent,description=Rate that should be applied."`
	Disabled bool           `json:"disabled,omitempty" jsonschema:"title=Disabled,description=When true, this value should no longer be used."`
}

Value 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 (Value) Validate

func (v Value) Validate() error

Validate ensures the tax rate contains all the required fields.

Jump to

Keyboard shortcuts

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