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: routes for quote materials

Brad Barbincddee7e3ddf1
diff --git a/apps/carbon/app/components/Assignee.tsx b/apps/carbon/app/components/Assignee.tsx
index 682eb3d70b..fe47d579c1 100644
--- a/apps/carbon/app/components/Assignee.tsx
+++ b/apps/carbon/app/components/Assignee.tsx
@@ -84,7 +84,7 @@ const Assign = forwardRef<HTMLButtonElement, ComboboxProps>(
<PopoverTrigger asChild>
<button
className={cn(
- "rounded-md px-2.5 py-0.5 text-sm hover:bg-muted/50 transition-colors cursor-pointer border border-border",
+ "rounded-md px-2.5 py-0.5 text-sm transition-colors cursor-pointer bg-background hover:bg-accent hover:text-accent-foreground border border-input",
className
)}
role="combobox"
diff --git a/apps/carbon/app/components/EmployeeAvatar.tsx b/apps/carbon/app/components/EmployeeAvatar.tsx
index a9afd7b3fd..39c711976c 100644
--- a/apps/carbon/app/components/EmployeeAvatar.tsx
+++ b/apps/carbon/app/components/EmployeeAvatar.tsx
@@ -36,7 +36,7 @@ const EmployeeAvatar = ({
<HStack className="truncate">
<Avatar
size={size ?? "xs"}
- src={person.avatarUrl ?? undefined}
+ path={person.avatarUrl ?? undefined}
name={person?.name ?? ""}
/>
<span className={className}>{person.name}</span>
diff --git a/apps/carbon/app/components/TreeView/TreeView.tsx b/apps/carbon/app/components/TreeView/TreeView.tsx
index a2fb37056b..7b99c4d0a5 100644
--- a/apps/carbon/app/components/TreeView/TreeView.tsx
+++ b/apps/carbon/app/components/TreeView/TreeView.tsx
@@ -631,7 +631,7 @@ export function LevelLine({
className={cn(
"h-8 w-2 border-r border-border",
isError && "border-destructive",
- isSelected && "border-foreground"
+ isSelected && "border-foreground/60"
)}
/>
);
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index f81e6bce52..b13ef5d19a 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -638,6 +638,17 @@ export async function getQuoteMaterials(
return client.from("quoteMaterial").select("*").eq("quoteId", quoteId);
}
+export async function getQuoteMaterial(
+ client: SupabaseClient<Database>,
+ materialId: string
+) {
+ return client
+ .from("quoteMaterialWithMakeMethodId")
+ .select("*")
+ .eq("id", materialId)
+ .single();
+}
+
export async function getQuoteMaterialsByLine(
client: SupabaseClient<Database>,
quoteLineId: string
@@ -1401,13 +1412,13 @@ export async function upsertQuoteMaterial(
.from("quoteMaterial")
.update(sanitize(quoteMaterial))
.eq("id", quoteMaterial.id)
- .select("id")
+ .select("id, methodType")
.single();
}
return client
.from("quoteMaterial")
.insert([quoteMaterial])
- .select("id")
+ .select("id, methodType")
.single();
}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index f60ffef768..fa17b766e0 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -555,7 +555,7 @@ function MaterialForm({
value={itemData.methodType}
replenishmentSystem="Buy and Make"
/>
- <Number name="quantity" label="Quantity" />
+ <Number name="quantity" label="Quantity per Parent" />
<UnitOfMeasure
name="unitOfMeasureCode"
value={itemData.unitOfMeasureCode}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
index 5894cd166c..d78016f20b 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
@@ -101,12 +101,7 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
</div>
<div className="flex w-full items-center justify-between gap-2">
- <div
- className={cn(
- "flex items-center gap-2 overflow-x-hidden",
- node.level > 1 && "opacity-50"
- )}
- >
+ <div className="flex items-center gap-2 overflow-x-hidden">
<MethodIcon
type={
// node.data.isRoot ? "Method" :
@@ -157,12 +152,19 @@ function NodeData({ node }: { node: FlatTreeItem<QuoteMethod> }) {
}
function getNodePath(node: FlatTreeItem<QuoteMethod>) {
- return node.data.methodType === "Make"
+ return node.data.isRoot
? path.to.quoteLineMethod(
node.data.quoteId,
node.data.quoteLineId,
node.data.quoteMaterialMakeMethodId
)
+ : node.data.methodType === "Make"
+ ? path.to.quoteLineMaterialMake(
+ node.data.quoteId,
+ node.data.quoteLineId,
+ node.data.quoteMaterialMakeMethodId,
+ node.data.methodMaterialId
+ )
: path.to.quoteLineMaterial(
node.data.quoteId,
node.data.quoteLineId,
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
new file mode 100644
index 0000000000..e38b8813ad
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
@@ -0,0 +1,222 @@
+import {
+ Card,
+ CardContent,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ toast,
+ VStack,
+} from "@carbon/react";
+import { useFetcher, useNavigate, useParams } from "@remix-run/react";
+
+import { ValidatedForm } from "@carbon/remix-validated-form";
+import { useEffect, useState } from "react";
+import type { z } from "zod";
+import {
+ DefaultMethodType,
+ Hidden,
+ InputControlled,
+ Item,
+ Number,
+ Select,
+ Submit,
+ UnitOfMeasure,
+} from "~/components/Form";
+import { useOptimisticLocation, usePermissions } from "~/hooks";
+import { useSupabase } from "~/lib/supabase";
+import type { quoteOperationValidator } from "~/modules/sales";
+import { quoteMaterialValidator } from "~/modules/sales";
+import type { MethodItemType, MethodType } from "~/modules/shared";
+import { methodItemType } from "~/modules/shared";
+import { path } from "~/utils/path";
+
+type QuoteMaterialFormProps = {
+ initialValues: z.infer<typeof quoteMaterialValidator> & {
+ quoteMaterialMakeMethodId: string | null;
+ };
+ operations: z.infer<typeof quoteOperationValidator>[];
+};
+
+const QuoteMaterialForm = ({
+ initialValues,
+ operations,
+}: QuoteMaterialFormProps) => {
+ const fetcher = useFetcher<{ id: string; methodType: MethodType }>();
+ const { supabase } = useSupabase();
+ const permissions = usePermissions();
+ const navigate = useNavigate();
+ const location = useOptimisticLocation();
+
+ const { quoteId, lineId, materialId } = useParams();
+ if (!quoteId) throw new Error("quoteId not found");
+ if (!lineId) throw new Error("lineId not found");
+ if (!materialId) throw new Error("materialId not found");
+
+ const [itemType, setItemType] = useState<MethodItemType>(
+ initialValues.itemType
+ );
+ const [itemData, setItemData] = useState<{
+ itemId: string;
+ itemReadableId: string;
+ methodType: MethodType;
+ description: string;
+ unitOfMeasureCode: string;
+ quantity: number;
+ }>({
+ itemId: initialValues.itemId ?? "",
+ itemReadableId: initialValues.itemReadableId ?? "",
+ methodType: initialValues.methodType ?? "Buy",
+ description: initialValues.description ?? "",
+ unitOfMeasureCode: initialValues.unitOfMeasureCode ?? "EA",
+ quantity: initialValues.quantity ?? 1,
+ });
+
+ const onTypeChange = (value: MethodItemType) => {
+ setItemType(value);
+ setItemData({
+ itemId: "",
+ itemReadableId: "",
+ methodType: "" as "Buy",
+ quantity: 1,
+ description: "",
+ unitOfMeasureCode: "EA",
+ });
+ };
+
+ const onItemChange = async (itemId: string) => {
+ if (!supabase) return;
+
+ const item = await supabase
+ .from("item")
+ .select("name, readableId, unitOfMeasureCode, defaultMethodType")
+ .eq("id", itemId)
+ .single();
+
+ if (item.error) {
+ toast.error("Failed to load item details");
+ return;
+ }
+
+ setItemData((d) => ({
+ ...d,
+ itemId,
+ itemReadableId: initialValues?.itemReadableId ?? "",
+ description: initialValues?.description ?? "",
+ unitOfMeasureCode: initialValues?.unitOfMeasureCode ?? "EA",
+ methodType: initialValues?.methodType ?? "Buy",
+ }));
+ };
+
+ useEffect(() => {
+ const newPath =
+ initialValues.methodType === "Make"
+ ? path.to.quoteLineMaterialMake(
+ quoteId,
+ lineId,
+ initialValues.quoteMaterialMakeMethodId!,
+ initialValues.id!
+ )
+ : path.to.quoteLineMaterial(
+ quoteId,
+ lineId,
+ initialValues.methodType.toLowerCase(),
+ initialValues.id!
+ );
+ if (location.pathname !== newPath) {
+ navigate(newPath);
+ }
+ }, [
+ initialValues.id,
+ initialValues.methodType,
+ initialValues.quoteMaterialMakeMethodId,
+ lineId,
+ location.pathname,
+ navigate,
+ quoteId,
+ ]);
+
+ return (
+ <Card>
+ <ValidatedForm
+ method="post"
+ action={path.to.quoteMaterial(quoteId, lineId, initialValues?.id!)}
+ defaultValues={initialValues}
+ fetcher={fetcher}
+ validator={quoteMaterialValidator}
+ >
+ <CardHeader>
+ <CardTitle>{itemData.itemReadableId}</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <Hidden name="quoteMakeMethodId" />
+ <Hidden name="itemReadableId" value={itemData.itemReadableId} />
+ <Hidden name="order" />
+ <VStack className="pt-4">
+ <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
+ <Select
+ name="itemType"
+ label="Type"
+ options={methodItemType.map((value) => ({
+ value,
+ label: value,
+ }))}
+ onChange={(value) => {
+ onTypeChange(value?.value as MethodItemType);
+ }}
+ />
+ <Item
+ name="itemId"
+ label={itemType}
+ type={itemType}
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ />
+ <Select
+ name="quoteOperationId"
+ label="Operation"
+ isClearable
+ options={operations.map((o) => ({
+ value: o.id!,
+ label: o.description,
+ }))}
+ />
+ </div>
+ <InputControlled
+ name="description"
+ label="Description"
+ value={itemData.description}
+ onChange={(newValue) => {
+ setItemData((d) => ({ ...d, description: newValue }));
+ }}
+ />
+ <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
+ <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) =>
+ setItemData((d) => ({
+ ...d,
+ unitOfMeasureCode: newValue?.value ?? "EA",
+ }))
+ }
+ />
+ </div>
+ </VStack>
+ </CardContent>
+ <CardFooter>
+ <Submit isDisabled={!permissions.can("update", "sales")}>Save</Submit>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
+ );
+};
+
+export default QuoteMaterialForm;
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/index.ts b/apps/carbon/app/modules/sales/ui/Quotes/index.ts
index c81a7605c4..4d22630b63 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/index.ts
+++ b/apps/carbon/app/modules/sales/ui/Quotes/index.ts
@@ -8,6 +8,7 @@ import QuoteForm from "./QuoteForm";
import QuoteHeader from "./QuoteHeader";
import QuoteLineDocuments from "./QuoteLineDocuments";
import QuoteLineForm from "./QuoteLineForm";
+import QuoteMaterialForm from "./QuoteMaterialForm";
import QuotesTable from "./QuotesTable";
export {
@@ -21,5 +22,6 @@ export {
QuoteHeader,
QuoteLineDocuments,
QuoteLineForm,
+ QuoteMaterialForm,
QuotesTable,
};
diff --git a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.buy.$materialId.tsx b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.buy.$materialId.tsx
index 50cdb6edd3..05e453b543 100644
--- a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.buy.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.buy.$materialId.tsx
@@ -44,7 +44,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
}
-export default function MethodMaterialPickPage() {
+export default function MethodMaterialBuyPage() {
const { item } = useLoaderData<typeof loader>();
const { itemId, materialId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.buy.$materialId.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.buy.$materialId.tsx
index 458289c534..c05cc8a34b 100644
--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.buy.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.buy.$materialId.tsx
@@ -44,7 +44,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
}
-export default function MethodMaterialPickPage() {
+export default function MethodMaterialBuyPage() {
const { item } = useLoaderData<typeof loader>();
const { itemId, materialId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx
new file mode 100644
index 0000000000..57f17bfa35
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx
@@ -0,0 +1,66 @@
+import { VStack } from "@carbon/react";
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+
+import { getQuoteMaterial, QuoteMaterialForm } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "parts",
+ });
+
+ const { quoteId, lineId, materialId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ const [material] = await Promise.all([getQuoteMaterial(client, materialId)]);
+
+ if (material.error) {
+ throw redirect(
+ path.to.quoteLine(quoteId, lineId),
+ await flash(
+ request,
+ error(material.error, "Failed to load quote material")
+ )
+ );
+ }
+
+ return json({
+ material: {
+ ...material.data,
+ id: material.data.id ?? "",
+ description: material.data.description ?? "",
+ itemId: material.data.itemId ?? "",
+ itemReadableId: material.data.itemReadableId ?? "",
+ itemType: material.data.itemType as "Part",
+ methodType: material.data.methodType ?? "Make",
+ order: material.data.order ?? 1,
+ quantity: material.data.quantity ?? 0,
+ quoteMakeMethodId: material.data.quoteMakeMethodId ?? "",
+ quoteMaterialMakeMethodId: material.data.quoteMaterialMakeMethodId,
+ quoteOperationId: material.data.quoteOperationId ?? undefined,
+ unitOfMeasureCode: material.data.unitOfMeasureCode ?? "",
+ },
+ });
+}
+
+export default function QuoteMaterialBuyPage() {
+ const { material } = useLoaderData<typeof loader>();
+
+ const { materialId } = useParams();
+ if (!materialId) throw new Error("Could not find materialId");
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <QuoteMaterialForm
+ key={materialId}
+ initialValues={material}
+ operations={[]}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
new file mode 100644
index 0000000000..acdcf8a4bc
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
@@ -0,0 +1,124 @@
+import { VStack } from "@carbon/react";
+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import {
+ getQuoteMaterial,
+ getQuoteMaterialsByMethodId,
+ getQuoteOperationsByMethodId,
+ QuoteBillOfMaterial,
+ QuoteBillOfProcess,
+ QuoteMaterialForm,
+} from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "sales",
+ });
+
+ const { quoteId, lineId, methodId, materialId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+ if (!methodId) throw new Error("Could not find methodId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ const [material, materials, operations] = await Promise.all([
+ getQuoteMaterial(client, materialId),
+ getQuoteMaterialsByMethodId(client, methodId),
+ getQuoteOperationsByMethodId(client, methodId),
+ ]);
+
+ if (material.error) {
+ throw redirect(
+ path.to.quoteLine(quoteId, lineId),
+ await flash(
+ request,
+ error(material.error, "Failed to load quote material")
+ )
+ );
+ }
+
+ if (materials.error) {
+ throw redirect(
+ path.to.quoteLine(quoteId, lineId),
+ await flash(
+ request,
+ error(materials.error, "Failed to load quote materials")
+ )
+ );
+ }
+
+ if (operations.error) {
+ throw redirect(
+ path.to.quoteLine(quoteId, lineId),
+ await flash(
+ request,
+ error(operations.error, "Failed to load quote operations")
+ )
+ );
+ }
+
+ return json({
+ material: {
+ ...material.data,
+ id: material.data.id ?? "",
+ description: material.data.description ?? "",
+ itemId: material.data.itemId ?? "",
+ itemReadableId: material.data.itemReadableId ?? "",
+ itemType: material.data.itemType as "Part",
+ methodType: material.data.methodType ?? "Make",
+ order: material.data.order ?? 1,
+ quantity: material.data.quantity ?? 0,
+ quoteMakeMethodId: material.data.quoteMakeMethodId ?? "",
+ quoteMaterialMakeMethodId: material.data.quoteMaterialMakeMethodId,
+ quoteOperationId: material.data.quoteOperationId ?? undefined,
+ unitOfMeasureCode: material.data.unitOfMeasureCode ?? "",
+ },
+ materials:
+ materials?.data.map((m) => ({
+ ...m,
+ itemType: m.itemType as "Part",
+ unitOfMeasureCode: m.unitOfMeasureCode ?? "",
+ quoteOperationId: m.quoteOperationId ?? undefined,
+ })) ?? [],
+ operations:
+ operations.data?.map((o) => ({
+ ...o,
+ description: o.description ?? "",
+ equipmentTypeId: o.equipmentTypeId ?? undefined,
+ quoteMakeMethodId: o.quoteMakeMethodId ?? methodId,
+ })) ?? [],
+ });
+}
+
+export default function QuoteMakeMethodRoute() {
+ const { methodId } = useParams();
+ if (!methodId) throw new Error("Could not find methodId");
+
+ const { material, materials, operations } = useLoaderData<typeof loader>();
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <QuoteMaterialForm
+ key={material.id}
+ initialValues={material}
+ operations={[]}
+ />
+ <QuoteBillOfProcess
+ key={`bop:${methodId}`}
+ quoteMakeMethodId={methodId}
+ operations={operations}
+ />
+ <QuoteBillOfMaterial
+ key={`bom:${methodId}`}
+ quoteMakeMethodId={methodId}
+ materials={materials}
+ operations={operations}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx
new file mode 100644
index 0000000000..949aa6ec4a
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx
@@ -0,0 +1,66 @@
+import { VStack } from "@carbon/react";
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+
+import { getQuoteMaterial, QuoteMaterialForm } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "parts",
+ });
+
+ const { quoteId, lineId, materialId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+ if (!materialId) throw new Error("Could not find materialId");
+
+ const [material] = await Promise.all([getQuoteMaterial(client, materialId)]);
+
+ if (material.error) {
+ throw redirect(
+ path.to.quoteLine(quoteId, lineId),
+ await flash(
+ request,
+ error(material.error, "Failed to load quote material")
+ )
+ );
+ }
+
+ return json({
+ material: {
+ ...material.data,
+ id: material.data.id ?? "",
+ description: material.data.description ?? "",
+ itemId: material.data.itemId ?? "",
+ itemReadableId: material.data.itemReadableId ?? "",
+ itemType: material.data.itemType as "Part",
+ methodType: material.data.methodType ?? "Make",
+ order: material.data.order ?? 1,
+ quantity: material.data.quantity ?? 0,
+ quoteMakeMethodId: material.data.quoteMakeMethodId ?? "",
+ quoteMaterialMakeMethodId: material.data.quoteMaterialMakeMethodId,
+ quoteOperationId: material.data.quoteOperationId ?? undefined,
+ unitOfMeasureCode: material.data.unitOfMeasureCode ?? "",
+ },
+ });
+}
+
+export default function QuoteMaterialPickPage() {
+ const { material } = useLoaderData<typeof loader>();
+
+ const { materialId } = useParams();
+ if (!materialId) throw new Error("Could not find materialId");
+
+ return (
+ <VStack spacing={2} className="p-2">
+ <QuoteMaterialForm
+ key={materialId}
+ initialValues={material}
+ operations={[]}
+ />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
index 033c622088..b3f8b8567e 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
@@ -24,7 +24,7 @@ import { LuChevronsUpDown, LuGhost, LuImage, LuPlus } from "react-icons/lu";
import { MdMoreVert } from "react-icons/md";
import { flattenTree } from "~/components/TreeView";
import type { Tree } from "~/components/TreeView/TreeView";
-import { useRouteData, useUser } from "~/hooks";
+import { useOptimisticLocation, useRouteData, useUser } from "~/hooks";
import type { QuotationLine, QuoteMethod } from "~/modules/sales";
import {
DeleteQuoteLine,
@@ -220,6 +220,7 @@ function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
const navigate = useNavigate();
const disclosure = useDisclosure();
+ const location = useOptimisticLocation();
useMount(() => {
if (lineId === line.id) {
@@ -242,7 +243,7 @@ function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
disclosure.onOpen();
}
- if (!isSelected) {
+ if (location.pathname !== path.to.quoteLine(quoteId, line.id!)) {
// navigate to line
navigate(path.to.quoteLine(quoteId, line.id!));
}
@@ -282,9 +283,7 @@ function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
)}
<VStack spacing={0}>
- <span className="font-mono font-semibold">
- {line.itemReadableId}
- </span>
+ <span className="font-semibold">{line.itemReadableId}</span>
<span className="font-mono text-muted-foreground text-xs">
{line.customerPartId}
{line.customerPartRevision && ` (${line.customerPartRevision})`}
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
index 97d16ff0b6..28bab19cb3 100644
--- 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
@@ -65,5 +65,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
- return json({ id: quoteMaterialId });
+ return json({
+ id: quoteMaterialId,
+ methodType: updateQuoteMaterial.data.methodType,
+ });
}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index ff01bd0813..d14c55459b 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -600,11 +600,21 @@ export const path = {
methodType: string,
id: string
) => generatePath(`${x}/quote/${quoteId}/${lineId}/${methodType}/${id}`),
+ quoteLineMaterialMake: (
+ quoteId: string,
+ lineId: string,
+ makeMethodId: string,
+ materialId: string
+ ) =>
+ generatePath(
+ `${x}/quote/${quoteId}/${lineId}/make/${makeMethodId}/${materialId}`
+ ),
quoteLineMethod: (quoteId: string, quoteLineId: string, methodId: string) =>
generatePath(`${x}/quote/${quoteId}/${quoteLineId}/method/${methodId}`),
quoteMaterial: (quoteId: string, lineId: string, id: string) =>
- generatePath(`${x}/quote/methods/${quoteId}/${lineId}/${id}`),
+ generatePath(`${x}/quote/methods/${quoteId}/${lineId}/material/${id}`),
quoteMaterialsOrder: `${x}/quote/methods/material/order`,
+
quoteOperation: (quoteId: string, lineId: string, id: string) =>
generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/${id}`),
quoteOperationsOrder: `${x}/quote/methods/operation/order`,
diff --git a/packages/database/supabase/migrations/20240715024405_quotes.sql b/packages/database/supabase/migrations/20240715024405_quotes.sql
index ff5e70c04e..c56eaea833 100644
--- a/packages/database/supabase/migrations/20240715024405_quotes.sql
+++ b/packages/database/supabase/migrations/20240715024405_quotes.sql
@@ -368,18 +368,20 @@ WITH RECURSIVE material AS (
"quoteId",
"quoteLineId",
"id",
- "quoteMakeMethodId",
- "methodType",
- "quoteMaterialMakeMethodId",
+ "id" AS "quoteMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "quoteMaterialMakeMethodId",
"itemId",
- "itemType",
- "quantity",
- "quoteMakeMethodId" AS "parentMaterialId",
- CAST(1 AS DOUBLE PRECISION) AS "order"
+ 'Part' AS "itemType",
+ 1::NUMERIC(10,4) AS "quantity",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot"
FROM
- "quoteMaterialWithMakeMethodId"
+ "quoteMakeMethod"
WHERE
"quoteId" = qid
+ AND "parentMaterialId" IS NULL
UNION
SELECT
child."quoteId",
@@ -392,7 +394,8 @@ WITH RECURSIVE material AS (
child."itemType",
child."quantity",
parent."id" AS "parentMaterialId",
- child."order"
+ child."order",
+ FALSE AS "isRoot"
FROM
"quoteMaterialWithMakeMethodId" child
INNER JOIN material parent ON parent."quoteMaterialMakeMethodId" = child."quoteMakeMethodId"
@@ -410,25 +413,8 @@ SELECT
material."methodType",
material."parentMaterialId",
material."order",
- false AS "isRoot"
+ material."isRoot"
FROM material INNER JOIN item ON material."itemId" = item.id
-UNION
-SELECT
- mm."quoteId",
- mm."quoteLineId",
- mm."id" AS "methodMaterialId",
- NULL AS "makeMethodId",
- mm.id AS "quoteMakeMethodId",
- mm."itemId",
- i."readableId" AS "itemReadableId",
- i."type"::text,
- 1 AS "quantity",
- 'Make' AS "methodType",
- NULL AS "parentMaterialId",
- CAST(1 AS DOUBLE PRECISION) AS "order",
- true AS "isRoot"
-
-FROM "quoteMakeMethod" mm INNER JOIN item i ON mm."itemId" = i.id
-WHERE mm."quoteId" = qid
+WHERE material."quoteId" = qid
ORDER BY "order"
-$$ LANGUAGE sql STABLE;
+$$ LANGUAGE sql STABLE;
\ No newline at end of file