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.

wip: quote BoM and BoP routes

Brad Barbinbd1a6dbe5198
diff --git a/apps/carbon/app/components/Gantt/Gantt.tsx b/apps/carbon/app/components/Gantt/Gantt.tsx
index 1288c3aa27..465c404f86 100644
--- a/apps/carbon/app/components/Gantt/Gantt.tsx
+++ b/apps/carbon/app/components/Gantt/Gantt.tsx
@@ -41,7 +41,7 @@ import type { GanttEvent } from "~/components/Gantt/types";
import { ShortcutKey, variants } from "~/components/ShortcutKey";
import * as Timeline from "~/components/Timeline";
import type { NodesState, UseTreeStateOutput } from "~/components/TreeView";
-import { TreeView, useTree } from "~/components/TreeView";
+import { LevelLine, TreeView, useTree } from "~/components/TreeView";
import { useShortcutKeys } from "~/hooks";
import type { Shortcut } from "~/hooks/useShortcutKeys";
import { setResizableGanttSettings } from "~/utils/resizablePanel";
@@ -181,7 +181,7 @@ const Gantt = ({
>
<div className="flex h-8 items-center">
{Array.from({ length: node.level }).map((_, index) => (
- <TaskLine
+ <LevelLine
key={index}
isError={node.data.isError}
isSelected={state.selected}
@@ -608,24 +608,6 @@ function NodeStatusIcon({ node }: { node: GanttEvent }) {
);
}
-function TaskLine({
- isError,
- isSelected,
-}: {
- isError: boolean;
- isSelected: boolean;
-}) {
- return (
- <div
- className={cn(
- "h-8 w-2 border-r border-border",
- isError && "border-destructive",
- isSelected && "border-foreground"
- )}
- />
- );
-}
-
function ShowParentLink({ ganttReadableId }: { ganttReadableId: string }) {
const [mouseOver, setMouseOver] = useState(false);
const { spanParam } = useParams();
diff --git a/apps/carbon/app/components/TreeView/TreeView.tsx b/apps/carbon/app/components/TreeView/TreeView.tsx
index d68c3059f3..a2fb37056b 100644
--- a/apps/carbon/app/components/TreeView/TreeView.tsx
+++ b/apps/carbon/app/components/TreeView/TreeView.tsx
@@ -618,3 +618,21 @@ export function createTreeFromFlatItems<TData>(
return indexedItems[rootId];
}
+
+export function LevelLine({
+ isError = false,
+ isSelected,
+}: {
+ isError?: boolean;
+ isSelected: boolean;
+}) {
+ return (
+ <div
+ className={cn(
+ "h-8 w-2 border-r border-border",
+ isError && "border-destructive",
+ isSelected && "border-foreground"
+ )}
+ />
+ );
+}
diff --git a/apps/carbon/app/components/TreeView/index.ts b/apps/carbon/app/components/TreeView/index.ts
index 4ecd0ce2b5..b7766fcf41 100644
--- a/apps/carbon/app/components/TreeView/index.ts
+++ b/apps/carbon/app/components/TreeView/index.ts
@@ -1,8 +1,8 @@
import type { NodesState, NodeState } from "./reducer";
import type { FlatTree, FlatTreeItem, UseTreeStateOutput } from "./TreeView";
-import { flattenTree, TreeView, useTree } from "./TreeView";
+import { flattenTree, LevelLine, TreeView, useTree } from "./TreeView";
-export { flattenTree, TreeView, useTree };
+export { flattenTree, LevelLine, TreeView, useTree };
export type {
FlatTree,
FlatTreeItem,
diff --git a/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx
index 55e8f3e75d..321848846a 100644
--- a/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BoMExplorer.tsx
@@ -12,7 +12,7 @@ import { useNavigate, useParams } from "@remix-run/react";
import { useRef, useState } from "react";
import { LuChevronDown, LuChevronUp, LuSearch } from "react-icons/lu";
import type { FlatTreeItem } from "~/components/TreeView";
-import { TreeView, useTree } from "~/components/TreeView";
+import { LevelLine, TreeView, useTree } from "~/components/TreeView";
import type { Method } from "~/modules/items";
import type { MethodItemType } from "~/modules/shared";
import { MethodIcon, MethodItemTypeIcon } from "~/modules/shared";
@@ -127,7 +127,7 @@ const BoMExplorer = ({ itemType, methods, selectedId }: BoMExplorerProps) => {
>
<div className="flex h-8 items-center">
{Array.from({ length: node.level }).map((_, index) => (
- <TaskLine key={index} isSelected={state.selected} />
+ <LevelLine key={index} isSelected={state.selected} />
))}
<div
className={cn(
@@ -216,17 +216,6 @@ function NodeData({ node }: { node: FlatTreeItem<Method> }) {
);
}
-function TaskLine({ isSelected }: { isSelected: boolean }) {
- return (
- <div
- className={cn(
- "h-8 w-2 border-r border-border",
- isSelected && "border-foreground/30"
- )}
- />
- );
-}
-
function getRootLink(itemType: MethodItemType, itemId: string) {
switch (itemType) {
case "Part":
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 4da24df6d5..0eb350eae3 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -1225,6 +1225,20 @@ export async function updateQuoteFavorite(
}
}
+export async function updateQuoteOperationOrder(
+ client: SupabaseClient<Database>,
+ updates: {
+ id: string;
+ order: number;
+ updatedBy: string;
+ }[]
+) {
+ const updatePromises = updates.map(({ id, order, updatedBy }) =>
+ client.from("quoteOperation").update({ order, updatedBy }).eq("id", id)
+ );
+ return Promise.all(updatePromises);
+}
+
export async function upsertQuote(
client: SupabaseClient<Database>,
quote:
@@ -1332,7 +1346,7 @@ export async function upsertQuoteMaterial(
| (Omit<z.infer<typeof quoteMaterialValidator>, "id"> & {
quoteId: string;
quoteLineId: string;
- quoteOperationId: string;
+ quoteOperationId?: string;
companyId: string;
createdBy: string;
customFields?: Json;
@@ -1341,7 +1355,7 @@ export async function upsertQuoteMaterial(
id: string;
quoteId: string;
quoteLineId: string;
- quoteOperationId: string;
+ quoteOperationId?: string;
updatedBy: string;
customFields?: Json;
})
diff --git a/apps/carbon/app/modules/sales/types.ts b/apps/carbon/app/modules/sales/types.ts
index dd150ac42d..df5d80b3c4 100644
--- a/apps/carbon/app/modules/sales/types.ts
+++ b/apps/carbon/app/modules/sales/types.ts
@@ -10,6 +10,7 @@ import type {
getQuoteLines,
getQuoteMakeMethod,
getQuoteMaterials,
+ getQuoteMethodTrees,
getQuoteOperation,
getQuotes,
getSalesOrderExternalDocuments,
@@ -47,6 +48,10 @@ export type CustomerType = NonNullable<
Awaited<ReturnType<typeof getCustomerTypes>>["data"]
>[number];
+export type QuoteMethod = NonNullable<
+ Awaited<ReturnType<typeof getQuoteMethodTrees>>["data"]
+>[number]["data"];
+
export type QuotationMakeMethod = NonNullable<
Awaited<ReturnType<typeof getQuoteMakeMethod>>["data"]
>;
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index e3b577ddb0..95017e4f65 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -163,7 +163,7 @@ const QuoteBillOfMaterial = ({
fetcher.submit(new FormData(), {
method: "post",
- action: path.to.deleteMethodMaterial(quoteMakeMethodId, item.id),
+ action: path.to.deleteQuoteMaterial(item.id),
});
};
@@ -191,7 +191,7 @@ const QuoteBillOfMaterial = ({
formData.append("updates", JSON.stringify(updates));
fetcher.submit(formData, {
method: "post",
- action: path.to.methodMaterialsOrder(quoteMakeMethodId),
+ action: path.to.quoteMaterialsOrder(quoteMakeMethodId),
});
}, 1000);
@@ -475,8 +475,8 @@ function MaterialForm({
<ValidatedForm
action={
isTemporaryId(item.id)
- ? path.to.newMethodMaterial(item.data.quoteMakeMethodId!)
- : path.to.methodMaterial(item.data.quoteMakeMethodId, item.id!)
+ ? path.to.newQuoteMaterial(item.data.quoteMakeMethodId!)
+ : path.to.quoteMaterial(item.data.quoteMakeMethodId, item.id!)
}
method="post"
defaultValues={item.data}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index ee896a080f..9138c584bc 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -12,7 +12,7 @@ import {
useDebounce,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
-import { useFetcher } from "@remix-run/react";
+import { useFetcher, useParams } from "@remix-run/react";
import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useState } from "react";
@@ -174,7 +174,7 @@ const QuoteBillOfProcess = ({
formData.append("updates", JSON.stringify(updates));
sortOrderFetcher.submit(formData, {
method: "post",
- action: path.to.methodOperationsOrder(quoteMakeMethodId),
+ action: path.to.quoteOperationsOrder,
});
}, 1000);
@@ -367,6 +367,10 @@ function OperationForm({
setItems: Dispatch<SetStateAction<ItemWithData[]>>;
setSelectedItemId: Dispatch<SetStateAction<string | null>>;
}) {
+ const { quoteId, lineId } = useParams();
+ if (!quoteId) throw new Error("quoteId not found");
+ if (!lineId) throw new Error("lineId not found");
+
const methodOperationFetcher = useFetcher<{ id: string }>();
const { supabase } = useSupabase();
@@ -457,8 +461,8 @@ function OperationForm({
<ValidatedForm
action={
isTemporaryId(item.id)
- ? path.to.newMethodOperation(item.data.quoteMakeMethodId!)
- : path.to.methodOperation(item.data.quoteMakeMethodId, item.id!)
+ ? path.to.newQuoteOperation(quoteId, lineId)
+ : path.to.quoteOperation(quoteId, lineId, item.id!)
}
method="post"
defaultValues={item.data}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
index 4b8f96a58a..d854c09779 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
@@ -1,17 +1,22 @@
import { Badge, HStack, VStack, cn } from "@carbon/react";
+import { useNavigate } from "@remix-run/react";
import { useRef } from "react";
import { LuChevronDown, LuChevronUp } from "react-icons/lu";
-import type { FlatTreeItem } from "~/components/TreeView";
-import { TreeView, useTree } from "~/components/TreeView";
-import type { Method } from "~/modules/items/types";
+import type { FlatTree, FlatTreeItem } from "~/components/TreeView";
+import { LevelLine, TreeView, useTree } from "~/components/TreeView";
+import { useOptimisticLocation } from "~/hooks";
import { MethodIcon, MethodItemTypeIcon } from "~/modules/shared";
+import { path } from "~/utils/path";
+import type { QuoteMethod } from "../../types";
type QuoteBoMExplorerProps = {
- methods: FlatTreeItem<Method>[];
+ methods: FlatTree<QuoteMethod>;
};
const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
const parentRef = useRef<HTMLDivElement>(null);
+ const navigate = useNavigate();
+ const location = useOptimisticLocation();
const {
nodes,
@@ -22,7 +27,6 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
expandAllBelowDepth,
// toggleExpandLevel,
collapseAllBelowDepth,
- selectNode,
scrollToNode,
virtualizer,
} = useTree({
@@ -50,18 +54,20 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
key={node.id}
className={cn(
"flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2",
- state.selected
+ getNodePath(node) === location.pathname
? "bg-muted hover:bg-muted/90"
: "bg-transparent hover:bg-muted/90"
)}
onClick={() => {
- selectNode(node.id);
- alert("navigating to " + node.id);
+ navigate(getNodePath(node));
}}
>
<div className="flex h-8 items-center">
{Array.from({ length: node.level }).map((_, index) => (
- <TaskLine key={index} isSelected={state.selected} />
+ <LevelLine
+ key={index}
+ isSelected={getNodePath(node) === location.pathname}
+ />
))}
<div
className={cn(
@@ -129,7 +135,7 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
export default QuoteBoMExplorer;
-function NodeText({ node }: { node: FlatTreeItem<Method> }) {
+function NodeText({ node }: { node: FlatTreeItem<QuoteMethod> }) {
return (
<div className="flex items-center gap-1">
<span className="text-sm font-mono">{node.data.itemReadableId}</span>
@@ -137,7 +143,7 @@ function NodeText({ node }: { node: FlatTreeItem<Method> }) {
);
}
-function NodeData({ node }: { node: FlatTreeItem<Method> }) {
+function NodeData({ node }: { node: FlatTreeItem<QuoteMethod> }) {
return (
<HStack spacing={1}>
<Badge className="text-xs" variant="outline">
@@ -150,13 +156,14 @@ function NodeData({ node }: { node: FlatTreeItem<Method> }) {
);
}
-function TaskLine({ isSelected }: { isSelected: boolean }) {
- return (
- <div
- className={cn(
- "h-8 w-2 border-r border-border",
- isSelected && "border-foreground/30"
- )}
- />
- );
+function getNodePath(node: FlatTreeItem<QuoteMethod>) {
+ return node.data.isRoot
+ ? path.to.quoteLineMethod(node.data.quoteId, node.data.quoteLineId)
+ : path.to.quoteLineMaterial(
+ node.data.quoteId,
+ node.data.quoteLineId,
+ node.data.quoteMaterialMakeMethodId ??
+ node.data.methodType.toLowerCase(),
+ node.data.methodMaterialId
+ );
}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsx
index faffa3c8ec..b1bbe04447 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsx
@@ -1,13 +1,27 @@
import { VStack } from "@carbon/react";
import { useParams } from "@remix-run/react";
+import type { Tree } from "~/components/TreeView/TreeView";
+import { useRouteData } from "~/hooks";
+import type { QuoteMethod } from "~/modules/sales";
import { QuoteBillOfMaterial, QuoteBillOfProcess } from "~/modules/sales";
+import { path } from "~/utils/path";
export default function QuoteMakeMethodRoute() {
const { quoteId, lineId } = useParams();
if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
- const quoteMakeMethodId = "";
+ const quoteData = useRouteData<{ methods: Tree<QuoteMethod>[] }>(
+ path.to.quote(quoteId)
+ );
+
+ const methodTree = quoteData?.methods?.find(
+ (m) => m.data.quoteLineId === lineId
+ );
+
+ const quoteMakeMethodId = methodTree?.data.quoteMaterialMakeMethodId;
+ if (!quoteMakeMethodId) throw new Error("Could not find quoteMakeMethodId");
return (
<VStack spacing={2} className="p-2">
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
index 5ea1f28428..033c622088 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
@@ -13,17 +13,19 @@ import {
ResizablePanelGroup,
ScrollArea,
useDisclosure,
+ useMount,
VStack,
} from "@carbon/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useState } from "react";
-import { LuGhost, LuImage, LuPlus } from "react-icons/lu";
+import { LuChevronsUpDown, LuGhost, LuImage, LuPlus } from "react-icons/lu";
import { MdMoreVert } from "react-icons/md";
-import type { FlatTree } from "~/components/TreeView";
+import { flattenTree } from "~/components/TreeView";
+import type { Tree } from "~/components/TreeView/TreeView";
import { useRouteData, useUser } from "~/hooks";
-import type { QuotationLine } from "~/modules/sales";
+import type { QuotationLine, QuoteMethod } from "~/modules/sales";
import {
DeleteQuoteLine,
getQuote,
@@ -172,7 +174,11 @@ function QuoteExplorer() {
)}
</VStack>
<div className="w-full flex flex-0 sm:flex-row border-t border-border p-4 sm:justify-start sm:space-x-2">
- <Button leftIcon={<LuPlus />} onClick={newQuoteLineDisclosure.onOpen}>
+ <Button
+ className="w-full"
+ leftIcon={<LuPlus />}
+ onClick={newQuoteLineDisclosure.onOpen}
+ >
Add Line Item
</Button>
</div>
@@ -203,101 +209,6 @@ function EmptyQuote({ onAdd }: { onAdd: () => void }) {
);
}
-const methods: FlatTree<{
- itemId: string;
- makeMethodId: string | null;
- methodType: string;
- materialMakeMethodId: string | null;
- itemType: string;
- quantity: number;
- itemReadableId: string;
- order: number;
- methodMaterialId: string;
- parentMaterialId: string | null;
- isRoot: boolean;
-}> = [
- {
- id: "node-d9210a4deb583",
- children: ["node-b1633fd85ebf", "node-889f33c1ba64b"],
- hasChildren: true,
- level: 0,
- parentId: undefined,
- data: {
- itemId: "cqc7ms9r80lmbqsrdnbg",
- makeMethodId: null,
- methodType: "Make",
- materialMakeMethodId: "cqc7ms9r80lmbqkrdnc0",
- itemType: "Part",
- quantity: 1,
- itemReadableId: "P2392303",
- order: 1,
- methodMaterialId: "cqc7ms9r80lmbqkrdnc0",
- parentMaterialId: null,
- isRoot: true,
- },
- },
- {
- id: "node-b1633fd85ebf",
- children: [],
- hasChildren: false,
- level: 1,
- data: {
- itemId: "cqc7nq1r80lmchkrdnf0",
- makeMethodId: "cqc7ms9r80lmbqkrdnc0",
- methodType: "Pick",
- materialMakeMethodId: null,
- itemType: "Tool",
- quantity: 1,
- itemReadableId: "T932023",
- order: 1,
- methodMaterialId: "cqc7nrpr80lmbusrdnfg",
- parentMaterialId: "cqc7ms9r80lmbqkrdnc0",
- isRoot: false,
- },
- parentId: "node-d9210a4deb583",
- },
- {
- id: "node-889f33c1ba64b",
- children: ["node-324eaa176575a"],
- hasChildren: true,
- level: 1,
- data: {
- itemId: "cqc7n1pr80lmbv4rdncg",
- makeMethodId: "cqc7ms9r80lmbqkrdnc0",
- methodType: "Make",
- materialMakeMethodId: "cqc7n1pr80lmbqkrdnd0",
- itemType: "Part",
- quantity: 2,
- itemReadableId: "P2392304",
- order: 1,
- methodMaterialId: "cqc7n3pr80lmbukrdndg",
- parentMaterialId: "cqc7ms9r80lmbqkrdnc0",
- isRoot: false,
- },
- parentId: "node-d9210a4deb583",
- },
- {
- id: "node-324eaa176575a",
- children: [],
- hasChildren: false,
- level: 2,
- data: {
- itemId: "cqc7njpr80lmbv4rdne0",
- makeMethodId: "cqc7n1pr80lmbqkrdnd0",
- methodType: "Buy",
- materialMakeMethodId: null,
- itemType: "Material",
- quantity: 3.8,
- itemReadableId: "RAW3290393",
- order: 1,
- methodMaterialId: "cqc7nlhr80lmbv4rdneg",
- parentMaterialId: "cqc7n3pr80lmbukrdndg",
- isRoot: false,
- },
- parentId: "node-889f33c1ba64b",
- },
-];
-
type QuoteLineItemProps = {
line: QuotationLine;
onDelete: (line: QuotationLine) => void;
@@ -305,15 +216,30 @@ type QuoteLineItemProps = {
function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
const { quoteId, lineId } = useParams();
+ if (!quoteId) throw new Error("Could not find quoteId");
+
const navigate = useNavigate();
const disclosure = useDisclosure();
- if (!quoteId) throw new Error("Could not find quoteId");
+ useMount(() => {
+ if (lineId === line.id) {
+ disclosure.onOpen();
+ }
+ });
+
+ const quoteData = useRouteData<{ methods: Tree<QuoteMethod>[] }>(
+ path.to.quote(quoteId)
+ );
+
+ const methodTree = quoteData?.methods?.find(
+ (m) => m.data.quoteLineId === line.id
+ );
+ const methods = methodTree ? flattenTree(methodTree) : [];
const isSelected = lineId === line.id;
const onLineClick = (line: QuotationLine) => {
if (line.methodType === "Make") {
- disclosure.onToggle();
+ disclosure.onOpen();
}
if (!isSelected) {
@@ -365,27 +291,39 @@ function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
</span>
</VStack>
</HStack>
-
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <HStack spacing={0}>
+ {line.methodType === "Make" && (
<IconButton
- aria-label="More"
- icon={<MdMoreVert />}
+ aria-label={disclosure.isOpen ? "Hide" : "Show"}
+ icon={<LuChevronsUpDown />}
variant="ghost"
- onClick={(e) => e.stopPropagation()}
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
onClick={(e) => {
e.stopPropagation();
- onDelete(line);
+ disclosure.onToggle();
}}
- >
- Delete Line
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ />
+ )}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="More"
+ icon={<MdMoreVert />}
+ variant="ghost"
+ onClick={(e) => e.stopPropagation()}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ onDelete(line);
+ }}
+ >
+ Delete Line
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </HStack>
</HStack>
{disclosure.isOpen && (
<VStack className="border-b border-border">
diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.$id.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.$id.tsx
new file mode 100644
index 0000000000..0ab7c8df5a
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.$id.tsx
@@ -0,0 +1,66 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { methodMaterialValidator, upsertMethodMaterial } from "~/modules/items";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ create: "parts",
+ });
+
+ const { makeMethodId, id } = params;
+ if (!makeMethodId) {
+ throw new Error("makeMethodId not found");
+ }
+ if (!id) {
+ throw new Error("id not found");
+ }
+
+ const formData = await request.formData();
+ const validation = await validator(methodMaterialValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const updateMethodMaterial = await upsertMethodMaterial(client, {
+ ...validation.data,
+ id: id,
+ companyId,
+ updatedBy: userId,
+ customFields: setCustomFields(formData),
+ });
+ if (updateMethodMaterial.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(updateMethodMaterial.error, "Failed to update method material")
+ )
+ );
+ }
+
+ const methodMaterialId = updateMethodMaterial.data?.id;
+ if (!methodMaterialId) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(updateMethodMaterial, "Failed to update method material")
+ )
+ );
+ }
+
+ return json({ id: methodMaterialId });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.delete.$id.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.delete.$id.tsx
new file mode 100644
index 0000000000..bfe8afe575
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.delete.$id.tsx
@@ -0,0 +1,36 @@
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { deleteMethodMaterial } from "~/modules/items";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client } = await requirePermissions(request, {
+ delete: "parts",
+ });
+
+ const { makeMethodId, id } = params;
+ if (!makeMethodId) {
+ throw new Error("makeMethodId not found");
+ }
+ if (!id) {
+ throw new Error("id not found");
+ }
+
+ const deleteMaterial = await deleteMethodMaterial(client, id);
+ if (deleteMaterial.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(deleteMaterial.error, "Failed to delete method material")
+ )
+ );
+ }
+
+ return json({});
+}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.new.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.new.tsx
new file mode 100644
index 0000000000..10cd21afad
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.material.new.tsx
@@ -0,0 +1,67 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { quoteMaterialValidator, upsertQuoteMaterial } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ create: "parts",
+ });
+
+ const { quoteId, lineId } = params;
+ if (!quoteId) {
+ throw new Error("quoteId not found");
+ }
+ if (!lineId) {
+ throw new Error("lineId not found");
+ }
+
+ const formData = await request.formData();
+ const validation = await validator(quoteMaterialValidator).validate(formData);
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+
+ const insertQuoteMaterial = await upsertQuoteMaterial(client, {
+ ...data,
+ quoteId,
+ quoteLineId: lineId,
+ companyId,
+ createdBy: userId,
+ customFields: setCustomFields(formData),
+ });
+ if (insertQuoteMaterial.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(insertQuoteMaterial.error, "Failed to insert method material")
+ )
+ );
+ }
+
+ const methodMaterialId = insertQuoteMaterial.data?.id;
+ if (!methodMaterialId) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(insertQuoteMaterial, "Failed to insert method material")
+ )
+ );
+ }
+
+ return json({ id: methodMaterialId });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsx
new file mode 100644
index 0000000000..ff49ed5cf3
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsx
@@ -0,0 +1,69 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import {
+ methodOperationValidator,
+ upsertMethodOperation,
+} from "~/modules/items";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ create: "parts",
+ });
+
+ const { makeMethodId, id } = params;
+ if (!makeMethodId) {
+ throw new Error("makeMethodId not found");
+ }
+ if (!id) {
+ throw new Error("id not found");
+ }
+
+ const formData = await request.formData();
+ const validation = await validator(methodOperationValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const updateMethodOperation = await upsertMethodOperation(client, {
+ ...validation.data,
+ id: id,
+ companyId,
+ updatedBy: userId,
+ customFields: setCustomFields(formData),
+ });
+ if (updateMethodOperation.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(updateMethodOperation.error, "Failed to update method operation")
+ )
+ );
+ }
+
+ const methodOperationId = updateMethodOperation.data?.id;
+ if (!methodOperationId) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(updateMethodOperation, "Failed to update method operation")
+ )
+ );
+ }
+
+ return json({ id: methodOperationId });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsx
new file mode 100644
index 0000000000..0e1ce24dc6
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsx
@@ -0,0 +1,69 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { quoteOperationValidator, upsertQuoteOperation } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ create: "parts",
+ });
+
+ const { quoteId, lineId } = params;
+ if (!quoteId) {
+ throw new Error("quoteId not found");
+ }
+ if (!lineId) {
+ throw new Error("lineId not found");
+ }
+
+ const formData = await request.formData();
+ const validation = await validator(quoteOperationValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+
+ const insertQuoteOperation = await upsertQuoteOperation(client, {
+ ...data,
+ quoteId,
+ quoteLineId: lineId,
+ companyId,
+ createdBy: userId,
+ customFields: setCustomFields(formData),
+ });
+ if (insertQuoteOperation.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(insertQuoteOperation.error, "Failed to insert method operation")
+ )
+ );
+ }
+
+ const methodOperationId = insertQuoteOperation.data?.id;
+ if (!methodOperationId) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(insertQuoteOperation, "Failed to insert method operation")
+ )
+ );
+ }
+
+ return json({ id: methodOperationId });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.material.order.tsx b/apps/carbon/app/routes/x+/quote+/methods.material.order.tsx
new file mode 100644
index 0000000000..1e54220170
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.material.order.tsx
@@ -0,0 +1,42 @@
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+
+import { updateMaterialOrder } from "~/modules/items";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "parts",
+ });
+
+ const updateMap = (await request.formData()).get("updates") as string;
+ if (!updateMap) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive a new sort order"))
+ );
+ }
+
+ const updates = Object.entries(JSON.parse(updateMap)).map(
+ ([id, orderString]) => ({
+ id,
+ order: Number(orderString),
+ updatedBy: userId,
+ })
+ );
+
+ const updateSortOrders = await updateMaterialOrder(client, updates);
+ if (updateSortOrders.some((update) => update.error))
+ return json(
+ {},
+ await flash(
+ request,
+ error(updateSortOrders, "Failed to update sort order")
+ )
+ );
+
+ return null;
+}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.operation.order.tsx b/apps/carbon/app/routes/x+/quote+/methods.operation.order.tsx
new file mode 100644
index 0000000000..e055119cc3
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.operation.order.tsx
@@ -0,0 +1,42 @@
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+
+import { updateQuoteOperationOrder } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "parts",
+ });
+
+ const updateMap = (await request.formData()).get("updates") as string;
+ if (!updateMap) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive a new sort order"))
+ );
+ }
+
+ const updates = Object.entries(JSON.parse(updateMap)).map(
+ ([id, orderString]) => ({
+ id,
+ order: Number(orderString),
+ updatedBy: userId,
+ })
+ );
+
+ const updateSortOrders = await updateQuoteOperationOrder(client, updates);
+ if (updateSortOrders.some((update) => update.error))
+ return json(
+ {},
+ await flash(
+ request,
+ error(updateSortOrders, "Failed to update sort order")
+ )
+ );
+
+ return null;
+}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 8d119d5f3a..a3a7303fc1 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -452,12 +452,8 @@ export const path = {
newQuoteLine: (id: string) => generatePath(`${x}/quote/${id}/new`),
newQuoteLineQuantity: (id: string, lineId: string) =>
generatePath(`${x}/quote/${id}/lines/${lineId}/new`),
- newQuoteOperation: (quoteId: string, lineId: string, parentId?: string) =>
- generatePath(
- `${x}/quote/${quoteId}/lines/${lineId}/operation/new${
- parentId ? `?quoteAssemblyId=${parentId}` : ""
- }`
- ),
+ newQuoteOperation: (quoteId: string, lineId: string) =>
+ generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/new`),
newQuoteMaterial: (quoteId: string, lineId: string, operationId: string) =>
generatePath(
`${x}/quote/${quoteId}/lines/${lineId}/operation/${operationId}/material/new`
@@ -583,10 +579,21 @@ export const path = {
generatePath(
`${x}/quote/${quoteId}/lines/${lineId}/operation/${operationId}/material/${materialId}`
),
- quoteOperation: (quoteId: string, lineId: string, operationId: string) =>
+ quoteLineMaterial: (
+ quoteId: string,
+ lineId: string,
+ makeMethodId: string,
+ methodMaterialId: string
+ ) =>
generatePath(
- `${x}/quote/${quoteId}/lines/${lineId}/operation/${operationId}`
+ `${x}/quote/${quoteId}/${lineId}/${makeMethodId}/${methodMaterialId}`
),
+ quoteLineMethod: (quoteId: string, quoteLineId: string) =>
+ generatePath(`${x}/quote/${quoteId}/${quoteLineId}/method`),
+ quoteOperation: (quoteId: string, lineId: string, id: string) =>
+ generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/${id}`),
+ quoteOperationsOrder: `${x}/quote/methods/operation/order`,
+
quoteRelease: (id: string) => generatePath(`${x}/quote/${id}/release`),
quotes: `${x}/sales/quotes`,
receipt: (id: string) => generatePath(`${x}/receipt/${id}`),