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: pick list session widget

Brad Barbin3826d495dbdc
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
index d1d099d2c8..b5b1dba106 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -287,7 +287,7 @@ const JobHeader = () => {
}
dropdownItems={[
{
- label: "Mark as Planned",
+ label: <JobStatus status="Planned" />,
icon: <LuCheckCheck />,
onClick: markAsPlanned,
},
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
index 32d3bb2463..13178b3312 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
@@ -1,18 +1,34 @@
-import { Badge, Button, cn, HStack, VStack } from "@carbon/react";
+import {
+ Badge,
+ Button,
+ cn,
+ Count,
+ HStack,
+ IconButton,
+ ScrollArea,
+ useMount,
+ VStack,
+} from "@carbon/react";
import { useNumberFormatter } from "@react-aria/i18n";
import { useFetcher, useParams } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
-import { memo, useMemo } from "react";
+import { memo, useMemo, useState } from "react";
import {
LuArrowDown,
LuArrowLeft,
LuArrowUp,
LuBookMarked,
- LuCircleCheck,
+ LuCheckCheck,
LuFlag,
LuGitPullRequest,
LuHash,
+ LuMaximize2,
+ LuMinus,
LuRefreshCcwDot,
+ LuShoppingCart,
+ LuTrash2,
+ LuTruck,
+ LuX,
} from "react-icons/lu";
import {
Hyperlink,
@@ -23,6 +39,12 @@ import {
} from "~/components";
import { usePermissions, useRouteData } from "~/hooks";
import { useBom, useItems } from "~/stores";
+import {
+ useOrderItems,
+ usePickListSession,
+ usePickListSessionItemsCount,
+ useTransferItems,
+} from "~/stores/pick-list-session";
import { path } from "~/utils/path";
import type { Job, JobMaterial } from "../../types";
@@ -44,6 +66,81 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
const [items] = useItems();
const [, setSelectedMaterialId] = useBom();
+ const sessionItemsCount = usePickListSessionItemsCount();
+ const [, setPickListSession] = usePickListSession();
+
+ useMount(() => {
+ // Prepopulate pick list session with all parts that need transferred or ordered
+ const itemsToAdd: Array<{
+ id: string;
+ itemReadableId: string;
+ description: string;
+ action: "transfer" | "order";
+ quantity: number;
+ }> = [];
+
+ data.forEach((material) => {
+ if (
+ material.itemTrackingType === "Non-Inventory" ||
+ material.methodType === "Make" ||
+ !material.id
+ ) {
+ return;
+ }
+
+ const quantityRequiredByShelf = isAllocated
+ ? material.quantityFromProductionOrderInShelf
+ : material.quantityFromProductionOrderInShelf +
+ material.estimatedQuantity;
+
+ // Check if transfer is needed
+ const quantityOnHandInShelf = material.quantityOnHandInShelf;
+ const hasShelfQuantityFlag =
+ quantityOnHandInShelf < quantityRequiredByShelf;
+
+ if (hasShelfQuantityFlag) {
+ itemsToAdd.push({
+ id: material.id,
+ itemReadableId: material.itemReadableId,
+ description: material.description,
+ action: "transfer",
+ quantity: quantityRequiredByShelf - quantityOnHandInShelf,
+ });
+ }
+
+ // Check if order is needed
+ const quantityOnHand =
+ material.quantityOnHandInShelf + material.quantityOnHandNotInShelf;
+
+ const incoming =
+ material.quantityOnPurchaseOrder + material.quantityOnProductionOrder;
+
+ const allocated =
+ material.quantityFromProductionOrderInShelf +
+ material.quantityFromProductionOrderNotInShelf +
+ material.quantityOnSalesOrder;
+
+ const hasTotalQuantityFlag =
+ quantityOnHand + incoming - allocated <
+ (material.estimatedQuantity ?? 0);
+
+ if (hasTotalQuantityFlag) {
+ itemsToAdd.push({
+ id: material.id,
+ itemReadableId: material.itemReadableId,
+ description: material.description,
+ action: "order",
+ quantity:
+ (material.estimatedQuantity ?? 0) -
+ (quantityOnHand + incoming - allocated),
+ });
+ }
+ });
+
+ if (itemsToAdd.length > 0) {
+ setPickListSession({ items: itemsToAdd });
+ }
+ });
const columns = useMemo<ColumnDef<JobMaterial>[]>(() => {
return [
@@ -87,7 +184,7 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
},
{
accessorKey: "estimatedQuantity",
- header: "Quantity",
+ header: "Required",
cell: ({ row }) => formatter.format(row.original.estimatedQuantity),
meta: {
icon: <LuHash />,
@@ -143,20 +240,20 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
}
const quantityOnHandInShelf = row.original.quantityOnHandInShelf;
-
- if (quantityOnHandInShelf < quantityRequiredByShelf)
- return (
- <Badge variant="destructive">
- <LuFlag className="mr-2" />
- {quantityOnHandInShelf}
- </Badge>
- );
+ const hasShelfQuantityFlag =
+ quantityOnHandInShelf < quantityRequiredByShelf;
return (
- <Badge variant="green">
- <LuCircleCheck className="mr-2" />
- {quantityOnHandInShelf}
- </Badge>
+ <HStack>
+ {hasShelfQuantityFlag ? (
+ <>
+ <span className="text-red-500">{quantityOnHandInShelf}</span>
+ <LuFlag className="text-red-500" />
+ </>
+ ) : (
+ <span>{quantityOnHandInShelf}</span>
+ )}
+ </HStack>
);
},
meta: {
@@ -186,18 +283,22 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
row.original.quantityFromProductionOrderNotInShelf +
row.original.quantityOnSalesOrder;
- if (
+ const hasTotalQuantityFlag =
quantityOnHand + incoming - allocated <
- (row.original.estimatedQuantity ?? 0)
- ) {
- return (
- <Badge variant="destructive">
- <LuFlag className="mr-2" />
- {quantityOnHand}
- </Badge>
- );
- }
- return quantityOnHand;
+ (row.original.estimatedQuantity ?? 0);
+
+ return (
+ <HStack>
+ {hasTotalQuantityFlag ? (
+ <>
+ <span className="text-red-500">{quantityOnHand}</span>
+ <LuFlag className="text-red-500" />
+ </>
+ ) : (
+ <span>{quantityOnHand}</span>
+ )}
+ </HStack>
+ );
},
meta: {
icon: <LuHash />,
@@ -226,36 +327,293 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
},
},
];
- }, [items, jobId, setSelectedMaterialId]);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [
+ items,
+ jobId,
+ setSelectedMaterialId,
+ isAllocated,
+ formatter,
+ sessionItemsCount,
+ ]);
const permissions = usePermissions();
return (
- <Table<JobMaterial>
- compact
- count={count}
- columns={columns}
- data={data}
- primaryAction={
- data.length > 0 && permissions.can("update", "production") ? (
- <fetcher.Form action={path.to.jobRecalculate(jobId)} method="post">
- <Button
- leftIcon={<LuRefreshCcwDot />}
- isLoading={fetcher.state !== "idle"}
- isDisabled={fetcher.state !== "idle"}
- type="submit"
- variant="secondary"
- >
- Recalculate
- </Button>
- </fetcher.Form>
- ) : undefined
- }
- title="Materials"
- />
+ <>
+ <Table<JobMaterial>
+ compact
+ count={count}
+ columns={columns}
+ data={data}
+ primaryAction={
+ data.length > 0 && permissions.can("update", "production") ? (
+ <fetcher.Form action={path.to.jobRecalculate(jobId)} method="post">
+ <Button
+ leftIcon={<LuRefreshCcwDot />}
+ isLoading={fetcher.state !== "idle"}
+ isDisabled={fetcher.state !== "idle"}
+ type="submit"
+ variant="secondary"
+ >
+ Recalculate
+ </Button>
+ </fetcher.Form>
+ ) : undefined
+ }
+ title="Materials"
+ />
+ <PickListSessionWidget />
+ </>
);
});
JobMaterialsTable.displayName = "JobMaterialsTable";
export default JobMaterialsTable;
+
+const PickListSessionWidget = () => {
+ const [session, setPickListSession] = usePickListSession();
+ const sessionItemsCount = usePickListSessionItemsCount();
+ const orderItems = useOrderItems();
+ const transferItems = useTransferItems();
+
+ const [isExpanded, setIsExpanded] = useState(false);
+ const [isMinimized, setIsMinimized] = useState(false);
+
+ const allItems = [...orderItems, ...transferItems];
+
+ const onRemoveItem = (itemId: string, action: "order" | "transfer") => {
+ const updatedItems = session.items.filter(
+ (sessionItem) =>
+ !(sessionItem.id === itemId && sessionItem.action === action)
+ );
+ setPickListSession({ items: updatedItems });
+ };
+
+ const onClearAll = () => {
+ setPickListSession({ items: [] });
+ };
+
+ if (sessionItemsCount === 0) {
+ return null;
+ }
+
+ if (isMinimized) {
+ return (
+ <div className="fixed bottom-6 right-6 z-50">
+ <button
+ onClick={() => setIsMinimized(false)}
+ className="relative flex items-center justify-center w-16 h-16 bg-card border-2 border-border rounded-full shadow-2xl hover:scale-105 transition-transform duration-200"
+ >
+ <LuShoppingCart className="w-6 h-6 text-foreground" />
+ {allItems.length > 0 && (
+ <Badge className="absolute -top-2 -right-2 h-7 w-7 flex items-center justify-center p-0 border-2 border-background">
+ {allItems.length}
+ </Badge>
+ )}
+ </button>
+ </div>
+ );
+ }
+
+ return (
+ <div className="fixed bottom-6 right-6 z-50">
+ <div
+ className={`bg-card border-2 border-border rounded-2xl shadow-2xl transition-all duration-300 ease-in-out ${
+ isExpanded ? "w-96 h-[32rem]" : "w-80 h-auto"
+ }`}
+ >
+ {/* Header */}
+ <div className="flex items-center justify-between p-4 border-b-2 border-border">
+ <div className="flex items-center gap-3">
+ <div className="flex items-center justify-center w-10 h-10 bg-primary rounded-lg">
+ <LuCheckCheck className="w-5 h-5 text-primary-foreground" />
+ </div>
+ <div>
+ <h3 className="font-semibold text-card-foreground text-base">
+ Action Items
+ </h3>
+ <p className="text-xs text-muted-foreground">
+ {allItems.length} {allItems.length === 1 ? "item" : "items"}
+ </p>
+ </div>
+ </div>
+ <div className="flex items-center gap-1">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 w-8 p-0 text-muted-foreground hover:text-foreground"
+ onClick={() => setIsExpanded(!isExpanded)}
+ >
+ {isExpanded ? (
+ <LuMinus className="size-4" />
+ ) : (
+ <LuMaximize2 className="size-4" />
+ )}
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 w-8 p-0 text-muted-foreground hover:text-foreground"
+ onClick={() => setIsMinimized(true)}
+ >
+ <LuX className="size-4" />
+ </Button>
+ </div>
+ </div>
+
+ {/* Content */}
+ {isExpanded ? (
+ <div className="flex flex-col h-[calc(32rem-5rem)]">
+ <ScrollArea className="flex-1 p-4">
+ {allItems.length === 0 ? (
+ <div className="flex flex-col items-center justify-center h-full text-center py-12">
+ <div className="w-16 h-16 bg-muted rounded-full flex items-center justify-center mb-4">
+ <LuShoppingCart className="w-8 h-8 text-muted-foreground" />
+ </div>
+ <p className="text-sm text-muted-foreground">
+ No parts added yet
+ </p>
+ <p className="text-xs text-muted-foreground mt-1">
+ Start adding parts to your pick list
+ </p>
+ </div>
+ ) : (
+ <div className="space-y-3">
+ {orderItems.length > 0 && (
+ <div className="mb-4">
+ <HStack className="mb-2">
+ <LuShoppingCart className="h-3 w-3" />
+ <span className="text-sm font-medium">
+ Orders <Count count={orderItems.length} />
+ </span>
+ </HStack>
+ <div className="space-y-2">
+ {orderItems.map((item) => (
+ <div
+ key={`${item.id}-order`}
+ className="group bg-secondary/50 border border-border rounded-lg p-3 hover:bg-secondary transition-colors"
+ >
+ <div className="flex items-start justify-between gap-3">
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center justify-between gap-2 mb-1">
+ <span className="font-mono text-xs font-semibold">
+ {item.itemReadableId}
+ </span>
+ <Badge variant="outline">Order</Badge>
+ </div>
+ <p className="text-sm text-card-foreground font-medium truncate">
+ {item.description}
+ </p>
+ </div>
+ <IconButton
+ variant="secondary"
+ aria-label="Remove item"
+ icon={<LuTrash2 />}
+ size="sm"
+ onClick={() => onRemoveItem(item.id, "order")}
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {transferItems.length > 0 && (
+ <div>
+ <HStack className="mb-2">
+ <LuTruck className="h-3 w-3" />
+ <span className="text-sm font-medium">
+ Transfers <Count count={transferItems.length} />
+ </span>
+ </HStack>
+ <div className="space-y-2">
+ {transferItems.map((item) => (
+ <div
+ key={`${item.id}-transfer`}
+ className="group bg-secondary/50 border border-border rounded-lg p-3 hover:bg-secondary transition-colors"
+ >
+ <div className="flex items-start justify-between gap-3">
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center justify-between gap-2 mb-1">
+ <span className="font-mono text-xs font-semibold">
+ {item.itemReadableId}
+ </span>
+ <Badge variant="outline">Transfer</Badge>
+ </div>
+ <p className="text-sm text-card-foreground font-medium truncate">
+ {item.description}
+ </p>
+ </div>
+ <IconButton
+ variant="secondary"
+ aria-label="Remove item"
+ icon={<LuTrash2 />}
+ size="sm"
+ onClick={() =>
+ onRemoveItem(item.id, "transfer")
+ }
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ )}
+ </ScrollArea>
+
+ {/* Footer */}
+ {allItems.length > 0 && (
+ <div className="p-4 border-t-2 border-border space-y-2">
+ <Button
+ className="w-full bg-accent hover:bg-accent/90 text-accent-foreground font-semibold"
+ size="lg"
+ >
+ Submit
+ </Button>
+ <Button
+ variant="secondary"
+ className="w-full bg-transparent"
+ onClick={onClearAll}
+ >
+ Clear All
+ </Button>
+ </div>
+ )}
+ </div>
+ ) : (
+ <div className="p-4">
+ {allItems.length === 0 ? (
+ <p className="text-sm text-muted-foreground text-center py-2">
+ No parts added yet
+ </p>
+ ) : (
+ <div className="space-y-2">
+ {allItems.slice(0, 3).map((item) => (
+ <div
+ key={`${item.id}-${item.action}`}
+ className="flex items-center justify-between text-sm"
+ >
+ <span className="font-mono text-xs">
+ {item.itemReadableId}
+ </span>
+ <Badge variant="outline">{item.action}</Badge>
+ </div>
+ ))}
+ {allItems.length > 3 && (
+ <p className="text-xs text-muted-foreground text-center pt-1">
+ +{allItems.length - 3} more
+ </p>
+ )}
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+};
diff --git a/apps/erp/app/routes/x+/job+/$jobId.status.tsx b/apps/erp/app/routes/x+/job+/$jobId.status.tsx
index 14d3f7acdf..0184355f64 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.status.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.status.tsx
@@ -138,6 +138,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
+ if (status === "Planned") {
+ throw redirect(
+ path.to.jobMaterials(id),
+ await flash(request, success("Job marked as planned"))
+ );
+ }
+
throw redirect(
requestReferrer(request) ?? path.to.job(id),
await flash(request, success("Updated job status"))
diff --git a/apps/erp/app/stores/index.ts b/apps/erp/app/stores/index.ts
index 632604e84e..859ce84bda 100644
--- a/apps/erp/app/stores/index.ts
+++ b/apps/erp/app/stores/index.ts
@@ -2,4 +2,5 @@ export * from "./bom";
export * from "./customers";
export * from "./items";
export * from "./people";
+export * from "./pick-list-session";
export * from "./suppliers";
diff --git a/apps/erp/app/stores/pick-list-session.ts b/apps/erp/app/stores/pick-list-session.ts
new file mode 100644
index 0000000000..16a1019b36
--- /dev/null
+++ b/apps/erp/app/stores/pick-list-session.ts
@@ -0,0 +1,87 @@
+import { useStore as useValue } from "@nanostores/react";
+import { atom, computed } from "nanostores";
+import { useNanoStore } from "~/hooks";
+
+export type PickListSessionItem = {
+ id: string;
+ itemReadableId: string;
+ description: string;
+ action: "order" | "transfer";
+ quantity?: number;
+};
+
+export type PickListSessionState = {
+ items: PickListSessionItem[];
+};
+
+const $sessionStore = atom<PickListSessionState>({
+ items: [],
+});
+
+const $sessionItemsCount = computed(
+ $sessionStore,
+ (session) => session.items.length
+);
+
+const $orderItems = computed($sessionStore, (session) =>
+ session.items.filter((item) => item.action === "order")
+);
+
+const $transferItems = computed($sessionStore, (session) =>
+ session.items.filter((item) => item.action === "transfer")
+);
+
+export const usePickListSession = () =>
+ useNanoStore<PickListSessionState>($sessionStore, "session");
+export const usePickListSessionItemsCount = () => useValue($sessionItemsCount);
+export const useOrderItems = () => useValue($orderItems);
+export const useTransferItems = () => useValue($transferItems);
+
+// PickListSession actions
+export const addToPickListSession = (item: PickListSessionItem) => {
+ const currentPickListSession = $sessionStore.get();
+
+ // Check if item already exists with same action
+ const existingItemIndex = currentPickListSession.items.findIndex(
+ (sessionItem) =>
+ sessionItem.id === item.id && sessionItem.action === item.action
+ );
+
+ if (existingItemIndex >= 0) {
+ // Update existing item
+ const updatedItems = [...currentPickListSession.items];
+ updatedItems[existingItemIndex] = {
+ ...updatedItems[existingItemIndex],
+ ...item,
+ };
+ $sessionStore.set({ items: updatedItems });
+ } else {
+ // Add new item
+ $sessionStore.set({ items: [...currentPickListSession.items, item] });
+ }
+};
+
+export const removeFromPickListSession = (
+ itemId: string,
+ action: "order" | "transfer"
+) => {
+ const currentPickListSession = $sessionStore.get();
+ const updatedItems = currentPickListSession.items.filter(
+ (item) => !(item.id === itemId && item.action === action)
+ );
+ $sessionStore.set({ items: updatedItems });
+};
+
+export const clearPickListSession = () => {
+ $sessionStore.set({ items: [] });
+};
+
+export const isInPickListSession = (
+ itemId: string,
+ action: "order" | "transfer"
+) => {
+ const currentPickListSession = $sessionStore.get();
+ return currentPickListSession.items.some(
+ (item) => item.id === itemId && item.action === action
+ );
+};
diff --git a/packages/react/src/SplitButton.tsx b/packages/react/src/SplitButton.tsx
index a69a4e09b8..46dc529b9a 100644
--- a/packages/react/src/SplitButton.tsx
+++ b/packages/react/src/SplitButton.tsx
@@ -21,7 +21,7 @@ interface SplitButtonProps {
isDisabled?: boolean;
onClick?: () => void;
dropdownItems: {
- label: string;
+ label: React.ReactNode;
onClick: () => void;
icon?: React.ReactElement;
}[];