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: update bill of process to include outside operations

Brad Barbin77b687961fac
diff --git a/apps/carbon/app/components/Form/InputControlled.tsx b/apps/carbon/app/components/Form/InputControlled.tsx
index bd1f5401c1..25b703f818 100644
--- a/apps/carbon/app/components/Form/InputControlled.tsx
+++ b/apps/carbon/app/components/Form/InputControlled.tsx
@@ -34,6 +34,7 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
prefix,
suffix,
value,
+ className,
onChange,
...rest
},
@@ -54,7 +55,11 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
};
return (
- <FormControl isInvalid={!!error} isRequired={isRequired}>
+ <FormControl
+ isInvalid={!!error}
+ isRequired={isRequired}
+ className={className}
+ >
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
<InputGroup>
{prefix && <InputLeftAddon children={prefix} />}
diff --git a/apps/carbon/app/modules/items/items.models.ts b/apps/carbon/app/modules/items/items.models.ts
index a888eedad8..e2bcb49181 100644
--- a/apps/carbon/app/modules/items/items.models.ts
+++ b/apps/carbon/app/modules/items/items.models.ts
@@ -4,6 +4,7 @@ import {
methodItemType,
methodOperationOrders,
methodType,
+ operationTypes,
standardFactorType,
} from "../shared";
@@ -206,33 +207,143 @@ export const methodMaterialValidator = z
}
);
-export const methodOperationValidator = z.object({
- id: zfd.text(z.string().optional()),
- makeMethodId: z.string().min(0, { message: "Make method is required" }),
- order: zfd.numeric(z.number().min(0)),
- operationOrder: z.enum(methodOperationOrders, {
- errorMap: (issue, ctx) => ({
- message: "Operation order is required",
+export const methodOperationValidator = z
+ .object({
+ id: zfd.text(z.string().optional()),
+ makeMethodId: z.string().min(0, { message: "Make method is required" }),
+ order: zfd.numeric(z.number().min(0)),
+ operationOrder: z.enum(methodOperationOrders, {
+ errorMap: (issue, ctx) => ({
+ message: "Operation order is required",
+ }),
}),
- }),
- processId: z.string().min(20, { message: "Process is required" }),
- workCenterId: zfd.text(z.string().optional()),
- description: zfd.text(
- z.string().min(0, { message: "Description is required" })
- ),
- setupUnit: z.enum(standardFactorType, {
- errorMap: () => ({ message: "Setup unit is required" }),
- }),
- setupTime: zfd.numeric(z.number().min(0)),
- laborUnit: z.enum(standardFactorType, {
- errorMap: () => ({ message: "Labor unit is required" }),
- }),
- laborTime: zfd.numeric(z.number().min(0)),
- machineUnit: z.enum(standardFactorType, {
- errorMap: () => ({ message: "Machine unit is required" }),
- }),
- machineTime: zfd.numeric(z.number().min(0)),
-});
+ operationType: z.enum(operationTypes, {
+ errorMap: (issue, ctx) => ({
+ message: "Operation type is required",
+ }),
+ }),
+ processId: z.string().min(20, { message: "Process is required" }),
+ workCenterId: zfd.text(z.string().optional()),
+ description: zfd.text(
+ z.string().min(0, { message: "Description is required" })
+ ),
+ setupUnit: z
+ .enum(standardFactorType, {
+ errorMap: () => ({ message: "Setup unit is required" }),
+ })
+ .optional(),
+ setupTime: zfd.numeric(z.number().min(0).optional()),
+ laborUnit: z
+ .enum(standardFactorType, {
+ errorMap: () => ({ message: "Labor unit is required" }),
+ })
+ .optional(),
+ laborTime: zfd.numeric(z.number().min(0).optional()),
+ machineUnit: z
+ .enum(standardFactorType, {
+ errorMap: () => ({ message: "Machine unit is required" }),
+ })
+ .optional(),
+ machineTime: zfd.numeric(z.number().min(0).optional()),
+ operationCost: zfd.numeric(z.number().min(0).optional()),
+ operationLeadTime: zfd.numeric(z.number().min(0).optional()),
+ })
+ .refine(
+ (data) => {
+ if (data.operationType === "Outside") {
+ return Number.isFinite(data.operationCost);
+ }
+ return true;
+ },
+ {
+ message: "Operation cost is required",
+ path: ["operationCost"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Outside") {
+ return Number.isFinite(data.operationLeadTime);
+ }
+ return true;
+ },
+ {
+ message: "Lead time is required",
+ path: ["operationLeadTime"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return !!data.setupUnit;
+ }
+ return true;
+ },
+ {
+ message: "Setup unit is required",
+ path: ["setupUnit"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return !!data.laborUnit;
+ }
+ return true;
+ },
+ {
+ message: "Labor unit is required",
+ path: ["laborUnit"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return !!data.laborUnit;
+ }
+ return true;
+ },
+ {
+ message: "Machine unit is required",
+ path: ["machineUnit"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return Number.isFinite(data.setupTime);
+ }
+ return true;
+ },
+ {
+ message: "Setup time is required",
+ path: ["setupTime"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return Number.isFinite(data.laborTime);
+ }
+ return true;
+ },
+ {
+ message: "Labor time is required",
+ path: ["laborTime"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return Number.isFinite(data.machineTime);
+ }
+ return true;
+ },
+ {
+ message: "Machine time is required",
+ path: ["machineTime"],
+ }
+ );
export const itemCostValidator = z.object({
itemId: z.string().min(1, { message: "Item ID is required" }),
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
index 813a383b4d..c6f9d9f252 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -9,6 +9,7 @@ import {
CardHeader,
CardTitle,
Editor,
+ Enumerable,
HStack,
cn,
generateHTML,
@@ -27,6 +28,7 @@ import { LuSettings2, LuX } from "react-icons/lu";
import type { z } from "zod";
import { DirectionAwareTabs } from "~/components/DirectionAwareTabs";
import {
+ Combobox,
Hidden,
InputControlled,
Number,
@@ -42,7 +44,11 @@ import type { Item, SortableItemRenderProps } from "~/components/SortableList";
import { SortableList, SortableListItem } from "~/components/SortableList";
import { usePermissions, useUser } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
-import { TimeTypeIcon, methodOperationOrders } from "~/modules/shared";
+import {
+ TimeTypeIcon,
+ methodOperationOrders,
+ operationTypes,
+} from "~/modules/shared";
import { path } from "~/utils/path";
import { methodOperationValidator } from "../../items.models";
@@ -73,18 +79,24 @@ function makeItem(operation: Operation): ItemWithData {
order: operation.operationOrder,
details: (
<HStack spacing={1}>
- {operation.laborTime > 0 && (
- <Badge variant="secondary">
- <TimeTypeIcon type="Labor" className="h-3 w-3 mr-1" />
- {operation.laborTime} {operation.laborUnit}
- </Badge>
- )}
+ {operation.operationType === "Outside" ? (
+ <Enumerable value="Outside" />
+ ) : (
+ <>
+ {(operation?.laborTime ?? 0) > 0 && (
+ <Badge variant="secondary">
+ <TimeTypeIcon type="Labor" className="h-3 w-3 mr-1" />
+ {operation.laborTime} {operation.laborUnit}
+ </Badge>
+ )}
- {operation.machineTime > 0 && (
- <Badge variant="secondary">
- <TimeTypeIcon type="Machine" className="h-3 w-3 mr-1" />
- {operation.machineTime} {operation.machineUnit}
- </Badge>
+ {(operation?.machineTime ?? 0) > 0 && (
+ <Badge variant="secondary">
+ <TimeTypeIcon type="Machine" className="h-3 w-3 mr-1" />
+ {operation.machineTime} {operation.machineUnit}
+ </Badge>
+ )}
+ </>
)}
</HStack>
),
@@ -103,6 +115,9 @@ const initialMethodOperation: Omit<Operation, "makeMethodId" | "order"> = {
machineTime: 0,
machineUnit: "Minutes/Piece",
operationOrder: "After Previous",
+ operationType: "Inside",
+ operationCost: 0,
+ operationLeadTime: 0,
methodOperationWorkInstruction: {
content: {},
},
@@ -530,6 +545,7 @@ function OperationForm({
const [processData, setProcessData] = useState<{
processId: string;
+ operationType: string;
description: string;
setupUnitHint: string;
setupUnit: string;
@@ -539,6 +555,7 @@ function OperationForm({
machineUnit: string;
}>({
processId: item.data.processId ?? "",
+ operationType: item.data.operationType ?? "Inside",
description: item.data.description ?? "",
setupUnitHint: getUnitHint(item.data.setupUnit),
setupUnit: item.data.setupUnit ?? "Total Minutes",
@@ -628,6 +645,7 @@ function OperationForm({
onProcessChange(value?.value as string);
}}
/>
+
<Select
name="operationOrder"
label="Operation Order"
@@ -637,102 +655,149 @@ function OperationForm({
label: o,
}))}
/>
- <WorkCenter
- name="workCenterId"
- label="Work Center"
- isOptional
- processId={processData.processId}
+
+ <Select
+ name="operationType"
+ label="Operation Type"
+ placeholder="Operation Type"
+ options={operationTypes.map((o) => ({
+ value: o,
+ label: o,
+ }))}
onChange={(value) => {
- if (value) {
- onWorkCenterChange(value?.value as string);
- }
- }}
- />
- </div>
- <InputControlled
- name="description"
- label="Description"
- value={processData.description}
- onChange={(newValue) => {
- setProcessData((d) => ({ ...d, description: newValue }));
- }}
- />
- <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
- <UnitHint
- name="setupHint"
- label="Setup"
- value={processData.setupUnitHint}
- onChange={(hint) => {
- setProcessData((d) => ({
- ...d,
- setupUnitHint: hint,
- setupUnit: hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
- }));
- }}
- />
- <Number name="setupTime" label="Setup Time" minValue={0} />
- <StandardFactor
- name="setupUnit"
- label="Setup Unit"
- hint={processData.setupUnitHint}
- value={processData.setupUnit}
- onChange={(newValue) => {
- setProcessData((d) => ({
- ...d,
- setupUnit: newValue?.value ?? "Total Minutes",
- }));
- }}
- />
- <UnitHint
- name="laborHint"
- label="Labor"
- value={processData.laborUnitHint}
- onChange={(hint) => {
setProcessData((d) => ({
...d,
- laborUnitHint: hint,
- laborUnit: hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
+
+ setupUnit: "Total Minutes",
+ laborUnit: "Minutes/Piece",
+ machineUnit: "Minutes/Piece",
+ operationType: value?.value as string,
}));
}}
/>
- <Number name="laborTime" label="Labor Time" minValue={0} />
- <StandardFactor
- name="laborUnit"
- label="Labor Unit"
- hint={processData.laborUnitHint}
- value={processData.laborUnit}
+
+ <InputControlled
+ name="description"
+ label="Description"
+ value={processData.description}
onChange={(newValue) => {
- setProcessData((d) => ({
- ...d,
- laborUnit: newValue?.value ?? "Hours/Piece",
- }));
- }}
- />
- <UnitHint
- name="machineHint"
- label="Machine"
- value={processData.machineUnitHint}
- onChange={(hint) => {
- setProcessData((d) => ({
- ...d,
- machineUnitHint: hint,
- machineUnit: hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
- }));
- }}
- />
- <Number name="machineTime" label="Machine Time" minValue={0} />
- <StandardFactor
- name="machineUnit"
- label="Machine Unit"
- hint={processData.machineUnitHint}
- value={processData.machineUnit}
- onChange={(newValue) => {
- setProcessData((d) => ({
- ...d,
- machineUnit: newValue?.value ?? "Hours/Piece",
- }));
+ setProcessData((d) => ({ ...d, description: newValue }));
}}
+ className="col-span-2"
/>
+
+ {processData.operationType === "Outside" ? (
+ <>
+ <Combobox
+ isOptional
+ name="operationSupplierId"
+ label="Supplier"
+ options={[]}
+ />
+ <Number
+ name="operationCost"
+ label="Cost per Unit"
+ minValue={0}
+ formatOptions={{
+ style: "currency",
+ currency: "USD",
+ }}
+ />
+ <Number name="operationLeadTime" label="Lead Time" minValue={0} />
+ </>
+ ) : (
+ <>
+ <WorkCenter
+ name="workCenterId"
+ label="Work Center"
+ isOptional
+ processId={processData.processId}
+ onChange={(value) => {
+ if (value) {
+ onWorkCenterChange(value?.value as string);
+ }
+ }}
+ />
+ <UnitHint
+ name="setupHint"
+ label="Setup"
+ value={processData.setupUnitHint}
+ onChange={(hint) => {
+ setProcessData((d) => ({
+ ...d,
+ setupUnitHint: hint,
+ setupUnit:
+ hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
+ }));
+ }}
+ />
+ <Number name="setupTime" label="Setup Time" minValue={0} />
+ <StandardFactor
+ name="setupUnit"
+ label="Setup Unit"
+ hint={processData.setupUnitHint}
+ value={processData.setupUnit}
+ onChange={(newValue) => {
+ setProcessData((d) => ({
+ ...d,
+ setupUnit: newValue?.value ?? "Total Minutes",
+ }));
+ }}
+ />
+ <UnitHint
+ name="laborHint"
+ label="Labor"
+ value={processData.laborUnitHint}
+ onChange={(hint) => {
+ setProcessData((d) => ({
+ ...d,
+ laborUnitHint: hint,
+ laborUnit:
+ hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
+ }));
+ }}
+ />
+ <Number name="laborTime" label="Labor Time" minValue={0} />
+ <StandardFactor
+ name="laborUnit"
+ label="Labor Unit"
+ hint={processData.laborUnitHint}
+ value={processData.laborUnit}
+ onChange={(newValue) => {
+ setProcessData((d) => ({
+ ...d,
+ laborUnit: newValue?.value ?? "Hours/Piece",
+ }));
+ }}
+ />
+ <UnitHint
+ name="machineHint"
+ label="Machine"
+ value={processData.machineUnitHint}
+ onChange={(hint) => {
+ setProcessData((d) => ({
+ ...d,
+ machineUnitHint: hint,
+ machineUnit:
+ hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
+ }));
+ }}
+ />
+ <Number name="machineTime" label="Machine Time" minValue={0} />
+ <StandardFactor
+ name="machineUnit"
+ label="Machine Unit"
+ hint={processData.machineUnitHint}
+ value={processData.machineUnit}
+ onChange={(newValue) => {
+ setProcessData((d) => ({
+ ...d,
+ machineUnit: newValue?.value ?? "Hours/Piece",
+ }));
+ }}
+ />
+ </>
+ )}
</div>
<motion.div
className="flex w-full items-center justify-end p-2"
diff --git a/apps/carbon/app/modules/shared/shared.models.ts b/apps/carbon/app/modules/shared/shared.models.ts
index 7889a9c2da..32537d2966 100644
--- a/apps/carbon/app/modules/shared/shared.models.ts
+++ b/apps/carbon/app/modules/shared/shared.models.ts
@@ -15,14 +15,6 @@ export const methodOperationOrders = [
"With Previous",
] as const;
-export const methodType = ["Buy", "Make", "Pick"] as const;
-
-export const noteValidator = z.object({
- id: zfd.text(z.string().optional()),
- documentId: z.string().min(1),
- note: z.string().min(1, { message: "Note is required" }),
-});
-
export const months = [
"January",
"February",
@@ -37,3 +29,13 @@ export const months = [
"November",
"December",
] as const;
+
+export const methodType = ["Buy", "Make", "Pick"] as const;
+
+export const noteValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ documentId: z.string().min(1),
+ note: z.string().min(1, { message: "Note is required" }),
+});
+
+export const operationTypes = ["Inside", "Outside"] as const;
diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx
index ac9f720432..fcc0da1e2c 100644
--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx
@@ -86,7 +86,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
methodOperations:
methodOperations.data?.map((operation) => ({
...operation,
- equipmentTypeId: operation.equipmentTypeId ?? undefined,
+ workCenterId: operation.workCenterId ?? undefined,
methodOperationWorkInstruction:
operation.methodOperationWorkInstruction as {
content: JSONContent | null;