Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: color code qr codes for kanban

Brad Barbin67dc337a15f7
diff --git a/apps/erp/app/routes/file+/kanban+/$id.$action[.]png.tsx b/apps/erp/app/routes/file+/kanban+/$id.$action[.]png.tsx
index 39e79e4881..b7a4bb463a 100644
--- a/apps/erp/app/routes/file+/kanban+/$id.$action[.]png.tsx
+++ b/apps/erp/app/routes/file+/kanban+/$id.$action[.]png.tsx
@@ -26,16 +26,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const url = new URL(request.url);
let kanbanUrl = "";
+ let qrColor = "000000";
const baseUrl = `${url.protocol}//${url.host}`;
if (action === "order") {
kanbanUrl = `${baseUrl}${path.to.api.kanban(id)}`;
+ qrColor = "000000"; // black
} else if (action === "start") {
kanbanUrl = `${baseUrl}${path.to.api.kanbanStart(id)}`;
+ qrColor = "059669"; // emerald-600
} else if (action === "complete") {
kanbanUrl = `${baseUrl}${path.to.api.kanbanComplete(id)}`;
+ qrColor = "2563eb"; // blue-600
}
- const buffer = await generateQRCodeBuffer(kanbanUrl, 36);
+ console.log({ qrColor });
+
+ const buffer = await generateQRCodeBuffer(kanbanUrl, 36, qrColor);
// @ts-ignore
return new Response(buffer, {
diff --git a/apps/erp/app/routes/file+/kanban+/labels.$action[.]pdf.tsx b/apps/erp/app/routes/file+/kanban+/labels.$action[.]pdf.tsx
index 91f2de40da..24e741a608 100644
--- a/apps/erp/app/routes/file+/kanban+/labels.$action[.]pdf.tsx
+++ b/apps/erp/app/routes/file+/kanban+/labels.$action[.]pdf.tsx
@@ -101,7 +101,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
// Generate PDF
const stream = await renderToStream(
- <KanbanLabelPDF baseUrl={baseUrl} labels={labels} />
+ <KanbanLabelPDF
+ baseUrl={baseUrl}
+ labels={labels}
+ action={action as "order" | "start" | "complete"}
+ />
);
const body: Buffer = await new Promise((resolve, reject) => {
diff --git a/llm/cache/kanban-system.md b/llm/cache/kanban-system.md
index 4126e9b602..44da66741c 100644
--- a/llm/cache/kanban-system.md
+++ b/llm/cache/kanban-system.md
@@ -110,8 +110,27 @@ Located at `/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx`:
- Table view of kanbans with search and filtering
- Column visibility controls
-- Action buttons for edit/delete/QR code generation
- Location filtering support
+- Displays columns:
+ - Item (with thumbnail, name, and readable ID)
+ - Job badge (shows active job if exists, with pulsing dot)
+ - Action links (Create/Start/Complete based on kanbanOutput setting)
+ - Reorder Qty (with unit of measure)
+ - Replenishment system (Buy/Make)
+ - Supplier (for Buy kanbans)
+ - Shelf name
+ - Auto Release checkbox (Make only)
+ - Auto Start checkbox (Make only)
+ - Created by/at, Updated by/at
+- Context menu actions:
+ - Edit kanban
+ - Delete kanban
+- Bulk actions:
+ - Print labels for selected kanbans
+- Primary actions:
+ - Location selector (hard refresh on change)
+ - Settings button (links to inventory settings)
+ - New Kanban button
## Routes and API
@@ -124,35 +143,87 @@ Located at `/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx`:
### API Routes
-- `/api/kanban/:id` - Kanban API endpoint (handles replenishment logic)
-- `/file/kanban/:id.png` - QR code generation for kanban
+- `/api/kanban/:id` - Main kanban API endpoint (handles replenishment logic)
+- `/api/kanban/collision/:id` - Handles kanban job collision (when kanban already has active job)
+- `/api/kanban/start/:id` - Starts next operation for kanban job
+- `/api/kanban/complete/:id` - Completes current operation for kanban job
+- `/api/kanban/link/:id` - Links kanban to job
+- `/file/kanban/:id/:action.png` - QR code generation for kanban actions
+- `/file/kanban/labels/:action.pdf?ids=` - PDF label generation for kanbans
## QR Code Integration
### QR Code Generation
-- Route: `/file/kanban/:id.png`
-- Generates QR code pointing to `/api/kanban/:id`
+- Route: `/file/kanban/:id/:action.png` where action is "order", "start", or "complete"
+- Generates QR code pointing to corresponding API endpoints:
+ - "order" -> `/api/kanban/:id` (creates job/order)
+ - "start" -> `/api/kanban/start/:id` (starts operation)
+ - "complete" -> `/api/kanban/complete/:id` (completes operation)
- Uses `@carbon/documents/qr` package
- 36px size with PNG format
- Cached with max-age headers
### QR Code Usage
-- Available as action in KanbansTable
+- Available as action in KanbansTable based on kanbanOutput setting
+- Three action types available:
+ - **order/Create** - QR code to create a job (Make) or purchase order (Buy)
+ - **start/Start** - QR code to start next operation (Make only)
+ - **complete/Complete** - QR code to complete current operation (Make only)
- Generates scannable codes for physical kanban cards
- Links to API endpoint for replenishment processing
+- Start and Complete actions only shown for "Make" replenishment system
+
+### Kanban Output Types
+
+Three kanban output types defined in settings (`kanbanOutputTypes`):
+
+1. **label** - PDF labels with QR codes
+2. **qrcode** - QR codes displayed in hover cards
+3. **url** - Copyable URLs for the actions
+
+### Label PDF Generation
+
+Located at `/apps/erp/app/routes/file+/kanban+/labels.$action[.]pdf.tsx`
+
+- Generates PDF labels using `@carbon/documents/pdf` KanbanLabelPDF component
+- Accepts comma-separated kanban IDs via query parameter `?ids=`
+- Action parameter determines which API endpoint the QR code points to ("order", "start", or "complete")
+- Currently generates same label design for all actions (no color differentiation)
+- Label layout:
+ - 2x3 grid (6 labels per letter-size page)
+ - QR code and item thumbnail
+ - Item name and readable ID
+ - Location/shelf name
+ - Quantity with unit of measure
+ - Supplier name at bottom
+- Fetches item thumbnails in parallel and converts to base64
+- No color coding currently implemented for different action types
## Replenishment System Integration
### API Handler (`/api/kanban/:id`)
+Located at `/apps/erp/app/routes/api+/kanban.$id.tsx`
+
- Validates kanban access and company association
- Routes based on replenishment system:
- - **"Make"** - Production order creation logic (placeholder)
- - **"Buy"** - Purchase order creation logic (placeholder)
+ - **"Make"** - Creates production job with:
+ - Auto-generated job ID from sequence
+ - Copies quantity, location, shelf from kanban
+ - Creates job method from item
+ - Associates kanban with job
+ - Optional auto-release (triggers MRP, scheduling)
+ - Optional auto-start (redirects to MES operation start)
+ - Redirects to job or MES operation page
+ - **"Buy"** - Creates/adds to purchase order:
+ - Finds or creates draft purchase order for supplier
+ - Adds purchase order line with kanban quantity
+ - Uses supplier pricing or item cost
+ - Sets location/shelf from kanban or item defaults
+ - Redirects to purchase order page
- **"Buy and Make"** - Not yet supported (throws error)
-- Currently redirects to authenticated root after processing
### Replenishment Types
@@ -162,16 +233,29 @@ Defined in `replenishmentSystemTypes`:
- `"Make"` - Production-based replenishment
- `"Buy and Make"` - Hybrid approach (not implemented)
+### Kanban Collision Handling
+
+- When a "Make" kanban already has an active job (jobReadableId exists), scanning the "order" QR code redirects to `/api/kanban/collision/:id`
+- Prevents creating duplicate jobs for the same kanban
+- Allows user to navigate to existing job instead
+
## Path Configuration
Kanban-related paths defined in `/apps/erp/app/utils/path.ts`:
```typescript
api: {
- kanban: (id: string) => `/api/kanban/${id}`
+ kanban: (id: string) => `/api/kanban/${id}`,
+ kanbanCollision: (id: string) => `/api/kanban/collision/${id}`,
+ kanbanComplete: (id: string) => `/api/kanban/complete/${id}`,
+ kanbanJobLink: (id: string) => `/api/kanban/link/${id}`,
+ kanbanStart: (id: string) => `/api/kanban/start/${id}`
}
file: {
- kanbanQrCode: (id: string) => `/file/kanban/${id}.png`
+ kanbanLabelsPdf: (ids: string | string[], action: "order" | "start" | "complete") =>
+ `/file/kanban/labels/${action}.pdf?ids=${ids}`,
+ kanbanQrCode: (id: string, action: "order" | "start" | "complete") =>
+ `/file/kanban/${id}/${action}.png`
}
to: {
kanbans: '/x/inventory/kanbans',
diff --git a/packages/documents/src/pdf/KanbanLabelPDF.tsx b/packages/documents/src/pdf/KanbanLabelPDF.tsx
index 90302182ab..0a6fb6cc69 100644
--- a/packages/documents/src/pdf/KanbanLabelPDF.tsx
+++ b/packages/documents/src/pdf/KanbanLabelPDF.tsx
@@ -19,6 +19,7 @@ interface KanbanLabel {
interface KanbanLabelPDFProps {
baseUrl: string;
labels: KanbanLabel[];
+ action?: "order" | "start" | "complete";
}
// Initialize tailwind-styled-components
@@ -37,7 +38,11 @@ const tw = createTw({
},
});
-const KanbanLabelPDF = ({ baseUrl, labels }: KanbanLabelPDFProps) => {
+const KanbanLabelPDF = ({
+ baseUrl,
+ labels,
+ action = "order",
+}: KanbanLabelPDFProps) => {
// Fixed 2x3 layout (6 labels per page)
const rows = 3;
const columns = 2;
@@ -58,6 +63,21 @@ const KanbanLabelPDF = ({ baseUrl, labels }: KanbanLabelPDFProps) => {
// QR code size - make it prominent
const qrCodeSize = Math.min(labelHeight * 0.35, labelWidth * 0.4);
+ // QR code color based on action type
+ const getQRColor = () => {
+ if (action === "start") return "059669"; // emerald-600
+ if (action === "complete") return "2563eb"; // blue-600
+ return "000000"; // black for order
+ };
+
+ // Get appropriate API endpoint based on action
+ const getKanbanUrl = (labelId: string) => {
+ if (action === "start") return `${baseUrl}/api/kanban/start/${labelId}`;
+ if (action === "complete")
+ return `${baseUrl}/api/kanban/complete/${labelId}`;
+ return `${baseUrl}/api/kanban/${labelId}`;
+ };
+
return (
<Document>
{Array.from({ length: pageCount }).map((_, pageIndex) => (
@@ -107,8 +127,9 @@ const KanbanLabelPDF = ({ baseUrl, labels }: KanbanLabelPDFProps) => {
{/* QR Code */}
<Image
src={generateQRCode(
- `${baseUrl}/api/kanban/${label.id}`,
- qrCodeSize / 72
+ getKanbanUrl(label.id),
+ qrCodeSize / 72,
+ getQRColor()
)}
style={{
width: qrCodeSize,
diff --git a/packages/documents/src/qr/qr-code.ts b/packages/documents/src/qr/qr-code.ts
index 562a5e348c..ccee2589ae 100644
--- a/packages/documents/src/qr/qr-code.ts
+++ b/packages/documents/src/qr/qr-code.ts
@@ -2,7 +2,8 @@ import bwipjs from "@bwip-js/node";
export async function generateQRCode(
text: string,
- size: number
+ size: number,
+ color?: string
): Promise<string> {
const buffer = await bwipjs.toBuffer({
bcid: "qrcode",
@@ -10,13 +11,15 @@ export async function generateQRCode(
scale: 2,
height: size,
width: size,
+ ...(color && { barcolor: color }),
});
return `data:image/png;base64,${buffer.toString("base64")}`;
}
export async function generateQRCodeBuffer(
text: string,
- size: number
+ size: number,
+ color?: string
): Promise<Buffer> {
const buffer = await bwipjs.toBuffer({
bcid: "qrcode",
@@ -24,6 +27,7 @@ export async function generateQRCodeBuffer(
scale: 2,
height: size,
width: size,
+ ...(color && { barcolor: color }),
});
return buffer;
}