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 tracking modal to mes

Brad Barbin4e87a7e42b0d
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
index df9d3e704e..cf0accdfa7 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
@@ -57,7 +57,7 @@ import { path } from "~/utils/path";
import type { methodOperationValidator } from "../../items.models";
import { methodMaterialValidator } from "../../items.models";
import type { ConfigurationParameter, ConfigurationRule } from "../../types";
-import { Database } from "@carbon/database";
+import type { Database } from "@carbon/database";
type Material = z.infer<typeof methodMaterialValidator> & {
description: string;
@@ -830,15 +830,6 @@ function makeItem(
checked,
details: (
<HStack spacing={2}>
- <Tooltip>
- <TooltipTrigger>
- <Badge variant="secondary">
- <MethodIcon type={material.methodType} />
- </Badge>
- </TooltipTrigger>
- <TooltipContent>{material.methodType}</TooltipContent>
- </Tooltip>
-
{["Batch", "Serial"].includes(material.item.itemTrackingType) && (
<Tooltip>
<TooltipTrigger>
@@ -852,6 +843,15 @@ function makeItem(
</Tooltip>
)}
+ <Tooltip>
+ <TooltipTrigger>
+ <Badge variant="secondary">
+ <MethodIcon type={material.methodType} />
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>{material.methodType}</TooltipContent>
+ </Tooltip>
+
<Badge variant="secondary">{material.quantity}</Badge>
<Tooltip>
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
index b9f9f6761a..596848ec8f 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
@@ -111,14 +111,6 @@ function makeItem(
checked: checked,
details: (
<HStack spacing={2}>
- <Tooltip>
- <TooltipTrigger>
- <Badge variant="secondary">
- <MethodIcon type={material.methodType} />
- </Badge>
- </TooltipTrigger>
- <TooltipContent>{material.methodType}</TooltipContent>
- </Tooltip>
{material.requiresBatchTracking ? (
<Tooltip>
<TooltipTrigger>
@@ -138,6 +130,15 @@ function makeItem(
<TooltipContent>Serial Tracking</TooltipContent>
</Tooltip>
) : null}
+
+ <Tooltip>
+ <TooltipTrigger>
+ <Badge variant="secondary">
+ <MethodIcon type={material.methodType} />
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>{material.methodType}</TooltipContent>
+ </Tooltip>
<Badge variant="secondary">{material.quantity}</Badge>
<Tooltip>
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index 213ad80834..5f22970c7b 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -47,7 +47,7 @@ import { path } from "~/utils/path";
import type { quoteOperationValidator } from "../../sales.models";
import { quoteMaterialValidator } from "../../sales.models";
import type { Quotation } from "../../types";
-import { Database } from "@carbon/database";
+import type { Database } from "@carbon/database";
type Material = z.infer<typeof quoteMaterialValidator> & {
item: {
@@ -114,15 +114,6 @@ function makeItem(
checked: checked,
details: (
<HStack spacing={2}>
- <Tooltip>
- <TooltipTrigger>
- <Badge variant="secondary">
- <MethodIcon type={material.methodType} />
- </Badge>
- </TooltipTrigger>
- <TooltipContent>{material.methodType}</TooltipContent>
- </Tooltip>
-
{["Batch", "Serial"].includes(material.item.itemTrackingType) && (
<Tooltip>
<TooltipTrigger>
@@ -136,6 +127,15 @@ function makeItem(
</Tooltip>
)}
+ <Tooltip>
+ <TooltipTrigger>
+ <Badge variant="secondary">
+ <MethodIcon type={material.methodType} />
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>{material.methodType}</TooltipContent>
+ </Tooltip>
+
<Badge variant="secondary">{material.quantity}</Badge>
<Tooltip>
diff --git a/apps/mes/app/components/Icons.tsx b/apps/mes/app/components/Icons.tsx
index 5eaada219a..4e1f45beab 100644
--- a/apps/mes/app/components/Icons.tsx
+++ b/apps/mes/app/components/Icons.tsx
@@ -3,9 +3,11 @@ import { AiOutlinePartition } from "react-icons/ai";
import { FaCodePullRequest } from "react-icons/fa6";
import {
LuAtom,
+ LuBarcode,
LuCircleCheck,
LuCircleX,
LuClock,
+ LuGroup,
LuFlaskConical,
LuHammer,
LuHeadphones,
@@ -17,6 +19,7 @@ import {
LuSquare,
LuToggleLeft,
LuUser,
+ LuBox,
} from "react-icons/lu";
import {
@@ -32,6 +35,7 @@ import {
BsFileZipFill,
} from "react-icons/bs";
import { RxCodesandboxLogo } from "react-icons/rx";
+import { TbTargetOff } from "react-icons/tb";
import { AlmostDoneIcon } from "~/assets/icons/AlmostDoneIcon";
import { HighPriorityIcon } from "~/assets/icons/HighPriorityIcon";
import { InProgressStatusIcon } from "~/assets/icons/InProgressStatusIcon";
@@ -40,7 +44,7 @@ import { MediumPriorityIcon } from "~/assets/icons/MediumPriorityIcon";
import { TodoStatusIcon } from "~/assets/icons/TodoStatusIcon";
import type { documentTypes } from "~/services/models";
import type { Operation } from "~/services/types";
-import { Database } from "../../../../packages/database/src/types";
+import type { Database } from "../../../../packages/database/src/types";
type FileIconProps = {
type: (typeof documentTypes)[number];
@@ -225,3 +229,24 @@ export const ProcedureAttributeTypeIcon = ({
return <LuImage className={cn("text-indigo-500", className)} />;
}
};
+
+export const TrackingTypeIcon = ({
+ type,
+ className,
+}: {
+ type: string;
+ className?: string;
+}) => {
+ switch (type) {
+ case "Serial":
+ return <LuBarcode className={cn("text-foreground", className)} />;
+ case "Batch":
+ return <LuGroup className={cn("text-emerald-500", className)} />;
+ case "Inventory":
+ return <LuBox className={cn("text-blue-500", className)} />;
+ case "Non-Inventory":
+ return <TbTargetOff className={cn("text-red-500", className)} />;
+ default:
+ return <LuSquare className={cn("text-muted-foreground", className)} />;
+ }
+};
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 7c5e8ddf01..772875f8b7 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -149,6 +149,7 @@ import {
LuHammer,
LuHardHat,
LuPaperclip,
+ LuQrCode,
LuSend,
LuTimer,
LuTrash,
@@ -156,8 +157,8 @@ import {
} from "react-icons/lu";
import {
MethodIcon,
- MethodItemTypeIcon,
ProcedureAttributeTypeIcon,
+ TrackingTypeIcon,
} from "~/components/Icons";
import { getFileType } from "~/services/operations.service";
import { useItems, usePeople } from "~/stores";
@@ -220,6 +221,7 @@ export const JobOperation = ({
setEventType,
setSelectedMaterial,
setupProductionEvent,
+ trackingModal,
} = useOperation(originalOperation, events, isModalOpen);
const controlsHeight = useMemo(() => {
@@ -531,11 +533,10 @@ export const JobOperation = ({
)}
>
<Td>
- <HStack spacing={2}>
- <MethodItemTypeIcon
- type={material.itemType}
- className="size-4"
- />
+ <HStack
+ spacing={2}
+ className="justify-between"
+ >
<VStack spacing={0}>
<span className="font-semibold">
{material.itemReadableId}
@@ -544,6 +545,22 @@ export const JobOperation = ({
{material.description}
</span>
</VStack>
+ {material.requiresBatchTracking ? (
+ <Badge variant="secondary">
+ <TrackingTypeIcon
+ type="Batch"
+ className="shrink-0"
+ />
+ </Badge>
+ ) : null}
+ {material.requiresSerialTracking ? (
+ <Badge variant="secondary">
+ <TrackingTypeIcon
+ type="Serial"
+ className="shrink-0"
+ />
+ </Badge>
+ ) : null}
</HStack>
</Td>
<Td className="lg:table-cell hidden">
@@ -565,17 +582,35 @@ export const JobOperation = ({
)}
</Td>
<Td className="text-right">
- {material.methodType !== "Make" && (
+ {material.methodType !== "Make" &&
+ material.requiresBatchTracking === false &&
+ material.requiresSerialTracking ===
+ false && (
+ <IconButton
+ aria-label="Issue Material"
+ variant="ghost"
+ icon={<LuGitBranchPlus />}
+ className="h-8 w-8"
+ onClick={() => {
+ flushSync(() => {
+ setSelectedMaterial(material);
+ });
+ issueModal.onOpen();
+ }}
+ />
+ )}
+ {(material.requiresBatchTracking ||
+ material.requiresSerialTracking) && (
<IconButton
aria-label="Issue Material"
variant="ghost"
- icon={<LuGitBranchPlus />}
+ icon={<LuQrCode />}
className="h-8 w-8"
onClick={() => {
flushSync(() => {
setSelectedMaterial(material);
});
- issueModal.onOpen();
+ trackingModal.onOpen();
}}
/>
)}
@@ -1240,6 +1275,13 @@ export const JobOperation = ({
</Await>
</Suspense>
)}
+ {trackingModal.isOpen && (
+ <TrackingModal
+ operationId={operation.id}
+ material={selectedMaterial ?? undefined}
+ onClose={trackingModal.onClose}
+ />
+ )}
{issueModal.isOpen && (
<IssueModal
operationId={operation.id}
@@ -1504,7 +1546,7 @@ function useOperation(
const completeModal = useDisclosure();
const finishModal = useDisclosure();
const issueModal = useDisclosure();
-
+ const trackingModal = useDisclosure();
// we do this to avoid re-rendering when the modal is open
const isAnyModalOpen =
pauseInterval ||
@@ -1723,6 +1765,7 @@ function useOperation(
completeModal,
finishModal,
issueModal,
+ trackingModal,
isOverdue: operation.jobDueDate
? new Date(operation.jobDueDate) < new Date()
: false,
@@ -2303,6 +2346,26 @@ function QuantityModal({
);
}
+function TrackingModal({
+ operationId,
+ material,
+ onClose,
+}: {
+ operationId: string;
+ material?: JobMaterial;
+ onClose: () => void;
+}) {
+ return (
+ <Modal open onOpenChange={onClose}>
+ <ModalContent>
+ <ModalHeader>
+ <ModalTitle>Tracking</ModalTitle>
+ </ModalHeader>
+ </ModalContent>
+ </Modal>
+ );
+}
+
function IssueModal({
operationId,
material,
@@ -2340,19 +2403,21 @@ function IssueModal({
materialId: material?.id,
jobOperationId: operationId,
itemId: material?.itemId,
- quantity: 1,
- adjustmentType: "Positive Adjmt.",
+ quantity:
+ (material?.estimatedQuantity ?? 0) -
+ (material?.quantityIssued ?? 0),
+ adjustmentType: "Negative Adjmt.",
}}
>
<ModalBody>
<Hidden name="jobOperationId" />
<Hidden name="materialId" />
- {!material?.id && (
- <Hidden name="adjustmentType" value="Set Quantity" />
+ {material?.id && (
+ <Hidden name="adjustmentType" value="Negative Adjmt." />
)}
<VStack spacing={4}>
<Combobox name="itemId" label="Item" options={itemOptions} />
- {material?.id && (
+ {!material?.id && (
<Select
name="adjustmentType"
label="Adjustment Type"