# `commerce@1`: merchant sales and costs

Version **1.1.0** · published 2026-12-02 · MIT · boards (planned): ecommerce-orders, ticket-sales, daily-sales-covers, food-cost, affiliates, sponsorships, sales-tax-vat · [changelog](../CHANGELOG.md)

A connector writes the grains present in its source. A board can read just the tables it needs, leaving the other
tables empty. Order-level exports, summarized POS reports, affiliate reports and supplier invoices are kept at
their own grain, without creating synthetic orders or adding overlapping totals. Subscription state and invoice
receivables belong to [`billing@1`](../../billing/1/README.md).

| Reader | Tables |
|---|---|
| E-commerce Orders | `orders`, `order_lines`, `refunds`, `channels`, `products` |
| Sales Tax / VAT | `orders`, `refunds`, `order_taxes` for the commerce input paired with finance records |
| Ticket Sales | the order and refund tables plus `events` and `event_sales_targets` |
| Daily Sales & Covers | `channels` and `pos_daily` |
| Food Cost | `supplier_invoice_lines` and `pos_daily` |
| Affiliates | `affiliate_daily` |
| Sponsorships | `sponsorship_deals` and `sponsorship_payouts` |

## Conventions

- **Identity.** Namespace each source record by provider and merchant account. E.g.
  `store-csv:orchid-store:order:105`. Match source IDs across file and API lanes for the same provider
  and account. For a source without IDs, hash the stable natural key with an occurrence counter for genuinely
  distinct otherwise-identical rows. Never use import time or physical row order to generate an identity. Retain
  only an opaque buyer or contact identifier. Do not store raw contact details, addresses or payment credentials.
- **Provenance.** Every imported row keeps `source`, `source_ref` and `imported_at`. Use `confidence` only
  for inferred values. A source reference identifies an object or file and line, with private content stripped.
  Record imports' skipped or unresolved rows in `import_issues` at their original grain.
- **Time.** Local business days use `YYYY-MM-DD`. An order with a timestamp carries it in UTC plus an IANA
  time zone. A source-provided local business day takes precedence over the calendar date when a merchant's
  reporting cutoff is after midnight. Use the event time zone for ticket targets.
- **Currencies.** Amounts are in major units of the row's ISO 4217 currency. Group by currency before summing.
  `meta.base_currency` is the reporting preference. There are no implied conversion rates.
- **Required metadata.** Set `schema`, `schema_version`, `as_of`, `data_hash`, `source_built_at`
  and `base_currency`. Hash the normalized source-derived rows with deterministic ordering, excluding import
  timestamps. `source_built_at` is the UTC instant when those rows were built. `as_of` is the local report day.

## Sales, refunds and tax

For an accepted sale (`orders.status = 'completed'`), the original amount charged is merchandise gross less its
discount, plus shipping and tax. A refund leaves these order values intact. Its total is refunded net merchandise
plus refunded shipping and tax. Merchandise sales net of refunds is completed orders' gross less discount, less
the refunds' **merchandise** component. Use the sale day for booked sales and the refund day for reductions in
period reports. The original order ID supports a separate cohort view.

Use order rows for order counts, average order value and identified repeat buyers. Count each order once even when
it has multiple products. Use line rows for product sales. A source may only export part of the item detail and
may leave order-level discounts unallocated. Imported line sums cannot exceed order totals for the corresponding
components. Reconcile a complete export against its order totals separately. Optional refund line IDs allow ticket
returns to be assigned to an event and product returns to an item. Without a line link, use the refund at order grain.
If the source provides both refund headers and component allocations, retain either the header or allocations plus
any unallocated balance so monetary amounts appear only once.

Report tax charged and tax returned separately by period and jurisdiction. An order's known jurisdiction components
cannot exceed the order charge. A refund's known components cannot exceed its returned tax. A partial breakdown is
allowed. Keep the unassigned portion visible as a gap. Tax basis and rate can be absent. Do not derive tax obligations
or filing dates from tax amounts. They can be board settings backed by local records.

## Other grains

- **Ticketing.** A ticket is one unit on a line linked to an event. Counts are whole numbers for ticket
  lines and their linked returns. Use net tickets sold through each target's local day to compare cumulative pace.
  Capacity and targets can be left out when unknown. Channel comes from the order.
- **Point of sale.** A channel's daily and daypart totals must be mutually exclusive for a given day and currency.
  Net POS sales excludes tax and deducts discounts and refunds. It can be negative on a return-heavy day.
  Use covers for sales per guest and closed checks for average check, and leave the result empty when its
  denominator was not exported or is zero.
- **Cost of food.** Use supplier purchase amount less credits, per currency and category. Invoice dates describe
  purchase timing. Units must match before comparing per-unit prices. Invoice cost over net POS sales is a
  purchases-to-sales measure. Inventory consumption and waste need additional data.
- **Affiliates.** One row per disjoint partner/day/status bucket. Payout status is a classification of the current
  records. A transition from approved to paid replaces the prior classification. A separate reversal is subtracted
  once from commission. Clicks and conversions can be unknown. An unallocated click-only daily summary can occupy
  its own `unknown` bucket so counts are not repeated across statuses.
- **Sponsorships.** Booked, delivered and paid are distinct. Store contract and delivery state on the deal,
  and settled amounts in the payout rows. Multiple payouts can apply to one deal. A deal's booked amount
  is counted once. Rates need comparable currency and placement units.

## Ship-to place (1.1)

`orders.ship_country` and `orders.ship_region` hold where an order shipped (or was collected) when the export gives
it, so a sales-tax or VAT board can group sales by jurisdiction. They are optional: a board treats an order without
them as "place unknown" and never infers a place from a currency or a channel.

## Compatibility

Boards declaring `commerce@1 >=1.0` work with later 1.x databases. New optional fields and tables do not require
changes to existing metrics. A major version uses an explicit migration and a one-release overlap. The original
input files remain the rebuild source. See the [standard rules](../../README.md) for extensions and versioning.

<!-- fields:begin (generated from schema.sql by spec/build.py; edit the DDL comments) -->

### `meta` (required table)

Database metadata. See standard.json for required keys.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `key` | TEXT | **yes** | metadata key, e.g. base_currency |
| `value` | TEXT | no | text value |

### `channels`

One channel within a merchant account, including an offline register or ticket outlet.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `channel_id` | TEXT | **yes** | stable namespaced id |
| `name` | TEXT | **yes** | display label, e.g. Lobby box office |
| `kind` | TEXT (vocab `channel_kinds`) | **yes** | channel_kinds vocabulary |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `products`

One product, ticket class, or POS item from the merchant's catalogue.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `product_id` | TEXT | **yes** | stable namespaced product or variant id |
| `name` | TEXT | **yes** | display label, e.g. Ceramic cup |
| `sku` | TEXT | no | merchant's published item code |
| `category` | TEXT | no | source category, if provided |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `events`

One ticketed event or performance. Every separately sold occurrence has its own event id.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `event_id` | TEXT | **yes** | stable namespaced id |
| `name` | TEXT | **yes** | event label, e.g. Paper Lantern Night |
| `starts_at` | TEXT (instant) | **yes** | UTC start instant |
| `tz` | TEXT | **yes** | IANA time zone of the event |
| `capacity` | INTEGER | no | sellable admission count, when declared |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `orders`

One merchant order at its original value, before refunds.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `order_id` | TEXT | **yes** | stable merchant-scoped id |
| `channel_id` | TEXT | **yes** | sales channel, including an explicitly unknown channel |
| `customer_id` | TEXT | no | opaque merchant-scoped buyer id, when repeat buyers can be identified |
| `ordered_on` | TEXT (date) | **yes** | merchant-local order day |
| `ordered_at` | TEXT (instant) | no | UTC order instant when available |
| `tz` | TEXT | no | IANA time zone used for ordered_on, when available |
| `ship_country` | TEXT (country) | no | ISO 3166-1 alpha-2 country the order shipped to (or was collected in), when the export gives it (1.1) |
| `ship_region` | TEXT | no | ISO 3166-2 subdivision code without the country prefix (CA, ON, NSW), when given; the tax jurisdiction a sales-tax board groups by (1.1) |
| `status` | TEXT (vocab `order_status`) | **yes** | order_status vocabulary |
| `currency` | TEXT (currency) | **yes** | ISO 4217 of every amount on this row |
| `gross_amount` | REAL | **yes** | merchandise amount before discounts, shipping and tax |
| `discount_amount` | REAL | **yes** | reduction in merchandise price |
| `shipping_amount` | REAL | **yes** | shipping charged, excluding tax |
| `tax_amount` | REAL | **yes** | total tax charged, including shipping tax where applicable |
| `total_amount` | REAL | **yes** | gross minus discount plus shipping and tax |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `order_lines`

One merchandise line on an order. A ticket line links to its event; other lines leave event_id empty.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `line_id` | TEXT | **yes** | stable namespaced id |
| `order_id` | TEXT | **yes** | original order id |
| `product_id` | TEXT | no | known product or ticket class |
| `event_id` | TEXT | no | ticketed occurrence |
| `quantity` | REAL | **yes** | sold quantity; fractional quantities are valid for weighed goods |
| `currency` | TEXT (currency) | **yes** | ISO 4217, same as the order |
| `gross_amount` | REAL | **yes** | line amount before discounts and tax |
| `discount_amount` | REAL | **yes** | discount allocated to this line, including order-level discounts if allocated |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `refunds`

One non-overlapping amount refunded. An export can contain order-level rows, item allocations or both at distinct grains.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `refund_id` | TEXT | **yes** | stable refund id or refund-allocation id |
| `order_id` | TEXT | **yes** | original order id |
| `line_id` | TEXT | no | refunded item where known |
| `refunded_on` | TEXT (date) | **yes** | merchant-local effective refund day |
| `quantity` | REAL | no | refunded item units if the source reports them |
| `currency` | TEXT (currency) | **yes** | ISO 4217, same as the order |
| `merchandise_amount` | REAL | **yes** | refunded merchandise after applicable discounts |
| `shipping_amount` | REAL | **yes** | refunded shipping, excluding tax |
| `tax_amount` | REAL | **yes** | tax returned to the buyer |
| `total_amount` | REAL | **yes** | merchandise plus shipping and tax |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `order_taxes`

One tax component by jurisdiction on an order or refund, where the source breaks it out.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `tax_id` | TEXT | **yes** | stable namespaced tax component id |
| `order_id` | TEXT | **yes** | original order id |
| `refund_id` | TEXT | no | tax returned; NULL means tax charged on sale |
| `jurisdiction` | TEXT | **yes** | source tax jurisdiction code or stable mapped label |
| `tax_kind` | TEXT (vocab `tax_kinds`) | **yes** | tax_kinds vocabulary |
| `rate` | REAL | no | applied share as a decimal, e.g. 0.075 |
| `taxable_amount` | REAL | no | reported taxable basis for this component, including a zero basis |
| `currency` | TEXT (currency) | **yes** | ISO 4217, same as the order |
| `tax_amount` | REAL | **yes** | nonnegative collected or returned component |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `event_sales_targets`

One planned end-of-day cumulative ticket target for an event.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `target_id` | TEXT | **yes** | stable id derived from event and target day |
| `event_id` | TEXT | **yes** | target event |
| `target_on` | TEXT (date) | **yes** | date in events.tz |
| `tickets_target` | INTEGER | **yes** | desired cumulative net tickets by end of day |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `pos_daily`

One non-overlapping daily or daypart POS summary for a channel, with no synthetic order rows.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `summary_id` | TEXT | **yes** | stable namespaced id |
| `channel_id` | TEXT | **yes** | reporting location or register |
| `sold_on` | TEXT (date) | **yes** | local business date of the shift |
| `daypart` | TEXT (vocab `dayparts`) | **yes** | dayparts vocabulary |
| `covers` | INTEGER | no | guests seated; NULL if unavailable |
| `checks` | INTEGER | no | closed checks; NULL if unavailable |
| `currency` | TEXT (currency) | **yes** | ISO 4217 of every amount on this row |
| `gross_amount` | REAL | **yes** | merchandise sales before discounts/refunds, excluding tax |
| `discount_amount` | REAL | **yes** | discounts applied |
| `refund_amount` | REAL | **yes** | merchandise refunds recorded that day or daypart |
| `net_amount` | REAL | **yes** | gross minus discounts and refunds, possibly negative |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `supplier_invoice_lines`

One supplier invoice or supplier credit line for food and other inventory costs.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `line_id` | TEXT | **yes** | stable namespaced source invoice line id |
| `invoice_id` | TEXT | **yes** | merchant-scoped source supplier invoice id |
| `supplier_id` | TEXT | **yes** | opaque supplier id in this merchant's account |
| `issued_on` | TEXT (date) | **yes** | supplier invoice date |
| `item_id` | TEXT | no | opaque supplier item id, when available |
| `item_name` | TEXT | **yes** | product display label |
| `category` | TEXT | no | explicit category, e.g. food or beverages |
| `kind` | TEXT (vocab `supplier_line_kinds`) | **yes** | supplier_line_kinds vocabulary |
| `quantity` | REAL | no | positive billed or credited units when available |
| `unit` | TEXT | no | unit of quantity, e.g. kg or each |
| `currency` | TEXT (currency) | **yes** | ISO 4217 of the amount |
| `amount` | REAL | **yes** | cost or returned cost excluding tax; credits subtract |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `affiliate_daily`

One reported day and partner commission bucket. Buckets on a day have disjoint source attribution.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `activity_id` | TEXT | **yes** | stable namespaced id |
| `partner_id` | TEXT | **yes** | opaque affiliate partner or program id |
| `partner_name` | TEXT | no | display label, when reported |
| `activity_on` | TEXT (date) | **yes** | conversion or reporting date stated in the export |
| `status` | TEXT (vocab `affiliate_status`) | **yes** | affiliate_status vocabulary |
| `payout_id` | TEXT | no | opaque payout reference when one is reported |
| `clicks` | INTEGER | no | attributed clicks if reported for this bucket |
| `conversions` | INTEGER | no | attributed conversions if reported for this bucket |
| `currency` | TEXT (currency) | **yes** | ISO 4217 of the commission |
| `commission_amount` | REAL | **yes** | commission amount; reversed buckets subtract |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `sponsorship_deals`

One booked creator sponsorship deal; split distinct campaign bookings into separate rows.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `deal_id` | TEXT | **yes** | stable namespaced deal id |
| `sponsor_id` | TEXT | **yes** | opaque sponsor id |
| `sponsor_name` | TEXT | no | company display label, when reported |
| `campaign` | TEXT | **yes** | deal or placement label |
| `booked_on` | TEXT (date) | **yes** | date agreement was booked |
| `due_on` | TEXT (date) | no | agreed delivery day, when known |
| `delivered_on` | TEXT (date) | no | date final contracted delivery was completed |
| `status` | TEXT (vocab `sponsorship_status`) | **yes** | sponsorship_status vocabulary |
| `currency` | TEXT (currency) | **yes** | ISO 4217 of booked_amount |
| `booked_amount` | REAL | **yes** | contracted amount excluding tax |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `sponsorship_payouts`

One payment applied to a sponsorship. A payment split across deals has one row per allocation.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `payment_id` | TEXT | **yes** | stable namespaced payment or allocation id |
| `deal_id` | TEXT | **yes** | paid sponsorship |
| `received_on` | TEXT (date) | **yes** | local settlement day |
| `currency` | TEXT (currency) | **yes** | ISO 4217, same as the deal |
| `amount` | REAL | **yes** | received revenue applied to the deal, excluding tax |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `import_issues`

Connector accounting or unresolved rows recorded for the board's to-review page.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `issue_id` | TEXT | **yes** | stable namespaced issue id |
| `severity` | TEXT (vocab `severities`) | **yes** | severities vocabulary |
| `code` | TEXT | **yes** | connector's stable issue kind |
| `detail` | TEXT | **yes** | explanation without private row content |
| `source` | TEXT | **yes** | connector id |
| `source_ref` | TEXT | **yes** | export location or source object id |
| `imported_at` | TEXT (instant) | **yes** | UTC import instant |
| `confidence` | TEXT (vocab `confidence`) | no | confidence vocabulary, only when inferred |

### `overrides` (required table)

Local corrections to source data, with the reason and evidence kept.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `override_id` | TEXT | **yes** | stable id |
| `target` | TEXT | **yes** | table.key.column the override applies to |
| `field` | TEXT | no | column name |
| `old_value` | TEXT | no | value before |
| `new_value` | TEXT | no | value after |
| `reason` | TEXT | **yes** | why, in the person's words |
| `evidence` | TEXT | no | where it comes from |
| `author` | TEXT | no | person or assistant |
| `created_at` | TEXT | no | ISO 8601 instant |

### `annotations` (required table)

Notes on metrics and pages (platform table). Numbers only through {{metric:...}} placeholders.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `annotation_id` | TEXT | **yes** | stable id |
| `target` | TEXT | **yes** | metric id or page id |
| `kind` | TEXT | **yes** | note \| caveat \| flag \| decision \| open_item |
| `body` | TEXT | **yes** | the note text |
| `author` | TEXT | no | person or assistant |
| `source_ref` | TEXT | no | where it came from |
| `created_at` | TEXT | no | ISO 8601 instant |
| `data_hash` | TEXT | no | hash of the cited metric values when written (stale when they change) |
| `status` | TEXT | no | active \| stale \| retired |

### `metric_registry` (required table)

The board's metrics, installed from metrics.sql by the importer (platform table).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `metric_id` | TEXT | **yes** | e.g. kpi.mrr |
| `version` | INTEGER | no | the metric's own version |
| `unit` | TEXT | no | usd \| rows \| pct \| date \| count ... |
| `params` | TEXT | no | comma list of parameters it honours |
| `description` | TEXT | no | the @desc line |
| `sql` | TEXT | no | expanded SQL |
| `test` | TEXT | no | the @test line (check that covers it) |

<!-- fields:end -->
