WFDASH-WEBAPP/scripts
Dave 7256de8859 feat(pos): refund a whole sale, put the goods back, print a credit slip
A customer who brings goods back needs the sale reversed: the items go
back into stock and the money comes back off the till. There was no way
to mark a POS sale as refunded, so nothing stopped the same sale being
refunded twice — which credits the customer twice and puts the same
stock back on the shelf twice.

Refunds are WHOLE-SALE only by operator decision; no partial refunds.
That is what lets `pos_sales.refunded` be a boolean instead of a
per-line refund table. Three columns: `refunded`, `refunded_at`,
`refund_amount`, stamped from the sale's post-discount total, which is
what the customer actually paid.

DOUBLE-REFUND GUARD, twice over, because this is the one failure that
costs real money:

  - `refunded` is read before anything else, and a flagged sale returns
    409 with no stock writes at all
  - the flag is stamped BEFORE any stock write, so a second concurrent
    tap sees it and bails. Writing stock first and flagging last would
    let both taps through.

A stock write that fails part-way does NOT roll the flag back. The
customer has their money either way, so re-running would double-credit
them; the failed lines come back in `stockErrors` for a manual count
correction, which is strictly better than a second refund.

Stock needs no schema: `return` was already in STOCK_REASON_VALUES,
just never used. Rows are written with POSITIVE change_qty and
reference_type "pos_sale_refund", leaving the original
customer_fulfillment rows untouched so the sale's own audit trail still
shows what was originally rung up.

cashup.html had expected drawer = sum of cash sales, so a cash refund
would have shown as a false variance on every cash-up after it. It now
subtracts cash refunds, and refunded sales contribute nothing to
takings for any tender.

The tender is read off the sale, never off the request — an earlier
version accepted it in the body, which would have let a caller assert
that a cash sale was really an EFT and talk the drawer out of balance.

At the till: tap still reprints, hold a sale row for 600ms to refund —
moving money sits behind a gesture you cannot do by accident. Refunded
sales stay in the list, dimmed and badged, because deleting them would
destroy the audit trail. The sheet names the items and says plainly what
happens next ("Hand back R10.57 in cash. The drawer count for this day
will drop by that amount.").

The credit slip reuses the sale renderer and the whole printer path with
`refund: true`, so there is no second printer to configure — but note
there were THREE render paths to fix (on-screen, Bluetooth text, ePOS
XML), and missing the third would have printed "TOTAL" on a credit note.

Migration applied to live PB and verified idempotent; field shapes
round-tripped on a real sale and restored. 10 new tests, 148 POS tests
pass, tsc clean, build passes. sw.js v34 -> v35 (history, cashup,
receipt and epos-print are all cache-first in the shell).
2026-10-07 23:41:09 +02:00
..
__pycache__ feat(mcp): enhance API documentation and add new tools 2026-08-15 00:06:40 +02:00
dev
fixes feat(quotes): split attachments into internal vs outbound with operator upload UI 2026-09-09 13:43:56 +02:00
migrations feat(pos): refund a whole sale, put the goods back, print a credit slip 2026-10-07 23:41:09 +02:00
perf feat: add new order, invoice, and dashboard management tools 2026-08-05 23:00:54 +02:00
smoke chore(giellie): add MiniMax vision/tool-call probe 2026-09-30 23:33:13 +02:00
utils
2026-08-03-load-husqvarna-cart.ts chore(scripts): one-time stock-order loaders + source screenshots 2026-08-03 17:33:28 +02:00
2026-08-03-load-yg1-quote-soq078608.ts chore(scripts): one-time stock-order loaders + source screenshots 2026-08-03 17:33:28 +02:00
2026-08-03-merge-yg1-drafts.ts chore(scripts): one-time stock-order loaders + source screenshots 2026-08-03 17:33:28 +02:00
2026-08-13-heal-item-intel.ts feat(tv): add TV dashboard + refine workflows 2026-08-13 20:55:22 +02:00
2026-08-21-backfill-order-duplicates.ts feat(orders): enhance order handling with email_message_id deduplication and displayContactName utility 2026-08-21 19:18:02 +02:00
_csv-sink.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
_dump-browser-csv.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
_env.ts feat(tv): add TV dashboard + refine workflows 2026-08-13 20:55:22 +02:00
_scrape-dowel-pins.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
_scrape-grease-nipples.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
_scrape-spring-pins.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
apply-default-markup.test.ts feat(stock): inline qty editing + column sort + pricing-gap operator scripts 2026-09-14 13:04:26 +02:00
apply-default-markup.ts feat(stock): inline qty editing + column sort + pricing-gap operator scripts 2026-09-14 13:04:26 +02:00
audit-pb-fields.py
backfill-item-intel.ts feat(item-intel): add new item intel popover and backend workflows 2026-08-11 02:57:57 +02:00
backfill-po-items.mjs
backfill-stock-prices.test.ts feat(stock): seed pricing fields on create + sync price_list to stock_items 2026-09-14 13:04:08 +02:00
backfill-stock-prices.ts feat(stock): seed pricing fields on create + sync price_list to stock_items 2026-09-14 13:04:08 +02:00
build_v5_workflow.py
compress-attachments-once.mjs feat(audit): implement audit trail for delivery notes and orders 2026-09-30 01:48:44 +02:00
deploy_v5_to_n8n.py
diff-nss-fix.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
fleetai-probe.mjs feat(rep-visits): FleetAI tracker adapter, nearby-customer matching, stop detection 2026-09-06 14:22:28 +02:00
import-data.ts
list-irda-stock.ts feat(stock): inline qty editing + column sort + pricing-gap operator scripts 2026-09-14 13:04:26 +02:00
mcp-doc-gen.py feat(mcp): enhance API documentation and add new tools 2026-08-15 00:06:40 +02:00
mrbxnim4-telegram-cloud-photo-size-4-6016860144018328845-y.jpg
n8n-v2-error.ts
n8n-v2-main.ts
nss-add-invoice-columns.ts fix(invoicing): bill only what's collected, support partial pickups + kit splits 2026-09-17 13:53:36 +02:00
nss-backfill-in-stock-qty.ts fix(order-process): stamp qty_collected when marking items in stock 2026-09-18 08:07:38 +02:00
nss-dowel-pins-din6325-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-dowel-pins-din6325-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-dowel-pins-din6325-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-dowel-pins-din6325-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-fasteners-fix-name-description.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-fasteners-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-fasteners-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-fasteners-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-fasteners-pilot.csv feat(stock): implement auto-markup for selling price and markup on stock item creation and updates 2026-09-16 09:49:52 +02:00
nss-fasteners-revert-name-description.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-fasteners-single-pieces.csv feat(stock): implement auto-markup for selling price and markup on stock item creation and updates 2026-09-16 09:49:52 +02:00
nss-fix-kusasalethu-inv10924.ts fix(invoicing): bill only what's collected, support partial pickups + kit splits 2026-09-17 13:53:36 +02:00
nss-grease-nipples-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-grease-nipples-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-grease-nipples-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-grease-nipples-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-hex-bolts-din931-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-hex-bolts-din931-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-hex-bolts-din931-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-hex-bolts-din931-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-hex-bolts-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-hex-bolts-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-scrape-bundle.js feat(stock): implement auto-markup for selling price and markup on stock item creation and updates 2026-09-16 09:49:52 +02:00
nss-set-screws-din933-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-set-screws-din933-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-set-screws-din933-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-set-screws-din933-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-split-pins-din94-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-split-pins-din94-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-split-pins-din94-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-split-pins-din94-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-spring-pins-iso8752-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-spring-pins-iso8752-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-spring-pins-iso8752-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-spring-pins-iso8752-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-threaded-rods-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-threaded-rods-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-threaded-rods-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-threaded-rods-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-washers-din126-pb-import.json feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-washers-din126-pilot.csv feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-washers-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
nss-washers-pb-transform.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
quotes.pb.js
recent-stock-movements.ts feat(stock): implement auto-markup for selling price and markup on stock item creation and updates 2026-09-16 09:49:52 +02:00
regenerate-delivery-note-pdfs.ts feat: add driverless collection confirm and new order tooling 2026-08-12 01:13:46 +02:00
seed-gielie-quotes.py
setup-pocketbase.ts
verify-nss-bolts.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-dowel-pins.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-fix.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-grease-nipples.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-ingest.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-revert.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-rods.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-set-screws.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-split-pins.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-spring-pins.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify-nss-washers.ts feat(stock): update pricing logic and transform script for fasteners 2026-09-21 12:32:44 +02:00
verify_v5.py