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.

quote pdf changes

neilk1702691dc1e927
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index bdeea583e9..6b8d68be99 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -394,6 +394,17 @@ export async function getQuoteLineQuantities(
.order("createdAt");
}
+export async function getQuoteLineQuantitiesByQuoteId(
+ client: SupabaseClient<Database>,
+ quoteId: string
+) {
+ return client
+ .from("quoteLineQuantity")
+ .select("*")
+ .eq("quoteId", quoteId)
+ .order("createdAt");
+}
+
export async function getQuoteMaterials(
client: SupabaseClient<Database>,
quoteId: string
diff --git a/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
index bca71f3fa6..fb3e9593bf 100644
--- a/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
+++ b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
@@ -2,7 +2,11 @@ import { QuotePDF } from "@carbon/documents";
import { renderToStream } from "@react-pdf/renderer";
import { type LoaderFunctionArgs } from "@remix-run/node";
import logger from "~/lib/logger";
-import { getQuote, getQuoteLines } from "~/modules/sales";
+import {
+ getQuote,
+ getQuoteLineQuantitiesByQuoteId,
+ getQuoteLines,
+} from "~/modules/sales";
import { getCompany } from "~/modules/settings";
import { requirePermissions } from "~/services/auth";
@@ -14,11 +18,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { id } = params;
if (!id) throw new Error("Could not find id");
- const [company, quote, quoteLines] = await Promise.all([
- getCompany(client),
- getQuote(client, id),
- getQuoteLines(client, id),
- ]);
+ const [company, quote, quoteLines, quoteLineQuantitiesByQuoteId] =
+ await Promise.all([
+ getCompany(client),
+ getQuote(client, id),
+ getQuoteLines(client, id),
+ getQuoteLineQuantitiesByQuoteId(client, id),
+ ]);
if (company.error) {
logger.error(company.error);
@@ -32,6 +38,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
logger.error(quoteLines.error);
}
+ if (quoteLineQuantitiesByQuoteId.error) {
+ logger.error(quoteLineQuantitiesByQuoteId.error);
+ }
+
if (company.error || quote.error || quoteLines.error) {
throw new Error("Failed to load quote");
}
@@ -41,6 +51,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
company={company.data}
quote={quote.data}
quoteLines={quoteLines.data}
+ quoteLineQuantities={quoteLineQuantitiesByQuoteId.data}
/>
);
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index ce9d6ccf82..a6cb871ca6 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -2,12 +2,15 @@ import type { Database } from "@carbon/database";
import { StyleSheet, Text, View } from "@react-pdf/renderer";
import type { PDF } from "../types";
-// import { getLineDescription } from "../utils/quote";
import { Header, Summary, Template } from "./components";
+import { getExtendedPrice, getUnitCost } from "../utils/quote";
interface QuotePDFProps extends PDF {
quote: Database["public"]["Views"]["quotes"]["Row"];
quoteLines: Database["public"]["Tables"]["quoteLine"]["Row"][];
+ quoteLineQuantities:
+ | Database["public"]["Tables"]["quoteLineQuantity"]["Row"][]
+ | null;
}
const QuotePDF = ({
@@ -15,6 +18,7 @@ const QuotePDF = ({
meta,
quote,
quoteLines,
+ quoteLineQuantities,
title = "Quote",
}: QuotePDFProps) => {
return (
@@ -44,13 +48,38 @@ const QuotePDF = ({
<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>
+ <Text style={styles.tableCol2}>Lead Time</Text>
+ <Text style={styles.tableCol3}>Qty</Text>
+ <Text style={styles.tableCol4}>Cost</Text>
+ <Text style={styles.tableCol5}>Total</Text>
</View>
{quoteLines.map((line) => (
- <View style={styles.tr} key={line.id}>
- <Text key={line.id}>{line.description}</Text>
+ <View key={line.id} style={styles.tr}>
+ <View style={styles.tableCol1}>
+ <Text style={styles.bold}>{line.description}</Text>
+ <Text style={{ fontSize: 9, opacity: 0.8 }}>{line.partId}</Text>
+ </View>
+ <View style={styles.quantityTable}>
+ {quoteLineQuantities &&
+ quoteLineQuantities.map((quantity) =>
+ quantity.quoteLineId === line.id ? (
+ <View style={styles.quantityRow} key={quantity.id}>
+ <View style={styles.quantityCol1}>
+ <Text>{quantity.leadTime} days</Text>
+ </View>
+ <View style={styles.quantityCol2}>
+ <Text>{quantity.quantity}</Text>
+ </View>
+ <View style={styles.quantityCol3}>
+ <Text>{getUnitCost(quantity).toFixed(2)}</Text>
+ </View>
+ <View style={styles.quantityCol4}>
+ <Text>${getExtendedPrice(quantity).toFixed(2)}</Text>
+ </View>
+ </View>
+ ) : null
+ )}
+ </View>
</View>
))}
</View>
@@ -153,19 +182,48 @@ const styles = StyleSheet.create({
textTransform: "uppercase",
},
tableCol1: {
- width: "50%",
+ width: "40%",
textAlign: "left",
},
tableCol2: {
width: "15%",
- textAlign: "right",
+ textAlign: "left",
},
tableCol3: {
- width: "15%",
- textAlign: "right",
+ width: "12.5%",
+ textAlign: "left",
},
tableCol4: {
+ width: "12.5%",
+ textAlign: "left",
+ },
+ tableCol5: {
+ width: "15%",
+ textAlign: "left",
+ },
+ quantityTable: {
+ width: "60%",
+ },
+ quantityRow: {
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ padding: "6px 3px 6px 3px",
+ },
+ quantityCol1: {
+ width: "15%",
+ textAlign: "left",
+ },
+ quantityCol2: {
+ width: "12.5%",
+ textAlign: "left",
+ },
+ quantityCol3: {
+ width: "12.5%",
+ textAlign: "left",
+ },
+ quantityCol4: {
width: "20%",
- textAlign: "right",
+ textAlign: "left",
},
});
diff --git a/packages/documents/src/utils/quote.ts b/packages/documents/src/utils/quote.ts
index e743f06d76..ee4a36b32c 100644
--- a/packages/documents/src/utils/quote.ts
+++ b/packages/documents/src/utils/quote.ts
@@ -6,8 +6,25 @@ export function getLineDescription(
return line?.quantity;
}
-// export function getLineTotal(
-// line: Database["public"]["Tables"]["quoteLine"]["Row"]
-// ) {
-// console.log(line);
-// }
+export function getExtendedPrice(
+ line: Database["public"]["Tables"]["quoteLineQuantity"]["Row"]
+) {
+ return (
+ line?.quantity *
+ (getUnitCost(line) + line.unitTaxAmount) *
+ (1 - line.discountPercentage / 100) *
+ (1 + line.markupPercentage / 100)
+ );
+}
+
+export function getUnitCost(
+ line: Database["public"]["Tables"]["quoteLineQuantity"]["Row"]
+) {
+ return line.quantity
+ ? (line.materialCost +
+ line.laborCost +
+ line.overheadCost +
+ line.additionalCost) /
+ line.quantity
+ : 0;
+}