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(purchasing): RFQ PDF and units of measure on the RFQ share pages (#2079)

Brad Barbin7546f00172cf
diff --git a/.claude/rules/pdf-generation-patterns.md b/.claude/rules/pdf-generation-patterns.md
index 4850f37cff..a7f2aab04a 100644
--- a/.claude/rules/pdf-generation-patterns.md
+++ b/.claude/rules/pdf-generation-patterns.md
@@ -19,7 +19,7 @@ print-queue/ZPL side in [printing-system.md](printing-system.md).
1. **Block-registry driven** (customizable docs + tracking label): the PDF file is
a thin driver that resolves a `documentTemplate` and renders an ordered list of
block components. Files: `SalesInvoicePDF`, `SalesOrderPDF`, `PurchaseOrderPDF`,
- `QuotePDF`, `PackingSlipPDF`, `StockTransferPDF`, `JobTravelerPDF`, `IssuePDF`,
+ `PurchaseReturnOrderPDF`, `PurchasingRfqPDF`, `QuotePDF`, `PackingSlipPDF`, `StockTransferPDF`, `JobTravelerPDF`, `IssuePDF`,
`ProductLabelPDF` (trackingLabel). Add new ones via the template engine — see
document-template-customizer.md. Every one is registered in
`pdf/preview-documents.tsx` `DOCUMENT_PDFS[type] = { Component, sample }`.
diff --git a/apps/erp/app/modules/purchasing/AGENTS.md b/apps/erp/app/modules/purchasing/AGENTS.md
index 41a18f65d9..30ab2c6f45 100644
--- a/apps/erp/app/modules/purchasing/AGENTS.md
+++ b/apps/erp/app/modules/purchasing/AGENTS.md
@@ -89,13 +89,13 @@ Each is a `defineServiceFn` const in `purchasing.server.ts`. The route calls it
- **Line dates** — every PO line keeps its own `requiredDate` (requested), `promisedDate` and `receivedDate` (delivery; receipt posting also sets it), mapped to the order's `receiptRequestedDate` / `receiptPromisedDate` / `deliveryDate` by `purchaseOrderLineDateOfOrderDate` (`purchasing.models.ts`). A new line starts on the order's requested and promised dates (`upsertPurchaseOrderLine` fills them when absent; both line forms default them). A changed order date is copied by `cascadePurchaseOrderDateToLines` (`purchasing.service.ts`) to every line whose date is empty or still the order's previous one, in the transaction that writes the delivery row; a line given its own date keeps it, and received-complete lines keep their requested and promised dates. An order whose date is not changing moves no line, so saving the Shipping card fills no empty line. The delivery date is when the goods arrived (receipt posting sets the order's), so it reaches only lines with something received (`quantityReceived > 0`). Receipt posting also overwrites a line's `receivedDate` with the posting day on every receipt, so a hand-corrected delivery date lasts until the line's next receipt. Pinned by `apps/erp/test/database/purchase-order-line-dates.test.ts`. A saved line's dates save one at a time (`updatePurchaseOrderLineDate`), outside the line form's submit: the requested date is fixed once the order is released, the promised date once the line is received complete or the order fully received, and the delivery date stays correctable. The line page edits them in the form's Dates section (`PurchaseOrderLineDateFields`); the order summary edits each line's promised date in place (`PurchaseOrderLinePromisedDate`). The line details route drops the date fields from its update, because `updatePurchaseOrderLineRestatingCompletion` sanitizes a missing field to null.
- Purchase orders — `updatePurchaseOrder` (the details form: header columns only, never `status`, refused on a finalized order), `updatePurchaseOrders` (one field of the properties panel, refused on a released order except `deliveryDate`, and `receiptPromisedDate` until the order is fully received: `isPurchaseOrderPromisedDateEditable`. A new requested, promised or delivery date also moves the order's lines — see Line dates), `updatePurchaseOrderDelivery` (the Shipping card, `$orderId.delivery.tsx`; refused on a released order; cascades its three dates the same way), `updatePurchaseOrderLineDate` (one date of one line, `$orderId.$lineId.date.tsx`; `purchaseOrderLineDateRefusal`), `deletePurchaseOrders` (Draft / Planned, or Needs Approval by its requester — `purchaseOrderDeleteRefusal` in `purchasing.models.ts`; cancels the pending approvals in the delete's transaction), `finalizePurchaseOrderAndNotify` (party contact and supplier approval rules, the approval rule or the planning bypass, then prices, the PDF document and the email; the email attaches the new PDF, the supplier interaction's files without the PDFs stored for its orders (`withoutStoredPurchaseOrderPdfs`: every order converted from one supplier quote shares the folder) and the default attachments, and the PO page's Finalize list shows the same files; an order that needs approval is never released: `submitPurchaseOrderForApproval` sets Needs Approval and opens the request in one transaction, and the approvers are notified after it commits), `decidePurchaseOrderApproval`, `reopenPurchaseOrder` (Draft / Planned, optionally as a revision; `delete` permission from a released status), `closePurchaseOrderAndApprovals`. The status route takes only Draft, Planned and Closed.
- Return orders — `updateReturnOrders`, `confirmReturnOrder` (stores the PDF; a failed PDF is a `warning`), `cancelReturnOrder`, `reopenReturnOrder`, `addReturnOrderLine` (Draft only), `updateReturnOrderLine` (post-confirm locks: `lockedReturnLineField`).
-- RFQs — `createPurchasingRfq`, `updatePurchasingRfqs`, `cancelPurchasingRfq` (cancels the linked supplier quotes), `finalizePurchasingRfqAndNotify` (`service.finalizePurchasingRfq`, ported from `finalize-purchasing-rfq`, then the emails: the RFQ and line documents, and each line item's original CAD file from `getItemModelFiles` — attached in line order while the total stays under `PO_EMAIL_ATTACHMENT_LIMIT_MB` (`splitRfqModelAttachments`), the rest signed for 7 days and listed as links in the body; a model with no known size goes as a link, one whose attachment cannot be signed falls back to a link, and one with no link either is named in the body).
+- RFQs — `createPurchasingRfq`, `updatePurchasingRfqs`, `cancelPurchasingRfq` (cancels the linked supplier quotes), `finalizePurchasingRfqAndNotify` (`service.finalizePurchasingRfq`, ported from `finalize-purchasing-rfq`, then the emails: the RFQ and line documents, and each line item's original CAD file from `getItemModelFiles` — attached in line order while the total stays under `PO_EMAIL_ATTACHMENT_LIMIT_MB` (`splitRfqModelAttachments`), the rest signed for 7 days and listed as links in the body; a model with no known size goes as a link, one whose attachment cannot be signed falls back to a link, and one with no link either is named in the body). The RFQ PDF (`file+/purchasing-rfq+/$id[.]pdf.tsx`, template type `purchasingRfq`, the header's PDF action at any status) is for suppliers who quote on paper: one row per quantity break with the line's purchase unit, and blank Unit Price, Lead Time and Total cells. Both share pages (`share+/purchasing-rfq.$id.tsx`, `share+/supplier-quote.$id.tsx`) show the line's purchase unit (else inventory unit) beside each quantity.
- Supplier quotes — `updateSupplierQuotes`, `finalizeSupplierQuoteWithLink`, `sendSupplierQuoteToSupplier`; `submitDigitalSupplierQuote` / `declineDigitalSupplierQuote` / `updateDigitalSupplierQuoteLineNotes` / `recordSupplierQuoteLinkVisit` (system only, not published: the supplier's share link runs them through `shareLinkContext`, `~/modules/service-context.server`; submit refuses a line that is not the quote's).
- Suppliers — `requestSupplierApproval`, `deactivateSupplier`, `decideSupplierApproval`.
- Planning — `orderPlannedPurchases` (suggestions to Planned POs, one per supplier per week), `updatePlanningPurchaseOrderLine`, `applyPlanningActions`, `dismissPurchasingPlanningActions`, `reopenPurchasingPlanningActions`, `assignPurchasingPlanningActions`. The route answers `{ success, message }`, the shape `usePlanningActions` (production module, shared with production planning) reads.
- Leases — see Leases.
-The PO and return order PDFs render in `purchasing.pdf.tsx` (`renderPurchaseOrderPdf`, `renderPurchaseReturnOrderPdf`) from a client, so the `file+` routes and the operations that store them render one document. Email links use `ERP_URL` (`~/utils/path`), not the request's host. Import other modules' code from the file that defines it (`*.service.ts`, `*.models.ts`); modules have no barrel.
+The PO, return order and RFQ PDFs render in `purchasing.pdf.tsx` (`renderPurchaseOrderPdf`, `renderPurchaseReturnOrderPdf`, `renderPurchasingRfqPdf`) from a client, so the `file+` routes and the operations that store them render one document. Email links use `ERP_URL` (`~/utils/path`), not the request's host. Import other modules' code from the file that defines it (`*.service.ts`, `*.models.ts`); modules have no barrel.
## Key Exports
diff --git a/apps/erp/app/modules/purchasing/purchasing.pdf.tsx b/apps/erp/app/modules/purchasing/purchasing.pdf.tsx
index f97ce2dfab..3f582565a5 100644
--- a/apps/erp/app/modules/purchasing/purchasing.pdf.tsx
+++ b/apps/erp/app/modules/purchasing/purchasing.pdf.tsx
@@ -8,7 +8,8 @@ import {
ensureFont,
getPurchaseOrderDisplayId,
PurchaseOrderPDF,
- PurchaseReturnOrderPDF
+ PurchaseReturnOrderPDF,
+ PurchasingRfqPDF
} from "@carbon/documents/pdf";
import {
collectSectionIds,
@@ -40,6 +41,8 @@ import {
getPurchaseOrderLocations,
getPurchaseReturnOrder,
getPurchaseReturnOrderLines,
+ getPurchasingRFQ,
+ getPurchasingRFQLines,
getPurchasingTerms,
getSupplier,
getSupplierLocation,
@@ -412,3 +415,138 @@ export async function renderPurchaseReturnOrderPdf(
fileName: `${company.data.name} - ${purchaseReturnOrder.data.purchaseReturnOrderId}.pdf`
};
}
+
+/** A purchasing RFQ's PDF ("Request for Quote"), for suppliers who quote on paper. */
+export async function renderPurchasingRfqPdf(
+ client: SupabaseClient<Database>,
+ {
+ companyId,
+ purchasingRfqId,
+ locale
+ }: {
+ companyId: string;
+ purchasingRfqId: string;
+ locale: string;
+ }
+): Promise<Rendered> {
+ const [
+ company,
+ companySettings,
+ purchasingRfq,
+ purchasingRfqLines,
+ terms,
+ documentTemplate
+ ] = await Promise.all([
+ getCompany(client, companyId),
+ getCompanySettings(client, companyId),
+ getPurchasingRFQ(client, purchasingRfqId),
+ getPurchasingRFQLines(client, purchasingRfqId),
+ getPurchasingTerms(client, companyId),
+ getDocumentTemplate(client, companyId, "purchasingRfq")
+ ]);
+
+ if (company.error) {
+ logger.error("Failed to load company", { error: company.error });
+ }
+
+ if (purchasingRfq.error) {
+ logger.error("Failed to load purchasingRfq", {
+ error: purchasingRfq.error
+ });
+ }
+
+ if (purchasingRfqLines.error) {
+ logger.error("Failed to load purchasingRfqLines", {
+ error: purchasingRfqLines.error
+ });
+ }
+
+ if (terms.error) {
+ logger.error("Failed to load terms", { error: terms.error });
+ }
+
+ if (
+ company.error ||
+ purchasingRfq.error ||
+ purchasingRfqLines.error ||
+ terms.error
+ ) {
+ throw new Error("Failed to load request for quote");
+ }
+
+ const templateConfig = toDocumentTemplate(
+ documentTemplate.data,
+ "purchasingRfq"
+ );
+ const showThumbnails = templateShowsThumbnails(
+ templateConfig,
+ "purchasingRfq"
+ );
+
+ const [location, thumbnailRows] = await Promise.all([
+ purchasingRfq.data.locationId
+ ? getLocation(client, purchasingRfq.data.locationId)
+ : null,
+ showThumbnails
+ ? Promise.all(
+ (purchasingRfqLines.data ?? []).map((line) =>
+ line.id && line.thumbnailPath
+ ? getBase64ImageFromSupabase(client, line.thumbnailPath).then(
+ (data) => ({ id: line.id!, data })
+ )
+ : null
+ )
+ )
+ : []
+ ]);
+
+ const thumbnails = thumbnailRows.reduce<Record<string, string | null>>(
+ (acc, thumbnail) => {
+ if (thumbnail) acc[thumbnail.id] = thumbnail.data;
+ return acc;
+ },
+ {}
+ );
+
+ const shipToAddress = location?.data
+ ? {
+ name: location.data.name,
+ addressLine1: location.data.addressLine1,
+ addressLine2: location.data.addressLine2,
+ city: location.data.city,
+ stateProvince: location.data.stateProvince,
+ postalCode: location.data.postalCode,
+ countryCode: location.data.countryCode
+ }
+ : null;
+
+ const resolved = resolveTemplate("purchasingRfq", templateConfig);
+ const sections = await resolveSections(
+ client,
+ companyId,
+ collectSectionIds(resolved)
+ );
+ await ensureFont(resolved.settings.fontFamily);
+
+ const body = await collect(
+ await renderToStream(
+ <PurchasingRfqPDF
+ company={company.data as any}
+ companySettings={companySettings.data}
+ locale={locale}
+ purchasingRfq={purchasingRfq.data}
+ purchasingRfqLines={purchasingRfqLines.data ?? []}
+ shipToAddress={shipToAddress}
+ thumbnails={thumbnails}
+ terms={(terms?.data?.purchasingTerms ?? {}) as JSONContent}
+ template={templateConfig}
+ sections={sections}
+ />
+ )
+ );
+
+ return {
+ body,
+ fileName: `${company.data.name} - ${purchasingRfq.data.rfqId}.pdf`
+ };
+}
diff --git a/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQHeader.tsx b/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQHeader.tsx
index 4a4e2b3953..69dace8371 100644
--- a/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQHeader.tsx
+++ b/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQHeader.tsx
@@ -27,6 +27,7 @@ import {
LuChevronDown,
LuCircleX,
LuEye,
+ LuFile,
LuGitCompare,
LuLoaderCircle,
LuSend,
@@ -153,6 +154,18 @@ const PurchasingRFQHeader = () => {
</RecordAction>
)}
+ <RecordAction slot="overflow">
+ <Button leftIcon={<LuFile />} variant="secondary" asChild>
+ <a
+ target="_blank"
+ href={path.to.file.purchasingRfq(rfqId)}
+ rel="noreferrer"
+ >
+ <Trans>PDF</Trans>
+ </a>
+ </Button>
+ </RecordAction>
+
{/* Share Dropdown - for Requested status with external links */}
{status === "Requested" && hasSuppliers && (
<RecordAction slot="overflow">
diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
index 164d194e77..cf8d9e5cb3 100644
--- a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
@@ -1532,7 +1532,7 @@
{"name":"settings_getCustomFieldsTables","classification":"READ","schema":"cd40ae40fad5","response":"b1e2b7dc7754","permission":"settings:view","paginates":true},
{"name":"settings_getDocumentSections","classification":"READ","schema":"31b84d65b2ac","response":"d8b65982e0d9","permission":"settings:view","paginates":false},
{"name":"settings_getDocumentTemplate","classification":"READ","schema":"2a2940399e72","response":"99cae633d7cb","permission":"settings:view","paginates":false},
- {"name":"settings_getDocumentTemplateConfig","classification":"READ","schema":"2a2940399e72","response":"586da3c785a5","permission":"settings:view","paginates":false},
+ {"name":"settings_getDocumentTemplateConfig","classification":"READ","schema":"2a2940399e72","response":"35881586657b","permission":"settings:view","paginates":false},
{"name":"settings_getEmployeeCompanies","classification":"READ","schema":"31b84d65b2ac","response":"5783a32e0f4a","permission":"settings:view","paginates":false},
{"name":"settings_getIndustries","classification":"READ","schema":"31b84d65b2ac","response":"5dcce0f224dd","permission":"settings:view","paginates":false},
{"name":"settings_getIntegration","classification":"READ","schema":"7f8214d1083f","response":"099545249106","permission":"settings:view","paginates":false},
@@ -1554,7 +1554,7 @@
{"name":"settings_removePrinterRoute","classification":"DESTRUCTIVE","schema":"3797626bd17e","response":"3797626bd17e","permission":"settings:update","paginates":false},
{"name":"settings_resolveSections","classification":"WRITE","schema":"1ddda22ecba8","response":"32e51b029d79","permission":"settings:update","paginates":false},
{"name":"settings_saveDocumentSection","classification":"WRITE","schema":"8a0f21626132","response":"d77a04e8c53e","permission":"settings:update","paginates":false},
- {"name":"settings_saveDocumentTemplate","classification":"WRITE","schema":"d7e28d85cf1d","response":"f1822dd9c8ab","permission":"settings:update","paginates":false},
+ {"name":"settings_saveDocumentTemplate","classification":"WRITE","schema":"a3a61935eea0","response":"f47f00537b3b","permission":"settings:update","paginates":false},
{"name":"settings_setIntegrationSyncEnabled","classification":"WRITE","schema":"fa07001f8501","response":"4111dc6445bb","permission":"settings:update","paginates":false},
{"name":"settings_transitionSyncOperations","classification":"WRITE","schema":"c5a1f2594d65","response":"401e1aae225f","permission":"settings:update","paginates":false},
{"name":"settings_updateAccountingSettings","classification":"WRITE","schema":"ecf0d5091645","response":"70bcf2b87ee3","permission":"settings:update","paginates":false},
diff --git a/apps/erp/app/routes/file+/purchasing-rfq+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/purchasing-rfq+/$id[.]pdf.tsx
new file mode 100644
index 0000000000..ebd1116c3b
--- /dev/null
+++ b/apps/erp/app/routes/file+/purchasing-rfq+/$id[.]pdf.tsx
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { getPreferenceHeaders } from "@carbon/utils";
+import type { LoaderFunctionArgs } from "react-router";
+import { renderPurchasingRfqPdf } from "~/modules/purchasing/purchasing.pdf";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "purchasing"
+ });
+
+ const { id } = params;
+ if (!id) throw new Error("Could not find id");
+
+ const pdf = await renderPurchasingRfqPdf(client, {
+ companyId,
+ purchasingRfqId: id,
+ locale: getPreferenceHeaders(request).locale
+ });
+
+ const headers = new Headers({
+ "Content-Type": "application/pdf",
+ "Content-Disposition": `inline; filename="${pdf.fileName}"`
+ });
+ return new Response(new Uint8Array(pdf.body), { status: 200, headers });
+}
diff --git a/apps/erp/app/routes/share+/purchasing-rfq.$id.tsx b/apps/erp/app/routes/share+/purchasing-rfq.$id.tsx
index 1d3e1e00bf..269eef6a32 100644
--- a/apps/erp/app/routes/share+/purchasing-rfq.$id.tsx
+++ b/apps/erp/app/routes/share+/purchasing-rfq.$id.tsx
@@ -127,9 +127,9 @@ const Header = ({
{rfq?.rfqId && (
<p className="text-lg text-muted-foreground">{rfq.rfqId}</p>
)}
- {rfq?.dueDate && (
+ {rfq?.expirationDate && (
<p className="text-lg text-muted-foreground">
- Due <DateTime value={rfq.dueDate} variant="date" />
+ Due <DateTime value={rfq.expirationDate} variant="date" />
</p>
)}
</div>
@@ -267,6 +267,7 @@ const LinePricing = ({ line }: { line: PurchasingRFQLine }) => {
<Tr className="whitespace-nowrap">
<Th className="w-[50px]" />
<Th className="w-2">Quantity</Th>
+ <Th className="w-[80px]">Unit</Th>
<Th className="w-[150px]">Unit Price</Th>
<Th className="w-[120px]">Lead Time</Th>
<Th className="w-[150px]">Shipping Cost</Th>
@@ -281,6 +282,10 @@ const LinePricing = ({ line }: { line: PurchasingRFQLine }) => {
<div className="w-4 h-4 border rounded" />
</Td>
<Td>{qty}</Td>
+ <Td>
+ {line.purchaseUnitOfMeasureCode ??
+ line.inventoryUnitOfMeasureCode}
+ </Td>
<Td className="text-muted-foreground">—</Td>
<Td className="text-muted-foreground">—</Td>
<Td className="text-muted-foreground">—</Td>
diff --git a/apps/erp/app/routes/share+/supplier-quote.$id.tsx b/apps/erp/app/routes/share+/supplier-quote.$id.tsx
index 9d60d4da6c..4cd4b6115f 100644
--- a/apps/erp/app/routes/share+/supplier-quote.$id.tsx
+++ b/apps/erp/app/routes/share+/supplier-quote.$id.tsx
@@ -638,6 +638,7 @@ const LinePricing = ({
<Tr className="whitespace-nowrap">
<Th className="w-[50px]" />
<Th className="w-2">Quantity</Th>
+ <Th className="w-[80px]">Unit</Th>
<Th className="w-[150px]">
<HStack spacing={4}>
<span>Unit Price</span>
@@ -706,6 +707,10 @@ const LinePricing = ({
</label>
</Td>
<Td>{qty}</Td>
+ <Td>
+ {line.purchaseUnitOfMeasureCode ??
+ line.inventoryUnitOfMeasureCode}
+ </Td>
{isSelected ? (
<>
<Td className="">
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 9ab1d58055..11208bfbbb 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -1210,6 +1210,8 @@ export const path = {
purchaseReturnOrder: (id: string) =>
generatePath(`${file}/purchase-return-order/${id}.pdf`),
+ purchasingRfq: (id: string) =>
+ generatePath(`${file}/purchasing-rfq/${id}.pdf`),
quote: (id: string) => generatePath(`${file}/quote/${id}.pdf`),
receiptLabelsPdf: (
id: string,
diff --git a/packages/documents/src/pdf/PurchasingRfqPDF.tsx b/packages/documents/src/pdf/PurchasingRfqPDF.tsx
new file mode 100644
index 0000000000..2c4cd1f923
--- /dev/null
+++ b/packages/documents/src/pdf/PurchasingRfqPDF.tsx
@@ -0,0 +1,146 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import type { Database } from "@carbon/database";
+import type { JSONContent } from "@carbon/react";
+import { Fragment } from "react";
+import type { DocumentTemplate, ResolvedSection } from "../template";
+import {
+ DEFAULT_HEADER_OPTIONS,
+ interpolateContent,
+ resolveTemplate
+} from "../template";
+import type { PDF } from "../types";
+import { resolveRegistrationLine } from "../utils/shared";
+import type {
+ PurchasingRfqAddress,
+ PurchasingRfqData,
+ PurchasingRfqPdfLine
+} from "./blocks/purchasingRfq";
+import {
+ buildPurchasingRfqVars,
+ purchasingRfqBlockRegistry
+} from "./blocks/purchasingRfq";
+import { Template } from "./components";
+
+interface PurchasingRfqPDFProps extends PDF {
+ purchasingRfq: Database["public"]["Views"]["purchasingRfqs"]["Row"];
+ purchasingRfqLines: PurchasingRfqPdfLine[];
+ /** The receiving location the supplier quotes delivery to. */
+ shipToAddress?: PurchasingRfqAddress | null;
+ /** Base64 thumbnails keyed by line id. */
+ thumbnails?: Record<string, string | null>;
+ companySettings?:
+ | Database["public"]["Tables"]["companySettings"]["Row"]
+ | null;
+ terms: JSONContent;
+ /** Stored layout. When omitted, the default RFQ layout is used. */
+ template?: DocumentTemplate | null;
+ /** Shared sections referenced by the template, keyed by id. */
+ sections?: Record<string, ResolvedSection>;
+}
+
+/**
+ * A purchasing RFQ on paper: the lines and quantity breaks the supplier
+ * prices, with blank Unit Price, Lead Time and Total cells to fill in.
+ */
+const PurchasingRfqPDF = ({
+ company,
+ companySettings,
+ meta,
+ purchasingRfq,
+ purchasingRfqLines,
+ shipToAddress,
+ thumbnails,
+ terms,
+ locale,
+ template,
+ sections = {},
+ title = "Request for Quote"
+}: PurchasingRfqPDFProps) => {
+ const { blocks, theme, settings, headerSectionId, footerSectionId } =
+ resolveTemplate("purchasingRfq", template);
+
+ const vars = buildPurchasingRfqVars({
+ purchasingRfq,
+ shipToAddress,
+ company
+ });
+
+ const registration = resolveRegistrationLine({
+ company,
+ footerSectionId,
+ sections,
+ settings,
+ vars
+ });
+
+ const headerOptions = {
+ ...DEFAULT_HEADER_OPTIONS,
+ ...(headerSectionId ? (sections[headerSectionId]?.config ?? {}) : {})
+ };
+
+ const data: PurchasingRfqData = {
+ company,
+ companySettings,
+ locale,
+ purchasingRfq,
+ purchasingRfqLines,
+ shipToAddress,
+ thumbnails,
+ terms,
+ theme,
+ sections,
+ vars,
+ headerOptions
+ };
+
+ const headerSection = headerSectionId
+ ? sections[headerSectionId]?.content
+ : undefined;
+ const footerSection = footerSectionId
+ ? sections[footerSectionId]?.content
+ : undefined;
+ const headerContent = headerSection
+ ? interpolateContent(headerSection, vars)
+ : undefined;
+ const footerContent = footerSection
+ ? interpolateContent(footerSection, vars)
+ : undefined;
+
+ const showHeader = headerSectionId !== null;
+ const showFooter = footerSectionId !== null;
+ const visibleBlocks = blocks.filter(
+ (block) => block.visible && !(block.type === "header" && !showHeader)
+ );
+
+ return (
+ <Template
+ theme={theme}
+ title={title}
+ meta={{
+ author: meta?.author ?? "Carbon",
+ keywords: meta?.keywords ?? "request for quote, rfq",
+ subject: meta?.subject ?? "Request for Quote"
+ }}
+ footerDocumentId={purchasingRfq?.rfqId}
+ footerLabel={registration.label}
+ showFooter={showFooter}
+ showPageNumbers={settings.showPageNumbers}
+ pageNumberFormat={settings.pageNumberFormat}
+ showRegistrationLine={registration.show}
+ fontFamily={settings.fontFamily}
+ headerContent={headerContent}
+ footerContent={footerContent}
+ >
+ {visibleBlocks.map((block) => {
+ const render = purchasingRfqBlockRegistry[block.type];
+ if (!render) return null;
+ return <Fragment key={block.id}>{render({ block, data })}</Fragment>;
+ })}
+ </Template>
+ );
+};
+
+export default PurchasingRfqPDF;
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/HeaderBlock.tsx b/packages/documents/src/pdf/blocks/purchasingRfq/HeaderBlock.tsx
new file mode 100644
index 0000000000..bfa1856032
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/HeaderBlock.tsx
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { Header } from "../../components";
+import type { PurchasingRfqData } from "./types";
+
+export function HeaderBlock({ data }: { data: PurchasingRfqData }) {
+ return (
+ <Header
+ company={data.company}
+ title="Request for Quote"
+ documentId={data.purchasingRfq?.rfqId}
+ locale={data.locale}
+ options={data.headerOptions}
+ />
+ );
+}
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/LineItemsBlock.tsx b/packages/documents/src/pdf/blocks/purchasingRfq/LineItemsBlock.tsx
new file mode 100644
index 0000000000..7bff686e1b
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/LineItemsBlock.tsx
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import type { JSONContent } from "@carbon/react";
+import { distinctItemText } from "@carbon/utils";
+import { Image, Text, View } from "@react-pdf/renderer";
+import {
+ DEFAULT_LINE_ITEMS_OPTIONS,
+ type LineItemsBlock as LineItemsBlockType
+} from "../../../template";
+import { Note } from "../../components";
+import { itemTextOverflowStyle } from "../itemText";
+import { useTw } from "../tw";
+import type { PurchasingRfqData, PurchasingRfqPdfLine } from "./types";
+
+/** The quantity breaks a supplier prices; a line with none asks for one. */
+function quantitiesOf(line: PurchasingRfqPdfLine): number[] {
+ return Array.isArray(line.quantity) && line.quantity.length > 0
+ ? line.quantity
+ : [1];
+}
+
+export function LineItemsBlock({
+ block,
+ data
+}: {
+ block: LineItemsBlockType;
+ data: PurchasingRfqData;
+}) {
+ const tw = useTw();
+ const { purchasingRfqLines, thumbnails, theme } = data;
+ const opts = { ...DEFAULT_LINE_ITEMS_OPTIONS, ...block.options };
+ const overflow = itemTextOverflowStyle(opts);
+ // The supplier writes the price and lead time in by hand.
+ const blank = tw("border-b border-gray-400 h-[12px] mx-2");
+
+ return (
+ <View style={tw("mb-4")}>
+ <View
+ fixed
+ style={[
+ tw("flex flex-row py-2 px-3 text-[9px] font-bold items-center"),
+ { backgroundColor: theme.accent, color: theme.accentForeground }
+ ]}
+ >
+ <Text style={tw("w-[5%] text-center")}>#</Text>
+ <Text style={tw("w-[35%]")}>Item</Text>
+ <Text style={tw("w-[12%] text-center")}>Qty</Text>
+ <Text style={tw("w-[8%] text-center")}>UOM</Text>
+ <Text style={tw("w-[14%] text-center")}>Unit Price</Text>
+ <Text style={tw("w-[12%] text-center")}>Lead Time</Text>
+ <Text style={tw("w-[14%] text-center")}>Total</Text>
+ </View>
+
+ {purchasingRfqLines.map((line, index) => {
+ const notes = (line.externalNotes ?? {}) as JSONContent;
+ const thumbnail = line.id ? thumbnails?.[line.id] : null;
+ const quantities = quantitiesOf(line);
+
+ return (
+ <View
+ key={line.id ?? index}
+ wrap={false}
+ style={[
+ tw("flex flex-col py-2 px-3 border-b border-gray-200 text-[9px]"),
+ {
+ backgroundColor:
+ opts.zebra && index % 2 === 1
+ ? "rgba(249, 250, 251, 0.6)"
+ : "transparent"
+ }
+ ]}
+ >
+ <View style={tw("flex flex-row")}>
+ <Text style={tw("w-[5%] text-center text-gray-600")}>
+ {index + 1}
+ </Text>
+ <View style={tw("w-[35%] pr-2")}>
+ <Text style={{ ...tw("text-gray-800"), ...overflow }}>
+ {line.itemReadableId ?? ""}
+ </Text>
+ {distinctItemText(line.itemReadableId, line.description) ? (
+ <Text
+ style={{
+ ...tw("text-[8px] text-gray-600 mt-0.5"),
+ ...overflow
+ }}
+ >
+ {line.description}
+ </Text>
+ ) : null}
+ {opts.showThumbnails && thumbnail ? (
+ <View style={tw("mt-1 w-16")}>
+ <Image src={thumbnail} style={tw("w-full h-auto")} />
+ </View>
+ ) : null}
+ </View>
+ <View style={tw("w-[60%] flex flex-col")}>
+ {quantities.map((quantity, qtyIndex) => (
+ <View
+ key={qtyIndex}
+ style={tw(
+ `flex flex-row items-end ${qtyIndex > 0 ? "mt-2" : ""}`
+ )}
+ >
+ <Text style={tw("w-[20%] text-center text-gray-800")}>
+ {quantity}
+ </Text>
+ <Text style={tw("w-[13.33%] text-center text-gray-600")}>
+ {line.purchaseUnitOfMeasureCode ??
+ line.inventoryUnitOfMeasureCode ??
+ ""}
+ </Text>
+ <View style={tw("w-[23.33%]")}>
+ <View style={blank} />
+ </View>
+ <View style={tw("w-[20%]")}>
+ <View style={blank} />
+ </View>
+ <View style={tw("w-[23.33%]")}>
+ <View style={blank} />
+ </View>
+ </View>
+ ))}
+ </View>
+ </View>
+ {Object.keys(notes).length > 0 ? (
+ <View style={tw("mt-1 pl-[5%] text-[8px] text-gray-600")}>
+ <Note content={notes} />
+ </View>
+ ) : null}
+ </View>
+ );
+ })}
+ </View>
+ );
+}
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/NotesBlock.tsx b/packages/documents/src/pdf/blocks/purchasingRfq/NotesBlock.tsx
new file mode 100644
index 0000000000..c7ffd151dc
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/NotesBlock.tsx
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import type { JSONContent } from "@carbon/react";
+import { Text, View } from "@react-pdf/renderer";
+import { Note } from "../../components";
+import { useTw } from "../tw";
+import type { PurchasingRfqData } from "./types";
+
+export function NotesBlock({ data }: { data: PurchasingRfqData }) {
+ const tw = useTw();
+ const notes = (data.purchasingRfq?.notes ?? {}) as JSONContent;
+ if (Object.keys(notes).length === 0) return null;
+
+ return (
+ <View style={tw("border border-gray-200 mb-4")}>
+ <View style={tw("p-3")}>
+ <Text style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}>
+ Notes
+ </Text>
+ <View style={tw("text-[9px] text-gray-800")}>
+ <Note content={notes} />
+ </View>
+ </View>
+ </View>
+ );
+}
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/PartiesBlock.tsx b/packages/documents/src/pdf/blocks/purchasingRfq/PartiesBlock.tsx
new file mode 100644
index 0000000000..90684aeba4
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/PartiesBlock.tsx
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { formatDate } from "@carbon/utils";
+import { Text, View } from "@react-pdf/renderer";
+import { getCountryName } from "../../../utils/shared";
+import { AddressBlock } from "../../components";
+import { useTw } from "../tw";
+import type { PurchasingRfqAddress, PurchasingRfqData } from "./types";
+
+function resolveCountry(address?: PurchasingRfqAddress | null): string {
+ if (!address) return "";
+ return address.country ?? getCountryName(address.countryCode);
+}
+
+export function PartiesBlock({ data }: { data: PurchasingRfqData }) {
+ const tw = useTw();
+ const { purchasingRfq, shipToAddress, locale } = data;
+
+ return (
+ <View style={tw("border border-gray-200 mb-4")}>
+ <View style={tw("flex flex-row")}>
+ {/* LEFT — the receiving location the supplier quotes delivery to */}
+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>
+ <Text style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}>
+ Ship To
+ </Text>
+ <View style={tw("text-[9px] text-gray-800")}>
+ <AddressBlock
+ name={data.company?.name}
+ addressLine1={shipToAddress?.addressLine1}
+ addressLine2={shipToAddress?.addressLine2}
+ city={shipToAddress?.city}
+ stateProvince={shipToAddress?.stateProvince}
+ postalCode={shipToAddress?.postalCode}
+ country={resolveCountry(shipToAddress)}
+ />
+ </View>
+ </View>
+
+ {/* RIGHT — request details */}
+ <View style={tw("w-1/2 p-3")}>
+ <Text style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}>
+ Request Details
+ </Text>
+ <View style={tw("text-[9px] text-gray-800")}>
+ {purchasingRfq?.rfqId ? (
+ <Text>RFQ Number: {purchasingRfq.rfqId}</Text>
+ ) : null}
+ {purchasingRfq?.rfqDate ? (
+ <Text>
+ Date: {formatDate(purchasingRfq.rfqDate, undefined, locale)}
+ </Text>
+ ) : null}
+ {purchasingRfq?.expirationDate ? (
+ <Text>
+ Quote Due:{" "}
+ {formatDate(purchasingRfq.expirationDate, undefined, locale)}
+ </Text>
+ ) : null}
+ </View>
+ </View>
+ </View>
+ </View>
+ );
+}
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/TermsBlock.tsx b/packages/documents/src/pdf/blocks/purchasingRfq/TermsBlock.tsx
new file mode 100644
index 0000000000..2436c5c541
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/TermsBlock.tsx
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { Text, View } from "@react-pdf/renderer";
+import type { TermsBlock as TermsBlockType } from "../../../template";
+import { Note } from "../../components";
+import { hasContent, resolveTerms } from "../resolveTerms";
+import { useTw } from "../tw";
+import type { PurchasingRfqData } from "./types";
+
+export function TermsBlock({
+ block,
+ data
+}: {
+ block: TermsBlockType;
+ data: PurchasingRfqData;
+}) {
+ const tw = useTw();
+ const { theme, vars } = data;
+ const terms = resolveTerms(block, data.terms, vars);
+ if (!hasContent(terms)) return null;
+
+ return (
+ <View break>
+ <View style={tw("border-b border-gray-400 mb-3 pb-2 mt-2")}>
+ <Text
+ style={[
+ tw("text-[14px] font-bold uppercase tracking-wide"),
+ { color: theme.accent }
+ ]}
+ >
+ Terms & Conditions
+ </Text>
+ </View>
+ <Note content={terms!} />
+ </View>
+ );
+}
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/index.ts b/packages/documents/src/pdf/blocks/purchasingRfq/index.ts
new file mode 100644
index 0000000000..7caa3591e9
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/index.ts
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+export { purchasingRfqBlockRegistry } from "./registry";
+export type {
+ BlockRenderer,
+ PurchasingRfqAddress,
+ PurchasingRfqData,
+ PurchasingRfqPdfLine
+} from "./types";
+export { buildPurchasingRfqVars } from "./vars";
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/registry.tsx b/packages/documents/src/pdf/blocks/purchasingRfq/registry.tsx
new file mode 100644
index 0000000000..dffd65dfee
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/registry.tsx
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import type { DocumentBlockType } from "../../../template";
+import { CustomFieldBlock } from "../CustomFieldBlock";
+import { extensionBlocks } from "../extensionRegistry";
+import { HeaderBlock } from "./HeaderBlock";
+import { LineItemsBlock } from "./LineItemsBlock";
+import { NotesBlock } from "./NotesBlock";
+import { PartiesBlock } from "./PartiesBlock";
+import { TermsBlock } from "./TermsBlock";
+import type { BlockRenderer } from "./types";
+
+/** Block-type → renderer for the purchasing RFQ (request for quote). */
+export const purchasingRfqBlockRegistry: Partial<
+ Record<DocumentBlockType, BlockRenderer>
+> = {
+ ...extensionBlocks,
+ header: ({ data }) => <HeaderBlock data={data} />,
+ parties: ({ data }) => <PartiesBlock data={data} />,
+ notes: ({ data }) => <NotesBlock data={data} />,
+ lineItems: ({ block, data }) =>
+ block.type === "lineItems" ? (
+ <LineItemsBlock block={block} data={data} />
+ ) : null,
+ terms: ({ block, data }) =>
+ block.type === "terms" ? <TermsBlock block={block} data={data} /> : null,
+ customField: ({ block, data }) =>
+ block.type === "customField" ? (
+ <CustomFieldBlock
+ block={block}
+ customFields={
+ (data.purchasingRfq?.customFields ?? {}) as Record<string, unknown>
+ }
+ />
+ ) : null
+};
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/types.ts b/packages/documents/src/pdf/blocks/purchasingRfq/types.ts
new file mode 100644
index 0000000000..9fd6641cf1
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/types.ts
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import type { Database } from "@carbon/database";
+import type { JSONContent } from "@carbon/react";
+import type {
+ DocumentBlock,
+ DocumentTheme,
+ HeaderOptions,
+ ResolvedSection
+} from "../../../template";
+import type { Company, CompanySettings } from "../../../types";
+
+export type PurchasingRfqPdfLine =
+ Database["public"]["Views"]["purchasingRfqLines"]["Row"];
+
+/**
+ * A party/address for the parties block. Pass a resolved display `country`
+ * when known; renderers fall back to mapping `countryCode`.
+ */
+export interface PurchasingRfqAddress {
+ name?: string | null;
+ addressLine1?: string | null;
+ addressLine2?: string | null;
+ city?: string | null;
+ stateProvince?: string | null;
+ postalCode?: string | null;
+ country?: string | null;
+ countryCode?: string | null;
+}
+
+/** Everything a purchasing RFQ block renderer might need. */
+export interface PurchasingRfqData {
+ company: Company;
+ companySettings?: CompanySettings | null;
+ locale: string;
+ purchasingRfq: Database["public"]["Views"]["purchasingRfqs"]["Row"];
+ purchasingRfqLines: PurchasingRfqPdfLine[];
+ /** The receiving location the supplier quotes delivery to. */
+ shipToAddress?: PurchasingRfqAddress | null;
+ /** Base64 thumbnails keyed by line id. */
+ thumbnails?: Record<string, string | null>;
+ terms: JSONContent;
+ theme: DocumentTheme;
+ sections: Record<string, ResolvedSection>;
+ vars: Record<string, string>;
+ headerOptions: HeaderOptions;
+}
+
+export type BlockRenderer = (args: {
+ block: DocumentBlock;
+ data: PurchasingRfqData;
+}) => JSX.Element | null;
diff --git a/packages/documents/src/pdf/blocks/purchasingRfq/vars.ts b/packages/documents/src/pdf/blocks/purchasingRfq/vars.ts
new file mode 100644
index 0000000000..c53173cd71
--- /dev/null
+++ b/packages/documents/src/pdf/blocks/purchasingRfq/vars.ts
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import type { PurchasingRfqData } from "./types";
+
+/**
+ * Merge-field variable map for a purchasing RFQ. Tokens mirror
+ * `PURCHASING_RFQ_MERGE_FIELDS` in template/merge.ts.
+ */
+export function buildPurchasingRfqVars(
+ data: Pick<PurchasingRfqData, "purchasingRfq" | "shipToAddress" | "company">
+): Record<string, string> {
+ const rfq = data.purchasingRfq;
+ const str = (v: unknown): string => (v == null ? "" : String(v));
+
+ return {
+ "rfq.number": str(rfq?.rfqId),
+ "rfq.date": str(rfq?.rfqDate),
+ "rfq.dueDate": str(rfq?.expirationDate),
+ "rfq.location": str(data.shipToAddress?.name ?? rfq?.locationName),
+ "company.name": str(data.company?.name),
+ "company.city": str(data.company?.city),
+ "company.country": str(data.company?.countryCode),
+ "company.taxId": str(data.company?.taxId),
+ "company.eori": str(data.company?.eori),
+ "company.vatNumber": str(data.company?.vatNumber),
+ "company.registrationNumber": str(data.company?.registrationNumber)
+ };
+}
diff --git a/packages/documents/src/pdf/index.ts b/packages/documents/src/pdf/index.ts
index 19d2d8db08..e048d168ee 100644
--- a/packages/documents/src/pdf/index.ts
+++ b/packages/documents/src/pdf/index.ts
@@ -19,6 +19,7 @@ import PackingSlipPDF from "./PackingSlipPDF";
import ProductLabelPDF from "./ProductLabelPDF";
import PurchaseOrderPDF from "./PurchaseOrderPDF";
import PurchaseReturnOrderPDF from "./PurchaseReturnOrderPDF";
+import PurchasingRfqPDF from "./PurchasingRfqPDF";
import { DOCUMENT_PDFS } from "./preview-documents";
import { SAMPLE_PURCHASE_RETURN_ORDER } from "./purchaseReturnOrder.samples";
import QuotePDF from "./QuotePDF";
@@ -49,6 +50,7 @@ export {
ProductLabelPDF,
PurchaseOrderPDF,
PurchaseReturnOrderPDF,
+ PurchasingRfqPDF,
QuotePDF,
registerDocumentFonts,
SAMPLE_ISSUE,
diff --git a/packages/documents/src/pdf/preview-documents.tsx b/packages/documents/src/pdf/preview-documents.tsx
index dd2d94c4a7..a732b7e0fb 100644
--- a/packages/documents/src/pdf/preview-documents.tsx
+++ b/packages/documents/src/pdf/preview-documents.tsx
@@ -12,9 +12,11 @@ import PackingSlipPDF from "./PackingSlipPDF";
import ProductLabelPDF from "./ProductLabelPDF";
import PurchaseOrderPDF from "./PurchaseOrderPDF";
import PurchaseReturnOrderPDF from "./PurchaseReturnOrderPDF";
+import PurchasingRfqPDF from "./PurchasingRfqPDF";
import { SAMPLE_PACKING_SLIP } from "./packingSlip.samples";
import { SAMPLE_PURCHASE_ORDER } from "./purchaseOrder.samples";
import { SAMPLE_PURCHASE_RETURN_ORDER } from "./purchaseReturnOrder.samples";
+import { SAMPLE_PURCHASING_RFQ } from "./purchasingRfq.samples";
import QuotePDF from "./QuotePDF";
import { SAMPLE_QUOTE } from "./quote.samples";
import SalesInvoicePDF from "./SalesInvoicePDF";
@@ -49,6 +51,10 @@ export const DOCUMENT_PDFS: Record<DocumentTemplateType, PreviewEntry> = {
Component: PurchaseReturnOrderPDF,
sample: SAMPLE_PURCHASE_RETURN_ORDER
},
+ purchasingRfq: {
+ Component: PurchasingRfqPDF,
+ sample: SAMPLE_PURCHASING_RFQ
+ },
quote: { Component: QuotePDF, sample: SAMPLE_QUOTE },
packingSlip: { Component: PackingSlipPDF, sample: SAMPLE_PACKING_SLIP },
stockTransfer: {
diff --git a/packages/documents/src/pdf/purchasingRfq.samples.ts b/packages/documents/src/pdf/purchasingRfq.samples.ts
new file mode 100644
index 0000000000..6de3b8cca4
--- /dev/null
+++ b/packages/documents/src/pdf/purchasingRfq.samples.ts
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+/**
+ * Sample data for previewing the purchasing RFQ template. Cast to `any` — it
+ * only needs the fields the blocks read.
+ */
+export const SAMPLE_PURCHASING_RFQ = {
+ company: {
+ id: "sample",
+ name: "Acme Manufacturing Co.",
+ addressLine1: "1 Industrial Way",
+ addressLine2: null,
+ city: "Detroit",
+ stateProvince: "MI",
+ postalCode: "48201",
+ countryCode: "US",
+ baseCurrencyCode: "USD",
+ logoLight: null,
+ logoLightIcon: null,
+ logoWatermark: null,
+ eori: null,
+ registrationNumber: null
+ },
+ purchasingRfq: {
+ rfqId: "PRFQ000012",
+ rfqDate: "2026-06-01",
+ expirationDate: "2026-06-15",
+ locationName: "Headquarters",
+ notes: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [
+ {
+ type: "text",
+ text: "Please quote each quantity break and include freight to our dock."
+ }
+ ]
+ }
+ ]
+ }
+ },
+ purchasingRfqLines: [
+ {
+ id: "line-1",
+ itemReadableId: "A500-RECTTUBE-1.5X3X.188",
+ description: 'A500 Gr B steel rectangular tube, 1.5" x 3" x .188"',
+ quantity: [18500, 73900, 922800],
+ purchaseUnitOfMeasureCode: "LB",
+ externalNotes: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [{ type: "text", text: "Mill certs required." }]
+ }
+ ]
+ }
+ },
+ {
+ id: "line-2",
+ itemReadableId: "SCREW-M8-40",
+ description: "Hex Cap Screw, M8 x 40",
+ quantity: [500, 2000],
+ purchaseUnitOfMeasureCode: "EA",
+ externalNotes: null
+ }
+ ],
+ shipToAddress: {
+ name: "Headquarters",
+ addressLine1: "1 Industrial Way",
+ city: "Detroit",
+ stateProvince: "MI",
+ postalCode: "48201",
+ countryCode: "US"
+ },
+ thumbnails: {},
+ terms: {},
+ locale: "en-US"
+};
diff --git a/packages/documents/src/template/defaults.ts b/packages/documents/src/template/defaults.ts
index a3a10c8298..6d39f570a2 100644
--- a/packages/documents/src/template/defaults.ts
+++ b/packages/documents/src/template/defaults.ts
@@ -376,6 +376,20 @@ function returnOrderBlocks(): DocumentBlock[] {
];
}
+/**
+ * Layout for a purchasing RFQ: no summary block — nothing is priced yet, the
+ * supplier fills the line-items table in.
+ */
+function rfqBlocks(): DocumentBlock[] {
+ return [
+ { id: "header", type: "header", visible: true },
+ { id: "parties", type: "parties", visible: true },
+ { id: "notes", type: "notes", visible: true },
+ { id: "lineItems", type: "lineItems", visible: true },
+ { id: "terms", type: "terms", visible: true }
+ ];
+}
+
/** Standard layout for a fulfillment document (packing slip): no summary. */
function fulfillmentBlocks(): DocumentBlock[] {
return [
@@ -521,6 +535,15 @@ export const DEFAULT_TEMPLATES: Record<DocumentTemplateType, DocumentTemplate> =
headerSectionId: BUILT_IN_SECTION_IDS.header,
footerSectionId: BUILT_IN_SECTION_IDS.footer
},
+ purchasingRfq: {
+ formatVersion: CURRENT_TEMPLATE_FORMAT_VERSION,
+ documentType: "purchasingRfq",
+ blocks: rfqBlocks(),
+ theme: { ...DEFAULT_THEME },
+ settings: { ...DEFAULT_DOCUMENT_SETTINGS },
+ headerSectionId: BUILT_IN_SECTION_IDS.header,
+ footerSectionId: BUILT_IN_SECTION_IDS.footer
+ },
quote: {
formatVersion: CURRENT_TEMPLATE_FORMAT_VERSION,
documentType: "quote",
@@ -767,6 +790,13 @@ export const DOCUMENT_CATALOG: DocumentCatalogEntry[] = [
supported: true,
themeColors: "full"
},
+ {
+ type: "purchasingRfq",
+ label: "Request for Quote",
+ group: "Purchasing",
+ supported: true,
+ themeColors: "full"
+ },
{
type: "purchaseOrder",
label: "Purchase Order",
diff --git a/packages/documents/src/template/merge.ts b/packages/documents/src/template/merge.ts
index c5087f5e08..68c815e734 100644
--- a/packages/documents/src/template/merge.ts
+++ b/packages/documents/src/template/merge.ts
@@ -187,6 +187,14 @@ const PURCHASE_RETURN_ORDER_MERGE_FIELDS: MergeField[] = [
...COMPANY_MERGE_FIELDS
];
+const PURCHASING_RFQ_MERGE_FIELDS: MergeField[] = [
+ { token: "rfq.number", label: "RFQ Number", group: "RFQ" },
+ { token: "rfq.date", label: "RFQ Date", group: "RFQ" },
+ { token: "rfq.dueDate", label: "Due Date", group: "RFQ" },
+ { token: "rfq.location", label: "Receiving Location", group: "RFQ" },
+ ...COMPANY_MERGE_FIELDS
+];
+
const QUOTE_MERGE_FIELDS: MergeField[] = [
{ token: "quote.number", label: "Quote Number", group: "Quote" },
{ token: "quote.revision", label: "Revision", group: "Quote" },
@@ -266,6 +274,7 @@ export const MERGE_FIELDS: Record<string, MergeField[]> = {
salesReturnOrder: SALES_RETURN_ORDER_MERGE_FIELDS,
purchaseOrder: PURCHASE_ORDER_MERGE_FIELDS,
purchaseReturnOrder: PURCHASE_RETURN_ORDER_MERGE_FIELDS,
+ purchasingRfq: PURCHASING_RFQ_MERGE_FIELDS,
quote: QUOTE_MERGE_FIELDS,
packingSlip: PACKING_SLIP_MERGE_FIELDS,
stockTransfer: STOCK_TRANSFER_MERGE_FIELDS,
diff --git a/packages/documents/src/template/schema.ts b/packages/documents/src/template/schema.ts
index d5c9bfaf92..8f0e0c161b 100644
--- a/packages/documents/src/template/schema.ts
+++ b/packages/documents/src/template/schema.ts
@@ -404,6 +404,7 @@ export const documentTemplateTypeSchema = z.enum([
"salesReturnOrder",
"purchaseOrder",
"purchaseReturnOrder",
+ "purchasingRfq",
"quote",
"packingSlip",
"stockTransfer",
@@ -423,6 +424,7 @@ export const REGISTRATION_LINE_DOCUMENT_TYPES: DocumentTemplateType[] = [
"salesReturnOrder",
"purchaseOrder",
"purchaseReturnOrder",
+ "purchasingRfq",
"quote",
"packingSlip"
];