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 ui for consumables

Brad Barbin1439b2377d61
diff --git a/apps/carbon/app/modules/items/items.service.ts b/apps/carbon/app/modules/items/items.service.ts
index 5c70e4ee1c..af288d5d73 100644
--- a/apps/carbon/app/modules/items/items.service.ts
+++ b/apps/carbon/app/modules/items/items.service.ts
@@ -51,6 +51,65 @@ export async function deleteUnitOfMeasure(
return client.from("unitOfMeasure").delete().eq("id", id);
}
+export async function getConsumable(
+ client: SupabaseClient<Database>,
+ itemId: string,
+ companyId: string
+) {
+ return client
+ .from("consumables")
+ .select("*")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId)
+ .single();
+}
+
+export async function getConsumables(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args: GenericQueryFilters & {
+ search: string | null;
+ supplierId: string | null;
+ }
+) {
+ let query = client
+ .from("consumables")
+ .select("*", {
+ count: "exact",
+ })
+ .eq("companyId", companyId);
+
+ if (args.search) {
+ query = query.or(
+ `id.ilike.%${args.search}%,name.ilike.%${args.search}%,description.ilike.%${args.search}%`
+ );
+ }
+
+ if (args.supplierId) {
+ query = query.contains("supplierIds", [args.supplierId]);
+ }
+
+ query = setGenericQueryFilters(query, args, [
+ { column: "id", ascending: true },
+ ]);
+ return query;
+}
+
+export async function getConsumablesList(
+ client: SupabaseClient<Database>,
+ companyId: string
+) {
+ let query = client
+ .from("item")
+ .select("id, name, readableId")
+ .eq("type", "Consumable")
+ .eq("companyId", companyId)
+ .eq("blocked", false)
+ .eq("active", true);
+
+ return query.order("name");
+}
+
export async function getItemCost(
client: SupabaseClient<Database>,
itemId: string,
diff --git a/apps/carbon/app/modules/items/types.ts b/apps/carbon/app/modules/items/types.ts
index 3497e53e55..bf38390269 100644
--- a/apps/carbon/app/modules/items/types.ts
+++ b/apps/carbon/app/modules/items/types.ts
@@ -1,5 +1,6 @@
import type { Database } from "@carbon/database";
import type {
+ getConsumables,
getItemCost,
getItemGroups,
getItemGroupsList,
@@ -16,6 +17,10 @@ import type {
getUnitOfMeasuresList,
} from "./items.service";
+export type Consumable = NonNullable<
+ Awaited<ReturnType<typeof getConsumables>>["data"]
+>[number];
+
export type ItemCost = NonNullable<
Awaited<ReturnType<typeof getItemCost>>
>["data"];
diff --git a/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsx b/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsx
new file mode 100644
index 0000000000..135742e945
--- /dev/null
+++ b/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsx
@@ -0,0 +1,160 @@
+import {
+ ModalCard,
+ ModalCardBody,
+ ModalCardContent,
+ ModalCardDescription,
+ ModalCardFooter,
+ ModalCardHeader,
+ ModalCardProvider,
+ ModalCardTitle,
+ cn,
+ toast,
+} from "@carbon/react";
+import { ValidatedForm } from "@carbon/remix-validated-form";
+import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
+import type { z } from "zod";
+import {
+ Boolean,
+ CustomFormFields,
+ Hidden,
+ Input,
+ InputControlled,
+ ItemGroup,
+ Select,
+ Submit,
+ TextArea,
+ UnitOfMeasure,
+} from "~/components/Form";
+import { useNextItemId, usePermissions } from "~/hooks";
+import { consumableValidator, itemInventoryTypes } from "~/modules/items";
+import { path } from "~/utils/path";
+
+type ConsumableFormProps = {
+ initialValues: z.infer<typeof consumableValidator>;
+ type?: "card" | "modal";
+ onClose?: () => void;
+};
+
+function startsWithLetter(value: string) {
+ return /^[A-Za-z]/.test(value);
+}
+
+const ConsumableForm = ({
+ initialValues,
+ type = "card",
+ onClose,
+}: ConsumableFormProps) => {
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created consumable`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create consumable: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
+
+ const { id, onIdChange, loading } = useNextItemId("consumable");
+ const permissions = usePermissions();
+ const isEditing = !!initialValues.id;
+
+ const itemInventoryTypeOptions =
+ itemInventoryTypes.map((itemInventoryType) => ({
+ label: itemInventoryType,
+ value: itemInventoryType,
+ })) ?? [];
+
+ return (
+ <ModalCardProvider type={type}>
+ <ModalCard onClose={onClose}>
+ <ModalCardContent>
+ <ValidatedForm
+ action={isEditing ? undefined : path.to.newConsumable}
+ method="post"
+ validator={consumableValidator}
+ defaultValues={initialValues}
+ fetcher={fetcher}
+ >
+ <ModalCardHeader>
+ <ModalCardTitle>
+ {isEditing ? "Consumable Details" : "New Consumable"}
+ </ModalCardTitle>
+ {!isEditing && (
+ <ModalCardDescription>
+ A consumable is a physical item used to make a part that can
+ be used across multiple jobs
+ </ModalCardDescription>
+ )}
+ </ModalCardHeader>
+ <ModalCardBody>
+ <Hidden name="type" value={type} />
+ <div
+ className={cn(
+ "grid w-full gap-x-8 gap-y-2",
+ isEditing ? "grid-cols-1 md:grid-cols-3" : "grid-cols-1"
+ )}
+ >
+ {isEditing ? (
+ <Input name="id" label="Consumable ID" isReadOnly />
+ ) : (
+ <InputControlled
+ name="id"
+ label="Consumable ID"
+ helperText={
+ startsWithLetter(id)
+ ? "Use ... to get the next consumable ID"
+ : undefined
+ }
+ value={id}
+ onChange={onIdChange}
+ isDisabled={loading}
+ autoFocus
+ />
+ )}
+
+ <Input name="name" label="Name" />
+ <ItemGroup name="itemGroupId" label="Posting Group" />
+ {isEditing && (
+ <TextArea name="description" label="Description" />
+ )}
+
+ <Select
+ name="itemInventoryType"
+ label="Consumable Type"
+ options={itemInventoryTypeOptions}
+ />
+ <UnitOfMeasure
+ name="unitOfMeasureCode"
+ label="Unit of Measure"
+ />
+
+ <Boolean name="blocked" label="Blocked" />
+ {isEditing && <Boolean name="active" label="Active" />}
+
+ <CustomFormFields table="consumable" />
+ </div>
+ </ModalCardBody>
+ <ModalCardFooter>
+ <Submit
+ isDisabled={
+ isEditing
+ ? !permissions.can("update", "parts")
+ : !permissions.can("create", "parts")
+ }
+ >
+ Save
+ </Submit>
+ </ModalCardFooter>
+ </ValidatedForm>
+ </ModalCardContent>
+ </ModalCard>
+ </ModalCardProvider>
+ );
+};
+
+export default ConsumableForm;
diff --git a/apps/carbon/app/modules/items/ui/Consumables/ConsumableHeader.tsx b/apps/carbon/app/modules/items/ui/Consumables/ConsumableHeader.tsx
new file mode 100644
index 0000000000..71e84f40a7
--- /dev/null
+++ b/apps/carbon/app/modules/items/ui/Consumables/ConsumableHeader.tsx
@@ -0,0 +1,108 @@
+import {
+ Card,
+ CardAction,
+ CardAttribute,
+ CardAttributeLabel,
+ CardAttributeValue,
+ CardAttributes,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Enumerable,
+ HStack,
+ Menubar,
+ VStack,
+} from "@carbon/react";
+
+import { useParams } from "@remix-run/react";
+import { Assign, EmployeeAvatar, useOptimisticAssignment } from "~/components";
+import { usePermissions, useRouteData } from "~/hooks";
+import type { Consumable } from "~/modules/items";
+import { path } from "~/utils/path";
+
+const ConsumableHeader = () => {
+ const permissions = usePermissions();
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("itemId not found");
+
+ const routeData = useRouteData<{ consumableSummary: Consumable }>(
+ path.to.consumable(itemId)
+ );
+
+ const optimisticAssignment = useOptimisticAssignment({
+ id: itemId,
+ table: "item",
+ });
+ const assignee =
+ optimisticAssignment !== undefined
+ ? optimisticAssignment
+ : routeData?.consumableSummary?.assignee;
+
+ return (
+ <VStack>
+ {permissions.is("employee") && !!routeData?.consumableSummary?.id && (
+ <Menubar>
+ <Assign
+ id={itemId}
+ table="item"
+ value={routeData?.consumableSummary?.assignee ?? ""}
+ />
+ </Menubar>
+ )}
+ <Card>
+ <HStack className="justify-between items-start">
+ <CardHeader>
+ <CardTitle>{routeData?.consumableSummary?.id}</CardTitle>
+ <CardDescription>
+ {routeData?.consumableSummary?.name}
+ </CardDescription>
+ </CardHeader>
+ <CardAction>
+ {/* <Button
+ variant="secondary"
+ onClick={() => alert("TODO")}
+ leftIcon={<FaHistory />}
+ >
+ View History
+ </Button> */}
+ </CardAction>
+ </HStack>
+ <CardContent>
+ <CardAttributes>
+ <CardAttribute>
+ <CardAttributeLabel>Assignee</CardAttributeLabel>
+ <CardAttributeValue>
+ {assignee ? (
+ <EmployeeAvatar employeeId={assignee ?? null} />
+ ) : (
+ "-"
+ )}
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Inventory Type</CardAttributeLabel>
+ <CardAttributeValue>
+ <Enumerable
+ value={
+ routeData?.consumableSummary?.itemInventoryType ?? null
+ }
+ />
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>UoM</CardAttributeLabel>
+ <CardAttributeValue>
+ <Enumerable
+ value={routeData?.consumableSummary?.unitOfMeasure ?? null}
+ />
+ </CardAttributeValue>
+ </CardAttribute>
+ </CardAttributes>
+ </CardContent>
+ </Card>
+ </VStack>
+ );
+};
+
+export default ConsumableHeader;
diff --git a/apps/carbon/app/modules/items/ui/Consumables/ConsumableNavigation.tsx b/apps/carbon/app/modules/items/ui/Consumables/ConsumableNavigation.tsx
new file mode 100644
index 0000000000..240ebfb0f9
--- /dev/null
+++ b/apps/carbon/app/modules/items/ui/Consumables/ConsumableNavigation.tsx
@@ -0,0 +1,80 @@
+import { useParams } from "@remix-run/react";
+
+import {
+ LuBox,
+ LuFileBarChart,
+ LuFileText,
+ LuShare2,
+ LuShoppingCart,
+ LuTags,
+} from "react-icons/lu";
+import { DetailSidebar } from "~/components/Layout";
+import { usePermissions } from "~/hooks";
+import type { Role } from "~/types";
+import { path } from "~/utils/path";
+
+export function useConsumableNavigation() {
+ const permissions = usePermissions();
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("itemId not found");
+
+ return [
+ {
+ name: "Details",
+ to: path.to.consumableDetails(itemId),
+ icon: LuFileText,
+ shortcut: "Command+Shift+d",
+ },
+ {
+ name: "Purchasing",
+ to: path.to.consumablePurchasing(itemId),
+ role: ["employee", "supplier"],
+ icon: LuShoppingCart,
+ shortcut: "Command+Shift+p",
+ },
+ {
+ name: "Suppliers",
+ to: path.to.consumableSuppliers(itemId),
+ role: ["employee", "supplier"],
+ icon: LuShare2,
+ shortcut: "Command+Shift+s",
+ },
+
+ {
+ name: "Costing",
+ to: path.to.consumableCosting(itemId),
+ role: ["employee", "supplier"],
+ icon: LuTags,
+ shortcut: "Command+Shift+c",
+ },
+ {
+ name: "Planning",
+ to: path.to.consumablePlanning(itemId),
+ role: ["employee"],
+ icon: LuFileBarChart,
+ shortcut: "Command+Shift+p",
+ },
+ {
+ name: "Inventory",
+ to: path.to.consumableInventory(itemId),
+ role: ["employee", "supplier"],
+ icon: LuBox,
+ shortcut: "Command+Shift+i",
+ },
+ ].filter(
+ (item) =>
+ item.role === undefined ||
+ item.role.some((role) => permissions.is(role as Role))
+ );
+}
+
+const ConsumableNavigation = () => {
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("itemId not found");
+
+ const links = useConsumableNavigation();
+
+ return <DetailSidebar links={links} />;
+};
+
+export default ConsumableNavigation;
diff --git a/apps/carbon/app/modules/items/ui/Consumables/ConsumablesTable.tsx b/apps/carbon/app/modules/items/ui/Consumables/ConsumablesTable.tsx
new file mode 100644
index 0000000000..ffaa397961
--- /dev/null
+++ b/apps/carbon/app/modules/items/ui/Consumables/ConsumablesTable.tsx
@@ -0,0 +1,215 @@
+import { Checkbox, Enumerable, MenuIcon, MenuItem } from "@carbon/react";
+import { formatDate } from "@carbon/utils";
+import { useNavigate } from "@remix-run/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { memo, useMemo } from "react";
+import { LuPencil } from "react-icons/lu";
+import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";
+import { usePermissions, useUrlParams } from "~/hooks";
+import { useCustomColumns } from "~/hooks/useCustomColumns";
+import type { Consumable } from "~/modules/items";
+import { itemInventoryTypes } from "~/modules/items";
+import { usePeople } from "~/stores";
+import type { ListItem } from "~/types";
+import { path } from "~/utils/path";
+
+type ConsumablesTableProps = {
+ data: Consumable[];
+ itemGroups: ListItem[];
+ count: number;
+};
+
+const ConsumablesTable = memo(
+ ({ data, count, itemGroups }: ConsumablesTableProps) => {
+ const navigate = useNavigate();
+ const permissions = usePermissions();
+ const [params] = useUrlParams();
+ const [people] = usePeople();
+ const customColumns = useCustomColumns<Consumable>("consumable");
+
+ const columns = useMemo<ColumnDef<Consumable>[]>(() => {
+ const defaultColumns: ColumnDef<Consumable>[] = [
+ {
+ accessorKey: "id",
+ header: "Consumable ID",
+ cell: ({ row }) => (
+ <Hyperlink to={path.to.consumableDetails(row.original.itemId!)}>
+ {row.original.id}
+ </Hyperlink>
+ ),
+ },
+ {
+ accessorKey: "name",
+ header: "Name",
+ cell: (item) => item.getValue(),
+ },
+ {
+ accessorKey: "description",
+ header: "Description",
+ cell: (item) => item.getValue(),
+ },
+ {
+ accessorKey: "itemInventoryType",
+ header: "Inventory",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: itemInventoryTypes.map((type) => ({
+ value: type,
+ label: <Enumerable value={type} />,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "itemGroup",
+ header: "Posting Group",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: itemGroups.map(({ name }) => ({
+ value: name,
+ label: <Enumerable value={name} />,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "active",
+ header: "Active",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Active" },
+ { value: "false", label: "Inactive" },
+ ],
+ },
+ pluralHeader: "Active Statuses",
+ },
+ },
+ {
+ accessorKey: "blocked",
+ header: "Blocked",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Blocked" },
+ { value: "false", label: "Not Blocked" },
+ ],
+ },
+ pluralHeader: "Blocked Statuses",
+ },
+ },
+ {
+ id: "assignee",
+ header: "Assignee",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.assignee} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ id: "createdBy",
+ header: "Created By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.createdBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "createdAt",
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
+ {
+ id: "updatedBy",
+ header: "Updated By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.updatedBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "updatedAt",
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
+ ];
+ return [...defaultColumns, ...customColumns];
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [params]);
+
+ const renderContextMenu = useMemo(() => {
+ // eslint-disable-next-line react/display-name
+ return (row: Consumable) => (
+ <MenuItem onClick={() => navigate(path.to.consumable(row.id!))}>
+ <MenuIcon icon={<LuPencil />} />
+ Edit Consumable
+ </MenuItem>
+ );
+ }, [navigate]);
+
+ return (
+ <>
+ <Table<Consumable>
+ count={count}
+ columns={columns}
+ data={data}
+ defaultColumnPinning={{
+ left: ["id"],
+ }}
+ defaultColumnVisibility={{
+ description: false,
+ active: false,
+ blocked: false,
+ createdBy: false,
+ createdAt: false,
+ updatedBy: false,
+ updatedAt: false,
+ }}
+ primaryAction={
+ permissions.can("create", "parts") && (
+ <New label="Consumable" to={path.to.newConsumable} />
+ )
+ }
+ renderContextMenu={renderContextMenu}
+ withColumnOrdering
+ />
+ </>
+ );
+ }
+);
+
+ConsumablesTable.displayName = "ConsumableTable";
+
+export default ConsumablesTable;
diff --git a/apps/carbon/app/modules/items/ui/Consumables/index.ts b/apps/carbon/app/modules/items/ui/Consumables/index.ts
new file mode 100644
index 0000000000..6a4835a640
--- /dev/null
+++ b/apps/carbon/app/modules/items/ui/Consumables/index.ts
@@ -0,0 +1,11 @@
+import ConsumableForm from "./ConsumableForm";
+import ConsumableHeader from "./ConsumableHeader";
+import ConsumableNavigation from "./ConsumableNavigation";
+import ConsumablesTable from "./ConsumablesTable";
+
+export {
+ ConsumableForm,
+ ConsumableHeader,
+ ConsumableNavigation,
+ ConsumablesTable,
+};
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 2e45b41d7e..d819aa1da7 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -106,11 +106,20 @@ export const path = {
contractor: (id: string) =>
generatePath(`${x}/resources/contractors/${id}`),
contractors: `${x}/resources/contractors`,
+ consumable: (id: string) => generatePath(`${x}/consumable/${id}`),
consumables: `${x}/items/consumables`,
+ consumableCosting: (id: string) =>
+ generatePath(`${x}/consumable/${id}/costing`),
+ consumableDetails: (id: string) =>
+ generatePath(`${x}/consumable/${id}/details`),
consumableInventory: (id: string) =>
generatePath(`${x}/consumable/${id}/inventory`),
consumablePlanning: (id: string) =>
generatePath(`${x}/consumable/${id}/planning`),
+ consumablePurchasing: (id: string) =>
+ generatePath(`${x}/consumable/${id}/purchasing`),
+ consumableSuppliers: (id: string) =>
+ generatePath(`${x}/consumable/${id}/suppliers`),
convertQuoteToOrder: (id: string) =>
generatePath(`${x}/quote/${id}/convert-to-order`),
currency: (id: string) => generatePath(`${x}/accounting/currencies/${id}`),
@@ -313,6 +322,7 @@ export const path = {
generatePath(`${x}/resources/attributes/list/${id}/new`),
newChartOfAccount: `${x}/accounting/charts/new`,
newCompany: `${x}/settings/company/new`,
+ newConsumable: `${x}/consumable/new`,
newContractor: `${x}/resources/contractors/new`,
newCurrency: `${x}/accounting/currencies/new`,
newCustomer: `${x}/customer/new`,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index ef3a203849..10206a411b 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -1792,7 +1792,6 @@ export type Database = {
customFields: Json | null
id: string
itemId: string | null
- unitOfMeasureCode: string
updatedAt: string | null
updatedBy: string | null
}
@@ -1805,7 +1804,6 @@ export type Database = {
customFields?: Json | null
id: string
itemId?: string | null
- unitOfMeasureCode: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -1818,7 +1816,6 @@ export type Database = {
customFields?: Json | null
id?: string
itemId?: string | null
- unitOfMeasureCode?: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -1935,13 +1932,6 @@ export type Database = {
referencedRelation: "itemQuantities"
referencedColumns: ["itemId"]
},
- {
- foreignKeyName: "consumable_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "consumable_updatedBy_fkey"
columns: ["updatedBy"]
@@ -7721,7 +7711,6 @@ export type Database = {
itemId: string | null
materialFormId: string
materialSubstanceId: string
- unitOfMeasureCode: string
updatedAt: string | null
updatedBy: string | null
}
@@ -7739,7 +7728,6 @@ export type Database = {
itemId?: string | null
materialFormId: string
materialSubstanceId: string
- unitOfMeasureCode: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -7757,7 +7745,6 @@ export type Database = {
itemId?: string | null
materialFormId?: string
materialSubstanceId?: string
- unitOfMeasureCode?: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -7888,13 +7875,6 @@ export type Database = {
referencedRelation: "materialSubstance"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "material_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "material_updatedBy_fkey"
columns: ["updatedBy"]
@@ -19821,13 +19801,6 @@ export type Database = {
referencedRelation: "itemQuantities"
referencedColumns: ["itemId"]
},
- {
- foreignKeyName: "consumable_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "consumable_updatedBy_fkey"
columns: ["updatedBy"]
@@ -21087,13 +21060,6 @@ export type Database = {
referencedRelation: "materialSubstance"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "material_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "material_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index ef3a203849..10206a411b 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -1792,7 +1792,6 @@ export type Database = {
customFields: Json | null
id: string
itemId: string | null
- unitOfMeasureCode: string
updatedAt: string | null
updatedBy: string | null
}
@@ -1805,7 +1804,6 @@ export type Database = {
customFields?: Json | null
id: string
itemId?: string | null
- unitOfMeasureCode: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -1818,7 +1816,6 @@ export type Database = {
customFields?: Json | null
id?: string
itemId?: string | null
- unitOfMeasureCode?: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -1935,13 +1932,6 @@ export type Database = {
referencedRelation: "itemQuantities"
referencedColumns: ["itemId"]
},
- {
- foreignKeyName: "consumable_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "consumable_updatedBy_fkey"
columns: ["updatedBy"]
@@ -7721,7 +7711,6 @@ export type Database = {
itemId: string | null
materialFormId: string
materialSubstanceId: string
- unitOfMeasureCode: string
updatedAt: string | null
updatedBy: string | null
}
@@ -7739,7 +7728,6 @@ export type Database = {
itemId?: string | null
materialFormId: string
materialSubstanceId: string
- unitOfMeasureCode: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -7757,7 +7745,6 @@ export type Database = {
itemId?: string | null
materialFormId?: string
materialSubstanceId?: string
- unitOfMeasureCode?: string
updatedAt?: string | null
updatedBy?: string | null
}
@@ -7888,13 +7875,6 @@ export type Database = {
referencedRelation: "materialSubstance"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "material_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "material_updatedBy_fkey"
columns: ["updatedBy"]
@@ -19821,13 +19801,6 @@ export type Database = {
referencedRelation: "itemQuantities"
referencedColumns: ["itemId"]
},
- {
- foreignKeyName: "consumable_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "consumable_updatedBy_fkey"
columns: ["updatedBy"]
@@ -21087,13 +21060,6 @@ export type Database = {
referencedRelation: "materialSubstance"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "material_unitOfMeasureCode_fkey"
- columns: ["unitOfMeasureCode", "companyId"]
- isOneToOne: false
- referencedRelation: "unitOfMeasure"
- referencedColumns: ["code", "companyId"]
- },
{
foreignKeyName: "material_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/migrations/20240608105638_consumables.sql b/packages/database/supabase/migrations/20240608105638_consumables.sql
index 18e41c374a..14ee551a22 100644
--- a/packages/database/supabase/migrations/20240608105638_consumables.sql
+++ b/packages/database/supabase/migrations/20240608105638_consumables.sql
@@ -1,7 +1,6 @@
CREATE TABLE "consumable" (
"id" TEXT NOT NULL,
"itemId" TEXT,
- "unitOfMeasureCode" TEXT NOT NULL,
"approved" BOOLEAN NOT NULL DEFAULT false,
"approvedBy" TEXT,
"customFields" JSONB,
@@ -13,7 +12,6 @@ CREATE TABLE "consumable" (
CONSTRAINT "consumable_pkey" PRIMARY KEY ("id", "companyId"),
CONSTRAINT "consumable_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE SET NULL ON UPDATE CASCADE,
- CONSTRAINT "consumable_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure"("code", "companyId") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "consumable_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),
CONSTRAINT "consumable_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),
CONSTRAINT "consumable_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),
@@ -62,6 +60,7 @@ CREATE OR REPLACE VIEW "consumables" WITH(SECURITY_INVOKER=true) AS
i.description,
i."itemGroupId",
i."itemInventoryType",
+ i."unitOfMeasureCode",
i.active,
i.blocked,
i.assignee,
@@ -79,4 +78,4 @@ CREATE OR REPLACE VIEW "consumables" WITH(SECURITY_INVOKER=true) AS
FROM "itemSupplier" s
GROUP BY "itemId"
) s ON s."itemId" = c."itemId"
- LEFT JOIN "unitOfMeasure" uom ON uom.code = c."unitOfMeasureCode" AND uom."companyId" = c."companyId";
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
diff --git a/packages/database/supabase/migrations/20240608114413_materials.sql b/packages/database/supabase/migrations/20240608114413_materials.sql
index 234aaf79ab..8c24aaa5e1 100644
--- a/packages/database/supabase/migrations/20240608114413_materials.sql
+++ b/packages/database/supabase/migrations/20240608114413_materials.sql
@@ -130,7 +130,6 @@ CREATE TABLE "material" (
"grade" TEXT,
"dimensions" TEXT,
"finish" TEXT,
- "unitOfMeasureCode" TEXT NOT NULL,
"approved" BOOLEAN NOT NULL DEFAULT false,
"approvedBy" TEXT,
"customFields" JSONB,
@@ -144,7 +143,6 @@ CREATE TABLE "material" (
CONSTRAINT "material_materialFormId_fkey" FOREIGN KEY ("materialFormId") REFERENCES "materialForm"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "material_materialSubstanceId_fkey" FOREIGN KEY ("materialSubstanceId") REFERENCES "materialSubstance"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "material_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE SET NULL ON UPDATE CASCADE,
- CONSTRAINT "material_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure"("code", "companyId") ON DELETE SET NULL ON UPDATE CASCADE,
-- unique index on itemId, materialFormId, materialSubstanceId, grade, dimensions, finish
CONSTRAINT "material_unique" UNIQUE ("itemId", "materialFormId", "materialSubstanceId", "grade", "dimensions", "finish", "companyId"),
CONSTRAINT "material_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),
@@ -199,6 +197,7 @@ CREATE OR REPLACE VIEW "materials" WITH(SECURITY_INVOKER=true) AS
i.description,
i."itemGroupId",
i."itemInventoryType",
+ i."unitOfMeasureCode",
i.active,
i.blocked,
i.assignee,
@@ -220,7 +219,7 @@ CREATE OR REPLACE VIEW "materials" WITH(SECURITY_INVOKER=true) AS
) s ON s."itemId" = m."itemId"
LEFT JOIN "materialForm" mf ON mf.id = m."materialFormId"
LEFT JOIN "materialSubstance" ms ON ms.id = m."materialSubstanceId"
- LEFT JOIN "unitOfMeasure" uom ON uom.code = m."unitOfMeasureCode" AND uom."companyId" = m."companyId";
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
INSERT INTO "materialSubstance" ("name", "createdBy")