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.

display customer address on pdf

neilk17766b6f287646
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 6b8d68be99..e8f02a813e 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -383,6 +383,17 @@ export async function getQuoteLines(
return client.from("quoteLine").select("*").eq("quoteId", quoteId);
}
+export async function getQuoteCustomerDetails(
+ client: SupabaseClient<Database>,
+ quoteId: string
+) {
+ return client
+ .from("quoteCustomerDetails")
+ .select("*")
+ .eq("quoteId", quoteId)
+ .single();
+}
+
export async function getQuoteLineQuantities(
client: SupabaseClient<Database>,
quoteLineId: string
diff --git a/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
index 6bd9aac65a..7c99bc4c78 100644
--- a/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
+++ b/apps/carbon/app/routes/file+/quote+/$id[.]pdf.tsx
@@ -6,7 +6,7 @@ import {
getQuote,
getQuoteLineQuantitiesByQuoteId,
getQuoteLines,
- getCustomer,
+ getQuoteCustomerDetails,
} from "~/modules/sales";
import { getCompany } from "~/modules/settings";
import { requirePermissions } from "~/services/auth";
@@ -19,13 +19,19 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { id } = params;
if (!id) throw new Error("Could not find id");
- const [company, quote, quoteLines, quoteLineQuantitiesByQuoteId] =
- await Promise.all([
- getCompany(client),
- getQuote(client, id),
- getQuoteLines(client, id),
- getQuoteLineQuantitiesByQuoteId(client, id),
- ]);
+ const [
+ company,
+ quote,
+ quoteLines,
+ quoteLineQuantitiesByQuoteId,
+ quoteLocations,
+ ] = await Promise.all([
+ getCompany(client),
+ getQuote(client, id),
+ getQuoteLines(client, id),
+ getQuoteLineQuantitiesByQuoteId(client, id),
+ getQuoteCustomerDetails(client, id),
+ ]);
if (company.error) {
logger.error(company.error);
@@ -43,19 +49,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
logger.error(quoteLineQuantitiesByQuoteId.error);
}
- const customer = await Promise.resolve(
- getCustomer(client, quote.data?.customerId ?? "")
- );
-
- if (customer.error) {
- logger.error(customer.error);
+ if (quoteLocations.error) {
+ logger.error(quoteLocations.error);
}
if (
company.error ||
- customer.error ||
- customer.error ||
quote.error ||
+ quoteLocations.error ||
quoteLines.error
) {
throw new Error("Failed to load quote");
@@ -64,10 +65,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const stream = await renderToStream(
<QuotePDF
company={company.data}
- customer={customer.data}
quote={quote.data}
quoteLines={quoteLines.data}
quoteLineQuantities={quoteLineQuantitiesByQuoteId.data}
+ quoteCustomerDetails={quoteLocations.data}
/>
);
diff --git a/packages/database/supabase/migrations/20240321035710_quote-locations.sql b/packages/database/supabase/migrations/20240321035710_quote-locations.sql
new file mode 100644
index 0000000000..0d8fedf44f
--- /dev/null
+++ b/packages/database/supabase/migrations/20240321035710_quote-locations.sql
@@ -0,0 +1,18 @@
+CREATE OR REPLACE VIEW
+ "quoteCustomerDetails"
+WITH
+ (SECURITY_INVOKER) AS
+SELECT
+ q.id as "quoteId",
+ c.name as "customerName",
+ ca."addressLine1" AS "customerAddressLine1",
+ ca."addressLine2" AS "customerAddressLine2",
+ ca."city" AS "customerCity",
+ ca."state" AS "customerState",
+ ca."postalCode" AS "customerPostalCode",
+ ca."countryCode" AS "customerCountryCode"
+FROM
+ "quote" q
+ LEFT OUTER JOIN "customer" c ON c.id = q."customerId"
+ LEFT OUTER JOIN "customerLocation" cl on cl.id = q."customerLocationId"
+ LEFT OUTER JOIN "address" ca ON ca.id = cl."addressId";
\ No newline at end of file
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index 28ef87af80..9019029a38 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -6,21 +6,21 @@ import { QuoteSummary, Template, QuoteHeader } from "./components";
import { getExtendedPrice, getUnitCost } from "../utils/quote";
interface QuotePDFProps extends PDF {
- customer: Database["public"]["Tables"]["customer"]["Row"];
quote: Database["public"]["Views"]["quotes"]["Row"];
quoteLines: Database["public"]["Tables"]["quoteLine"]["Row"][];
quoteLineQuantities:
| Database["public"]["Tables"]["quoteLineQuantity"]["Row"][]
| null;
+ quoteCustomerDetails: Database["public"]["Views"]["quoteCustomerDetails"]["Row"];
}
const QuotePDF = ({
company,
- customer,
meta,
quote,
quoteLines,
quoteLineQuantities,
+ quoteCustomerDetails,
title = "Quote",
}: QuotePDFProps) => {
return (
@@ -40,7 +40,7 @@ const QuotePDF = ({
/>
<QuoteSummary
company={company}
- customer={customer}
+ quoteCustomerDetails={quoteCustomerDetails}
items={[
{
label: "Date",
diff --git a/packages/documents/src/pdf/components/QuoteSummary.tsx b/packages/documents/src/pdf/components/QuoteSummary.tsx
index e806729e8f..b3a5424b67 100644
--- a/packages/documents/src/pdf/components/QuoteSummary.tsx
+++ b/packages/documents/src/pdf/components/QuoteSummary.tsx
@@ -1,9 +1,9 @@
import { StyleSheet, Text, View } from "@react-pdf/renderer";
-import type { Company, Customer } from "../../types";
+import type { Company, QuoteCustomerDetails } from "../../types";
type SummaryProps = {
company: Company;
- customer: Customer;
+ quoteCustomerDetails: QuoteCustomerDetails;
items: {
label: string;
value?: string | null;
@@ -58,7 +58,11 @@ const styles = StyleSheet.create({
},
});
-const QuoteSummary = ({ company, customer, items }: SummaryProps) => {
+const QuoteSummary = ({
+ company,
+ quoteCustomerDetails,
+ items,
+}: SummaryProps) => {
return (
<View style={styles.summary}>
<View style={styles.companyDetails}>
@@ -74,7 +78,18 @@ const QuoteSummary = ({ company, customer, items }: SummaryProps) => {
</View>
<View style={styles.companyDetails}>
<Text style={styles.documentSummaryLabel}>To</Text>
- <Text style={styles.companyName}>{customer.name}</Text>
+ <Text style={styles.companyName}>
+ {quoteCustomerDetails.customerName}
+ </Text>
+ {quoteCustomerDetails.customerAddressLine1 && (
+ <Text>{quoteCustomerDetails.customerAddressLine1}</Text>
+ )}
+ {quoteCustomerDetails.customerAddressLine2 && (
+ <Text>{quoteCustomerDetails.customerAddressLine2}</Text>
+ )}
+ {quoteCustomerDetails.customerCity && (
+ <Text>{quoteCustomerDetails.customerCity}</Text>
+ )}
</View>
<View style={styles.documentSummary}>
{items.map((item) => (
diff --git a/packages/documents/src/types.ts b/packages/documents/src/types.ts
index 437be2a024..60caa8eb77 100644
--- a/packages/documents/src/types.ts
+++ b/packages/documents/src/types.ts
@@ -27,4 +27,5 @@ export type Meta = {
};
export type Company = Database["public"]["Tables"]["company"]["Row"];
-export type Customer = Database["public"]["Tables"]["customer"]["Row"];
+export type QuoteCustomerDetails =
+ Database["public"]["Views"]["quoteCustomerDetails"]["Row"];