Commit graph

38 commits

Author SHA1 Message Date
Mavis
5f73d2ea71 feat: Fedex import flow, orders + invoice APIs, payment bundles
- /fedex: batch create, document upload/replace/delete, save shipment, imported list
- /api/orders, /api/invoices, /api/pb-file, /api/pb/refresh-token, /api/stock-codes
- /api/payments/bundle: generate + download-all remittance bundles
- shared app/components/DocCell.tsx and app/lib/{invoice-docs,pb-fetch,pb-token}.ts
- recon: invoice reconciliation reports and PowerShell fix-plan scripts
- .gitignore: exclude one-off scripts/_* debugging artefacts, recon/pdfs+txts, data backups
2026-10-18 17:27:40 +02:00
Mavis
f57273b1ae chore: extend .gitignore to cover one-off scripts and build artefacts
The prior .gitignore only covered `scripts/_import_one_off_*.py`,
`scripts/_smoke_*.py`, and `tsconfig.tsbuildinfo`. This session
created scripts with other prefixes (_import_splits_, _patch_) and
a tsconfig.tsbuildinfo.bak that leaked through.

Added:
- scripts/_import_splits_*.py
- scripts/_patch_*.py
- tsconfig.tsbuildinfo.bak

Now all session-local helpers stay out of git.
2026-09-19 01:14:03 +02:00
Mavis
975d6bfec3 chore: track new and corrected invoice PDFs in invoices/
Following the 472ae5c pattern of tracking renamed invoice PDFs:
- invoices/157925.pdf                            [page 1 of JEI Supplier Invoice222.pdf]
- invoices/157926.pdf                            [page 2 of JEI Supplier Invoice222.pdf]
- invoices/GBP JEI Invoice - with bank details.pdf
- invoices/JEI Supplier Invoice222.pdf           [2-page original, both invoices on it]
- invoices/Supplier Invoice162326.pdf            [invoice 162154 - filename typo]
- invoices/161453.pdf                            [corrected/re-uploaded version]

The 161453.pdf replacement was driven by PATCH of the existing PB
record id o797ahy6sw175to (carriage 0 -> 280, total 844 -> 1124,
notes 'Drill serial #: 3105', pdf_file replaced).
2026-09-19 01:13:29 +02:00
Mavis
7cf8d4b2e2 feat(order): new /order tab — stock-code picker + qty, cost preview, PDF export
Quick order-builder for the user. Pick a stock code, set a qty, hit Add.
Default unit price is the HIGHEST price ever paid for each code (worst-
case budget), with the reference invoice [no + date] shown in the table
so the price source is auditable. Ties broken by most-recent date so
the source reflects current market, not an old historical peak.

UI:
- Stock code dropdown shows code, description, default price, ref inv
- Inline-editable qty + unit price per row
- Running grand total at bottom
- Clear button (with confirm) wipes the list
- Export PDF button calls window.print() — browser "Save as PDF" gives
  a clean table with no chrome (header/nav/controls hidden via @media
  print stylesheet)

Persistence:
- List kept in localStorage key 'jei:order-list' across reloads

Files:
- app/order/page.tsx       [server: fetches stock codes + lines, builds highest-price map]
- app/order/OrderClient.tsx [client: UI, state, print stylesheet]
- app/layout.tsx           [nav: added Order link]

PB query note: when using `fields=...` to limit the response, you must
also include 'expand.invoice.invoice_no' and 'expand.invoice.invoice_date'
in the field selector, otherwise PB drops the expand data entirely.
2026-09-19 01:13:22 +02:00
Mavis
346a60cf97 feat(payments): relax batch_ref regex to allow spaces, slashes, dots, colons, etc.
The previous rule ^[A-Za-z0-9_-]{1,50}$ rejected common bank/POP
references that include punctuation [e.g. 'Bank ref 26/09/18',
'INV/2026.09:18 #3', 'POP 12345']. New rule permits letters, digits,
space, underscore, hyphen, slash, dot, comma, colon, parens,
ampersand, hash, apostrophe, plus; length 1-100. Still rejects
characters that break filesystems/URLs [e.g. < > " ? * | \ ;].

Files updated:
- app/api/payments/create/route.ts   [inline regex + new error msg]
- app/api/payments/[id]/edit/route.ts [BATCH_REF_PATTERN + new error msg]
- app/unpaid/UnpaidClient.tsx        [HTML pattern attribute]
- app/remittance/RemittanceClient.tsx [HTML pattern attribute]
- docs/superpowers/plans/2026-09-18-jei-payments-and-remittance.md [plan doc]
2026-09-19 01:13:15 +02:00
Ysterbaard
472ae5c0f0 chore: track renamed proforma PDFs (147842, 148931, 149943) 2026-09-18 23:14:49 +02:00
Ysterbaard
bcc8dfdfbc feat: edit button on remittance batches (batch_ref, payment_date, notes, zar_paid) 2026-09-18 23:14:19 +02:00
Ysterbaard
551baeeb80 feat: add ZAR Paid field to JEI_payment_batches (optional) 2026-09-18 23:10:54 +02:00
Ysterbaard
ca1c6cfedd fix: invalidate Next.js router cache on payment actions (unpay/create/replace-pop) 2026-09-18 23:00:50 +02:00
Ysterbaard
146d31df87 chore: move JEI dev port from 6003 to 5001 (user preference) 2026-09-18 21:24:07 +02:00
Ysterbaard
a50990d88f fix: move batchRefs fetch after records is filled (linked batch ref on /invoices) 2026-09-18 20:06:40 +02:00
Ysterbaard
14586a6e4f feat: add Unpaid and Remittance nav links 2026-09-18 19:58:44 +02:00
Ysterbaard
e54b1ae223 feat: add Status column + paid/unpaid row colors on /invoices 2026-09-18 19:56:33 +02:00
Mavis
84eb542104 fix: drop -created from remittance sort (PB lacks created column) 2026-09-18 19:54:08 +02:00
Ysterbaard
9faad5878f fix(plan): drop ,-created from remittance sort (PB v0.39.8 lacks created column on base tables) 2026-09-18 19:53:09 +02:00
Ysterbaard
39b649f035 feat: /remittance page with batch cards, Replace POP and Unpay buttons 2026-09-18 19:51:37 +02:00
Ysterbaard
29240cc051 feat: /unpaid page with selection, sticky footer, and Create Payment modal 2026-09-18 19:43:37 +02:00
Ysterbaard
39641e805a chore: move JEI dev port to 6003 (avoid clash with Workflow CIPC service on :6002) 2026-09-18 19:41:26 +02:00
Ysterbaard
b13e4c38ab fix(plan): correct off-by-one in getPb import path for [id]/* routes 2026-09-18 19:08:28 +02:00
Ysterbaard
3299b67442 feat: POST /api/payments/[id]/replace-pop and /unpay 2026-09-18 19:05:12 +02:00
Ysterbaard
44f17d2a6e feat: POST /api/payments/create with validation and atomic invoice patching 2026-09-18 18:37:17 +02:00
Ysterbaard
5fec004a46 feat: add PaymentBatch types and Invoice.payment_batch 2026-09-18 18:28:16 +02:00
Ysterbaard
3290803e0b feat: add JEI_payment_batches schema migration script 2026-09-18 18:22:22 +02:00
Ysterbaard
9e0ec2c6a5 Add 2026-09-18 Payments & Remittance implementation plan 2026-09-18 18:13:10 +02:00
Ysterbaard
a8bacb8eb5 Add 2026-09-18 Payments & Remittance design spec 2026-09-18 18:08:19 +02:00
Mavis
922cd01dd4 chore: rename JEI invoice PDFs to invoice numbers + dedupe
- 22 files renamed to <invoice_no>.pdf (154923.pdf, 151778.pdf, etc.)
- 5 duplicate files moved to invoices/_non_jei/
- 7 files left as-is (multi-invoice PDFs or unscannable:
  1.Invoice_29.05.pdf, Invoice.pdf, JEI Drilling Invoices.pdf,
  JEI SA Invoice 147842.pdf, JEI SA Proforma 148931.pdf,
  newdoc10018920260413143327_001.pdf, Supplier Invoice.pdf,
  Supplier Invoices.pdf)
2026-09-18 17:55:12 +02:00
Mavis
006a324081 feat: OCR scanned PDFs and capture all 11 missing stock codes
- Installed Tesseract OCR via winget
- Added scripts/ocr_invoices.py to OCR all PDFs via PyMuPDF
- Updated extract_invoices.py to fall back to OCR text for scanned pages
- Fixed stock-code regex to match "qty + code" pairs only (avoids spurious
  matches like bare TCT in invoice headers)
- Added merge step to combine multi-page proformas into single invoice records
- All 11 previously-missing codes now in PB:
  JEITCS12, JEITCS18, JEITCS22, JEITCL22, JEITCL92,
  JEICS17, JEICS19, JEICS27, JEICS30, JEICS34, JEICS14-P1
- Only JEITCS50 remains unlisted (genuinely never ordered)

PB now: 19 invoices, 158 stock codes, 281 line items
2026-09-18 06:12:30 +02:00
Mavis
236f5b7bf0 fix: cleanup 6x duplicate lines + bogus JEISA000 stock code
- Removed 424 duplicate invoice lines from re-running the import
- Deleted JEISA000 stock code (it was actually your Account Ref)
- Made create_line idempotent in import_to_pb.py so re-runs skip existing
- Removed debug prints from extract_invoices.py
2026-09-18 00:41:26 +02:00
Mavis
44f9b6957e fix: bypass Next.js fetch-cache for PB SDK calls
Next.js patches the global fetch with a cache layer that was returning
stale PB responses (showing description_goods as the code itself because
the snapshot was from before the import fixed the descriptions).

Wrap the SDK with a custom fetch using cache: no-store so every page
request gets fresh data from PocketBase.
2026-09-17 23:59:13 +02:00
Mavis
b18cb13a6c feat: capture stock-code descriptions from PDF line text
- Two PDF layouts supported: description-before-stock-code and description-after
- Clean up trailing inch-quote artifacts and multiple-comma noise
- Importer PATCHes existing records when new description is better
- Stock codes tab now shows real goods descriptions, not just codes
2026-09-17 23:49:54 +02:00
Mavis
22ddfe82bf fix: avoid PB SDK filter=undefined serialization (caused 400 errors)
The PB JS SDK serializes `filter: undefined` as the literal string
undefined in the URL, which PB rejects with 400 Bad Request.
Switched to conditionally including filter only when non-empty.
2026-09-17 23:17:58 +02:00
Mavis
b95599fe83 fix: dashboard autocancellation - single invoice fetch + clearer error 2026-09-17 23:11:55 +02:00
Mavis
cc4906fba5 chore: tidy .gitignore and update NOTES.md with build discoveries 2026-09-17 23:08:38 +02:00
Mavis
22854074ca feat: working JEI invoice tracker with PB import + UI on port 6002
- Next.js 14 + Tailwind + TypeScript scaffolded
- PocketBase v0.39.8 collections: JEI_invoices, JEI_invoice_lines, JEI_stock_codes
  (30 fields total, locked to superuser)
- PDF extraction: scripts/extract_invoices.py parses 33 PDFs -> 38 records
- Import script: scripts/import_to_pb.py idempotent push to PB
- Imported: 24 invoices, 70+ stock codes, 118 invoice lines
- Pages: /, /invoices, /invoices/[id], /stock-codes, /stock-codes/[code]
- All 5 pages verified returning 200 with real data on port 6002
2026-09-17 23:07:56 +02:00
Mavis
97d0339aa6 notes: duplicate file findings + dedup strategy 2026-09-17 21:35:07 +02:00
Mavis
f1f28ba13a spec: clarify acceptance #4 wording 2026-09-17 21:32:20 +02:00
Mavis
3cce09db23 spec: revise with PDF discoveries + deliver-to + document_type; add NOTES.md and .gitignore 2026-09-17 21:32:05 +02:00
Mavis
14eee3fb9a spec: JEI invoice tracker design (2026-09-17) 2026-09-17 21:19:22 +02:00