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.

Add QuotePDF functionality

neilk176fbcbb16234c
diff --git a/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx b/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
index 775f06a6f6..3437ec695e 100644
--- a/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
+++ b/apps/carbon/app/routes/file+/quote+/$quoteId[.]pdf.tsx
@@ -1,13 +1,8 @@
-import { PurchaseOrderPDF } from "@carbon/documents";
+import { QuotePDF } 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 { getQuote, getQuoteLines } from "~/modules/sales";
import { getCompany } from "~/modules/settings";
import { requirePermissions } from "~/services/auth";
@@ -19,9 +14,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { quoteId } = params;
if (!quoteId) throw new Error("Could not find quoteId");
- const [company, quote] = await Promise.all([
+ const [company, quote, quoteLines] = await Promise.all([
getCompany(client),
getQuote(client, quoteId),
+ getQuoteLines(client, quoteId),
]);
if (company.error) {
@@ -32,31 +28,16 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
logger.error(quote.error);
}
- // if (purchaseOrderLines.error) {
- // logger.error(purchaseOrderLines.error);
- // }
-
- // if (purchaseOrderLocations.error) {
- // logger.error(purchaseOrderLocations.error);
- // }
+ if (quoteLines.error) {
+ logger.error(quoteLines.error);
+ }
- // if (
- // company.error ||
- // purchaseOrder.error ||
- // purchaseOrderLines.error ||
- // purchaseOrderLocations.error
- // ) {
- // throw new Error("Failed to load purchase order");
- // }
+ if (company.error || quote.error || quoteLines.error) {
+ throw new Error("Failed to load quote");
+ }
const stream = await renderToStream(
- <PurchaseOrderPDF
- company={company.data}
- quote={quote.data}
- // purchaseOrder={purchaseOrder.data}
- // purchaseOrderLines={purchaseOrderLines.data ?? []}
- // purchaseOrderLocations={purchaseOrderLocations.data}
- />
+ <QuotePDF company={company.data} quote={quote.data} />
);
const body: Buffer = await new Promise((resolve, reject) => {
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
new file mode 100644
index 0000000000..f66e1ce15b
--- /dev/null
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -0,0 +1,304 @@
+import type { Database } from "@carbon/database";
+import { StyleSheet, Text, View } from "@react-pdf/renderer";
+
+import type { PDF } from "../types";
+// import {
+// getLineDescription,
+// getLineDescriptionDetails,
+// getLineTotal,
+// getTotal,
+// } from "../utils/purchase-order";
+// import { formatAddress } from "../utils/shared";
+import { Header, Summary, Template } from "./components";
+
+interface QuotePDFProps extends PDF {
+ quote: Database["public"]["Views"]["quotes"]["Row"];
+}
+
+// TODO: format currency based on settings
+
+const QuotePDF = ({ company, meta, quote, title = "Quote" }: QuotePDFProps) => {
+ // const {
+ // supplierName,
+ // supplierAddressLine1,
+ // supplierAddressLine2,
+ // supplierCity,
+ // supplierState,
+ // supplierPostalCode,
+ // supplierCountryCode,
+ // deliveryName,
+ // deliveryAddressLine1,
+ // deliveryAddressLine2,
+ // deliveryCity,
+ // deliveryState,
+ // deliveryPostalCode,
+ // deliveryCountryCode,
+ // dropShipment,
+ // customerName,
+ // customerAddressLine1,
+ // customerAddressLine2,
+ // customerCity,
+ // customerState,
+ // customerPostalCode,
+ // customerCountryCode,
+ // } = purchaseOrderLocations;
+
+ return (
+ <Template
+ title={title}
+ meta={{
+ author: meta?.author ?? "Carbon ERP",
+ keywords: meta?.keywords ?? "Quote",
+ subject: meta?.subject ?? "Quote",
+ }}
+ >
+ <View>
+ <Header title={title} company={company} />
+ <Summary
+ company={company}
+ items={[
+ {
+ label: "Date",
+ value: quote?.quoteDate,
+ },
+ {
+ label: "Quote #",
+ value: quote?.quoteId,
+ },
+ ]}
+ />
+ <View style={styles.row}>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Supplier</Text>
+ {/* <Text>{quote.n}</Text>
+ {/* {supplierAddressLine1 && <Text>{supplierAddressLine1}</Text>}
+ {supplierAddressLine2 && <Text>{supplierAddressLine2}</Text>} */}
+ {/* <Text>
+ {formatAddress(supplierCity, supplierState, supplierPostalCode)}
+ </Text> */}
+ {/* <Text>{supplierCountryCode}</Text> */}
+ </View>
+ {/* {dropShipment ? (
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Ship To</Text>
+ <Text>{customerName}</Text>
+ {customerAddressLine1 && <Text>{customerAddressLine1}</Text>}
+ {customerAddressLine2 && <Text>{customerAddressLine2}</Text>}
+ <Text>
+ {formatAddress(customerCity, customerState, customerPostalCode)}
+ </Text>
+ <Text>{customerCountryCode}</Text>
+ </View>
+ ) : (
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Ship To</Text>
+ <Text>{deliveryName}</Text>
+ {deliveryAddressLine1 && <Text>{deliveryAddressLine1}</Text>}
+ {deliveryAddressLine2 && <Text>{deliveryAddressLine2}</Text>}
+ <Text>
+ {formatAddress(deliveryCity, deliveryState, deliveryPostalCode)}
+ </Text>
+ <Text>{deliveryCountryCode}</Text>
+ </View>
+ )} */}
+ </View>
+ {/* <View style={styles.row}>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Supplier Order #</Text>
+ <Text>{purchaseOrder?.supplierReference}</Text>
+ </View>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Requested Date</Text>
+ <Text>{purchaseOrder?.receiptRequestedDate}</Text>
+ </View>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Promised Date</Text>
+ <Text>{purchaseOrder?.receiptPromisedDate}</Text>
+ </View>
+ </View> */}
+ {/* <View style={styles.row}>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Shipping Method</Text>
+ <Text>{purchaseOrder?.shippingMethodName}</Text>
+ </View>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Shipping Terms</Text>
+ <Text>{purchaseOrder?.shippingTermName}</Text>
+ </View>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Payment Terms</Text>
+ <Text>{purchaseOrder?.paymentTermName}</Text>
+ </View>
+ </View> */}
+ <View style={styles.table}>
+ <View style={styles.thead}>
+ <Text style={styles.tableCol1}>Description</Text>
+ <Text style={styles.tableCol2}>Qty</Text>
+ <Text style={styles.tableCol3}>Price</Text>
+ <Text style={styles.tableCol4}>Total</Text>
+ </View>
+ {/* {purchaseOrderLines.map((line) => (
+ <View style={styles.tr} key={line.id}>
+ <View style={styles.tableCol1}>
+ <Text style={{ ...styles.bold, marginBottom: 4 }}>
+ {getLineDescription(line)}
+ </Text>
+ <Text style={{ fontSize: 9, opacity: 0.8 }}>
+ {getLineDescriptionDetails(line)}
+ </Text>
+ </View>
+ <Text style={styles.tableCol2}>
+ {line.purchaseOrderLineType === "Comment"
+ ? ""
+ : line.purchaseQuantity}
+ </Text>
+ <Text style={styles.tableCol3}>
+ {line.purchaseOrderLineType === "Comment" ? null : (
+ <>
+ <Text>$</Text>
+ <Text>
+ {line.unitPrice ? line.unitPrice.toFixed(2) : ""}
+ </Text>
+ </>
+ )}
+ </Text>
+ <Text style={styles.tableCol4}>
+ {line.purchaseOrderLineType === "Comment" ? null : (
+ <>
+ <Text>$</Text>
+ <Text>{getLineTotal(line)}</Text>
+ </>
+ )}
+ </Text>
+ </View>
+ ))} */}
+ {/* <View style={styles.tfoot}>
+ <Text>Total</Text>
+ <Text style={styles.bold}>
+ <Text>$</Text>
+ <Text>{getTotal(purchaseOrderLines)}</Text>
+ </Text>
+ </View> */}
+ {quote.partIds?.map((part, index) => (
+ <View style={styles.tr} key={index}>
+ <View style={styles.tableCol1}>
+ <Text style={{ ...styles.bold, marginBottom: 4 }}>{part}</Text>
+ </View>
+ </View>
+ ))}
+ </View>
+ {quote.notes && (
+ <View style={styles.row}>
+ <View style={styles.colFull}>
+ <Text style={styles.label}>Notes</Text>
+ <Text>{quote.notes}</Text>
+ </View>
+ </View>
+ )}
+ </View>
+ </Template>
+ );
+};
+
+export default QuotePDF;
+
+const styles = StyleSheet.create({
+ row: {
+ display: "flex",
+ alignItems: "flex-start",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ marginBottom: 20,
+ width: "100%",
+ },
+ colFull: {
+ display: "flex",
+ flexDirection: "column",
+ rowGap: 3,
+ fontSize: 11,
+ fontWeight: 500,
+ width: "100%",
+ },
+ colHalf: {
+ display: "flex",
+ flexDirection: "column",
+ rowGap: 3,
+ fontSize: 11,
+ fontWeight: 500,
+ width: "50%",
+ },
+ colThird: {
+ display: "flex",
+ flexDirection: "column",
+ rowGap: 3,
+ fontSize: 11,
+ fontWeight: 500,
+ width: "32%",
+ },
+ label: {
+ color: "#7d7d7d",
+ },
+ bold: {
+ fontWeight: 700,
+ color: "#000000",
+ },
+ table: {
+ marginBottom: 20,
+ fontSize: 10,
+ },
+ thead: {
+ flexGrow: 1,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "center",
+ marginTop: "20px",
+ padding: "6px 3px 6px 3px",
+ borderTop: 1,
+ borderTopColor: "#CCCCCC",
+ borderTopStyle: "solid",
+ borderBottom: 1,
+ borderBottomColor: "#CCCCCC",
+ borderBottomStyle: "solid",
+ fontWeight: 700,
+ color: "#7d7d7d",
+ textTransform: "uppercase",
+ },
+ tr: {
+ flexGrow: 1,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ padding: "6px 3px 6px 3px",
+ borderBottom: 1,
+ borderBottomColor: "#CCCCCC",
+ },
+ tfoot: {
+ flexGrow: 1,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "center",
+ padding: "6px 3px 6px 3px",
+ borderTopStyle: "solid",
+ borderBottom: 1,
+ borderBottomColor: "#CCCCCC",
+ borderBottomStyle: "solid",
+ fontWeight: 700,
+ color: "#7d7d7d",
+ textTransform: "uppercase",
+ },
+ tableCol1: {
+ width: "50%",
+ textAlign: "left",
+ },
+ tableCol2: {
+ width: "15%",
+ textAlign: "right",
+ },
+ tableCol3: {
+ width: "15%",
+ textAlign: "right",
+ },
+ tableCol4: {
+ width: "20%",
+ textAlign: "right",
+ },
+});
diff --git a/packages/documents/src/pdf/index.ts b/packages/documents/src/pdf/index.ts
index 693633b5a1..21843f7731 100644
--- a/packages/documents/src/pdf/index.ts
+++ b/packages/documents/src/pdf/index.ts
@@ -1,4 +1,5 @@
import PurchaseOrderPDF from "./PurchaseOrderPDF";
+import QuotePDF from "./QuotePDF";
// const PurchaseOrderPDF = null;
-export { PurchaseOrderPDF };
+export { PurchaseOrderPDF, QuotePDF };
diff --git a/packages/documents/src/utils/quote.ts b/packages/documents/src/utils/quote.ts
new file mode 100644
index 0000000000..fd5de6e505
--- /dev/null
+++ b/packages/documents/src/utils/quote.ts
@@ -0,0 +1,8 @@
+// TODO: build util functions to display quote line details
+// import type { Database } from "@carbon/database";
+
+// export function getLineDescription(
+// line: Database["public"]["Views"][""]
+// ) {
+// }
+// }