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 routes for quote operations

Brad Barbina4d8eeb5473f
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index b2b03d5b25..964682d006 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -112,7 +112,9 @@ export const quotationOperationValidator = withZod(
quoteAssemblyId: zfd.text(z.string().optional()),
workCellTypeId: z.string().min(20, { message: "Work cell is required" }),
equipmentTypeId: zfd.text(z.string().optional()),
- description: zfd.text(z.string().optional()),
+ description: zfd.text(
+ z.string().min(0, { message: "Description is required" })
+ ),
setupHours: zfd.numeric(z.number().min(0)),
standardFactor: z.enum(standardFactorType, {
errorMap: () => ({ message: "Standard factor is required" }),
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx
index 4a1421b093..fa8ff88d31 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx
@@ -14,7 +14,6 @@ import {
HStack,
IconButton,
VStack,
- cn,
} from "@carbon/react";
import { useNavigate, useParams } from "@remix-run/react";
import { useState } from "react";
@@ -94,7 +93,7 @@ const QuotationAssemblyForm = ({
: path.to.newQuoteAssembly(quoteId, lineId)
}
>
- <Card className={cn(!isEditing && "mt-4")}>
+ <Card>
<HStack className="w-full justify-between items-start">
<CardHeader>
<CardTitle>
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
index 0464e0fbb3..d910e196a7 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
@@ -47,7 +47,7 @@ const QuotationForm = ({ initialValues }: QuotationFormProps) => {
defaultValues={initialValues}
className="w-full"
>
- <Card className={cn(!isEditing && "mt-4")}>
+ <Card>
<CardHeader>
<CardTitle>{isEditing ? "Quote" : "New Quote"}</CardTitle>
{!isEditing && (
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx
index dba0ea92f5..9f30d28c6d 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx
@@ -99,7 +99,7 @@ const QuotationLineQuantities = ({
{
accessorKey: "unitCostBase",
header: "Unit Cost",
- cell: (item) => formatter.format(item.getValue<number>()),
+ cell: ({ row }) => formatter.format(getUnitCost(row.original)),
},
{
accessorKey: "unitTaxAmount",
@@ -111,7 +111,7 @@ const QuotationLineQuantities = ({
cell: ({ row }) =>
formatter.format(
row.original.quantity *
- (row.original.unitCostBase + row.original.unitTaxAmount)
+ (getUnitCost(row.original) + row.original.unitTaxAmount)
),
},
{
@@ -246,3 +246,12 @@ const QuotationLineQuantities = ({
};
export default QuotationLineQuantities;
+
+function getUnitCost(quantity: QuotationLineQuantity) {
+ return (
+ quantity.materialCost +
+ quantity.laborCost +
+ quantity.overheadCost +
+ quantity.additionalCost
+ );
+}
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx
index 53d705d87f..998e1fa26f 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx
@@ -14,7 +14,6 @@ import {
HStack,
IconButton,
VStack,
- cn,
} from "@carbon/react";
import { useNavigate, useParams } from "@remix-run/react";
import { useState } from "react";
@@ -84,7 +83,7 @@ const QuotationOperationForm = ({
setWorkCellData({
workCellTypeId,
- description: data?.description ?? "",
+ description: data?.name ?? "",
quotingRate: data?.quotingRate ?? 0,
laborRate: data?.laborRate ?? 0,
overheadRate: data?.overheadRate ?? 0,
@@ -127,7 +126,7 @@ const QuotationOperationForm = ({
: path.to.newQuoteOperation(quoteId, lineId)
}
>
- <Card className={cn(!isEditing && "mt-4")}>
+ <Card>
<HStack className="w-full justify-between items-start">
<CardHeader>
<CardTitle>
@@ -190,7 +189,7 @@ const QuotationOperationForm = ({
</VStack>
<VStack>
<NumberControlled
- name="setupTime"
+ name="setupHours"
label="Setup Time (hours)"
minValue={0}
value={equipmentData.setupHours}
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/index.ts b/apps/carbon/app/modules/sales/ui/Quotation/index.ts
index 8b19d82384..04331ba167 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/index.ts
+++ b/apps/carbon/app/modules/sales/ui/Quotation/index.ts
@@ -1,3 +1,4 @@
+import QuotationAssemblyForm from "./QuotationAssemblyForm";
import QuotationDocuments from "./QuotationDocuments";
import QuotationForm from "./QuotationForm";
import QuotationHeader from "./QuotationHeader";
@@ -6,16 +7,19 @@ import {
default as QuotationLineQuantities,
default as QuotationLines,
} from "./QuotationLines";
+import QuotationOperationForm from "./QuotationOperationForm";
import QuotationSidebar from "./QuotationSidebar";
import QuotationStatus from "./QuotationStatus";
export {
+ QuotationAssemblyForm,
QuotationDocuments,
QuotationForm,
QuotationHeader,
QuotationLineForm,
QuotationLineQuantities,
QuotationLines,
+ QuotationOperationForm,
QuotationSidebar,
QuotationStatus,
};
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.new.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.new.tsx
index ba87526886..e4fdf1a810 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.new.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.new.tsx
@@ -1,10 +1,9 @@
-import { redirect, useParams } from "@remix-run/react";
-import { useUrlParams } from "~/hooks";
-import QuotationAssemblyForm from "~/modules/sales/ui/Quotation/QuotationAssemblyForm";
-
import type { ActionFunctionArgs } from "@remix-run/node";
+import { redirect, useParams } from "@remix-run/react";
import { validationError } from "remix-validated-form";
+import { useUrlParams } from "~/hooks";
import {
+ QuotationAssemblyForm,
quotationAssemblyValidator,
upsertQuoteAssembly,
} from "~/modules/sales";
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.delete.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.delete.tsx
new file mode 100644
index 0000000000..cda0eac7d6
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.delete.tsx
@@ -0,0 +1,62 @@
+import { json, redirect, useNavigate, useParams } from "@remix-run/react";
+
+import type { ActionFunctionArgs } from "@remix-run/node";
+import { ConfirmDelete } from "~/components/Modals";
+import { useRouteData } from "~/hooks";
+import type { QuotationAssembly } from "~/modules/sales";
+import { deleteQuoteAssembly } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client } = await requirePermissions(request, {
+ update: "sales",
+ });
+
+ const { id: quoteId, lineId: quoteLineId, assemblyId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!quoteLineId) throw new Error("Could not find quoteLineId");
+ if (!assemblyId) throw new Error("Could not find assemblyId");
+
+ const deleteAssembly = await deleteQuoteAssembly(client, assemblyId);
+
+ if (deleteAssembly.error) {
+ return json(
+ path.to.quoteLine(quoteId, quoteLineId),
+ await flash(
+ request,
+ error(deleteAssembly.error, "Failed to update quote assembly")
+ )
+ );
+ }
+
+ return redirect(path.to.quoteLine(quoteId, quoteLineId));
+}
+
+export default function DeleteQuoteAssembly() {
+ const navigate = useNavigate();
+
+ const { id, lineId, assemblyId } = useParams();
+ if (!id) throw new Error("id not found");
+ if (!lineId) throw new Error("lineId not found");
+ if (!assemblyId) throw new Error("assemblyId not found");
+
+ const routeData = useRouteData<{ quoteAssembly: QuotationAssembly }>(
+ path.to.quoteAssembly(id, lineId, assemblyId)
+ );
+
+ if (!routeData?.quoteAssembly) throw new Error("quote assembly not found");
+
+ return (
+ <ConfirmDelete
+ action={path.to.deleteQuoteAssembly(id, lineId, assemblyId)}
+ name={routeData?.quoteAssembly.partId}
+ text={`Are you sure you want to delete the assembly: ${routeData?.quoteAssembly.partId}? This cannot be undone.`}
+ onCancel={() => navigate(path.to.quoteAssembly(id, lineId, assemblyId))}
+ />
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx
new file mode 100644
index 0000000000..bd6a14e111
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx
@@ -0,0 +1,112 @@
+import { Outlet, json, redirect, useLoaderData } from "@remix-run/react";
+import QuotationOperationForm from "~/modules/sales/ui/Quotation/QuotationOperationForm";
+
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
+import { validationError } from "remix-validated-form";
+import {
+ getQuoteOperation,
+ quotationOperationValidator,
+ upsertQuoteOperation,
+} from "~/modules/sales";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+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 { id, operationId } = params;
+ if (!id) throw new Error("Could not find id");
+ if (!operationId) throw new Error("Could not find operationId");
+
+ const operation = await getQuoteOperation(client, operationId);
+ if (operation.error) {
+ return redirect(
+ path.to.quote(id),
+ await flash(
+ request,
+ error(operation.error, "Failed to load quote operation.")
+ )
+ );
+ }
+
+ return json({
+ quoteOperation: operation.data,
+ });
+}
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ create: "sales",
+ });
+
+ const { id: quoteId, lineId: quoteLineId, operationId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!quoteLineId) throw new Error("Could not find quoteLineId");
+ if (!operationId) throw new Error("Could not find operationId");
+
+ const validation = await quotationOperationValidator.validate(
+ await request.formData()
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+
+ const updateQuotationOperation = await upsertQuoteOperation(client, {
+ id: operationId,
+ quoteId,
+ quoteLineId,
+ ...data,
+ createdBy: userId,
+ });
+
+ if (updateQuotationOperation.error) {
+ return json(
+ path.to.quote(quoteId),
+ await flash(
+ request,
+ error(
+ updateQuotationOperation.error,
+ "Failed to update quote operation"
+ )
+ )
+ );
+ }
+
+ return redirect(path.to.quoteOperation(quoteId, quoteLineId, operationId));
+}
+
+export default function QuoteOperation() {
+ const { quoteOperation } = useLoaderData<typeof loader>();
+
+ const initialValues = {
+ id: quoteOperation.id,
+ quoteId: quoteOperation.quoteId,
+ quoteLineId: quoteOperation.quoteLineId,
+ quoteAssemblyId: quoteOperation.quoteAssemblyId ?? "",
+ workCellTypeId: quoteOperation.workCellTypeId,
+ equipmentTypeId: quoteOperation.equipmentTypeId ?? "",
+ description: quoteOperation.description ?? "",
+ setupHours: quoteOperation.setupHours,
+ standardFactor: quoteOperation.standardFactor as "Total Hours",
+ productionStandard: quoteOperation.productionStandard,
+ quotingRate: quoteOperation.quotingRate,
+ laborRate: quoteOperation.laborRate,
+ overheadRate: quoteOperation.overheadRate,
+ };
+
+ return (
+ <>
+ <QuotationOperationForm initialValues={initialValues} />
+ <Outlet />
+ </>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.new.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.new.tsx
new file mode 100644
index 0000000000..66f41e66c2
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.new.tsx
@@ -0,0 +1,86 @@
+import { redirect, useParams } from "@remix-run/react";
+import { useUrlParams } from "~/hooks";
+
+import type { ActionFunctionArgs } from "@remix-run/node";
+import { validationError } from "remix-validated-form";
+import {
+ QuotationOperationForm,
+ quotationOperationValidator,
+ upsertQuoteOperation,
+} from "~/modules/sales";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ create: "sales",
+ });
+
+ const { id: quoteId, lineId: quoteLineId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!quoteLineId) throw new Error("Could not find quoteLineId");
+
+ const validation = await quotationOperationValidator.validate(
+ await request.formData()
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+
+ const createQuotationOperation = await upsertQuoteOperation(client, {
+ quoteId,
+ quoteLineId,
+ ...data,
+ createdBy: userId,
+ });
+
+ if (createQuotationOperation.error) {
+ return redirect(
+ path.to.newQuoteOperation(quoteId, quoteLineId),
+ await flash(
+ request,
+ error(
+ createQuotationOperation.error,
+ "Failed to create quote operation"
+ )
+ )
+ );
+ }
+
+ const operationId = createQuotationOperation.data.id;
+ if (operationId) {
+ return redirect(path.to.quoteOperation(quoteId, quoteLineId, operationId));
+ }
+}
+
+export default function NewQuoteOperation() {
+ const { id: quoteId, lineId } = useParams();
+ const [params] = useUrlParams();
+ const quoteAssemblyId = params.get("parentOperationId");
+
+ if (!quoteId) throw new Error("quoteId not found");
+ if (!lineId) throw new Error("lineId not found");
+
+ const initialValues = {
+ quoteId,
+ quoteLineId: lineId,
+ quoteAssemblyId: quoteAssemblyId ?? undefined,
+ description: "",
+ workCellTypeId: "",
+ productionStandard: 0,
+ quotingRate: 0,
+ laborRate: 0,
+ overheadRate: 0,
+ setupHours: 0,
+ standardFactor: "Total Hours" as "Total Hours",
+ };
+
+ return <QuotationOperationForm initialValues={initialValues} />;
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index 9f736e3c47..fa1d10b95c 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -172,12 +172,12 @@ const data: BillOfMaterialNode[] = [
type: "parent",
children: [
{
- id: "cnc03dgmu0l0h0gm0330",
+ id: "cncmajs9k0ldipluqngg",
label: "P00001233",
type: "line",
children: [
{
- id: "cnc03dgmu0l0h0gm0330",
+ id: "cncmajs9k0ldipluqngg",
label: "Assemblies",
type: "assemblies",
children: [
@@ -228,7 +228,7 @@ const data: BillOfMaterialNode[] = [
],
},
{
- id: "cnc03dgmu0l0h0gm0330",
+ id: "cncmajs9k0ldipluqngg",
label: "Operations",
type: "operations",
children: [
@@ -309,14 +309,17 @@ const BillOfMaterialItem = ({
<Button
variant="ghost"
className="w-full justify-between text-muted-foreground"
+ asChild
>
- <span>{label}</span>
- <IoMdAdd />
+ <Link to={path.to.newQuoteOperation(quoteId, id, parentId)}>
+ <span>{label}</span>
+ <IoMdAdd />
+ </Link>
</Button>
);
case "line":
return (
- <Button variant="ghost" className="flex-1 justify-between" asChild>
+ <Button variant="primary" className="flex-1 justify-between" asChild>
<Link to={path.to.quoteLine(quoteId, id)} prefetch="intent">
<span className="flex justify-start">
<AiOutlinePartition className="w-4 h-4 mr-2" />