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

neilk17d815e7b43639
diff --git a/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx b/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
new file mode 100644
index 0000000000..775f06a6f6
--- /dev/null
+++ b/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
@@ -0,0 +1,75 @@
+import { PurchaseOrderPDF } from "@carbon/documents";
+import { renderToStream } from "@react-pdf/renderer";
+import { type LoaderFunctionArgs } from "@remix-run/node";
+import logger from "~/lib/logger";
+// import {
+// getPurchaseOrder,
+// getPurchaseOrderLines,
+// getPurchaseOrderLocations,
+// } from "~/modules/purchasing";
+import { getQuote } from "~/modules/sales";
+import { getCompany } from "~/modules/settings";
+import { requirePermissions } from "~/services/auth";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "purchasing",
+ });
+
+ const { quoteId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+
+ const [company, quote] = await Promise.all([
+ getCompany(client),
+ getQuote(client, quoteId),
+ ]);
+
+ if (company.error) {
+ logger.error(company.error);
+ }
+
+ if (quote.error) {
+ logger.error(quote.error);
+ }
+
+ // if (purchaseOrderLines.error) {
+ // logger.error(purchaseOrderLines.error);
+ // }
+
+ // if (purchaseOrderLocations.error) {
+ // logger.error(purchaseOrderLocations.error);
+ // }
+
+ // if (
+ // company.error ||
+ // purchaseOrder.error ||
+ // purchaseOrderLines.error ||
+ // purchaseOrderLocations.error
+ // ) {
+ // throw new Error("Failed to load purchase order");
+ // }
+
+ const stream = await renderToStream(
+ <PurchaseOrderPDF
+ company={company.data}
+ quote={quote.data}
+ // purchaseOrder={purchaseOrder.data}
+ // purchaseOrderLines={purchaseOrderLines.data ?? []}
+ // purchaseOrderLocations={purchaseOrderLocations.data}
+ />
+ );
+
+ const body: Buffer = await new Promise((resolve, reject) => {
+ const buffers: Uint8Array[] = [];
+ stream.on("data", (data) => {
+ buffers.push(data);
+ });
+ stream.on("end", () => {
+ resolve(Buffer.concat(buffers));
+ });
+ stream.on("error", reject);
+ });
+
+ const headers = new Headers({ "Content-Type": "application/pdf" });
+ return new Response(body, { status: 200, headers });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index 7b18ed906b..476c4b79af 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -198,11 +198,7 @@ export default function QuotationRoute() {
<VStack className="p-2">
<Menubar>
<MenubarItem asChild>
- <a
- target="_blank"
- href={path.to.file.quote("TODO")}
- rel="noreferrer"
- >
+ <a target="_blank" href={path.to.file.quote(id)} rel="noreferrer">
Preview
</a>
</MenubarItem>