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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: preview quote pdf
Brad Barbinc9c3f477b81d
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex e0c464e951..f820a6c84a 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -617,7 +617,7 @@ export async function getQuoteLinePricesByQuoteId(.from("quoteLinePrice").select("*").eq("quoteId", quoteId)- .order("createdAt");+ .order("quoteLineId", { ascending: true });}export async function getQuoteMaterials(diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsxindex a5a9022f85..e4b84f4010 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx@@ -1,16 +1,7 @@-import {- Badge,- Button,- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuTrigger,- HStack,- Heading,-} from "@carbon/react";+import { Badge, Button, HStack, Heading } from "@carbon/react";import { useParams } from "@remix-run/react";-import { LuCheckCheck, LuChevronDown, LuEye } from "react-icons/lu";+import { LuCheckCheck, LuEye } from "react-icons/lu";import { RiProgress4Line } from "react-icons/ri";import { Assignee, useOptimisticAssignment } from "~/components";@@ -51,10 +42,16 @@ const QuoteHeader = () => {value={assignee ?? ""}className="h-8"/>- <Button leftIcon={<LuEye />} variant="secondary">- Preview+ <Button leftIcon={<LuEye />} variant="secondary" asChild>+ <a+ target="_blank"+ href={path.to.file.quote(quoteId)}+ rel="noreferrer"+ >+ Preview+ </a></Button>- <DropdownMenu>+ {/* <DropdownMenu><DropdownMenuTrigger><Button rightIcon={<LuChevronDown />} variant="secondary">Actions@@ -65,7 +62,7 @@ const QuoteHeader = () => {<DropdownMenuItem>Print</DropdownMenuItem><DropdownMenuItem>Export</DropdownMenuItem></DropdownMenuContent>- </DropdownMenu>+ </DropdownMenu> */}<Button leftIcon={<LuCheckCheck />}>Send</Button></HStack></HStack>diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsxindex f948b4064b..af4a1608c7 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx@@ -233,12 +233,6 @@ const QuoteLineForm = ({}}/>- <Input name="customerPartId" label="Customer Part ID" />- <Input- name="customerPartRevision"- label="Customer Part Revision"- />-<Selectname="status"label="Line Status"@@ -248,6 +242,12 @@ const QuoteLineForm = ({}))}/>+ <Input name="customerPartId" label="Customer Part ID" />+ <Input+ name="customerPartRevision"+ label="Customer Part Revision"+ />+<CustomFormFields table="quoteLine" /></div><div className="flex gap-y-4">diff --git a/apps/carbon/app/routes/_public+/refresh-session.tsx b/apps/carbon/app/routes/_public+/refresh-session.tsxindex 5016fef9bf..9b7f008545 100644--- a/apps/carbon/app/routes/_public+/refresh-session.tsx+++ b/apps/carbon/app/routes/_public+/refresh-session.tsx@@ -1,5 +1,5 @@import type { ActionFunctionArgs } from "@remix-run/node";-import { json } from "@remix-run/node";+import { json, redirect } from "@remix-run/node";import { useNavigate } from "@remix-run/react";import {@@ -9,7 +9,10 @@ import {import { assertIsPost } from "~/utils/http";import { path } from "~/utils/path";-// this is just for supabase provider refresh+export async function loader() {+ throw redirect(path.to.authenticatedRoot);+}+export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);diff --git a/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsxindex ed36b021fd..5cfa613810 100644--- a/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx+++ b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx@@ -5,6 +5,7 @@ import logger from "~/lib/logger";import {getQuote,getQuoteCustomerDetails,+ getQuoteLinePricesByQuoteId,getQuoteLines,} from "~/modules/sales";import { getCompany } from "~/modules/settings";@@ -18,12 +19,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find id");- const [company, quote, quoteLines, quoteLocations] = await Promise.all([- getCompany(client, companyId),- getQuote(client, id),- getQuoteLines(client, id),- getQuoteCustomerDetails(client, id),- ]);+ const [company, quote, quoteLines, quoteLinePrices, quoteLocations] =+ await Promise.all([+ getCompany(client, companyId),+ getQuote(client, id),+ getQuoteLines(client, id),+ getQuoteLinePricesByQuoteId(client, id),+ getQuoteCustomerDetails(client, id),+ ]);if (company.error) {logger.error(company.error);@@ -37,6 +40,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {logger.error(quoteLines.error);}+ if (quoteLinePrices.error) {+ logger.error(quoteLinePrices.error);+ }+if (quoteLocations.error) {logger.error(quoteLocations.error);}@@ -50,6 +57,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {company={company.data}quote={quote.data}quoteLines={quoteLines.data ?? []}+ quoteLinePrices={quoteLinePrices.data ?? []}quoteCustomerDetails={quoteLocations.data}/>);diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsxindex 08c9825436..668a70bd37 100644--- a/packages/documents/src/pdf/QuotePDF.tsx+++ b/packages/documents/src/pdf/QuotePDF.tsx@@ -1,15 +1,9 @@import type { Database } from "@carbon/database";-import type { JSONContent } from "@carbon/react";-import { generateHTML } from "@carbon/react";import { getLocalTimeZone, today } from "@internationalized/date";import { StyleSheet, Text, View } from "@react-pdf/renderer";import type { PDF } from "../types";-import {- getLineDescription,- getLineDescriptionDetails,- getTotal,-} from "../utils/quote";+import { getLineDescription, getLineDescriptionDetails } from "../utils/quote";import { formatAddress } from "../utils/shared";import { Header, Summary, Template } from "./components";@@ -17,6 +11,7 @@ interface QuotePDFProps extends PDF {quote: Database["public"]["Views"]["quotes"]["Row"];quoteLines: Database["public"]["Views"]["quoteLines"]["Row"][];quoteCustomerDetails: Database["public"]["Views"]["quoteCustomerDetails"]["Row"];+ quoteLinePrices: Database["public"]["Tables"]["quoteLinePrice"]["Row"][];}// TODO: format currency based on settings@@ -30,6 +25,7 @@ const QuotePDF = ({meta,quote,quoteLines,+ quoteLinePrices,quoteCustomerDetails,title = "Quote",}: QuotePDFProps) => {@@ -43,6 +39,16 @@ const QuotePDF = ({customerCountryCode,} = quoteCustomerDetails;+ const pricesByLine = quoteLinePrices.reduce<+ Record<string, Database["public"]["Tables"]["quoteLinePrice"]["Row"][]>+ >((acc, price) => {+ if (!acc[price.quoteLineId]) {+ acc[price.quoteLineId] = [];+ }+ acc[price.quoteLineId].push(price);+ return acc;+ }, {});+return (<Templatetitle={title}@@ -56,23 +62,37 @@ const QuotePDF = ({<Header title={title} company={company} /><Summarycompany={company}- items={[- {- label: "Quote Date",- value: today(getLocalTimeZone()).toString(),- },- {- label: "Expires",- value: quote?.expirationDate ?? "",- },- {- label: "Quote #",- value: quote?.quoteId,- },- ]}+ items={+ quote.expirationDate+ ? [+ {+ label: "Date",+ value: today(getLocalTimeZone()).toString(),+ },+ {+ label: "Expires",+ value: quote?.expirationDate ?? "",+ },+ {+ label: "Quote #",+ value: quote?.quoteId,+ },+ ]+ : [+ {+ label: "Date",+ value: today(getLocalTimeZone()).toString(),+ },++ {+ label: "Quote #",+ value: quote?.quoteId,+ },+ ]+ }/><View style={styles.row}>- <View style={styles.colThird}>+ <View style={{ ...styles.colThird, ...styles.header }}><Text style={styles.label}>Supplier</Text><Text>{customerName}</Text>{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}@@ -86,57 +106,57 @@ 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.tableCol3}>Lead Time</Text>- <Text style={styles.tableCol4}>Total</Text>+ <View style={styles.rowThird}>+ <Text style={styles.tableCol1}>Description</Text>+ </View>+ <View style={styles.rowTwoThirds}>+ <Text style={styles.tableCol2}>Qty</Text>+ <Text style={styles.tableCol3}>Price</Text>+ <Text style={styles.tableCol3}>Lead Time</Text>+ <Text style={styles.tableCol4}>Total</Text>+ </View></View>{quoteLines.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 style={styles.rowThird}>+ <View style={styles.tableCol1}>+ <Text style={{ ...styles.bold, marginBottom: 4 }}>+ {getLineDescription(line)}+ </Text>+ <Text style={{ fontSize: 9, opacity: 0.8 }}>+ {getLineDescriptionDetails(line)}+ </Text>+ </View>+ </View>+ <View style={styles.colTwoThirds}>+ {line.quantity.map((quantity) => {+ const prices = pricesByLine[line.id] ?? [];+ const price = prices.find(+ (price) => price.quantity === quantity+ );+ const netPrice =+ price?.unitPrice *+ (1 - (price?.discountPercent ?? 0) / 100);++ return (+ <View key={quantity} style={styles.row}>+ <Text style={styles.tableCol2}>{quantity}</Text>+ <Text style={styles.tableCol3}>+ {netPrice ? formatter.format(netPrice) : "-"}+ </Text>+ <Text style={styles.tableCol3}>+ {price ? `${price.leadTime} days` : "-"}+ </Text>+ <Text style={styles.tableCol4}>+ {netPrice ? formatter.format(netPrice * quantity) : "-"}+ </Text>+ </View>+ );+ })}</View>- {/* <Text style={styles.tableCol2}>{line.pricingQuantity}</Text>- <Text style={styles.tableCol3}>- <Text>- {line.pricingQuantity- ? formatter.format(- (line.pricingExtendedPrice ?? 0) / line.pricingQuantity- )- : formatter.format(0)}- </Text>- </Text>- <Text style={styles.tableCol3}>- <Text>{line.pricingLeadTime ?? 0}</Text>- </Text>- <Text style={styles.tableCol4}>- <Text>{formatter.format(line.pricingExtendedPrice ?? 0)}</Text>- </Text> */}</View>))}- <View style={styles.tfoot}>- <Text>Total</Text>- <Text style={styles.bold}>- <Text>{formatter.format(getTotal(quoteLines))}</Text>- </Text>- </View></View>- {quote?.notes && (- <View style={styles.row}>- <View style={styles.colHalf}>- <Text style={styles.label}>Notes</Text>- <Text>- {generateHTML((quote?.notes ?? {}) as JSONContent, [])}- </Text>- </View>- </View>- )}</View></Template>);@@ -145,6 +165,9 @@ const QuotePDF = ({export default QuotePDF;const styles = StyleSheet.create({+ header: {+ fontSize: 11,+ },row: {display: "flex",alignItems: "flex-start",@@ -153,32 +176,34 @@ const styles = StyleSheet.create({marginBottom: 20,width: "100%",},- colFull: {++ rowThird: {display: "flex",- flexDirection: "column",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "100%",+ flexDirection: "row",+ columnGap: 3,+ width: "33%",+ },+ rowTwoThirds: {+ display: "flex",+ flexDirection: "row",+ columnGap: 3,+ width: "66%",},- colHalf: {+ colTwoThirds: {display: "flex",flexDirection: "column",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "50%",+ columnGap: 3,+ width: "66%",},colThird: {display: "flex",flexDirection: "column",rowGap: 3,- fontSize: 11,- fontWeight: 500,width: "32%",},label: {color: "#7d7d7d",+ fontWeight: 700,},bold: {fontWeight: 700,@@ -201,10 +226,12 @@ const styles = StyleSheet.create({borderBottom: 1,borderBottomColor: "#CCCCCC",borderBottomStyle: "solid",+ fontSize: 9,fontWeight: 700,color: "#7d7d7d",textTransform: "uppercase",},+tr: {flexGrow: 1,flexDirection: "row",@@ -212,6 +239,8 @@ const styles = StyleSheet.create({padding: "6px 3px 6px 3px",borderBottom: 1,borderBottomColor: "#CCCCCC",+ fontSize: 10,+ fontWeight: 400,},tfoot: {flexGrow: 1,@@ -232,15 +261,15 @@ const styles = StyleSheet.create({textAlign: "left",},tableCol2: {- width: "15%",+ width: "20%",textAlign: "right",},tableCol3: {- width: "15%",+ width: "25%",textAlign: "right",},tableCol4: {- width: "20%",+ width: "30%",textAlign: "right",},});diff --git a/packages/documents/src/utils/quote.ts b/packages/documents/src/utils/quote.tsindex 812d1ff58c..d971a82880 100644--- a/packages/documents/src/utils/quote.ts+++ b/packages/documents/src/utils/quote.ts@@ -16,17 +16,3 @@ export function getLineDescriptionDetails() {return line?.description ? `${line.description}` : "";}--export function getTotal(- lines: Database["public"]["Views"]["quoteLines"]["Row"][]-) {- let total = 0;-- lines.forEach((line) => {- if (line?.pricingExtendedPrice) {- total += line.pricingExtendedPrice;- }- });-- return total;-}