National Commerce Docs
Database

Reporting & Financials

Precomputed financial reporting tables: weekly account rollups, net-revenue snapshots, and the global model inputs that feed the math.

These tables store precomputed financial reporting. Nothing here is edited by hand during normal use: rows are written by database functions and RPCs that run the financial math. This page describes what each table holds. The Data Flows page explains how the calculations produce these rows.

The functions that populate these tables are cataloged on the Automation page. Weekly Reports is filled in by generate_weekly_report(), and net_revenue_calculations is filled in by the net-revenue RPCs.

Weekly Reports

A precomputed weekly financial rollup per account for the window from date_start to date_end. Each row holds both totals for the week and the matching per-unit figures. Rows are generated by the generate_weekly_report() function, not written directly by the app.

ColumnTypeNotes
idbigintPrimary key. Generated always as identity.
brandinteger→ references Brands. The account this rollup belongs to.
date_starttimestampStart of the reporting window.
date_endtimestampEnd of the reporting window.
total_units_shippedbigintUnits shipped in the window. Defaults to 0.
total_sale_pricenumericTotal sale price for the window. Defaults to 0.
total_shipping_costnumericTotal shipping cost. Defaults to 0.
total_fulfillment_expensenumericTotal fulfillment expense. Defaults to 0.
total_amazon_commissionnumericTotal Amazon commission. Defaults to 0.
total_net_revenuenumericTotal net revenue for the window. Defaults to 0.
amazon_commission_percentagenumericCommission rate applied. Defaults to 0.15.
sale_price_per_unitnumericSale price per unit. Defaults to 0.
shipping_cost_per_unitnumericShipping cost per unit. Defaults to 0.
fulfillment_expense_per_unitnumericFulfillment expense per unit. Defaults to 0.
amazon_commission_per_unitnumericAmazon commission per unit. Defaults to 0.
net_revenue_per_unitnumericNet revenue per unit. Defaults to 0.
created_attimestamptzRow creation time. Defaults to now().

Note that amazon_commission_percentage defaults to 0.15 (15%). Every other numeric total and per-unit column defaults to 0.

The brand column is a foreign key to Brands, so each weekly report is tied to exactly one account. There are no other foreign keys on this table.

net_revenue_calculations

A saved snapshot of one net-revenue calculation over a period. Each row records the inputs used and the averages and totals that came out of them. It mirrors the inputs and outputs of the net_revenue_calc() function. This table has no foreign keys. Snapshots stand on their own.

ColumnTypeNotes
idbigintPrimary key. Generated always as identity.
start_of_periodtimestampStart of the calculation period.
end_of_periodtimestampEnd of the calculation period.
units_shippednumericUnits shipped in the period (input).
total_shipping_paidnumericTotal shipping paid (input).
sale_pricenumericSale price used (input).
amazon_commissionnumericAmazon commission (input).
gross_invoice_amountnumericGross invoice amount (input).
invoice_credits_fulfillment_feesnumericInvoice credits for fulfillment fees (input).
amazon_commission_avg_per_itemnumericAverage Amazon commission per item (output).
fulfillment_expense_avg_per_itemnumericAverage fulfillment expense per item (output).
shipping_expense_avg_per_itemnumericAverage shipping expense per item (output).
net_revenue_avg_per_itemnumericAverage net revenue per item (output).
net_revenue_this_periodnumericTotal net revenue for the period (output).
created_attimestamptzRow creation time. Defaults to now().

These columns have no defaults; every value is written when the snapshot is created. Because there are no foreign keys, a snapshot is not linked to any account or brand; it captures a single calculation on its own.

Model inputs

Weekly input assumptions for the financial model. Each row holds the raw numbers for one week that the net-revenue math reads from. This table has no foreign keys.

ColumnTypeNotes
idintegerPrimary key. Defaults from the Model inputs_id_seq sequence.
Start_of_the_weekdateFirst day of the week these inputs cover.
End_of_the_weekdateLast day of the week these inputs cover.
Units_Shipped__Total_bigintTotal units shipped for the week.
Total_Shipping_PaidnumericTotal shipping paid for the week.
Gross_Invoice_Amount__Fulfillment_Fees_numericGross invoice amount including fulfillment fees.
Invoice_Credits__Fulfillment_Fees_numericInvoice credits for fulfillment fees.
Sale_Price__1_Pack_numericSale price of a 1-pack. Defaults to 29.99.
Amazon_Commission__numericAmazon commission rate. Defaults to 0.15.
created_attimestampRow creation time. Defaults to now().
updated_attimestampLast update time.
created_byvarcharWho created the row.
updated_byvarcharWho last updated the row.

Two defaults drive the model: Sale_Price__1_Pack_ defaults to 29.99 and Amazon_Commission__ defaults to 0.15 (15%). If a weekly row leaves these blank, the calculation uses these values.

This table has no foreign keys. It is a global set of assumptions per week rather than a per-account record.

For how these inputs turn into net-revenue figures and weekly rollups, see Data Flows. For the functions that write these rows, see Automation.

On this page