Documentation ¶
Overview ¶
Package bill provides models for dealing with Billing and specifically invoicing.
Index ¶
- Constants
- Variables
- func RequireLineTaxCategory(key cbc.Code) validation.Rule
- func WithData(data json.RawMessage) schema.Option
- func WithExtension(key cbc.Key, code cbc.Code) schema.Option
- func WithIssueDate(date cal.Date) schema.Option
- func WithOptions(opts *CorrectionOptions) schema.Option
- func WithReason(reason string) schema.Option
- func WithSeries(value cbc.Code) schema.Option
- func WithStamps(stamps []*head.Stamp) schema.Option
- type Charge
- type CorrectionOptions
- type Delivery
- type Discount
- type Invoice
- func (inv *Invoice) Calculate() error
- func (inv *Invoice) ConvertInto(cur currency.Code) (*Invoice, error)
- func (inv *Invoice) Correct(opts ...schema.Option) error
- func (inv *Invoice) CorrectionOptionsSchema() (interface{}, error)
- func (inv *Invoice) Empty()
- func (inv *Invoice) GetExtensions() []tax.Extensions
- func (inv *Invoice) GetType() cbc.Key
- func (inv *Invoice) Invert() error
- func (inv Invoice) JSONSchemaExtend(js *jsonschema.Schema)
- func (inv *Invoice) Normalize(normalizers tax.Normalizers)
- func (inv *Invoice) RemoveIncludedTaxes() (*Invoice, error)
- func (inv *Invoice) Replicate() error
- func (inv *Invoice) ScenarioSummary() *tax.ScenarioSummarydeprecated
- func (i *Invoice) UNTDID1001() cbc.Code
- func (inv *Invoice) UnmarshalJSON(data []byte) error
- func (inv *Invoice) Validate() error
- func (inv *Invoice) ValidateWithContext(ctx context.Context) error
- func (inv *Invoice) ValidationContext(ctx context.Context) context.Context
- type Line
- type LineCharge
- type LineDiscount
- type Ordering
- type Payment
- type Tax
- type Totals
Constants ¶
const ( ChargeKeyStampDuty cbc.Key = "stamp-duty" ChargeKeyOutlay cbc.Key = "outlay" ChargeKeyTax cbc.Key = "tax" ChargeKeyCustoms cbc.Key = "customs" ChargeKeyDelivery cbc.Key = "delivery" ChargeKeyPacking cbc.Key = "packing" ChargeKeyHandling cbc.Key = "handling" ChargeKeyInsurance cbc.Key = "insurance" ChargeKeyStorage cbc.Key = "storage" ChargeKeyAdmin cbc.Key = "admin" // administration ChargeKeyCleaning cbc.Key = "cleaning" )
Charge keys for identifying the type of charge being applied. These are based on a subset of the UN/CEFACT UNTDID 7161 codes, and are intentionally kept lean.
const ( DiscountKeyEarlyCompletion cbc.Key = "early-completion" DiscountKeyMilitary cbc.Key = "military" DiscountKeyWorkAccident cbc.Key = "work-accident" DiscountKeySpecialAgreement cbc.Key = "special-agreement" DiscountKeyProductionError cbc.Key = "production-error" DiscountKeyNewOutlet cbc.Key = "new-outlet" DiscountKeySample cbc.Key = "sample" DiscountKeyEndOfRange cbc.Key = "end-of-range" DiscountKeyIncoterm cbc.Key = "incoterm" DiscountKeyPOSThreshold cbc.Key = "pos-threshold" DiscountKeySpecialRebate cbc.Key = "special-rebate" DiscountKeyTemporary cbc.Key = "temporary" DiscountKeyStandard cbc.Key = "standard" DiscountKeyYarlyTurnover cbc.Key = "yearly-turnover" )
Discount keys for identifying the type of discount being applied. These are based on the UN/CEFACT UNTDID 5189 code list subset defined in the EN16931 code lists and are mean as suggestions.
const ( InvoiceTypeStandard cbc.Key = "standard" InvoiceTypeProforma cbc.Key = "proforma" InvoiceTypeCorrective cbc.Key = "corrective" InvoiceTypeCreditNote cbc.Key = "credit-note" InvoiceTypeDebitNote cbc.Key = "debit-note" InvoiceTypeOther cbc.Key = "other" )
Predefined list of the invoice type codes officially supported.
const (
ShortSchemaInvoice = "bill/invoice"
)
Constants used to help identify invoices
const ( // UNTDID1001Key is the key used to identify the UNTDID 1001 code // associated with an invoice type. UNTDID1001Key cbc.Key = "untdid1001" )
Variables ¶
var Corrective schema.Option = func(o interface{}) { opts := o.(*CorrectionOptions) opts.Type = InvoiceTypeCorrective }
Corrective is used for creating corrective or rectified invoices that completely replace a previous document.
var Credit schema.Option = func(o interface{}) { opts := o.(*CorrectionOptions) opts.Type = InvoiceTypeCreditNote }
Credit indicates that the corrective operation requires a credit note or equivalent.
var Debit schema.Option = func(o interface{}) { opts := o.(*CorrectionOptions) opts.Type = InvoiceTypeDebitNote }
Debit indicates that the corrective operation is to append new items to the previous invoice, usually as a debit note.
var InvoiceTypes = []*cbc.Definition{ { Key: InvoiceTypeStandard, Name: i18n.String{ i18n.EN: "Standard", }, Desc: i18n.String{ i18n.EN: "A regular commercial invoice document between a supplier and customer.", }, Map: cbc.CodeMap{ UNTDID1001Key: "380", }, }, { Key: InvoiceTypeProforma, Name: i18n.String{ i18n.EN: "Proforma", }, Desc: i18n.String{ i18n.EN: "For a clients validation before sending a final invoice.", }, Map: cbc.CodeMap{ UNTDID1001Key: "325", }, }, { Key: InvoiceTypeCorrective, Name: i18n.String{ i18n.EN: "Corrective", }, Desc: i18n.String{ i18n.EN: "Corrected invoice that completely *replaces* the preceding document.", }, Map: cbc.CodeMap{ UNTDID1001Key: "384", }, }, { Key: InvoiceTypeCreditNote, Name: i18n.String{ i18n.EN: "Credit Note", }, Desc: i18n.String{ i18n.EN: here.Doc(` Reflects a refund either partial or complete of the preceding document. A credit note effectively *extends* the previous document. `), }, Map: cbc.CodeMap{ UNTDID1001Key: "381", }, }, { Key: InvoiceTypeDebitNote, Name: i18n.String{ i18n.EN: "Debit Note", }, Desc: i18n.String{ i18n.EN: "An additional set of charges to be added to the preceding document.", }, Map: cbc.CodeMap{ UNTDID1001Key: "383", }, }, { Key: InvoiceTypeOther, Name: i18n.String{ i18n.EN: "Other", }, Desc: i18n.String{ i18n.EN: here.Doc(` Any other type of invoice that does not fit into the standard categories and implies that any scenarios defined in tax regimes or addons will not be applied. This is useful for being able to create invoices with custom types in extensions, but is not recommend for general use. `), }, }, }
InvoiceTypes describes each of the InvoiceTypes supported.
Functions ¶
func RequireLineTaxCategory ¶ added in v0.115.0
func RequireLineTaxCategory(key cbc.Code) validation.Rule
RequireLineTaxCategory is a validation rule that ensures the line has the required tax category.
func WithData ¶ added in v0.51.0
func WithData(data json.RawMessage) schema.Option
WithData expects a raw JSON object that will be marshalled into a CorrectionOptions instance and used as the base for the correction.
func WithExtension ¶ added in v0.67.0
WithExtension adds a specific extension combination to the invoice's preceding data, can be called multiple times.
func WithIssueDate ¶ added in v0.51.0
WithIssueDate can be used to override the issue date of the corrective invoice produced.
func WithOptions ¶ added in v0.51.0
func WithOptions(opts *CorrectionOptions) schema.Option
WithOptions takes an already completed CorrectionOptions instance and uses this as a base instead of passing individual options. This is useful for passing options from an API, developers should use the regular option methods.
func WithReason ¶ added in v0.40.0
WithReason allows a reason to be provided for the corrective operation.
func WithSeries ¶ added in v0.77.0
WithSeries assigns a new series to the corrective document.
Types ¶
type Charge ¶ added in v0.13.0
type Charge struct { uuid.Identify // Line number inside the list of charges (calculated). Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"` // Key for grouping or identifying charges for tax purposes. A suggested list of // keys is provided, but these may be extended by the issuer. Key cbc.Key `json:"key,omitempty" jsonschema:"title=Key"` // Code to used to refer to the this charge by the issuer Code cbc.Code `json:"code,omitempty" jsonschema:"title=Code"` // Text description as to why the charge was applied Reason string `json:"reason,omitempty" jsonschema:"title=Reason"` // Base represents the value used as a base for percent calculations instead // of the invoice's sum of lines. Base *num.Amount `json:"base,omitempty" jsonschema:"title=Base"` // Percentage to apply to the sum of all lines Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"` // Amount to apply (calculated if percent present) Amount num.Amount `json:"amount" jsonschema:"title=Amount" jsonschema_extras:"calculated=true"` // List of taxes to apply to the charge Taxes tax.Set `json:"taxes,omitempty" jsonschema:"title=Taxes"` // Extension codes that apply to the charge Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"` // Additional semi-structured information. Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"` // contains filtered or unexported fields }
Charge represents a surchange applied to the complete document independent from the individual lines.
func (*Charge) GetTaxes ¶ added in v0.20.0
GetTaxes responds with the array of tax rates applied to this line.
func (*Charge) GetTotal ¶ added in v0.13.0
GetTotal provides the final total for this line, excluding any tax calculations.
func (Charge) JSONSchemaExtend ¶ added in v0.204.0
func (Charge) JSONSchemaExtend(schema *jsonschema.Schema)
JSONSchemaExtend adds the charge key definitions to the schema.
func (*Charge) Normalize ¶ added in v0.200.0
func (m *Charge) Normalize(normalizers tax.Normalizers)
Normalize performs normalization on the line and embedded objects using the provided list of normalizers.
type CorrectionOptions ¶ added in v0.51.0
type CorrectionOptions struct { head.CorrectionOptions // The type of corrective invoice to produce. Type cbc.Key `json:"type" jsonschema:"title=Type"` // When the new corrective invoice's issue date should be set to. IssueDate *cal.Date `json:"issue_date,omitempty" jsonschema:"title=Issue Date"` // Series to assign to the new corrective invoice. Series cbc.Code `json:"series,omitempty" jsonschema:"title=Series"` // Stamps of the previous document to include in the preceding data. Stamps []*head.Stamp `json:"stamps,omitempty" jsonschema:"title=Stamps"` // Human readable reason for the corrective operation. Reason string `json:"reason,omitempty" jsonschema:"title=Reason"` // Extensions for region specific requirements that may be added in the preceding // or at the document level, according to the local rules. Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"` // contains filtered or unexported fields }
CorrectionOptions defines a structure used to pass configuration options to correct a previous invoice. This is made available to make it easier to pass options between external services.
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"` // Identities is used to define specific codes or IDs that may be used to // identify the delivery. Identities []*org.Identity `json:"identities,omitempty" jsonschema:"title=Identities"` // When the goods should be expected. Date *cal.Date `json:"date,omitempty" jsonschema:"title=Date"` // Period of time in which to expect delivery if a specific date is not available. Period *cal.Period `json:"period,omitempty" jsonschema:"title=Period"` // Additional custom data. Meta *cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"` }
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 { uuid.Identify // Line number inside the list of discounts (calculated) Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"` // Key for identifying the type of discount being applied. Key cbc.Key `json:"key,omitempty" jsonschema:"title=Key"` // Code to used to refer to the this discount by the issuer Code cbc.Code `json:"code,omitempty" jsonschema:"title=Code"` // Text description as to why the discount was applied Reason string `json:"reason,omitempty" jsonschema:"title=Reason"` // Base represents the value used as a base for percent calculations instead // of the invoice's sum of lines. Base *num.Amount `json:"base,omitempty" jsonschema:"title=Base"` // Percentage to apply to the base or invoice's sum. Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"` // Amount to apply (calculated if percent present). Amount num.Amount `json:"amount" jsonschema:"title=Amount" jsonschema_extras:"calculated=true"` // List of taxes to apply to the discount Taxes tax.Set `json:"taxes,omitempty" jsonschema:"title=Taxes"` // Extension codes that apply to the discount Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"` // Additional semi-structured information. Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"` // contains filtered or unexported fields }
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) GetTaxes ¶ added in v0.20.0
GetTaxes responds with the array of tax rates applied to this line.
func (*Discount) GetTotal ¶ added in v0.13.0
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) JSONSchemaExtend ¶ added in v0.204.0
func (Discount) JSONSchemaExtend(schema *jsonschema.Schema)
JSONSchemaExtend adds the discount key definitions to the schema.
func (*Discount) Normalize ¶ added in v0.200.0
func (m *Discount) Normalize(normalizers tax.Normalizers)
Normalize performs normalization on the line and embedded objects using the provided list of normalizers.
type Invoice ¶
type Invoice struct { tax.Regime tax.Addons tax.Tags uuid.Identify // Type of invoice document subject to the requirements of the local tax regime. Type cbc.Key `json:"type" jsonschema:"title=Type" jsonschema_extras:"calculated=true"` // Used as a prefix to group codes. Series cbc.Code `json:"series,omitempty" jsonschema:"title=Series"` // Sequential code used to identify this invoice in tax declarations. Code cbc.Code `json:"code" jsonschema:"title=Code"` // When the invoice was created. IssueDate cal.Date `json:"issue_date" jsonschema:"title=Issue Date" jsonschema_extras:"calculated=true"` // Date when the operation defined by the invoice became effective. OperationDate *cal.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 *cal.Date `json:"value_date,omitempty" jsonschema:"title=Value Date"` // Currency for all invoice totals. Currency currency.Code `json:"currency" jsonschema:"title=Currency" jsonschema_extras:"calculated=true"` // Exchange rates to be used when converting the invoices monetary values into other currencies. ExchangeRates []*currency.ExchangeRate `json:"exchange_rates,omitempty" jsonschema:"title=Exchange Rates"` // Key information regarding previous invoices and potentially details as to why they // were corrected. Preceding []*org.DocumentRef `json:"preceding,omitempty" jsonschema:"title=Preceding Details"` // Special tax configuration for billing. Tax *Tax `json:"tax,omitempty" jsonschema:"title=Tax"` // The entity supplying the goods or services and usually responsible for paying taxes. Supplier *org.Party `json:"supplier" jsonschema:"title=Supplier"` // Legal entity receiving the goods or services, may be nil 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 []*Line `json:"lines,omitempty" jsonschema:"title=Lines"` // Discounts or allowances applied to the complete invoice Discounts []*Discount `json:"discounts,omitempty" jsonschema:"title=Discounts"` // Charges or surcharges applied to the complete invoice Charges []*Charge `json:"charges,omitempty" jsonschema:"title=Charges"` // Ordering details including document references and buyer or seller parties. Ordering *Ordering `json:"ordering,omitempty" jsonschema:"title=Ordering Details"` // Information on when, how, and to whom the invoice should be paid. Payment *Payment `json:"payment,omitempty" jsonschema:"title=Payment Details"` // Specific details on delivery of the goods referenced in the invoice. Delivery *Delivery `json:"delivery,omitempty" jsonschema:"title=Delivery Details"` // Summary of all the invoice totals, including taxes (calculated). Totals *Totals `json:"totals" jsonschema:"title=Totals" jsonschema_extras:"calculated=true"` // Unstructured information that is relevant to the invoice, such as correction or additional // legal details. Notes []*org.Note `json:"notes,omitempty" jsonschema:"title=Notes"` // Additional complementary objects that add relevant information to the invoice. Complements []*schema.Object `json:"complements,omitempty" jsonschema:"title=Complements"` // Additional semi-structured data that doesn't fit into the body of the invoice. Meta cbc.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 ¶
Calculate performs all the normalizations and 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) ConvertInto ¶ added in v0.82.0
ConvertInto will use the defined exchange rates in the invoice to convert all the prices into the given currency.
The intent of this method is help convert the invoice amounts when the destination is unable or unwilling to handle the current currency. This is typically the case with tax related reports or declarations.
The method will return a new invoice with all the amounts converted into the given currency or an error if the conversion is not possible.
Conversion is done by first exchanging the lowest common amounts to the destination currency, then recalculating the totals.
func (*Invoice) Correct ¶ added in v0.40.0
Correct moves key fields of the current invoice to the preceding structure and performs any regime specific actions defined by the regime's configuration. If the existing document doesn't have a code, we'll raise an error, for most use cases this will prevent looping over the same invoice.
func (*Invoice) CorrectionOptionsSchema ¶ added in v0.58.1
CorrectionOptionsSchema provides a dynamic JSON schema of the options that can be used on the invoice in order to correct it. Data is extracted from the tax regime associated with the supplier.
func (*Invoice) Empty ¶ added in v0.40.0
func (inv *Invoice) Empty()
Empty is a convenience method that will empty all the lines and related rows.
func (*Invoice) GetExtensions ¶ added in v0.200.0
func (inv *Invoice) GetExtensions() []tax.Extensions
GetExtensions goes through the invoice and grabs all the extensions that are in use and expected to be used as part of a scenario.
func (*Invoice) GetType ¶ added in v0.200.0
GetType provides the invoice type as part of the tax.ScenarioDocument interface.
func (*Invoice) Invert ¶ added in v0.40.0
Invert effectively reverses the invoice by inverting the sign of all quantity or amount values. Caution should be taken when using this method as advances will also be inverted, while payment terms will remain the same, which could be confusing if no further modifications are made. After inverting the invoice is recalculated and any differences will raise an error.
func (Invoice) JSONSchemaExtend ¶ added in v0.38.0
func (inv Invoice) JSONSchemaExtend(js *jsonschema.Schema)
JSONSchemaExtend extends the schema with additional property details
func (*Invoice) Normalize ¶ added in v0.200.0
func (inv *Invoice) Normalize(normalizers tax.Normalizers)
Normalize is run as part of the Calculate method to ensure that the invoice is in a consistent state before calculations are performed. This will leverage any add-ons alongside the tax regime.
func (*Invoice) RemoveIncludedTaxes ¶ added in v0.25.2
RemoveIncludedTaxes is a special function that will go through all prices which may include the tax included in the invoice, and remove them.
This method will call "Calculate" on the invoice automatically both before and after to ensure that the data matches.
If after removing taxes the totals don't match, a rounding error will be added to the invoice totals. In most scenarios this shouldn't be more than a cent or two.
A new invoice object is returned, leaving the original instance untouched.
func (*Invoice) Replicate ¶ added in v0.75.0
Replicate modifies the invoice's fields to ensure that it can be used as part of a replication process. A replicated invoice is one that contains the same base details like supplier, customer, lines, etc., but with updated identifiers and dates.
func (*Invoice) ScenarioSummary
deprecated
added in
v0.38.0
func (inv *Invoice) ScenarioSummary() *tax.ScenarioSummary
ScenarioSummary determines a summary of the tax scenario for the invoice based on the document type and tax tags.
Deprecated: tax regimes should be updated to automatically apply all the required extensions and meta-data to the invoice itself. This method will still be needed until all regimes have transitioned to the new approach.
func (*Invoice) UNTDID1001 ¶ added in v0.38.0
UNTDID1001 provides the official code number assigned with the Invoice type.
func (*Invoice) UnmarshalJSON ¶ added in v0.200.0
UnmarshalJSON implements the json.Unmarshaler interface and provides any data migrations that might be required.
func (*Invoice) Validate ¶
Validate checks to ensure the invoice is valid and contains all the information we need.
func (*Invoice) ValidateWithContext ¶ added in v0.38.0
ValidateWithContext checks to ensure the invoice is valid and contains all the information we need.
type Line ¶
type Line struct { uuid.Identify // Line number inside the parent (calculated) Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"` // 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 (calculated) Sum num.Amount `json:"sum" jsonschema:"title=Sum" jsonschema_extras:"calculated=true"` // 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"` // Map of taxes to be applied and used in the invoice totals Taxes tax.Set `json:"taxes,omitempty" jsonschema:"title=Taxes"` // Total line amount after applying discounts to the sum (calculated). Total num.Amount `json:"total" jsonschema:"title=Total" jsonschema_extras:"calculated=true"` // Set of specific notes for this line that may be required for // clarification. Notes []*org.Note `json:"notes,omitempty" jsonschema:"title=Notes"` // contains filtered or unexported fields }
Line is a single row in an invoice.
func (*Line) GetTaxes ¶ added in v0.20.0
GetTaxes responds with the array of tax rates applied to this line.
func (*Line) GetTotal ¶
GetTotal provides the final total for this line, excluding any tax calculations.
func (*Line) Normalize ¶ added in v0.200.0
func (l *Line) Normalize(normalizers tax.Normalizers)
Normalize performs normalization on the line and embedded objects using the provided list of normalizers.
type LineCharge ¶ added in v0.13.0
type LineCharge struct { // Key for grouping or identifying charges for tax purposes. A suggested list of // keys is provided, but these are for reference only and may be extended by // the issuer. Key cbc.Key `json:"key,omitempty" jsonschema:"title=Key"` // Reference or ID for this charge defined by the issuer Code cbc.Code `json:"code,omitempty" jsonschema:"title=Code"` // Text description as to why the charge was applied Reason string `json:"reason,omitempty" jsonschema:"title=Reason"` // Percentage if fixed amount not applied Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"` // Fixed or resulting charge amount to apply (calculated if percent present). Amount num.Amount `json:"amount" jsonschema:"title=Amount" jsonschema_extras:"calculated=true"` // Extension codes that apply to the charge Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"` }
LineCharge represents an amount added to the line, and will be applied before taxes.
func CleanLineCharges ¶ added in v0.204.1
func CleanLineCharges(lines []*LineCharge) []*LineCharge
CleanLineCharges removes any empty charges from the list.
func (*LineCharge) IsEmpty ¶ added in v0.204.1
func (lc *LineCharge) IsEmpty() bool
IsEmpty returns true if the charge is empty.
func (LineCharge) JSONSchemaExtend ¶ added in v0.204.0
func (LineCharge) JSONSchemaExtend(schema *jsonschema.Schema)
JSONSchemaExtend adds the charge key definitions to the schema.
func (*LineCharge) Normalize ¶ added in v0.204.0
func (lc *LineCharge) Normalize(normalizers tax.Normalizers)
Normalize performs normalization on the charge and embedded objects using the provided list of normalizers.
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 { // Key for identifying the type of discount being applied. Key cbc.Key `json:"key,omitempty" jsonschema:"title=Key"` // Code or reference for this discount defined by the issuer Code cbc.Code `json:"code,omitempty" jsonschema:"title=Code"` // Text description as to why the discount was applied Reason string `json:"reason,omitempty" jsonschema:"title=Reason"` // Percentage to apply to the line total to calcaulte the discount amount Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"` // Fixed discount amount to apply (calculated if percent present) Amount num.Amount `json:"amount" jsonschema:"title=Amount" jsonschema_extras:"calculated=true"` // Extension codes that apply to the discount Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"` }
LineDiscount represents an amount deducted from the line, and will be applied before taxes.
func CleanLineDiscounts ¶ added in v0.204.1
func CleanLineDiscounts(lines []*LineDiscount) []*LineDiscount
CleanLineDiscounts removes any empty discounts from the list.
func (*LineDiscount) IsEmpty ¶ added in v0.204.1
func (ld *LineDiscount) IsEmpty() bool
IsEmpty returns true if the discount is empty.
func (LineDiscount) JSONSchemaExtend ¶ added in v0.204.0
func (LineDiscount) JSONSchemaExtend(schema *jsonschema.Schema)
JSONSchemaExtend adds the discount key definitions to the schema.
func (*LineDiscount) Normalize ¶ added in v0.204.0
func (ld *LineDiscount) Normalize(normalizers tax.Normalizers)
Normalize performs normalization on the discount and embedded objects using the provided list of normalizers.
func (*LineDiscount) Validate ¶ added in v0.13.0
func (ld *LineDiscount) Validate() error
Validate checks the line discount's fields.
type Ordering ¶
type Ordering struct { // Identifier assigned by the customer or buyer for internal routing purposes. Code cbc.Code `json:"code,omitempty" jsonschema:"title=Code"` // Any additional Codes, IDs, SKUs, or other regional or custom // identifiers that may be used to identify the order. Identities []*org.Identity `json:"identities,omitempty" jsonschema:"title=Identities"` // Period of time that the invoice document refers to often used in addition to the details // provided in the individual line items. Period *cal.Period `json:"period,omitempty" jsonschema:"title=Period"` // Party who is responsible for issuing payment, if not the same as the customer. Buyer *org.Party `json:"buyer,omitempty" jsonschema:"title=Buyer"` // Seller is the party liable to pay taxes on the transaction if not the same as the supplier. Seller *org.Party `json:"seller,omitempty" jsonschema:"title=Seller"` // Projects this invoice refers to. Projects []*org.DocumentRef `json:"projects,omitempty" jsonschema:"title=Projects"` // The identification of contracts. Contracts []*org.DocumentRef `json:"contracts,omitempty" jsonschema:"title=Contracts"` // Purchase orders issued by the customer or buyer. Purchases []*org.DocumentRef `json:"purchases,omitempty" jsonschema:"title=Purchase Orders"` // Sales orders issued by the supplier or seller. Sales []*org.DocumentRef `json:"sales,omitempty" jsonschema:"title=Sales Orders"` // Receiving Advice. Receiving []*org.DocumentRef `json:"receiving,omitempty" jsonschema:"title=Receiving Advice"` // Despatch advice. Despatch []*org.DocumentRef `json:"despatch,omitempty" jsonschema:"title=Despatch Advice"` // Tender advice, the identification of the call for tender or lot the invoice relates to. Tender []*org.DocumentRef `json:"tender,omitempty" jsonschema:"title=Tender Advice"` }
Ordering provides additional information about the ordering process including references to other documents and alternative parties involved in the order-to-delivery process.
func (*Ordering) Normalize ¶ added in v0.200.0
func (o *Ordering) Normalize(normalizers tax.Normalizers)
Normalize attempts to clean and normalize the Ordering data.
type Payment ¶
type Payment struct { // The party responsible for receiving payment of the invoice, if not the supplier. Payee *org.Party `json:"payee,omitempty" jsonschema:"title=Payee"` // Payment terms or conditions. Terms *pay.Terms `json:"terms,omitempty" jsonschema:"title=Terms"` // Any amounts that have been paid in advance and should be deducted from the amount due. Advances []*pay.Advance `json:"advances,omitempty" jsonschema:"title=Advances"` // Details on how payment should be made. Instructions *pay.Instructions `json:"instructions,omitempty" jsonschema:"title=Instructions"` }
Payment contains details as to how the invoice should be paid.
func (*Payment) Normalize ¶ added in v0.200.0
func (p *Payment) Normalize(normalizers tax.Normalizers)
Normalize will try to normalize the payment's data.
func (*Payment) ResetAdvances ¶ added in v0.41.0
func (p *Payment) ResetAdvances()
ResetAdvances clears the advances list.
type Tax ¶ added in v0.20.0
type Tax struct { // Category of the tax already included in the line item prices, especially // useful for B2C retailers with customers who prefer final prices inclusive of // tax. PricesInclude cbc.Code `json:"prices_include,omitempty" jsonschema:"title=Prices Include"` // Additional extensions that are applied to the invoice as a whole as opposed to specific // sections. Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"` // Any additional data that may be required for processing, but should never // be relied upon by recipients. Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"` // contains filtered or unexported fields }
Tax defines a summary of the taxes which may be applied to an invoice.
func (*Tax) MergeExtensions ¶ added in v0.207.0
func (t *Tax) MergeExtensions(ext tax.Extensions) *Tax
MergeExtensions makes it easier to add extensions to the tax object by automatically handling nil data, and replying a new updated instance.
func (*Tax) Normalize ¶ added in v0.200.0
func (t *Tax) Normalize(normalizers tax.Normalizers)
Normalize performs normalization on the tax and embedded objects using the provided list of normalizers.
func (*Tax) UnmarshalJSON ¶ added in v0.200.0
UnmarshalJSON helps migrate the desc field to description.
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 included in the invoice. Taxes *tax.Total `json:"taxes,omitempty" jsonschema:"title=Tax Totals"` // Total amount of tax to apply to the invoice. Tax num.Amount `json:"tax,omitempty" jsonschema:"title=Tax"` // Grand total after all taxes have been applied. TotalWithTax num.Amount `json:"total_with_tax" jsonschema:"title=Total with Tax"` // Rounding amount to apply to the invoice in case the total and payable // amounts don't quite match. Rounding *num.Amount `json:"rounding,omitempty" jsonschema:"title=Rounding"` // 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.