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 batch properties to each item inventory screen

Brad Barbin6bc566dd2ff8
diff --git a/apps/erp/app/components/Documents.tsx b/apps/erp/app/components/Documents.tsx
index 19e360c802..cda2536d4e 100644
--- a/apps/erp/app/components/Documents.tsx
+++ b/apps/erp/app/components/Documents.tsx
@@ -38,8 +38,8 @@ import { stripSpecialCharacters } from "~/utils/string";
type DocumentsProps = {
files: StorageItem[];
modelUpload?: ModelUpload;
- sourceDocument: "Job";
- sourceDocumentId: string;
+ sourceDocument?: "Job";
+ sourceDocumentId?: string;
sourceDocumentLineId?: string;
writeBucket: string;
writeBucketPermission: string;
@@ -145,7 +145,7 @@ const Documents = ({
);
const deleteModel = useCallback(async () => {
- if (!carbon) return;
+ if (!carbon || !sourceDocumentId) return;
if (sourceDocument === "Job") {
const result = await carbon
@@ -213,7 +213,11 @@ const Documents = ({
if (fileUpload.error) {
toast.error(`Failed to upload file: ${file.name}`);
- } else if (fileUpload.data?.path) {
+ } else if (
+ fileUpload.data?.path &&
+ sourceDocument &&
+ sourceDocumentId
+ ) {
toast.success(`Uploaded: ${file.name}`);
const formData = new FormData();
formData.append("path", fileUpload.data.path);
@@ -254,7 +258,9 @@ const Documents = ({
<HStack className="justify-between items-start">
<CardHeader>
<CardTitle>Files</CardTitle>
- <CardDescription>{sourceDocument} documents</CardDescription>
+ {sourceDocument && (
+ <CardDescription>{sourceDocument} documents</CardDescription>
+ )}
</CardHeader>
<CardAction>
<File
diff --git a/apps/erp/app/components/Hyperlink.tsx b/apps/erp/app/components/Hyperlink.tsx
index 3e4f1d21f2..5aae94fd86 100644
--- a/apps/erp/app/components/Hyperlink.tsx
+++ b/apps/erp/app/components/Hyperlink.tsx
@@ -1,7 +1,8 @@
-import { cn } from "@carbon/react";
+import { Button, cn } from "@carbon/react";
import type { LinkProps } from "@remix-run/react";
import { Link } from "@remix-run/react";
import type { ComponentProps, PropsWithChildren } from "react";
+import { LuSquareArrowOutUpRight } from "react-icons/lu";
const Hyperlink = ({
children,
@@ -14,12 +15,20 @@ const Hyperlink = ({
<Link
prefetch="intent"
className={cn(
- "text-foreground font-medium cursor-pointer hover:underline",
+ "group/hyperlink text-foreground font-medium cursor-pointer flex flex-row items-center justify-between gap-2",
className
)}
{...props}
>
- {children}
+ <span className="flex-1">{children}</span>
+ <Button
+ leftIcon={<LuSquareArrowOutUpRight />}
+ variant="secondary"
+ className="opacity-0 transition-opacity duration-200 group-hover/hyperlink:opacity-100 no-underline"
+ size="sm"
+ >
+ Open
+ </Button>
</Link>
) : (
<span className={cn("text-foreground", className)} {...props}>
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsx
index a1cc01368e..6b0104bef2 100644
--- a/apps/erp/app/components/Table/Table.tsx
+++ b/apps/erp/app/components/Table/Table.tsx
@@ -636,8 +636,8 @@ const Table = <T extends object>({
</TableBase>
</div>
) : hasFilters ? (
- <div className="flex flex-col w-full h-full items-center justify-start gap-4 pt-[15dvh]">
- <div className="flex justify-center items-center h-12 w-12 rounded-full bg-foreground text-background">
+ <div className="flex flex-col w-full h-full items-center justify-center gap-4">
+ <div className="flex justify-center items-center h-12 w-12 rounded-full bg-foreground text-background -mt-[10dvh]">
<LuTriangleAlert className="h-6 w-6 flex-shrink-0" />
</div>
<span className="text-xs font-mono font-light text-foreground uppercase">
@@ -648,8 +648,8 @@ const Table = <T extends object>({
</Button>
</div>
) : (
- <div className="flex flex-col w-full h-full items-center justify-start gap-4 pt-[15dvh]">
- <div className="flex justify-center items-center h-12 w-12 rounded-full bg-foreground text-background">
+ <div className="flex flex-col w-full h-full items-center justify-center gap-4">
+ <div className="flex justify-center items-center h-12 w-12 rounded-full bg-foreground text-background -mt-[10dvh]">
<LuTriangleAlert className="h-6 w-6 flex-shrink-0" />
</div>
<span className="text-xs font-mono font-light text-foreground uppercase">
diff --git a/apps/erp/app/modules/inventory/Batches/BatchHeader.tsx b/apps/erp/app/modules/inventory/Batches/BatchHeader.tsx
new file mode 100644
index 0000000000..279fb95392
--- /dev/null
+++ b/apps/erp/app/modules/inventory/Batches/BatchHeader.tsx
@@ -0,0 +1,38 @@
+import { HStack, Heading } from "@carbon/react";
+import { Link, useParams } from "@remix-run/react";
+import { Copy } from "~/components";
+import { useRouteData } from "~/hooks";
+import type { BatchDetails } from "~/modules/inventory";
+import { path } from "~/utils/path";
+
+const BatchHeader = () => {
+ const { batchId } = useParams();
+ if (!batchId) throw new Error("batchId not found");
+
+ const routeData = useRouteData<{
+ batch: BatchDetails;
+ }>(path.to.batch(batchId));
+
+ if (!routeData?.batch) throw new Error("Failed to load batch");
+ const { batch } = routeData;
+
+ return (
+ <>
+ <div className="flex flex-shrink-0 items-center justify-between py-2 px-4 bg-card border-b border-border h-[50px] overflow-x-auto scrollbar-hide dark:border-none dark:shadow-[inset_0_0_1px_rgb(255_255_255_/_0.24),_0_0_0_0.5px_rgb(0,0,0,1),0px_0px_4px_rgba(0,_0,_0,_0.08),_0px_0px_10px_rgba(0,_0,_0,_0.12),_0px_0px_24px_rgba(0,_0,_0,_0.16),_0px_0px_80px_rgba(0,_0,_0,_0.2)]">
+ <HStack className="w-full justify-between">
+ <HStack>
+ <Link to={path.to.batch(batchId)}>
+ <Heading size="h4" className="flex items-center gap-2">
+ <span>Batch {batch.number}</span>
+ </Heading>
+ </Link>
+ <Copy text={batch?.number ?? ""} />
+ </HStack>
+ <HStack></HStack>
+ </HStack>
+ </div>
+ </>
+ );
+};
+
+export default BatchHeader;
diff --git a/apps/erp/app/modules/inventory/Batches/BatchProperties.tsx b/apps/erp/app/modules/inventory/Batches/BatchProperties.tsx
new file mode 100644
index 0000000000..9624a185c6
--- /dev/null
+++ b/apps/erp/app/modules/inventory/Batches/BatchProperties.tsx
@@ -0,0 +1,496 @@
+import {
+ Array as ArrayInput,
+ Hidden,
+ Input,
+ Select,
+ Submit,
+ ValidatedForm,
+} from "@carbon/form";
+import {
+ Button,
+ ClientOnly,
+ cn,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+ HStack,
+ IconButton,
+ ModalCard,
+ ModalCardBody,
+ ModalCardHeader,
+ ModalCardProvider,
+ ModalCardTitle,
+ toast,
+ useDisclosure,
+ VStack,
+} from "@carbon/react";
+import { formatRelativeTime } from "@carbon/utils";
+import type { DragEndEvent, DragStartEvent } from "@dnd-kit/core";
+import {
+ DndContext,
+ DragOverlay,
+ KeyboardSensor,
+ MouseSensor,
+ TouchSensor,
+ useSensor,
+ useSensors,
+} from "@dnd-kit/core";
+import { SortableContext, useSortable } from "@dnd-kit/sortable";
+import { CSS } from "@dnd-kit/utilities";
+import {
+ useFetcher,
+ useFetchers,
+ useParams,
+ useSubmit,
+} from "@remix-run/react";
+import { useEffect, useRef, useState } from "react";
+import { createPortal } from "react-dom";
+import {
+ LuCirclePlus,
+ LuEllipsisVertical,
+ LuGripVertical,
+} from "react-icons/lu";
+import { EmployeeAvatar } from "~/components";
+import { ConfiguratorDataTypeIcon } from "~/components/Configurator/Icons";
+import { ConfirmDelete } from "~/components/Modals";
+import { configurationParameterDataTypes } from "~/modules/items/items.models";
+import type { action as batchPropertyAction } from "~/routes/x+/inventory+/batch-property+/$itemId.property";
+import { path } from "~/utils/path";
+import { capitalize } from "~/utils/string";
+import { batchPropertyValidator } from "../inventory.models";
+import type { BatchProperty } from "../types";
+
+export default function BatchPropertiesForm({
+ properties: initialProperties,
+ type = "card",
+ onClose,
+}: {
+ properties: BatchProperty[];
+ type?: "card" | "modal";
+ onClose?: () => void;
+}) {
+ const { isList, itemId, onChangeCheckForListType, setIsList } =
+ useBatchProperties();
+
+ const submit = useSubmit();
+ const fetcher = useFetcher<typeof batchPropertyAction>();
+
+ useEffect(() => {
+ if (fetcher.data?.success === false) {
+ toast.error("Failed to update batch property");
+ }
+ }, [fetcher.data]);
+
+ const propertiesById = new Map<string, BatchProperty>(
+ initialProperties.map((property) => [property.id, property])
+ );
+
+ const pendingProperties = usePendingProperties({ itemId });
+
+ // merge pending properties and existing properties
+ for (let pendingProperty of pendingProperties) {
+ let property = propertiesById.get(pendingProperty.id);
+ if (property) {
+ propertiesById.set(pendingProperty.id, {
+ ...property,
+ ...pendingProperty,
+ });
+ }
+ }
+
+ const properties = Array.from(propertiesById.values()).sort(
+ (a, b) => a.sortOrder - b.sortOrder
+ );
+ const [activeProperty, setActiveProperty] = useState<BatchProperty | null>(
+ null
+ );
+
+ const sensors = useSensors(
+ useSensor(MouseSensor),
+ useSensor(TouchSensor),
+ useSensor(KeyboardSensor)
+ );
+
+ return (
+ <ModalCardProvider type={type}>
+ <ModalCard onClose={onClose}>
+ <ModalCardHeader>
+ <ModalCardTitle>Batch Properties</ModalCardTitle>
+ </ModalCardHeader>
+
+ <ModalCardBody>
+ <div className="flex flex-col gap-4">
+ <div className="p-6 border rounded-lg">
+ <ValidatedForm
+ action={path.to.batchProperty(itemId)}
+ method="post"
+ fetcher={fetcher}
+ validator={batchPropertyValidator}
+ resetAfterSubmit
+ onSubmit={() => {
+ setIsList(false);
+ }}
+ defaultValues={{
+ itemId: itemId,
+ label: "",
+ dataType: "text",
+ listOptions: [],
+ }}
+ className="w-full"
+ >
+ <Hidden name="id" />
+ <Hidden name="itemId" />
+ <VStack spacing={4}>
+ <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">
+ <VStack>
+ <Input name="label" label="Label" />
+ </VStack>
+
+ <Select
+ name="dataType"
+ label="Data Type"
+ options={configurationParameterDataTypes.map((type) => ({
+ label: (
+ <HStack className="w-full">
+ <ConfiguratorDataTypeIcon
+ type={type}
+ className="mr-2"
+ />
+ {capitalize(type)}
+ </HStack>
+ ),
+ value: type,
+ }))}
+ onChange={onChangeCheckForListType}
+ />
+ {isList && (
+ <ArrayInput name="listOptions" label="List Options" />
+ )}
+ </div>
+ <HStack spacing={2}>
+ <Submit
+ leftIcon={<LuCirclePlus />}
+ isDisabled={fetcher.state !== "idle"}
+ isLoading={fetcher.state !== "idle"}
+ >
+ Add Property
+ </Submit>
+ </HStack>
+ </VStack>
+ </ValidatedForm>
+ </div>
+
+ {properties.length > 0 && (
+ <DndContext
+ sensors={sensors}
+ onDragStart={onDragStart}
+ onDragEnd={onDragEnd}
+ >
+ <SortableContext items={properties.map((p) => p.id)}>
+ <div className="flex flex-col gap-2">
+ {properties.map((property) => (
+ <BatchPropertyComponent
+ key={property.id}
+ property={property}
+ />
+ ))}
+ </div>
+ </SortableContext>
+ <ClientOnly fallback={null}>
+ {() =>
+ createPortal(
+ <DragOverlay>
+ {activeProperty && (
+ <BatchPropertyComponent
+ property={activeProperty}
+ isOverlay
+ />
+ )}
+ </DragOverlay>,
+ document.body
+ )
+ }
+ </ClientOnly>
+ </DndContext>
+ )}
+ </div>
+ </ModalCardBody>
+ </ModalCard>
+ </ModalCardProvider>
+ );
+
+ function onDragStart(event: DragStartEvent) {
+ const { active } = event;
+ const activeProperty = properties.find((p) => p.id === active.id);
+ if (activeProperty) {
+ setActiveProperty(activeProperty);
+ }
+ }
+
+ function onDragEnd(event: DragEndEvent) {
+ setActiveProperty(null);
+
+ const { active, over } = event;
+
+ if (!over) return;
+
+ const activeId = active.id;
+ const overId = over.id;
+
+ if (activeId === overId) return;
+
+ const activeIndex = properties.findIndex((p) => p.id === activeId);
+ const overIndex = properties.findIndex((p) => p.id === overId);
+
+ if (activeIndex === -1 || overIndex === -1) return;
+
+ const activeProperty = properties[activeIndex];
+ const overProperty = properties[overIndex];
+
+ let newSortOrder: number;
+
+ if (activeIndex > overIndex) {
+ // Moving up
+ const prevProperty = properties[overIndex - 1];
+ newSortOrder = prevProperty
+ ? (prevProperty.sortOrder + overProperty.sortOrder) / 2
+ : overProperty.sortOrder / 2;
+ } else {
+ // Moving down
+ const nextProperty = properties[overIndex + 1];
+ newSortOrder = nextProperty
+ ? (overProperty.sortOrder + nextProperty.sortOrder) / 2
+ : overProperty.sortOrder + 1;
+ }
+
+ submit(
+ {
+ id: activeProperty.id,
+ sortOrder: newSortOrder,
+ },
+ {
+ method: "post",
+ action: path.to.batchPropertyOrder(itemId),
+ navigate: false,
+ }
+ );
+ }
+}
+
+function BatchPropertyComponent({
+ property,
+ isOverlay,
+}: {
+ property: BatchProperty;
+ isOverlay?: boolean;
+}) {
+ const { isList, onChangeCheckForListType } = useBatchProperties(property);
+
+ const disclosure = useDisclosure();
+ const deletePropertyDisclosure = useDisclosure();
+ const submitted = useRef(false);
+ const fetcher = useFetcher<typeof batchPropertyAction>();
+
+ const {
+ attributes,
+ listeners,
+ setNodeRef,
+ transform,
+ transition,
+ isDragging,
+ } = useSortable({
+ id: property.id,
+ });
+
+ const style = {
+ transform: CSS.Transform.toString(transform),
+ transition,
+ };
+
+ useEffect(() => {
+ if (submitted.current && fetcher.state === "idle") {
+ disclosure.onClose();
+ submitted.current = false;
+ }
+ }, [disclosure, fetcher.state]);
+
+ const isUpdated = property.updatedBy !== null;
+ const person = isUpdated ? property.updatedBy : property.createdBy;
+ const date = property.updatedAt ?? property.createdAt;
+
+ return (
+ <div
+ ref={setNodeRef}
+ style={style}
+ className={cn(
+ "p-4 bg-card border rounded-lg",
+ isOverlay ? "ring-2 ring-primary" : isDragging && "opacity-30"
+ )}
+ >
+ {disclosure.isOpen ? (
+ <ValidatedForm
+ action={path.to.batchProperty(property.itemId)}
+ method="post"
+ validator={batchPropertyValidator}
+ fetcher={fetcher}
+ resetAfterSubmit
+ onSubmit={() => {
+ disclosure.onClose();
+ }}
+ defaultValues={{
+ id: property.id,
+ itemId: property.itemId,
+ label: property.label,
+ dataType: property.dataType,
+ listOptions: property.listOptions ?? [],
+ }}
+ >
+ <Hidden name="id" />
+ <Hidden name="itemId" />
+
+ <VStack spacing={4}>
+ <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">
+ <VStack>
+ <Input name="label" label="Label" autoFocus />
+ </VStack>
+
+ <Select
+ name="dataType"
+ label="Data Type"
+ options={configurationParameterDataTypes.map((type) => ({
+ label: (
+ <HStack className="w-full">
+ <ConfiguratorDataTypeIcon type={type} className="mr-2" />
+ {capitalize(type)}
+ </HStack>
+ ),
+ value: type,
+ }))}
+ onChange={onChangeCheckForListType}
+ />
+ {isList && <ArrayInput name="listOptions" label="List Options" />}
+ </div>
+ <HStack className="w-full justify-end" spacing={2}>
+ <Button variant="secondary" onClick={disclosure.onClose}>
+ Cancel
+ </Button>
+ <Submit
+ isDisabled={fetcher.state !== "idle"}
+ isLoading={fetcher.state !== "idle"}
+ >
+ Save
+ </Submit>
+ </HStack>
+ </VStack>
+ </ValidatedForm>
+ ) : (
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={2} className="w-1/2">
+ <IconButton
+ aria-label="Reorder"
+ icon={<LuGripVertical />}
+ variant="ghost"
+ {...attributes}
+ {...listeners}
+ className="cursor-grab"
+ />
+ <HStack spacing={4} className="flex-1">
+ <div className="bg-muted border rounded-full flex items-center justify-center p-2">
+ <ConfiguratorDataTypeIcon
+ type={property.dataType}
+ className="w-4 h-4"
+ />
+ </div>
+ <VStack spacing={0}>
+ <span className="text-sm font-medium">{property.label}</span>
+ </VStack>
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ {isUpdated ? "Updated" : "Created"} {formatRelativeTime(date)}
+ </span>
+ <EmployeeAvatar employeeId={person} withName={false} />
+ </HStack>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="Open menu"
+ icon={<LuEllipsisVertical />}
+ variant="ghost"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={disclosure.onOpen}>
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ destructive
+ onClick={deletePropertyDisclosure.onOpen}
+ >
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </div>
+ )}
+ {deletePropertyDisclosure.isOpen && (
+ <ConfirmDelete
+ action={path.to.deleteBatchProperty(property.itemId, property.id)}
+ isOpen={deletePropertyDisclosure.isOpen}
+ name={property.label}
+ text={`Are you sure you want to delete the ${property.label} property?`}
+ onCancel={() => {
+ deletePropertyDisclosure.onClose();
+ }}
+ onSubmit={() => {
+ deletePropertyDisclosure.onClose();
+ }}
+ />
+ )}
+ </div>
+ );
+}
+
+function useBatchProperties(property?: BatchProperty) {
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const [isList, setIsList] = useState(property?.dataType === "list");
+
+ const onChangeCheckForListType = (
+ newValue: {
+ value: string;
+ label: string | JSX.Element;
+ } | null
+ ) => {
+ if (!newValue) return;
+ const type = newValue.value;
+ setIsList(type === "list");
+ };
+
+ return {
+ isList,
+ itemId,
+ onChangeCheckForListType,
+ setIsList,
+ };
+}
+
+function usePendingProperties({ itemId }: { itemId: string }) {
+ type PendingItem = ReturnType<typeof useFetchers>[number] & {
+ formData: FormData;
+ };
+ return useFetchers()
+ .filter((fetcher): fetcher is PendingItem => {
+ return fetcher.formAction === path.to.batchPropertyOrder(itemId);
+ })
+ .map((fetcher) => {
+ let id = String(fetcher.formData.get("id"));
+ let sortOrder = Number(fetcher.formData.get("sortOrder"));
+ return { id, sortOrder };
+ });
+}
diff --git a/apps/erp/app/modules/inventory/Batches/BatchesTable.tsx b/apps/erp/app/modules/inventory/Batches/BatchesTable.tsx
index 219b412e1b..c6f886bb3f 100644
--- a/apps/erp/app/modules/inventory/Batches/BatchesTable.tsx
+++ b/apps/erp/app/modules/inventory/Batches/BatchesTable.tsx
@@ -1,4 +1,4 @@
-import { MenuIcon, MenuItem, VStack } from "@carbon/react";
+import { Badge, MenuIcon, MenuItem, VStack } from "@carbon/react";
import { formatDate } from "@carbon/utils";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
@@ -9,8 +9,9 @@ import {
LuCalendar,
LuContainer,
LuPencil,
+ LuTruck,
} from "react-icons/lu";
-import { Hyperlink, New, SupplierAvatar, Table } from "~/components";
+import { Hyperlink, SupplierAvatar, Table } from "~/components";
import { usePermissions } from "~/hooks";
import type { BatchTableRow } from "~/modules/inventory";
import { useItems, useSuppliers } from "~/stores";
@@ -64,6 +65,26 @@ const BatchesTable = memo(({ data, count }: BatchesTableProps) => {
},
},
},
+ {
+ accessorKey: "source",
+ header: "Source",
+ cell: ({ row }) =>
+ row.original.source === "Purchased" ? (
+ <Badge variant="green">Purchased</Badge>
+ ) : (
+ <Badge variant="blue">Manufactured</Badge>
+ ),
+ meta: {
+ icon: <LuTruck />,
+ filter: {
+ type: "static",
+ options: [
+ { value: "Purchased", label: "Purchased" },
+ { value: "Manufactured", label: "Manufactured" },
+ ],
+ },
+ },
+ },
{
accessorKey: "supplierId",
header: "Supplier",
@@ -130,11 +151,6 @@ const BatchesTable = memo(({ data, count }: BatchesTableProps) => {
defaultColumnPinning={{
left: ["batchId"],
}}
- primaryAction={
- permissions.can("create", "inventory") && (
- <New label="Batch" to={path.to.newBatch} />
- )
- }
renderContextMenu={renderContextMenu}
title="Batches"
/>
diff --git a/apps/erp/app/modules/inventory/inventory.models.ts b/apps/erp/app/modules/inventory/inventory.models.ts
index ab7a7c07ef..68a8d76536 100644
--- a/apps/erp/app/modules/inventory/inventory.models.ts
+++ b/apps/erp/app/modules/inventory/inventory.models.ts
@@ -1,5 +1,6 @@
import { z } from "zod";
import { zfd } from "zod-form-data";
+import { configurationParameterDataTypes } from "../items/items.models";
export const itemTypes = [
"Part",
@@ -41,6 +42,39 @@ export const itemLedgerDocumentTypes = [
"Direct Transfer",
] as const;
+export const batchPropertyValidator = z
+ .object({
+ id: zfd.text(z.string().optional()),
+ itemId: z.string().min(1, { message: "Item ID is required" }),
+ label: z.string().min(1, { message: "Label is required" }),
+ dataType: z.enum(configurationParameterDataTypes),
+ listOptions: z.string().min(1).array().optional(),
+ configurationParameterGroupId: z.string().optional(),
+ })
+ .refine(
+ (data) => {
+ if (data.dataType === "list") {
+ return !!data.listOptions;
+ }
+ return true;
+ },
+ { message: "List options are required", path: ["listOptions"] }
+ )
+ .refine(
+ (data) => {
+ return data.label.match(/^[a-zA-Z0-9 ]+$/);
+ },
+ {
+ message: "Only alphanumeric characters and spaces are allowed",
+ path: ["label"],
+ }
+ );
+
+export const batchPropertyOrderValidator = z.object({
+ id: z.string().min(1, { message: "ID is required" }),
+ sortOrder: zfd.numeric(z.number().min(0)),
+});
+
export const inventoryAdjustmentValidator = z.object({
itemId: z.string().min(1, { message: "Item ID is required" }),
locationId: z.string().min(20, { message: "Location is required" }),
diff --git a/apps/erp/app/modules/inventory/inventory.service.ts b/apps/erp/app/modules/inventory/inventory.service.ts
index 1b70bf12ef..136df89c09 100644
--- a/apps/erp/app/modules/inventory/inventory.service.ts
+++ b/apps/erp/app/modules/inventory/inventory.service.ts
@@ -8,6 +8,8 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import type {
+ batchPropertyOrderValidator,
+ batchPropertyValidator,
inventoryAdjustmentValidator,
receiptValidator,
shelfValidator,
@@ -76,6 +78,22 @@ export async function insertManualInventoryAdjustment(
return client.from("itemLedger").insert([data]).select("*").single();
}
+export async function getBatch(
+ client: SupabaseClient<Database>,
+ batchId: string,
+ companyId: string
+) {
+ return client
+ .from("batchNumber")
+ .select(
+ "*, item(id, name, readableId), receiptLineTracking(*, receipt(*)), jobMaterialTracking(*, jobMaterial(job(id, jobId))), jobProductionTracking(*)"
+ )
+ .eq("id", batchId)
+ .eq("companyId", companyId)
+ .eq("receiptLineTracking.posted", true)
+ .single();
+}
+
export async function getBatches(
client: SupabaseClient<Database>,
companyId: string,
@@ -102,6 +120,38 @@ export async function getBatches(
return query;
}
+export async function getBatchFiles(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args: {
+ receiptLineIds: string[];
+ batchId: string;
+ }
+) {
+ const [batchFiles, receiptFiles] = await Promise.all([
+ client.storage
+ .from("private")
+ .list(`${companyId}/inventory/${args.batchId}`),
+ getReceiptFiles(client, companyId, args.receiptLineIds),
+ ]);
+
+ if (batchFiles.error) {
+ return batchFiles;
+ }
+
+ if (receiptFiles.error) {
+ return receiptFiles;
+ }
+
+ return {
+ data: [...batchFiles.data, ...receiptFiles.data].map((file) => ({
+ ...file,
+ bucket: "inventory",
+ })),
+ error: null,
+ };
+}
+
export async function getItemLedgerPage(
client: SupabaseClient<Database>,
itemId: string,
@@ -137,6 +187,13 @@ export async function getItemLedgerPage(
};
}
+export async function deleteBatchProperty(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("batchProperty").delete().eq("id", id);
+}
+
export async function deleteReceipt(
client: SupabaseClient<Database>,
receiptId: string
@@ -154,6 +211,18 @@ export async function deleteShippingMethod(
.eq("id", shippingMethodId);
}
+export async function getBatchProperties(
+ client: SupabaseClient<Database>,
+ itemId: string,
+ companyId: string
+) {
+ return client
+ .from("batchProperty")
+ .select("*")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId);
+}
+
export async function getInventoryItems(
client: SupabaseClient<Database>,
locationId: string,
@@ -404,6 +473,46 @@ export async function getShippingTermsList(
.order("name", { ascending: true });
}
+export async function updateBatchPropertyOrder(
+ client: SupabaseClient<Database>,
+ data: Omit<
+ z.infer<typeof batchPropertyOrderValidator>,
+ "batchPropertyGroupId"
+ > & {
+ batchPropertyGroupId?: string | null;
+ updatedBy: string;
+ }
+) {
+ return client.from("batchProperty").update(sanitize(data)).eq("id", data.id);
+}
+
+export async function upsertBatchProperty(
+ client: SupabaseClient<Database>,
+ batchProperty: z.infer<typeof batchPropertyValidator> & {
+ companyId: string;
+ userId: string;
+ }
+) {
+ const { userId, ...data } = batchProperty;
+ if (batchProperty.id) {
+ return client
+ .from("batchProperty")
+ .update(
+ sanitize({
+ ...data,
+ updatedBy: userId,
+ updatedAt: new Date().toISOString(),
+ })
+ )
+ .eq("id", batchProperty.id);
+ }
+
+ return client.from("batchProperty").insert({
+ ...data,
+ createdBy: userId,
+ });
+}
+
export async function upsertReceipt(
client: SupabaseClient<Database>,
receipt:
diff --git a/apps/erp/app/modules/inventory/types.ts b/apps/erp/app/modules/inventory/types.ts
index 61b0d023a7..aa820c3c8c 100644
--- a/apps/erp/app/modules/inventory/types.ts
+++ b/apps/erp/app/modules/inventory/types.ts
@@ -1,6 +1,8 @@
import type { Database } from "@carbon/database";
import type {
+ getBatch,
getBatches,
+ getBatchProperties,
getInventoryItems,
getItemLedgerPage,
getReceiptLines,
@@ -9,6 +11,14 @@ import type {
getShippingMethods,
} from "./inventory.service";
+export type BatchDetails = NonNullable<
+ Awaited<ReturnType<typeof getBatch>>["data"]
+>;
+
+export type BatchProperty = NonNullable<
+ Awaited<ReturnType<typeof getBatchProperties>>["data"]
+>[number];
+
export type BatchTableRow = NonNullable<
Awaited<ReturnType<typeof getBatches>>["data"]
>[number];
diff --git a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx
index 2689e271ac..04adc91512 100644
--- a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx
+++ b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx
@@ -750,7 +750,7 @@ function Shelf({
if (!locationId) return null;
return (
- <div className="flex flex-col items-start gap-1 min-w-[140px]">
+ <div className="flex flex-col items-start gap-1 min-w-[140px] text-sm">
<label className="text-xs text-muted-foreground">Shelf</label>
<Combobox
value={shelfId ?? undefined}
diff --git a/apps/erp/app/routes/x+/batch+/$batchId.tsx b/apps/erp/app/routes/x+/batch+/$batchId.tsx
new file mode 100644
index 0000000000..d5b9ad2fbc
--- /dev/null
+++ b/apps/erp/app/routes/x+/batch+/$batchId.tsx
@@ -0,0 +1,600 @@
+import { error, getCarbonServiceRole, useCarbon } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type { JSONContent } from "@carbon/react";
+import {
+ Badge,
+ Card,
+ CardAction,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+ HStack,
+ IconButton,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ toast,
+ useDebounce,
+ VStack,
+} from "@carbon/react";
+import { Editor, generateHTML } from "@carbon/react/Editor";
+import { useRouteData } from "@carbon/remix";
+import { formatDate, formatRelativeTime } from "@carbon/utils";
+import { Await, Link, useLoaderData, useParams } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
+import { nanoid } from "nanoid";
+import { Suspense, useState } from "react";
+import {
+ LuEllipsisVertical,
+ LuFactory,
+ LuHammer,
+ LuHandCoins,
+ LuTruck,
+} from "react-icons/lu";
+import {
+ Documents,
+ EmployeeAvatar,
+ Empty,
+ Hyperlink,
+ SupplierAvatar,
+} from "~/components";
+import { usePermissions, useUser } from "~/hooks";
+import type { BatchDetails } from "~/modules/inventory";
+import BatchHeader from "~/modules/inventory/Batches/BatchHeader";
+import { getBatch, getBatchFiles } from "~/modules/inventory/inventory.service";
+import type { Handle } from "~/utils/handle";
+import { getPrivateUrl, path } from "~/utils/path";
+
+export const handle: Handle = {
+ breadcrumb: "Batches",
+ to: path.to.batches,
+ module: "inventory",
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { companyId } = await requirePermissions(request, {
+ view: "inventory",
+ });
+
+ const serviceRole = await getCarbonServiceRole();
+
+ const { batchId } = params;
+ if (!batchId) throw new Error("Batch ID is required");
+
+ const batch = await getBatch(serviceRole, batchId, companyId);
+ if (batch.error) {
+ throw redirect(
+ path.to.batches,
+ await flash(request, error(batch.error, "Failed to load batch"))
+ );
+ }
+
+ const receiptLineIds = batch.data.receiptLineTracking.map(
+ (receiptLine) => receiptLine.receiptLineId
+ );
+
+ return defer({
+ batch: batch.data,
+ receiptFiles: getBatchFiles(serviceRole, companyId, {
+ receiptLineIds,
+ batchId,
+ }) ?? { data: [], error: null },
+ });
+}
+
+export default function BatchDetailRoute() {
+ const { receiptFiles } = useLoaderData<typeof loader>();
+ const { batchId } = useParams();
+ if (!batchId) throw new Error("Could not find batchId");
+
+ return (
+ <div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
+ <BatchHeader />
+ <div className="flex h-[calc(100dvh-99px)] overflow-y-auto scrollbar-hide w-full">
+ <VStack
+ spacing={4}
+ className="h-full p-2 w-full max-w-5xl mx-auto pb-32"
+ >
+ <BatchSummary />
+ <BatchTransactions />
+ <Suspense fallback={null}>
+ <Await resolve={receiptFiles}>
+ {(files) => (
+ <Documents
+ writeBucket="inventory"
+ writeBucketPermission="inventory"
+ files={files.data ?? []}
+ sourceDocumentId={batchId}
+ />
+ )}
+ </Await>
+ </Suspense>
+ <BatchNotes />
+ </VStack>
+ </div>
+ </div>
+ );
+}
+
+function BatchSummary() {
+ const { batchId } = useParams();
+ if (!batchId) throw new Error("Could not find batchId");
+
+ const routeData = useRouteData<{
+ batch: BatchDetails;
+ }>(path.to.batch(batchId));
+
+ if (!routeData?.batch) return null;
+
+ const { batch } = routeData;
+
+ return (
+ <Card>
+ <CardHeader>
+ <HStack className="justify-between items-center">
+ <div className="flex flex-col gap-1">
+ <CardTitle>{batch.item.readableId}</CardTitle>
+ <CardDescription className="flex flex-col gap-2">
+ <span>{batch.item.name}</span>
+ <div>
+ {batch.source === "Purchased" ? (
+ <Badge variant="green">Purchased</Badge>
+ ) : (
+ <Badge variant="blue">Manufactured</Badge>
+ )}
+ </div>
+ </CardDescription>
+ </div>
+ <div className="flex flex-col gap-1 items-end">
+ <SupplierAvatar supplierId={batch.supplierId ?? null} />
+ {batch.manufacturingDate && (
+ <span className="text-muted-foreground text-sm">
+ Manufactured {formatDate(batch.manufacturingDate)}
+ </span>
+ )}
+ {batch.expirationDate && (
+ <span className="text-muted-foreground text-sm">
+ Expires {formatDate(batch.expirationDate)}
+ </span>
+ )}
+ </div>
+ </HStack>
+ </CardHeader>
+ <CardContent>
+ <VStack></VStack>
+ </CardContent>
+ </Card>
+ );
+}
+
+function BatchTransactions() {
+ const { batchId } = useParams();
+ if (!batchId) throw new Error("Could not find batchId");
+
+ const routeData = useRouteData<{
+ batch: BatchDetails;
+ }>(path.to.batch(batchId));
+
+ if (!routeData?.batch) return null;
+
+ const { batch } = routeData;
+
+ // Combine all tracking types and sort by time
+ const allTransactions = [
+ ...batch.receiptLineTracking.map((tracking) => ({
+ ...tracking,
+ type: "received" as const,
+ })),
+ ...(batch.jobMaterialTracking || []).map((tracking) => ({
+ ...tracking,
+ type: "consumed" as const,
+ })),
+ ...(batch.jobProductionTracking || []).map((tracking) => ({
+ ...tracking,
+ type: "produced" as const,
+ })),
+ ].sort(
+ (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
+ );
+
+ return (
+ <Card>
+ <Tabs defaultValue="all">
+ <HStack className="justify-between w-full">
+ <CardHeader>
+ <CardTitle>Transactions</CardTitle>
+ </CardHeader>
+ <CardAction>
+ <TabsList>
+ <TabsTrigger value="all">All</TabsTrigger>
+ <TabsTrigger value="received">Received</TabsTrigger>
+ <TabsTrigger value="consumed">Consumed</TabsTrigger>
+ <TabsTrigger value="produced">Produced</TabsTrigger>
+ <TabsTrigger value="shipped">Shipped</TabsTrigger>
+ </TabsList>
+ </CardAction>
+ </HStack>
+ <CardContent>
+ <TabsContent className="w-full" value="all">
+ <VStack className="w-full" spacing={4}>
+ {allTransactions.length === 0 ? (
+ <Empty className="text-sm text-muted-foreground">
+ No transactions found
+ </Empty>
+ ) : (
+ allTransactions.map((transaction) => {
+ if (transaction.type === "received") {
+ return (
+ <ReceivedTransaction
+ key={transaction.id}
+ transaction={transaction}
+ />
+ );
+ }
+ if (transaction.type === "consumed") {
+ return (
+ <ConsumedTransaction
+ key={transaction.id}
+ transaction={transaction}
+ />
+ );
+ }
+ if (transaction.type === "produced") {
+ return (
+ <ProducedTransaction
+ key={transaction.id}
+ transaction={transaction}
+ />
+ );
+ }
+ return null;
+ })
+ )}
+ </VStack>
+ </TabsContent>
+ <TabsContent className="w-full" value="received">
+ <VStack className="w-full" spacing={4}>
+ {batch.receiptLineTracking.length === 0 ? (
+ <Empty className="text-sm text-muted-foreground">
+ No received transactions found
+ </Empty>
+ ) : (
+ batch.receiptLineTracking.map((receiptLine) => (
+ <ReceivedTransaction
+ key={receiptLine.id}
+ transaction={{
+ ...receiptLine,
+ type: "received",
+ createdAt: receiptLine.createdAt,
+ }}
+ />
+ ))
+ )}
+ </VStack>
+ </TabsContent>
+ <TabsContent className="w-full" value="consumed">
+ <VStack className="w-full" spacing={4}>
+ {!batch.jobMaterialTracking?.length ? (
+ <Empty className="text-sm text-muted-foreground">
+ No consumed transactions found
+ </Empty>
+ ) : (
+ batch.jobMaterialTracking.map((tracking) => (
+ <ConsumedTransaction
+ key={tracking.id}
+ transaction={{
+ ...tracking,
+ type: "consumed",
+ createdAt: tracking.createdAt,
+ }}
+ />
+ ))
+ )}
+ </VStack>
+ </TabsContent>
+ <TabsContent className="w-full" value="produced">
+ <VStack className="w-full" spacing={4}>
+ {!batch.jobProductionTracking?.length ? (
+ <Empty className="text-sm text-muted-foreground">
+ No produced transactions found
+ </Empty>
+ ) : (
+ batch.jobProductionTracking.map((tracking) => (
+ <ProducedTransaction
+ key={tracking.id}
+ transaction={{
+ ...tracking,
+ type: "produced",
+ createdAt: tracking.createdAt,
+ }}
+ />
+ ))
+ )}
+ </VStack>
+ </TabsContent>
+ <TabsContent className="w-full" value="shipped">
+ <VStack>
+ <Empty className="text-sm text-muted-foreground">
+ No shipped transactions found
+ </Empty>
+ </VStack>
+ </TabsContent>
+ </CardContent>
+ </Tabs>
+ </Card>
+ );
+}
+
+function ReceivedTransaction({
+ transaction,
+}: {
+ transaction: BatchDetails["receiptLineTracking"][number] & {
+ type: "received";
+ };
+}) {
+ return (
+ <div className="flex flex-col border p-6 w-full rounded-lg">
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <HStack spacing={4} className="flex-1">
+ <TransactionIcon type="received" />
+ <VStack spacing={0}>
+ <Hyperlink
+ to={path.to.receipt(transaction.receipt.id)}
+ className="text-sm font-medium"
+ >
+ {transaction.receipt.receiptId}
+ </Hyperlink>
+ <span className="text-xs text-muted-foreground">
+ {`Received from ${transaction.receipt.sourceDocumentReadableId}`}
+ </span>
+ </VStack>
+ <span className="text-base text-muted-foreground text-right">
+ {transaction.quantity}
+ </span>
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ Created {formatRelativeTime(transaction.createdAt)}
+ </span>
+ <EmployeeAvatar
+ employeeId={transaction.createdBy}
+ withName={false}
+ />
+ </HStack>
+ <MoreMenu link={path.to.receipt(transaction.receipt.id)} />
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function ConsumedTransaction({
+ transaction,
+}: {
+ transaction: BatchDetails["jobMaterialTracking"][number] & {
+ type: "consumed";
+ };
+}) {
+ return (
+ <div className="flex flex-col border p-6 w-full rounded-lg">
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <HStack spacing={4} className="flex-1">
+ <TransactionIcon type="consumed" />
+ <VStack spacing={0}>
+ <Hyperlink
+ to={path.to.jobMaterials(transaction.jobMaterial.job?.id)}
+ className="text-sm font-medium"
+ >
+ {transaction.jobMaterial.job?.jobId}
+ </Hyperlink>
+ <span className="text-xs text-muted-foreground">
+ Consumed by Job
+ </span>
+ </VStack>
+ <span className="text-base text-muted-foreground text-right">
+ {transaction.quantity}
+ </span>
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ Created {formatRelativeTime(transaction.createdAt)}
+ </span>
+ <EmployeeAvatar
+ employeeId={transaction.createdBy}
+ withName={false}
+ />
+ </HStack>
+ <MoreMenu
+ link={path.to.jobMaterials(transaction.jobMaterial.job?.id)}
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function ProducedTransaction({
+ transaction,
+}: {
+ transaction: BatchDetails["jobProductionTracking"][number] & {
+ type: "produced";
+ };
+}) {
+ return (
+ <div className="flex flex-col border p-6 w-full rounded-lg">
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <HStack spacing={4} className="flex-1">
+ <TransactionIcon type="produced" />
+ <VStack spacing={0}>
+ <span className="text-xs text-muted-foreground">
+ Job Production
+ </span>
+ </VStack>
+ <span className="text-base text-muted-foreground text-right">
+ {transaction.quantity}
+ </span>
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ Created {formatRelativeTime(transaction.createdAt)}
+ </span>
+ <EmployeeAvatar
+ employeeId={transaction.createdBy}
+ withName={false}
+ />
+ </HStack>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+type TrasactionType = "received" | "consumed" | "produced" | "shipped";
+
+function TransactionIcon({ type }: { type: TrasactionType }) {
+ if (type === "received")
+ return (
+ <div className="bg-blue-500 text-white border rounded-full flex items-center justify-center p-2">
+ <LuHandCoins className="size-4" />
+ </div>
+ );
+ if (type === "consumed")
+ return (
+ <div className="bg-orange-500 text-white border rounded-full flex items-center justify-center p-2">
+ <LuFactory className="size-4" />
+ </div>
+ );
+ if (type === "produced")
+ return (
+ <div className="bg-emerald-500 text-zinc-900 border rounded-full flex items-center justify-center p-2">
+ <LuHammer className="size-4" />
+ </div>
+ );
+ if (type === "shipped")
+ return (
+ <div className="bg-yellow-500 text-zinc-900 border rounded-full flex items-center justify-center p-2">
+ <LuTruck className="size-4" />
+ </div>
+ );
+}
+
+function BatchNotes() {
+ const {
+ company: { id: companyId },
+ } = useUser();
+
+ const { batchId } = useParams();
+ if (!batchId) throw new Error("Could not find batchId");
+
+ const routeData = useRouteData<{
+ batch: BatchDetails;
+ }>(path.to.batch(batchId));
+
+ if (!routeData?.batch) throw new Error("Could not find batch");
+
+ const { batch } = routeData;
+
+ const { carbon } = useCarbon();
+ const permissions = usePermissions();
+ const [tab, setTab] = useState("internal");
+ const [notes, setNotes] = useState(batch.notes ?? {});
+
+ const onUploadImage = async (file: File) => {
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/inventory/${batchId}/${nanoid()}.${fileType}`;
+
+ const result = await carbon?.storage.from("private").upload(fileName, file);
+
+ if (result?.error) {
+ toast.error("Failed to upload image");
+ throw new Error(result.error.message);
+ }
+
+ if (!result?.data) {
+ throw new Error("Failed to upload image");
+ }
+
+ return getPrivateUrl(result.data.path);
+ };
+
+ const onUpdateNotes = useDebounce(
+ async (content: JSONContent) => {
+ await carbon
+ ?.from("batchNumber")
+ .update({
+ notes: content,
+ })
+ .eq("id", batchId!);
+ },
+ 2500,
+ true
+ );
+
+ return (
+ <>
+ <Card>
+ <Tabs value={tab} onValueChange={setTab}>
+ <CardHeader>
+ <CardTitle>Notes</CardTitle>
+ </CardHeader>
+
+ <CardContent>
+ {permissions.can("update", "inventory") ? (
+ <Editor
+ initialValue={(notes ?? {}) as JSONContent}
+ onUpload={onUploadImage}
+ onChange={(value) => {
+ setNotes(value);
+ onUpdateNotes(value);
+ }}
+ />
+ ) : (
+ <div
+ className="prose dark:prose-invert"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(notes as JSONContent),
+ }}
+ />
+ )}
+ </CardContent>
+ </Tabs>
+ </Card>
+ </>
+ );
+}
+
+function MoreMenu({ link }: { link: string }) {
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="Open menu"
+ icon={<LuEllipsisVertical />}
+ variant="ghost"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem asChild>
+ <Link to={link}>View</Link>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+}
diff --git a/apps/erp/app/routes/x+/batch+/_layout.tsx b/apps/erp/app/routes/x+/batch+/_layout.tsx
new file mode 100644
index 0000000000..53bf700878
--- /dev/null
+++ b/apps/erp/app/routes/x+/batch+/_layout.tsx
@@ -0,0 +1,27 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { Outlet } from "@remix-run/react";
+import type { LoaderFunctionArgs, MetaFunction } from "@vercel/remix";
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+
+export const meta: MetaFunction = () => {
+ return [{ title: "Carbon | Batch" }];
+};
+
+export const handle: Handle = {
+ breadcrumb: "Inventory",
+ to: path.to.inventory,
+ module: "inventory",
+};
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ await requirePermissions(request, {
+ view: "inventory",
+ });
+
+ return null;
+}
+
+export default function BatchRoute() {
+ return <Outlet />;
+}
diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.inventory.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.inventory.tsx
index 7f01b9b479..10bfb2a038 100644
--- a/apps/erp/app/routes/x+/consumable+/$itemId.inventory.tsx
+++ b/apps/erp/app/routes/x+/consumable+/$itemId.inventory.tsx
@@ -3,11 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import { VStack } from "@carbon/react";
-import { useLoaderData } from "@remix-run/react";
+import { Await, useLoaderData } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
+import { Suspense } from "react";
import { useRouteData } from "~/hooks";
-import { InventoryDetails } from "~/modules/inventory/ui/Inventory";
+import { getBatchProperties, InventoryDetails } from "~/modules/inventory";
+import BatchPropertiesForm from "~/modules/inventory/Batches/BatchProperties";
import type { Consumable, UnitOfMeasureListItem } from "~/modules/items";
import {
getItemQuantities,
@@ -139,11 +141,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- return json({
+ return defer({
consumableInventory: consumableInventory.data,
itemShelfQuantities: itemShelfQuantities.data,
quantities: quantities.data,
itemId,
+ batchProperties: getBatchProperties(client, itemId, companyId),
});
}
@@ -195,8 +198,13 @@ export default function ConsumableInventoryRoute() {
unitOfMeasures: UnitOfMeasureListItem[];
}>(path.to.consumableRoot);
- const { consumableInventory, itemShelfQuantities, quantities, itemId } =
- useLoaderData<typeof loader>();
+ const {
+ consumableInventory,
+ itemShelfQuantities,
+ quantities,
+ itemId,
+ batchProperties,
+ } = useLoaderData<typeof loader>();
const consumableData = useRouteData<{
consumableSummary: Consumable;
@@ -211,7 +219,7 @@ export default function ConsumableInventoryRoute() {
...getCustomFields(consumableInventory.customFields ?? {}),
};
return (
- <VStack spacing={2}>
+ <VStack spacing={2} className="p-2">
<PickMethodForm
key={initialValues.itemId}
initialValues={initialValues}
@@ -228,6 +236,18 @@ export default function ConsumableInventoryRoute() {
shelves={sharedConsumablesData?.shelves ?? []}
unitOfMeasures={sharedConsumablesData?.unitOfMeasures ?? []}
/>
+ {consumableData.consumableSummary?.itemTrackingType === "Batch" && (
+ <Suspense fallback={null}>
+ <Await resolve={batchProperties}>
+ {(resolvedProperties) => (
+ <BatchPropertiesForm
+ key={`batch-properties:${itemId}`}
+ properties={resolvedProperties.data ?? []}
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
</VStack>
);
}
diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.tsx
index 0d6953576c..85cd22f374 100644
--- a/apps/erp/app/routes/x+/consumable+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/consumable+/$itemId.tsx
@@ -1,7 +1,6 @@
import { error, getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { VStack } from "@carbon/react";
import { Outlet } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
@@ -64,13 +63,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export default function ConsumableRoute() {
return (
- <div className="flex flex-col h-[calc(100dvh-49px)] w-full overflow-hidden">
+ <div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<ConsumableHeader />
<div className="flex h-[calc(100dvh-99px)] w-full">
<div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
- <VStack spacing={2} className="p-2 w-full h-full">
- <Outlet />
- </VStack>
+ <Outlet />
</div>
<ConsumableProperties />
</div>
diff --git a/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.delete.$id.tsx b/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.delete.$id.tsx
new file mode 100644
index 0000000000..f278bf7bb2
--- /dev/null
+++ b/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.delete.$id.tsx
@@ -0,0 +1,28 @@
+import { assertIsPost, notFound } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import type { ActionFunctionArgs } from "@vercel/remix";
+import { json } from "@vercel/remix";
+import { deleteBatchProperty } from "~/modules/inventory";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client } = await requirePermissions(request, {
+ delete: "inventory",
+ });
+
+ const { id } = params;
+ if (!id) throw notFound("id not found");
+
+ const remove = await deleteBatchProperty(client, id);
+
+ if (remove.error) {
+ return json({
+ success: false,
+ error: "Failed to delete batch property",
+ });
+ }
+
+ return json({
+ success: true,
+ });
+}
diff --git a/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.order.tsx b/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.order.tsx
new file mode 100644
index 0000000000..6fe6d146eb
--- /dev/null
+++ b/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.order.tsx
@@ -0,0 +1,48 @@
+import { assertIsPost } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import {
+ batchPropertyOrderValidator,
+ updateBatchPropertyOrder,
+} from "~/modules/inventory";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "inventory",
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const formData = await request.formData();
+ const validation = await validator(batchPropertyOrderValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ console.error(validation.error);
+ return json({
+ success: false,
+ error: "Invalid form data",
+ });
+ }
+
+ const upsert = await updateBatchPropertyOrder(client, {
+ ...validation.data,
+ updatedBy: userId,
+ });
+
+ if (upsert.error) {
+ console.error(upsert.error);
+ return json({
+ success: false,
+ error: upsert.error.message,
+ });
+ }
+
+ return json({
+ success: true,
+ });
+}
diff --git a/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.tsx b/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.tsx
new file mode 100644
index 0000000000..046466a35b
--- /dev/null
+++ b/apps/erp/app/routes/x+/inventory+/batch-property+/$itemId.property.tsx
@@ -0,0 +1,49 @@
+import { assertIsPost } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import {
+ batchPropertyValidator,
+ upsertBatchProperty,
+} from "~/modules/inventory";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ update: "inventory",
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const formData = await request.formData();
+ const validation = await validator(batchPropertyValidator).validate(formData);
+
+ if (validation.error) {
+ return json({
+ success: false,
+ error: "Invalid form data",
+ });
+ }
+
+ const { listOptions, ...data } = validation.data;
+
+ const upsert = await upsertBatchProperty(client, {
+ ...data,
+ listOptions: data.dataType === "list" ? listOptions : undefined,
+ companyId,
+ userId,
+ });
+
+ if (upsert.error) {
+ console.error(upsert.error);
+ return json({
+ success: false,
+ error: upsert.error.message,
+ });
+ }
+
+ return json({
+ success: true,
+ });
+}
diff --git a/apps/erp/app/routes/x+/material+/$itemId.inventory.tsx b/apps/erp/app/routes/x+/material+/$itemId.inventory.tsx
index 50bed34cfc..dff89d4ff8 100644
--- a/apps/erp/app/routes/x+/material+/$itemId.inventory.tsx
+++ b/apps/erp/app/routes/x+/material+/$itemId.inventory.tsx
@@ -3,11 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import { VStack } from "@carbon/react";
-import { useLoaderData } from "@remix-run/react";
+import { Await, useLoaderData } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
+import { Suspense } from "react";
import { useRouteData } from "~/hooks";
-import { InventoryDetails } from "~/modules/inventory";
+import { getBatchProperties, InventoryDetails } from "~/modules/inventory";
+import BatchPropertiesForm from "~/modules/inventory/Batches/BatchProperties";
import type { Material, UnitOfMeasureListItem } from "~/modules/items";
import {
getItemQuantities,
@@ -136,11 +138,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- return json({
+ return defer({
materialInventory: materialInventory.data,
itemShelfQuantities: itemShelfQuantities.data,
quantities: quantities.data,
itemId,
+ batchProperties: getBatchProperties(client, itemId, companyId),
});
}
@@ -192,8 +195,13 @@ export default function MaterialInventoryRoute() {
unitOfMeasures: UnitOfMeasureListItem[];
}>(path.to.materialRoot);
- const { materialInventory, itemShelfQuantities, quantities, itemId } =
- useLoaderData<typeof loader>();
+ const {
+ materialInventory,
+ itemShelfQuantities,
+ quantities,
+ itemId,
+ batchProperties,
+ } = useLoaderData<typeof loader>();
const materialData = useRouteData<{
materialSummary: Material;
@@ -208,13 +216,13 @@ export default function MaterialInventoryRoute() {
...getCustomFields(materialInventory.customFields ?? {}),
};
return (
- <VStack spacing={2}>
+ <VStack spacing={2} className="p-2">
<PickMethodForm
key={initialValues.itemId}
initialValues={initialValues}
locations={sharedMaterialsData?.locations ?? []}
shelves={sharedMaterialsData?.shelves ?? []}
- type="Part"
+ type="Material"
/>
<InventoryDetails
itemShelfQuantities={itemShelfQuantities}
@@ -225,6 +233,18 @@ export default function MaterialInventoryRoute() {
shelves={sharedMaterialsData?.shelves ?? []}
unitOfMeasures={sharedMaterialsData?.unitOfMeasures ?? []}
/>
+ {materialData.materialSummary?.itemTrackingType === "Batch" && (
+ <Suspense fallback={null}>
+ <Await resolve={batchProperties}>
+ {(resolvedProperties) => (
+ <BatchPropertiesForm
+ key={`batch-properties:${itemId}`}
+ properties={resolvedProperties.data ?? []}
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
</VStack>
);
}
diff --git a/apps/erp/app/routes/x+/material+/$itemId.tsx b/apps/erp/app/routes/x+/material+/$itemId.tsx
index af8e27b391..71e8057e05 100644
--- a/apps/erp/app/routes/x+/material+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/material+/$itemId.tsx
@@ -1,7 +1,6 @@
import { error, getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { VStack } from "@carbon/react";
import { Outlet } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
@@ -70,9 +69,7 @@ export default function MaterialRoute() {
<MaterialHeader />
<div className="flex h-[calc(100dvh-99px)] w-full">
<div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
- <VStack spacing={2} className="p-2 w-full h-full">
- <Outlet />
- </VStack>
+ <Outlet />
</div>
<MaterialProperties />
</div>
diff --git a/apps/erp/app/routes/x+/part+/$itemId.inventory.tsx b/apps/erp/app/routes/x+/part+/$itemId.inventory.tsx
index 9019416e1c..3fb1a03f46 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.inventory.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.inventory.tsx
@@ -3,11 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import { VStack } from "@carbon/react";
-import { useLoaderData } from "@remix-run/react";
+import { Await, useLoaderData } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
+import { Suspense } from "react";
import { useRouteData } from "~/hooks";
-import { InventoryDetails } from "~/modules/inventory";
+import { getBatchProperties, InventoryDetails } from "~/modules/inventory";
+import BatchPropertiesForm from "~/modules/inventory/Batches/BatchProperties";
import type { PartSummary, UnitOfMeasureListItem } from "~/modules/items";
import {
getItemQuantities,
@@ -128,11 +130,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- return json({
+ return defer({
partInventory: partInventory.data,
itemShelfQuantities: itemShelfQuantities.data,
quantities: quantities.data,
itemId,
+ batchProperties: getBatchProperties(client, itemId, companyId),
});
}
@@ -184,8 +187,13 @@ export default function PartInventoryRoute() {
unitOfMeasures: UnitOfMeasureListItem[];
}>(path.to.partRoot);
- const { partInventory, itemShelfQuantities, quantities, itemId } =
- useLoaderData<typeof loader>();
+ const {
+ partInventory,
+ itemShelfQuantities,
+ quantities,
+ itemId,
+ batchProperties,
+ } = useLoaderData<typeof loader>();
const partData = useRouteData<{
partSummary: PartSummary;
@@ -216,6 +224,18 @@ export default function PartInventoryRoute() {
shelves={sharedPartsData?.shelves ?? []}
unitOfMeasures={sharedPartsData?.unitOfMeasures ?? []}
/>
+ {partData.partSummary?.itemTrackingType === "Batch" && (
+ <Suspense fallback={null}>
+ <Await resolve={batchProperties}>
+ {(resolvedProperties) => (
+ <BatchPropertiesForm
+ key={`batch-properties:${itemId}`}
+ properties={resolvedProperties.data ?? []}
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
</VStack>
);
}
diff --git a/apps/erp/app/routes/x+/part+/$itemId.tsx b/apps/erp/app/routes/x+/part+/$itemId.tsx
index 4b7e1b25ac..e44e61461c 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.tsx
@@ -1,10 +1,9 @@
import { error, getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { Outlet, useLoaderData } from "@remix-run/react";
+import { Outlet } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
-import { useRealtime } from "~/hooks";
import {
getItemFiles,
getPart,
@@ -58,10 +57,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
export default function PartRoute() {
- const { partSummary } = useLoaderData<typeof loader>();
-
- useRealtime("modelUpload", `modelPath=eq.${partSummary.modelPath}`);
-
return (
<div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<PartHeader />
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.inventory.tsx b/apps/erp/app/routes/x+/tool+/$itemId.inventory.tsx
index 752a9485a1..ef8ba10db0 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.inventory.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.inventory.tsx
@@ -3,11 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import { VStack } from "@carbon/react";
-import { useLoaderData } from "@remix-run/react";
+import { Await, useLoaderData } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
+import { Suspense } from "react";
import { useRouteData } from "~/hooks";
-import { InventoryDetails } from "~/modules/inventory";
+import { getBatchProperties, InventoryDetails } from "~/modules/inventory";
+import BatchPropertiesForm from "~/modules/inventory/Batches/BatchProperties";
import type { ToolSummary, UnitOfMeasureListItem } from "~/modules/items";
import {
getItemQuantities,
@@ -128,11 +130,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- return json({
+ return defer({
toolInventory: toolInventory.data,
itemShelfQuantities: itemShelfQuantities.data,
quantities: quantities.data,
itemId,
+ batchProperties: getBatchProperties(client, itemId, companyId),
});
}
@@ -184,8 +187,13 @@ export default function ToolInventoryRoute() {
unitOfMeasures: UnitOfMeasureListItem[];
}>(path.to.toolRoot);
- const { toolInventory, itemShelfQuantities, quantities, itemId } =
- useLoaderData<typeof loader>();
+ const {
+ toolInventory,
+ itemShelfQuantities,
+ quantities,
+ itemId,
+ batchProperties,
+ } = useLoaderData<typeof loader>();
const toolData = useRouteData<{
toolSummary: ToolSummary;
@@ -216,6 +224,18 @@ export default function ToolInventoryRoute() {
shelves={sharedToolsData?.shelves ?? []}
unitOfMeasures={sharedToolsData?.unitOfMeasures ?? []}
/>
+ {toolData.toolSummary?.itemTrackingType === "Batch" && (
+ <Suspense fallback={null}>
+ <Await resolve={batchProperties}>
+ {(resolvedProperties) => (
+ <BatchPropertiesForm
+ key={`batch-properties:${itemId}`}
+ properties={resolvedProperties.data ?? []}
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
</VStack>
);
}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.tsx
index e22f352487..b725e673ca 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.tsx
@@ -60,8 +60,10 @@ export default function ToolRoute() {
return (
<div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<ToolHeader />
- <div className="flex h-[calc(100dvh-99px)] w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
- <Outlet />
+ <div className="flex h-[calc(100dvh-99px)] w-full">
+ <div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
+ <Outlet />
+ </div>
<ToolProperties />
</div>
</div>
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 795f90a1b7..79b681bcac 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -141,7 +141,11 @@ export const path = {
attributeCategoryList: (id: string) =>
generatePath(`${x}/people/attributes/list/${id}`),
batches: `${x}/inventory/batches`,
- batch: (id: string) => generatePath(`${x}/inventory/batches/${id}`),
+ batch: (id: string) => generatePath(`${x}/batch/${id}`),
+ batchProperty: (itemId: string) =>
+ generatePath(`${x}/inventory/batch-property/${itemId}/property`),
+ batchPropertyOrder: (itemId: string) =>
+ generatePath(`${x}/inventory/batch-property/${itemId}/property/order`),
bulkEditPermissions: `${x}/users/bulk-edit-permissions`,
bulkUpdateItems: `${x}/items/update`,
bulkUpdateJob: `${x}/job/update`,
@@ -250,6 +254,10 @@ export const path = {
generatePath(`${x}/people/attribute/delete/${id}`),
deleteAttributeCategory: (id: string) =>
generatePath(`${x}/people/attributes/delete/${id}`),
+ deleteBatchProperty: (itemId: string, id: string) =>
+ generatePath(
+ `${x}/inventory/batch-property/${itemId}/property/delete/${id}`
+ ),
deleteConfigurationParameter: (itemId: string, id: string) =>
generatePath(`${x}/part/${itemId}/parameter/delete/${id}`),
deleteConfigurationParameterGroup: (itemId: string, id: string) =>
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index b43f910f8d..7aca837d60 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -4392,6 +4392,9 @@ export default {
{
$ref: "#/parameters/rowFilter.batchNumber.itemId",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.source",
+ },
{
$ref: "#/parameters/rowFilter.batchNumber.companyId",
},
@@ -4404,9 +4407,18 @@ export default {
{
$ref: "#/parameters/rowFilter.batchNumber.expirationDate",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.notes",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.properties",
+ },
{
$ref: "#/parameters/rowFilter.batchNumber.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.createdBy",
+ },
{
$ref: "#/parameters/select",
},
@@ -4475,6 +4487,9 @@ export default {
{
$ref: "#/parameters/rowFilter.batchNumber.itemId",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.source",
+ },
{
$ref: "#/parameters/rowFilter.batchNumber.companyId",
},
@@ -4487,9 +4502,18 @@ export default {
{
$ref: "#/parameters/rowFilter.batchNumber.expirationDate",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.notes",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.properties",
+ },
{
$ref: "#/parameters/rowFilter.batchNumber.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.createdBy",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -4512,6 +4536,9 @@ export default {
{
$ref: "#/parameters/rowFilter.batchNumber.itemId",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.source",
+ },
{
$ref: "#/parameters/rowFilter.batchNumber.companyId",
},
@@ -4524,9 +4551,18 @@ export default {
{
$ref: "#/parameters/rowFilter.batchNumber.expirationDate",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.notes",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.properties",
+ },
{
$ref: "#/parameters/rowFilter.batchNumber.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.batchNumber.createdBy",
+ },
{
$ref: "#/parameters/body.batchNumber",
},
@@ -13149,6 +13185,78 @@ export default {
tags: ["costLedger"],
},
},
+ "/batchNumbers": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.number",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.manufacturingDate",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.expirationDate",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.supplierId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.source",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.itemName",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchNumbers.itemReadableId",
+ },
+ {
+ $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/batchNumbers",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["batchNumbers"],
+ },
+ },
"/purchaseOrderLine": {
get: {
parameters: [
@@ -18051,6 +18159,204 @@ export default {
tags: ["accountCategory"],
},
},
+ "/batchProperty": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.label",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.key",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.dataType",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.listOptions",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.sortOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.updatedAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.updatedBy",
+ },
+ {
+ $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/batchProperty",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["batchProperty"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.batchProperty",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["batchProperty"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.label",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.key",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.dataType",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.listOptions",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.sortOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.updatedAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.updatedBy",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["batchProperty"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.label",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.key",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.dataType",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.listOptions",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.sortOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.updatedAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.batchProperty.updatedBy",
+ },
+ {
+ $ref: "#/parameters/body.batchProperty",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["batchProperty"],
+ },
+ },
"/salesOrders": {
get: {
parameters: [
@@ -21301,7 +21607,10 @@ export default {
$ref: "#/parameters/rowFilter.jobMaterialTracking.companyId",
},
{
- $ref: "#/parameters/rowFilter.jobMaterialTracking.consumedAt",
+ $ref: "#/parameters/rowFilter.jobMaterialTracking.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialTracking.createdBy",
},
{
$ref: "#/parameters/select",
@@ -21387,7 +21696,10 @@ export default {
$ref: "#/parameters/rowFilter.jobMaterialTracking.companyId",
},
{
- $ref: "#/parameters/rowFilter.jobMaterialTracking.consumedAt",
+ $ref: "#/parameters/rowFilter.jobMaterialTracking.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialTracking.createdBy",
},
{
$ref: "#/parameters/preferReturn",
@@ -21427,7 +21739,10 @@ export default {
$ref: "#/parameters/rowFilter.jobMaterialTracking.companyId",
},
{
- $ref: "#/parameters/rowFilter.jobMaterialTracking.consumedAt",
+ $ref: "#/parameters/rowFilter.jobMaterialTracking.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialTracking.createdBy",
},
{
$ref: "#/parameters/body.jobMaterialTracking",
@@ -27741,6 +28056,9 @@ export default {
{
$ref: "#/parameters/rowFilter.receiptLineTracking.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.receiptLineTracking.createdBy",
+ },
{
$ref: "#/parameters/select",
},
@@ -27833,6 +28151,9 @@ export default {
{
$ref: "#/parameters/rowFilter.receiptLineTracking.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.receiptLineTracking.createdBy",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -27879,6 +28200,9 @@ export default {
{
$ref: "#/parameters/rowFilter.receiptLineTracking.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.receiptLineTracking.createdBy",
+ },
{
$ref: "#/parameters/body.receiptLineTracking",
},
@@ -27919,7 +28243,10 @@ export default {
$ref: "#/parameters/rowFilter.jobProductionTracking.companyId",
},
{
- $ref: "#/parameters/rowFilter.jobProductionTracking.producedAt",
+ $ref: "#/parameters/rowFilter.jobProductionTracking.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobProductionTracking.createdBy",
},
{
$ref: "#/parameters/select",
@@ -28002,7 +28329,10 @@ export default {
$ref: "#/parameters/rowFilter.jobProductionTracking.companyId",
},
{
- $ref: "#/parameters/rowFilter.jobProductionTracking.producedAt",
+ $ref: "#/parameters/rowFilter.jobProductionTracking.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobProductionTracking.createdBy",
},
{
$ref: "#/parameters/preferReturn",
@@ -28039,7 +28369,10 @@ export default {
$ref: "#/parameters/rowFilter.jobProductionTracking.companyId",
},
{
- $ref: "#/parameters/rowFilter.jobProductionTracking.producedAt",
+ $ref: "#/parameters/rowFilter.jobProductionTracking.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobProductionTracking.createdBy",
},
{
$ref: "#/parameters/body.jobProductionTracking",
@@ -36846,6 +37179,9 @@ export default {
{
$ref: "#/parameters/rowFilter.serialNumber.itemId",
},
+ {
+ $ref: "#/parameters/rowFilter.serialNumber.source",
+ },
{
$ref: "#/parameters/rowFilter.serialNumber.supplierId",
},
@@ -36929,6 +37265,9 @@ export default {
{
$ref: "#/parameters/rowFilter.serialNumber.itemId",
},
+ {
+ $ref: "#/parameters/rowFilter.serialNumber.source",
+ },
{
$ref: "#/parameters/rowFilter.serialNumber.supplierId",
},
@@ -36966,6 +37305,9 @@ export default {
{
$ref: "#/parameters/rowFilter.serialNumber.itemId",
},
+ {
+ $ref: "#/parameters/rowFilter.serialNumber.source",
+ },
{
$ref: "#/parameters/rowFilter.serialNumber.supplierId",
},
@@ -44999,7 +45341,7 @@ export default {
type: "object",
},
batchNumber: {
- required: ["id", "number", "itemId", "companyId", "createdAt"],
+ required: ["id", "number", "itemId", "source", "companyId", "createdAt"],
properties: {
id: {
default: "public.xid()",
@@ -45017,6 +45359,12 @@ export default {
format: "text",
type: "string",
},
+ source: {
+ default: "Purchased",
+ enum: ["Purchased", "Manufactured"],
+ format: 'public."trackingSource"',
+ type: "string",
+ },
companyId: {
description:
"Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
@@ -45035,11 +45383,24 @@ export default {
format: "date",
type: "string",
},
+ notes: {
+ format: "json",
+ },
+ properties: {
+ format: "jsonb",
+ },
createdAt: {
default: "now()",
format: "timestamp with time zone",
type: "string",
},
+ createdBy: {
+ default: "auth.uid()",
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
},
type: "object",
},
@@ -49352,6 +49713,57 @@ export default {
},
type: "object",
},
+ batchNumbers: {
+ properties: {
+ id: {
+ format: "text",
+ type: "string",
+ },
+ number: {
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ manufacturingDate: {
+ format: "date",
+ type: "string",
+ },
+ expirationDate: {
+ format: "date",
+ type: "string",
+ },
+ supplierId: {
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ itemId: {
+ description:
+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `item.id`.<fk table='item' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ source: {
+ enum: ["Purchased", "Manufactured"],
+ format: 'public."trackingSource"',
+ type: "string",
+ },
+ itemName: {
+ format: "text",
+ type: "string",
+ },
+ itemReadableId: {
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
purchaseOrderLine: {
required: [
"id",
@@ -51733,6 +52145,86 @@ export default {
},
type: "object",
},
+ batchProperty: {
+ required: [
+ "id",
+ "itemId",
+ "label",
+ "key",
+ "dataType",
+ "sortOrder",
+ "companyId",
+ "createdAt",
+ "createdBy",
+ ],
+ properties: {
+ id: {
+ default: "public.xid()",
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ itemId: {
+ description:
+ "Note:\nThis is a Foreign Key to `item.id`.<fk table='item' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ label: {
+ format: "text",
+ type: "string",
+ },
+ key: {
+ format: "text",
+ type: "string",
+ },
+ dataType: {
+ enum: ["text", "numeric", "boolean", "list"],
+ format: 'public."configurationParameterDataType"',
+ type: "string",
+ },
+ listOptions: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ sortOrder: {
+ default: 1,
+ format: "double precision",
+ type: "number",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ createdBy: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ updatedAt: {
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ updatedBy: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
salesOrders: {
properties: {
id: {
@@ -53357,7 +53849,7 @@ export default {
"itemId",
"quantity",
"companyId",
- "consumedAt",
+ "createdAt",
],
properties: {
id: {
@@ -53407,11 +53899,18 @@ export default {
format: "text",
type: "string",
},
- consumedAt: {
+ createdAt: {
default: "now()",
format: "timestamp with time zone",
type: "string",
},
+ createdBy: {
+ default: "auth.uid()",
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
},
type: "object",
},
@@ -56255,18 +56754,18 @@ export default {
format: "timestamp with time zone",
type: "string",
},
+ createdBy: {
+ default: "auth.uid()",
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
},
type: "object",
},
jobProductionTracking: {
- required: [
- "id",
- "jobId",
- "itemId",
- "quantity",
- "companyId",
- "producedAt",
- ],
+ required: ["id", "jobId", "itemId", "quantity", "companyId", "createdAt"],
properties: {
id: {
default: "public.xid()",
@@ -56309,11 +56808,18 @@ export default {
format: "text",
type: "string",
},
- producedAt: {
+ createdAt: {
default: "now()",
format: "timestamp with time zone",
type: "string",
},
+ createdBy: {
+ default: "auth.uid()",
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
},
type: "object",
},
@@ -57026,7 +57532,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",
},
@@ -57075,7 +57581,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",
},
@@ -60323,7 +60829,15 @@ export default {
type: "object",
},
serialNumber: {
- required: ["id", "number", "itemId", "companyId", "status", "createdAt"],
+ required: [
+ "id",
+ "number",
+ "itemId",
+ "source",
+ "companyId",
+ "status",
+ "createdAt",
+ ],
properties: {
id: {
default: "public.xid()",
@@ -60341,6 +60855,12 @@ export default {
format: "text",
type: "string",
},
+ source: {
+ default: "Purchased",
+ enum: ["Purchased", "Manufactured"],
+ format: 'public."trackingSource"',
+ type: "string",
+ },
supplierId: {
format: "text",
type: "string",
@@ -64161,6 +64681,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.batchNumber.source": {
+ name: "source",
+ required: false,
+ format: 'public."trackingSource"',
+ in: "query",
+ type: "string",
+ },
"rowFilter.batchNumber.companyId": {
name: "companyId",
required: false,
@@ -64189,6 +64716,20 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.batchNumber.notes": {
+ name: "notes",
+ required: false,
+ format: "json",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumber.properties": {
+ name: "properties",
+ required: false,
+ format: "jsonb",
+ in: "query",
+ type: "string",
+ },
"rowFilter.batchNumber.createdAt": {
name: "createdAt",
required: false,
@@ -64196,6 +64737,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.batchNumber.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.methodMaterial": {
name: "methodMaterial",
description: "methodMaterial",
@@ -69684,6 +70232,85 @@ export default {
in: "query",
type: "string",
},
+ "body.batchNumbers": {
+ name: "batchNumbers",
+ description: "batchNumbers",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/batchNumbers",
+ },
+ },
+ "rowFilter.batchNumbers.id": {
+ name: "id",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.number": {
+ name: "number",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.manufacturingDate": {
+ name: "manufacturingDate",
+ required: false,
+ format: "date",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.expirationDate": {
+ name: "expirationDate",
+ required: false,
+ format: "date",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.supplierId": {
+ name: "supplierId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.companyId": {
+ name: "companyId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.itemId": {
+ name: "itemId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.source": {
+ name: "source",
+ required: false,
+ format: 'public."trackingSource"',
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.itemName": {
+ name: "itemName",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchNumbers.itemReadableId": {
+ name: "itemReadableId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.purchaseOrderLine": {
name: "purchaseOrderLine",
description: "purchaseOrderLine",
@@ -72975,6 +73602,99 @@ export default {
in: "query",
type: "string",
},
+ "body.batchProperty": {
+ name: "batchProperty",
+ description: "batchProperty",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/batchProperty",
+ },
+ },
+ "rowFilter.batchProperty.id": {
+ name: "id",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.itemId": {
+ name: "itemId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.label": {
+ name: "label",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.key": {
+ name: "key",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.dataType": {
+ name: "dataType",
+ required: false,
+ format: 'public."configurationParameterDataType"',
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.listOptions": {
+ name: "listOptions",
+ required: false,
+ format: "text[]",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.sortOrder": {
+ name: "sortOrder",
+ required: false,
+ format: "double precision",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.companyId": {
+ name: "companyId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.createdAt": {
+ name: "createdAt",
+ required: false,
+ format: "timestamp with time zone",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.updatedAt": {
+ name: "updatedAt",
+ required: false,
+ format: "timestamp with time zone",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.batchProperty.updatedBy": {
+ name: "updatedBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.salesOrders": {
name: "salesOrders",
description: "salesOrders",
@@ -75046,13 +75766,20 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.jobMaterialTracking.consumedAt": {
- name: "consumedAt",
+ "rowFilter.jobMaterialTracking.createdAt": {
+ name: "createdAt",
required: false,
format: "timestamp with time zone",
in: "query",
type: "string",
},
+ "rowFilter.jobMaterialTracking.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.oauthToken": {
name: "oauthToken",
description: "oauthToken",
@@ -78797,6 +79524,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.receiptLineTracking.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.jobProductionTracking": {
name: "jobProductionTracking",
description: "jobProductionTracking",
@@ -78855,13 +79589,20 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.jobProductionTracking.producedAt": {
- name: "producedAt",
+ "rowFilter.jobProductionTracking.createdAt": {
+ name: "createdAt",
required: false,
format: "timestamp with time zone",
in: "query",
type: "string",
},
+ "rowFilter.jobProductionTracking.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.employeeJob": {
name: "employeeJob",
description: "employeeJob",
@@ -84148,6 +84889,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.serialNumber.source": {
+ name: "source",
+ required: false,
+ format: 'public."trackingSource"',
+ in: "query",
+ type: "string",
+ },
"rowFilter.serialNumber.supplierId": {
name: "supplierId",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 18a2591db8..b54c1d352c 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -1732,31 +1732,43 @@ export type Database = {
Row: {
companyId: string;
createdAt: string;
+ createdBy: string | null;
expirationDate: string | null;
id: string;
itemId: string;
manufacturingDate: string | null;
+ notes: Json | null;
number: string;
+ properties: Json | null;
+ source: Database["public"]["Enums"]["trackingSource"];
supplierId: string | null;
};
Insert: {
companyId: string;
createdAt?: string;
+ createdBy?: string | null;
expirationDate?: string | null;
id?: string;
itemId: string;
manufacturingDate?: string | null;
+ notes?: Json | null;
number: string;
+ properties?: Json | null;
+ source?: Database["public"]["Enums"]["trackingSource"];
supplierId?: string | null;
};
Update: {
companyId?: string;
createdAt?: string;
+ createdBy?: string | null;
expirationDate?: string | null;
id?: string;
itemId?: string;
manufacturingDate?: string | null;
+ notes?: Json | null;
number?: string;
+ properties?: Json | null;
+ source?: Database["public"]["Enums"]["trackingSource"];
supplierId?: string | null;
};
Relationships: [
@@ -1788,6 +1800,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "batchNumber_itemId_fkey";
columns: ["itemId"];
@@ -1797,6 +1844,154 @@ export type Database = {
}
];
};
+ batchProperty: {
+ Row: {
+ companyId: string;
+ createdAt: string;
+ createdBy: string;
+ dataType: Database["public"]["Enums"]["configurationParameterDataType"];
+ id: string;
+ itemId: string;
+ label: string;
+ listOptions: string[] | null;
+ sortOrder: number;
+ updatedAt: string | null;
+ updatedBy: string | null;
+ };
+ Insert: {
+ companyId: string;
+ createdAt?: string;
+ createdBy: string;
+ dataType: Database["public"]["Enums"]["configurationParameterDataType"];
+ id?: string;
+ itemId: string;
+ label: string;
+ listOptions?: string[] | null;
+ sortOrder?: number;
+ updatedAt?: string | null;
+ updatedBy?: string | null;
+ };
+ Update: {
+ companyId?: string;
+ createdAt?: string;
+ createdBy?: string;
+ dataType?: Database["public"]["Enums"]["configurationParameterDataType"];
+ id?: string;
+ itemId?: string;
+ label?: string;
+ listOptions?: string[] | null;
+ sortOrder?: number;
+ updatedAt?: string | null;
+ updatedBy?: string | null;
+ };
+ Relationships: [
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "companies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "company";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "customFieldTables";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "integrations";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
+ {
+ foreignKeyName: "batchProperty_itemId_fkey";
+ columns: ["itemId"];
+ isOneToOne: false;
+ referencedRelation: "item";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ }
+ ];
+ };
company: {
Row: {
addressLine1: string | null;
@@ -8568,7 +8763,8 @@ export type Database = {
Row: {
batchNumberId: string | null;
companyId: string;
- consumedAt: string;
+ createdAt: string;
+ createdBy: string | null;
id: string;
itemId: string;
jobMaterialId: string;
@@ -8579,7 +8775,8 @@ export type Database = {
Insert: {
batchNumberId?: string | null;
companyId: string;
- consumedAt?: string;
+ createdAt?: string;
+ createdBy?: string | null;
id?: string;
itemId: string;
jobMaterialId: string;
@@ -8590,7 +8787,8 @@ export type Database = {
Update: {
batchNumberId?: string | null;
companyId?: string;
- consumedAt?: string;
+ createdAt?: string;
+ createdBy?: string | null;
id?: string;
itemId?: string;
jobMaterialId?: string;
@@ -8641,6 +8839,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "jobMaterialTracking_itemId_fkey";
columns: ["itemId"];
@@ -9418,6 +9651,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "jobProductionTracking_itemId_fkey";
columns: ["itemId"];
@@ -18450,6 +18718,7 @@ export type Database = {
batchNumberId: string | null;
companyId: string;
createdAt: string;
+ createdBy: string | null;
id: string;
index: number;
itemId: string;
@@ -18463,6 +18732,7 @@ export type Database = {
batchNumberId?: string | null;
companyId: string;
createdAt?: string;
+ createdBy?: string | null;
id?: string;
index?: number;
itemId: string;
@@ -18476,6 +18746,7 @@ export type Database = {
batchNumberId?: string | null;
companyId?: string;
createdAt?: string;
+ createdBy?: string | null;
id?: string;
index?: number;
itemId?: string;
@@ -18528,6 +18799,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "receiptLineTracking_itemId_fkey";
columns: ["itemId"];
@@ -20584,6 +20890,7 @@ export type Database = {
id: string;
itemId: string;
number: string;
+ source: Database["public"]["Enums"]["trackingSource"];
status: string;
supplierId: string | null;
};
@@ -20594,6 +20901,7 @@ export type Database = {
id?: string;
itemId: string;
number: string;
+ source?: Database["public"]["Enums"]["trackingSource"];
status?: string;
supplierId?: string | null;
};
@@ -20604,6 +20912,7 @@ export type Database = {
id?: string;
itemId?: string;
number?: string;
+ source?: Database["public"]["Enums"]["trackingSource"];
status?: string;
supplierId?: string | null;
};
@@ -29371,14 +29680,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["customerCountryCode"];
+ columns: ["supplierCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
},
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["supplierCountryCode"];
+ columns: ["customerCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
@@ -30976,14 +31285,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 18a2591db8..b54c1d352c 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -1732,31 +1732,43 @@ export type Database = {
Row: {
companyId: string;
createdAt: string;
+ createdBy: string | null;
expirationDate: string | null;
id: string;
itemId: string;
manufacturingDate: string | null;
+ notes: Json | null;
number: string;
+ properties: Json | null;
+ source: Database["public"]["Enums"]["trackingSource"];
supplierId: string | null;
};
Insert: {
companyId: string;
createdAt?: string;
+ createdBy?: string | null;
expirationDate?: string | null;
id?: string;
itemId: string;
manufacturingDate?: string | null;
+ notes?: Json | null;
number: string;
+ properties?: Json | null;
+ source?: Database["public"]["Enums"]["trackingSource"];
supplierId?: string | null;
};
Update: {
companyId?: string;
createdAt?: string;
+ createdBy?: string | null;
expirationDate?: string | null;
id?: string;
itemId?: string;
manufacturingDate?: string | null;
+ notes?: Json | null;
number?: string;
+ properties?: Json | null;
+ source?: Database["public"]["Enums"]["trackingSource"];
supplierId?: string | null;
};
Relationships: [
@@ -1788,6 +1800,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchNumber_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "batchNumber_itemId_fkey";
columns: ["itemId"];
@@ -1797,6 +1844,154 @@ export type Database = {
}
];
};
+ batchProperty: {
+ Row: {
+ companyId: string;
+ createdAt: string;
+ createdBy: string;
+ dataType: Database["public"]["Enums"]["configurationParameterDataType"];
+ id: string;
+ itemId: string;
+ label: string;
+ listOptions: string[] | null;
+ sortOrder: number;
+ updatedAt: string | null;
+ updatedBy: string | null;
+ };
+ Insert: {
+ companyId: string;
+ createdAt?: string;
+ createdBy: string;
+ dataType: Database["public"]["Enums"]["configurationParameterDataType"];
+ id?: string;
+ itemId: string;
+ label: string;
+ listOptions?: string[] | null;
+ sortOrder?: number;
+ updatedAt?: string | null;
+ updatedBy?: string | null;
+ };
+ Update: {
+ companyId?: string;
+ createdAt?: string;
+ createdBy?: string;
+ dataType?: Database["public"]["Enums"]["configurationParameterDataType"];
+ id?: string;
+ itemId?: string;
+ label?: string;
+ listOptions?: string[] | null;
+ sortOrder?: number;
+ updatedAt?: string | null;
+ updatedBy?: string | null;
+ };
+ Relationships: [
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "companies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "company";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "customFieldTables";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "batchProperty_companyId_fkey";
+ columns: ["companyId"];
+ isOneToOne: false;
+ referencedRelation: "integrations";
+ referencedColumns: ["companyId"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
+ {
+ foreignKeyName: "batchProperty_itemId_fkey";
+ columns: ["itemId"];
+ isOneToOne: false;
+ referencedRelation: "item";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "batchProperty_updatedBy_fkey";
+ columns: ["updatedBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ }
+ ];
+ };
company: {
Row: {
addressLine1: string | null;
@@ -8568,7 +8763,8 @@ export type Database = {
Row: {
batchNumberId: string | null;
companyId: string;
- consumedAt: string;
+ createdAt: string;
+ createdBy: string | null;
id: string;
itemId: string;
jobMaterialId: string;
@@ -8579,7 +8775,8 @@ export type Database = {
Insert: {
batchNumberId?: string | null;
companyId: string;
- consumedAt?: string;
+ createdAt?: string;
+ createdBy?: string | null;
id?: string;
itemId: string;
jobMaterialId: string;
@@ -8590,7 +8787,8 @@ export type Database = {
Update: {
batchNumberId?: string | null;
companyId?: string;
- consumedAt?: string;
+ createdAt?: string;
+ createdBy?: string | null;
id?: string;
itemId?: string;
jobMaterialId?: string;
@@ -8641,6 +8839,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobMaterialTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "jobMaterialTracking_itemId_fkey";
columns: ["itemId"];
@@ -9418,6 +9651,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "jobProductionTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "jobProductionTracking_itemId_fkey";
columns: ["itemId"];
@@ -18450,6 +18718,7 @@ export type Database = {
batchNumberId: string | null;
companyId: string;
createdAt: string;
+ createdBy: string | null;
id: string;
index: number;
itemId: string;
@@ -18463,6 +18732,7 @@ export type Database = {
batchNumberId?: string | null;
companyId: string;
createdAt?: string;
+ createdBy?: string | null;
id?: string;
index?: number;
itemId: string;
@@ -18476,6 +18746,7 @@ export type Database = {
batchNumberId?: string | null;
companyId?: string;
createdAt?: string;
+ createdBy?: string | null;
id?: string;
index?: number;
itemId?: string;
@@ -18528,6 +18799,41 @@ export type Database = {
referencedRelation: "integrations";
referencedColumns: ["companyId"];
},
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employees";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeesAcrossCompanies";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "receiptLineTracking_createdBy_fkey";
+ columns: ["createdBy"];
+ isOneToOne: false;
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ },
{
foreignKeyName: "receiptLineTracking_itemId_fkey";
columns: ["itemId"];
@@ -20584,6 +20890,7 @@ export type Database = {
id: string;
itemId: string;
number: string;
+ source: Database["public"]["Enums"]["trackingSource"];
status: string;
supplierId: string | null;
};
@@ -20594,6 +20901,7 @@ export type Database = {
id?: string;
itemId: string;
number: string;
+ source?: Database["public"]["Enums"]["trackingSource"];
status?: string;
supplierId?: string | null;
};
@@ -20604,6 +20912,7 @@ export type Database = {
id?: string;
itemId?: string;
number?: string;
+ source?: Database["public"]["Enums"]["trackingSource"];
status?: string;
supplierId?: string | null;
};
@@ -29371,14 +29680,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["customerCountryCode"];
+ columns: ["supplierCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
},
{
foreignKeyName: "address_countryCode_fkey";
- columns: ["supplierCountryCode"];
+ columns: ["customerCountryCode"];
isOneToOne: false;
referencedRelation: "country";
referencedColumns: ["alpha2"];
@@ -30976,14 +31285,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/20250128094053_traceability.sql b/packages/database/supabase/migrations/20250128094053_traceability.sql
index 964befcb33..325ff8b402 100644
--- a/packages/database/supabase/migrations/20250128094053_traceability.sql
+++ b/packages/database/supabase/migrations/20250128094053_traceability.sql
@@ -6,11 +6,17 @@ ALTER TYPE "itemTrackingType" ADD VALUE IF NOT EXISTS 'Batch';
-- Add tracking method to item table
ALTER TABLE "item" ADD COLUMN "trackingMethod" TEXT CHECK ("trackingMethod" IN ('None', 'SerialNumber', 'BatchNumber'));
+CREATE TYPE "trackingSource" AS ENUM (
+ 'Purchased',
+ 'Manufactured'
+);
+
-- Create table for serial numbers
CREATE TABLE "serialNumber" (
"id" TEXT NOT NULL DEFAULT xid(),
"number" TEXT NOT NULL,
"itemId" TEXT NOT NULL,
+ "source" "trackingSource" NOT NULL DEFAULT 'Purchased',
"supplierId" TEXT,
"companyId" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'Available' CHECK ("status" IN ('Available', 'Reserved', 'Consumed')),
@@ -31,11 +37,15 @@ CREATE TABLE "batchNumber" (
"id" TEXT NOT NULL DEFAULT xid(),
"number" TEXT NOT NULL,
"itemId" TEXT NOT NULL,
+ "source" "trackingSource" NOT NULL DEFAULT 'Purchased',
"companyId" TEXT NOT NULL,
"supplierId" TEXT,
"manufacturingDate" DATE,
"expirationDate" DATE,
+ "notes" JSON DEFAULT '{}',
+ "properties" JSONB DEFAULT '{}',
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "createdBy" TEXT REFERENCES "user"("id") ON DELETE CASCADE DEFAULT auth.uid(),
CONSTRAINT "batchNumber_id_unique" UNIQUE ("id"),
CONSTRAINT "batchNumber_pkey" PRIMARY KEY ("number", "itemId"),
@@ -140,6 +150,7 @@ CREATE TABLE "receiptLineTracking" (
"posted" BOOLEAN NOT NULL DEFAULT false,
"companyId" TEXT NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "createdBy" TEXT REFERENCES "user"("id") ON DELETE CASCADE DEFAULT auth.uid(),
CONSTRAINT "receiptLineTracking_pkey" PRIMARY KEY ("id"),
CONSTRAINT "receiptLineTracking_receiptLine_fkey" FOREIGN KEY ("receiptLineId") REFERENCES "receiptLine"("id") ON DELETE CASCADE,
@@ -163,7 +174,8 @@ CREATE TABLE "jobMaterialTracking" (
"batchNumberId" TEXT,
"quantity" NUMERIC(12, 4) NOT NULL DEFAULT 1,
"companyId" TEXT NOT NULL,
- "consumedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "createdBy" TEXT REFERENCES "user"("id") ON DELETE CASCADE DEFAULT auth.uid(),
CONSTRAINT "jobMaterialTracking_pkey" PRIMARY KEY ("id"),
CONSTRAINT "jobMaterialTracking_jobMaterial_fkey" FOREIGN KEY ("jobMaterialId") REFERENCES "jobMaterial"("id") ON DELETE CASCADE,
@@ -186,7 +198,8 @@ CREATE TABLE "jobProductionTracking" (
"batchNumberId" TEXT,
"quantity" NUMERIC(12, 4) NOT NULL DEFAULT 1,
"companyId" TEXT NOT NULL,
- "producedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "createdBy" TEXT REFERENCES "user"("id") ON DELETE CASCADE DEFAULT auth.uid(),
CONSTRAINT "jobProductionTracking_pkey" PRIMARY KEY ("id"),
CONSTRAINT "jobProductionTracking_job_fkey" FOREIGN KEY ("jobId") REFERENCES "job"("id") ON DELETE CASCADE,
@@ -393,7 +406,7 @@ CREATE OR REPLACE FUNCTION update_receipt_line_batch_tracking(
) RETURNS void AS $$
BEGIN
-- First upsert the batch number
- INSERT INTO "batchNumber" ("id", "number", "itemId", "companyId", "manufacturingDate", "expirationDate", "supplierId")
+ INSERT INTO "batchNumber" ("id", "number", "itemId", "companyId", "manufacturingDate", "expirationDate", "supplierId", "source")
SELECT
p_batch_id,
p_batch_number,
@@ -401,7 +414,8 @@ BEGIN
rl."companyId",
p_manufacturing_date,
p_expiration_date,
- r."supplierId"
+ r."supplierId",
+ 'Purchased'
FROM "receiptLine" rl
JOIN "receipt" r ON r.id = rl."receiptId"
WHERE rl.id = p_receipt_line_id
@@ -445,13 +459,14 @@ DECLARE
v_serial_id TEXT;
BEGIN
-- First upsert the serial number
- INSERT INTO "serialNumber" ("id", "number", "itemId", "companyId", "supplierId")
+ INSERT INTO "serialNumber" ("id", "number", "itemId", "companyId", "supplierId", "source")
SELECT
xid(),
p_serial_number,
rl."itemId",
rl."companyId",
- r."supplierId"
+ r."supplierId",
+ 'Purchased'
FROM "receiptLine" rl
JOIN "receipt" r ON r.id = rl."receiptId"
WHERE rl.id = p_receipt_line_id
@@ -571,6 +586,7 @@ END;
$$ LANGUAGE plpgsql SECURITY INVOKER;
+DROP VIEW IF EXISTS "batchNumbers";
CREATE OR REPLACE VIEW "batchNumbers" WITH(SECURITY_INVOKER=true) AS
SELECT DISTINCT
bn."id",
@@ -580,13 +596,14 @@ CREATE OR REPLACE VIEW "batchNumbers" WITH(SECURITY_INVOKER=true) AS
bn."supplierId",
bn."companyId",
bn."itemId",
+ bn."source",
i."name" AS "itemName",
i."readableId" AS "itemReadableId"
FROM "batchNumber" bn
JOIN "item" i ON i."id" = bn."itemId"
WHERE EXISTS (
SELECT 1 FROM "receiptLineTracking" rlt
- WHERE rlt."batchNumberId" = bn."id"
+ WHERE rlt."batchNumberId" = bn."id" AND rlt."posted" = true
) OR EXISTS (
SELECT 1 FROM "jobProductionTracking" jpt
WHERE jpt."batchNumberId" = bn."id"
@@ -599,5 +616,65 @@ CREATE OR REPLACE VIEW "batchNumbers" WITH(SECURITY_INVOKER=true) AS
bn."supplierId",
bn."companyId",
bn."itemId",
+ bn."source",
i."name",
- i."readableId";
\ No newline at end of file
+ i."readableId";
+
+CREATE TABLE IF NOT EXISTS "batchProperty" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "itemId" TEXT NOT NULL,
+ "label" TEXT NOT NULL,
+ "dataType" "configurationParameterDataType" NOT NULL,
+ "listOptions" TEXT[],
+ "sortOrder" DOUBLE PRECISION NOT NULL DEFAULT 1,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+ "updatedBy" TEXT,
+
+ CONSTRAINT "batchProperty_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "batchProperty_itemId_key_unique" UNIQUE ("itemId", "key"),
+ CONSTRAINT "batchProperty_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "batchProperty_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "batchProperty_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,
+ CONSTRAINT "batchProperty_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE INDEX "batchProperty_itemId_idx" ON "batchProperty" ("itemId");
+CREATE INDEX "batchProperty_companyId_idx" ON "batchProperty" ("companyId");
+
+ALTER TABLE "batchProperty" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees with inventory_view can view batch parameters" ON "batchProperty"
+ FOR SELECT
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('inventory_view', "companyId")
+ );
+
+CREATE POLICY "Employees with inventory_create can insert batch parameters" ON "batchProperty"
+ FOR INSERT
+ WITH CHECK (
+ has_role('employee', "companyId") AND
+ has_company_permission('inventory_create', "companyId")
+);
+
+CREATE POLICY "Employees with inventory_update can update batch parameters" ON "batchProperty"
+ FOR UPDATE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('inventory_update', "companyId")
+ );
+
+CREATE POLICY "Employees with inventory_delete can delete batch parameters" ON "batchProperty"
+ FOR DELETE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('inventory_delete', "companyId")
+ );
+
+CREATE POLICY "Requests with an API key can access batch parameters" ON "batchProperty"
+FOR ALL USING (
+ has_valid_api_key_for_company("companyId")
+);
\ No newline at end of file