Commit graph

15 commits

Author SHA1 Message Date
9d2ba5a430 feat(quotes): delete quotes from the app, add customer inline with full details
Two things that meant going into PocketBase by hand or jumping between
screens.

Deleting a quote
- Quotes had no delete action - a test quote could only be removed
  through the PocketBase admin UI. Purchase orders already soft delete
  by flipping a `deleted` flag, so quotes now do the same: the Delete
  action confirms first, then hides the quote from the list while the
  record and its PDF stay in PocketBase for audit.
- The quotes list filters out soft-deleted quotes, so a deleted quote
  is out of the way but recoverable by clearing the flag.

Adding a customer while writing a quote
- Typing a customer name that was not in the list used to create a
  name-only stub, which then had to be edited from the Customers screen
  before the quote could show an address or VAT number.
- The picker now opens the full customer form right there - address,
  VAT number, email and phone - with the name pre-filled. The new
  customer is created, added to the list and selected, so the quote
  carries on and the PDF has the details.
2026-10-21 05:09:11 +02:00
99e9d947cf feat(quotes,customers): address + VAT on quotes, 30-day validity, searchable customer
A quote should look like a document from a real company, so this adds
the customer details a quote needs, gives every quote a valid-until
date, and makes the customer picker usable once there are 20+ of them.

Customer details on quotes
- The `customers` collection only had a name, so the quote PDF's
  "Customer Information" block could only ever print a name. Added
  optional address, VAT number, email and phone fields.
- The PDF block now grows to fit whatever is on file and prints the
  VAT number and contact line, so a filled-in customer produces a
  professional quote.
- The quote details dialog shows the same details.
- The customer form gained the new fields, and "Edit customer" now
  works - it was a menu item that did nothing, so there was no way
  to add a VAT number to an existing customer.
- The customers table shows Address and VAT Number columns.

Valid until
- Quotes were created with an empty validUntil, so the PDF printed
  "Valid Until: N/A". The form now defaults it to 30 days after the
  quote date and keeps it in step when the date moves. The three
  existing quotes without one were backfilled the same way.

Searchable customer picker
- The customer dropdown listed every customer in a plain select with
  no way to add one that was missing. It is now a searchable combobox
  (by name, address or VAT number) that offers to create the customer
  when nothing matches, and creates it inline.

Sidebar
- Settings moved to a gear in the corner next to the app name, and
  Logs moved into Settings as a tab. The nav is now eight items with
  no grouping - grouping them would add a layer for no gain at this
  size. The old /logs link still lands on the logs tab.

Also fixes a real PDF bug: item descriptions were cut to 40 characters,
which is wider than the description column, so long names printed on
top of the SKU column. Descriptions and SKUs are now measured against
the real column width and truncated with an ellipsis.

Live PocketBase changes (see scripts/add-customer-fields.mjs):
- customers update and delete rules were null (superusers only), so a
  member could not edit the customer they had just added. They now
  match the other collections.
2026-10-21 04:45:58 +02:00
d606345de4 fix(quotes,po): repair item storage, totals and PDF line items
Quotes and purchase orders were silently losing their line items.

Quote items field was a multi-relation to stock_items, but PocketBase
stored only the last id as a plain string no matter how it was sent
(JSON string via FormData, raw array, or repeated FormData entries).
Every quote created through the UI had `items: ""` or `items: "<id>"`.
Recreated the field as JSON so an array of stock_item ids round-trips
(companion fields quantities/unitPrices already line up with it).

PO snapshot_items had the same class of bug from the other direction:
String(obj) coerced the snapshot array to "[object Object]", which
PocketBase stored verbatim, rendering the PO as N rows of
"Unknown / £0.00". The form now sends JSON-stringified arrays, and
the reader only trusts a snapshot whose rows actually carry a name.

Also fixes:
- Quote item lines are hydrated from stock_items; the parallel
  quantities/unitPrices arrays are the source of truth, so quotes
  written before the schema fix still render and total correctly.
- Quote form rejects stock rows where no item was actually picked
  from the dropdown, instead of saving an empty stockItemId.
- PO PDF filename is now the plain order number (PO-20261015-001.pdf).

Adds the quotes.items schema migration plus three dev scripts for
creating a quote, re-applying the field fix and rendering a test PDF.
2026-10-20 20:13:46 +02:00
0b8f003f87 feat(po): add MCP server, agent-friendly PO API, and PDF rendering
- server/pb-mcp.mjs: 15-tool MCP server for purchase-order workflow
  (CRUD, suppliers, stock, customers, customer POs, validate_draft,
  generate_order_number)
- src/lib/api/purchaseOrders.ts: typed helpers shared by UI + MCP + n8n
- src/components/purchase-orders/pdf.ts: jsPDF PO generator
- src/components/purchase-orders/ViewOrderDialog.tsx: read-only dialog
- src/components/purchase-orders/AttachmentsDialog.tsx: attachment mgmt
- src/components/purchase-orders/NumberInput.tsx: numeric input
- scripts/mcp-create-po.mjs: end-to-end driver (MCP stdio smoke test)
- pocketbase/pb_migrations/1786200007_*: schema migration
- docs/MCP_AND_N8N.md: MCP + n8n integration guide

Verified end-to-end via MCP: generate_order_number → create_purchase_order
with snapshot_items for an actual quote (DRILL-19042 / 161053).
2026-09-07 11:12:13 +02:00
c272526d67 feat(automation): add PO-to-invoice pipeline
- 6 new PocketBase migrations: customer_pos, customer_po_lines, invoices,
  invoice_items, email_inbox, workflow_runs
- n8N workflow JSON: 01-customer-po-to-parsed.json + 02-parsed-po-to-invoice.json
- MCP server config (.cursor/mcp.json + .mcp.json) for AI agent PB access
- .env.example template with all required credentials documented
- n8n/README.md with deployment, testing, and customization notes
2026-09-06 23:40:33 +02:00
642548295e chore: untrack .env and pb_data, update gitignore 2026-09-01 07:45:02 +02:00
SJCoetz
d4be480ecb Add PO snapshot_items and edit/order handling
Add a PocketBase migration and store snapshot_items on purchase order creation so POs keep item details even if stock items change or are deleted. Wire snapshot_items through the UI: PurchaseOrders list prefers snapshot data when present; EditPurchaseOrderDialog supports snapshot fallback, SKU, entryMode (stock/manual), add/remove rows, and updates stock item GBP prices for stock-mode items. BookOutForm now deducts stock quantities on booking out and surfaces precise errors. Minor UI and behavior tweaks: low-stock report filters only actual stock items, columns typing includes snapshotItems, and edit action/menu is always available with an Edit dialog integrated into the PurchaseOrders page.
2026-05-24 00:11:37 +02:00
davidels1
f7b46986c5 Add GBP cost price to stock and purchase orders
Introduces a new 'cost_price_gbp' field to the stock items schema and database migration. Updates stock item forms to support both ZAR and GBP cost prices. Purchase order forms and PDF generation now use GBP pricing, with enhanced supplier and order metadata. Adds a searchable stock item selector for purchase orders and improves type definitions and UI labels for clarity.
2025-11-05 14:55:42 +02:00
davidels1
9f79dae941 Refactor authentication checks in useDashboardData and add collection auth rules for authenticated users 2025-09-25 01:50:01 +02:00
davidels1
23198d9094 Fixed login 2025-09-25 00:15:35 +02:00
davidels1
2dc385cbdc Create 1757376600_created_logs.js 2025-09-24 23:21:13 +02:00
[dyad]
ef32f7f080 [dyad] Corrected typo in PocketBase suppliers schema - wrote 3 file(s) 2025-09-12 13:37:56 +02:00
[dyad]
0ae8d41a0a [dyad] Fixed TypeScript import errors in Suppliers page - wrote 10 file(s) 2025-09-12 13:31:06 +02:00
[dyad]
afb3a07435 [dyad] Adding quantity field to book_out_records collection - wrote 1 file(s) 2025-09-10 12:37:53 +02:00
[dyad]
c0d46021a8 [dyad] Connecting to PocketBase - wrote 3 file(s) + extra files edited outside of Dyad 2025-09-10 08:29:28 +02:00