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 the ability to manufacture a tool

Brad Barbindce14cc80a4d
diff --git a/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx
index a3860dd009..3ca922dd4b 100644
--- a/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx
@@ -222,6 +222,8 @@ function getRootLink(itemType: MethodItemType, itemId: string) {
return path.to.partMakeMethod(itemId);
case "Fixture":
return path.to.fixtureMakeMethod(itemId);
+ case "Tool":
+ return path.to.toolMakeMethod(itemId);
default:
throw new Error(`Unimplemented BoMExplorer itemType: ${itemType}`);
}
@@ -246,6 +248,12 @@ function getMaterialLink(
makeMethodId,
materialId
);
+ case "Tool":
+ return path.to.toolManufacturingMaterial(
+ itemId,
+ makeMethodId,
+ materialId
+ );
default:
throw new Error(`Unimplemented BoMExplorer itemType: ${itemType}`);
}
diff --git a/apps/carbon/app/modules/items/ui/Methods/utils.ts b/apps/carbon/app/modules/items/ui/Methods/utils.ts
index d84fa4de5b..de3da9e986 100644
--- a/apps/carbon/app/modules/items/ui/Methods/utils.ts
+++ b/apps/carbon/app/modules/items/ui/Methods/utils.ts
@@ -6,6 +6,8 @@ export function getPathToMakeMethod(type: string, id: string) {
return path.to.partMakeMethod(id);
case "Fixture":
return path.to.fixtureMakeMethod(id);
+ case "Tool":
+ return path.to.toolMakeMethod(id);
default:
return "#";
}
diff --git a/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx b/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx
index 8a502f88d0..8377d4d7ff 100644
--- a/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx
+++ b/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx
@@ -29,7 +29,11 @@ import {
UnitOfMeasure,
} from "~/components/Form";
import { useNextItemId, usePermissions, useUser } from "~/hooks";
-import { itemTrackingTypes, toolValidator } from "~/modules/items";
+import {
+ itemReplenishmentSystems,
+ itemTrackingTypes,
+ toolValidator,
+} from "~/modules/items";
import { path } from "~/utils/path";
type ToolFormProps = {
@@ -69,9 +73,17 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {
value: itemTrackingType,
})) ?? [];
+ const [replenishmentSystem, setReplenishmentSystem] = useState<string>(
+ initialValues.replenishmentSystem ?? "Buy"
+ );
const [defaultMethodType, setDefaultMethodType] = useState<string>(
initialValues.defaultMethodType ?? "Buy"
);
+ const itemReplenishmentSystemOptions =
+ itemReplenishmentSystems.map((itemReplenishmentSystem) => ({
+ label: itemReplenishmentSystem,
+ value: itemReplenishmentSystem,
+ })) ?? [];
return (
<ModalCardProvider type={type}>
@@ -97,7 +109,6 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {
</ModalCardHeader>
<ModalCardBody>
<Hidden name="type" value={type} />
- <Hidden name="replenishmentSystem" value="Buy" />
<div
className={cn(
"grid w-full gap-x-8 gap-y-4",
@@ -134,11 +145,23 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {
{isEditing && (
<TextArea name="description" label="Long Description" />
)}
-
+ <Select
+ name="replenishmentSystem"
+ label="Replenishment System"
+ options={itemReplenishmentSystemOptions}
+ onChange={(newValue) => {
+ setReplenishmentSystem(newValue?.value ?? "Buy");
+ if (newValue?.value === "Buy") {
+ setDefaultMethodType("Buy");
+ } else {
+ setDefaultMethodType("Make");
+ }
+ }}
+ />
<DefaultMethodType
name="defaultMethodType"
label="Default Method Type"
- replenishmentSystem="Buy"
+ replenishmentSystem={replenishmentSystem}
value={defaultMethodType}
onChange={(newValue) =>
setDefaultMethodType(newValue?.value ?? "Buy")
diff --git a/apps/carbon/app/modules/items/ui/Tools/ToolsTable.tsx b/apps/carbon/app/modules/items/ui/Tools/ToolsTable.tsx
index bf9f846936..89eb099a35 100644
--- a/apps/carbon/app/modules/items/ui/Tools/ToolsTable.tsx
+++ b/apps/carbon/app/modules/items/ui/Tools/ToolsTable.tsx
@@ -28,6 +28,7 @@ import {
LuCalendar,
LuCheck,
LuPencil,
+ LuRefreshCw,
LuTag,
LuTrash,
LuUser,
@@ -43,11 +44,12 @@ import {
Table,
TrackingTypeIcon,
} from "~/components";
+import { Enumerable } from "~/components/Enumerable";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import type { Tool } from "~/modules/items";
-import { itemTrackingTypes } from "~/modules/items";
+import { itemReplenishmentSystems, itemTrackingTypes } from "~/modules/items";
import { methodType } from "~/modules/shared";
import type { action } from "~/routes/x+/items+/update";
import { usePeople } from "~/stores";
@@ -132,6 +134,7 @@ const ToolsTable = memo(({ data, tags, count }: ToolsTableProps) => {
icon: <TbTargetArrow />,
},
},
+
{
accessorKey: "defaultMethodType",
header: "Default Method",
@@ -157,6 +160,21 @@ const ToolsTable = memo(({ data, tags, count }: ToolsTableProps) => {
icon: <RxCodesandboxLogo />,
},
},
+ {
+ accessorKey: "replenishmentSystem",
+ header: "Replenishment",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: itemReplenishmentSystems.map((type) => ({
+ value: type,
+ label: <Enumerable value={type} />,
+ })),
+ },
+ icon: <LuRefreshCw />,
+ },
+ },
{
accessorKey: "tags",
header: "Tags",
diff --git a/apps/carbon/app/modules/items/ui/Tools/useToolNavigation.tsx b/apps/carbon/app/modules/items/ui/Tools/useToolNavigation.tsx
index 2dd4016fe7..bbb0477967 100644
--- a/apps/carbon/app/modules/items/ui/Tools/useToolNavigation.tsx
+++ b/apps/carbon/app/modules/items/ui/Tools/useToolNavigation.tsx
@@ -1,5 +1,6 @@
import { useParams } from "@remix-run/react";
+import { BiListCheck } from "react-icons/bi";
import { LuBox, LuFileText, LuShoppingCart, LuTags } from "react-icons/lu";
import { usePermissions, useRouteData } from "~/hooks";
import type { Role } from "~/types";
@@ -11,12 +12,15 @@ export function useToolNavigation() {
const { itemId } = useParams();
if (!itemId) throw new Error("itemId not found");
- const routeData = useRouteData<{ toolSummary: ToolSummary }>(
- path.to.tool(itemId)
- );
+ const routeData = useRouteData<{
+ toolSummary: ToolSummary;
+ }>(path.to.tool(itemId));
+ if (!routeData?.toolSummary?.replenishmentSystem)
+ throw new Error("Could not find replenishmentSystem in routeData");
if (!routeData?.toolSummary?.itemTrackingType)
throw new Error("Could not find itemTrackingType in routeData");
+ const replenishment = routeData.toolSummary.replenishmentSystem;
const itemTrackingType = routeData.toolSummary.itemTrackingType;
return [
@@ -29,10 +33,19 @@ export function useToolNavigation() {
{
name: "Purchasing",
to: path.to.toolPurchasing(itemId),
+ isDisabled: replenishment === "Make",
role: ["employee", "supplier"],
icon: LuShoppingCart,
shortcut: "Command+Shift+p",
},
+ {
+ name: "Manufacturing",
+ to: path.to.toolManufacturing(itemId),
+ isDisabled: replenishment === "Buy",
+ role: ["employee"],
+ icon: BiListCheck,
+ shortcut: "Command+Shift+m",
+ },
{
name: "Costing",
to: path.to.toolCosting(itemId),
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.costing.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.costing.tsx
index 80ea653554..985f695164 100644
--- a/apps/carbon/app/routes/x+/tool+/$itemId.costing.tsx
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.costing.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import { VStack } from "@carbon/react";
import { useLoaderData } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -88,13 +89,15 @@ export async function action({ request, params }: ActionFunctionArgs) {
export default function ToolCostingRoute() {
const { itemCost } = useLoaderData<typeof loader>();
return (
- <ItemCostingForm
- key={itemCost.itemId}
- initialValues={{
- ...itemCost,
- // itemPostingGroupId: itemCost?.itemPostingGroupId ?? undefined,
- ...getCustomFields(itemCost.customFields),
- }}
- />
+ <VStack spacing={2} className="p-2">
+ <ItemCostingForm
+ key={itemCost.itemId}
+ initialValues={{
+ ...itemCost,
+ // itemPostingGroupId: itemCost?.itemPostingGroupId ?? undefined,
+ ...getCustomFields(itemCost.customFields),
+ }}
+ />
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.details.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.details.tsx
index 6c533f5c79..421bba5031 100644
--- a/apps/carbon/app/routes/x+/tool+/$itemId.details.tsx
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.details.tsx
@@ -80,7 +80,7 @@ export default function ToolDetailsRoute() {
};
return (
- <VStack spacing={2} className="w-full h-full">
+ <VStack spacing={2} className="w-full h-full p-2">
<ToolForm
key={JSON.stringify(toolInitialValues)}
initialValues={toolInitialValues}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.inventory.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.inventory.tsx
index bc7a42f2c8..ef38a414e3 100644
--- a/apps/carbon/app/routes/x+/tool+/$itemId.inventory.tsx
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.inventory.tsx
@@ -199,7 +199,7 @@ export default function ToolInventoryRoute() {
...getCustomFields(toolInventory.customFields ?? {}),
};
return (
- <VStack spacing={2}>
+ <VStack spacing={2} className="p-2">
<PickMethodForm
key={initialValues.itemId}
initialValues={initialValues}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.$makeMethodId.$materialId.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.$makeMethodId.$materialId.tsx
new file mode 100644
index 0000000000..a782f9a7b2
--- /dev/null
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.$makeMethodId.$materialId.tsx
@@ -0,0 +1,128 @@
+import type { JSONContent } from "@carbon/react";
+import { VStack } from "@carbon/react";
+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+
+import { error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import {
+ BillOfMaterial,
+ BillOfProcess,
+ ItemForm,
+ MakeMethodTools,
+ getItem,
+ getMethodMaterial,
+ getMethodMaterialsByMakeMethod,
+ getMethodOperationsByMakeMethodId,
+} from "~/modules/items";
+import type { MethodItemType, MethodType } from "~/modules/shared";
+import { path } from "~/utils/path";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "parts",
+ });
+
+ const { itemId, materialId, makeMethodId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+ if (!materialId) throw new Error("Could not find materialId");
+ if (!makeMethodId) throw new Error("Could not find makeMethodId");
+
+ const [material, methodMaterials, methodOperations] = await Promise.all([
+ getMethodMaterial(client, materialId),
+ getMethodMaterialsByMakeMethod(client, makeMethodId),
+ getMethodOperationsByMakeMethodId(client, makeMethodId),
+ ]);
+
+ if (material.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(request, error(material.error, "Failed to load material"))
+ );
+ }
+
+ if (methodOperations.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(
+ request,
+ error(methodOperations.error, "Failed to load method operations")
+ )
+ );
+ }
+ if (methodMaterials.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(
+ request,
+ error(methodMaterials.error, "Failed to load method materials")
+ )
+ );
+ }
+
+ const item = await getItem(client, material.data.itemId);
+ if (item.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(request, error(item.error, "Failed to load item"))
+ );
+ }
+
+ return json({
+ item: {
+ ...item.data,
+ defaultMethodType: item.data.defaultMethodType ?? "Buy",
+ unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",
+ description: item.data.description ?? "",
+ },
+ material: material.data,
+ methodMaterials:
+ methodMaterials.data?.map((m) => ({
+ ...m,
+ description: m.item?.name ?? "",
+ methodType: m.methodType as MethodType,
+ itemType: m.itemType as MethodItemType,
+ methodOperationId: m.methodOperationId ?? undefined,
+ })) ?? [],
+ methodOperations:
+ methodOperations.data?.map((operation) => ({
+ ...operation,
+ workCenterId: operation.workCenterId ?? undefined,
+ operationSupplierProcessId:
+ operation.operationSupplierProcessId ?? undefined,
+ workInstruction: operation.workInstruction as JSONContent | null,
+ })) ?? [],
+ });
+}
+
+export default function MethodMaterialMakePage() {
+ const loaderData = useLoaderData<typeof loader>();
+ const { item, methodMaterials, methodOperations } = loaderData;
+
+ const { itemId, makeMethodId, materialId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+ if (!makeMethodId) throw new Error("Could not find makeMethodId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <MakeMethodTools itemId={item.id} type="Tool" />
+ <ItemForm
+ key={`item:${itemId}:${makeMethodId}:${materialId}`}
+ type={item.type}
+ initialValues={item}
+ />
+ <BillOfProcess
+ key={`bop:${itemId}:${methodOperations.length}`}
+ makeMethodId={makeMethodId}
+ operations={methodOperations}
+ />
+ <BillOfMaterial
+ key={`bom:${itemId}:${methodMaterials.length}`}
+ makeMethodId={makeMethodId}
+ materials={methodMaterials}
+ operations={methodOperations}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing._index.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing._index.tsx
new file mode 100644
index 0000000000..e5b8ac19cb
--- /dev/null
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing._index.tsx
@@ -0,0 +1,10 @@
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { redirect } from "@vercel/remix";
+import { path } from "~/utils/path";
+
+export async function loader({ params }: LoaderFunctionArgs) {
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ throw redirect(path.to.toolMakeMethod(itemId));
+}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.buy.$materialId.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.buy.$materialId.tsx
new file mode 100644
index 0000000000..dda2f92a5e
--- /dev/null
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.buy.$materialId.tsx
@@ -0,0 +1,62 @@
+import { VStack } from "@carbon/react";
+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+
+import { error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { ItemForm, getItem, getMethodMaterial } from "~/modules/items";
+import { path } from "~/utils/path";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "parts",
+ });
+
+ const { itemId, materialId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ const [material] = await Promise.all([getMethodMaterial(client, materialId)]);
+
+ if (material.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(request, error(material.error, "Failed to load material"))
+ );
+ }
+
+ const item = await getItem(client, material.data.itemId);
+ if (item.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(request, error(item.error, "Failed to load item"))
+ );
+ }
+
+ return json({
+ item: {
+ ...item.data,
+ defaultMethodType: item.data.defaultMethodType ?? "Buy",
+ unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",
+ description: item.data.description ?? "",
+ },
+ material: material.data,
+ });
+}
+
+export default function MethodMaterialBuyPage() {
+ const { item } = useLoaderData<typeof loader>();
+ const { itemId, materialId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <ItemForm
+ key={`item:${itemId}:${materialId}`}
+ type={item.type}
+ initialValues={item}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.method.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.method.tsx
new file mode 100644
index 0000000000..03b93b1ba7
--- /dev/null
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.method.tsx
@@ -0,0 +1,45 @@
+import { VStack } from "@carbon/react";
+import { useParams } from "@remix-run/react";
+import { useRouteData } from "~/hooks";
+
+import type { MakeMethod, Material, MethodOperation } from "~/modules/items";
+import {
+ BillOfMaterial,
+ BillOfProcess,
+ MakeMethodTools,
+} from "~/modules/items";
+import { path } from "~/utils/path";
+
+export default function MakeMethodRoute() {
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const manufacturingRouteData = useRouteData<{
+ makeMethod: MakeMethod;
+ methodMaterials: Material[];
+ methodOperations: MethodOperation[];
+ }>(path.to.toolManufacturing(itemId));
+
+ const makeMethodId = manufacturingRouteData?.makeMethod?.id;
+ if (!makeMethodId) throw new Error("Could not find makeMethodId");
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <MakeMethodTools itemId={itemId} type="Tool" />
+ <BillOfProcess
+ key={`bop:${itemId}:${manufacturingRouteData?.methodOperations?.length}`}
+ makeMethodId={makeMethodId}
+ // @ts-ignore
+ operations={manufacturingRouteData?.methodOperations ?? []}
+ />
+ <BillOfMaterial
+ key={`bom:${itemId}:${manufacturingRouteData?.methodMaterials?.length}`}
+ makeMethodId={makeMethodId}
+ // @ts-ignore
+ materials={manufacturingRouteData?.methodMaterials ?? []}
+ // @ts-ignore
+ operations={manufacturingRouteData?.methodOperations}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.pick.$materialId.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.pick.$materialId.tsx
new file mode 100644
index 0000000000..538361bee5
--- /dev/null
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.pick.$materialId.tsx
@@ -0,0 +1,62 @@
+import { VStack } from "@carbon/react";
+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+
+import { error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { ItemForm, getItem, getMethodMaterial } from "~/modules/items";
+import { path } from "~/utils/path";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "parts",
+ });
+
+ const { itemId, materialId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ const [material] = await Promise.all([getMethodMaterial(client, materialId)]);
+
+ if (material.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(request, error(material.error, "Failed to load material"))
+ );
+ }
+
+ const item = await getItem(client, material.data.itemId);
+ if (item.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(request, error(item.error, "Failed to load item"))
+ );
+ }
+
+ return json({
+ item: {
+ ...item.data,
+ defaultMethodType: item.data.defaultMethodType ?? "Buy",
+ unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",
+ description: item.data.description ?? "",
+ },
+ material: material.data,
+ });
+}
+
+export default function MethodMaterialPickPage() {
+ const { item } = useLoaderData<typeof loader>();
+ const { itemId, materialId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <ItemForm
+ key={`item:${itemId}:${materialId}`}
+ type={item.type}
+ initialValues={item}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.tsx
new file mode 100644
index 0000000000..84b5edc3ea
--- /dev/null
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.manufacturing.tsx
@@ -0,0 +1,153 @@
+import type { JSONContent } from "@carbon/react";
+import {
+ ClientOnly,
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ScrollArea,
+} from "@carbon/react";
+import {
+ Outlet,
+ json,
+ redirect,
+ useLoaderData,
+ useParams,
+} from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+
+import { error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type { FlatTreeItem } from "~/components/TreeView";
+import { flattenTree } from "~/components/TreeView";
+import type { Method } from "~/modules/items";
+import {
+ BoMExplorer,
+ getMakeMethod,
+ getMethodMaterialsByMakeMethod,
+ getMethodOperationsByMakeMethodId,
+ getMethodTree,
+} from "~/modules/items";
+import type { MethodItemType, MethodType } from "~/modules/shared";
+import { path } from "~/utils/path";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const makeMethod = await getMakeMethod(client, itemId, companyId);
+
+ if (makeMethod.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(
+ request,
+ error(makeMethod.error, "Failed to load make method")
+ )
+ );
+ }
+
+ const [methodTree, methodMaterials, methodOperations] = await Promise.all([
+ getMethodTree(client, makeMethod.data.id),
+ getMethodMaterialsByMakeMethod(client, makeMethod.data.id),
+ getMethodOperationsByMakeMethodId(client, makeMethod.data.id),
+ ]);
+ if (methodTree?.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(
+ request,
+ error(methodTree.error, "Failed to load method tree")
+ )
+ );
+ }
+
+ if (methodOperations.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(
+ request,
+ error(methodOperations.error, "Failed to load method operations")
+ )
+ );
+ }
+ if (methodMaterials.error) {
+ throw redirect(
+ path.to.toolDetails(itemId),
+ await flash(
+ request,
+ error(methodMaterials.error, "Failed to load method materials")
+ )
+ );
+ }
+
+ return json({
+ makeMethod: makeMethod.data,
+ methodMaterials:
+ methodMaterials.data?.map((m) => ({
+ ...m,
+ description: m.item?.name ?? "",
+ methodType: m.methodType as MethodType,
+ itemType: m.itemType as MethodItemType,
+ })) ?? [],
+ methodOperations:
+ methodOperations.data?.map((operation) => ({
+ ...operation,
+ workCenterId: operation.workCenterId ?? undefined,
+ workInstruction: operation.workInstruction as JSONContent,
+ })) ?? [],
+ methods: (methodTree.data.length > 0
+ ? flattenTree(methodTree.data[0])
+ : []) satisfies FlatTreeItem<Method>[],
+ });
+}
+
+export default function ToolManufacturing() {
+ const { methods } = useLoaderData<typeof loader>();
+
+ const params = useParams();
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ return (
+ <div className="flex flex-grow overflow-hidden">
+ <ClientOnly fallback={null}>
+ {() => (
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card"
+ >
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <div className="grid h-full overflow-hidden p-2">
+ <BoMExplorer
+ itemType="Tool"
+ // @ts-ignore
+ methods={methods}
+ />
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel
+ order={2}
+ minSize={40}
+ defaultSize={60}
+ className="border-t border-border"
+ >
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <Outlet key={JSON.stringify(params)} />
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ )}
+ </ClientOnly>
+ </div>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.planning.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.planning.tsx
index 2aeeaace84..7f8bda744d 100644
--- a/apps/carbon/app/routes/x+/tool+/$itemId.planning.tsx
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.planning.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import { VStack } from "@carbon/react";
import { useLoaderData } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -149,14 +150,16 @@ export default function ToolPlanningRoute() {
if (!sharedToolsData) throw new Error("Could not load shared tools data");
return (
- <ItemPlanningForm
- key={toolPlanning.itemId}
- initialValues={{
- ...toolPlanning,
- ...getCustomFields(toolPlanning.customFields),
- }}
- locations={sharedToolsData.locations ?? []}
- type="Tool"
- />
+ <VStack spacing={2} className="p-2">
+ <ItemPlanningForm
+ key={toolPlanning.itemId}
+ initialValues={{
+ ...toolPlanning,
+ ...getCustomFields(toolPlanning.customFields),
+ }}
+ locations={sharedToolsData.locations ?? []}
+ type="Tool"
+ />
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.purchasing.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.purchasing.tsx
index 40a9ef4a94..5ac7a360d4 100644
--- a/apps/carbon/app/routes/x+/tool+/$itemId.purchasing.tsx
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.purchasing.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import { VStack } from "@carbon/react";
import { useLoaderData, useParams } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -103,7 +104,7 @@ export default function ToolPurchasingRoute() {
};
return (
- <>
+ <VStack spacing={2} className="p-2">
<ItemPurchasingForm
key={initialValues.itemId}
initialValues={initialValues}
@@ -112,6 +113,6 @@ export default function ToolPurchasingRoute() {
}
/>
<BuyMethods buyMethods={buyMethods} />
- </>
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/x+/tool+/$itemId.tsx b/apps/carbon/app/routes/x+/tool+/$itemId.tsx
index 43cbd30f86..8954ad50d6 100644
--- a/apps/carbon/app/routes/x+/tool+/$itemId.tsx
+++ b/apps/carbon/app/routes/x+/tool+/$itemId.tsx
@@ -1,7 +1,6 @@
import { error, getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { VStack } from "@carbon/react";
import { Outlet } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
@@ -62,12 +61,8 @@ export default function ToolRoute() {
return (
<div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<ToolHeader />
- <div className="flex h-[calc(100dvh-99px)] w-full">
- <div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
- <VStack spacing={2} className="p-2 w-full h-full">
- <Outlet />
- </VStack>
- </div>
+ <div className="flex h-[calc(100dvh-99px)] w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
+ <Outlet />
<ToolProperties />
</div>
</div>
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 65c0618649..e88b72c02b 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -820,6 +820,19 @@ export const path = {
toolInventory: (id: string) => generatePath(`${x}/tool/${id}/inventory`),
toolInventoryLocation: (id: string, locationId: string) =>
generatePath(`${x}/tool/${id}/inventory?location=${locationId}`),
+ toolMakeMethod: (id: string) =>
+ generatePath(`${x}/tool/${id}/manufacturing/method`),
+ toolManufacturing: (id: string) =>
+ generatePath(`${x}/tool/${id}/manufacturing`),
+ toolManufacturingMaterial: (
+ itemId: string,
+ makeMethodId: string,
+ methodMaterialId: string
+ ) =>
+ generatePath(
+ `${x}/tool/${itemId}/manufacturing/${makeMethodId}/${methodMaterialId}`
+ ),
+
toolPlanning: (id: string) => generatePath(`${x}/tool/${id}/planning`),
toolPlanningLocation: (id: string, locationId: string) =>
generatePath(`${x}/tool/${id}/planning?location=${locationId}`),
diff --git a/packages/database/supabase/migrations/20241122132608_manufacturable-tool.sql b/packages/database/supabase/migrations/20241122132608_manufacturable-tool.sql
new file mode 100644
index 0000000000..871f51717c
--- /dev/null
+++ b/packages/database/supabase/migrations/20241122132608_manufacturable-tool.sql
@@ -0,0 +1,3 @@
+CREATE TRIGGER create_tool_make_method_related_records
+ AFTER INSERT on public.tool
+ FOR EACH ROW EXECUTE PROCEDURE public.create_make_method_related_records();
\ No newline at end of file