This commit replaces the legacy item history and AI insights system with a standardized, fuzzy-matched item intel workflow: - Update AiItemHistoryTrigger component to support both quote and order items via the `collection` prop, replacing the old `insights` prop with `intel` - Add full `ItemIntel` type definitions to `src/lib/types.ts` for the new standardized insight payload - Create new REST API endpoints for fetching and computing item intel for `quote_items` and `order_items` - Rewrite the MCP insight endpoint to use the new shared `item-intel-service` instead of legacy individual insight functions - Reorder quotes page tabs to place Delivery Note quotes alongside New quotes for better daily operator workflow - Add item intel triggers to quote process and order process pages - Remove deprecated document-level `AiInsightsPanel` components from quote and order detail pages - Add bulk backfill endpoint for populating intel across existing active items
400 lines
13 KiB
JSON
400 lines
13 KiB
JSON
PB: https://pocketbase-gnqc88suy8fqk6wyryjjdpvl.169.239.180.130.sslip.io
|
||
Write: no (dry-run)
|
||
Targets: 3 quote_items
|
||
|
||
Auth OK
|
||
|
||
── M20 x 30 set screw black (rar7m1d0m6jgeb5) ──
|
||
1002ms · stock_list=3 · supplier_history=3 · price_list=0 · recent_quote=2 · recent_order=2
|
||
summary: out of stock (last supplier Pro-Tech Fasteners (Pty) Ltd,.) · bought from 3 suppliers — top: Gracal Trading (Pty) Ltd,. R6.22 3d ago · last quoted R12.20 14d ago (Q000032) · last order 11d ago (1114938-OR, delivered)
|
||
|
||
── SAE 50 - 20L (0zbkoxfdlz0t7mh) ──
|
||
475ms · stock_list=3 · supplier_history=1 · price_list=5 · recent_quote=2 · recent_order=2
|
||
summary: in stock 2 (AFRIQ LUBE AND SERVICES CC, cost R990.00) · bought from AFRIQ LUBE AND SERVICES CC 10d ago @ R990.00 (×5) · last quoted R2277.77 14d ago (RFQ000125) · last order 11d ago (PO055945, delivered) · on price list (5)
|
||
|
||
── Silicone sealant clear (h5szkwdxs1u2quk) ──
|
||
576ms · stock_list=3 · supplier_history=1 · price_list=0 · recent_quote=2 · recent_order=2
|
||
summary: in stock 24 (Matus - Impumemelo,., cost R32.50) · bought from Matus - Impumemelo,. 10d ago @ R32.50 (×4) · last quoted R45.10 14d ago (Q000782) · last order 11d ago (MSP17006, delivered)
|
||
|
||
════════════════════════════════════════════════════════
|
||
FULL JSON
|
||
════════════════════════════════════════════════════════
|
||
[
|
||
{
|
||
"item": {
|
||
"id": "rar7m1d0m6jgeb5",
|
||
"collection": "quote_items",
|
||
"description": "M20 x 30 set screw black",
|
||
"sku": "",
|
||
"quantity": 399
|
||
},
|
||
"summary": "out of stock (last supplier Pro-Tech Fasteners (Pty) Ltd,.) · bought from 3 suppliers — top: Gracal Trading (Pty) Ltd,. R6.22 3d ago · last quoted R12.20 14d ago (Q000032) · last order 11d ago (1114938-OR, delivered)",
|
||
"generated_at": "2026-08-10T14:47:13.843Z",
|
||
"stock_list": [
|
||
{
|
||
"sku": "PKS11",
|
||
"name": "M20 X 75 SET SCREW ZPL",
|
||
"description": "M20 X 75 SET SCREW ZPL",
|
||
"qty": 0,
|
||
"cost_price": 0,
|
||
"selling_price": 0,
|
||
"supplier": "Pro-Tech Fasteners (Pty) Ltd,.",
|
||
"status": "out"
|
||
},
|
||
{
|
||
"sku": "PKS12",
|
||
"name": "M20 X 80 SET SCREW ZPL",
|
||
"description": "M20 X 80 SET SCREW ZPL",
|
||
"qty": 0,
|
||
"cost_price": 0,
|
||
"selling_price": 0,
|
||
"supplier": "Pro-Tech Fasteners (Pty) Ltd,.",
|
||
"status": "out"
|
||
},
|
||
{
|
||
"sku": "PKS06",
|
||
"name": "M12 X 40 SET SCREW ZPL",
|
||
"description": "M12 X 40 SET SCREW ZPL",
|
||
"qty": 0,
|
||
"cost_price": 0,
|
||
"selling_price": 0,
|
||
"supplier": "NSS Fastners",
|
||
"status": "out"
|
||
}
|
||
],
|
||
"supplier_history": [
|
||
{
|
||
"supplier": "Gracal Trading (Pty) Ltd,.",
|
||
"last_cost": 6.22,
|
||
"last_bought_at": "2026-08-07 12:38:50.834Z",
|
||
"days_ago": 3,
|
||
"times_bought": 4,
|
||
"last_purchase_number": "PO26080706STK"
|
||
},
|
||
{
|
||
"supplier": "Pro-Tech Fasteners (Pty) Ltd,.",
|
||
"last_cost": 8.92,
|
||
"last_bought_at": "2026-08-07 12:34:50.052Z",
|
||
"days_ago": 3,
|
||
"times_bought": 2,
|
||
"last_purchase_number": "PO26080705STK"
|
||
},
|
||
{
|
||
"supplier": "NSS Fastners",
|
||
"last_cost": 1.75,
|
||
"last_bought_at": "2026-08-07 12:24:21.969Z",
|
||
"days_ago": 3,
|
||
"times_bought": 2,
|
||
"last_purchase_number": "PO26080704STK"
|
||
}
|
||
],
|
||
"price_list": [],
|
||
"recent_quote": [
|
||
{
|
||
"quote_number": "Q000032",
|
||
"quote_status": "emailed",
|
||
"quoted_at": "2026-07-26 23:15:44.137Z",
|
||
"days_ago": 14,
|
||
"quantity": 100,
|
||
"cost_price": 10,
|
||
"selling_price": 12.2,
|
||
"description": "M20 x 30 DAVE"
|
||
},
|
||
{
|
||
"quote_number": "Q000121",
|
||
"quote_status": "emailed",
|
||
"quoted_at": "2026-07-26 23:15:04.947Z",
|
||
"days_ago": 14,
|
||
"quantity": 160,
|
||
"cost_price": 10.96,
|
||
"selling_price": 14.25,
|
||
"description": "M20 X 60MM HT SET SCREW HDG"
|
||
}
|
||
],
|
||
"recent_order": [
|
||
{
|
||
"order_number": "1114938-OR",
|
||
"updated": "2026-07-30 08:05:50.650Z",
|
||
"days_ago": 11,
|
||
"quantity": 50,
|
||
"cost_price": 1.63,
|
||
"selling_price": 2.12,
|
||
"item_status": "delivered",
|
||
"supplier": "NSS Fastners",
|
||
"description": "M12 X 30 SET SCREW"
|
||
},
|
||
{
|
||
"order_number": "WYNAND06/08/2026",
|
||
"updated": "2026-08-07 09:16:25.852Z",
|
||
"days_ago": 3,
|
||
"quantity": 50,
|
||
"cost_price": 6.35,
|
||
"selling_price": 8.26,
|
||
"item_status": "collection_pool",
|
||
"supplier": "NSS Fastners",
|
||
"description": "M20 X 130 SET SCREW GR10.9 BLK"
|
||
}
|
||
]
|
||
},
|
||
{
|
||
"item": {
|
||
"id": "0zbkoxfdlz0t7mh",
|
||
"collection": "quote_items",
|
||
"description": "SAE 50 - 20L",
|
||
"sku": "",
|
||
"quantity": 2
|
||
},
|
||
"summary": "in stock 2 (AFRIQ LUBE AND SERVICES CC, cost R990.00) · bought from AFRIQ LUBE AND SERVICES CC 10d ago @ R990.00 (×5) · last quoted R2277.77 14d ago (RFQ000125) · last order 11d ago (PO055945, delivered) · on price list (5)",
|
||
"generated_at": "2026-08-10T14:47:14.802Z",
|
||
"stock_list": [
|
||
{
|
||
"sku": "SAE50SF/CF4-20",
|
||
"name": "SAE 50 - 20L",
|
||
"description": "SAE 50 - 20L",
|
||
"qty": 2,
|
||
"cost_price": 990,
|
||
"selling_price": 0,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"status": "in_stock"
|
||
},
|
||
{
|
||
"sku": "SAE40SFCF4-20",
|
||
"name": "SAE 40 - 20L",
|
||
"description": "SAE 40 - 20L",
|
||
"qty": 2,
|
||
"cost_price": 963,
|
||
"selling_price": 0,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"status": "in_stock"
|
||
},
|
||
{
|
||
"sku": "HYD68-20",
|
||
"name": "HYDRAULIC 68 - 20L",
|
||
"description": "HYDRAULIC 68 - 20L",
|
||
"qty": 16,
|
||
"cost_price": 748,
|
||
"selling_price": 0,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"status": "in_stock"
|
||
}
|
||
],
|
||
"supplier_history": [
|
||
{
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"last_cost": 990,
|
||
"last_bought_at": "2026-07-31 12:20:09.438Z",
|
||
"days_ago": 10,
|
||
"times_bought": 5,
|
||
"last_purchase_number": "PO26073109STK"
|
||
}
|
||
],
|
||
"price_list": [
|
||
{
|
||
"score": 0.667,
|
||
"sku": "AFRIQ-ENGINEOILS-SAE_50_SF_CF4-20LT",
|
||
"description": "SAE 50 SF/CF4 - 20 LT",
|
||
"brand": "AFRIQ",
|
||
"category": "Lubricants",
|
||
"cost_price": 879,
|
||
"selling_price": 879,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"source_file": "AFRIQ-RESELLERS-2026-05",
|
||
"updated": "2026-08-10 12:33:36.175Z"
|
||
},
|
||
{
|
||
"score": 0.667,
|
||
"sku": "AFRIQ-ENGINEOILS-SAE_50_SF_CF4-210LT",
|
||
"description": "SAE 50 SF/CF4 - 210 LT",
|
||
"brand": "AFRIQ",
|
||
"category": "Lubricants",
|
||
"cost_price": 8594,
|
||
"selling_price": 8594,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"source_file": "AFRIQ-RESELLERS-2026-05",
|
||
"updated": "2026-08-10 12:33:36.188Z"
|
||
},
|
||
{
|
||
"score": 0.667,
|
||
"sku": "AFRIQ-ENGINEOILS-SAE_50_SF_CF4-1000LT",
|
||
"description": "SAE 50 SF/CF4 - 1000 LT",
|
||
"brand": "AFRIQ",
|
||
"category": "Lubricants",
|
||
"cost_price": 38059,
|
||
"selling_price": 38059,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"source_file": "AFRIQ-RESELLERS-2026-05",
|
||
"updated": "2026-08-10 12:33:36.205Z"
|
||
},
|
||
{
|
||
"score": 0.667,
|
||
"sku": "AFRIQ-ENGINEOILS-SAE_50_SF_CF4-20500ML",
|
||
"description": "SAE 50 SF/CF4 - 20X500ML",
|
||
"brand": "AFRIQ",
|
||
"category": "Lubricants",
|
||
"cost_price": 566,
|
||
"selling_price": 566,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"source_file": "AFRIQ-RESELLERS-2026-05",
|
||
"updated": "2026-08-10 12:33:36.232Z"
|
||
},
|
||
{
|
||
"score": 0.667,
|
||
"sku": "AFRIQ-ENGINEOILS-SAE_50_SF_CF4-121LT",
|
||
"description": "SAE 50 SF/CF4 - 12X1LT",
|
||
"brand": "AFRIQ",
|
||
"category": "Lubricants",
|
||
"cost_price": 586,
|
||
"selling_price": 586,
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"source_file": "AFRIQ-RESELLERS-2026-05",
|
||
"updated": "2026-08-10 12:33:36.262Z"
|
||
}
|
||
],
|
||
"recent_quote": [
|
||
{
|
||
"quote_number": "RFQ000125",
|
||
"quote_status": "emailed",
|
||
"quoted_at": "2026-07-26 23:14:59.851Z",
|
||
"days_ago": 14,
|
||
"quantity": 1,
|
||
"cost_price": 1687.24,
|
||
"selling_price": 2277.77,
|
||
"description": "20L"
|
||
},
|
||
{
|
||
"quote_number": "Q007498",
|
||
"quote_status": "emailed",
|
||
"quoted_at": "2026-07-26 22:46:09.466Z",
|
||
"days_ago": 14,
|
||
"quantity": 6,
|
||
"cost_price": 434,
|
||
"selling_price": 607.6,
|
||
"description": "ANTIFREEZE 50% 20L"
|
||
}
|
||
],
|
||
"recent_order": [
|
||
{
|
||
"order_number": "PO055945",
|
||
"updated": "2026-07-30 07:34:43.565Z",
|
||
"days_ago": 11,
|
||
"quantity": 2,
|
||
"cost_price": 434,
|
||
"selling_price": 585.9,
|
||
"item_status": "delivered",
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"description": "20L ANTIFREEZE COOLANT -ALL SEASON 50% BUYOUTS FLEETCOOL EQUIVALENT THIS PRODUCT ALSO USES OAT TECHNOLOGY AND FORMULATED WITH ETHYLENE GLYCOL"
|
||
},
|
||
{
|
||
"order_number": "13/05/2026 Johan",
|
||
"updated": "2026-07-30 07:14:23.576Z",
|
||
"days_ago": 11,
|
||
"quantity": 20,
|
||
"cost_price": 478,
|
||
"selling_price": 597.5,
|
||
"item_status": "delivered",
|
||
"supplier": "AFRIQ LUBE AND SERVICES CC",
|
||
"description": "Antifreeze 50% All season 20L"
|
||
}
|
||
]
|
||
},
|
||
{
|
||
"item": {
|
||
"id": "h5szkwdxs1u2quk",
|
||
"collection": "quote_items",
|
||
"description": "Silicone sealant clear",
|
||
"sku": "",
|
||
"quantity": 12
|
||
},
|
||
"summary": "in stock 24 (Matus - Impumemelo,., cost R32.50) · bought from Matus - Impumemelo,. 10d ago @ R32.50 (×4) · last quoted R45.10 14d ago (Q000782) · last order 11d ago (MSP17006, delivered)",
|
||
"generated_at": "2026-08-10T14:47:15.285Z",
|
||
"stock_list": [
|
||
{
|
||
"sku": "SKU2-FE6EB3",
|
||
"name": "SILICONE CLEAR",
|
||
"description": "Silicone sealant clear",
|
||
"qty": 24,
|
||
"cost_price": 32.5,
|
||
"selling_price": 0,
|
||
"supplier": "Matus - Impumemelo,.",
|
||
"status": "in_stock"
|
||
},
|
||
{
|
||
"sku": "SKU3-27031C",
|
||
"name": "SILICONE WHITE",
|
||
"description": "Silicone sealant white",
|
||
"qty": 24,
|
||
"cost_price": 32.5,
|
||
"selling_price": 0,
|
||
"supplier": "Matus - Impumemelo,.",
|
||
"status": "in_stock"
|
||
},
|
||
{
|
||
"sku": "SKU4-9FED0D",
|
||
"name": "SILICONE HIGH HEAT H/R",
|
||
"description": "Silicone sealant high heat heat-resistant",
|
||
"qty": 24,
|
||
"cost_price": 106.5,
|
||
"selling_price": 0,
|
||
"supplier": "Matus - Impumemelo,.",
|
||
"status": "in_stock"
|
||
}
|
||
],
|
||
"supplier_history": [
|
||
{
|
||
"supplier": "Matus - Impumemelo,.",
|
||
"last_cost": 32.5,
|
||
"last_bought_at": "2026-07-31 12:23:17.546Z",
|
||
"days_ago": 10,
|
||
"times_bought": 4,
|
||
"last_purchase_number": "PO26073110STK"
|
||
}
|
||
],
|
||
"price_list": [],
|
||
"recent_quote": [
|
||
{
|
||
"quote_number": "Q000782",
|
||
"quote_status": "approved",
|
||
"quoted_at": "2026-07-26 23:12:59.230Z",
|
||
"days_ago": 14,
|
||
"quantity": 4,
|
||
"cost_price": 30.45,
|
||
"selling_price": 45.1,
|
||
"description": "Clear silicone"
|
||
},
|
||
{
|
||
"quote_number": "Q000783",
|
||
"quote_status": "approved",
|
||
"quoted_at": "2026-07-26 23:12:59.096Z",
|
||
"days_ago": 14,
|
||
"quantity": 4,
|
||
"cost_price": 30.45,
|
||
"selling_price": 45.1,
|
||
"description": "Clear silicone"
|
||
}
|
||
],
|
||
"recent_order": [
|
||
{
|
||
"order_number": "MSP17006",
|
||
"updated": "2026-07-30 07:48:00.648Z",
|
||
"days_ago": 11,
|
||
"quantity": 8,
|
||
"cost_price": 26,
|
||
"selling_price": 41.11,
|
||
"item_status": "delivered",
|
||
"supplier": "Fowkes Bros (Pty) Ltd",
|
||
"description": "SILICONE SEALANT CLEAR 260ML"
|
||
},
|
||
{
|
||
"order_number": "MSP17141",
|
||
"updated": "2026-07-30 07:39:41.044Z",
|
||
"days_ago": 11,
|
||
"quantity": 10,
|
||
"cost_price": 30.45,
|
||
"selling_price": 40.5,
|
||
"item_status": "delivered",
|
||
"supplier": "CNL - IN STOCK",
|
||
"description": "SERMAT Silicone Sealant Clear"
|
||
}
|
||
]
|
||
}
|
||
]
|