bill

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: Apache-2.0 Imports: 9 Imported by: 24

Documentation

Index

Constants

View Source
const (
	InvoiceType = "bill.Invoice"
)

Standard billing model types that can be incorporated into an envelope.

Variables

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 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"`
}

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

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"`
	// Sequential code used to identify this invoice in tax declarations.
	Code string `json:"code" jsonschema:"title=Code"`
	// 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"`
	// When true, implies that all item prices already include non-retained taxes. This is especially
	// useful for retailers where prices are often displayed including tax.
	PricesIncludeTax bool `json:"prices_include_tax,omitempty" jsonschema:"title=Prices Include Tax"`

	// Key information regarding a previous invoice.
	Preceding *Preceding `json:"preceding,omitempty" jsonschema:"title=Preceding Reference"`

	// 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"`
	// 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 details.
	Notes string `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(r region.Region) 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) Type

func (Invoice) Type() string

Type provides the body type used for mapping.

func (*Invoice) Validate

func (inv *Invoice) Validate(r region.Region) 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"`
	// Discount applied to this line
	Discount *org.Discount `json:"discount,omitempty" jsonschema:"title=Discount"`
	// 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 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"`
	// A code, invoice number, or other reference detail used to identify the outlay.
	Ref string `json:"ref,omitempty" jsonschema:"title=Reference"`
	// Details on what the outlay was.
	Description string `json:"desc" jsonschema:"title=Description"`
	// Amount paid by the supplier.
	Paid num.Amount `json:"paid" jsonschema:"title=Paid"`
}

Outlay represents a 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, for example when an accountant or lawyer will 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.Advance    `` /* 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 fo the previous invoice.
	Code string `json:"code" jsonschema:"title=Code"`
	// When the preceding invoice was issued.
	IssueDate *org.Date `json:"issue_date" jsonschema:"title=Issue Date"`
	// 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`.

type Totals

type Totals struct {
	// Sum of all line item sums
	Sum num.Amount `json:"sum" jsonschema:"title=Sum"`
	// Sum of all discounts applied to each line
	Discount num.Amount `json:"discount" jsonschema:"title=Discount"`
	// Sum of all line sums minus the discounts
	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"`
	// 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
	Payable num.Amount `json:"payable" jsonschema:"title=Payable"`
	// Total amount 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