Skip to content

Catalog-backed invoices and lines

Invoice headers and lines joined to catalog chart of accounts, payment terms and country VAT rates.

related volume small InvoicesAccountingFinanceCatalogRelationships
Languages
eng
Formats
csv

Recipe

recipe.gbddl
gbddl 1
language eng

table accounts catalog(glAccount, parent: "generic") (
  number text primarykey catalogField(column: "number")
  name   text catalogField(column: "name")
  class  text catalogField(column: "class")
)

table terms catalog(paymentTerm) (
  code     varchar(12) primarykey catalogField(column: "code")
  name     text catalogField(column: "name")
  net_days int16 catalogField(column: "net_days")
)

table countries catalog(country, group: "G20") (
  iso      text primarykey countryCode()
  vat_rate decimal(4, 1) catalogField(column: "vat_rate")
)

table invoices rows 20 (
  id        int64 autoincrement primarykey
  number    text unique pattern(pattern: "INV-#####")
  country   text fk(countries.iso)
  vat_rate  decimal(4, 1) eq(country.vat_rate)
  account   text fk(accounts.number)
  term      varchar(12) fk(terms.code)
  issued_on date date(min: "2023-01-01", max: "2024-12-31")
  amount    decimal(10, 2) money(min: 10, max: 5000)
)

table invoice_lines rows 60 per(invoices, 1, 4) (
  id          int64 autoincrement primarykey
  invoice_id  int64 fk(invoices.id)
  account     text fk(accounts.number)
  description text words(maxWords: 4)
  quantity    int64 integer(min: 1, max: 10)
  unit_price  decimal(8, 2) decimal(min: 1, max: 1000)
)

output csv

This is the exact recipe.gbddl committed to the repository. Copy it, or download the raw source.

About this recipe

Catalog-backed invoices

A multi-table recipe that generates invoice headers and lines whose reference data is joined from the catalog instead of generated freely: the chart of accounts, the payment terms and the country VAT rates are real catalog values.

What it demonstrates

  • Catalog tables — accounts, terms and countries are catalog(...) tables, so each row is a real record of the selected catalog type rather than a drawn value.
  • Catalog fields — catalogField(column: ...) reads the number, name and class of each account, the code, name and net_days of each term, and the vat_rate of each country. countryCode() reads the country's ISO alpha-2 code.
  • Foreign keys into the catalog — invoices references accounts.number, terms.code and countries.iso, and invoice_lines references accounts.number and invoices.id, so every reference is a real code.
  • Equality pull — invoices.vat_rate is eq(country.vat_rate): it copies the VAT rate of the referenced country row, keeping the rate coherent with the country instead of drawing an unrelated number.
  • Relationships and distribution — invoice_lines is grouped per(invoices, 1, 4), one to four lines per invoice, and the invoice number is a unique pattern mask.

Run it

Submit the recipe body to POST /api/v1/jobs?input_format=gbddl, or paste it into Chef, to generate the data. The repository's local runner (run by task test) also generates it and verifies its output.

The recipe outputs one CSV file per table: accounts.csv, terms.csv, countries.csv, invoices.csv and invoice_lines.csv.

Adapt it

  • Change parent: "generic" to skr03, skr04 or pcg for another chart of accounts.
  • Change group: "G20" to another country group (for example EU) to use a different set of VAT rates.
  • Add catalogField(column: "discount_pct") to terms to expose the cash discount, or pull the country name into invoices with a second eq.

Guarantees and limitations

Every primary key and unique invoice number is distinct, every foreign key names an existing parent row (a real account, term, country or invoice), and invoices.vat_rate equals the referenced country's catalog rate. The VAT rate is the catalog's well-formed placeholder, not audit-grade tax data; amounts are synthetic and the dataset is not a balanced ledger.

Tested features

Smart types, physical types, rules and formats this recipe exercises and verifies.

catalogFieldtable:catalogcountryCodepatterndatemoneywordsintegerdecimalprimary-keyuniquefkpereqautoincrement