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 view for all job operation step records

Brad Barbin5d453dada179
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 5196645b1c..4e666c9e91 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -8,7 +8,7 @@ import {
type PostgrestError,
type SupabaseClient,
} from "@supabase/supabase-js";
-import type { z } from 'zod/v3';
+import type { z } from "zod/v3";
import type { StorageItem } from "~/types";
import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
@@ -938,6 +938,18 @@ export async function getJobOperationsByMethodId(
.order("order", { ascending: true });
}
+export async function getJobOperationStepRecords(
+ client: SupabaseClient<Database>,
+ jobId: string,
+ args: GenericQueryFilters
+) {
+ let query = client.rpc("get_job_operation_step_records", {
+ p_job_id: jobId,
+ });
+
+ return query;
+}
+
export async function getOutsideOperationsByJobId(
client: SupabaseClient<Database>,
jobId: string,
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
index b5b1dba106..557996c496 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -49,6 +49,7 @@ import {
LuCirclePlay,
LuCircleStop,
LuClock,
+ LuClipboardList,
LuEllipsisVertical,
LuHardHat,
LuList,
@@ -99,6 +100,8 @@ const JobHeader = () => {
return "materials";
if (location.pathname.includes(path.to.jobOperations(jobId)))
return "operations";
+ if (location.pathname.includes(path.to.jobOperationStepRecords(jobId)))
+ return "step-records";
if (location.pathname.includes(path.to.jobProductionEvents(jobId)))
return "events";
if (location.pathname.includes(path.to.jobProductionQuantities(jobId)))
@@ -216,7 +219,7 @@ const JobHeader = () => {
</DropdownMenuRadioItem>
))}
<DropdownMenuSeparator />
- {["events", "quantities"].map((i) => (
+ {["events", "quantities", "step-records"].map((i) => (
<DropdownMenuRadioItem value={i} key={i}>
<DropdownMenuIcon icon={getExplorerMenuIcon(i)} />
{getExplorerLabel(i)}
@@ -410,6 +413,8 @@ function getExplorerLabel(type: string) {
return "Materials";
case "operations":
return "Operations";
+ case "step-records":
+ return "Step Records";
case "events":
return "Production Events";
case "quantities":
@@ -425,6 +430,8 @@ function getExplorerMenuIcon(type: string) {
return <LuPackage />;
case "operations":
return <LuSettings />;
+ case "step-records":
+ return <LuClipboardList />;
case "events":
return <LuClock />;
case "quantities":
@@ -440,6 +447,8 @@ const getExplorePath = (jobId: string, type: string) => {
return path.to.jobMaterials(jobId);
case "operations":
return path.to.jobOperations(jobId);
+ case "step-records":
+ return path.to.jobOperationStepRecords(jobId);
case "events":
return path.to.jobProductionEvents(jobId);
case "quantities":
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobOperationStepRecordsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobOperationStepRecordsTable.tsx
new file mode 100644
index 0000000000..dfff846ed3
--- /dev/null
+++ b/apps/erp/app/modules/production/ui/Jobs/JobOperationStepRecordsTable.tsx
@@ -0,0 +1,234 @@
+import type { Database } from "@carbon/database";
+import { Checkbox, cn } from "@carbon/react";
+import { formatDateTime } from "@carbon/utils";
+import { useNumberFormatter } from "@react-aria/i18n";
+import { useParams } from "@remix-run/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { memo, useMemo } from "react";
+import {
+ LuCalendar,
+ LuClipboardList,
+ LuFileText,
+ LuList,
+ LuPaperclip,
+ LuSettings,
+ LuUser,
+} from "react-icons/lu";
+import { EmployeeAvatar, Table } from "~/components";
+import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";
+import { ProcedureStepTypeIcon } from "~/components/Icons";
+import { procedureStepType } from "~/modules/shared/shared.models";
+import { usePeople } from "~/stores";
+import { getPrivateUrl } from "~/utils/path";
+
+type JobOperationStepRecord = {
+ id: string;
+ jobOperationStepId: string;
+ index: number;
+ type: Database["public"]["Enums"]["procedureStepType"];
+ name: string;
+ value: string | null;
+ numericValue: number | null;
+ booleanValue: boolean | null;
+ userValue: string | null;
+ unitOfMeasureCode: string | null;
+ minValue: number | null;
+ maxValue: number | null;
+ operationId: string;
+ operationDescription: string | null;
+ operationOrder: number | null;
+ itemId: string | null;
+ itemReadableId: string | null;
+ companyId: string;
+ createdAt: string;
+ createdBy: string;
+ updatedAt: string | null;
+ updatedBy: string | null;
+};
+
+type JobOperationStepRecordsTableProps = {
+ data: JobOperationStepRecord[];
+ count: number;
+};
+
+const JobOperationStepRecordsTable = memo(
+ ({ data, count }: JobOperationStepRecordsTableProps) => {
+ const { jobId } = useParams();
+ if (!jobId) throw new Error("Job ID is required");
+
+ const numberFormatter = useNumberFormatter();
+ const unitOfMeasures = useUnitOfMeasure();
+ const [employees] = usePeople();
+
+ const columns = useMemo<ColumnDef<JobOperationStepRecord>[]>(() => {
+ return [
+ {
+ accessorKey: "operationDescription",
+ header: "Operation",
+ cell: ({ row }) => row.original.operationDescription,
+ meta: {
+ icon: <LuSettings />,
+ },
+ },
+ {
+ accessorKey: "name",
+ header: "Step",
+ cell: ({ row }) => row.original.name,
+ meta: {
+ icon: <LuClipboardList />,
+ },
+ },
+ {
+ id: "value",
+ header: "Value",
+ cell: ({ row }) => {
+ const record = row.original;
+
+ switch (record.type) {
+ case "Task":
+ case "Checkbox":
+ return <Checkbox checked={record.booleanValue ?? false} />;
+ case "Value":
+ return <p className="text-sm">{record.value}</p>;
+ case "Measurement":
+ if (typeof record.numericValue === "number") {
+ return (
+ <p
+ className={cn(
+ "text-sm",
+ record.minValue !== null &&
+ record.minValue !== undefined &&
+ record.numericValue < record.minValue &&
+ "text-red-500",
+ record.maxValue !== null &&
+ record.maxValue !== undefined &&
+ record.numericValue > record.maxValue &&
+ "text-red-500"
+ )}
+ >
+ {numberFormatter.format(record.numericValue)}{" "}
+ {
+ unitOfMeasures.find(
+ (u) => u.value === record.unitOfMeasureCode
+ )?.label
+ }
+ </p>
+ );
+ }
+ return null;
+ case "Timestamp":
+ return (
+ <p className="text-sm">
+ {formatDateTime(record.value ?? "")}
+ </p>
+ );
+ case "List":
+ return <p className="text-sm">{record.value}</p>;
+ case "Person":
+ return (
+ <p className="text-sm">
+ {employees.find((e) => e.id === record.userValue)?.name}
+ </p>
+ );
+ case "File":
+ if (record.value) {
+ return (
+ <div className="flex gap-2 text-xs">
+ <LuPaperclip className="size-4 text-muted-foreground" />
+ <a
+ href={getPrivateUrl(record.value)}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ View File
+ </a>
+ </div>
+ );
+ }
+ return null;
+ case "Inspection":
+ return (
+ <div className="flex gap-2 items-center text-sm">
+ {record.value && (
+ <>
+ <LuPaperclip className="size-4 text-muted-foreground" />
+ <a
+ href={getPrivateUrl(record.value)}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-xs"
+ >
+ View File
+ </a>
+ </>
+ )}
+ <Checkbox checked={record.booleanValue ?? false} />
+ </div>
+ );
+ default:
+ return null;
+ }
+ },
+ meta: {
+ icon: <LuFileText />,
+ },
+ },
+ {
+ id: "type",
+ header: "Type",
+ cell: ({ row }) => (
+ <div className="flex items-center gap-2">
+ <ProcedureStepTypeIcon type={row.original.type} />
+ {row.original.type}
+ </div>
+ ),
+ meta: {
+ icon: <LuList />,
+ filter: {
+ type: "static",
+ options: procedureStepType.map((type) => ({
+ value: type,
+ label: <ProcedureStepTypeIcon type={type} />,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "createdBy",
+ header: "Created By",
+ cell: ({ row }) => (
+ <EmployeeAvatar
+ employeeId={row.original.createdBy}
+ withName={true}
+ />
+ ),
+ meta: {
+ icon: <LuUser />,
+ },
+ },
+ {
+ accessorKey: "createdAt",
+ header: "Created At",
+ cell: ({ row }) => formatDateTime(row.original.createdAt ?? ""),
+ meta: {
+ icon: <LuCalendar />,
+ },
+ },
+ ];
+ }, [numberFormatter, unitOfMeasures, employees]);
+
+ return (
+ <Table<JobOperationStepRecord>
+ compact
+ count={count}
+ columns={columns}
+ data={data}
+ title="Step Records"
+ />
+ );
+ }
+);
+
+JobOperationStepRecordsTable.displayName = "JobOperationStepRecordsTable";
+
+export default JobOperationStepRecordsTable;
diff --git a/apps/erp/app/modules/production/ui/Jobs/index.ts b/apps/erp/app/modules/production/ui/Jobs/index.ts
index e4a4359b20..d627711dca 100644
--- a/apps/erp/app/modules/production/ui/Jobs/index.ts
+++ b/apps/erp/app/modules/production/ui/Jobs/index.ts
@@ -10,6 +10,7 @@ import JobMaterialForm from "./JobMaterialForm";
import JobMaterialsTable from "./JobMaterialsTable";
import JobNotes from "./JobNotes";
import JobOperationsTable from "./JobOperationsTable";
+import JobOperationStepRecordsTable from "./JobOperationStepRecordsTable";
import JobProperties from "./JobProperties";
import JobsTable from "./JobsTable";
import JobStatus from "./JobStatus";
@@ -31,6 +32,7 @@ export {
JobMaterialsTable,
JobNotes,
JobOperationsTable,
+ JobOperationStepRecordsTable,
JobProperties,
JobsTable,
JobStatus,
diff --git a/apps/erp/app/routes/x+/job+/$jobId.steps.tsx b/apps/erp/app/routes/x+/job+/$jobId.steps.tsx
new file mode 100644
index 0000000000..ab8a7689fd
--- /dev/null
+++ b/apps/erp/app/routes/x+/job+/$jobId.steps.tsx
@@ -0,0 +1,69 @@
+import { error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { useMount, VStack } from "@carbon/react";
+import { useLoaderData } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
+import { usePanels } from "~/components/Layout";
+import { getJobOperationStepRecords } from "~/modules/production";
+import { JobOperationStepRecordsTable } from "~/modules/production/ui/Jobs";
+
+import { path } from "~/utils/path";
+import { getGenericQueryFilters } from "~/utils/query";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "production",
+ role: "employee",
+ });
+
+ const { jobId } = params;
+ if (!jobId) throw new Error("Could not find jobId");
+
+ const url = new URL(request.url);
+ const searchParams = new URLSearchParams(url.search);
+
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
+
+ const stepRecords = await getJobOperationStepRecords(client, jobId, {
+ limit,
+ offset,
+ sorts,
+ filters,
+ });
+
+ if (stepRecords.error) {
+ redirect(
+ path.to.production,
+ await flash(
+ request,
+ error(stepRecords.error, "Failed to fetch job operation step records")
+ )
+ );
+ }
+
+ return json({
+ count: stepRecords.count ?? 0,
+ stepRecords: stepRecords.data ?? [],
+ });
+}
+
+export default function JobOperationStepRecordsRoute() {
+ const { count, stepRecords } = useLoaderData<typeof loader>();
+
+ const { setIsExplorerCollapsed } = usePanels();
+
+ console.log({ stepRecords });
+
+ useMount(() => {
+ setIsExplorerCollapsed(true);
+ });
+
+ return (
+ <VStack spacing={0} className="h-[calc(100dvh-99px)]">
+ <JobOperationStepRecordsTable data={stepRecords} count={count} />
+ </VStack>
+ );
+}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index a1a20d8e71..d699bbcd49 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -799,6 +799,8 @@ export const path = {
jobOperationTool: (id: string) =>
generatePath(`${x}/job/methods/operation/tool/${id}`),
jobOperationStatus: `${x}/job/methods/operation/status`,
+ jobOperationStepRecords: (id: string) =>
+ generatePath(`${x}/job/${id}/steps`),
jobProductionEvent: (jobId: string, eventId: string) =>
generatePath(`${x}/job/${jobId}/events/${eventId}`),
jobProductionEvents: (id: string) => generatePath(`${x}/job/${id}/events`),
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 864c961e7e..61bd1f2cc8 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -49562,6 +49562,33 @@ export type Database = {
workInstruction: Json
}[]
}
+ get_job_operation_step_records: {
+ Args: { p_job_id: string }
+ Returns: {
+ booleanValue: boolean
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ index: number
+ itemId: string
+ itemReadableId: string
+ jobOperationStepId: string
+ maxValue: number
+ minValue: number
+ name: string
+ numericValue: number
+ operationDescription: string
+ operationId: string
+ operationOrder: number
+ type: Database["public"]["Enums"]["procedureStepType"]
+ unitOfMeasureCode: string
+ updatedAt: string
+ updatedBy: string
+ userValue: string
+ value: string
+ }[]
+ }
get_job_operations_by_work_center: {
Args: { location_id: string; work_center_id: string }
Returns: {
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 864c961e7e..61bd1f2cc8 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -49562,6 +49562,33 @@ export type Database = {
workInstruction: Json
}[]
}
+ get_job_operation_step_records: {
+ Args: { p_job_id: string }
+ Returns: {
+ booleanValue: boolean
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ index: number
+ itemId: string
+ itemReadableId: string
+ jobOperationStepId: string
+ maxValue: number
+ minValue: number
+ name: string
+ numericValue: number
+ operationDescription: string
+ operationId: string
+ operationOrder: number
+ type: Database["public"]["Enums"]["procedureStepType"]
+ unitOfMeasureCode: string
+ updatedAt: string
+ updatedBy: string
+ userValue: string
+ value: string
+ }[]
+ }
get_job_operations_by_work_center: {
Args: { location_id: string; work_center_id: string }
Returns: {
diff --git a/packages/database/supabase/migrations/20251117015159_job-operation-steps.sql b/packages/database/supabase/migrations/20251117015159_job-operation-steps.sql
new file mode 100644
index 0000000000..746e5805ff
--- /dev/null
+++ b/packages/database/supabase/migrations/20251117015159_job-operation-steps.sql
@@ -0,0 +1,93 @@
+-- Function to get all jobOperationStepRecords for a given job
+DROP FUNCTION IF EXISTS get_job_operation_step_records;
+CREATE OR REPLACE FUNCTION get_job_operation_step_records(p_job_id TEXT)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobOperationStepId" TEXT,
+ "index" INTEGER,
+ "type" "procedureStepType",
+ "name" TEXT,
+ "value" TEXT,
+ "numericValue" NUMERIC,
+ "booleanValue" BOOLEAN,
+ "userValue" TEXT,
+ "unitOfMeasureCode" TEXT,
+ "minValue" NUMERIC,
+ "maxValue" NUMERIC,
+ "operationId" TEXT,
+ "operationDescription" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "companyId" TEXT,
+ "createdAt" TIMESTAMP WITH TIME ZONE,
+ "createdBy" TEXT,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+ "updatedBy" TEXT
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH job_operations AS (
+ -- Get all job operations for the given job
+ SELECT
+ jo."id",
+ jo."description",
+ jo."order",
+ jo."jobMakeMethodId"
+ FROM "jobOperation" jo
+ WHERE jo."jobId" = p_job_id
+ ),
+ job_operation_steps AS (
+ -- Get all job operation steps for those operations
+ SELECT
+ jos."id",
+ jos."type",
+ jos."name",
+ jos."unitOfMeasureCode",
+ jos."minValue",
+ jos."maxValue",
+ jos."operationId",
+ jo."description" as "operationDescription",
+ jo."jobMakeMethodId"
+ FROM "jobOperationStep" jos
+ INNER JOIN job_operations jo ON jos."operationId" = jo."id"
+ ),
+ job_items AS (
+ -- Get item info from jobMakeMethod
+ SELECT
+ jmm."id" as "makeMethodId",
+ i."id" as "itemId",
+ i."readableIdWithRevision" as "itemReadableId"
+ FROM "jobMakeMethod" jmm
+ LEFT JOIN "item" i ON jmm."parentMaterialId" = i."id"
+ )
+ -- Get all job operation step records for those steps
+ SELECT
+ josr."id",
+ josr."jobOperationStepId",
+ josr."index",
+ jos."type",
+ jos."name",
+ josr."value",
+ josr."numericValue",
+ josr."booleanValue",
+ josr."userValue",
+ jos."unitOfMeasureCode",
+ jos."minValue",
+ jos."maxValue",
+ jos."operationId",
+ jos."operationDescription",
+ ji."itemId",
+ ji."itemReadableId",
+ josr."companyId",
+ josr."createdAt",
+ josr."createdBy",
+ josr."updatedAt",
+ josr."updatedBy"
+ FROM "jobOperationStepRecord" josr
+ INNER JOIN job_operation_steps jos ON josr."jobOperationStepId" = jos."id"
+ LEFT JOIN job_items ji ON jos."jobMakeMethodId" = ji."makeMethodId"
+ ORDER BY josr."jobOperationStepId", josr."index";
+END;
+$$ LANGUAGE plpgsql;