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 scrap reason and notes to the ProductionQuantitiesTable

Rob Carrington9fa25e55770b
diff --git a/apps/carbon/app/modules/production/production.models.ts b/apps/carbon/app/modules/production/production.models.ts
index 61399aa1b4..57811e61ee 100644
--- a/apps/carbon/app/modules/production/production.models.ts
+++ b/apps/carbon/app/modules/production/production.models.ts
@@ -422,6 +422,8 @@ export const productionQuantityValidator = z.object({
type: z.enum(["Rework", "Scrap", "Production"], {
errorMap: () => ({ message: "Quantity type is required" }),
}),
+ scrapReasonId: zfd.text(z.string().optional()),
+ notes: zfd.text(z.string().optional()),
createdBy: zfd.text(z.string().optional()),
quantity: zfd.numeric(z.number().min(0)),
});
diff --git a/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx b/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx
index f4d1ffef2a..ad470287d6 100644
--- a/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx
+++ b/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx
@@ -9,16 +9,22 @@ import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import { usePeople } from "~/stores";
import { path } from "~/utils/path";
-import type { ProductionQuantity } from "../../types";
+import type { ProductionQuantity, ScrapReason } from "../../types";
type ProductionQuantitiesTableProps = {
data: ProductionQuantity[];
count: number;
operations: { id: string; description: string | null }[];
+ scrapReasons: ScrapReason[];
};
const ProductionQuantitiesTable = memo(
- ({ data, count, operations }: ProductionQuantitiesTableProps) => {
+ ({
+ data,
+ count,
+ operations,
+ scrapReasons,
+ }: ProductionQuantitiesTableProps) => {
const { jobId } = useParams();
if (!jobId) throw new Error("Job ID is required");
const [people] = usePeople();
@@ -109,8 +115,36 @@ const ProductionQuantitiesTable = memo(
header: "Quantity",
cell: ({ row }) => row.original.quantity,
},
+ {
+ accessorKey: "scrapReasonId",
+ header: "Scrap Reason",
+ cell: ({ row }) => {
+ const scrapReason = scrapReasons.find(
+ (reason) => reason.id === row.original.scrapReasonId
+ );
+ return <Enumerable value={scrapReason?.name ?? ""} />;
+ },
+ meta: {
+ filter: {
+ type: "static",
+ options: scrapReasons?.map((reason) => ({
+ value: reason.id,
+ label: <Enumerable value={reason.name ?? ""} />,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "notes",
+ header: "Notes",
+ cell: ({ row }) => (
+ <span className="max-w-[200px] truncate block">
+ {row.original.notes}
+ </span>
+ ),
+ },
];
- }, [operations, people]);
+ }, [operations, people, scrapReasons]);
const permissions = usePermissions();
diff --git a/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx b/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx
index a1fc834607..ef6d06ee6e 100644
--- a/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx
+++ b/apps/carbon/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx
@@ -12,6 +12,7 @@ import {
} from "@carbon/react";
import { useNavigate } from "@remix-run/react";
+import { useState } from "react";
import type { z } from "zod";
import {
Employee,
@@ -36,6 +37,10 @@ const ProductionQuantityForm = ({
const navigate = useNavigate();
const onClose = () => navigate(-1);
+ const [type, setType] = useState<"Production" | "Scrap" | "Rework">(
+ initialValues.type
+ );
+
const isDisabled = !permissions.can("update", "production");
return (
<Drawer
@@ -68,9 +73,16 @@ const ProductionQuantityForm = ({
{ label: "Scrap", value: "Scrap" },
{ label: "Rework", value: "Rework" },
]}
+ onChange={(value) =>
+ setType(value?.value as "Production" | "Scrap" | "Rework")
+ }
/>
- <ScrapReason name="scrapReasonId" label="Scrap Reason" />
- <TextArea name="notes" label="Notes" />
+ {type === "Scrap" && (
+ <>
+ <ScrapReason name="scrapReasonId" label="Scrap Reason" />
+ <TextArea name="notes" label="Notes" />
+ </>
+ )}
</VStack>
</DrawerBody>
<DrawerFooter>
diff --git a/apps/carbon/app/routes/x+/job+/$jobId.quantities.$id.tsx b/apps/carbon/app/routes/x+/job+/$jobId.quantities.$id.tsx
index f49c760569..5880b28f40 100644
--- a/apps/carbon/app/routes/x+/job+/$jobId.quantities.$id.tsx
+++ b/apps/carbon/app/routes/x+/job+/$jobId.quantities.$id.tsx
@@ -50,6 +50,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { id, ...data } = validation.data;
if (!id) throw new Error("id not found");
+ // If the type is not Scrap, set the scrapReasonId and notes to null
+ if (data.type !== "Scrap") {
+ data.scrapReasonId = undefined;
+ data.notes = undefined;
+ }
+
const update = await updateProductionQuantity(client, {
id,
...data,
diff --git a/apps/carbon/app/routes/x+/job+/$jobId.quantities.tsx b/apps/carbon/app/routes/x+/job+/$jobId.quantities.tsx
index 676b9e0daa..4300b86bce 100644
--- a/apps/carbon/app/routes/x+/job+/$jobId.quantities.tsx
+++ b/apps/carbon/app/routes/x+/job+/$jobId.quantities.tsx
@@ -8,9 +8,9 @@ import { json, redirect } from "@vercel/remix";
import {
getJobOperationsList,
getProductionQuantities,
+ getScrapReasons,
ProductionQuantitiesTable,
} from "~/modules/production";
-import { getWorkCentersList } from "~/modules/resources";
import { path, requestReferrer } from "~/utils/path";
import { getGenericQueryFilters } from "~/utils/query";
@@ -44,10 +44,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
count: 0,
events: [],
operations: [],
+ scrapReasons: [],
});
}
- const [events] = await Promise.all([
+ const [events, scrapReasons] = await Promise.all([
getProductionQuantities(client, operations.data?.map((o) => o.id) ?? [], {
search,
limit,
@@ -55,7 +56,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
sorts,
filters,
}),
- getWorkCentersList(client, companyId),
+ getScrapReasons(client, companyId),
]);
if (events.error) {
@@ -69,11 +70,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
count: events.count ?? 0,
events: events.data ?? [],
operations: operations.data ?? [],
+ scrapReasons: scrapReasons.data ?? [],
});
}
export default function ProductionQuantitiesRoute() {
- const { count, events, operations } = useLoaderData<typeof loader>();
+ const { count, events, operations, scrapReasons } =
+ useLoaderData<typeof loader>();
return (
<>
@@ -82,6 +85,7 @@ export default function ProductionQuantitiesRoute() {
data={events}
count={count}
operations={operations}
+ scrapReasons={scrapReasons}
/>
</VStack>
<Outlet />