Skip to main content

Overview

The InvoiceLine class represents a single line item in an invoice. Each line contains information about the invoiced item, quantity, pricing, applicable taxes, and optional delivery and payment terms. An invoice typically contains multiple invoice lines representing different products or services.

Class Definition

import { InvoiceLine } from 'ubl-builder/lib/ubl21/CommonAggregateComponents';

Constructor Parameters

id
string | UdtIdentifier
required
An identifier for this invoice line (e.g., “1”, “2”, “3”)
invoicedQuantity
string | UdtQuantity
required
The quantity of items on this invoice line
lineExtensionAmount
string | UdtAmount
required
The total amount for this invoice line, including allowance charges but net of taxes
item
Item
required
The item associated with this invoice line
price
Price
required
The price of the item associated with this invoice line
uuid
string | UdtIdentifier
A universally unique identifier for this invoice line
notes
string[] | UdtText[]
Free-form text conveying information that is not contained explicitly in other structures
taxPointDate
string | UdtDate
The date of this invoice line, used to indicate the point at which tax becomes applicable
accountingCostCode
string | UdtCode
The buyer’s accounting cost centre for this invoice line, expressed as a code
accountingCost
string | UdtText
The buyer’s accounting cost centre for this invoice line, expressed as text
paymentPurposeCode
string | UdtCode
A code signifying the business purpose for this payment
freeOfChargeIndicator
string | UdtIndicator
An indicator that this invoice line is free of charge (true) or not (false). Default is false.
invoicePeriods
PeriodType[]
Invoice periods to which this invoice line applies
orderLineReferences
OrderLineReference[]
References to order lines associated with this invoice line
delivery
Delivery
Delivery information associated with this invoice line
paymentTerms
PaymentTerms
Payment terms associated with this invoice line
taxTotals
TaxTotal[]
Tax totals applicable to this invoice line
deliveryTerms
DeliveryTerms
Terms and conditions of the delivery associated with this invoice line

Methods

setId()

Sets the line identifier.
setId(value: string | UdtIdentifier): void
value
string | UdtIdentifier
required
The line ID

setLineExtensionAmount()

Sets the line extension amount (line total before taxes).
setLineExtensionAmount(value: string | UdtAmount, currencyID?: string): void
value
string | UdtAmount
required
The line extension amount
currencyID
string
default:"COP"
The currency code (e.g., “USD”, “EUR”)

getLineExtensionAmount()

Gets the line extension amount.
getLineExtensionAmount(rawValue?: boolean): string | UdtAmount
rawValue
boolean
default:"true"
If true, returns the raw string value. If false, returns the UdtAmount instance.
return
string | UdtAmount
The line extension amount

setTaxTotals()

Sets the array of tax totals for this line.
setTaxTotals(taxTotals: TaxTotal[]): void
taxTotals
TaxTotal[]
required
Array of TaxTotal instances

getTaxTotals()

Returns the array of tax totals.
getTaxTotals(): TaxTotal[]
return
TaxTotal[]
Array of tax totals

getPrice()

Returns the price object for this line.
getPrice(): Price
return
Price
The Price object

Usage Examples

import { 
  InvoiceLine,
  Item,
  Price,
  SellersItemIdentification,
  ClassifiedTaxCategory,
  TaxScheme
} from 'ubl-builder/lib/ubl21/CommonAggregateComponents';

// Create the item
const item = new Item({
  name: 'Laptop Computer',
  sellersItemIdentification: new SellersItemIdentification({ id: 'LAP-001' }),
  classifiedTaxCategory: new ClassifiedTaxCategory({
    id: 'S',
    percent: '21',
    taxScheme: new TaxScheme({ id: 'VAT' })
  })
});

// Create the price
const price = new Price({
  priceAmount: '1000.00'
});

// Create the invoice line
const line = new InvoiceLine({
  id: '1',
  invoicedQuantity: '2',
  lineExtensionAmount: '2000.00',
  item: item,
  price: price
});
The lineExtensionAmount should be calculated as invoicedQuantity * priceAmount (minus any line-level allowances/charges, before taxes). Always ensure this calculation is accurate to avoid validation errors.

Calculation Formula

For a basic invoice line:
lineExtensionAmount = invoicedQuantity × price.priceAmount
With taxes:
lineTaxAmount = lineExtensionAmount × taxRate
lineTotal = lineExtensionAmount + lineTaxAmount
  • Item - Item information and classification
  • Price - Price per unit
  • TaxTotal - Tax calculations for the line
  • Delivery - Delivery information
  • Invoice - Parent document containing invoice lines

Best Practices

  1. Sequential IDs: Use sequential line IDs (“1”, “2”, “3”) for clarity
  2. Currency Consistency: Ensure all amounts use the same currency as the parent invoice
  3. Quantity Units: Use appropriate unit codes in UdtQuantity (e.g., “EA” for each, “HUR” for hours)
  4. Tax Calculation: Always validate that tax amounts match the declared tax rates
  5. Line Totals: Verify that the sum of all line extension amounts equals the invoice’s LegalMonetaryTotal.LineExtensionAmount

UBL Schema Reference

For more information, see the UBL 2.1 InvoiceLine specification.

Build docs developers (and LLMs) love