bill

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: Apache-2.0 Imports: 10 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

CorrectionCodeList provides a fixed list of all the correction codes that are currently supported by GOBL.

CorrectionMethodCodeList provides a fixed list of codes for validation purposes.

View Source
var UNTDID1001TypeCodeMap = map[TypeCode]string{
	ProformaTypeCode:   "325",
	PartialTypeCode:    "326",
	CommercialTypeCode: "380",
	SimplifiedTypeCode: "380",
	CorrectedTypeCode:  "384",
	CreditNoteTypeCode: "381",
	SelfBilledTypeCode: "389",
}

UNTDID1001TypeCodeMap offers a way to convert the GOBL invoice type code into one supported by our subset of the UNTDID 1001 official list.

Functions

This section is empty.

Types

type Charge added in v0.13.0

type Charge struct {
	// Unique identifying for the discount entry
	UUID string `json:"uuid,omitempty" jsonschema:"title=UUID"`
	// Line number inside the list of discounts
	Index int `json:"i" jsonschema:"title=Index"`
	// Code to used to refer to the this charge
	Ref string `json:"ref,omitempty" jsonschema:"title=Reference"`
	// Base represents the value used as a base for rate calculations.
	// If not already provided, we'll take the invoices sum before
	// discounts.
	Base *num.Amount `json:"base,omitempty" jsonschema:"title=Base"`
	// Percentage rate to apply to the invoice's Sum
	Rate *num.Percentage `json:"rate,omitempty" jsonschema:"title=Rate"`
	// Amount to apply
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
	// List of taxes to apply to the charge
	Taxes tax.Rates `json:"taxes,omitempty" jsonschema:"title=Taxes"`
	// Code for why was this charge applied?
	Code string `json:"code,omitempty" jsonschema:"title=Reason Code"`
	// Text description as to why the charge was applied
	Reason string `json:"reason,omitempty" jsonschema:"title=Reason"`
	// Additional semi-structured information.
	Meta org.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Charge represents a surchange applied to the complete document independent from the individual lines.

func (*Charge) GetTaxRates added in v0.13.0

func (m *Charge) GetTaxRates() tax.Rates

GetTaxRates responds with the array of tax rates applied to this line.

func (*Charge) GetTotal added in v0.13.0

func (m *Charge) GetTotal() num.Amount

GetTotal provides the final total for this line, excluding any tax calculations.

func (*Charge) Validate added in v0.13.0

func (m *Charge) Validate() error

Validate checks the discount's fields.

type Charges added in v0.13.0

type Charges []*Charge

Charges represents an array of charge objects

type CorrectionCode added in v0.16.0

type CorrectionCode string

CorrectionCode helps identify from a set of reasons why this correction is happening

const (
	CodeCorrectionCode            CorrectionCode = "code"       // Invoice Code
	SeriesCorrectionCode          CorrectionCode = "series"     // Invoice series number
	IssueDateCorrectionCode       CorrectionCode = "issue-date" // Issue Date
	SupplierCorrectionCode        CorrectionCode = "supplier"   // General supplier details
	CustomerCorrectionCode        CorrectionCode = "customer"   // General customer details
	SupplierNameCorrectionCode    CorrectionCode = "supplier-name"
	CustomerNameCorrectionCode    CorrectionCode = "customer-name"
	SupplierTaxIDCorrectionCode   CorrectionCode = "supplier-tax-id"
	CustomerTaxIDCorrectionCode   CorrectionCode = "customer-tax-id"
	SupplierAddressCorrectionCode CorrectionCode = "supplier-addr"
	CustomerAddressCorrectionCode CorrectionCode = "customer-addr"
	LineCorrectionCode            CorrectionCode = "line"
	PeriodCorrectionCode          CorrectionCode = "period"
	TypeCorrectionCode            CorrectionCode = "type"
	LegalDetailsCorrectionCode    CorrectionCode = "legal-details"
	TaxRateCorrectionCode         CorrectionCode = "tax-rate"
	TaxAmountCorrectionCode       CorrectionCode = "tax-amount"
	TaxBaseCorrectionCode         CorrectionCode = "tax-base"
	TaxCorrectionCode             CorrectionCode = "tax"          // General issue with tax calculations
	TaxRetainedCorrectionCode     CorrectionCode = "tax-retained" // Error in retained tax calculations
	RefundCorrectionCode          CorrectionCode = "refund"       // Goods or materials have been returned to supplier
	DiscountCorrectionCode        CorrectionCode = "discount"     // New discounts or rebates added
	JudicialCorrectionCode        CorrectionCode = "judicial"     // Court ruling or administrative decision
	InsolvencyCorrectionCode      CorrectionCode = "insolvency"   // the customer is insolvent and cannot pay
)

List of currently supported correction codes. These are determined by local needs and could be increased as new regions are added with local requirements.

func (CorrectionCode) Validate added in v0.16.0

func (cc CorrectionCode) Validate() error

Validate ensures the correction code is part of the accepted list

type CorrectionMethodCode added in v0.16.0

type CorrectionMethodCode string

CorrectionMethodCode identifies that type of correction being applied.

const (
	CompleteCorrectionMethodCode   CorrectionMethodCode = "complete"   // everything has changed
	PartialCorrectionMethodCode    CorrectionMethodCode = "partial"    // only differences corrected
	DiscountCorrectionMethodCode   CorrectionMethodCode = "discount"   // deducted from future invoices
	AuthorizedCorrectionMethodCode CorrectionMethodCode = "authorized" // Permitted by tax agency
)

Defined list of correction methods

func (CorrectionMethodCode) Validate added in v0.16.0

func (cc CorrectionMethodCode) Validate() error

Validate ensures the correction code is part of the accepted list

type Delivery

type Delivery struct {
	// The party who will receive delivery of the goods defined in the invoice and is not responsible for taxes.
	Receiver *org.Party `json:"receiver,omitempty" jsonschema:"title=Receiver"`
	// When the goods should be expected
	Date *org.Date `json:"date,omitempty" jsonschema:"title=Date"`
	// Start of a n invoicing or delivery period
	StartDate *org.Date `json:"start_date,omitempty" jsonschema:"title=Start Date"`
	// End of a n invoicing or delivery period
	EndDate *org.Date `json:"end_date,omitempty" jsonschema:"title=End Date"`
}

Delivery covers the details of the destination for the products described in the invoice body.

type Discount added in v0.13.0

type Discount struct {
	// Unique identifying for the discount entry
	UUID string `json:"uuid,omitempty" jsonschema:"title=UUID"`
	// Line number inside the list of discounts
	Index int `json:"i" jsonschema:"title=Index"`
	// Reference or ID for this Discount
	Ref string `json:"ref,omitempty" jsonschema:"title=Reference"`
	// Base represents the value used as a base for rate calculations.
	// If not already provided, we'll take the invoices sum.
	Base *num.Amount `json:"base,omitempty" jsonschema:"title=Base"`
	// Percentage rate to apply to the invoice's Sum
	Rate *num.Percentage `json:"rate,omitempty" jsonschema:"title=Rate"`
	// Amount to apply
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
	// List of taxes to apply to the discount
	Taxes tax.Rates `json:"taxes,omitempty" jsonschema:"title=Taxes"`
	// Code for the reason this discount applied
	Code string `json:"code,omitempty" jsonschema:"title=Reason Code"`
	// Text description as to why the discount was applied
	Reason string `json:"reason,omitempty" jsonschema:"title=Reason"`
	// Additional semi-structured information.
	Meta org.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Discount represents an allowance applied to the complete document independent from the individual lines. These have more in common with Invoice Lines than anything else, as each discount must have the correct taxes defined.

func (*Discount) GetTaxRates added in v0.13.0

func (m *Discount) GetTaxRates() tax.Rates

GetTaxRates responds with the array of tax rates applied to this line.

func (*Discount) GetTotal added in v0.13.0

func (m *Discount) GetTotal() num.Amount

GetTotal provides the final total for this line, excluding any tax calculations. We return a negative value so that discounts will be applied correctly.

func (*Discount) Validate added in v0.13.0

func (m *Discount) Validate() error

Validate checks the discount's fields.

type Discounts added in v0.13.0

type Discounts []*Discount

Discounts represents an array of discounts.

type Invoice

type Invoice struct {
	// Unique document ID. Not required, but always recommended in addition to the Code.
	UUID *uuid.UUID `json:"uuid,omitempty" jsonschema:"title=UUID"`

	// Code for the region the invoice should be validated with.
	Region region.Code `json:"region" jsonschema:"title=Region"`

	// Sequential code used to identify this invoice in tax declarations.
	Code string `json:"code" jsonschema:"title=Code"`
	// Used in addition to the Code in some regions.
	Series string `json:"series,omitempty" jsonschema:"title=Series"`
	// Functional type of the invoice, default is always 'commercial'.
	TypeCode TypeCode `json:"type_code,omitempty" jsonschema:"title=Type Code"`
	// Currency for all invoice totals.
	Currency currency.Code `json:"currency" jsonschema:"title=Currency"`
	// Exchange rates to be used when converting the invoices monetary values into other currencies.
	ExchangeRates currency.ExchangeRates `json:"rates,omitempty" jsonschema:"title=Exchange Rates"`

	// Implies that all item prices already include the specified tax, especially
	// useful for retailers or B2C companies where prices are often displayed including tax.
	//
	// We only only one tax category to be defined as it is overly complex to work-out what the base
	// price should be from multiple rates.
	PricesIncludeTax tax.Code `json:"prices_include_tax,omitempty" jsonschema:"title=Prices Include Tax"`

	// Key information regarding a previous invoice and potentially details as to why it
	// was corrected.
	Preceding *Preceding `json:"preceding,omitempty" jsonschema:"title=Preceding Details"`

	// When the invoice was created.
	IssueDate org.Date `json:"issue_date" jsonschema:"title=Issue Date"`
	// Date when the operation defined by the invoice became effective.
	OperationDate *org.Date `json:"op_date,omitempty" jsonschema:"title=Operation Date"`
	// When the taxes of this invoice become accountable, if none set, the issue date is used.
	ValueDate *org.Date `json:"value_date,omitempty" jsonschema:"title=Value Date"`

	// The taxable entity supplying the goods or services.
	Supplier *org.Party `json:"supplier" jsonschema:"title=Supplier"`
	// Legal entity receiving the goods or services, may be empty in certain circumstances such as simplified invoices.
	Customer *org.Party `json:"customer,omitempty" jsonschema:"title=Customer"`

	// List of invoice lines representing each of the items sold to the customer.
	Lines Lines `json:"lines,omitempty" jsonschema:"title=Lines"`
	// Discounts or allowances applied to the complete invoice
	Discounts Discounts `json:"discounts,omitempty" jsonschema:"title=Discounts"`
	// Charges or surcharges applied to the complete invoice
	Charges Charges `json:"charges,omitempty" jsonschema:"title=Charges"`
	// Expenses paid for by the supplier but invoiced directly to the customer.
	Outlays Outlays `json:"outlays,omitempty" jsonschema:"title=Outlays"`

	// Summary of all the invoice totals, including taxes.
	Totals *Totals `json:"totals" jsonschema:"title=Totals"`

	Ordering *Ordering `json:"ordering,omitempty" jsonschema:"title=Ordering Details"`
	Payment  *Payment  `json:"payment,omitempty" jsonschema:"title=Payment Details"`
	Delivery *Delivery `json:"delivery,omitempty" jsonschema:"title=Delivery Details"`

	// Unstructured information that is relevant to the invoice, such as correction or additional
	// legal details.
	Notes org.Notes `json:"notes,omitempty" jsonschema:"title=Notes"`
	// Additional semi-structured data that doesn't fit into the body of the invoice.
	Meta org.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Invoice represents a payment claim for goods or services supplied under conditions agreed between the supplier and the customer. In most cases the resulting document describes the actual financial commitment of goods or services ordered from the supplier.

func (*Invoice) Calculate

func (inv *Invoice) Calculate() error

Calculate performs all the calculations required for the invoice totals and taxes. If the original invoice only includes partial calculations, this will figure out what's missing.

func (*Invoice) Validate

func (inv *Invoice) Validate() error

Validate checks to ensure the invoice is valid and contains all the information we need.

type Line

type Line struct {
	// Unique identifier for this line
	UUID string `json:"uuid,omitempty" jsonschema:"title=UUID"`
	// Line number inside the parent
	Index int `json:"i" jsonschema:"title=Index"`
	// Number of items
	Quantity num.Amount `json:"quantity" jsonschema:"title=Quantity"`
	// Details about what is being sold
	Item *org.Item `json:"item" jsonschema:"title=Item"`
	// Result of quantity multiplied by the item's price
	Sum num.Amount `json:"sum" jsonschema:"title=Sum"`
	// Discounts applied to this line
	Discounts []*LineDiscount `json:"discounts,omitempty" jsonschema:"title=Discounts"`
	// Charges applied to this line
	Charges []*LineCharge `json:"charges,omitempty" jsonschema:"title=Charges"`
	// List of taxes to be applied and used in the invoice totals
	Taxes tax.Rates `json:"taxes,omitempty" jsonschema:"title=Taxes"`
	// Total line amount after applying discounts to the sum
	Total num.Amount `json:"total" jsonschema:"title=Total"`
}

Line is a single row in an invoice.

func (*Line) GetTaxRates

func (l *Line) GetTaxRates() tax.Rates

GetTaxRates responds with the array of tax rates applied to this line.

func (*Line) GetTotal

func (l *Line) GetTotal() num.Amount

GetTotal provides the final total for this line, excluding any tax calculations.

func (*Line) Validate

func (l *Line) Validate() error

Validate ensures the line contains everything required.

type LineCharge added in v0.13.0

type LineCharge struct {
	// Percentage rate if fixed amount not applied
	Rate *num.Percentage `json:"rate,omitempty" jsonschema:"title=Rate"`
	// Fixed or resulting charge amount to apply
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
	// Reference code.
	Code string `json:"code,omitempty" jsonschema:"title=Code"`
	// Text description as to why the charge was applied
	Reason string `json:"reason,omitempty" jsonschema:"title=Reason"`
}

LineCharge represents an amount added to the line, and will be applied before taxes. TODO: use UNTDID 7161 code list

func (*LineCharge) Validate added in v0.13.0

func (lc *LineCharge) Validate() error

Validate checks the line charge's fields.

type LineDiscount added in v0.13.0

type LineDiscount struct {
	// Percentage rate if fixed amount not applied
	Rate *num.Percentage `json:"rate,omitempty" jsonschema:"title=Rate"`
	// Fixed discount amount to apply
	Amount num.Amount `json:"amount" jsonschema:"title=Value"`
	// Reason code.
	Code string `json:"code,omitempty" jsonschema:"title=Code"`
	// Text description as to why the discount was applied
	Reason string `json:"reason,omitempty" jsonschema:"title=Reason"`
}

LineDiscount represents an amount deducted from the line, and will be applied before taxes. TODO: use UNTDID 5189 code list

func (*LineDiscount) Validate added in v0.13.0

func (ld *LineDiscount) Validate() error

Validate checks the line discount's fields.

type Lines

type Lines []*Line

Lines holds an array of Line objects.

type Ordering

type Ordering struct {
	// Party who is selling the goods and is not responsible for taxes
	Seller *org.Party `json:"seller,omitempty" jsonschema:"title=Seller"`
}

Ordering allows additional order details to be appended

type Outlay

type Outlay struct {
	// Unique identity for this outlay.
	UUID string `json:"uuid,omitempty" jsonschema:"title=UUID"`
	// Outlay number index inside the invoice for ordering.
	Index int `json:"i" jsonschema:"title=Index"`
	// When was the outlay made.
	Date *org.Date `json:"date,omitempty" jsonschema:"title=Date"`
	// Invoice number or other reference detail used to identify the outlay.
	Code string `json:"code,omitempty" jsonschema:"title=Code"`
	// Series of the outlay invoice.
	Series string `json:"series,omitempty" jsonschema:"title=Series"`
	// Details on what the outlay was.
	Description string `json:"desc" jsonschema:"title=Description"`
	// Who was the supplier of the outlay
	Supplier *org.Party `json:"supplier,omitempty" jsonschema:"title=Supplier"`
	// Amount paid by the supplier.
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
}

Outlay represents a reimbursable expense that was paid for by the supplier and invoiced separately by the third party directly to the customer. Most suppliers will want to include the expenses of their providers as part of their own operational costs. However, outlays are common in countries like Spain where it is typical for an accountant or lawyer to pay for notary fees, but forward the invoice to the customer.

func (*Outlay) Validate added in v0.5.0

func (o *Outlay) Validate() error

Validate ensures the outlay contains everything required.

type Outlays

type Outlays []*Outlay

Outlays holds an array of Outlay objects used inside a billing document.

type Payment

type Payment struct {
	Payer        *org.Party        `` /* 130-byte string literal not displayed */
	Terms        *pay.Terms        `json:"terms,omitempty" jsonschema:"title=Terms,description=Payment terms or conditions."`
	Advances     pay.Advances      `` /* 152-byte string literal not displayed */
	Instructions *pay.Instructions `json:"instructions,omitempty" jsonschema:"title=Instructions,description=Details on how payment should be made."`
}

Payment contains details as to how the invoice should be paid.

type Preceding

type Preceding struct {
	// Preceding document's UUID if available can be useful for tracing.
	UUID *uuid.UUID `json:"uuid,omitempty" jsonschema:"title=UUID"`
	// Identity code of the previous invoice.
	Code string `json:"code" jsonschema:"title=Code"`
	// Additional identification details
	Series string `json:"series,omitempty" jsonschema:"title=Series"`
	// When the preceding invoice was issued.
	IssueDate org.Date `json:"issue_date" jsonschema:"title=Issue Date"`
	// Tax period in which the previous invoice has an effect.
	Period *org.Period `json:"period,omitempty" jsonschema:"title=Period"`
	// Specific codes for the corrections made.
	Corrections []CorrectionCode `json:"corrections,omitempty" jsonschema:"title=Corrections"`
	// How has the previous invoice been corrected?
	CorrectionMethod CorrectionMethodCode `json:"correction_method,omitempty" jsonschema:"title=Correction Method"`
	// Additional details regarding preceding invoice
	Notes string `json:"notes,omitempty" jsonschema:"title=Notes"`
	// Additional semi-structured data that may be useful in specific regions
	Meta org.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Preceding allows for information to be provided about a previous invoice that this one will replace or subtract from. If this is used, the invoice type code will most likely need to be set to `corrected` or `credit-note`.

func (*Preceding) Validate added in v0.16.0

func (p *Preceding) Validate() error

Validate ensures the preceding details look okay

type Totals

type Totals struct {
	// Sum of all line item sums
	Sum num.Amount `json:"sum" jsonschema:"title=Sum"`
	// Sum of all document level discounts
	Discount *num.Amount `json:"discount,omitempty" jsonschema:"title=Discount"`
	// Sum of all document level charges
	Charge *num.Amount `json:"charge,omitempty" jsonschema:"title=Charge"`
	// If prices include tax, this is the total tax included in the price.
	TaxIncluded *num.Amount `json:"tax_included,omitempty" jsonschema:"title=Tax Included"`
	// Sum of all line sums minus the discounts, plus the charges, without tax.
	Total num.Amount `json:"total" jsonschema:"title=Total"`
	// Summary of all the taxes with a final sum to add or deduct from the amount payable.
	Taxes *tax.Total `json:"taxes,omitempty" jsonschema:"title=Tax Totals"`
	// Grand total after all taxes have been applied.
	TotalWithTax num.Amount `json:"total_with_tax" jsonschema:"title=Total with Tax"`
	// Total paid in outlays that need to be reimbursed
	Outlays *num.Amount `json:"outlays,omitempty" jsonschema:"title=Outlay Totals"`
	// Total amount to be paid after applying taxes and outlays.
	Payable num.Amount `json:"payable" jsonschema:"title=Payable"`
	// Total amount already paid in advance.
	Advances *num.Amount `json:"advance,omitempty" jsonschema:"title=Advance"`
	// How much actually needs to be paid now.
	Due *num.Amount `json:"due,omitempty" jsonschema:"title=Due"`
}

Totals contains the summaries of all calculations for the invoice.

type TypeCode

type TypeCode string

TypeCode defines the "Invoice Type Code" according to a subset of the UNTDID 1001 standard list.

const (
	CommercialTypeCode TypeCode = ""            // Commercial Invoice, default
	ProformaTypeCode   TypeCode = "proforma"    // Proforma invoice
	SimplifiedTypeCode TypeCode = "simplified"  // Simplified Invoice
	PartialTypeCode    TypeCode = "partial"     // Partial Invoice
	CorrectedTypeCode  TypeCode = "corrected"   // Corrected Invoice
	CreditNoteTypeCode TypeCode = "credit-note" // Credit Note
	SelfBilledTypeCode TypeCode = "self-billed" // Self Billed Invoice
)

Predefined list of the invoice type codes officially supported.

func (TypeCode) UNTDID1001

func (c TypeCode) UNTDID1001() string

UNTDID1001 provides the official code number assigned to the type.

func (TypeCode) Validate

func (c TypeCode) Validate() error

Validate is used to ensure the code provided is one of those we know about.

Jump to

Keyboard shortcuts

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