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: add kanban api endpoint

Brad Barbinabaacc703a9f
diff --git a/apps/erp/app/modules/inventory/inventory.models.ts b/apps/erp/app/modules/inventory/inventory.models.ts
index defc34972d..6f86762597 100644
--- a/apps/erp/app/modules/inventory/inventory.models.ts
+++ b/apps/erp/app/modules/inventory/inventory.models.ts
@@ -52,6 +52,27 @@ export const trackedEntityStatus = [
"Reserved",
] as const;
+export const replenishmentSystemTypes = [
+ "Buy",
+ "Make",
+ "Buy and Make",
+] as const;
+
+export const receiptSourceDocumentType = [
+ // "Sales Order",
+ // "Sales Invoice",
+ // "Sales Return Order",
+ "Purchase Order",
+ "Purchase Invoice",
+ // "Purchase Return Order",
+ "Inbound Transfer",
+ // "Outbound Transfer",
+ // "Manufacturing Consumption",
+ // "Manufacturing Output",
+] as const;
+
+export const receiptStatusType = ["Draft", "Pending", "Posted"] as const;
+
export const batchPropertyValidator = z
.object({
id: zfd.text(z.string().optional()),
@@ -96,20 +117,16 @@ export const itemLedgerValidator = z.object({
quantity: z.number(),
});
-export const receiptSourceDocumentType = [
- // "Sales Order",
- // "Sales Invoice",
- // "Sales Return Order",
- "Purchase Order",
- "Purchase Invoice",
- // "Purchase Return Order",
- "Inbound Transfer",
- // "Outbound Transfer",
- // "Manufacturing Consumption",
- // "Manufacturing Output",
-] as const;
-
-export const receiptStatusType = ["Draft", "Pending", "Posted"] as const;
+export const kanbanValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ itemId: z.string().min(1, { message: "Item is required" }),
+ replenishmentSystem: z.enum(replenishmentSystemTypes).default("Buy"),
+ quantity: zfd.numeric(
+ z.number().int().min(1, { message: "Quantity must be at least 1" })
+ ),
+ locationId: z.string().min(1, { message: "Location is required" }),
+ shelfId: zfd.text(z.string().optional()),
+});
export const receiptValidator = z.object({
id: z.string().min(1),
@@ -130,7 +147,12 @@ export const shelfValidator = z.object({
locationId: z.string().min(1, { message: "Location ID is required" }),
});
-export const shipmentStatusType = ["Draft", "Pending", "Posted", "Voided"] as const;
+export const shipmentStatusType = [
+ "Draft",
+ "Pending",
+ "Posted",
+ "Voided",
+] as const;
export const shipmentSourceDocumentType = [
"Sales Order",
@@ -231,19 +253,3 @@ export const warehouseTransferLineValidator = z
message: "From and To locations must be different",
path: ["toLocationId"],
});
-
-export const replenishmentSystemTypes = [
- "Buy",
- "Make",
- "Buy and Make",
-] as const;
-
-export const kanbanValidator = z.object({
- id: zfd.text(z.string().optional()),
- itemId: z.string().min(1, { message: "Item is required" }),
- replenishmentSystem: z.enum(replenishmentSystemTypes).default("Buy"),
- quantity: zfd.numeric(
- z.number().int().min(1, { message: "Quantity must be at least 1" })
- ),
- locationId: z.string().min(1, { message: "Location is required" }),
-});
diff --git a/apps/erp/app/modules/inventory/ui/Kanbans/KanbanForm.tsx b/apps/erp/app/modules/inventory/ui/Kanbans/KanbanForm.tsx
index 0207061898..f026dd36f2 100644
--- a/apps/erp/app/modules/inventory/ui/Kanbans/KanbanForm.tsx
+++ b/apps/erp/app/modules/inventory/ui/Kanbans/KanbanForm.tsx
@@ -17,7 +17,8 @@ import { useFetcher } from "@remix-run/react";
import { useState } from "react";
import type { z } from "zod";
import { Enumerable } from "~/components/Enumerable";
-import { Item, Location, Number, Submit } from "~/components/Form";
+import { Item, Location, Number, Shelf, Submit } from "~/components/Form";
+import { useUser } from "~/hooks";
import type { MethodItemType } from "~/modules/shared/types";
import { path } from "~/utils/path";
import {
@@ -41,25 +42,49 @@ const KanbanForm = ({ initialValues, onClose }: KanbanFormProps) => {
const isEditing = Boolean(initialValues.id);
+ const [shelfId, setShelfId] = useState<string | null>(
+ initialValues.shelfId || null
+ );
const [itemType, setItemType] = useState<MethodItemType | "Item">("Item");
const onTypeChange = (type: MethodItemType) => {
setItemType(type);
};
const { carbon } = useCarbon();
+ const { company } = useUser();
const onItemChange = async (value: { value: string } | null) => {
if (!carbon || !value) return;
- const item = await carbon
- .from("item")
- .select("replenishmentSystem")
- .eq("id", value.value)
- .single();
+ const [item, shelf] = await Promise.all([
+ carbon
+ .from("item")
+ .select("replenishmentSystem")
+ .eq("id", value.value)
+ .single(),
+ carbon
+ .from("pickMethod")
+ .select("defaultShelfId")
+ .eq("itemId", value.value)
+ .eq("companyId", company.id)
+ .eq("locationId", locationId)
+ .maybeSingle(),
+ ]);
if (item.error) {
toast.error("Failed to load item details");
return;
}
setSelectedReplenishmentSystem(item.data?.replenishmentSystem || "Buy");
+ if (shelf.data?.defaultShelfId) {
+ setShelfId(shelf.data.defaultShelfId);
+ }
+ };
+
+ const [locationId, setLocationId] = useState<string>(
+ initialValues.locationId || ""
+ );
+ const onLocationChange = (value: { value: string } | null) => {
+ setLocationId(value?.value || "");
+ setShelfId(null);
};
return (
@@ -129,8 +154,19 @@ const KanbanForm = ({ initialValues, onClose }: KanbanFormProps) => {
<Location
name="locationId"
label="Location"
+ onChange={onLocationChange}
isReadOnly={isEditing}
/>
+
+ <Shelf
+ name="shelfId"
+ label="Shelf"
+ locationId={locationId}
+ value={shelfId ?? undefined}
+ onChange={(value) => {
+ if (value) setShelfId(value?.id ?? null);
+ }}
+ />
</div>
</VStack>
</DrawerBody>
diff --git a/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx b/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
index cd152a1fcf..49d6d13a49 100644
--- a/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
+++ b/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
@@ -1,5 +1,6 @@
import {
Combobox,
+ Copy,
HStack,
IconButton,
MenuItem,
@@ -14,6 +15,7 @@ import { memo, useCallback, useMemo } from "react";
import {
LuCalendar,
LuHash,
+ LuLink,
LuMapPin,
LuPackage,
LuPencil,
@@ -106,6 +108,13 @@ const KanbansTable = memo(({ data, count, locationId }: KanbansTableProps) => {
/>
</PopoverContent>
</Popover>
+ <Copy
+ text={`${
+ typeof window === "undefined" ? "" : window.location.origin
+ }${path.to.api.kanban(row.original.id!)}`}
+ icon={<LuLink />}
+ size="md"
+ />
</HStack>
),
},
diff --git a/apps/erp/app/routes/file+/kanban+/$id[.]png.tsx b/apps/erp/app/routes/file+/kanban+/$id[.]png.tsx
index 057012ec4d..22216b2760 100644
--- a/apps/erp/app/routes/file+/kanban+/$id[.]png.tsx
+++ b/apps/erp/app/routes/file+/kanban+/$id[.]png.tsx
@@ -2,6 +2,7 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { generateQRCodeBuffer } from "@carbon/documents/qr";
import { json, type LoaderFunctionArgs } from "@vercel/remix";
import { getKanban } from "~/modules/inventory/inventory.service";
+import { path } from "~/utils/path";
export const config = { runtime: "nodejs" };
@@ -21,7 +22,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const url = new URL(request.url);
const baseUrl = `${url.protocol}//${url.host}`;
- const kanbanUrl = `${baseUrl}/api/kanban/${id}`;
+ const kanbanUrl = `${baseUrl}${path.to.api.kanban(id)}`;
const buffer = await generateQRCodeBuffer(kanbanUrl, 36);
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index ae8780bee9..7378e2fe0a 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -63,6 +63,7 @@ export const path = {
`${api}/production/methods/${id}/bom.csv?withOperations=${withOperations}`
),
jobs: `${api}/production/jobs`,
+ kanban: (id: string) => generatePath(`${api}/kanban/${id}`),
locations: `${api}/resources/locations`,
materialDimensions: (formId: string) =>
generatePath(`${api}/items/dimensions/${formId}`),
@@ -159,6 +160,10 @@ export const path = {
},
file: {
cadModel: (id: string) => generatePath(`${file}/model/${id}`),
+ kanbanLabelsPdf: (ids: string | string[]) => {
+ const idString = Array.isArray(ids) ? ids.join(",") : ids;
+ return generatePath(`${file}/kanban/labels.pdf?ids=${idString}`);
+ },
kanbanQrCode: (id: string) => generatePath(`${file}/kanban/${id}.png`),
jobTraveler: (id: string) => generatePath(`${file}/traveler/${id}.pdf`),
nonConformance: (id: string) => generatePath(`${file}/issue/${id}.pdf`),
@@ -198,6 +203,8 @@ export const path = {
return generatePath(url);
},
+ preview: (bucket: string, path: string) =>
+ generatePath(`${file}/preview/${bucket}/${path}`),
previewImage: (bucket: string, path: string) =>
generatePath(`${file}/preview/image?file=${bucket}/${path}`),
previewFile: (path: string) => generatePath(`${file}/preview/${path}`),
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index a5610910ad..efcb8a307b 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -14313,6 +14313,9 @@ export default {
{
$ref: "#/parameters/rowFilter.kanbans.locationId",
},
+ {
+ $ref: "#/parameters/rowFilter.kanbans.shelfId",
+ },
{
$ref: "#/parameters/rowFilter.kanbans.companyId",
},
@@ -54813,6 +54816,9 @@ export default {
{
$ref: "#/parameters/rowFilter.kanban.locationId",
},
+ {
+ $ref: "#/parameters/rowFilter.kanban.shelfId",
+ },
{
$ref: "#/parameters/rowFilter.kanban.companyId",
},
@@ -54902,6 +54908,9 @@ export default {
{
$ref: "#/parameters/rowFilter.kanban.locationId",
},
+ {
+ $ref: "#/parameters/rowFilter.kanban.shelfId",
+ },
{
$ref: "#/parameters/rowFilter.kanban.companyId",
},
@@ -54945,6 +54954,9 @@ export default {
{
$ref: "#/parameters/rowFilter.kanban.locationId",
},
+ {
+ $ref: "#/parameters/rowFilter.kanban.shelfId",
+ },
{
$ref: "#/parameters/rowFilter.kanban.companyId",
},
@@ -67012,6 +67024,12 @@ export default {
format: "text",
type: "string",
},
+ shelfId: {
+ description:
+ "Note:\nThis is a Foreign Key to `shelf.id`.<fk table='shelf' column='id'/>",
+ format: "text",
+ type: "string",
+ },
companyId: {
description:
"Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
@@ -86056,6 +86074,12 @@ export default {
format: "text",
type: "string",
},
+ shelfId: {
+ description:
+ "Note:\nThis is a Foreign Key to `shelf.id`.<fk table='shelf' column='id'/>",
+ format: "text",
+ type: "string",
+ },
companyId: {
description:
"Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
@@ -93762,6 +93786,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.kanbans.shelfId": {
+ name: "shelfId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.kanbans.companyId": {
name: "companyId",
required: false,
@@ -115221,6 +115251,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.kanban.shelfId": {
+ name: "shelfId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.kanban.companyId": {
name: "companyId",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 24f6ebdb13..9c53d050c5 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -11637,6 +11637,7 @@ export type Database = {
locationId: string
quantity: number
replenishmentSystem: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ shelfId: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -11649,6 +11650,7 @@ export type Database = {
locationId: string
quantity: number
replenishmentSystem?: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ shelfId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -11661,6 +11663,7 @@ export type Database = {
locationId?: string
quantity?: number
replenishmentSystem?: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ shelfId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -11770,6 +11773,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "kanban_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "kanban_updatedBy_fkey"
columns: ["updatedBy"]
@@ -39328,6 +39338,7 @@ export type Database = {
replenishmentSystem:
| Database["public"]["Enums"]["itemReplenishmentSystem"]
| null
+ shelfId: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -39437,6 +39448,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "kanban_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "kanban_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 24f6ebdb13..9c53d050c5 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -11637,6 +11637,7 @@ export type Database = {
locationId: string
quantity: number
replenishmentSystem: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ shelfId: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -11649,6 +11650,7 @@ export type Database = {
locationId: string
quantity: number
replenishmentSystem?: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ shelfId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -11661,6 +11663,7 @@ export type Database = {
locationId?: string
quantity?: number
replenishmentSystem?: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ shelfId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -11770,6 +11773,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "kanban_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "kanban_updatedBy_fkey"
columns: ["updatedBy"]
@@ -39328,6 +39338,7 @@ export type Database = {
replenishmentSystem:
| Database["public"]["Enums"]["itemReplenishmentSystem"]
| null
+ shelfId: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -39437,6 +39448,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "kanban_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "kanban_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/migrations/20250909012102_kanban.sql b/packages/database/supabase/migrations/20250909012102_kanban.sql
index c361f83f4d..5fbf374c4d 100644
--- a/packages/database/supabase/migrations/20250909012102_kanban.sql
+++ b/packages/database/supabase/migrations/20250909012102_kanban.sql
@@ -4,6 +4,7 @@ CREATE TABLE "kanban" (
"replenishmentSystem" "itemReplenishmentSystem" NOT NULL DEFAULT 'Buy',
"quantity" INTEGER NOT NULL,
"locationId" TEXT NOT NULL,
+ "shelfId" TEXT,
"companyId" TEXT NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
"createdBy" TEXT NOT NULL,
@@ -13,6 +14,7 @@ CREATE TABLE "kanban" (
CONSTRAINT "kanban_pkey" PRIMARY KEY ("id", "companyId"),
CONSTRAINT "kanban_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE CASCADE,
CONSTRAINT "kanban_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON DELETE CASCADE,
+ CONSTRAINT "kanban_shelfId_fkey" FOREIGN KEY ("shelfId") REFERENCES "shelf"("id") ON DELETE CASCADE,
CONSTRAINT "kanban_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE,
CONSTRAINT "kanban_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON DELETE CASCADE,
CONSTRAINT "kanban_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON DELETE CASCADE
diff --git a/packages/documents/src/pdf/index.ts b/packages/documents/src/pdf/index.ts
index 3019477dcf..54ec1f5d75 100644
--- a/packages/documents/src/pdf/index.ts
+++ b/packages/documents/src/pdf/index.ts
@@ -1,5 +1,6 @@
import IssuePDF from "./IssuePDF";
import JobTravelerPDF from "./JobTravelerPDF";
+import KanbanLabelPDF from "./KanbanLabelPDF";
import PackingSlipPDF from "./PackingSlipPDF";
import ProductLabelPDF from "./ProductLabelPDF";
import PurchaseOrderPDF from "./PurchaseOrderPDF";
diff --git a/packages/react/src/Copy.tsx b/packages/react/src/Copy.tsx
index 7e5cd043f4..99a62e351a 100644
--- a/packages/react/src/Copy.tsx
+++ b/packages/react/src/Copy.tsx
@@ -1,21 +1,22 @@
-import type { ReactNode } from "react";
import { useState } from "react";
import { LuCheck, LuCopy } from "react-icons/lu";
-import { copyToClipboard } from "./utils/dom";
-import { cn } from "./utils/cn";
-import { Button } from "./Button";
+import { IconButton } from "./IconButton";
import { Tooltip, TooltipContent, TooltipTrigger } from "./Tooltip";
+import { cn } from "./utils/cn";
+import { copyToClipboard } from "./utils/dom";
const Copy = ({
text,
icon,
className,
withTextInTooltip = false,
+ size = "sm",
}: {
text: string;
- icon?: ReactNode;
+ icon?: JSX.Element;
className?: string;
withTextInTooltip?: boolean;
+ size?: "sm" | "md" | "lg";
}) => {
const [isCopied, setIsCopied] = useState(false);
@@ -28,23 +29,17 @@ const Copy = ({
return (
<Tooltip>
<TooltipTrigger asChild>
- <Button
+ <IconButton
variant="secondary"
aria-label="Copy"
- size="sm"
+ icon={isCopied ? <LuCheck /> : icon ?? <LuCopy />}
+ size={size}
className={cn(
- "p-1 w-6 h-6",
isCopied && "text-emerald-500 hover:text-emerald-500",
className
)}
onClick={handleCopy}
- >
- {isCopied ? (
- <LuCheck className="w-3 h-3" />
- ) : (
- icon ?? <LuCopy className="w-3 h-3" />
- )}
- </Button>
+ />
</TooltipTrigger>
<TooltipContent>
<span>
diff --git a/packages/react/src/IconButton.tsx b/packages/react/src/IconButton.tsx
index 61e1eff1a5..887bd60f7e 100644
--- a/packages/react/src/IconButton.tsx
+++ b/packages/react/src/IconButton.tsx
@@ -12,9 +12,9 @@ export interface IconButtonProps
}
const iconSizes = {
- sm: "w-4 h-4",
- md: "w-5 h-5",
- lg: "w-6 h-6",
+ sm: "size-3",
+ md: "size-5",
+ lg: "size-6",
} as const;
const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(