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: include shipments in sales pdf thumbnail settings

Brad Barbin8ef21338da33
diff --git a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx
index d68af088cc..fabd009643 100644
--- a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx
+++ b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx
@@ -22,7 +22,7 @@ import {
getSalesOrderShipment,
getSalesTerms
} from "~/modules/sales";
-import { getCompany } from "~/modules/settings";
+import { getCompany, getCompanySettings } from "~/modules/settings";
import { getBase64ImageFromSupabase } from "~/modules/shared";
import { getLocale } from "~/utils/request";
@@ -34,11 +34,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { id } = params;
if (!id) throw new Error("Could not find id");
- const [company, shipment, shipmentLines] = await Promise.all([
- getCompany(client, companyId),
- getShipment(client, id),
- getShipmentLinesWithDetails(client, id)
- ]);
+ const [company, companySettings, shipment, shipmentLines] = await Promise.all(
+ [
+ getCompany(client, companyId),
+ getCompanySettings(client, companyId),
+ getShipment(client, id),
+ getShipmentLinesWithDetails(client, id)
+ ]
+ );
if (company.error) {
console.error(company.error);
@@ -109,37 +112,41 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
throw new Error("Failed to load customer");
}
- const thumbnailPaths = shipmentLines.data?.reduce<
- Record<string, string | null>
- >((acc, line) => {
- if (line.thumbnailPath) {
- acc[line.id!] = line.thumbnailPath;
- }
- return acc;
- }, {});
-
- const thumbnails: Record<string, string | null> =
- (thumbnailPaths
- ? await Promise.all(
- Object.entries(thumbnailPaths).map(([id, path]) => {
- if (!path) {
- return null;
- }
- return getBase64ImageFromSupabase(serviceRole, path).then(
- (data) => ({
- id,
- data
- })
- );
- })
- )
- : []
- )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
- if (thumbnail) {
- acc[thumbnail.id] = thumbnail.data;
+ let thumbnails: Record<string, string | null> = {};
+
+ if (companySettings.data?.includeThumbnailsOnSalesPdfs ?? true) {
+ const thumbnailPaths = shipmentLines.data?.reduce<
+ Record<string, string | null>
+ >((acc, line) => {
+ if (line.thumbnailPath) {
+ acc[line.id!] = line.thumbnailPath;
}
return acc;
- }, {}) ?? {};
+ }, {});
+
+ thumbnails =
+ (thumbnailPaths
+ ? await Promise.all(
+ Object.entries(thumbnailPaths).map(([id, path]) => {
+ if (!path) {
+ return null;
+ }
+ return getBase64ImageFromSupabase(serviceRole, path).then(
+ (data) => ({
+ id,
+ data
+ })
+ );
+ })
+ )
+ : []
+ )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
+ if (thumbnail) {
+ acc[thumbnail.id] = thumbnail.data;
+ }
+ return acc;
+ }, {}) ?? {};
+ }
const stream = await renderToStream(
<PackingSlipPDF
@@ -224,37 +231,41 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
throw new Error("Failed to load customer");
}
- const thumbnailPaths = shipmentLines.data?.reduce<
- Record<string, string | null>
- >((acc, line) => {
- if (line.thumbnailPath) {
- acc[line.id!] = line.thumbnailPath;
- }
- return acc;
- }, {});
-
- const thumbnails: Record<string, string | null> =
- (thumbnailPaths
- ? await Promise.all(
- Object.entries(thumbnailPaths).map(([id, path]) => {
- if (!path) {
- return null;
- }
- return getBase64ImageFromSupabase(serviceRole, path).then(
- (data) => ({
- id,
- data
- })
- );
- })
- )
- : []
- )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
- if (thumbnail) {
- acc[thumbnail.id] = thumbnail.data;
+ let thumbnails: Record<string, string | null> = {};
+
+ if (companySettings.data?.includeThumbnailsOnSalesPdfs ?? true) {
+ const thumbnailPaths = shipmentLines.data?.reduce<
+ Record<string, string | null>
+ >((acc, line) => {
+ if (line.thumbnailPath) {
+ acc[line.id!] = line.thumbnailPath;
}
return acc;
- }, {}) ?? {};
+ }, {});
+
+ thumbnails =
+ (thumbnailPaths
+ ? await Promise.all(
+ Object.entries(thumbnailPaths).map(([id, path]) => {
+ if (!path) {
+ return null;
+ }
+ return getBase64ImageFromSupabase(serviceRole, path).then(
+ (data) => ({
+ id,
+ data
+ })
+ );
+ })
+ )
+ : []
+ )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
+ if (thumbnail) {
+ acc[thumbnail.id] = thumbnail.data;
+ }
+ return acc;
+ }, {}) ?? {};
+ }
const stream = await renderToStream(
<PackingSlipPDF
@@ -334,37 +345,41 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
throw new Error("Failed to load supplier");
}
- const poThumbnailPaths = shipmentLines.data?.reduce<
- Record<string, string | null>
- >((acc, line) => {
- if (line.thumbnailPath) {
- acc[line.id!] = line.thumbnailPath;
- }
- return acc;
- }, {});
-
- const poThumbnails: Record<string, string | null> =
- (poThumbnailPaths
- ? await Promise.all(
- Object.entries(poThumbnailPaths).map(([id, path]) => {
- if (!path) {
- return null;
- }
- return getBase64ImageFromSupabase(client, path).then(
- (data) => ({
- id,
- data
- })
- );
- })
- )
- : []
- )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
- if (thumbnail) {
- acc[thumbnail.id] = thumbnail.data;
+ let poThumbnails: Record<string, string | null> = {};
+
+ if (companySettings.data?.includeThumbnailsOnPurchasingPdfs ?? true) {
+ const poThumbnailPaths = shipmentLines.data?.reduce<
+ Record<string, string | null>
+ >((acc, line) => {
+ if (line.thumbnailPath) {
+ acc[line.id!] = line.thumbnailPath;
}
return acc;
- }, {}) ?? {};
+ }, {});
+
+ poThumbnails =
+ (poThumbnailPaths
+ ? await Promise.all(
+ Object.entries(poThumbnailPaths).map(([id, path]) => {
+ if (!path) {
+ return null;
+ }
+ return getBase64ImageFromSupabase(client, path).then(
+ (data) => ({
+ id,
+ data
+ })
+ );
+ })
+ )
+ : []
+ )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
+ if (thumbnail) {
+ acc[thumbnail.id] = thumbnail.data;
+ }
+ return acc;
+ }, {}) ?? {};
+ }
const poStream = await renderToStream(
<PackingSlipPDF
diff --git a/apps/erp/app/routes/x+/settings+/sales.tsx b/apps/erp/app/routes/x+/settings+/sales.tsx
index 85a341a5a5..a1a138c493 100644
--- a/apps/erp/app/routes/x+/settings+/sales.tsx
+++ b/apps/erp/app/routes/x+/settings+/sales.tsx
@@ -393,8 +393,8 @@ export default function SalesSettingsRoute() {
<CardHeader>
<CardTitle>PDFs</CardTitle>
<CardDescription>
- Show part thumbnails on quotes, sales orders, and sales
- invoices.
+ Show part thumbnails on quotes, sales orders, sales invoices,
+ and shipments.
</CardDescription>
</CardHeader>
<CardContent>