Skip to content

Invoices

Supplier, invoice number, dates, amounts, payment terms and order references, plus charge rows that take their section from the table caption.

input.txtHover a value to see its type · click it to find it in the treeRun in Studio
SAMPLE INVOICE
Supplier: Bright Steps Learning Co.
Address: 48 Maple Avenue, Riverton, RV 20514
Invoice: INV-20241220-014
Issued: 2024-12-20
Services covered: 2024-12-02 through 2024-12-13
Due date: 2025-01-19
Amount payable: USD 3,900.00

Tutoring
School              Rate          Hours    Amount
Lincoln High        USD 25/hour   48       USD 1,200.00
Oak Middle          USD 25/hour   36       USD 900.00

Administration
School              Weekly rate    Weeks    Amount
Lincoln High        USD 450/week   2        USD 900.00
Oak Middle          USD 450/week   2        USD 900.00

Order reference: PO-552190
Task order: TO-30418
Contract: CN-77215
invoices.ymlspec
# Invoices: the facts an invoice states about itself, each a label and its value, and the rows of its
# tables of charges. Slash dates are not read, because their day and month order is not stated.

$imports: 'values'
$flags: [ CASE_INSENSITIVE ]

Invoice:
  $local:
    # Between a label and its value: a colon, a number sign, both, or a space.
    Is: '[ \t]*#?[ \t]*:[ \t]*|[ \t]*#[ \t]*|[ \t]+'
    # Up to the end of the line.
    Name: '\S([^\r\n]*\S)?'
    # A document number: INV-20241219-001, 2025-0042, RE-24/118, 4500123987.
    Code:
      $flags: [ -CASE_INSENSITIVE ]
      $patterns: '[A-Za-z]*[-/]?\d[A-Za-z0-9]*([-/.][A-Za-z0-9]+)*'
    Till: '[ \t]+(through|thru|to|until|till)[ \t]+|[ \t]*[-–—][ \t]*'

  Supplier:
    $local:
      Label: [ 'Supplier', 'Vendor', 'Seller', 'Contractor', 'From', 'Billed by', '(Service )?provider' ]
    $fields: { name: Name }
    # Only after a colon: 'services from 2025-01-01' names no supplier.
    $patterns: '${Label}[ \t]*:[ \t]*#{name}'
    $value: '#{name}'

  Address:
    $local:
      Label: [ 'Address', '(Supplier|Remit to|Billing) address' ]
    $fields: { address: Name }
    $patterns: '${Label}[ \t]*:[ \t]*#{address}'
    $value: '#{address}'

  Id:
    $local:
      Label: [ 'Invoice', 'Invoice (number|no\.?|id)', 'Inv\. no\.?' ]
    $fields: { code: Code }
    $patterns: '${Label}${Is}#{code}'
    $value: '#{code}'

  # A date the invoice states: each kind declares its label.
  Dates:
    $flags: [ MULTILINE ]
    $fields: { date: Date }
    $patterns: '${Label}${Is}#{date}'
    $value: '#{date}'

    Issue:
      $local:
        # A bare 'Date' counts only at the start of a line, not in 'Due date' or 'Order date'.
        Label: [ 'Issued( on)?', 'Issue date', 'Date of issue', 'Invoice date', 'Dated', '^[ \t]*Date' ]

    Due:
      $local:
        Label: [ 'Due date', '(Payment )?due( on| by)?', 'Pay by' ]

  ServicePeriod:
    $local:
      Label:
        - 'Services covered'
        - 'Services( rendered| provided| performed)?'
        - '(Service|Billing|Invoice) period'
        - 'Period( of service)?'
        - 'For the period'
    $fields: { start: Date, end: Date }
    $patterns: '${Label}${Is}(from[ \t]+)?#{start}${Till}#{end}'
    $value: { start: '#{start}', end: '#{end}' }

  # An amount the invoice states: each kind declares its label.
  Amounts:
    $fields: { amount: Money::Amount }
    $patterns: '${Label}${Is}#{amount}'
    $value: { amount: '#{amount.amount}', currency: '#{amount.currency}' }

    Subtotal:
      $local:
        Label: [ 'Sub-?total' ]

    Tax:
      $local:
        # Sales tax, VAT 20%, Tax (8%)
        Label: [ '((Sales )?tax|VAT|GST)( \(?\d+(\.\d+)?%\)?)?' ]

    Payable:
      $local:
        Label:
          - 'Amount (payable|due)'
          - 'Total( amount)? (payable|due)'
          - 'Balance due'
          - 'Please pay'
          - '(Grand|Invoice) total'
          - 'Total'

  # When payment is due, counted in days: Net 30, payable within 30 days.
  PaymentTerms:
    $local: { Days: '\d+' }
    $fields: { days: Days }
    $patterns:
      - 'Net ?#{days}'
      - '(payable |due )?(within|in) #{days} days'
    $value: '#{days}'

  # A reference to another document: each kind declares its label.
  Reference:
    $fields: { code: Code }
    $patterns: '${Label}${Is}#{code}'
    $value: '#{code}'

    Order:
      $local:
        Label:
          - '(Purchase )?order( reference| ref\.?| number| no\.?)?'
          - 'P\.?O\.?( number| no\.?)?'

    TaskOrder:
      $local:
        Label: 'Task order( number| no\.?)?'

    Contract:
      $local:
        Label:
          - 'Contract( reference| ref\.?| number| no\.?)?'
          - 'Agreement( number| no\.?)?'

    Other:
      $local:
        Label: '((Our|Your|Customer) )?(reference|ref\.?)( number| no\.?)?'

# One row of a table of charges. The header names the columns, and a caption above the header, such as
# 'Tutoring', names the section of every row.
LineItem:
  $local:
    Text: '\S([^\r\n]*\S)?'
    DescriptionHeader: [ 'Description', 'Item', 'Service', 'Product', 'Particulars', 'Details', 'Activity', 'School' ]
    QuantityHeader: [ 'Qty\.?', 'Quantity', 'Hours', 'Days', 'Weeks', 'Months', 'Units' ]
    RateHeader: [ 'Rate', '(Hourly|Daily|Weekly|Monthly) rate', 'Unit price', 'Price', 'Unit cost' ]
    AmountHeader: [ 'Amount', 'Total', 'Line total' ]
  $fields:
    section: Text
    description: Text
    quantity: Number
    rate: Money
    amount: Money::Amount
  $tables:
    $caption: section
    $columns:
      description: DescriptionHeader
      quantity: QuantityHeader
      rate: RateHeader
      amount: AmountHeader
  $value:
    section: '[#{section}]'
    description: '#{description}'
    quantity: '[#{quantity}]'
    rate: '[#{rate.amount}]'
    per: '[#{rate.per}]'
    amount: '[#{amount.amount}]'
    currency: '[#{amount.currency}]'
$ texomy parse input.txt -m invoices
invoices.json
[
  {
    "type": "Invoice::Supplier",
    "start": 15,
    "end": 50,
    "fields": {
      "name": {
        "type": "Name",
        "start": 25,
        "end": 50,
        "text": "Bright Steps Learning Co."
      }
    },
    "value": "Bright Steps Learning Co."
  },
  {
    "type": "Invoice::Address",
    "start": 51,
    "end": 95,
    "fields": {
      "address": {
        "type": "Name",
        "start": 60,
        "end": 95,
        "text": "48 Maple Avenue, Riverton, RV 20514"
      }
    },
    "value": "48 Maple Avenue, Riverton, RV 20514"
  },
  {
    "type": "Invoice::Id",
    "start": 96,
    "end": 121,
    "fields": {
      "code": {
        "type": "Code",
        "start": 105,
        "end": 121,
        "text": "INV-20241220-014"
      }
    },
    "value": "INV-20241220-014"
  },
  {
    "type": "Invoice::Dates::Issue",
    "start": 122,
    "end": 140,
    "fields": {
      "date": {
        "type": "Date::Iso",
        "start": 130,
        "end": 140,
        "fields": {
          "year": {
            "type": "Year",
            "start": 130,
            "end": 134,
            "text": "2024"
          },
          "month": {
            "type": "Month::Numeric",
            "start": 135,
            "end": 137,
            "text": "12"
          },
          "day": {
            "type": "Day::Two",
            "start": 138,
            "end": 140,
            "text": "20"
          }
        },
        "value": "2024-12-20"
      }
    },
    "value": "2024-12-20"
  },
  {
    "type": "Invoice::ServicePeriod",
    "start": 141,
    "end": 188,
    "fields": {
      "start": {
        "type": "Date::Iso",
        "start": 159,
        "end": 169,
        "fields": {
          "year": {
            "type": "Year",
            "start": 159,
            "end": 163,
            "text": "2024"
          },
          "month": {
            "type": "Month::Numeric",
            "start": 164,
            "end": 166,
            "text": "12"
          },
          "day": {
            "type": "Day::Two",
            "start": 167,
            "end": 169,
            "text": "02"
          }
        },
        "value": "2024-12-02"
      },
      "end": {
        "type": "Date::Iso",
        "start": 178,
        "end": 188,
        "fields": {
          "year": {
            "type": "Year",
            "start": 178,
            "end": 182,
            "text": "2024"
          },
          "month": {
            "type": "Month::Numeric",
            "start": 183,
            "end": 185,
            "text": "12"
          },
          "day": {
            "type": "Day::Two",
            "start": 186,
            "end": 188,
            "text": "13"
          }
        },
        "value": "2024-12-13"
      }
    },
    "value": {
      "start": "2024-12-02",
      "end": "2024-12-13"
    }
  },
  {
    "type": "Invoice::Dates::Due",
    "start": 189,
    "end": 209,
    "fields": {
      "date": {
        "type": "Date::Iso",
        "start": 199,
        "end": 209,
        "fields": {
          "year": {
            "type": "Year",
            "start": 199,
            "end": 203,
            "text": "2025"
          },
          "month": {
            "type": "Month::Numeric",
            "start": 204,
            "end": 206,
            "text": "01"
          },
          "day": {
            "type": "Day::Two",
            "start": 207,
            "end": 209,
            "text": "19"
          }
        },
        "value": "2025-01-19"
      }
    },
    "value": "2025-01-19"
  },
  {
    "type": "Invoice::Amounts::Payable",
    "start": 210,
    "end": 238,
    "fields": {
      "amount": {
        "type": "Money::Amount",
        "start": 226,
        "end": 238,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 230,
            "end": 238,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 230,
                  "end": 231,
                  "text": "3"
                },
                {
                  "type": "Digits",
                  "start": 232,
                  "end": 235,
                  "text": "900"
                }
              ],
              "fraction": {
                "type": "Digits",
                "start": 236,
                "end": 238,
                "text": "00"
              }
            },
            "value": "3900.00"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 226,
            "end": 229,
            "text": "USD",
            "value": "USD"
          }
        },
        "value": {
          "amount": "3900.00",
          "currency": "USD"
        }
      }
    },
    "value": {
      "amount": "3900.00",
      "currency": "USD"
    }
  },
  {
    "type": "LineItem",
    "start": 240,
    "end": 354,
    "fields": {
      "section": {
        "type": "Text",
        "start": 240,
        "end": 248,
        "text": "Tutoring"
      },
      "description": {
        "type": "Text",
        "start": 299,
        "end": 311,
        "text": "Lincoln High"
      },
      "quantity": {
        "type": "Number",
        "start": 333,
        "end": 335,
        "fields": {
          "groups": [
            {
              "type": "Digits",
              "start": 333,
              "end": 335,
              "text": "48"
            }
          ]
        },
        "value": "48"
      },
      "rate": {
        "type": "Money::Rate",
        "start": 319,
        "end": 330,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 323,
            "end": 325,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 323,
                  "end": 325,
                  "text": "25"
                }
              ]
            },
            "value": "25"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 319,
            "end": 322,
            "text": "USD",
            "value": "USD"
          },
          "per": {
            "type": "Unit::Hour",
            "start": 326,
            "end": 330,
            "text": "hour",
            "value": "hour"
          }
        },
        "value": {
          "amount": "25",
          "currency": "USD",
          "per": "hour"
        }
      },
      "amount": {
        "type": "Money::Amount",
        "start": 342,
        "end": 354,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 346,
            "end": 354,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 346,
                  "end": 347,
                  "text": "1"
                },
                {
                  "type": "Digits",
                  "start": 348,
                  "end": 351,
                  "text": "200"
                }
              ],
              "fraction": {
                "type": "Digits",
                "start": 352,
                "end": 354,
                "text": "00"
              }
            },
            "value": "1200.00"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 342,
            "end": 345,
            "text": "USD",
            "value": "USD"
          }
        },
        "value": {
          "amount": "1200.00",
          "currency": "USD"
        }
      }
    },
    "value": {
      "section": "Tutoring",
      "description": "Lincoln High",
      "quantity": "48",
      "rate": "25",
      "per": "hour",
      "amount": "1200.00",
      "currency": "USD"
    }
  },
  {
    "type": "LineItem",
    "start": 240,
    "end": 408,
    "fields": {
      "section": {
        "type": "Text",
        "start": 240,
        "end": 248,
        "text": "Tutoring"
      },
      "description": {
        "type": "Text",
        "start": 355,
        "end": 365,
        "text": "Oak Middle"
      },
      "quantity": {
        "type": "Number",
        "start": 389,
        "end": 391,
        "fields": {
          "groups": [
            {
              "type": "Digits",
              "start": 389,
              "end": 391,
              "text": "36"
            }
          ]
        },
        "value": "36"
      },
      "rate": {
        "type": "Money::Rate",
        "start": 375,
        "end": 386,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 379,
            "end": 381,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 379,
                  "end": 381,
                  "text": "25"
                }
              ]
            },
            "value": "25"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 375,
            "end": 378,
            "text": "USD",
            "value": "USD"
          },
          "per": {
            "type": "Unit::Hour",
            "start": 382,
            "end": 386,
            "text": "hour",
            "value": "hour"
          }
        },
        "value": {
          "amount": "25",
          "currency": "USD",
          "per": "hour"
        }
      },
      "amount": {
        "type": "Money::Amount",
        "start": 398,
        "end": 408,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 402,
            "end": 408,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 402,
                  "end": 405,
                  "text": "900"
                }
              ],
              "fraction": {
                "type": "Digits",
                "start": 406,
                "end": 408,
                "text": "00"
              }
            },
            "value": "900.00"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 398,
            "end": 401,
            "text": "USD",
            "value": "USD"
          }
        },
        "value": {
          "amount": "900.00",
          "currency": "USD"
        }
      }
    },
    "value": {
      "section": "Tutoring",
      "description": "Oak Middle",
      "quantity": "36",
      "rate": "25",
      "per": "hour",
      "amount": "900.00",
      "currency": "USD"
    }
  },
  {
    "type": "LineItem",
    "start": 410,
    "end": 530,
    "fields": {
      "section": {
        "type": "Text",
        "start": 410,
        "end": 424,
        "text": "Administration"
      },
      "description": {
        "type": "Text",
        "start": 476,
        "end": 488,
        "text": "Lincoln High"
      },
      "quantity": {
        "type": "Number",
        "start": 511,
        "end": 512,
        "fields": {
          "groups": [
            {
              "type": "Digits",
              "start": 511,
              "end": 512,
              "text": "2"
            }
          ]
        },
        "value": "2"
      },
      "rate": {
        "type": "Money::Rate",
        "start": 496,
        "end": 508,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 500,
            "end": 503,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 500,
                  "end": 503,
                  "text": "450"
                }
              ]
            },
            "value": "450"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 496,
            "end": 499,
            "text": "USD",
            "value": "USD"
          },
          "per": {
            "type": "Unit::Week",
            "start": 504,
            "end": 508,
            "text": "week",
            "value": "week"
          }
        },
        "value": {
          "amount": "450",
          "currency": "USD",
          "per": "week"
        }
      },
      "amount": {
        "type": "Money::Amount",
        "start": 520,
        "end": 530,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 524,
            "end": 530,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 524,
                  "end": 527,
                  "text": "900"
                }
              ],
              "fraction": {
                "type": "Digits",
                "start": 528,
                "end": 530,
                "text": "00"
              }
            },
            "value": "900.00"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 520,
            "end": 523,
            "text": "USD",
            "value": "USD"
          }
        },
        "value": {
          "amount": "900.00",
          "currency": "USD"
        }
      }
    },
    "value": {
      "section": "Administration",
      "description": "Lincoln High",
      "quantity": "2",
      "rate": "450",
      "per": "week",
      "amount": "900.00",
      "currency": "USD"
    }
  },
  {
    "type": "LineItem",
    "start": 410,
    "end": 585,
    "fields": {
      "section": {
        "type": "Text",
        "start": 410,
        "end": 424,
        "text": "Administration"
      },
      "description": {
        "type": "Text",
        "start": 531,
        "end": 541,
        "text": "Oak Middle"
      },
      "quantity": {
        "type": "Number",
        "start": 566,
        "end": 567,
        "fields": {
          "groups": [
            {
              "type": "Digits",
              "start": 566,
              "end": 567,
              "text": "2"
            }
          ]
        },
        "value": "2"
      },
      "rate": {
        "type": "Money::Rate",
        "start": 551,
        "end": 563,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 555,
            "end": 558,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 555,
                  "end": 558,
                  "text": "450"
                }
              ]
            },
            "value": "450"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 551,
            "end": 554,
            "text": "USD",
            "value": "USD"
          },
          "per": {
            "type": "Unit::Week",
            "start": 559,
            "end": 563,
            "text": "week",
            "value": "week"
          }
        },
        "value": {
          "amount": "450",
          "currency": "USD",
          "per": "week"
        }
      },
      "amount": {
        "type": "Money::Amount",
        "start": 575,
        "end": 585,
        "fields": {
          "amount": {
            "type": "Number",
            "start": 579,
            "end": 585,
            "fields": {
              "groups": [
                {
                  "type": "Digits",
                  "start": 579,
                  "end": 582,
                  "text": "900"
                }
              ],
              "fraction": {
                "type": "Digits",
                "start": 583,
                "end": 585,
                "text": "00"
              }
            },
            "value": "900.00"
          },
          "currency": {
            "type": "Currency::Usd",
            "start": 575,
            "end": 578,
            "text": "USD",
            "value": "USD"
          }
        },
        "value": {
          "amount": "900.00",
          "currency": "USD"
        }
      }
    },
    "value": {
      "section": "Administration",
      "description": "Oak Middle",
      "quantity": "2",
      "rate": "450",
      "per": "week",
      "amount": "900.00",
      "currency": "USD"
    }
  },
  {
    "type": "Invoice::Reference::Order",
    "start": 587,
    "end": 613,
    "fields": {
      "code": {
        "type": "Code",
        "start": 604,
        "end": 613,
        "text": "PO-552190"
      }
    },
    "value": "PO-552190"
  },
  {
    "type": "Invoice::Reference::TaskOrder",
    "start": 614,
    "end": 634,
    "fields": {
      "code": {
        "type": "Code",
        "start": 626,
        "end": 634,
        "text": "TO-30418"
      }
    },
    "value": "TO-30418"
  },
  {
    "type": "Invoice::Reference::Contract",
    "start": 635,
    "end": 653,
    "fields": {
      "code": {
        "type": "Code",
        "start": 645,
        "end": 653,
        "text": "CN-77215"
      }
    },
    "value": "CN-77215"
  }
]

About this spec

Invoices: supplier, invoice number, dates, service period, amounts, payment terms and references to orders and contracts, and the rows of charge tables with their section, quantity, rate and amount.

Package files

  • invoices.yml
  • texomy.json
  • values.yml
  • samples/consulting.txt
  • samples/prose.txt
  • samples/quote.txt
  • samples/software.txt
  • tests/invoices.test.yml
  • tests/samples.test.yml

99 nodes from 14 top-level matches.

Run it yourself

Save the example from Studio to a folder, then in that folder:

texomy parse input.txt -m invoices
texomy test

Write the spec once. Run it on everything.

Install the CLI, connect your agent, and turn your first sample into typed data in minutes.

brew install texomy/tap/texomy