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 shelfId to bill of materials

Brad Barbin2121470d16ae
diff --git a/apps/erp/app/modules/items/items.models.ts b/apps/erp/app/modules/items/items.models.ts
index 04f0c4fc90..658e89c639 100644
--- a/apps/erp/app/modules/items/items.models.ts
+++ b/apps/erp/app/modules/items/items.models.ts
@@ -211,8 +211,13 @@ export const methodMaterialValidator = z.object({
unitOfMeasureCode: z
.string()
.min(1, { message: "Unit of Measure is required" }),
- useDefaultShelf: zfd.checkbox(),
- shelfId: zfd.text(z.string().optional()),
+ shelfIds: z.string().transform((val) => {
+ try {
+ return JSON.parse(val) as Record<string, string>;
+ } catch {
+ return {};
+ }
+ }),
});
export const methodOperationValidator = z
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
index 933cdf42ad..3ce5e5ad15 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
@@ -39,11 +39,13 @@ import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useState } from "react";
import { flushSync } from "react-dom";
import {
+ LuArrowLeft,
LuChevronDown,
LuChevronRight,
LuCog,
LuExternalLink,
LuGitPullRequest,
+ LuGitPullRequestCreate,
LuGitPullRequestCreateArrow,
LuLock,
LuSettings2,
@@ -57,6 +59,7 @@ import {
DefaultMethodType,
Hidden,
Item,
+ Location,
Number,
Select,
Shelf,
@@ -73,6 +76,7 @@ import { usePermissions, useUser } from "~/hooks";
import type { Database } from "@carbon/database";
import { getItemReadableId } from "@carbon/utils";
import { ConfigurationEditor } from "~/components/Configurator/ConfigurationEditor";
+import { useShelves } from "~/components/Form/Shelf";
import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";
import {
methodType,
@@ -135,8 +139,7 @@ const initialMethodMaterial: Omit<Material, "makeMethodId" | "order"> & {
description: "",
quantity: 1,
unitOfMeasureCode: "EA",
- useDefaultShelf: true,
- shelfId: undefined,
+ shelfIds: {},
};
const BillOfMaterial = ({
@@ -481,7 +484,7 @@ const BillOfMaterial = ({
<div className="flex items-center gap-2">
<Button
variant="secondary"
- isDisabled={isReadOnly || selectedItemId !== null}
+ isDisabled={isReadOnly}
onClick={onAddItem}
>
Add Material
@@ -569,7 +572,18 @@ function MaterialForm({
const { carbon } = useCarbon();
const methodMaterialFetcher = useFetcher<{ id: string }>();
const params = useParams();
- const { company } = useUser();
+ const { company, defaults } = useUser();
+ const [locationId, setLocationId] = useState<string | undefined>(
+ defaults.locationId ?? undefined
+ );
+
+ const shelves = useShelves(locationId);
+
+ useEffect(() => {
+ if (defaults.locationId) {
+ setLocationId(defaults.locationId);
+ }
+ }, [defaults.locationId]);
const unitOfMeasures = useUnitOfMeasure();
@@ -598,8 +612,7 @@ function MaterialForm({
methodOperationId: string | undefined;
quantity: number;
kit: boolean;
- useDefaultShelf: boolean;
- shelfId: string | undefined;
+ shelfIds: Record<string, string>;
}>({
itemId: item.data.itemId ?? "",
methodType: item.data.methodType ?? "Buy",
@@ -608,8 +621,7 @@ function MaterialForm({
methodOperationId: item.data.methodOperationId ?? undefined,
quantity: item.data.quantity ?? 1,
kit: item.data.kit ?? false,
- useDefaultShelf: item.data.useDefaultShelf ?? true,
- shelfId: item.data.shelfId ?? undefined,
+ shelfIds: item.data.shelfIds ?? {},
});
const onTypeChange = (value: MethodItemType | "Item") => {
@@ -623,8 +635,7 @@ function MaterialForm({
description: "",
unitOfMeasureCode: "EA",
kit: false,
- useDefaultShelf: true,
- shelfId: undefined,
+ shelfIds: {},
methodOperationId: undefined,
});
};
@@ -673,7 +684,9 @@ function MaterialForm({
: path.to.methodMaterial(item.id!)
}
method="post"
- defaultValues={item.data}
+ defaultValues={{
+ ...item.data,
+ }}
validator={methodMaterialValidator}
className="w-full flex flex-col gap-y-4"
fetcher={methodMaterialFetcher}
@@ -683,6 +696,7 @@ function MaterialForm({
<Hidden name="makeMethodId" />
<Hidden name="order" />
<Hidden name="kit" value={itemData.kit.toString()} />
+ <Hidden name="shelfIds" value={JSON.stringify(itemData.shelfIds)} />
</div>
<div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
@@ -760,138 +774,172 @@ function MaterialForm({
}
/>
</div>
- {itemData.methodType !== "Make" && (
- <>
- <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
- <HStack
- className="w-full justify-between cursor-pointer"
- onClick={sourceDisclosure.onToggle}
- >
- <HStack>
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={sourceDisclosure.onToggle}
+ >
+ <HStack>
+ {itemData.methodType === "Make" ? (
+ <>
+ <LuGitPullRequestCreate />
+ <Label>Finish To</Label>
+ </>
+ ) : (
+ <>
<LuGitPullRequest />
<Label>Pull From</Label>
- </HStack>
- <HStack>
- <Badge variant="secondary">
- <MethodIcon
- type={itemData.methodType}
- className="size-3 mr-1"
- />
- {itemData.methodType}
- </Badge>
- <Badge variant="secondary">
- <LuGitPullRequest className="size-3 mr-1" />
- Default Shelf
- </Badge>
- <IconButton
- icon={<LuChevronRight />}
- aria-label={
- sourceDisclosure.isOpen
- ? "Collapse Source"
- : "Expand Source"
- }
- variant="ghost"
- onClick={(e) => {
- e.stopPropagation();
- sourceDisclosure.onToggle();
- }}
- className={`transition-transform ${
- sourceDisclosure.isOpen ? "rotate-90" : ""
- }`}
- />
- </HStack>
- </HStack>
- <div
- className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
- sourceDisclosure.isOpen ? "" : "hidden"
+ </>
+ )}
+ </HStack>
+ <HStack>
+ <Badge variant="secondary">
+ <MethodIcon type={itemData.methodType} className="size-3 mr-1" />
+ {itemData.methodType}
+ </Badge>
+ <LuArrowLeft
+ className={cn(itemData.methodType === "Make" ? "rotate-180" : "")}
+ />
+ <Badge variant="secondary">
+ <LuGitPullRequest className="size-3 mr-1" />
+ {shelves.options?.find(
+ (s) => s.value === itemData.shelfIds[locationId ?? ""]
+ )?.label ??
+ (itemData.methodType === "Make" ? "WIP" : "Default Shelf")}
+ </Badge>
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ sourceDisclosure.isOpen ? "Collapse Source" : "Expand Source"
+ }
+ variant="ghost"
+ onClick={(e) => {
+ e.stopPropagation();
+ sourceDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ sourceDisclosure.isOpen ? "rotate-90" : ""
}`}
- >
- <DefaultMethodType
- name="methodType"
- label="Method Type"
- value={itemData.methodType}
- isConfigured={rulesByField.has(key("methodType"))}
- onConfigure={
- configurable && !temporaryItems[item.id]
- ? () =>
- onConfigure({
- label: "Method Type",
- field: key("methodType"),
- code: rulesByField.get(key("methodType"))?.code,
- defaultValue: itemData.methodType,
- returnType: {
- type: "enum",
- listOptions: methodType,
- },
- })
- : undefined
- }
- replenishmentSystem="Buy and Make"
- />
-
- <Shelf name="shelfId" label="Shelf" isOptional />
- </div>
- </div>
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ sourceDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
+ <DefaultMethodType
+ name="methodType"
+ label="Method Type"
+ value={itemData.methodType}
+ isConfigured={rulesByField.has(key("methodType"))}
+ onConfigure={
+ configurable && !temporaryItems[item.id]
+ ? () =>
+ onConfigure({
+ label: "Method Type",
+ field: key("methodType"),
+ code: rulesByField.get(key("methodType"))?.code,
+ defaultValue: itemData.methodType,
+ returnType: {
+ type: "enum",
+ listOptions: methodType,
+ },
+ })
+ : undefined
+ }
+ replenishmentSystem="Buy and Make"
+ />
+ <Location
+ name="locationId"
+ label="Location"
+ value={locationId}
+ onChange={(value) => {
+ setLocationId(value?.value as string);
+ }}
+ />
+ <Shelf
+ name="shelfId"
+ label="Shelf"
+ value={itemData.shelfIds[locationId ?? ""]}
+ locationId={locationId}
+ onChange={(value) => {
+ setItemData((d) => ({
+ ...d,
+ shelfIds: {
+ ...d.shelfIds,
+ [locationId ?? ""]: value?.id ?? "",
+ },
+ }));
+ }}
+ isOptional
+ />
+ </div>
+ </div>
- <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
- <HStack
- className="w-full justify-between cursor-pointer"
- onClick={backflushDisclosure.onToggle}
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={backflushDisclosure.onToggle}
+ >
+ <HStack>
+ <LuGitPullRequestCreateArrow />
+ <Label>Backflush</Label>
+ </HStack>
+ <HStack>
+ <Badge
+ variant={
+ methodOperations.length > 0 ? "secondary" : "destructive"
+ }
>
- <HStack>
- <LuGitPullRequestCreateArrow />
- <Label>Backflush</Label>
- </HStack>
- <HStack>
- <Badge
- variant={
- methodOperations.length > 0 ? "secondary" : "destructive"
- }
- >
- <LuCog className="size-3 mr-1" />
- {itemData.methodOperationId
- ? methodOperations.find(
- (o) => o.id === itemData.methodOperationId
- )?.description || "Selected Operation"
- : "First Operation"}
- </Badge>
- <IconButton
- icon={<LuChevronRight />}
- aria-label={
- backflushDisclosure.isOpen
- ? "Collapse Backflush"
- : "Expand Backflush"
- }
- variant="ghost"
- size="md"
- onClick={(e) => {
- e.stopPropagation();
- backflushDisclosure.onToggle();
- }}
- className={`transition-transform ${
- backflushDisclosure.isOpen ? "rotate-90" : ""
- }`}
- />
- </HStack>
- </HStack>
- <div
- className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
- backflushDisclosure.isOpen ? "" : "hidden"
+ <LuCog className="size-3 mr-1" />
+ {itemData.methodOperationId
+ ? methodOperations.find(
+ (o) => o.id === itemData.methodOperationId
+ )?.description || "Selected Operation"
+ : "First Operation"}
+ </Badge>
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ backflushDisclosure.isOpen
+ ? "Collapse Backflush"
+ : "Expand Backflush"
+ }
+ variant="ghost"
+ size="md"
+ onClick={(e) => {
+ e.stopPropagation();
+ backflushDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ backflushDisclosure.isOpen ? "rotate-90" : ""
}`}
- >
- <Select
- name="methodOperationId"
- label="Operation"
- isOptional
- options={methodOperations.map((o) => ({
- value: o.id!,
- label: o.description,
- }))}
- />
- </div>
- </div>
- </>
- )}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ backflushDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
+ <Select
+ name="methodOperationId"
+ label="Operation"
+ isOptional
+ options={methodOperations.map((o) => ({
+ value: o.id!,
+ label: o.description,
+ }))}
+ onChange={(value) => {
+ setItemData((d) => ({
+ ...d,
+ methodOperationId: value?.value,
+ }));
+ }}
+ />
+ </div>
+ </div>
<motion.div
className="flex flex-1 items-center justify-end w-full"
diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.ts
index e8a003d093..cbe54e3d42 100644
--- a/apps/erp/app/modules/production/production.models.ts
+++ b/apps/erp/app/modules/production/production.models.ts
@@ -583,7 +583,7 @@ const baseMaterialValidator = z.object({
unitOfMeasureCode: z
.string()
.min(1, { message: "Unit of Measure is required" }),
- shelfId: z.string().optional().nullable(),
+ shelfId: zfd.text(z.string().optional()),
});
export const jobMaterialValidator = baseMaterialValidator
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
index d3590c0663..98b6e89382 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
@@ -16,11 +16,14 @@ import {
DropdownMenuRadioItem,
DropdownMenuTrigger,
HStack,
+ IconButton,
+ Label,
toast,
Tooltip,
TooltipContent,
TooltipTrigger,
useDebounce,
+ useDisclosure,
VStack,
} from "@carbon/react";
import { getItemReadableId } from "@carbon/utils";
@@ -30,8 +33,14 @@ import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useState } from "react";
import {
+ LuArrowLeft,
LuChevronDown,
+ LuChevronRight,
+ LuCog,
LuExternalLink,
+ LuGitPullRequest,
+ LuGitPullRequestCreate,
+ LuGitPullRequestCreateArrow,
LuSettings2,
LuX,
} from "react-icons/lu";
@@ -45,9 +54,11 @@ import {
Number,
NumberControlled,
Select,
+ Shelf,
Submit,
UnitOfMeasure,
} from "~/components/Form";
+import { useShelves } from "~/components/Form/Shelf";
import type {
Item as SortableItem,
SortableItemRenderProps,
@@ -555,11 +566,7 @@ const JobBillOfMaterial = ({
<CardAction>
<Button
variant="secondary"
- isDisabled={
- isDisabled ||
- !permissions.can("update", "production") ||
- selectedItemId !== null
- }
+ isDisabled={isDisabled || !permissions.can("update", "production")}
onClick={onAddItem}
>
Add Material
@@ -605,6 +612,10 @@ function MaterialForm({
const { jobId } = useParams();
if (!jobId) throw new Error("jobId not found");
+ const routeData = useRouteData<{
+ job: Job;
+ }>(path.to.job(jobId));
+
const { carbon } = useCarbon();
const methodMaterialFetcher = useFetcher<{ id: string }>();
const params = useParams();
@@ -628,22 +639,26 @@ function MaterialForm({
itemId: string;
methodType: MethodType;
description: string;
+ jobOperationId: string;
unitCost: number;
unitOfMeasureCode: string;
quantity: number;
kit: boolean;
requiresBatchTracking: boolean;
requiresSerialTracking: boolean;
+ shelfId?: string;
}>({
itemId: item.data.itemId ?? "",
methodType: item.data.methodType ?? "Buy",
description: item.data.description ?? "",
+ jobOperationId: item.data.jobOperationId ?? "",
unitCost: item.data.unitCost ?? 0,
unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",
quantity: item.data.quantity ?? 1,
kit: item.data.kit ?? false,
requiresBatchTracking: item.data.requiresBatchTracking ?? false,
requiresSerialTracking: item.data.requiresSerialTracking ?? false,
+ shelfId: item.data.shelfId ?? undefined,
});
const onTypeChange = (value: MethodItemType | "Item") => {
@@ -657,9 +672,11 @@ function MaterialForm({
unitCost: 0,
description: "",
unitOfMeasureCode: "EA",
+ jobOperationId: "",
kit: false,
requiresBatchTracking: false,
requiresSerialTracking: false,
+ shelfId: undefined,
});
};
@@ -703,6 +720,11 @@ function MaterialForm({
}
};
+ const sourceDisclosure = useDisclosure();
+ const backflushDisclosure = useDisclosure();
+ const locationId = routeData?.job?.locationId ?? undefined;
+ const shelves = useShelves(locationId);
+
return (
<ValidatedForm
action={
@@ -718,47 +740,182 @@ function MaterialForm({
? jobMaterialValidator
: jobMaterialValidatorForReleasedJob
}
- className="w-full"
+ className="w-full flex flex-col gap-y-4"
fetcher={methodMaterialFetcher}
>
- <Hidden name="id" />
- <Hidden name="jobMakeMethodId" />
- <Hidden name="kit" value={itemData.kit.toString()} />
- <Hidden name="order" />
- <Hidden
- name="requiresBatchTracking"
- value={itemData.requiresBatchTracking.toString()}
- />
- <Hidden
- name="requiresSerialTracking"
- value={itemData.requiresSerialTracking.toString()}
- />
- {itemData.methodType === "Make" && (
- <Hidden name="unitCost" value={itemData.unitCost} />
- )}
- <VStack>
- <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
- <Item
- disabledItems={[params.itemId!]}
- isReadOnly={isDisabled}
- name="itemId"
- label={itemType}
- includeInactive
- validItemTypes={["Consumable", "Material", "Part"]}
- type={itemType}
- onChange={(value) => {
- onItemChange(value?.value as string);
+ <div>
+ <Hidden name="id" />
+ <Hidden name="jobMakeMethodId" />
+ <Hidden name="kit" value={itemData.kit.toString()} />
+ <Hidden name="order" />
+ <Hidden
+ name="requiresBatchTracking"
+ value={itemData.requiresBatchTracking.toString()}
+ />
+ <Hidden
+ name="requiresSerialTracking"
+ value={itemData.requiresSerialTracking.toString()}
+ />
+ {itemData.methodType === "Make" && (
+ <Hidden name="unitCost" value={itemData.unitCost} />
+ )}
+ </div>
+
+ <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
+ <Item
+ disabledItems={[params.itemId!]}
+ isReadOnly={isDisabled}
+ name="itemId"
+ label={itemType}
+ includeInactive
+ validItemTypes={["Consumable", "Material", "Part"]}
+ type={itemType}
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ onTypeChange={onTypeChange}
+ />
+
+ <Number name="quantity" label="Quantity" />
+ <UnitOfMeasure
+ name="unitOfMeasureCode"
+ value={itemData.unitOfMeasureCode}
+ onChange={(newValue) =>
+ setItemData((d) => ({
+ ...d,
+ unitOfMeasureCode: newValue?.value ?? "EA",
+ }))
+ }
+ />
+ <InputControlled
+ name="description"
+ label="Description"
+ value={itemData.description}
+ onChange={(newValue) => {
+ setItemData((d) => ({ ...d, description: newValue }));
+ }}
+ className="col-span-2"
+ />
+ {itemData.methodType !== "Make" && (
+ <NumberControlled
+ name="unitCost"
+ label="Unit Cost"
+ value={itemData.unitCost}
+ minValue={0}
+ formatOptions={{
+ style: "currency",
+ currency: baseCurrency,
}}
- onTypeChange={onTypeChange}
/>
- <InputControlled
- name="description"
- label="Description"
- value={itemData.description}
- onChange={(newValue) => {
- setItemData((d) => ({ ...d, description: newValue }));
- }}
+ )}
+ </div>
+
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={sourceDisclosure.onToggle}
+ >
+ <HStack>
+ {itemData.methodType === "Make" ? (
+ <>
+ <LuGitPullRequestCreate />
+ <Label>Finish To</Label>
+ </>
+ ) : (
+ <>
+ <LuGitPullRequest />
+ <Label>Pull From</Label>
+ </>
+ )}
+ </HStack>
+ <HStack>
+ <Badge variant="secondary">
+ <MethodIcon type={itemData.methodType} className="size-3 mr-1" />
+ {itemData.methodType}
+ </Badge>
+ <LuArrowLeft
+ className={cn(itemData.methodType === "Make" ? "rotate-180" : "")}
+ />
+ <Badge variant="secondary">
+ <LuGitPullRequest className="size-3 mr-1" />
+ {shelves.options?.find((s) => s.value === itemData.shelfId)
+ ?.label ??
+ (itemData.methodType === "Make" ? "WIP" : "Default Shelf")}
+ </Badge>
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ sourceDisclosure.isOpen ? "Collapse Source" : "Expand Source"
+ }
+ variant="ghost"
+ onClick={(e) => {
+ e.stopPropagation();
+ sourceDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ sourceDisclosure.isOpen ? "rotate-90" : ""
+ }`}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ sourceDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
+ <DefaultMethodType
+ name="methodType"
+ label="Method Type"
+ value={itemData.methodType}
+ replenishmentSystem="Buy and Make"
/>
+ <Shelf name="shelfId" label="Shelf" locationId={locationId} />
+ </div>
+ </div>
+
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={backflushDisclosure.onToggle}
+ >
+ <HStack>
+ <LuGitPullRequestCreateArrow />
+ <Label>Backflush</Label>
+ </HStack>
+ <HStack>
+ <Badge
+ variant={jobOperations.length > 0 ? "secondary" : "destructive"}
+ >
+ <LuCog className="size-3 mr-1" />
+ {itemData.jobOperationId
+ ? jobOperations.find((o) => o.id === itemData.jobOperationId)
+ ?.description || "Selected Operation"
+ : "First Operation"}
+ </Badge>
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ backflushDisclosure.isOpen
+ ? "Collapse Backflush"
+ : "Expand Backflush"
+ }
+ variant="ghost"
+ size="md"
+ onClick={(e) => {
+ e.stopPropagation();
+ backflushDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ backflushDisclosure.isOpen ? "rotate-90" : ""
+ }`}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ backflushDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
<Select
name="jobOperationId"
label="Operation"
@@ -767,93 +924,66 @@ function MaterialForm({
value: o.id!,
label: o.description,
}))}
- />
-
- <DefaultMethodType
- name="methodType"
- label="Method Type"
- value={itemData.methodType}
- replenishmentSystem="Buy and Make"
- />
- <Number name="quantity" label="Quantity per Parent" />
- <UnitOfMeasure
- name="unitOfMeasureCode"
- value={itemData.unitOfMeasureCode}
- onChange={(newValue) =>
+ onChange={(newValue) => {
setItemData((d) => ({
...d,
- unitOfMeasureCode: newValue?.value ?? "EA",
- }))
- }
+ jobOperationId: newValue?.value as string,
+ }));
+ }}
/>
-
- {itemData.methodType !== "Make" && (
- <NumberControlled
- name="unitCost"
- label="Unit Cost"
- value={itemData.unitCost}
- minValue={0}
- formatOptions={{
- style: "currency",
- currency: baseCurrency,
- }}
- />
- )}
</div>
-
+ </div>
+
+ <motion.div
+ className="flex flex-1 items-center justify-end w-full pt-2"
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0,
+ duration: 0.55,
+ }}
+ >
<motion.div
- className="flex flex-1 items-center justify-end w-full pt-2"
- initial={{ opacity: 0, filter: "blur(4px)" }}
- animate={{ opacity: 1, filter: "blur(0px)" }}
- transition={{
- type: "spring",
- bounce: 0,
- duration: 0.55,
- }}
+ layout
+ className="flex items-center justify-between gap-2 w-full"
>
- <motion.div
- layout
- className="flex items-center justify-between gap-2 w-full"
- >
- {itemData.methodType === "Make" ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- leftIcon={<MethodIcon type={"Make"} isKit={itemData.kit} />}
- variant="secondary"
- size="sm"
- rightIcon={<LuChevronDown />}
- >
- {itemData.kit ? "Kit" : "Subassembly"}
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuRadioGroup
- value={itemData.kit ? "Kit" : "Subassembly"}
- onValueChange={(value) => {
- setItemData((d) => ({
- ...d,
- kit: value === "Kit",
- }));
- }}
- >
- <DropdownMenuRadioItem value="Subassembly">
- Subassembly
- </DropdownMenuRadioItem>
- <DropdownMenuRadioItem value="Kit">
- Kit
- </DropdownMenuRadioItem>
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- ) : (
- <div />
- )}
+ {itemData.methodType === "Make" ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ leftIcon={<MethodIcon type={"Make"} isKit={itemData.kit} />}
+ variant="secondary"
+ size="sm"
+ rightIcon={<LuChevronDown />}
+ >
+ {itemData.kit ? "Kit" : "Subassembly"}
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuRadioGroup
+ value={itemData.kit ? "Kit" : "Subassembly"}
+ onValueChange={(value) => {
+ setItemData((d) => ({
+ ...d,
+ kit: value === "Kit",
+ }));
+ }}
+ >
+ <DropdownMenuRadioItem value="Subassembly">
+ Subassembly
+ </DropdownMenuRadioItem>
+ <DropdownMenuRadioItem value="Kit">Kit</DropdownMenuRadioItem>
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <div />
+ )}
- <Submit isDisabled={isDisabled}>Save</Submit>
- </motion.div>
+ <Submit isDisabled={isDisabled}>Save</Submit>
</motion.div>
- </VStack>
+ </motion.div>
</ValidatedForm>
);
}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx b/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx
index 0f5d36825d..bf9ea6d82f 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx
@@ -10,7 +10,7 @@ import {
} from "@carbon/react";
import { Await, useFetcher, useParams } from "@remix-run/react";
import { Suspense, useCallback, useEffect, useState } from "react";
-import { LuBox, LuCopy, LuLink, LuUnlink2 } from "react-icons/lu";
+import { LuCopy, LuLink, LuUnlink2 } from "react-icons/lu";
import { usePermissions, useRouteData } from "~/hooks";
import type { action } from "~/routes/x+/items+/update";
@@ -288,10 +288,24 @@ const JobProperties = () => {
</Button>
</HStack>
) : (
- <Badge variant="secondary">
- <LuBox className="w-3 h-3 mr-1" />
- Inventory
- </Badge>
+ <ValidatedForm
+ defaultValues={{ shelfId: routeData?.job?.shelfId ?? undefined }}
+ validator={z.object({
+ shelfId: zfd.text(z.string().optional()),
+ })}
+ className="w-full"
+ >
+ <Shelf
+ label=""
+ name="shelfId"
+ inline
+ locationId={routeData?.job?.locationId ?? undefined}
+ isReadOnly={isDisabled}
+ onChange={(value) => {
+ onUpdate("shelfId", value?.id ?? null);
+ }}
+ />
+ </ValidatedForm>
)}
</VStack>
@@ -501,25 +515,6 @@ const JobProperties = () => {
/>
</ValidatedForm>
- <ValidatedForm
- defaultValues={{ shelfId: routeData?.job?.shelfId ?? undefined }}
- validator={z.object({
- shelfId: zfd.text(z.string().optional()),
- })}
- className="w-full"
- >
- <Shelf
- label="Shelf"
- name="shelfId"
- inline
- locationId={routeData?.job?.locationId ?? undefined}
- isReadOnly={isDisabled}
- onChange={(value) => {
- onUpdate("shelfId", value?.id ?? null);
- }}
- />
- </ValidatedForm>
-
<ValidatedForm
defaultValues={{
tags: routeData?.job.tags ?? [],
diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.ts
index c9de428cf8..5b369e5b05 100644
--- a/apps/erp/app/modules/sales/sales.models.ts
+++ b/apps/erp/app/modules/sales/sales.models.ts
@@ -233,6 +233,7 @@ export const quoteMaterialValidator = z
description: z.string().min(1, { message: "Description is required" }),
quoteOperationId: zfd.text(z.string().optional()),
quantity: zfd.numeric(z.number().min(0)),
+ shelfId: zfd.text(z.string().optional()),
unitCost: zfd.numeric(z.number().min(0)),
unitOfMeasureCode: z
.string()
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index 09d8075ce9..a05911dc35 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -17,11 +17,14 @@ import {
DropdownMenuRadioItem,
DropdownMenuTrigger,
HStack,
+ IconButton,
+ Label,
toast,
Tooltip,
TooltipContent,
TooltipTrigger,
useDebounce,
+ useDisclosure,
VStack,
} from "@carbon/react";
import { getItemReadableId } from "@carbon/utils";
@@ -31,8 +34,14 @@ import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useState } from "react";
import {
+ LuArrowLeft,
LuChevronDown,
+ LuChevronRight,
+ LuCog,
LuExternalLink,
+ LuGitPullRequest,
+ LuGitPullRequestCreate,
+ LuGitPullRequestCreateArrow,
LuSettings2,
LuX,
} from "react-icons/lu";
@@ -46,9 +55,11 @@ import {
Number,
NumberControlled,
Select,
+ Shelf,
Submit,
UnitOfMeasure,
} from "~/components/Form";
+import { useShelves } from "~/components/Form/Shelf";
import type {
Item as SortableItem,
SortableItemRenderProps,
@@ -549,11 +560,7 @@ const QuoteBillOfMaterial = ({
<CardAction>
<Button
variant="secondary"
- isDisabled={
- isDisabled ||
- !permissions.can("update", "sales") ||
- selectedItemId !== null
- }
+ isDisabled={isDisabled || !permissions.can("update", "sales")}
onClick={onAddItem}
>
Add Material
@@ -587,6 +594,7 @@ function MaterialForm({
}: {
item: ItemWithData;
isDisabled: boolean;
+
setSelectedItemId: Dispatch<SetStateAction<string | null>>;
quoteOperations: Operation[];
temporaryItems: TemporaryItems;
@@ -603,6 +611,7 @@ function MaterialForm({
const methodMaterialFetcher = useFetcher<{ id: string }>();
const params = useParams();
const { company } = useUser();
+ const routeData = useRouteData<{ quote: Quotation }>(path.to.quote(quoteId));
const baseCurrency = company?.baseCurrencyCode ?? "USD";
@@ -626,6 +635,8 @@ function MaterialForm({
unitOfMeasureCode: string;
quantity: number;
kit: boolean;
+ shelfId?: string;
+ quoteOperationId?: string;
}>({
itemId: item.data.itemId ?? "",
methodType: item.data.methodType ?? "Buy",
@@ -634,6 +645,8 @@ function MaterialForm({
unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",
quantity: item.data.quantity ?? 1,
kit: item.data.kit ?? false,
+ shelfId: item.data.shelfId,
+ quoteOperationId: item.data.quoteOperationId,
});
const onTypeChange = (value: MethodItemType | "Item") => {
@@ -641,7 +654,7 @@ function MaterialForm({
setItemType(value as MethodItemType);
setItemData({
itemId: "",
- methodType: "" as "Buy",
+ methodType: "Buy",
quantity: 1,
unitCost: 0,
description: "",
@@ -661,7 +674,7 @@ function MaterialForm({
carbon
.from("item")
.select(
- "name, readableIdWithRevision, type, unitOfMeasureCode, defaultMethodType"
+ "name, readableIdWithRevision, type, unitOfMeasureCode, defaultMethodType, itemTrackingType"
)
.eq("id", itemId)
.eq("companyId", company.id)
@@ -681,6 +694,8 @@ function MaterialForm({
unitCost: itemCost.data?.unitCost ?? 0,
unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",
methodType: item.data?.defaultMethodType ?? "Buy",
+ requiresBatchTracking: item.data?.itemTrackingType === "Batch",
+ requiresSerialTracking: item.data?.itemTrackingType === "Serial",
}));
if (item.data?.type) {
@@ -688,6 +703,11 @@ function MaterialForm({
}
};
+ const sourceDisclosure = useDisclosure();
+ const backflushDisclosure = useDisclosure();
+ const locationId = routeData?.quote?.locationId ?? undefined;
+ const shelves = useShelves(locationId);
+
return (
<ValidatedForm
action={
@@ -698,40 +718,177 @@ function MaterialForm({
method="post"
defaultValues={item.data}
validator={quoteMaterialValidator}
- className="w-full"
+ className="w-full flex flex-col gap-y-4"
fetcher={methodMaterialFetcher}
>
- <Hidden name="id" />
- <Hidden name="quoteMakeMethodId" />
- <Hidden name="order" />
- <Hidden name="kit" value={itemData.kit.toString()} />
- {itemData.methodType === "Make" && (
- <Hidden name="unitCost" value={itemData.unitCost} />
- )}
- <VStack>
- <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
- <Item
- disabledItems={[params.itemId!]}
- isReadOnly={isDisabled}
- name="itemId"
- label={itemType}
- includeInactive
- validItemTypes={["Consumable", "Material", "Part"]}
- type={itemType}
- onChange={(value) => {
- onItemChange(value?.value as string);
+ <div>
+ <Hidden name="id" />
+ <Hidden name="quoteMakeMethodId" />
+ <Hidden name="kit" value={itemData.kit.toString()} />
+ <Hidden name="order" />
+
+ {itemData.methodType === "Make" && (
+ <Hidden name="unitCost" value={itemData.unitCost} />
+ )}
+ </div>
+
+ <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
+ <Item
+ disabledItems={[params.itemId!]}
+ isReadOnly={isDisabled}
+ name="itemId"
+ label={itemType}
+ includeInactive
+ validItemTypes={["Consumable", "Material", "Part"]}
+ type={itemType}
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ onTypeChange={onTypeChange}
+ />
+
+ <Number name="quantity" label="Quantity" />
+ <UnitOfMeasure
+ name="unitOfMeasureCode"
+ value={itemData.unitOfMeasureCode}
+ onChange={(newValue) =>
+ setItemData((d) => ({
+ ...d,
+ unitOfMeasureCode: newValue?.value ?? "EA",
+ }))
+ }
+ />
+ <InputControlled
+ name="description"
+ label="Description"
+ value={itemData.description}
+ onChange={(newValue) => {
+ setItemData((d) => ({ ...d, description: newValue }));
+ }}
+ className="col-span-2"
+ />
+ {itemData.methodType !== "Make" && (
+ <NumberControlled
+ name="unitCost"
+ label="Unit Cost"
+ value={itemData.unitCost}
+ minValue={0}
+ formatOptions={{
+ style: "currency",
+ currency: baseCurrency,
}}
- onTypeChange={onTypeChange}
/>
- <InputControlled
- name="description"
- label="Description"
- value={itemData.description}
- onChange={(newValue) => {
- setItemData((d) => ({ ...d, description: newValue }));
- }}
+ )}
+ </div>
+
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={sourceDisclosure.onToggle}
+ >
+ <HStack>
+ {itemData.methodType === "Make" ? (
+ <>
+ <LuGitPullRequestCreate />
+ <Label>Finish To</Label>
+ </>
+ ) : (
+ <>
+ <LuGitPullRequest />
+ <Label>Pull From</Label>
+ </>
+ )}
+ </HStack>
+ <HStack>
+ <Badge variant="secondary">
+ <MethodIcon type={itemData.methodType} className="size-3 mr-1" />
+ {itemData.methodType}
+ </Badge>
+ <LuArrowLeft
+ className={cn(itemData.methodType === "Make" ? "rotate-180" : "")}
+ />
+ <Badge variant="secondary">
+ <LuGitPullRequest className="size-3 mr-1" />
+ {shelves.options?.find((s) => s.value === itemData.shelfId)
+ ?.label ??
+ (itemData.methodType === "Make" ? "WIP" : "Default Shelf")}
+ </Badge>
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ sourceDisclosure.isOpen ? "Collapse Source" : "Expand Source"
+ }
+ variant="ghost"
+ size="md"
+ onClick={(e) => {
+ e.stopPropagation();
+ sourceDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ sourceDisclosure.isOpen ? "rotate-90" : ""
+ }`}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ sourceDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
+ <DefaultMethodType
+ name="methodType"
+ label="Method Type"
+ value={itemData.methodType}
+ replenishmentSystem="Buy and Make"
/>
+ <Shelf name="shelfId" label="Shelf" locationId={locationId} />
+ </div>
+ </div>
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={backflushDisclosure.onToggle}
+ >
+ <HStack>
+ <LuGitPullRequestCreateArrow />
+ <Label>Backflush</Label>
+ </HStack>
+ <HStack>
+ <Badge
+ variant={quoteOperations.length > 0 ? "secondary" : "destructive"}
+ >
+ <LuCog className="size-3 mr-1" />
+ {itemData.quoteOperationId
+ ? quoteOperations.find(
+ (o) => o.id === itemData.quoteOperationId
+ )?.description || "Selected Operation"
+ : "First Operation"}
+ </Badge>
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ backflushDisclosure.isOpen
+ ? "Collapse Backflush"
+ : "Expand Backflush"
+ }
+ variant="ghost"
+ size="md"
+ onClick={(e) => {
+ e.stopPropagation();
+ backflushDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ backflushDisclosure.isOpen ? "rotate-90" : ""
+ }`}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ backflushDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
<Select
name="quoteOperationId"
label="Operation"
@@ -740,93 +897,66 @@ function MaterialForm({
value: o.id!,
label: o.description,
}))}
- />
-
- <DefaultMethodType
- name="methodType"
- label="Method Type"
- value={itemData.methodType}
- replenishmentSystem="Buy and Make"
- />
- <Number name="quantity" label="Quantity per Parent" />
- <UnitOfMeasure
- name="unitOfMeasureCode"
- value={itemData.unitOfMeasureCode}
- onChange={(newValue) =>
+ onChange={(newValue) => {
setItemData((d) => ({
...d,
- unitOfMeasureCode: newValue?.value ?? "EA",
- }))
- }
+ quoteOperationId: newValue?.value as string,
+ }));
+ }}
/>
-
- {itemData.methodType !== "Make" && (
- <NumberControlled
- name="unitCost"
- label="Unit Cost"
- value={itemData.unitCost}
- minValue={0}
- formatOptions={{
- style: "currency",
- currency: baseCurrency,
- }}
- />
- )}
</div>
-
+ </div>
+
+ <motion.div
+ className="flex flex-1 items-center justify-end w-full pt-2"
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0,
+ duration: 0.55,
+ }}
+ >
<motion.div
- className="flex flex-1 items-center justify-end w-full pt-2"
- initial={{ opacity: 0, filter: "blur(4px)" }}
- animate={{ opacity: 1, filter: "blur(0px)" }}
- transition={{
- type: "spring",
- bounce: 0,
- duration: 0.55,
- }}
+ layout
+ className="flex items-center justify-between gap-2 w-full"
>
- <motion.div
- layout
- className="flex items-center justify-between gap-2 w-full"
- >
- {itemData.methodType === "Make" ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- leftIcon={<MethodIcon type={"Make"} isKit={itemData.kit} />}
- variant="secondary"
- size="sm"
- rightIcon={<LuChevronDown />}
- >
- {itemData.kit ? "Kit" : "Subassembly"}
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuRadioGroup
- value={itemData.kit ? "Kit" : "Subassembly"}
- onValueChange={(value) => {
- setItemData((d) => ({
- ...d,
- kit: value === "Kit",
- }));
- }}
- >
- <DropdownMenuRadioItem value="Subassembly">
- Subassembly
- </DropdownMenuRadioItem>
- <DropdownMenuRadioItem value="Kit">
- Kit
- </DropdownMenuRadioItem>
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- ) : (
- <div />
- )}
+ {itemData.methodType === "Make" ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ leftIcon={<MethodIcon type={"Make"} isKit={itemData.kit} />}
+ variant="secondary"
+ size="sm"
+ rightIcon={<LuChevronDown />}
+ >
+ {itemData.kit ? "Kit" : "Subassembly"}
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuRadioGroup
+ value={itemData.kit ? "Kit" : "Subassembly"}
+ onValueChange={(value) => {
+ setItemData((d) => ({
+ ...d,
+ kit: value === "Kit",
+ }));
+ }}
+ >
+ <DropdownMenuRadioItem value="Subassembly">
+ Subassembly
+ </DropdownMenuRadioItem>
+ <DropdownMenuRadioItem value="Kit">Kit</DropdownMenuRadioItem>
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <div />
+ )}
- <Submit isDisabled={isDisabled}>Save</Submit>
- </motion.div>
+ <Submit isDisabled={isDisabled}>Save</Submit>
</motion.div>
- </VStack>
+ </motion.div>
</ValidatedForm>
);
}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 81c53b093e..433d656f56 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -9181,7 +9181,7 @@ export default {
$ref: "#/parameters/rowFilter.methodMaterial.kit",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.shelfId",
+ $ref: "#/parameters/rowFilter.methodMaterial.shelfIds",
},
{
$ref: "#/parameters/select",
@@ -9303,7 +9303,7 @@ export default {
$ref: "#/parameters/rowFilter.methodMaterial.kit",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.shelfId",
+ $ref: "#/parameters/rowFilter.methodMaterial.shelfIds",
},
{
$ref: "#/parameters/preferReturn",
@@ -9379,7 +9379,7 @@ export default {
$ref: "#/parameters/rowFilter.methodMaterial.kit",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.shelfId",
+ $ref: "#/parameters/rowFilter.methodMaterial.shelfIds",
},
{
$ref: "#/parameters/body.methodMaterial",
@@ -47814,6 +47814,9 @@ export default {
{
$ref: "#/parameters/rowFilter.pickList.id",
},
+ {
+ $ref: "#/parameters/rowFilter.pickList.pickListId",
+ },
{
$ref: "#/parameters/rowFilter.pickList.locationId",
},
@@ -47841,6 +47844,12 @@ export default {
{
$ref: "#/parameters/rowFilter.pickList.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.pickList.customFields",
+ },
+ {
+ $ref: "#/parameters/rowFilter.pickList.tags",
+ },
{
$ref: "#/parameters/select",
},
@@ -47903,6 +47912,9 @@ export default {
{
$ref: "#/parameters/rowFilter.pickList.id",
},
+ {
+ $ref: "#/parameters/rowFilter.pickList.pickListId",
+ },
{
$ref: "#/parameters/rowFilter.pickList.locationId",
},
@@ -47930,6 +47942,12 @@ export default {
{
$ref: "#/parameters/rowFilter.pickList.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.pickList.customFields",
+ },
+ {
+ $ref: "#/parameters/rowFilter.pickList.tags",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -47946,6 +47964,9 @@ export default {
{
$ref: "#/parameters/rowFilter.pickList.id",
},
+ {
+ $ref: "#/parameters/rowFilter.pickList.pickListId",
+ },
{
$ref: "#/parameters/rowFilter.pickList.locationId",
},
@@ -47973,6 +47994,12 @@ export default {
{
$ref: "#/parameters/rowFilter.pickList.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.pickList.customFields",
+ },
+ {
+ $ref: "#/parameters/rowFilter.pickList.tags",
+ },
{
$ref: "#/parameters/body.pickList",
},
@@ -63694,6 +63721,7 @@ export default {
"order",
"scrapQuantity",
"kit",
+ "shelfIds",
],
properties: {
id: {
@@ -63801,11 +63829,8 @@ export default {
format: "boolean",
type: "boolean",
},
- shelfId: {
- description:
- "Note:\nThis is a Foreign Key to `shelf.id`.<fk table='shelf' column='id'/>",
- format: "text",
- type: "string",
+ shelfIds: {
+ format: "jsonb",
},
},
type: "object",
@@ -64906,7 +64931,6 @@ export default {
status: {
enum: [
"Draft",
- "Staged",
"Ready",
"In Progress",
"Paused",
@@ -69276,7 +69300,6 @@ export default {
default: "Draft",
enum: [
"Draft",
- "Staged",
"Ready",
"In Progress",
"Paused",
@@ -71135,12 +71158,6 @@ export default {
"Audio",
"Other",
"Model",
- "Pick Transfer",
- "Vehicle Transfer",
- "Scrap Transfer",
- "Quarantine Transfer",
- "Customer Transfer",
- "Rejection Transfer",
],
format: 'public."documentType"',
type: "string",
@@ -80488,12 +80505,6 @@ export default {
"Audio",
"Other",
"Model",
- "Pick Transfer",
- "Vehicle Transfer",
- "Scrap Transfer",
- "Quarantine Transfer",
- "Customer Transfer",
- "Rejection Transfer",
],
format: 'public."documentType"',
type: "string",
@@ -82137,6 +82148,7 @@ export default {
pickList: {
required: [
"id",
+ "pickListId",
"locationId",
"status",
"createdDate",
@@ -82151,6 +82163,10 @@ export default {
format: "text",
type: "string",
},
+ pickListId: {
+ format: "text",
+ type: "string",
+ },
locationId: {
description:
"Note:\nThis is a Foreign Key to `location.id`.<fk table='location' column='id'/>",
@@ -82199,6 +82215,16 @@ export default {
format: "text",
type: "string",
},
+ customFields: {
+ format: "jsonb",
+ },
+ tags: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
},
type: "object",
},
@@ -90847,8 +90873,8 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.methodMaterial.shelfId": {
- name: "shelfId",
+ "rowFilter.methodMaterial.shelfIds": {
+ name: "shelfIds",
required: false,
in: "query",
type: "string",
@@ -111562,6 +111588,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.pickList.pickListId": {
+ name: "pickListId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.pickList.locationId": {
name: "locationId",
required: false,
@@ -111616,6 +111648,18 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.pickList.customFields": {
+ name: "customFields",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.pickList.tags": {
+ name: "tags",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.salesInvoiceShipment": {
name: "salesInvoiceShipment",
description: "salesInvoiceShipment",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 59535bdd07..9036bf118c 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -13100,7 +13100,7 @@ export type Database = {
productionQuantity: number | null
quantity: number
scrapQuantity: number
- shelfId: string | null
+ shelfIds: Json
tags: string[] | null
unitOfMeasureCode: string
updatedAt: string | null
@@ -13123,7 +13123,7 @@ export type Database = {
productionQuantity?: number | null
quantity: number
scrapQuantity?: number
- shelfId?: string | null
+ shelfIds?: Json
tags?: string[] | null
unitOfMeasureCode: string
updatedAt?: string | null
@@ -13146,7 +13146,7 @@ export type Database = {
productionQuantity?: number | null
quantity?: number
scrapQuantity?: number
- shelfId?: string | null
+ shelfIds?: Json
tags?: string[] | null
unitOfMeasureCode?: string
updatedAt?: string | null
@@ -13314,13 +13314,6 @@ export type Database = {
referencedRelation: "methodOperation"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "methodMaterial_shelfId_fkey"
- columns: ["shelfId"]
- isOneToOne: false
- referencedRelation: "shelf"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "methodMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -18509,9 +18502,12 @@ export type Database = {
createdAt: string
createdBy: string
createdDate: string
+ customFields: Json | null
id: string
locationId: string
+ pickListId: string
status: Database["public"]["Enums"]["pickListStatus"]
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
}
@@ -18521,9 +18517,12 @@ export type Database = {
createdAt?: string
createdBy: string
createdDate?: string
+ customFields?: Json | null
id?: string
locationId: string
+ pickListId: string
status?: Database["public"]["Enums"]["pickListStatus"]
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -18533,9 +18532,12 @@ export type Database = {
createdAt?: string
createdBy?: string
createdDate?: string
+ customFields?: Json | null
id?: string
locationId?: string
+ pickListId?: string
status?: Database["public"]["Enums"]["pickListStatus"]
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -24896,6 +24898,7 @@ export type Database = {
quoteMakeMethodId: string
quoteOperationId: string | null
scrapQuantity: number
+ shelfId: string | null
tags: string[] | null
unitCost: number
unitOfMeasureCode: string | null
@@ -24921,6 +24924,7 @@ export type Database = {
quoteMakeMethodId: string
quoteOperationId?: string | null
scrapQuantity?: number
+ shelfId?: string | null
tags?: string[] | null
unitCost?: number
unitOfMeasureCode?: string | null
@@ -24946,6 +24950,7 @@ export type Database = {
quoteMakeMethodId?: string
quoteOperationId?: string | null
scrapQuantity?: number
+ shelfId?: string | null
tags?: string[] | null
unitCost?: number
unitOfMeasureCode?: string | null
@@ -25121,6 +25126,13 @@ export type Database = {
referencedRelation: "quoteOperationsWithMakeMethods"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteMaterial_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -44090,6 +44102,7 @@ export type Database = {
quoteMaterialMakeMethodId: string | null
quoteOperationId: string | null
scrapQuantity: number | null
+ shelfId: string | null
tags: string[] | null
unitCost: number | null
unitOfMeasureCode: string | null
@@ -44266,6 +44279,13 @@ export type Database = {
referencedRelation: "quoteOperationsWithMakeMethods"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteMaterial_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -48699,6 +48719,7 @@ export type Database = {
parentMaterialId: string
quantity: number
revision: string
+ shelfIds: Json
unitCost: number
unitOfMeasureCode: string
version: number
@@ -49041,6 +49062,7 @@ export type Database = {
quoteMakeMethodId: string
quoteMaterialMakeMethodId: string
revision: string
+ shelfId: string
unitCost: number
version: number
}[]
@@ -49066,6 +49088,7 @@ export type Database = {
quoteMakeMethodId: string
quoteMaterialMakeMethodId: string
revision: string
+ shelfId: string
unitCost: number
unitOfMeasureCode: string
version: number
@@ -49467,12 +49490,6 @@ export type Database = {
| "Audio"
| "Other"
| "Model"
- | "Pick Transfer"
- | "Vehicle Transfer"
- | "Scrap Transfer"
- | "Quarantine Transfer"
- | "Customer Transfer"
- | "Rejection Transfer"
externalLinkDocumentType: "Quote" | "SupplierQuote" | "Customer"
factor:
| "Hours/Piece"
@@ -49578,7 +49595,6 @@ export type Database = {
| "Waiting"
jobStatus:
| "Draft"
- | "Staged"
| "Ready"
| "In Progress"
| "Paused"
@@ -50557,12 +50573,6 @@ export const Constants = {
"Audio",
"Other",
"Model",
- "Pick Transfer",
- "Vehicle Transfer",
- "Scrap Transfer",
- "Quarantine Transfer",
- "Customer Transfer",
- "Rejection Transfer",
],
externalLinkDocumentType: ["Quote", "SupplierQuote", "Customer"],
factor: [
@@ -50678,7 +50688,6 @@ export const Constants = {
],
jobStatus: [
"Draft",
- "Staged",
"Ready",
"In Progress",
"Paused",
diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.ts
index 6d9c6829ae..ea76b7f4bc 100644
--- a/packages/database/supabase/functions/get-method/index.ts
+++ b/packages/database/supabase/functions/get-method/index.ts
@@ -280,7 +280,7 @@ serve(async (req: Request) => {
const itemId = sourceId;
const isConfigured = !!configuration;
- const [makeMethod, jobMakeMethod, workCenters, supplierProcesses] =
+ const [makeMethod, jobMakeMethod, workCenters, supplierProcesses, job] =
await Promise.all([
client
.from("activeMakeMethods")
@@ -300,6 +300,12 @@ serve(async (req: Request) => {
.from("supplierProcess")
.select("*")
.eq("companyId", companyId),
+ client
+ .from("job")
+ .select("locationId")
+ .eq("id", jobId)
+ .eq("companyId", companyId)
+ .single(),
]);
if (makeMethod.error) {
@@ -314,6 +320,10 @@ serve(async (req: Request) => {
throw new Error("Failed to get related work centers");
}
+ if (job.error) {
+ throw new Error("Failed to get job");
+ }
+
const hydratedConfiguration = await hydrateConfiguration(
client,
configuration,
@@ -674,6 +684,8 @@ serve(async (req: Request) => {
) ?? {};
}
+ const locationId = job.data?.locationId;
+
const mapMethodMaterialToJobMaterial = async (
child: MethodTreeItem
) => {
@@ -755,6 +767,10 @@ serve(async (req: Request) => {
order: child.data.order,
description,
quantity,
+ shelfId: locationId
+ ? // @ts-ignore
+ (child.data.shelfIds?.[locationId] as string) || null
+ : null,
requiresSerialTracking,
requiresBatchTracking,
unitOfMeasureCode,
@@ -909,7 +925,13 @@ serve(async (req: Request) => {
companyId
);
- const [methodTrees, configurationRules] = await Promise.all([
+ const [job, methodTrees, configurationRules] = await Promise.all([
+ client
+ .from("job")
+ .select("locationId")
+ .eq("id", jobMakeMethod.data.jobId)
+ .eq("companyId", companyId)
+ .single(),
getMethodTree(client, makeMethod.data.id!),
isConfigured
? client
@@ -960,38 +982,6 @@ serve(async (req: Request) => {
.execute(),
]);
- function getFieldKey(field: string, id: string) {
- return `${field}:${id}`;
- }
-
- async function getConfiguredValue<T>({
- id,
- field,
- defaultValue,
- }: {
- id: string;
- field: string;
- defaultValue: T;
- }): Promise<T> {
- if (!configurationCodeByField) return defaultValue;
- const fieldKey = getFieldKey(field, id);
-
- if (configurationCodeByField?.[fieldKey]) {
- try {
- const mod = await importTypeScript(
- configurationCodeByField[fieldKey]
- );
- const result = await mod.configure(hydratedConfiguration);
- return (result ?? defaultValue) as T;
- } catch (err) {
- console.error(err);
- return defaultValue;
- }
- }
-
- return defaultValue;
- }
-
// traverse method tree and create:
// - jobMakeMethod
// - jobMakeMethodOperation
@@ -1153,6 +1143,8 @@ serve(async (req: Request) => {
requiresSerialTracking: child.data.itemTrackingType === "Serial",
unitOfMeasureCode: child.data.unitOfMeasureCode,
unitCost: child.data.unitCost,
+ // @ts-ignore
+ shelfId: child.data.shelfIds?.[job.data.locationId] || null,
companyId,
createdBy: userId,
customFields: {},
@@ -1236,6 +1228,7 @@ serve(async (req: Request) => {
workCenters,
supplierProcesses,
configurationRules,
+ quote,
] = await Promise.all([
client
.from("activeMakeMethods")
@@ -1259,6 +1252,12 @@ serve(async (req: Request) => {
.eq("itemId", itemId)
.eq("companyId", companyId)
: Promise.resolve({ data: null, error: null }),
+ client
+ .from("quote")
+ .select("locationId")
+ .eq("id", quoteId)
+ .eq("companyId", companyId)
+ .single(),
]);
const configurationCodeByField = configurationRules?.data?.reduce<
@@ -1268,6 +1267,8 @@ serve(async (req: Request) => {
return acc;
}, {});
+ const quoteLocationId = quote.data?.locationId;
+
if (makeMethod.error) {
throw new Error("Failed to get make method");
}
@@ -1715,6 +1716,10 @@ serve(async (req: Request) => {
methodType,
description,
quantity,
+ shelfId: quoteLocationId
+ ? // @ts-ignore: shelfIds is a dynamic object with location keys
+ (child.data.shelfIds?.[quoteLocationId] as string) || null
+ : null,
unitOfMeasureCode,
unitCost,
companyId,
@@ -2104,6 +2109,7 @@ serve(async (req: Request) => {
order: child.data.order,
description: child.data.description,
quantity: child.data.quantity,
+ shelfId: (child.data as any).shelfId || null, // @ts-ignore: shelfId field exists in database but types may not be updated
unitOfMeasureCode: child.data.unitOfMeasureCode,
unitCost: child.data.unitCost,
companyId,
@@ -2204,7 +2210,13 @@ serve(async (req: Request) => {
const itemId = makeMethod.data?.itemId;
- const [jobOperations, itemReplenishment] = await Promise.all([
+ const [job, jobOperations, itemReplenishment] = await Promise.all([
+ client
+ .from("job")
+ .select("locationId")
+ .eq("id", jobMakeMethod.data.jobId)
+ .eq("companyId", companyId)
+ .single(),
client
.from("jobOperationsWithMakeMethods")
.select(
@@ -2295,7 +2307,11 @@ serve(async (req: Request) => {
order: child.data.order,
quantity: child.data.quantity,
unitOfMeasureCode: child.data.unitOfMeasureCode,
- shelfId: child.data.shelfId || null,
+ shelfIds: job.data?.locationId
+ ? {
+ [job.data.locationId]: child.data.shelfId || null,
+ }
+ : {},
companyId,
createdBy: userId,
customFields: {},
@@ -2465,28 +2481,35 @@ serve(async (req: Request) => {
}
const makeMethodId = targetId;
- const [makeMethod, jobMakeMethod, jobOperations] = await Promise.all([
- client
- .from("makeMethod")
- .select("*")
- .eq("id", makeMethodId)
- .eq("companyId", companyId)
- .single(),
- client
- .from("jobMakeMethod")
- .select("*")
- .eq("jobId", jobId)
- .is("parentMaterialId", null)
- .eq("companyId", companyId)
- .single(),
- client
- .from("jobOperationsWithMakeMethods")
- .select(
- "*, jobOperationTool(*), jobOperationParameter(*), jobOperationStep(*)"
- )
- .eq("jobId", jobId)
- .eq("companyId", companyId),
- ]);
+ const [makeMethod, jobMakeMethod, jobOperations, job] =
+ await Promise.all([
+ client
+ .from("makeMethod")
+ .select("*")
+ .eq("id", makeMethodId)
+ .eq("companyId", companyId)
+ .single(),
+ client
+ .from("jobMakeMethod")
+ .select("*")
+ .eq("jobId", jobId)
+ .is("parentMaterialId", null)
+ .eq("companyId", companyId)
+ .single(),
+ client
+ .from("jobOperationsWithMakeMethods")
+ .select(
+ "*, jobOperationTool(*), jobOperationParameter(*), jobOperationStep(*)"
+ )
+ .eq("jobId", jobId)
+ .eq("companyId", companyId),
+ client
+ .from("job")
+ .select("locationId")
+ .eq("id", jobId)
+ .eq("companyId", companyId)
+ .single(),
+ ]);
if (makeMethod.error) {
throw new Error("Failed to get make method");
@@ -2575,7 +2598,11 @@ serve(async (req: Request) => {
order: child.data.order,
quantity: child.data.quantity,
unitOfMeasureCode: child.data.unitOfMeasureCode,
- shelfId: child.data.shelfId || null,
+ shelfIds: job.data?.locationId
+ ? {
+ [job.data.locationId]: child.data.shelfId || null,
+ }
+ : {},
companyId,
createdBy: userId,
customFields: {},
@@ -3073,7 +3100,13 @@ serve(async (req: Request) => {
const itemId = makeMethod.data?.itemId;
- const [quoteMethodTrees, itemReplenishment] = await Promise.all([
+ const [quote, quoteMethodTrees, itemReplenishment] = await Promise.all([
+ client
+ .from("quote")
+ .select("locationId")
+ .eq("id", quoteId)
+ .eq("companyId", companyId)
+ .single(),
getQuoteMethodTree(client, quoteMakeMethod.data.id),
client
.from("itemReplenishment")
@@ -3151,8 +3184,11 @@ serve(async (req: Request) => {
methodType: child.data.methodType,
order: child.data.order,
quantity: child.data.quantity,
+ shelfIds: quote.data?.locationId
+ ? // @ts-ignore: shelfIds is a dynamic object with location keys
+ { [quote.data.locationId]: child.data.shelfId || null }
+ : {},
unitOfMeasureCode: child.data.unitOfMeasureCode,
- shelfId: child.data.shelfId || null,
companyId,
createdBy: userId,
customFields: {},
@@ -3443,7 +3479,6 @@ serve(async (req: Request) => {
order: child.data.order,
quantity: child.data.quantity,
unitOfMeasureCode: child.data.unitOfMeasureCode,
- shelfId: child.data.shelfId || null,
companyId,
createdBy: userId,
customFields: {},
@@ -3733,6 +3768,7 @@ serve(async (req: Request) => {
child.data.quoteMakeMethodId
],
quantity: child.data.quantity,
+ shelfId: child.data.shelfId,
requiresBatchTracking:
child.data.itemTrackingType === "Batch",
requiresSerialTracking:
@@ -4021,6 +4057,7 @@ serve(async (req: Request) => {
child.data.quoteMakeMethodId
],
quantity: child.data.quantity,
+ shelfId: child.data.shelfId,
unitOfMeasureCode: child.data.unitOfMeasureCode,
unitCost: child.data.unitCost, // TODO: get unit cost
companyId,
@@ -4495,6 +4532,7 @@ serve(async (req: Request) => {
child.data.quoteMakeMethodId
],
quantity: child.data.quantity,
+ shelfId: child.data.shelfId,
unitCost: child.data.unitCost, // TODO: get unit cost
unitOfMeasureCode: child.data.unitOfMeasureCode,
companyId,
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 59535bdd07..9036bf118c 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -13100,7 +13100,7 @@ export type Database = {
productionQuantity: number | null
quantity: number
scrapQuantity: number
- shelfId: string | null
+ shelfIds: Json
tags: string[] | null
unitOfMeasureCode: string
updatedAt: string | null
@@ -13123,7 +13123,7 @@ export type Database = {
productionQuantity?: number | null
quantity: number
scrapQuantity?: number
- shelfId?: string | null
+ shelfIds?: Json
tags?: string[] | null
unitOfMeasureCode: string
updatedAt?: string | null
@@ -13146,7 +13146,7 @@ export type Database = {
productionQuantity?: number | null
quantity?: number
scrapQuantity?: number
- shelfId?: string | null
+ shelfIds?: Json
tags?: string[] | null
unitOfMeasureCode?: string
updatedAt?: string | null
@@ -13314,13 +13314,6 @@ export type Database = {
referencedRelation: "methodOperation"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "methodMaterial_shelfId_fkey"
- columns: ["shelfId"]
- isOneToOne: false
- referencedRelation: "shelf"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "methodMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -18509,9 +18502,12 @@ export type Database = {
createdAt: string
createdBy: string
createdDate: string
+ customFields: Json | null
id: string
locationId: string
+ pickListId: string
status: Database["public"]["Enums"]["pickListStatus"]
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
}
@@ -18521,9 +18517,12 @@ export type Database = {
createdAt?: string
createdBy: string
createdDate?: string
+ customFields?: Json | null
id?: string
locationId: string
+ pickListId: string
status?: Database["public"]["Enums"]["pickListStatus"]
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -18533,9 +18532,12 @@ export type Database = {
createdAt?: string
createdBy?: string
createdDate?: string
+ customFields?: Json | null
id?: string
locationId?: string
+ pickListId?: string
status?: Database["public"]["Enums"]["pickListStatus"]
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -24896,6 +24898,7 @@ export type Database = {
quoteMakeMethodId: string
quoteOperationId: string | null
scrapQuantity: number
+ shelfId: string | null
tags: string[] | null
unitCost: number
unitOfMeasureCode: string | null
@@ -24921,6 +24924,7 @@ export type Database = {
quoteMakeMethodId: string
quoteOperationId?: string | null
scrapQuantity?: number
+ shelfId?: string | null
tags?: string[] | null
unitCost?: number
unitOfMeasureCode?: string | null
@@ -24946,6 +24950,7 @@ export type Database = {
quoteMakeMethodId?: string
quoteOperationId?: string | null
scrapQuantity?: number
+ shelfId?: string | null
tags?: string[] | null
unitCost?: number
unitOfMeasureCode?: string | null
@@ -25121,6 +25126,13 @@ export type Database = {
referencedRelation: "quoteOperationsWithMakeMethods"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteMaterial_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -44090,6 +44102,7 @@ export type Database = {
quoteMaterialMakeMethodId: string | null
quoteOperationId: string | null
scrapQuantity: number | null
+ shelfId: string | null
tags: string[] | null
unitCost: number | null
unitOfMeasureCode: string | null
@@ -44266,6 +44279,13 @@ export type Database = {
referencedRelation: "quoteOperationsWithMakeMethods"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteMaterial_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -48699,6 +48719,7 @@ export type Database = {
parentMaterialId: string
quantity: number
revision: string
+ shelfIds: Json
unitCost: number
unitOfMeasureCode: string
version: number
@@ -49041,6 +49062,7 @@ export type Database = {
quoteMakeMethodId: string
quoteMaterialMakeMethodId: string
revision: string
+ shelfId: string
unitCost: number
version: number
}[]
@@ -49066,6 +49088,7 @@ export type Database = {
quoteMakeMethodId: string
quoteMaterialMakeMethodId: string
revision: string
+ shelfId: string
unitCost: number
unitOfMeasureCode: string
version: number
@@ -49467,12 +49490,6 @@ export type Database = {
| "Audio"
| "Other"
| "Model"
- | "Pick Transfer"
- | "Vehicle Transfer"
- | "Scrap Transfer"
- | "Quarantine Transfer"
- | "Customer Transfer"
- | "Rejection Transfer"
externalLinkDocumentType: "Quote" | "SupplierQuote" | "Customer"
factor:
| "Hours/Piece"
@@ -49578,7 +49595,6 @@ export type Database = {
| "Waiting"
jobStatus:
| "Draft"
- | "Staged"
| "Ready"
| "In Progress"
| "Paused"
@@ -50557,12 +50573,6 @@ export const Constants = {
"Audio",
"Other",
"Model",
- "Pick Transfer",
- "Vehicle Transfer",
- "Scrap Transfer",
- "Quarantine Transfer",
- "Customer Transfer",
- "Rejection Transfer",
],
externalLinkDocumentType: ["Quote", "SupplierQuote", "Customer"],
factor: [
@@ -50678,7 +50688,6 @@ export const Constants = {
],
jobStatus: [
"Draft",
- "Staged",
"Ready",
"In Progress",
"Paused",
diff --git a/packages/database/supabase/migrations/20251007014240_pick-lists.sql b/packages/database/supabase/migrations/20251007014240_pick-lists.sql
index f9ac306626..3ce1d1ea0b 100644
--- a/packages/database/supabase/migrations/20251007014240_pick-lists.sql
+++ b/packages/database/supabase/migrations/20251007014240_pick-lists.sql
@@ -5,9 +5,8 @@ BEGIN
SELECT 1 FROM information_schema.columns
WHERE table_name = 'methodMaterial' AND column_name = 'shelfId'
) THEN
- ALTER TABLE "methodMaterial" ADD COLUMN "shelfId" TEXT;
- ALTER TABLE "methodMaterial" ADD CONSTRAINT "methodMaterial_shelfId_fkey"
- FOREIGN KEY ("shelfId") REFERENCES "shelf" ("id") ON DELETE SET NULL ON UPDATE CASCADE;
+ ALTER TABLE "methodMaterial" ADD COLUMN "shelfIds" JSONB NOT NULL DEFAULT '{}';
+
END IF;
END $$;
@@ -24,6 +23,19 @@ BEGIN
END IF;
END $$;
+-- Add shelfId to quoteMaterial table for pick-from location
+DO $$
+BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'quoteMaterial' AND column_name = 'shelfId'
+ ) THEN
+ ALTER TABLE "quoteMaterial" ADD COLUMN "shelfId" TEXT;
+ ALTER TABLE "quoteMaterial" ADD CONSTRAINT "quoteMaterial_shelfId_fkey"
+ FOREIGN KEY ("shelfId") REFERENCES "shelf" ("id") ON DELETE SET NULL ON UPDATE CASCADE;
+ END IF;
+END $$;
+
-- Update jobMaterialWithMakeMethodId view to include shelfId
DROP VIEW IF EXISTS "jobMaterialWithMakeMethodId";
CREATE OR REPLACE VIEW "jobMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true) AS
@@ -38,6 +50,17 @@ CREATE OR REPLACE VIEW "jobMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true)
ON jmm."parentMaterialId" = jm."id"
INNER JOIN "item" i ON i.id = jm."itemId";
+
+DROP VIEW IF EXISTS "quoteMaterialWithMakeMethodId";
+CREATE OR REPLACE VIEW "quoteMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ qm.*,
+ qmm."id" AS "quoteMaterialMakeMethodId",
+ qmm.version AS "version"
+ FROM "quoteMaterial" qm
+ LEFT JOIN "quoteMakeMethod" qmm
+ ON qmm."parentMaterialId" = qm."id";
+
-- Create pick list status enum
CREATE TYPE "pickListStatus" AS ENUM (
'Draft',
@@ -187,4 +210,5 @@ FOR DELETE USING (
get_companies_with_employee_permission ('inventory_delete')
)::text[]
)
-);
\ No newline at end of file
+);
+
diff --git a/packages/database/supabase/migrations/20251007014346_update-job-method-rpcs-with-shelf.sql b/packages/database/supabase/migrations/20251007014346_update-job-method-rpcs-with-shelf.sql
index 851231e5de..f7d1649186 100644
--- a/packages/database/supabase/migrations/20251007014346_update-job-method-rpcs-with-shelf.sql
+++ b/packages/database/supabase/migrations/20251007014346_update-job-method-rpcs-with-shelf.sql
@@ -265,4 +265,325 @@ FROM material
INNER JOIN item ON material."itemId" = item.id
WHERE material."jobId" = jid
ORDER BY "order"
-$$ LANGUAGE sql STABLE;
\ No newline at end of file
+$$ LANGUAGE sql STABLE;
+
+
+DROP FUNCTION get_method_tree;
+CREATE OR REPLACE FUNCTION get_method_tree(uid TEXT)
+RETURNS TABLE (
+ "methodMaterialId" TEXT,
+ "makeMethodId" TEXT,
+ "materialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "itemType" TEXT,
+ "description" TEXT,
+ "unitOfMeasureCode" TEXT,
+ "unitCost" NUMERIC,
+ "quantity" NUMERIC,
+ "methodType" "methodType",
+ "itemTrackingType" TEXT,
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "operationId" TEXT,
+ "isRoot" BOOLEAN,
+ "kit" BOOLEAN,
+ "revision" TEXT,
+ "externalId" JSONB,
+ "version" NUMERIC(10,2),
+ "shelfIds" JSONB
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "id",
+ "makeMethodId",
+ "methodType",
+ "materialMakeMethodId",
+ "itemId",
+ "itemType",
+ "quantity",
+ "makeMethodId" AS "parentMaterialId",
+ NULL AS "operationId",
+ COALESCE("order", 1) AS "order",
+ "kit",
+ "shelfIds"
+ FROM
+ "methodMaterial"
+ WHERE
+ "makeMethodId" = uid
+ UNION
+ SELECT
+ child."id",
+ child."makeMethodId",
+ child."methodType",
+ child."materialMakeMethodId",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ parent."id" AS "parentMaterialId",
+ child."methodOperationId" AS "operationId",
+ child."order",
+ child."kit",
+ child."shelfIds"
+ FROM
+ "methodMaterial" child
+ INNER JOIN material parent ON parent."materialMakeMethodId" = child."makeMethodId"
+)
+SELECT
+ material.id as "methodMaterialId",
+ material."makeMethodId",
+ material."materialMakeMethodId",
+ material."itemId",
+ item."readableIdWithRevision" AS "itemReadableId",
+ material."itemType",
+ item."name" AS "description",
+ item."unitOfMeasureCode",
+ cost."unitCost",
+ material."quantity",
+ material."methodType",
+ item."itemTrackingType",
+ material."parentMaterialId",
+ material."order",
+ material."operationId",
+ false AS "isRoot",
+ material."kit",
+ item."revision",
+ item."externalId",
+ mm2."version",
+ material."shelfIds"
+FROM material
+INNER JOIN item
+ ON material."itemId" = item.id
+INNER JOIN "itemCost" cost
+ ON item.id = cost."itemId"
+INNER JOIN "makeMethod" mm
+ ON material."makeMethodId" = mm.id
+LEFT JOIN "makeMethod" mm2
+ ON material."materialMakeMethodId" = mm2.id
+UNION
+SELECT
+ mm."id" AS "methodMaterialId",
+ NULL AS "makeMethodId",
+ mm.id AS "materialMakeMethodId",
+ mm."itemId",
+ item."readableIdWithRevision" AS "itemReadableId",
+ item."type"::text,
+ item."name" AS "description",
+ item."unitOfMeasureCode",
+ cost."unitCost",
+ 1 AS "quantity",
+ 'Make' AS "methodType",
+ item."itemTrackingType",
+ NULL AS "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ NULL AS "operationId",
+ true AS "isRoot",
+ false AS "kit",
+ item."revision",
+ item."externalId",
+ mm."version",
+ '{}'::JSONB AS "shelfIds"
+FROM "makeMethod" mm
+INNER JOIN item
+ ON mm."itemId" = item.id
+INNER JOIN "itemCost" cost
+ ON item.id = cost."itemId"
+WHERE mm.id = uid
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;
+
+DROP FUNCTION IF EXISTS get_quote_methods_by_method_id;
+CREATE OR REPLACE FUNCTION get_quote_methods_by_method_id(mid TEXT)
+RETURNS TABLE (
+ "quoteId" TEXT,
+ "quoteLineId" TEXT,
+ "methodMaterialId" TEXT,
+ "quoteMakeMethodId" TEXT,
+ "quoteMaterialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "description" TEXT,
+ "unitOfMeasureCode" TEXT,
+ "itemType" TEXT,
+ "itemTrackingType" TEXT,
+ "quantity" NUMERIC,
+ "unitCost" NUMERIC,
+ "methodType" "methodType",
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "isRoot" BOOLEAN,
+ "kit" BOOLEAN,
+ "revision" TEXT,
+ "externalId" JSONB,
+ "version" NUMERIC(10,2),
+ "shelfId" TEXT
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "quoteId",
+ "quoteLineId",
+ "id",
+ "id" AS "quoteMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "quoteMaterialMakeMethodId",
+ "version",
+ "itemId",
+ 'Part' AS "itemType",
+ 1::NUMERIC AS "quantity",
+ 0::NUMERIC AS "unitCost",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot",
+ FALSE AS "kit",
+ NULL::TEXT AS "shelfId"
+ FROM
+ "quoteMakeMethod"
+ WHERE
+ "id" = mid
+ UNION
+ SELECT
+ child."quoteId",
+ child."quoteLineId",
+ child."id",
+ child."quoteMakeMethodId",
+ child."methodType",
+ child."quoteMaterialMakeMethodId",
+ child."version",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ child."unitCost",
+ parent."id" AS "parentMaterialId",
+ child."order",
+ FALSE AS "isRoot",
+ child."kit",
+ child."shelfId"
+ FROM
+ "quoteMaterialWithMakeMethodId" child
+ INNER JOIN material parent ON parent."quoteMaterialMakeMethodId" = child."quoteMakeMethodId"
+ WHERE parent."methodType" = 'Make'
+)
+SELECT
+ material."quoteId",
+ material."quoteLineId",
+ material.id as "methodMaterialId",
+ material."quoteMakeMethodId",
+ material."quoteMaterialMakeMethodId",
+ material."itemId",
+ item."readableIdWithRevision" AS "itemReadableId",
+ item."name" AS "description",
+ item."unitOfMeasureCode",
+ material."itemType",
+ item."itemTrackingType",
+ material."quantity",
+ material."unitCost",
+ material."methodType",
+ material."parentMaterialId",
+ material."order",
+ material."isRoot",
+ material."kit",
+ item."revision",
+ item."externalId",
+ material."version",
+ material."shelfId"
+FROM material
+INNER JOIN item ON material."itemId" = item.id
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;
+
+
+DROP FUNCTION IF EXISTS get_quote_methods;
+CREATE OR REPLACE FUNCTION get_quote_methods(qid TEXT)
+RETURNS TABLE (
+ "quoteId" TEXT,
+ "quoteLineId" TEXT,
+ "methodMaterialId" TEXT,
+ "quoteMakeMethodId" TEXT,
+ "quoteMaterialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "description" TEXT,
+ "itemType" TEXT,
+ "quantity" NUMERIC,
+ "unitCost" NUMERIC,
+ "methodType" "methodType",
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "isRoot" BOOLEAN,
+ "kit" BOOLEAN,
+ "revision" TEXT,
+ "externalId" JSONB,
+ "version" NUMERIC(10,2),
+ "shelfId" TEXT
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "quoteId",
+ "quoteLineId",
+ "id",
+ "id" AS "quoteMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "quoteMaterialMakeMethodId",
+ "itemId",
+ 'Part' AS "itemType",
+ 1::NUMERIC AS "quantity",
+ 0::NUMERIC AS "unitCost",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot",
+ FALSE AS "kit",
+ "version",
+ NULL::TEXT AS "shelfId"
+ FROM
+ "quoteMakeMethod"
+ WHERE
+ "quoteId" = qid
+ AND "parentMaterialId" IS NULL
+ UNION
+ SELECT
+ child."quoteId",
+ child."quoteLineId",
+ child."id",
+ child."quoteMakeMethodId",
+ child."methodType",
+ child."quoteMaterialMakeMethodId",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ child."unitCost",
+ parent."id" AS "parentMaterialId",
+ child."order",
+ FALSE AS "isRoot",
+ child."kit",
+ child."version",
+ child."shelfId"
+ FROM
+ "quoteMaterialWithMakeMethodId" child
+ INNER JOIN material parent ON parent."quoteMaterialMakeMethodId" = child."quoteMakeMethodId"
+)
+SELECT
+ material."quoteId",
+ material."quoteLineId",
+ material.id as "methodMaterialId",
+ material."quoteMakeMethodId",
+ material."quoteMaterialMakeMethodId",
+ material."itemId",
+ item."readableIdWithRevision" AS "itemReadableId",
+ item."name" AS "description",
+ material."itemType",
+ material."quantity",
+ material."unitCost",
+ material."methodType",
+ material."parentMaterialId",
+ material."order",
+ material."isRoot",
+ material."kit",
+ item."revision",
+ item."externalId",
+ material."version",
+ material."shelfId"
+FROM material
+INNER JOIN item ON material."itemId" = item.id
+WHERE material."quoteId" = qid
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;