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.

refactor: remove deprecated quote files

Brad Barbin1686ae4ddf7f
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id._index.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id._index.tsx
deleted file mode 100644
index 9214487b2f..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id._index.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import type { LoaderFunctionArgs } from "@remix-run/node";
-import { redirect } from "@remix-run/node";
-import { path } from "~/utils/path";
-
-export async function loader({ params }: LoaderFunctionArgs) {
- const { id } = params;
- if (!id) throw new Error("Could not find id");
- throw redirect(path.to.quoteDetails(id));
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.convert-to-order.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.convert-to-order.tsx
deleted file mode 100644
index c8c40c4720..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.convert-to-order.tsx
+++ /dev/null
@@ -1,123 +0,0 @@
-import { redirect, type ActionFunctionArgs } from "@remix-run/node";
-import {
- convertQuoteToOrder,
- getQuote,
- getQuoteLines,
- insertSalesOrderLines,
- upsertSalesOrder,
-} from "~/modules/sales";
-import { getNextSequence, rollbackNextSequence } from "~/modules/settings";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { assertIsPost } from "~/utils/http";
-import { path } from "~/utils/path";
-import { error, success } from "~/utils/result";
-
-export async function action(args: ActionFunctionArgs) {
- const { request, params } = args;
- assertIsPost(request);
-
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "sales",
- role: "employee",
- });
-
- const { id } = params;
- if (!id) throw new Error("Could not find id");
-
- let newSalesOrderId: string;
-
- const updateQuoteStatus = await convertQuoteToOrder(client, id, userId);
- if (updateQuoteStatus.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(
- updateQuoteStatus.error,
- "Failed to update quote status to Ordered"
- )
- )
- );
- }
-
- const quote = await getQuote(client, id);
- if (quote.error) {
- throw redirect(
- path.to.quote(id),
- await flash(request, error(quote.error, "Failed to get quote"))
- );
- }
-
- try {
- const nextSequence = await getNextSequence(client, "salesOrder", companyId);
- if (nextSequence.error) {
- throw redirect(
- path.to.newSalesOrder,
- await flash(
- request,
- error(nextSequence.error, "Failed to get next sequence")
- )
- );
- }
- const createSalesOrder = await upsertSalesOrder(client, {
- salesOrderId: nextSequence.data,
- quoteId: quote.data.id!,
- customerId: quote.data.customerId!,
- companyId,
- createdBy: userId,
- orderDate: new Date().toISOString(),
- });
-
- if (createSalesOrder.error || !createSalesOrder.data?.[0]) {
- // TODO: this should be done as a transaction
- await rollbackNextSequence(client, "salesOrder", companyId);
- throw redirect(
- path.to.quotes,
- await flash(
- request,
- error(createSalesOrder.error, "Failed to insert sales order")
- )
- );
- }
-
- const order = createSalesOrder.data?.[0];
- newSalesOrderId = order.id;
-
- // construct and insert the sales order lines
- const quoteLines = await getQuoteLines(client, id);
- if (quoteLines.data) {
- const lines = quoteLines?.data.map((quoteLine) => {
- return {
- salesOrderId: newSalesOrderId,
- salesOrderLineType: "Part" as "Part",
- companyId,
- itemId: quoteLine.itemId!,
- description: quoteLine.description!,
- createdBy: userId,
- };
- });
-
- const salesOrderLines = await insertSalesOrderLines(client, lines);
-
- if (salesOrderLines.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(salesOrderLines.error, "Failed to create sales order lines")
- )
- );
- }
- }
- } catch (err) {
- throw redirect(
- path.to.quote(id),
- await flash(request, error(err, "Failed to create sales order"))
- );
- }
- throw redirect(
- path.to.salesOrder(newSalesOrderId),
- await flash(request, success("Quote converted to sales order"))
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.details.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.details.tsx
deleted file mode 100644
index a3242a539c..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.details.tsx
+++ /dev/null
@@ -1,97 +0,0 @@
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs } from "@remix-run/node";
-import { redirect } from "@remix-run/node";
-import { useParams } from "@remix-run/react";
-import { useRouteData } from "~/hooks";
-import type { Quotation, QuotationAttachment } from "~/modules/sales";
-import {
- QuotationDocuments,
- QuotationForm,
- quotationValidator,
- upsertQuote,
-} from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { getCustomFields, setCustomFields } from "~/utils/form";
-import { assertIsPost } from "~/utils/http";
-import { path } from "~/utils/path";
-import { error, success } from "~/utils/result";
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
- update: "sales",
- });
-
- const { id } = params;
- if (!id) throw new Error("Could not find id");
-
- const formData = await request.formData();
- const validation = await validator(quotationValidator).validate(formData);
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { quoteId, ...data } = validation.data;
- if (!quoteId) throw new Error("Could not find quoteId");
-
- const updateQuotation = await upsertQuote(client, {
- id: id,
- quoteId,
- ...data,
- updatedBy: userId,
- customFields: setCustomFields(formData),
- });
- if (updateQuotation.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(updateQuotation.error, "Failed to update quote")
- )
- );
- }
-
- throw redirect(
- path.to.quote(id),
- await flash(request, success("Updated quote"))
- );
-}
-
-export default function QuotationBasicRoute() {
- const { id } = useParams();
- if (!id) throw new Error("Could not find id");
- const quoteData = useRouteData<{
- quotation: Quotation;
- internalDocuments: QuotationAttachment[];
- }>(path.to.quote(id));
- if (!quoteData) throw new Error("Could not find quote data");
-
- const initialValues = {
- id: quoteData?.quotation?.id ?? "",
- quoteId: quoteData?.quotation?.quoteId ?? "",
-
- customerId: quoteData?.quotation?.customerId ?? "",
- customerContactId: quoteData?.quotation?.customerContactId ?? "",
- customerLocationId: quoteData?.quotation?.customerLocationId ?? "",
- customerReference: quoteData?.quotation?.customerReference ?? "",
- locationId: quoteData?.quotation?.locationId ?? "",
- quoteDate: quoteData?.quotation?.dueDate ?? "",
- expirationDate: quoteData?.quotation.expirationDate ?? undefined,
- status: quoteData?.quotation?.status ?? ("Draft" as "Draft"),
- notes: quoteData?.quotation?.notes ?? "",
- ...getCustomFields(quoteData.quotation.customFields),
- };
-
- return (
- <>
- <QuotationForm key={initialValues.id} initialValues={initialValues} />
- <QuotationDocuments
- id={id}
- attachments={quoteData.internalDocuments}
- isExternal={false}
- />
- </>
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.external.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.external.tsx
deleted file mode 100644
index 69c7aa78e6..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.external.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import { useParams } from "@remix-run/react";
-import { useRouteData } from "~/hooks";
-import type { QuotationAttachment } from "~/modules/sales";
-import { QuotationDocuments } from "~/modules/sales";
-import { path } from "~/utils/path";
-
-export function action() {
- // used for reloading the data via fetcher.submit(null, { method: 'post'})
- return null;
-}
-
-export default function QuotationExternalDocumentsRoute() {
- const { id } = useParams();
- if (!id) throw new Error("id not found");
-
- const routeData = useRouteData<{
- externalDocuments: QuotationAttachment[];
- }>(path.to.quote(id));
-
- return (
- <QuotationDocuments
- attachments={routeData?.externalDocuments ?? []}
- isExternal
- id={id}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.internal.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.internal.tsx
deleted file mode 100644
index aeffa92aa9..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.internal.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import { useParams } from "@remix-run/react";
-import { useRouteData } from "~/hooks";
-import type { QuotationAttachment } from "~/modules/sales";
-import { QuotationDocuments } from "~/modules/sales";
-import { path } from "~/utils/path";
-
-export function action() {
- // used for reloading the data via fetcher.submit(null, { method: 'post'})
- return null;
-}
-
-export default function QuotationInternalDocumentsRoute() {
- const { id } = useParams();
- if (!id) throw new Error("id not found");
-
- const routeData = useRouteData<{
- internalDocuments: QuotationAttachment[];
- }>(path.to.quote(id));
-
- return (
- <QuotationDocuments
- attachments={routeData?.internalDocuments ?? []}
- isExternal={false}
- id={id}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
deleted file mode 100644
index f2c3df6b79..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-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/auth.server";
-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")
- )
- );
- }
-
- throw 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.itemId}
- text={`Are you sure you want to delete the assembly: ${routeData?.quoteAssembly.itemId}? This cannot be undone.`}
- onCancel={() => navigate(path.to.quoteAssembly(id, lineId, assemblyId))}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.tsx
deleted file mode 100644
index f26c4a7a34..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.tsx
+++ /dev/null
@@ -1,111 +0,0 @@
-import { Outlet, json, redirect, useLoaderData } from "@remix-run/react";
-import QuotationAssemblyForm from "~/modules/sales/ui/Quotation/QuotationAssemblyForm";
-
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
-import {
- getQuoteAssembly,
- quotationAssemblyValidator,
- upsertQuoteAssembly,
-} from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { getCustomFields, setCustomFields } from "~/utils/form";
-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, assemblyId } = params;
- if (!id) throw new Error("Could not find id");
- if (!assemblyId) throw new Error("Could not find assemblyId");
-
- const assembly = await getQuoteAssembly(client, assemblyId);
- if (assembly.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(assembly.error, "Failed to load quote assembly.")
- )
- );
- }
-
- return json({
- quoteAssembly: assembly.data,
- });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
- create: "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 formData = await request.formData();
- const validation = await validator(quotationAssemblyValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const updateQuotationAssembly = await upsertQuoteAssembly(client, {
- id: assemblyId,
- quoteId,
- quoteLineId,
- ...data,
- updatedBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (updateQuotationAssembly.error) {
- return json(
- path.to.quote(quoteId),
- await flash(
- request,
- error(updateQuotationAssembly.error, "Failed to update quote assembly")
- )
- );
- }
-
- throw redirect(path.to.quoteAssembly(quoteId, quoteLineId, assemblyId));
-}
-
-export default function QuoteAssembly() {
- const { quoteAssembly } = useLoaderData<typeof loader>();
-
- const initialValues = {
- id: quoteAssembly.id,
- quoteId: quoteAssembly.quoteId,
- quoteLineId: quoteAssembly.quoteLineId,
- parentAssemblyId: quoteAssembly.parentAssemblyId ?? undefined,
- itemId: quoteAssembly.itemId,
- description: quoteAssembly.description ?? "",
- quantityPerParent: quoteAssembly.quantityPerParent,
- unitOfMeasureCode: quoteAssembly.unitOfMeasureCode ?? "",
- ...getCustomFields(quoteAssembly.customFields),
- };
-
- return (
- <>
- <QuotationAssemblyForm
- key={initialValues.id}
- initialValues={initialValues}
- />
- <Outlet />
- </>
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.new.tsx
deleted file mode 100644
index 50f4966c05..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.new.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs } from "@remix-run/node";
-import { redirect, useParams } from "@remix-run/react";
-import { useUrlParams } from "~/hooks";
-import {
- QuotationAssemblyForm,
- quotationAssemblyValidator,
- upsertQuoteAssembly,
-} 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 { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, 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 formData = await request.formData();
- const validation = await validator(quotationAssemblyValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const createQuotationAssembly = await upsertQuoteAssembly(client, {
- quoteId,
- quoteLineId,
- companyId,
- ...data,
- createdBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (createQuotationAssembly.error) {
- throw redirect(
- path.to.newQuoteAssembly(quoteId, quoteLineId),
- await flash(
- request,
- error(createQuotationAssembly.error, "Failed to create quote assembly")
- )
- );
- }
-
- const assemblyId = createQuotationAssembly.data.id;
- if (assemblyId) {
- throw redirect(path.to.quoteAssembly(quoteId, quoteLineId, assemblyId));
- }
-}
-
-export default function NewQuoteAssembly() {
- const { id: quoteId, lineId } = useParams();
- const [params] = useUrlParams();
- const parentAssemblyId = params.get("parentAssemblyId");
-
- if (!quoteId) throw new Error("quoteId not found");
- if (!lineId) throw new Error("lineId not found");
-
- const initialValues = {
- quoteId,
- quoteLineId: lineId,
- parentAssemblyId: parentAssemblyId ?? undefined,
- itemId: "",
- description: "",
- quantityPerParent: 1,
- };
-
- return <QuotationAssemblyForm initialValues={initialValues} />;
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.delete.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.delete.tsx
deleted file mode 100644
index 41d3d9dd02..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.delete.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-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 { QuotationLine } from "~/modules/sales";
-import { deleteQuoteLine } from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-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 } = params;
- if (!quoteId) throw new Error("Could not find quoteId");
- if (!quoteLineId) throw new Error("Could not find quoteLineId");
-
- const deleteLine = await deleteQuoteLine(client, quoteLineId);
-
- if (deleteLine.error) {
- return json(
- path.to.quoteLine(quoteId, quoteLineId),
- await flash(
- request,
- error(deleteLine.error, "Failed to update quote line")
- )
- );
- }
-
- throw redirect(path.to.quote(quoteId));
-}
-
-export default function DeleteQuoteLine() {
- const { id, lineId } = useParams();
- if (!id) throw new Error("id not found");
- if (!lineId) throw new Error("lineId not found");
-
- const routeData = useRouteData<{ quotationLine: QuotationLine }>(
- path.to.quoteLine(id, lineId)
- );
- const navigate = useNavigate();
-
- if (!routeData?.quotationLine) throw new Error("quote line not found");
-
- const onCancel = () => navigate(path.to.quoteLine(id, lineId));
-
- return (
- <ConfirmDelete
- action={path.to.deleteQuoteLine(id, lineId)}
- name={routeData?.quotationLine.itemReadableId ?? "this line"}
- text={`Are you sure you want to delete the line: ${routeData?.quotationLine.itemReadableId}? This cannot be undone.`}
- onCancel={onCancel}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.tsx
deleted file mode 100644
index 2e50b997dc..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.tsx
+++ /dev/null
@@ -1,155 +0,0 @@
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
-import { json, redirect } from "@remix-run/node";
-import { Outlet, useLoaderData } from "@remix-run/react";
-import {
- QuotationLineForm,
- QuotationPricing,
- getQuoteLine,
- getQuoteLinePrice,
- quotationLineValidator,
- quotationPricingValidator,
- updateQuoteLinePrice,
- upsertQuoteLine,
-} from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { getCustomFields, setCustomFields } from "~/utils/form";
-import { assertIsPost, notFound } 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",
- role: "employee",
- });
-
- const { lineId } = params;
- if (!lineId) throw notFound("lineId not found");
-
- const [quotationLine, quotationLinePricing] = await Promise.all([
- getQuoteLine(client, lineId),
- getQuoteLinePrice(client, lineId),
- ]);
-
- return json({
- quotationLine: quotationLine?.data ?? null,
- quotationLinePricing: quotationLinePricing?.data,
- });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
- create: "purchasing",
- });
-
- const { id: quoteId, lineId } = params;
- if (!quoteId) throw new Error("Could not find id");
- if (!lineId) throw new Error("Could not find lineId");
-
- const formData = await request.formData();
- const intent = formData.get("intent");
-
- if (intent === "line") {
- const validation = await validator(quotationLineValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const updateQuotationLine = await upsertQuoteLine(client, {
- id: lineId,
- ...data,
- updatedBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (updateQuotationLine.error) {
- throw redirect(
- path.to.quoteLine(quoteId, lineId),
- await flash(
- request,
- error(updateQuotationLine.error, "Failed to update quote line")
- )
- );
- }
- } else if (intent === "pricing") {
- const validation = await validator(quotationPricingValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const updateLinePrice = await updateQuoteLinePrice(client, {
- quoteId,
- quoteLineId: lineId,
- ...validation.data,
- updatedBy: userId,
- });
-
- if (updateLinePrice.error) {
- throw redirect(
- path.to.quoteLine(quoteId, lineId),
- await flash(
- request,
- error(updateLinePrice.error, "Failed to update quote line price")
- )
- );
- }
- }
-
- throw redirect(path.to.quoteLine(quoteId, lineId));
-}
-
-export default function EditQuotationLineRoute() {
- const { quotationLine, quotationLinePricing } =
- useLoaderData<typeof loader>();
- if (!quotationLine) throw new Error("Could not find quotation line");
-
- const lineInitialValues = {
- id: quotationLine?.id ?? undefined,
- quoteId: quotationLine?.quoteId ?? "",
- itemId: quotationLine?.itemId ?? "",
- description: quotationLine?.description ?? "",
- customerPartId: quotationLine?.customerPartId ?? "",
- customerPartRevision: quotationLine?.customerPartRevision ?? "",
- replenishmentSystem: (quotationLine?.replenishmentSystem ?? "") as
- | "Buy"
- | "Make",
- status: quotationLine?.status ?? "Draft",
- unitOfMeasureCode: quotationLine?.unitOfMeasureCode ?? "",
- ...getCustomFields(quotationLine?.customFields),
- };
-
- const pricingInitialValues = {
- quantity: quotationLinePricing?.quantity ?? 1,
- unitCost: quotationLinePricing?.unitCost ?? 0,
- leadTime: quotationLinePricing?.leadTime ?? 0,
- discountPercent: quotationLinePricing?.discountPercent ?? 0,
- markupPercent: quotationLinePricing?.markupPercent ?? 0,
- extendedPrice: quotationLinePricing?.extendedPrice ?? 0,
- };
-
- return (
- <>
- <QuotationLineForm
- key={`${lineInitialValues.id}-line`}
- initialValues={lineInitialValues}
- />
- <QuotationPricing
- key={`${lineInitialValues.id}-pricing`}
- initialValues={pricingInitialValues}
- isMade={quotationLine?.replenishmentSystem === "Make"}
- />
- <Outlet />
- </>
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.delete.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.delete.tsx
deleted file mode 100644
index 02c31b81b6..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.delete.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-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 { QuotationOperation } from "~/modules/sales";
-import { deleteQuoteOperation } from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-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, 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 deleteOperation = await deleteQuoteOperation(client, operationId);
-
- if (deleteOperation.error) {
- return json(
- path.to.quoteLine(quoteId, quoteLineId),
- await flash(
- request,
- error(deleteOperation.error, "Failed to update quote operation")
- )
- );
- }
-
- throw redirect(path.to.quoteLine(quoteId, quoteLineId));
-}
-
-export default function DeleteQuoteOperation() {
- const navigate = useNavigate();
-
- const { id, lineId, operationId } = useParams();
- if (!id) throw new Error("id not found");
- if (!lineId) throw new Error("lineId not found");
- if (!operationId) throw new Error("operationId not found");
-
- const routeData = useRouteData<{ quoteOperation: QuotationOperation }>(
- path.to.quoteOperation(id, lineId, operationId)
- );
-
- if (!routeData?.quoteOperation) throw new Error("quote operation not found");
-
- return (
- <ConfirmDelete
- name={routeData.quoteOperation.description ?? "Operation"}
- text={`Are you sure you want to delete the operation? This cannot be undone.`}
- onCancel={() => navigate(path.to.quoteOperation(id, lineId, operationId))}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.material.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.material.new.tsx
deleted file mode 100644
index 172acc4055..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.material.new.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-import { json, redirect } from "@remix-run/react";
-
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs } from "@remix-run/node";
-import {
- QuotationMaterialForm,
- quotationMaterialValidator,
- 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 { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "sales",
- });
-
- const {
- id: quoteId,
- lineId: quoteLineId,
- operationId: quoteOperationId,
- } = params;
- if (!quoteId) throw new Error("Could not find quoteId");
- if (!quoteLineId) throw new Error("Could not find quoteLineId");
- if (!quoteOperationId) throw new Error("Could not find operationId");
-
- const formData = await request.formData();
- const validation = await validator(quotationMaterialValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const createQuotationMaterial = await upsertQuoteMaterial(client, {
- quoteId,
- quoteLineId,
- quoteOperationId,
- ...data,
- companyId,
- createdBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (createQuotationMaterial.error) {
- return json(
- path.to.quote(quoteId),
- await flash(
- request,
- error(createQuotationMaterial.error, "Failed to create quote material")
- )
- );
- }
-
- throw redirect(
- path.to.quoteOperation(quoteId, quoteLineId, quoteOperationId)
- );
-}
-
-export default function NewQuoteMaterial() {
- const initialValues = {
- itemId: "",
- quantity: 1,
- description: "",
- unitCost: 0,
- unitOfMeasureCode: "EA",
- };
-
- return <QuotationMaterialForm initialValues={initialValues} />;
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.tsx
deleted file mode 100644
index e3728f64c8..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.tsx
+++ /dev/null
@@ -1,136 +0,0 @@
-import { json, redirect, useLoaderData } from "@remix-run/react";
-
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
-import {
- QuotationMaterialLines,
- QuotationOperationForm,
- getQuoteMaterialsByOperation,
- getQuoteOperation,
- quotationOperationValidator,
- upsertQuoteOperation,
-} from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { getCustomFields, setCustomFields } from "~/utils/form";
-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, materials] = await Promise.all([
- getQuoteOperation(client, operationId),
- getQuoteMaterialsByOperation(client, operationId),
- ]);
- if (operation.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(operation.error, "Failed to load quote operation.")
- )
- );
- }
-
- if (materials.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(materials.error, "Failed to load quote materials.")
- )
- );
- }
-
- return json({
- quoteOperation: operation.data,
- quoteMaterials: materials.data ?? [],
- });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, 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 formData = await request.formData();
- const validation = await validator(quotationOperationValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const updateQuotationOperation = await upsertQuoteOperation(client, {
- id: operationId,
- quoteId,
- quoteLineId,
- ...data,
- companyId,
- createdBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (updateQuotationOperation.error) {
- return json(
- path.to.quote(quoteId),
- await flash(
- request,
- error(
- updateQuotationOperation.error,
- "Failed to update quote operation"
- )
- )
- );
- }
-
- throw redirect(path.to.quoteOperation(quoteId, quoteLineId, operationId));
-}
-
-export default function QuoteOperation() {
- const { quoteOperation, quoteMaterials } = 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,
- ...getCustomFields(quoteOperation.customFields),
- };
-
- return (
- <>
- <QuotationOperationForm
- key={initialValues.id}
- initialValues={initialValues}
- />
- <QuotationMaterialLines quotationMaterials={quoteMaterials} />
- </>
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.new.tsx
deleted file mode 100644
index 1b2e5ec111..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.new.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { redirect, useParams } from "@remix-run/react";
-import { useUrlParams } from "~/hooks";
-
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs } from "@remix-run/node";
-import {
- QuotationOperationForm,
- quotationOperationValidator,
- 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 { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, 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 formData = await request.formData();
- const validation = await validator(quotationOperationValidator).validate(
- formData
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const createQuotationOperation = await upsertQuoteOperation(client, {
- quoteId,
- quoteLineId,
- ...data,
- companyId,
- createdBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (createQuotationOperation.error) {
- throw redirect(
- path.to.newQuoteOperation(quoteId, quoteLineId),
- await flash(
- request,
- error(
- createQuotationOperation.error,
- "Failed to create quote operation"
- )
- )
- );
- }
-
- const operationId = createQuotationOperation.data.id;
- if (operationId) {
- throw 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-deprecated+/$id.lines.delete.$lineId.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.delete.$lineId.tsx
deleted file mode 100644
index 600b3bd70d..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.delete.$lineId.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
-import { json, redirect } from "@remix-run/node";
-import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
-import { ConfirmDelete } from "~/components/Modals";
-import { deleteQuoteLine, getQuoteLine } from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { notFound } from "~/utils/http";
-import { path } from "~/utils/path";
-import { error, success } from "~/utils/result";
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "sales",
- });
- const { lineId, id } = params;
- if (!lineId) throw notFound("lineId not found");
- if (!id) throw notFound("id not found");
-
- const quotationLine = await getQuoteLine(client, lineId);
- if (quotationLine.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(quotationLine.error, "Failed to get quotation line")
- )
- );
- }
-
- return json({ quotationLine: quotationLine.data });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "sales",
- });
-
- const { lineId, id } = params;
- if (!lineId) throw notFound("Could not find lineId");
- if (!id) throw notFound("Could not find id");
-
- const { error: deleteTypeError } = await deleteQuoteLine(client, lineId);
- if (deleteTypeError) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(deleteTypeError, "Failed to delete quotation line")
- )
- );
- }
-
- throw redirect(
- path.to.quote(id),
- await flash(request, success("Successfully deleted quotation line"))
- );
-}
-
-export default function DeleteQuoteLineRoute() {
- const { lineId, id } = useParams();
- const { quotationLine } = useLoaderData<typeof loader>();
- const navigate = useNavigate();
-
- if (!quotationLine) return null;
- if (!lineId) throw notFound("Could not find lineId");
- if (!id) throw notFound("Could not find id");
-
- const onCancel = () => navigate(path.to.quote(id));
-
- return (
- <ConfirmDelete
- action={path.to.deleteQuoteLine(id, lineId)}
- name="Quote Line"
- text={`Are you sure you want to delete the quotation line for ${quotationLine.itemReadableId}? This cannot be undone.`}
- onCancel={onCancel}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.new.tsx
deleted file mode 100644
index 3a3543ae86..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.new.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs } from "@remix-run/node";
-import { redirect } from "@remix-run/node";
-import { useParams } from "@remix-run/react";
-import {
- QuotationLineForm,
- insertQuoteLinePrice,
- quotationLineValidator,
- upsertQuoteLine,
-} 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 { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-export async function action({ request, params }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "sales",
- });
-
- const { id: quoteId } = params;
- if (!quoteId) throw new Error("Could not find id");
-
- const formData = await request.formData();
- const validation = await validator(quotationLineValidator).validate(formData);
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const createQuotationLine = await upsertQuoteLine(client, {
- ...data,
- companyId,
- createdBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (createQuotationLine.error) {
- throw redirect(
- path.to.quote(quoteId),
- await flash(
- request,
- error(createQuotationLine.error, "Failed to create quote line.")
- )
- );
- }
-
- const quoteLineId = createQuotationLine.data.id;
-
- await insertQuoteLinePrice(client, {
- quoteId,
- quoteLineId,
- quantity: 1,
- markupPercent: 15,
- createdBy: userId,
- });
-
- throw redirect(path.to.quoteLine(quoteId, quoteLineId));
-}
-
-export default function NewQuotationLineRoute() {
- const { id } = useParams();
-
- if (!id) throw new Error("Could not find quote id");
-
- const initialValues = {
- quoteId: id,
- itemId: "",
- description: "",
- replenishmentSystem: "" as "Buy" | "Make",
- unitOfMeasureCode: "",
- status: "Draft" as "Draft",
- };
-
- return <QuotationLineForm initialValues={initialValues} />;
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.release.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.release.tsx
deleted file mode 100644
index 2ed8822a60..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.release.tsx
+++ /dev/null
@@ -1,198 +0,0 @@
-import { QuoteEmail } from "@carbon/documents";
-import { validationError, validator } from "@carbon/remix-validated-form";
-import { renderAsync } from "@react-email/components";
-import { redirect, type ActionFunctionArgs } from "@remix-run/node";
-import { triggerClient } from "~/lib/trigger.server";
-import { upsertDocument } from "~/modules/documents";
-import {
- getCustomer,
- getCustomerContact,
- getQuote,
- getQuoteLines,
- quotationReleaseValidator,
- releaseQuote,
-} from "~/modules/sales";
-import { getCompany } from "~/modules/settings";
-import { getUser } from "~/modules/users/users.server";
-import { loader as pdfLoader } from "~/routes/file+/quote+/$id[.]pdf";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { assertIsPost } from "~/utils/http";
-import { path } from "~/utils/path";
-import { error, success } from "~/utils/result";
-
-export async function action(args: ActionFunctionArgs) {
- const { request, params } = args;
- assertIsPost(request);
-
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "sales",
- role: "employee",
- });
-
- const { id } = params;
- if (!id) throw new Error("Could not find id");
-
- let file: ArrayBuffer;
- let fileName: string;
-
- const release = await releaseQuote(client, id, userId);
- if (release.error) {
- throw redirect(
- path.to.quote(id),
- await flash(request, error(release.error, "Failed to release quote"))
- );
- }
-
- const quote = await getQuote(client, id);
- if (quote.error) {
- throw redirect(
- path.to.quote(id),
- await flash(request, error(quote.error, "Failed to get quote"))
- );
- }
-
- try {
- const pdf = await pdfLoader(args);
- if (pdf.headers.get("content-type") !== "application/pdf")
- throw new Error("Failed to generate PDF");
-
- file = await pdf.arrayBuffer();
- fileName = `${quote.data.quoteId} - ${new Date()
- .toISOString()
- .slice(0, -5)}.pdf`;
-
- const documentFilePath = `${companyId}/quote/internal/${id}/${fileName}`;
-
- const documentFileUpload = await client.storage
- .from("private")
- .upload(documentFilePath, file, {
- cacheControl: `${12 * 60 * 60}`,
- contentType: "application/pdf",
- upsert: true,
- });
-
- if (documentFileUpload.error) {
- throw redirect(
- path.to.quote(id),
- await flash(
- request,
- error(documentFileUpload.error, "Failed to upload file")
- )
- );
- }
-
- const createDocument = await upsertDocument(client, {
- path: documentFilePath,
- name: fileName,
- size: Math.round(file.byteLength / 1024),
- sourceDocument: "Quote",
- sourceDocumentId: id,
- readGroups: [userId],
- writeGroups: [userId],
- createdBy: userId,
- companyId,
- });
-
- if (createDocument.error) {
- return redirect(
- path.to.quote(id),
- await flash(
- request,
- error(createDocument.error, "Failed to create document")
- )
- );
- }
- } catch (err) {
- throw redirect(
- path.to.quote(id),
- await flash(request, error(err, "Failed to generate PDF"))
- );
- }
-
- const validation = await validator(quotationReleaseValidator).validate(
- await request.formData()
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { notification, customerContact: customerContactId } = validation.data;
-
- switch (notification) {
- case "Email":
- try {
- if (!customerContactId) throw new Error("Customer contact is required");
-
- const [company, customer, customerContact, quoteLines, user] =
- await Promise.all([
- getCompany(client, companyId),
- getCustomer(client, quote.data.customerId!),
- getCustomerContact(client, customerContactId),
- getQuoteLines(client, id),
- getUser(client, userId),
- ]);
-
- if (!company.data) throw new Error("Failed to get company");
- if (!customer.data) throw new Error("Failed to get customer");
- if (!customerContact.data)
- throw new Error("Failed to get customer contact");
- if (!user.data) throw new Error("Failed to get user");
-
- // TODO: Update sender email
- const emailTemplate = QuoteEmail({
- company: company.data,
- // @ts-ignore
- quote: quote.data,
- // @ts-ignore
- quoteLines: quoteLines.data ?? [],
- recipient: {
- email: customerContact.data?.contact!.email!,
- firstName: "Customer",
- lastName: "",
- },
- sender: {
- email: user.data.email,
- firstName: user.data.firstName,
- lastName: user.data.lastName,
- },
- });
-
- await triggerClient.sendEvent({
- name: "resend.email",
- payload: {
- to: customerContact.data.contact!.email!,
- from: user.data.email,
- subject: `${quote.data.quoteId} from ${company.data.name}`,
- html: await renderAsync(emailTemplate),
- text: await renderAsync(emailTemplate, { plainText: true }),
- attachments: [
- {
- content: Buffer.from(file),
- filename: fileName,
- },
- ],
- companyId,
- },
- });
- } catch (err) {
- throw redirect(
- path.to.quote(id),
- await flash(request, error(err, "Failed to send email"))
- );
- }
-
- break;
- case undefined:
- case "None":
- break;
- default:
- throw new Error("Invalid notification type");
- }
-
- throw redirect(
- path.to.quote(id),
- await flash(request, success("Quote released"))
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/$id.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.tsx
deleted file mode 100644
index 95e71e0dae..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/$id.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-import {
- HStack,
- Heading,
- Menubar,
- MenubarItem,
- VStack,
- useDisclosure,
- useKeyboardShortcuts,
-} from "@carbon/react";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
-import { json, redirect } from "@remix-run/node";
-import { Outlet, useLoaderData, useParams } from "@remix-run/react";
-import { useEffect, useRef } from "react";
-import {
- Assignee,
- CustomerAvatar,
- useOptimisticAssignment,
-} from "~/components";
-import { useSupabase } from "~/lib/supabase";
-import { getLocationsList } from "~/modules/resources";
-import {
- QuotationExplorer,
- QuotationStatus,
- getQuote,
- getQuoteAssemblies,
- getQuoteExternalDocuments,
- getQuoteInternalDocuments,
- getQuoteLines,
- getQuoteMaterials,
- getQuoteOperations,
- useQuotation,
-} from "~/modules/sales";
-import ConvertToSalesOrderModal from "~/modules/sales/ui/Quotation/ConvertToSalesOrderModal";
-import QuotationReleaseModal from "~/modules/sales/ui/Quotation/QuotationReleaseModal";
-
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { useCustomers } from "~/stores";
-import type { Handle } from "~/utils/handle";
-import { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-export const handle: Handle = {
- breadcrumb: "Quotations",
- to: path.to.quotes,
-};
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {
- view: "sales",
- });
-
- const { id } = params;
- if (!id) throw new Error("Could not find id");
-
- const [
- quotation,
- quotationLines,
- quotationAssemblies,
- quotationMaterials,
- quotationOperations,
- externalDocuments,
- internalDocuments,
- locations,
- ] = await Promise.all([
- getQuote(client, id),
- getQuoteLines(client, id),
- getQuoteAssemblies(client, id),
- getQuoteMaterials(client, id),
- getQuoteOperations(client, id),
- getQuoteExternalDocuments(client, companyId, id),
- getQuoteInternalDocuments(client, companyId, id),
- getLocationsList(client, companyId),
- ]);
-
- if (quotation.error) {
- throw redirect(
- path.to.quotes,
- await flash(
- request,
- error(quotation.error, "Failed to load quotation summary")
- )
- );
- }
-
- return json({
- quotation: quotation.data,
- quotationLines: quotationLines.data ?? [],
- quotationAssemblies: quotationAssemblies.data ?? [],
- quotationMaterials: quotationMaterials.data ?? [],
- quotationOperations: quotationOperations.data ?? [],
- externalDocuments: externalDocuments.data ?? [],
- internalDocuments: internalDocuments.data ?? [],
- locations: locations.data ?? [],
- });
-}
-
-export async function action({ request }: ActionFunctionArgs) {
- throw redirect(request.headers.get("Referer") ?? request.url);
-}
-
-export default function QuotationRoute() {
- const { supabase } = useSupabase();
- const {
- quotation,
- quotationLines,
- quotationAssemblies,
- quotationMaterials,
- quotationOperations,
- } = useLoaderData<typeof loader>();
- const releaseDisclosure = useDisclosure();
- const salesOrderDisclosure = useDisclosure();
-
- const [quote, setQuote] = useQuotation();
-
- useEffect(() => {
- setQuote({
- quote: quotation,
- lines: quotationLines,
- assemblies: quotationAssemblies,
- materials: quotationMaterials,
- operations: quotationOperations,
- });
- }, [
- quotationLines,
- quotationAssemblies,
- quotationMaterials,
- quotationOperations,
- setQuote,
- quotation,
- supabase,
- ]);
-
- const { id } = useParams();
- if (!id) throw new Error("id not found");
-
- const isReleased = !["Draft"].includes(quote.quote?.status ?? "");
-
- const buttonRef = useRef<HTMLButtonElement>(null);
- useKeyboardShortcuts({
- l: (event: KeyboardEvent) => {
- event.stopPropagation();
- buttonRef.current?.click();
- },
- });
-
- const [customers] = useCustomers();
- const customer = customers.find((s) => s.id === quotation?.customerId) ?? {
- name: "",
- id: "",
- };
-
- const optimisticAssignment = useOptimisticAssignment({
- id: id,
- table: "quote",
- });
- const assignee =
- optimisticAssignment !== undefined
- ? optimisticAssignment
- : quotation?.assignee;
-
- return (
- <div className="flex h-[calc(100vh-49px)]">
- <VStack className="w-96 h-full z-40 overflow-y-scroll bg-card border-r border-border">
- <VStack
- className="bg-card border-b border-border px-4 py-2 sticky top-0 z-50"
- spacing={1}
- >
- <HStack className="justify-between w-full">
- <Heading size="h4" noOfLines={1}>
- {quote.quote?.quoteId}
- </Heading>
- {quote.quote && <QuotationStatus status={quote.quote?.status} />}
- </HStack>
- </VStack>
- <VStack className="border-b border-border px-4 py-2 text-sm">
- <HStack className="justify-between w-full">
- <span className="text-xs text-muted-foreground">Customer</span>
- <CustomerAvatar customerId={customer.id} />
- </HStack>
- </VStack>
- <VStack className="border-b border-border px-4 py-2 text-sm">
- <HStack className="justify-between w-full">
- <span className="text-xs text-muted-foreground">Assignee</span>
- <Assignee id={id} table="quote" value={assignee ?? undefined} />
- </HStack>
- </VStack>
- <QuotationExplorer />
- </VStack>
-
- <div className="flex w-full h-full">
- <div className="w-full h-full flex-1 overflow-hidden">
- <VStack
- spacing={4}
- className="h-full w-full overflow-x-hidden flex-1 p-4"
- >
- <Menubar>
- <MenubarItem asChild>
- <a
- target="_blank"
- href={path.to.file.quote(id)}
- rel="noreferrer"
- >
- Preview
- </a>
- </MenubarItem>
- <MenubarItem
- onClick={releaseDisclosure.onOpen}
- isDisabled={isReleased}
- >
- Release
- </MenubarItem>
- <MenubarItem onClick={salesOrderDisclosure.onOpen}>
- Convert
- </MenubarItem>
- </Menubar>
- <Outlet />
- </VStack>
- </div>
- </div>
- {releaseDisclosure.isOpen && (
- <QuotationReleaseModal
- quotation={quotation}
- onClose={releaseDisclosure.onClose}
- />
- )}
- {salesOrderDisclosure.isOpen && (
- <ConvertToSalesOrderModal
- quotation={quotation}
- onClose={salesOrderDisclosure.onClose}
- />
- )}
- </div>
- );
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/_layout.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/_layout.tsx
deleted file mode 100644
index 24228b8da7..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/_layout.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import type { MetaFunction } from "@remix-run/node";
-import { Outlet } from "@remix-run/react";
-import type { Handle } from "~/utils/handle";
-import { path } from "~/utils/path";
-
-export const meta: MetaFunction = () => {
- return [{ title: "Carbon | Quotation" }];
-};
-
-export const handle: Handle = {
- breadcrumb: "Sales",
- to: path.to.quotes,
- module: "sales",
-};
-
-export default function QuotationRoute() {
- return <Outlet />;
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/delete.$id.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/delete.$id.tsx
deleted file mode 100644
index f384192ea8..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/delete.$id.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import type { ActionFunctionArgs } from "@remix-run/node";
-import { redirect } from "@remix-run/node";
-import { deleteQuote } from "~/modules/sales";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { assertIsPost, notFound } 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, {
- delete: "sales",
- });
-
- const { id } = params;
- if (!id) throw notFound("id not found");
-
- const remove = await deleteQuote(client, id);
-
- if (remove.error) {
- throw redirect(
- path.to.quotes,
- await flash(request, error(remove.error, "Failed to delete quote"))
- );
- }
-
- throw redirect(path.to.quotes);
-}
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/new.tsx
deleted file mode 100644
index adff3e4c39..0000000000
--- a/apps/carbon/app/routes/x+/quote-deprecated+/new.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import { validationError, validator } from "@carbon/remix-validated-form";
-import type { ActionFunctionArgs } from "@remix-run/node";
-import { redirect } from "@remix-run/node";
-import { useUser } from "~/hooks";
-import {
- QuotationForm,
- quotationValidator,
- upsertQuote,
-} from "~/modules/sales";
-import { getNextSequence, rollbackNextSequence } from "~/modules/settings";
-import { requirePermissions } from "~/services/auth/auth.server";
-import { flash } from "~/services/session.server";
-import { setCustomFields } from "~/utils/form";
-import { assertIsPost } from "~/utils/http";
-import { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-export async function action({ request }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "sales",
- });
-
- const formData = await request.formData();
- const validation = await validator(quotationValidator).validate(formData);
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const nextSequence = await getNextSequence(client, "quote", companyId);
- if (nextSequence.error) {
- throw redirect(
- path.to.newQuote,
- await flash(
- request,
- error(nextSequence.error, "Failed to get next sequence")
- )
- );
- }
-
- const createQuotation = await upsertQuote(client, {
- ...validation.data,
- companyId,
- quoteId: nextSequence.data,
- createdBy: userId,
- customFields: setCustomFields(formData),
- });
-
- if (createQuotation.error || !createQuotation.data?.[0]) {
- // TODO: this should be done as a transaction
- await rollbackNextSequence(client, "quote", companyId);
- throw redirect(
- path.to.quotes,
- await flash(
- request,
- error(createQuotation.error, "Failed to insert quotation")
- )
- );
- }
-
- const order = createQuotation.data?.[0];
-
- throw redirect(path.to.quote(order.id!));
-}
-
-export default function QuotationNewRoute() {
- const user = useUser();
- const initialValues = {
- locationId: user.defaults.locationId,
- description: "",
- status: "Draft" as "Draft",
- };
-
- return (
- <div className="w-1/2 max-w-[600px] min-w-[420px] mx-auto pt-4">
- {/* @ts-ignore */}
- <QuotationForm initialValues={initialValues} />
- </div>
- );
-}