fix(accounting): COGS could never post — sale_items has no total_cost column
onSaleCompleted summed sale_items.total_cost. That column does not exist; the
table stores a per-unit cost_price alongside quantity. Confirmed with SHOW
COLUMNS on the live database.
Every sale therefore threw "Unknown column" inside the sale.completed listener,
which is wrapped in a try/catch that only writes to the log. So inventory was
relieved in the stock ledger while the general ledger kept carrying it, and no
cost of sales was ever recognised — the gross margin on every sale was overstated
by its entire cost.
Now SUM(cost_price * quantity) over non-refunded lines. This also un-breaks
onSaleVoided, which reverses the 'sale_cogs' entry and could never find one.
Co-Authored-By:
Claude Opus 5 (1M context) <noreply@anthropic.com>
Showing
Please register or sign in to comment