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. Typically used for taxes related to // income. Retained bool `json:"retained,omitempty" jsonschema:"title=Retained"` // Specific tax definitions inside this category. Defs []Def `json:"defs" jsonschema:"title=Definitions"` }
Category ...
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"` Amount num.Amount `json:"amount" jsonschema:"title=Amount"` }
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.
func (*CategoryTotal) Rate ¶ added in v0.13.0
func (ct *CategoryTotal) Rate(code Code) *RateTotal
Rate grabs the matching rate from the category total, or nil.
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. Tax codes are standardised so that when validated they must contain between 2 and 6 inclusive upper-case letters or numbers.
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.
type Rate ¶
type Rate struct { // From the available options for the region. Category Code `json:"cat" jsonschema:"title=Category Code"` // As defined for the region and category. Code Code `json:"code" jsonschema:"title=Code"` }
Rate references the tax category and rate code that should be applied to this line item when calculating the final taxes.
Surcharges are very rarely used, but some countries require them to be able to apply an additional tax rate.
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"` 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 definition.
func NewRateTotal ¶
NewRateTotal returns a rate total.
type Rates ¶
type Rates []*Rate
Rates contains a list of taxes, usually applied to an invoice line or item.
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.
type TaxableLine ¶
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"` }
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) Calculate ¶
func (t *Total) Calculate(reg *Region, lines []TaxableLine, taxIncluded Code, date org.Date, zero num.Amount) error
Calculate figures out the total taxes for the set of `TaxableLine`s provided.
func (*Total) Category ¶ added in v0.13.0
func (t *Total) Category(code Code) *CategoryTotal
Category provides the category total for the matching code.
type Value ¶
type Value struct { // Date from which this value should be applied. Since *org.Date `json:"since,omitempty" jsonschema:"title=Since"` // Rate that should be applied Percent num.Percentage `json:"percent" jsonschema:"title=Percent"` // When true, this value should no longer be used. Disabled bool `json:"disabled,omitempty" jsonschema:"title=Disabled"` }
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.