Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

wip, rename file and fix bug

neilk1733f889ff2636
diff --git a/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
similarity index 88%
rename from apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
rename to apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
index 19c5dcb821..bca71f3fa6 100644
--- a/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
+++ b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
@@ -8,16 +8,16 @@ import { requirePermissions } from "~/services/auth";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
- view: "purchasing",
+ view: "sales",
});
- const { quoteId } = params;
- if (!quoteId) throw new Error("Could not find quoteId");
+ const { id } = params;
+ if (!id) throw new Error("Could not find id");
const [company, quote, quoteLines] = await Promise.all([
getCompany(client),
- getQuote(client, quoteId),
- getQuoteLines(client, quoteId),
+ getQuote(client, id),
+ getQuoteLines(client, id),
]);
if (company.error) {
diff --git a/apps/carbon/app/routes/x+/quote+/$id.release.tsx b/apps/carbon/app/routes/x+/quote+/$id.release.tsx
index 12ce9d1f6f..8597e93aad 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.release.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.release.tsx
@@ -3,22 +3,17 @@ 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 {
-// getPurchaseOrder,
-// getPurchaseOrderLines,
-// getPurchaseOrderLocations,
-// getSupplierContact,
-// } from "~/modules/purchasing";
import {
getQuote,
releaseQuote,
quotationReleaseValidator,
getCustomer,
+ getQuoteLines,
+ getCustomerContact,
} from "~/modules/sales";
import { getCompany } from "~/modules/settings";
-// import { getUser } from "~/modules/users/users.server";
-// import { loader as pdfLoader } from "~/routes/file+/purchase-order+/$id[.]pdf";
-import { loader as pdfLoader } from "~/routes/file+/quote+/$quoteId[.]pdf";
+import { getUser } from "~/modules/users/users.server";
+import { loader as pdfLoader } from "~/routes/file+/quote+/$id[.]pdf";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import { assertIsPost } from "~/utils/http";
@@ -30,7 +25,7 @@ export async function action(args: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- create: "purchasing",
+ create: "sales",
role: "employee",
});
@@ -68,7 +63,7 @@ export async function action(args: ActionFunctionArgs) {
.slice(0, -5)}.pdf`;
const fileUpload = await client.storage
- .from("purchasing-external")
+ .from("quote-internal")
.upload(`${bucketName}/${fileName}`, file, {
cacheControl: `${12 * 60 * 60}`,
contentType: "application/pdf",
@@ -76,13 +71,13 @@ export async function action(args: ActionFunctionArgs) {
if (fileUpload.error) {
return redirect(
- path.to.purchaseOrder(id),
+ path.to.quote(id),
await flash(request, error(fileUpload.error, "Failed to upload file"))
);
}
} catch (err) {
return redirect(
- path.to.purchaseOrder(id),
+ path.to.quote(id),
await flash(request, error(err, "Failed to generate PDF"))
);
}
@@ -95,76 +90,51 @@ export async function action(args: ActionFunctionArgs) {
return validationError(validation.error);
}
- const { notification, customerContact } = validation.data;
+ const { notification, customerContact: customerContactId } = validation.data;
switch (notification) {
case "Email":
try {
- if (!customerContact) throw new Error("Customer contact is required");
-
- const [
- company,
- customer,
- // supplier,
- // purchaseOrder,
- // purchaseOrderLines,
- // purchaseOrderLocations,
- // buyer,
- ] = await Promise.all([
- getCompany(client),
- getCustomer(client, quote.data.customerId),
- // getSupplierContact(client, customerContact),
- // getPurchaseOrder(client, id),
- // getPurchaseOrderLines(client, id),
- // getPurchaseOrderLocations(client, id),
- // getUser(client, userId),
- ]);
-
- // if (!supplier?.data?.contact) throw new Error("Failed to get supplier contact");
+ if (!customerContactId) throw new Error("Customer contact is required");
+ console.log("===>", customerContactId);
+
+ const [company, customer, customerContact, quoteLines, user] =
+ await Promise.all([
+ getCompany(client),
+ 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 (!buyer.data) throw new Error("Failed to get user");
- // if (!purchaseOrder.data) throw new Error("Failed to get purchase order");
- // if (!purchaseOrderLocations.data) throw new Error("Failed to get purchase order locations");
-
- // const emailTemplate = PurchaseOrderEmail({
- // company: company.data,
- // purchaseOrder: purchaseOrder.data,
- // purchaseOrderLines: purchaseOrderLines.data ?? [],
- // purchaseOrderLocations: purchaseOrderLocations.data,
- // recipient: {
- // email: supplier.data.contact.email,
- // firstName: supplier.data.contact.firstName,
- // lastName: supplier.data.contact.lastName,
- // },
- // sender: {
- // email: buyer.data.email,
- // firstName: buyer.data.firstName,
- // lastName: buyer.data.lastName,
- // },
- // });
+ if (!customer.data) throw new Error("Failed to get customer");
+ if (!customerContact.data)
+ throw new Error("Failed to get customer contact");
// TODO: Update sender email
const emailTemplate = QuoteEmail({
company: company.data,
quote: quote.data,
+ quoteLines: quoteLines.data ?? [],
recipient: {
- email: customerContact,
+ email: customerContact.data.contact.email,
firstName: "Customer",
lastName: "",
},
sender: {
- email: "[email protected]",
- firstName: "Neil",
- lastName: "Kanakia",
+ email: user.data.email,
+ firstName: user.data.firstName,
+ lastName: user.data.lastName,
},
});
await triggerClient.sendEvent({
name: "resend.email",
payload: {
- to: [customer.data.contact.email],
+ to: customerContactId,
// TODO: Update from email
+ from: user.data.email,
subject: `${quote.data.quoteId} from ${company.data.name}`,
html: await renderAsync(emailTemplate),
text: await renderAsync(emailTemplate, { plainText: true }),
@@ -178,7 +148,7 @@ export async function action(args: ActionFunctionArgs) {
});
} catch (err) {
return redirect(
- path.to.purchaseOrder(id),
+ path.to.quote(id),
await flash(request, error(err, "Failed to send email"))
);
}
@@ -192,7 +162,7 @@ export async function action(args: ActionFunctionArgs) {
}
return redirect(
- path.to.purchaseOrderExternalDocuments(id),
- await flash(request, success("Purchase order released"))
+ path.to.quote(id),
+ await flash(request, success("Quote released"))
);
}
diff --git a/packages/documents/src/email/QuoteEmail.tsx b/packages/documents/src/email/QuoteEmail.tsx
index 9057509b95..cc1cb1ebd0 100644
--- a/packages/documents/src/email/QuoteEmail.tsx
+++ b/packages/documents/src/email/QuoteEmail.tsx
@@ -14,18 +14,19 @@ import {
Text,
} from "@react-email/components";
import type { Email } from "../types";
-// import {
-// getLineDescription,
-// getLineDescriptionDetails,
-// getTotal,
-// } from "../utils/purchase-order";
-// import { formatAddress } from "../utils/shared";
interface QuoteEmailProps extends Email {
quote: Database["public"]["Tables"]["quote"]["Row"];
+ quoteLines: Database["public"]["Tables"]["quoteLine"]["Row"][];
}
-const QuoteEmail = ({ company, quote, recipient, sender }: QuoteEmailProps) => {
+const QuoteEmail = ({
+ company,
+ quote,
+ quoteLines,
+ recipient,
+ sender,
+}: QuoteEmailProps) => {
const reSubject = `Re: ${quote.quoteId} from ${company.name}`;
return (
@@ -162,6 +163,15 @@ const QuoteEmail = ({ company, quote, recipient, sender }: QuoteEmailProps) => {
Purchase Order Lines
</Text>
</Section>
+ <Section>
+ {quoteLines.map((line) => (
+ <Row key={line.id}>
+ <Column>
+ <Text>{line.description}</Text>
+ </Column>
+ </Row>
+ ))}
+ </Section>
{/* <Section>
{purchaseOrderLines.map((line) => (
<Row key={line.id} style={lineRow}>