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: material finishes crud

Brad Barbin87bb04f4e97b
diff --git a/apps/erp/app/modules/items/items.models.ts b/apps/erp/app/modules/items/items.models.ts
index 6ad03493e1..29b7e2c345 100644
--- a/apps/erp/app/modules/items/items.models.ts
+++ b/apps/erp/app/modules/items/items.models.ts
@@ -484,6 +484,12 @@ export const itemUnitSalePriceValidator = z.object({
allowInvoiceDiscount: zfd.checkbox(),
});
+export const materialFinishValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ materialSubstanceId: z.string().min(1, { message: "Substance is required" }),
+ name: z.string().min(1, { message: "Name is required" }).max(255),
+});
+
export const materialFormValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }).max(255),
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index c7fc610889..c0dc66014b 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -28,6 +28,7 @@ import type {
itemUnitSalePriceValidator,
itemValidator,
makeMethodVersionValidator,
+ materialFinishValidator,
materialFormValidator,
materialGradeValidator,
materialSubstanceValidator,
@@ -225,6 +226,13 @@ export async function deleteItemPostingGroup(
return client.from("itemPostingGroup").delete().eq("id", id);
}
+export async function deleteMaterialFinish(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("materialFinish").delete().eq("id", id);
+}
+
export async function deleteMaterialForm(
client: SupabaseClient<Database>,
id: string
@@ -804,6 +812,39 @@ export async function getMaterialsList(
return query.order("name");
}
+export async function getMaterialFinish(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("materialFinish").select("*").eq("id", id).single();
+}
+
+export async function getMaterialFinishes(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args?: GenericQueryFilters & { search: string | null }
+) {
+ let query = client
+ .from("materialFinishes")
+ .select("*", {
+ count: "exact",
+ })
+ .or(`companyId.eq.${companyId},companyId.is.null`);
+
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
+ }
+
+ if (args) {
+ query = setGenericQueryFilters(query, args, [
+ { column: "substanceName", ascending: true },
+ { column: "name", ascending: true },
+ ]);
+ }
+
+ return query;
+}
+
export async function getMaterialForm(
client: SupabaseClient<Database>,
id: string
@@ -2485,6 +2526,34 @@ export async function upsertMaterial(
return updateMaterial;
}
+export async function upsertMaterialFinish(
+ client: SupabaseClient<Database>,
+ materialFinish:
+ | (Omit<z.infer<typeof materialFinishValidator>, "id"> & {
+ companyId: string;
+ })
+ | (Omit<z.infer<typeof materialFinishValidator>, "id"> & {
+ id: string;
+ })
+) {
+ if ("id" in materialFinish) {
+ return (
+ client
+ .from("materialFinish")
+ .update(sanitize(materialFinish))
+ // @ts-ignore
+ .eq("id", materialFinish.id)
+ .select("id")
+ .single()
+ );
+ }
+ return client
+ .from("materialFinish")
+ .insert([materialFinish])
+ .select("*")
+ .single();
+}
+
export async function upsertMaterialForm(
client: SupabaseClient<Database>,
materialForm:
diff --git a/apps/erp/app/modules/items/types.ts b/apps/erp/app/modules/items/types.ts
index e54f0e976c..d02f57c33a 100644
--- a/apps/erp/app/modules/items/types.ts
+++ b/apps/erp/app/modules/items/types.ts
@@ -14,6 +14,7 @@ import type {
getItemShelfQuantities,
getMakeMethods,
getMaterial,
+ getMaterialFinishes,
getMaterialForms,
getMaterialGrades,
getMaterialSubstances,
@@ -107,6 +108,10 @@ export type Material = NonNullable<
Awaited<ReturnType<typeof getMaterials>>["data"]
>[number];
+export type MaterialFinish = NonNullable<
+ Awaited<ReturnType<typeof getMaterialFinishes>>["data"]
+>[number];
+
export type MaterialGrade = NonNullable<
Awaited<ReturnType<typeof getMaterialGrades>>["data"]
>[number];
diff --git a/apps/erp/app/modules/items/ui/MaterialFinishes/MaterialFinishForm.tsx b/apps/erp/app/modules/items/ui/MaterialFinishes/MaterialFinishForm.tsx
new file mode 100644
index 0000000000..b4fc4ccc64
--- /dev/null
+++ b/apps/erp/app/modules/items/ui/MaterialFinishes/MaterialFinishForm.tsx
@@ -0,0 +1,108 @@
+import { ValidatedForm } from "@carbon/form";
+import {
+ Button,
+ HStack,
+ ModalDrawer,
+ ModalDrawerBody,
+ ModalDrawerContent,
+ ModalDrawerFooter,
+ ModalDrawerHeader,
+ ModalDrawerProvider,
+ ModalDrawerTitle,
+ VStack,
+ toast,
+} from "@carbon/react";
+import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
+import type { z } from "zod";
+import { Hidden, Input, Submit } from "~/components/Form";
+import Substance from "~/components/Form/Substance";
+import { usePermissions } from "~/hooks";
+import { path } from "~/utils/path";
+import { materialFinishValidator } from "../../items.models";
+
+type MaterialFinishFormProps = {
+ initialValues: z.infer<typeof materialFinishValidator>;
+ type?: "modal" | "drawer";
+ open?: boolean;
+ onClose: (data?: { id: string; name: string }) => void;
+};
+
+const MaterialFinishForm = ({
+ initialValues,
+ open = true,
+ type = "drawer",
+ onClose,
+}: MaterialFinishFormProps) => {
+ const permissions = usePermissions();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string; name: string }>>();
+
+ const isEditing = initialValues.id !== undefined;
+ const isDisabled = isEditing
+ ? !permissions.can("update", "parts")
+ : !permissions.can("create", "parts");
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created material form`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create material form: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
+
+ return (
+ <ModalDrawerProvider type={type}>
+ <ModalDrawer
+ open={open}
+ onOpenChange={(open) => {
+ if (!open) onClose?.();
+ }}
+ >
+ <ModalDrawerContent>
+ <ValidatedForm
+ validator={materialFinishValidator}
+ method="post"
+ action={
+ isEditing
+ ? path.to.materialFinish(initialValues.id!)
+ : path.to.newMaterialFinish
+ }
+ defaultValues={initialValues}
+ fetcher={fetcher}
+ className="flex flex-col h-full"
+ >
+ <ModalDrawerHeader>
+ <ModalDrawerTitle>
+ {isEditing ? "Edit" : "New"} Material Finish
+ </ModalDrawerTitle>
+ </ModalDrawerHeader>
+ <ModalDrawerBody>
+ <Hidden name="id" />
+ <Hidden name="type" value={type} />
+ <VStack spacing={4}>
+ <Substance name="materialSubstanceId" label="Substance" />
+ <Input name="name" label="Name" />
+ </VStack>
+ </ModalDrawerBody>
+ <ModalDrawerFooter>
+ <HStack>
+ <Submit isDisabled={isDisabled}>Save</Submit>
+ <Button size="md" variant="solid" onClick={() => onClose()}>
+ Cancel
+ </Button>
+ </HStack>
+ </ModalDrawerFooter>
+ </ValidatedForm>
+ </ModalDrawerContent>
+ </ModalDrawer>
+ </ModalDrawerProvider>
+ );
+};
+
+export default MaterialFinishForm;
diff --git a/apps/erp/app/modules/items/ui/MaterialFinishes/MaterialFinishesTable.tsx b/apps/erp/app/modules/items/ui/MaterialFinishes/MaterialFinishesTable.tsx
new file mode 100644
index 0000000000..98ae2e187b
--- /dev/null
+++ b/apps/erp/app/modules/items/ui/MaterialFinishes/MaterialFinishesTable.tsx
@@ -0,0 +1,148 @@
+import { Badge, MenuIcon, MenuItem } from "@carbon/react";
+import { useNavigate } from "@remix-run/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { memo, useCallback, useMemo } from "react";
+import {
+ LuCircleCheck,
+ LuDessert,
+ LuGlassWater,
+ LuPencil,
+ LuTrash,
+} from "react-icons/lu";
+import { Hyperlink, New, Table } from "~/components";
+import { Enumerable } from "~/components/Enumerable";
+import { useSubstance } from "~/components/Form/Substance";
+import { usePermissions, useUrlParams } from "~/hooks";
+import { path } from "~/utils/path";
+import type { MaterialFinish } from "../../types";
+
+type MaterialFinishesTableProps = {
+ data: MaterialFinish[];
+ count: number;
+};
+
+const MaterialFinishesTable = memo(
+ ({ data, count }: MaterialFinishesTableProps) => {
+ const [params] = useUrlParams();
+ const navigate = useNavigate();
+ const permissions = usePermissions();
+ const substances = useSubstance();
+
+ const rows = useMemo(() => data, [data]);
+
+ const columns = useMemo<ColumnDef<(typeof rows)[number]>[]>(() => {
+ const defaultColumns: ColumnDef<(typeof rows)[number]>[] = [
+ {
+ accessorKey: "substanceName",
+ header: "Substance",
+ cell: ({ row }) => <Enumerable value={row.original.substanceName} />,
+ meta: {
+ icon: <LuGlassWater />,
+ filter: {
+ type: "static",
+ options: substances.map((substance) => ({
+ label: <Enumerable value={substance.label} />,
+ value: substance.label,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "name",
+ header: "Finish",
+ cell: ({ row }) =>
+ row.original.companyId === null ? (
+ <Enumerable value={row.original.name} />
+ ) : (
+ <Hyperlink
+ to={`${path.to.materialFinish(
+ row.original.id!
+ )}?${params.toString()}`}
+ >
+ <Enumerable value={row.original.name} />
+ </Hyperlink>
+ ),
+ meta: {
+ icon: <LuDessert />,
+ },
+ },
+
+ {
+ accessorKey: "companyId",
+ header: "Standard",
+ cell: ({ row }) => {
+ return row.original.companyId === null ? (
+ <Badge variant="outline">Standard</Badge>
+ ) : (
+ <Badge variant="blue">Custom</Badge>
+ );
+ },
+ meta: {
+ icon: <LuCircleCheck />,
+ },
+ },
+ ];
+ return [...defaultColumns];
+ }, [params, substances]);
+
+ const renderContextMenu = useCallback(
+ (row: (typeof rows)[number]) => {
+ return (
+ <>
+ <MenuItem
+ disabled={
+ !permissions.can("update", "parts") || row.companyId === null
+ }
+ onClick={() => {
+ navigate(
+ `${path.to.materialFinish(row.id!)}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuPencil />} />
+ Edit Material Finish
+ </MenuItem>
+ <MenuItem
+ disabled={
+ !permissions.can("delete", "parts") || row.companyId === null
+ }
+ destructive
+ onClick={() => {
+ navigate(
+ `${path.to.deleteMaterialFinish(
+ row.id!
+ )}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuTrash />} />
+ Delete Material Finish
+ </MenuItem>
+ </>
+ );
+ },
+ [navigate, params, permissions]
+ );
+
+ return (
+ <Table<(typeof rows)[number]>
+ data={data}
+ columns={columns}
+ count={count}
+ primaryAction={
+ permissions.can("create", "parts") && (
+ <New
+ label="Material Finish"
+ to={`${path.to.newMaterialFinish}?${params.toString()}`}
+ />
+ )
+ }
+ renderContextMenu={renderContextMenu}
+ title="Material Finishes"
+ />
+ );
+ }
+);
+
+MaterialFinishesTable.displayName = "MaterialFinishesTable";
+export default MaterialFinishesTable;
diff --git a/apps/erp/app/modules/items/ui/MaterialGrades/MaterialGradesTable.tsx b/apps/erp/app/modules/items/ui/MaterialGrades/MaterialGradesTable.tsx
index a3e37bcf27..40b9bb5581 100644
--- a/apps/erp/app/modules/items/ui/MaterialGrades/MaterialGradesTable.tsx
+++ b/apps/erp/app/modules/items/ui/MaterialGrades/MaterialGradesTable.tsx
@@ -42,7 +42,7 @@ const MaterialGradesTable = memo(
type: "static",
options: substances.map((substance) => ({
label: <Enumerable value={substance.label} />,
- value: substance.value,
+ value: substance.label,
})),
},
},
diff --git a/apps/erp/app/modules/items/ui/useItemsSubmodules.tsx b/apps/erp/app/modules/items/ui/useItemsSubmodules.tsx
index 1caedc429f..bc029fbf0f 100644
--- a/apps/erp/app/modules/items/ui/useItemsSubmodules.tsx
+++ b/apps/erp/app/modules/items/ui/useItemsSubmodules.tsx
@@ -2,6 +2,7 @@ import { AiOutlinePartition } from "react-icons/ai";
import {
LuAtom,
LuBeef,
+ LuDessert,
LuGlassWater,
LuHammer,
LuPizza,
@@ -66,6 +67,12 @@ const itemsRoutes: AuthenticatedRouteGroup[] = [
{
name: "Configure",
routes: [
+ {
+ name: "Finishes",
+ to: path.to.materialFinishes,
+ icon: <LuDessert />,
+ role: "employee",
+ },
{
name: "Grades",
to: path.to.materialGrades,
diff --git a/apps/erp/app/routes/x+/items+/finishes.$id.tsx b/apps/erp/app/routes/x+/items+/finishes.$id.tsx
index b1037636ad..1d04f70120 100644
--- a/apps/erp/app/routes/x+/items+/finishes.$id.tsx
+++ b/apps/erp/app/routes/x+/items+/finishes.$id.tsx
@@ -6,11 +6,11 @@ import { useLoaderData, useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import {
- getMaterialGrade,
- materialGradeValidator,
- upsertMaterialGrade,
+ getMaterialFinish,
+ materialFinishValidator,
+ upsertMaterialFinish,
} from "~/modules/items";
-import MaterialGradeForm from "~/modules/items/ui/MaterialGrades/MaterialGradeForm";
+import MaterialFinishForm from "~/modules/items/ui/MaterialFinishes/MaterialFinishForm";
import { getParams, path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
@@ -22,11 +22,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { id } = params;
if (!id) throw notFound("id not found");
- const materialGrade = await getMaterialGrade(client, id);
+ const materialFinish = await getMaterialFinish(client, id);
- if (materialGrade.data?.companyId === null) {
+ if (materialFinish.data?.companyId === null) {
throw redirect(
- path.to.materialGrades,
+ path.to.materialFinishes,
await flash(
request,
error(new Error("Access denied"), "Cannot edit global material grade")
@@ -35,7 +35,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
return json({
- materialGrade: materialGrade?.data ?? null,
+ materialFinish: materialFinish?.data ?? null,
});
}
@@ -48,48 +48,48 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { id } = params;
if (!id) throw new Error("Could not find id");
- console.log("id", id);
-
const formData = await request.formData();
- const validation = await validator(materialGradeValidator).validate(formData);
+ const validation = await validator(materialFinishValidator).validate(
+ formData
+ );
if (validation.error) {
return validationError(validation.error);
}
- const updateMaterialGrade = await upsertMaterialGrade(client, {
+ const updateMaterialFinish = await upsertMaterialFinish(client, {
id: id,
...validation.data,
});
- if (updateMaterialGrade.error) {
+ if (updateMaterialFinish.error) {
return json(
{},
await flash(
request,
- error(updateMaterialGrade.error, "Failed to update material grade")
+ error(updateMaterialFinish.error, "Failed to update material grade")
)
);
}
throw redirect(
- `${path.to.materialGrades}?${getParams(request)}`,
+ `${path.to.materialFinishes}?${getParams(request)}`,
await flash(request, success("Updated material grade"))
);
}
-export default function EditMaterialGradesRoute() {
- const { materialGrade } = useLoaderData<typeof loader>();
+export default function EditMaterialFinishsRoute() {
+ const { materialFinish } = useLoaderData<typeof loader>();
const navigate = useNavigate();
const initialValues = {
- id: materialGrade?.id ?? undefined,
- name: materialGrade?.name ?? "",
- materialSubstanceId: materialGrade?.materialSubstanceId ?? "",
+ id: materialFinish?.id ?? undefined,
+ name: materialFinish?.name ?? "",
+ materialSubstanceId: materialFinish?.materialSubstanceId ?? "",
};
return (
- <MaterialGradeForm
+ <MaterialFinishForm
key={initialValues.id}
initialValues={initialValues}
onClose={() => navigate(-1)}
diff --git a/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx b/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx
index bb54cb7236..5eb6024f32 100644
--- a/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx
+++ b/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx
@@ -5,7 +5,7 @@ import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import { ConfirmDelete } from "~/components/Modals";
-import { deleteMaterialGrade, getMaterialGrade } from "~/modules/items";
+import { deleteMaterialFinish, getMaterialFinish } from "~/modules/items";
import { getParams, path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
@@ -15,18 +15,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { id } = params;
if (!id) throw notFound("id not found");
- const materialGrade = await getMaterialGrade(client, id);
- if (materialGrade.error) {
+ const materialFinish = await getMaterialFinish(client, id);
+ if (materialFinish.error) {
throw redirect(
- path.to.materialGrades,
+ path.to.materialFinishes,
await flash(
request,
- error(materialGrade.error, "Failed to get material grade")
+ error(materialFinish.error, "Failed to get material finish")
)
);
}
- return json({ materialGrade: materialGrade.data });
+ return json({ materialFinish: materialFinish.data });
}
export async function action({ request, params }: ActionFunctionArgs) {
@@ -37,44 +37,44 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { id } = params;
if (!id) {
throw redirect(
- path.to.materialGrades,
- await flash(request, error(params, "Failed to get an material grade id"))
+ path.to.materialFinishes,
+ await flash(request, error(params, "Failed to get an material finish id"))
);
}
- const { error: deleteTypeError } = await deleteMaterialGrade(client, id);
+ const { error: deleteTypeError } = await deleteMaterialFinish(client, id);
if (deleteTypeError) {
throw redirect(
- `${path.to.materialGrades}?${getParams(request)}`,
+ `${path.to.materialFinishes}?${getParams(request)}`,
await flash(
request,
- error(deleteTypeError, "Failed to delete material grade")
+ error(deleteTypeError, "Failed to delete material finish")
)
);
}
throw redirect(
- path.to.materialGrades,
- await flash(request, success("Successfully deleted material grade"))
+ path.to.materialFinishes,
+ await flash(request, success("Successfully deleted material finish"))
);
}
-export default function DeleteMaterialGradeRoute() {
+export default function DeleteMaterialFinishRoute() {
const { id } = useParams();
if (!id) throw new Error("id not found");
- const { materialGrade } = useLoaderData<typeof loader>();
+ const { materialFinish } = useLoaderData<typeof loader>();
const navigate = useNavigate();
- if (!materialGrade) return null;
+ if (!materialFinish) return null;
const onCancel = () => navigate(-1);
return (
<ConfirmDelete
- action={path.to.deleteMaterialGrade(id)}
- name={materialGrade.name}
- text={`Are you sure you want to delete the material grade: ${materialGrade.name}? This cannot be undone.`}
+ action={path.to.deleteMaterialFinish(id)}
+ name={materialFinish.name}
+ text={`Are you sure you want to delete the material finish: ${materialFinish.name}? This cannot be undone.`}
onCancel={onCancel}
/>
);
diff --git a/apps/erp/app/routes/x+/items+/finishes.new.tsx b/apps/erp/app/routes/x+/items+/finishes.new.tsx
index d8b7f68cb4..e84ce74e00 100644
--- a/apps/erp/app/routes/x+/items+/finishes.new.tsx
+++ b/apps/erp/app/routes/x+/items+/finishes.new.tsx
@@ -5,8 +5,8 @@ import { validationError, validator } from "@carbon/form";
import { useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
-import { materialGradeValidator, upsertMaterialGrade } from "~/modules/items";
-import MaterialGradeForm from "~/modules/items/ui/MaterialGrades/MaterialGradeForm";
+import { materialFinishValidator, upsertMaterialFinish } from "~/modules/items";
+import MaterialFinishForm from "~/modules/items/ui/MaterialFinishes/MaterialFinishForm";
import { getParams, path } from "~/utils/path";
@@ -27,7 +27,9 @@ export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData();
const modal = formData.get("type") == "modal";
- const validation = await validator(materialGradeValidator).validate(formData);
+ const validation = await validator(materialFinishValidator).validate(
+ formData
+ );
if (validation.error) {
return validationError(validation.error);
@@ -35,40 +37,40 @@ export async function action({ request }: ActionFunctionArgs) {
const { id, ...data } = validation.data;
- const insertMaterialGrade = await upsertMaterialGrade(client, {
+ const insertMaterialFinish = await upsertMaterialFinish(client, {
...data,
companyId,
});
- if (insertMaterialGrade.error) {
+ if (insertMaterialFinish.error) {
return json(
{},
await flash(
request,
- error(insertMaterialGrade.error, "Failed to insert material grade")
+ error(insertMaterialFinish.error, "Failed to insert material finish")
)
);
}
- const materialGradeId = insertMaterialGrade.data?.id;
- if (!materialGradeId) {
+ const materialFinishId = insertMaterialFinish.data?.id;
+ if (!materialFinishId) {
return json(
{},
await flash(
request,
- error(insertMaterialGrade, "Failed to insert material grade")
+ error(insertMaterialFinish, "Failed to insert material finish")
)
);
}
return modal
- ? json(insertMaterialGrade, { status: 201 })
+ ? json(insertMaterialFinish, { status: 201 })
: redirect(
- `${path.to.materialGrades}?${getParams(request)}`,
- await flash(request, success("Part group created"))
+ `${path.to.materialFinishes}?${getParams(request)}`,
+ await flash(request, success("Finish created"))
);
}
-export default function NewMaterialGradesRoute() {
+export default function NewMaterialFinishsRoute() {
const navigate = useNavigate();
const initialValues = {
name: "",
@@ -76,7 +78,7 @@ export default function NewMaterialGradesRoute() {
};
return (
- <MaterialGradeForm
+ <MaterialFinishForm
onClose={() => navigate(-1)}
initialValues={initialValues}
/>
diff --git a/apps/erp/app/routes/x+/items+/finishes.tsx b/apps/erp/app/routes/x+/items+/finishes.tsx
index 45bb5b2dc6..82750df3d0 100644
--- a/apps/erp/app/routes/x+/items+/finishes.tsx
+++ b/apps/erp/app/routes/x+/items+/finishes.tsx
@@ -5,16 +5,16 @@ import { VStack } from "@carbon/react";
import { Outlet, useLoaderData } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
-import { getMaterialGrades } from "~/modules/items";
-import MaterialGradesTable from "~/modules/items/ui/MaterialGrades/MaterialGradesTable";
+import { getMaterialFinishes } from "~/modules/items";
+import MaterialFinishesTable from "~/modules/items/ui/MaterialFinishes/MaterialFinishesTable";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
import { getGenericQueryFilters } from "~/utils/query";
export const handle: Handle = {
- breadcrumb: "Grades",
- to: path.to.materialGrades,
+ breadcrumb: "Finishes",
+ to: path.to.materialFinishes,
};
export async function loader({ request }: LoaderFunctionArgs) {
@@ -29,8 +29,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
const { limit, offset, sorts, filters } =
getGenericQueryFilters(searchParams);
- const [materialGrades] = await Promise.all([
- getMaterialGrades(client, companyId, {
+ const [materialFinishes] = await Promise.all([
+ getMaterialFinishes(client, companyId, {
limit,
offset,
sorts,
@@ -39,8 +39,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
}),
]);
- if (materialGrades.error) {
- console.error(materialGrades.error);
+ if (materialFinishes.error) {
+ console.error(materialFinishes.error);
throw redirect(
path.to.items,
await flash(request, error(null, "Error loading material substances"))
@@ -48,17 +48,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
}
return json({
- materialGrades: materialGrades.data ?? [],
- count: materialGrades.count ?? 0,
+ materialFinishes: materialFinishes.data ?? [],
+ count: materialFinishes.count ?? 0,
});
}
-export default function MaterialGradesRoute() {
- const { materialGrades, count } = useLoaderData<typeof loader>();
+export default function MaterialFinishesRoute() {
+ const { materialFinishes, count } = useLoaderData<typeof loader>();
return (
<VStack spacing={0} className="h-full">
- <MaterialGradesTable data={materialGrades} count={count ?? 0} />
+ <MaterialFinishesTable data={materialFinishes} count={count ?? 0} />
<Outlet />
</VStack>
);
diff --git a/apps/erp/app/routes/x+/items+/grades.$id.tsx b/apps/erp/app/routes/x+/items+/grades.$id.tsx
index b1037636ad..94e130f86b 100644
--- a/apps/erp/app/routes/x+/items+/grades.$id.tsx
+++ b/apps/erp/app/routes/x+/items+/grades.$id.tsx
@@ -48,8 +48,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { id } = params;
if (!id) throw new Error("Could not find id");
- console.log("id", id);
-
const formData = await request.formData();
const validation = await validator(materialGradeValidator).validate(formData);
diff --git a/apps/erp/app/routes/x+/items+/grades.new.tsx b/apps/erp/app/routes/x+/items+/grades.new.tsx
index d8b7f68cb4..af57e2456e 100644
--- a/apps/erp/app/routes/x+/items+/grades.new.tsx
+++ b/apps/erp/app/routes/x+/items+/grades.new.tsx
@@ -64,7 +64,7 @@ export async function action({ request }: ActionFunctionArgs) {
? json(insertMaterialGrade, { status: 201 })
: redirect(
`${path.to.materialGrades}?${getParams(request)}`,
- await flash(request, success("Part group created"))
+ await flash(request, success("Grade created"))
);
}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 7c57238b2b..0a73d009dd 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -66,6 +66,7 @@ export const path = {
locations: `${api}/resources/locations`,
materialForms: `${api}/items/forms`,
materialGrades: `${api}/items/grades`,
+ materialFinishes: `${api}/items/finishes`,
materialSubstances: `${api}/items/substances`,
messagingNotify: `${api}/messaging/notify`,
mrp: (locationId?: string) =>
@@ -505,6 +506,8 @@ export const path = {
generatePath(`${x}/job/methods/operation/parameter/delete/${id}`),
deleteJobOperationTool: (id: string) =>
generatePath(`${x}/job/methods/operation/tool/delete/${id}`),
+ deleteMaterialFinish: (id: string) =>
+ generatePath(`${x}/items/finishes/delete/${id}`),
deleteMaterialForm: (id: string) =>
generatePath(`${x}/items/forms/delete/${id}`),
deleteMaterialGrade: (id: string) =>
@@ -734,11 +737,12 @@ export const path = {
generatePath(`${x}/material/${id}/view/costing`),
materialDetails: (id: string) =>
generatePath(`${x}/material/${id}/view/details`),
+ materialFinish: (id: string) => generatePath(`${x}/items/finishes/${id}`),
+ materialFinishes: `${x}/items/finishes`,
materialForm: (id: string) => generatePath(`${x}/items/forms/${id}`),
materialForms: `${x}/items/forms`,
materialGrade: (id: string) => generatePath(`${x}/items/grades/${id}`),
materialGrades: `${x}/items/grades`,
-
materialInventory: (id: string) =>
generatePath(`${x}/material/${id}/view/inventory`),
materialInventoryLocation: (id: string, locationId: string) =>
@@ -848,6 +852,7 @@ export const path = {
newProcedureParameter: (id: string) =>
generatePath(`${x}/procedure/${id}/parameters/new`),
newItemPostingGroup: `${x}/items/groups/new`,
+ newMaterialFinish: `${x}/items/finishes/new`,
newMaterialForm: `${x}/items/forms/new`,
newMaterialGrade: `${x}/items/grades/new`,
newMaterialSubstance: `${x}/items/substances/new`,
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index edfd1e2d18..8843410e4e 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -7107,6 +7107,63 @@ export default {
tags: ["quoteOperation"],
},
},
+ "/materialGrades": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.materialGrades.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialGrades.materialSubstanceId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialGrades.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialGrades.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialGrades.substanceName",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/materialGrades",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["materialGrades"],
+ },
+ },
"/receiptLines": {
get: {
parameters: [
@@ -14757,6 +14814,9 @@ export default {
{
$ref: "#/parameters/rowFilter.materialDimensions.materialFormId",
},
+ {
+ $ref: "#/parameters/rowFilter.materialDimensions.name",
+ },
{
$ref: "#/parameters/rowFilter.materialDimensions.companyId",
},
@@ -14825,6 +14885,9 @@ export default {
{
$ref: "#/parameters/rowFilter.materialDimensions.materialFormId",
},
+ {
+ $ref: "#/parameters/rowFilter.materialDimensions.name",
+ },
{
$ref: "#/parameters/rowFilter.materialDimensions.companyId",
},
@@ -14847,6 +14910,9 @@ export default {
{
$ref: "#/parameters/rowFilter.materialDimensions.materialFormId",
},
+ {
+ $ref: "#/parameters/rowFilter.materialDimensions.name",
+ },
{
$ref: "#/parameters/rowFilter.materialDimensions.companyId",
},
@@ -21117,6 +21183,63 @@ export default {
tags: ["salesOrderFavorite"],
},
},
+ "/materialFinishes": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.materialFinishes.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialFinishes.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialFinishes.materialSubstanceId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialFinishes.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.materialFinishes.substanceName",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/materialFinishes",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["materialFinishes"],
+ },
+ },
"/openProductionOrders": {
get: {
parameters: [
@@ -60935,6 +61058,36 @@ export default {
},
type: "object",
},
+ materialGrades: {
+ properties: {
+ id: {
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ materialSubstanceId: {
+ description:
+ "Note:\nThis is a Foreign Key to `materialSubstance.id`.<fk table='materialSubstance' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ name: {
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ substanceName: {
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
receiptLines: {
properties: {
id: {
@@ -61172,7 +61325,7 @@ export default {
properties: {
id: {
description:
- "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
format: "text",
type: "string",
},
@@ -61221,7 +61374,7 @@ export default {
},
supplierLocationId: {
description:
- "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
+ "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
format: "text",
type: "string",
},
@@ -64741,7 +64894,7 @@ export default {
type: "object",
},
materialDimensions: {
- required: ["id", "materialFormId", "companyId"],
+ required: ["id", "materialFormId", "name"],
properties: {
id: {
default: "public.xid()",
@@ -64755,6 +64908,10 @@ export default {
format: "text",
type: "string",
},
+ name: {
+ format: "text",
+ type: "string",
+ },
companyId: {
description:
"Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
@@ -67435,6 +67592,36 @@ export default {
},
type: "object",
},
+ materialFinishes: {
+ properties: {
+ id: {
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ name: {
+ format: "text",
+ type: "string",
+ },
+ materialSubstanceId: {
+ description:
+ "Note:\nThis is a Foreign Key to `materialSubstance.id`.<fk table='materialSubstance' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ substanceName: {
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
openProductionOrders: {
properties: {
id: {
@@ -86115,6 +86302,45 @@ export default {
in: "query",
type: "string",
},
+ "body.materialGrades": {
+ name: "materialGrades",
+ description: "materialGrades",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/materialGrades",
+ },
+ },
+ "rowFilter.materialGrades.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialGrades.materialSubstanceId": {
+ name: "materialSubstanceId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialGrades.name": {
+ name: "name",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialGrades.companyId": {
+ name: "companyId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialGrades.substanceName": {
+ name: "substanceName",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.receiptLines": {
name: "receiptLines",
description: "receiptLines",
@@ -90474,6 +90700,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.materialDimensions.name": {
+ name: "name",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.materialDimensions.companyId": {
name: "companyId",
required: false,
@@ -93504,6 +93736,45 @@ export default {
in: "query",
type: "string",
},
+ "body.materialFinishes": {
+ name: "materialFinishes",
+ description: "materialFinishes",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/materialFinishes",
+ },
+ },
+ "rowFilter.materialFinishes.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialFinishes.name": {
+ name: "name",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialFinishes.materialSubstanceId": {
+ name: "materialSubstanceId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialFinishes.companyId": {
+ name: "companyId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.materialFinishes.substanceName": {
+ name: "substanceName",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.openProductionOrders": {
name: "openProductionOrders",
description: "openProductionOrders",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index b687266199..6e07940ee6 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -12166,19 +12166,22 @@ export type Database = {
};
materialDimensions: {
Row: {
- companyId: string;
+ companyId: string | null;
id: string;
materialFormId: string;
+ name: string;
};
Insert: {
- companyId: string;
+ companyId?: string | null;
id?: string;
materialFormId: string;
+ name: string;
};
Update: {
- companyId?: string;
+ companyId?: string | null;
id?: string;
materialFormId?: string;
+ name?: string;
};
Relationships: [
{
@@ -37852,6 +37855,52 @@ export type Database = {
}
];
};
+ materialFinishes: {
+ Row: {
+ companyId: string | null;
+ id: string | null;
+ materialSubstanceId: string | null;
+ name: string | null;
+ substanceName: string | null;
+ };
+ Relationships: [
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "companies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "company";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "customFieldTables";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "integrations";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "materialFinish_materialSubstanceId_fkey";
+ columns: ["materialSubstanceId"];
+ isOneToOne: false;
+ referencedRelation: "materialSubstance";
+ referencedColumns: ["id"];
+ }
+ ];
+ };
materialGrades: {
Row: {
companyId: string | null;
@@ -43030,14 +43079,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["customerCountryCode"];
+ columns: ["paymentCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
},
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["paymentCountryCode"];
+ columns: ["customerCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index b687266199..6e07940ee6 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -12166,19 +12166,22 @@ export type Database = {
};
materialDimensions: {
Row: {
- companyId: string;
+ companyId: string | null;
id: string;
materialFormId: string;
+ name: string;
};
Insert: {
- companyId: string;
+ companyId?: string | null;
id?: string;
materialFormId: string;
+ name: string;
};
Update: {
- companyId?: string;
+ companyId?: string | null;
id?: string;
materialFormId?: string;
+ name?: string;
};
Relationships: [
{
@@ -37852,6 +37855,52 @@ export type Database = {
}
];
};
+ materialFinishes: {
+ Row: {
+ companyId: string | null;
+ id: string | null;
+ materialSubstanceId: string | null;
+ name: string | null;
+ substanceName: string | null;
+ };
+ Relationships: [
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "companies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "company";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "customFieldTables";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "materialFinish_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "integrations";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "materialFinish_materialSubstanceId_fkey";
+ columns: ["materialSubstanceId"];
+ isOneToOne: false;
+ referencedRelation: "materialSubstance";
+ referencedColumns: ["id"];
+ }
+ ];
+ };
materialGrades: {
Row: {
companyId: string | null;
@@ -43030,14 +43079,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["customerCountryCode"];
+ columns: ["paymentCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
},
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["paymentCountryCode"];
+ columns: ["customerCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
diff --git a/packages/database/supabase/migrations/20250719100358_material-seed.sql b/packages/database/supabase/migrations/20250719100358_material-seed.sql
index f167e7fd90..a60bfcc5fd 100644
--- a/packages/database/supabase/migrations/20250719100358_material-seed.sql
+++ b/packages/database/supabase/migrations/20250719100358_material-seed.sql
@@ -47,7 +47,7 @@ CREATE TABLE "materialFinish" (
CONSTRAINT "materialFinish_materialSubstanceId_fkey" FOREIGN KEY ("materialSubstanceId") REFERENCES "materialSubstance"("id"),
CONSTRAINT "materialFinish_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),
- CONSTRAINT "materialFinish_name_companyId_unique" UNIQUE ("name", "companyId")
+ CONSTRAINT "materialFinish_name_companyId_unique" UNIQUE ("materialSubstanceId", "name", "companyId")
);
CREATE OR REPLACE VIEW "materialFinishes" WITH(SECURITY_INVOKER=true) AS
@@ -81,40 +81,40 @@ INSERT INTO "materialFinish" ("id", "name", "materialSubstanceId", "companyId")
('brush-240-alum', '#240 Brushed', 'aluminum', null),
-- Stainless finishes
- ('1-ss', '#1 Mill Finish', 'stainless', null),
- ('2b-ss', '#2B Bright Cold Rolled', 'stainless', null),
- ('2d-ss', '#2D Dull Cold Rolled', 'stainless', null),
- ('3-ss', '#3 Intermediate Polish', 'stainless', null),
- ('4-ss', '#4 Brushed', 'stainless', null),
- ('6-ss', '#6 Fine Satin', 'stainless', null),
- ('7-ss', '#7 High Reflective', 'stainless', null),
- ('8-ss', '#8 Mirror', 'stainless', null),
- ('ba-ss', 'BA (Bright Annealed)', 'stainless', null),
+ ('1-ss', '#1', 'stainless', null),
+ ('2b-ss', '#2B', 'stainless', null),
+ ('2d-ss', '#2D', 'stainless', null),
+ ('3-ss', '#3', 'stainless', null),
+ ('4-ss', '#4', 'stainless', null),
+ ('6-ss', '#6', 'stainless', null),
+ ('7-ss', '#7', 'stainless', null),
+ ('8-ss', '#8', 'stainless', null),
+ ('ba-ss', 'BA', 'stainless', null),
-- Brass finishes
- ('brush-120-brass', '#120 Brushed', 'brass', null),
- ('brush-180-brass', '#180 Brushed', 'brass', null),
- ('brush-240-brass', '#240 Brushed', 'brass', null),
- ('mirror-brass', 'Mirror Polished', 'brass', null),
+ ('brush-120-brass', '#120', 'brass', null),
+ ('brush-180-brass', '#180', 'brass', null),
+ ('brush-240-brass', '#240', 'brass', null),
+ ('mirror-brass', 'Mirror', 'brass', null),
('satin-brass', 'Satin', 'brass', null),
-- Bronze finishes
- ('brush-120-bronze', '#120 Brushed', 'bronze', null),
- ('brush-180-bronze', '#180 Brushed', 'bronze', null),
- ('mirror-bronze', 'Mirror Polished', 'bronze', null),
+ ('brush-120-bronze', '#120', 'bronze', null),
+ ('brush-180-bronze', '#180', 'bronze', null),
+ ('mirror-bronze', 'Mirror', 'bronze', null),
('satin-bronze', 'Satin', 'bronze', null),
-- Copper finishes
- ('brush-120-copper', '#120 Brushed', 'copper', null),
- ('brush-180-copper', '#180 Brushed', 'copper', null),
- ('mirror-copper', 'Mirror Polished', 'copper', null),
+ ('brush-120-copper', '#120', 'copper', null),
+ ('brush-180-copper', '#180', 'copper', null),
+ ('mirror-copper', 'Mirror', 'copper', null),
('satin-copper', 'Satin', 'copper', null),
-- Inconel finishes
- ('mill-inconel', 'Mill Finish', 'inconel', null),
+ ('mill-inconel', 'Mill', 'inconel', null),
('ground-32-inconel', '32 Ra Ground', 'inconel', null),
('ground-16-inconel', '16 Ra Ground', 'inconel', null),
- ('polish-inconel', 'Polished', 'inconel', null),
+ ('polish-inconel', 'Polish', 'inconel', null),
-- Titanium finishes
('mill-ti', 'Mill Finish', 'titanium', null),
@@ -134,7 +134,7 @@ CREATE TABLE "materialGrade" (
CONSTRAINT "materialGrade_materialSubstanceId_fkey" FOREIGN KEY ("materialSubstanceId") REFERENCES "materialSubstance"("id"),
CONSTRAINT "materialGrade_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),
- CONSTRAINT "materialGrade_name_companyId_unique" UNIQUE ("name", "companyId")
+ CONSTRAINT "materialGrade_name_companyId_unique" UNIQUE ("materialSubstanceId", "name", "companyId")
);
CREATE OR REPLACE VIEW "materialGrades" WITH(SECURITY_INVOKER=true) AS
@@ -235,8 +235,192 @@ INSERT INTO "materialGrade" ("id", "materialSubstanceId", "name", "companyId") V
CREATE TABLE "materialDimensions" (
"id" TEXT NOT NULL PRIMARY KEY DEFAULT xid(),
"materialFormId" TEXT NOT NULL,
- "companyId" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "companyId" TEXT,
CONSTRAINT "materialDimensions_materialFormId_fkey" FOREIGN KEY ("materialFormId") REFERENCES "materialForm"("id"),
- CONSTRAINT "materialDimensions_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id")
+ CONSTRAINT "materialDimensions_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),
+ CONSTRAINT "materialDimensions_name_companyId_unique" UNIQUE ("materialFormId", "name", "companyId")
);
+
+INSERT INTO "materialDimensions" ("id", "materialFormId", "name", "companyId") VALUES
+ -- Sheet dimensions (gauges)
+ ('sheet-20ga', 'sheet', '20 Gauge', null),
+ ('sheet-18ga', 'sheet', '18 Gauge', null),
+ ('sheet-16ga', 'sheet', '16 Gauge', null),
+ ('sheet-14ga', 'sheet', '14 Gauge', null),
+ ('sheet-12ga', 'sheet', '12 Gauge', null),
+ ('sheet-11ga', 'sheet', '11 Gauge', null),
+ ('sheet-10ga', 'sheet', '10 Gauge', null),
+ ('sheet-7ga', 'sheet', '7 Gauge', null),
+
+ -- Plate dimensions (thicknesses)
+ ('plate-1-8', 'plate', '1/8"', null),
+ ('plate-3-16', 'plate', '3/16"', null),
+ ('plate-1-4', 'plate', '1/4"', null),
+ ('plate-5-16', 'plate', '5/16"', null),
+ ('plate-3-8', 'plate', '3/8"', null),
+ ('plate-1-2', 'plate', '1/2"', null),
+ ('plate-5-8', 'plate', '5/8"', null),
+ ('plate-3-4', 'plate', '3/4"', null),
+ ('plate-1', 'plate', '1"', null),
+ ('plate-1-25', 'plate', '1.25"', null),
+ ('plate-1-5', 'plate', '1.5"', null),
+ ('plate-2', 'plate', '2"', null),
+
+ -- Round bar dimensions (diameters)
+ ('roundbar-1-8', 'roundbar', '1/8"', null),
+ ('roundbar-3-16', 'roundbar', '3/16"', null),
+ ('roundbar-1-4', 'roundbar', '1/4"', null),
+ ('roundbar-5-16', 'roundbar', '5/16"', null),
+ ('roundbar-3-8', 'roundbar', '3/8"', null),
+ ('roundbar-1-2', 'roundbar', '1/2"', null),
+ ('roundbar-5-8', 'roundbar', '5/8"', null),
+ ('roundbar-3-4', 'roundbar', '3/4"', null),
+ ('roundbar-7-8', 'roundbar', '7/8"', null),
+ ('roundbar-1', 'roundbar', '1"', null),
+ ('roundbar-1-25', 'roundbar', '1.25"', null),
+ ('roundbar-1-5', 'roundbar', '1.5"', null),
+ ('roundbar-2', 'roundbar', '2"', null),
+ ('roundbar-2-5', 'roundbar', '2.5"', null),
+ ('roundbar-3', 'roundbar', '3"', null),
+ ('roundbar-4', 'roundbar', '4"', null),
+
+ -- Square bar dimensions
+ ('squarebar-1-8', 'squarebar', '1/8"', null),
+ ('squarebar-3-16', 'squarebar', '3/16"', null),
+ ('squarebar-1-4', 'squarebar', '1/4"', null),
+ ('squarebar-5-16', 'squarebar', '5/16"', null),
+ ('squarebar-3-8', 'squarebar', '3/8"', null),
+ ('squarebar-1-2', 'squarebar', '1/2"', null),
+ ('squarebar-5-8', 'squarebar', '5/8"', null),
+ ('squarebar-3-4', 'squarebar', '3/4"', null),
+ ('squarebar-1', 'squarebar', '1"', null),
+ ('squarebar-1-25', 'squarebar', '1.25"', null),
+ ('squarebar-1-5', 'squarebar', '1.5"', null),
+ ('squarebar-2', 'squarebar', '2"', null),
+
+ -- Hex bar dimensions
+ ('hexbar-1-4', 'hexbar', '1/4"', null),
+ ('hexbar-5-16', 'hexbar', '5/16"', null),
+ ('hexbar-3-8', 'hexbar', '3/8"', null),
+ ('hexbar-1-2', 'hexbar', '1/2"', null),
+ ('hexbar-5-8', 'hexbar', '5/8"', null),
+ ('hexbar-3-4', 'hexbar', '3/4"', null),
+ ('hexbar-7-8', 'hexbar', '7/8"', null),
+ ('hexbar-1', 'hexbar', '1"', null),
+ ('hexbar-1-25', 'hexbar', '1.25"', null),
+ ('hexbar-1-5', 'hexbar', '1.5"', null),
+
+ -- Flat bar dimensions (thickness x width)
+ ('flatbar-1-8x1-2', 'flatbar', '1/8" x 1/2"', null),
+ ('flatbar-1-8x3-4', 'flatbar', '1/8" x 3/4"', null),
+ ('flatbar-1-8x1', 'flatbar', '1/8" x 1"', null),
+ ('flatbar-3-16x1-2', 'flatbar', '3/16" x 1/2"', null),
+ ('flatbar-3-16x3-4', 'flatbar', '3/16" x 3/4"', null),
+ ('flatbar-3-16x1', 'flatbar', '3/16" x 1"', null),
+ ('flatbar-1-4x1-2', 'flatbar', '1/4" x 1/2"', null),
+ ('flatbar-1-4x3-4', 'flatbar', '1/4" x 3/4"', null),
+ ('flatbar-1-4x1', 'flatbar', '1/4" x 1"', null),
+ ('flatbar-1-4x1-5', 'flatbar', '1/4" x 1.5"', null),
+ ('flatbar-1-4x2', 'flatbar', '1/4" x 2"', null),
+ ('flatbar-3-8x1', 'flatbar', '3/8" x 1"', null),
+ ('flatbar-3-8x1-5', 'flatbar', '3/8" x 1.5"', null),
+ ('flatbar-3-8x2', 'flatbar', '3/8" x 2"', null),
+ ('flatbar-1-2x1', 'flatbar', '1/2" x 1"', null),
+ ('flatbar-1-2x1-5', 'flatbar', '1/2" x 1.5"', null),
+ ('flatbar-1-2x2', 'flatbar', '1/2" x 2"', null),
+ ('flatbar-1-2x3', 'flatbar', '1/2" x 3"', null),
+
+ -- Round tube dimensions (OD x wall thickness)
+ ('roundtube-1-2x049', 'roundtube', '1/2" x .049"', null),
+ ('roundtube-5-8x049', 'roundtube', '5/8" x .049"', null),
+ ('roundtube-3-4x049', 'roundtube', '3/4" x .049"', null),
+ ('roundtube-7-8x049', 'roundtube', '7/8" x .049"', null),
+ ('roundtube-1x049', 'roundtube', '1" x .049"', null),
+ ('roundtube-1x065', 'roundtube', '1" x .065"', null),
+ ('roundtube-1-25x049', 'roundtube', '1.25" x .049"', null),
+ ('roundtube-1-25x065', 'roundtube', '1.25" x .065"', null),
+ ('roundtube-1-5x049', 'roundtube', '1.5" x .049"', null),
+ ('roundtube-1-5x065', 'roundtube', '1.5" x .065"', null),
+ ('roundtube-2x049', 'roundtube', '2" x .049"', null),
+ ('roundtube-2x065', 'roundtube', '2" x .065"', null),
+ ('roundtube-2x083', 'roundtube', '2" x .083"', null),
+
+ -- Square tube dimensions (size x wall thickness)
+ ('squaretube-1-2x049', 'squaretube', '1/2" x .049"', null),
+ ('squaretube-5-8x049', 'squaretube', '5/8" x .049"', null),
+ ('squaretube-3-4x049', 'squaretube', '3/4" x .049"', null),
+ ('squaretube-1x049', 'squaretube', '1" x .049"', null),
+ ('squaretube-1x065', 'squaretube', '1" x .065"', null),
+ ('squaretube-1-25x049', 'squaretube', '1.25" x .049"', null),
+ ('squaretube-1-25x065', 'squaretube', '1.25" x .065"', null),
+ ('squaretube-1-5x049', 'squaretube', '1.5" x .049"', null),
+ ('squaretube-1-5x065', 'squaretube', '1.5" x .065"', null),
+ ('squaretube-2x049', 'squaretube', '2" x .049"', null),
+ ('squaretube-2x065', 'squaretube', '2" x .065"', null),
+ ('squaretube-2x083', 'squaretube', '2" x .083"', null),
+
+ -- Rectangular tube dimensions (width x height x wall thickness)
+ ('recttube-1x2x049', 'recttube', '1" x 2" x .049"', null),
+ ('recttube-1x2x065', 'recttube', '1" x 2" x .065"', null),
+ ('recttube-1-5x2x049', 'recttube', '1.5" x 2" x .049"', null),
+ ('recttube-1-5x2x065', 'recttube', '1.5" x 2" x .065"', null),
+ ('recttube-2x3x049', 'recttube', '2" x 3" x .049"', null),
+ ('recttube-2x3x065', 'recttube', '2" x 3" x .065"', null),
+ ('recttube-2x4x049', 'recttube', '2" x 4" x .049"', null),
+ ('recttube-2x4x065', 'recttube', '2" x 4" x .065"', null),
+ ('recttube-3x4x065', 'recttube', '3" x 4" x .065"', null),
+
+ -- Rectangular bar dimensions (thickness x width)
+ ('rectbar-1-8x1-2', 'rectbar', '1/8" x 1/2"', null),
+ ('rectbar-1-4x1-2', 'rectbar', '1/4" x 1/2"', null),
+ ('rectbar-1-4x3-4', 'rectbar', '1/4" x 3/4"', null),
+ ('rectbar-1-4x1', 'rectbar', '1/4" x 1"', null),
+ ('rectbar-3-8x3-4', 'rectbar', '3/8" x 3/4"', null),
+ ('rectbar-3-8x1', 'rectbar', '3/8" x 1"', null),
+ ('rectbar-1-2x1', 'rectbar', '1/2" x 1"', null),
+ ('rectbar-1-2x1-5', 'rectbar', '1/2" x 1.5"', null),
+ ('rectbar-1-2x2', 'rectbar', '1/2" x 2"', null),
+
+ -- Angle dimensions (leg x leg x thickness)
+ ('angle-1x1x1-8', 'angle', '1" x 1" x 1/8"', null),
+ ('angle-1x1x3-16', 'angle', '1" x 1" x 3/16"', null),
+ ('angle-1-25x1-25x1-8', 'angle', '1.25" x 1.25" x 1/8"', null),
+ ('angle-1-25x1-25x3-16', 'angle', '1.25" x 1.25" x 3/16"', null),
+ ('angle-1-5x1-5x1-8', 'angle', '1.5" x 1.5" x 1/8"', null),
+ ('angle-1-5x1-5x3-16', 'angle', '1.5" x 1.5" x 3/16"', null),
+ ('angle-2x2x1-8', 'angle', '2" x 2" x 1/8"', null),
+ ('angle-2x2x3-16', 'angle', '2" x 2" x 3/16"', null),
+ ('angle-2x2x1-4', 'angle', '2" x 2" x 1/4"', null),
+ ('angle-3x3x1-4', 'angle', '3" x 3" x 1/4"', null),
+ ('angle-3x3x5-16', 'angle', '3" x 3" x 5/16"', null),
+ ('angle-4x4x1-4', 'angle', '4" x 4" x 1/4"', null),
+ ('angle-4x4x5-16', 'angle', '4" x 4" x 5/16"', null),
+
+ -- Channel dimensions (depth x flange width x thickness)
+ ('channel-3x1-41x170', 'channel', 'C3 x 4.1', null),
+ ('channel-4x5-4x184', 'channel', 'C4 x 5.4', null),
+ ('channel-5x6-7x190', 'channel', 'C5 x 6.7', null),
+ ('channel-6x8-2x200', 'channel', 'C6 x 8.2', null),
+ ('channel-7x9-8x210', 'channel', 'C7 x 9.8', null),
+ ('channel-8x11-5x220', 'channel', 'C8 x 11.5', null),
+ ('channel-9x13-4x233', 'channel', 'C9 x 13.4', null),
+ ('channel-10x15-3x240', 'channel', 'C10 x 15.3', null),
+ ('channel-12x20-7x282', 'channel', 'C12 x 20.7', null),
+
+ -- Filament dimensions (diameters for 3D printing)
+ ('filament-1-75', 'filament', '1.75mm', null),
+ ('filament-3', 'filament', '3.0mm', null),
+
+ -- Pellet dimensions (mesh sizes)
+ ('pellet-4', 'pellet', '4 mesh', null),
+ ('pellet-6', 'pellet', '6 mesh', null),
+ ('pellet-8', 'pellet', '8 mesh', null),
+ ('pellet-10', 'pellet', '10 mesh', null),
+ ('pellet-12', 'pellet', '12 mesh', null),
+ ('pellet-14', 'pellet', '14 mesh', null),
+ ('pellet-16', 'pellet', '16 mesh', null),
+ ('pellet-20', 'pellet', '20 mesh', null);
+
+