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
Fix packing slip for warehouse transfer shipments
Sidwebworks71ab0b318c70
diff --git a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsxindex eca7f6c191..ef5625a008 100644--- a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx+++ b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx@@ -16,7 +16,8 @@ import {getShipment,getShipmentLinesWithDetails,getShipmentTracking,- getShippingMethod+ getShippingMethod,+ getWarehouseTransfer} from "~/modules/inventory";import {getPurchaseOrder,@@ -458,6 +459,117 @@ export async function loader({ request, params }: LoaderFunctionArgs) {headers: poHeaders});}+ case "Outbound Transfer": {+ const warehouseTransfer = await getWarehouseTransfer(+ client,+ shipment.data.sourceDocumentId+ );++ if (warehouseTransfer.error) {+ console.error(warehouseTransfer.error);+ throw new Error("Failed to load warehouse transfer");+ }++ const [shippingMethod, shipmentTracking] = await Promise.all([+ getShippingMethod(client, shipment.data.shippingMethodId ?? ""),+ getShipmentTracking(client, shipment.data.id, companyId)+ ]);++ const toLocation = warehouseTransfer.data.toLocation;+ const shippingAddress = toLocation+ ? {+ addressLine1: toLocation.addressLine1,+ addressLine2: toLocation.addressLine2,+ city: toLocation.city,+ stateProvince: toLocation.stateProvince,+ postalCode: toLocation.postalCode,+ countryCode: toLocation.countryCode+ }+ : null;++ let transferThumbnails: Record<string, string | null> = {};++ if (showThumbnails) {+ const transferThumbnailPaths = shipmentLines.data?.reduce<+ Record<string, string | null>+ >((acc, line) => {+ if (line.thumbnailPath) {+ acc[line.id!] = line.thumbnailPath;+ }+ return acc;+ }, {});++ transferThumbnails =+ (transferThumbnailPaths+ ? await Promise.all(+ Object.entries(transferThumbnailPaths).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 transferStream = await renderToStream(+ <PackingSlipPDF+ company={company.data as any}+ customer={{ name: toLocation?.name ?? "" } as any}+ locale={locale}+ meta={{+ author: "Carbon",+ keywords: "packing slip",+ subject: "Packing Slip"+ }}+ sourceDocument="Outbound Transfer"+ sourceDocumentId={warehouseTransfer.data.transferId ?? undefined}+ shipment={shipment.data}+ shipmentLines={shipmentLines.data ?? []}+ // @ts-expect-error+ shippingAddress={shippingAddress}+ terms={(terms?.data?.salesTerms ?? {}) as JSONContent}+ paymentTerm={{ id: "", name: "" }}+ shippingMethod={shippingMethod.data ?? { id: "", name: "" }}+ trackedEntities={shipmentTracking.data ?? []}+ title="Packing Slip"+ thumbnails={transferThumbnails}+ template={templateConfig}+ sections={templateSections}+ />+ );++ const transferBody: Buffer = await new Promise((resolve, reject) => {+ const buffers: Uint8Array[] = [];+ transferStream.on("data", (data) => {+ buffers.push(data);+ });+ transferStream.on("end", () => {+ resolve(Buffer.concat(buffers));+ });+ transferStream.on("error", reject);+ });++ const transferHeaders = new Headers({+ "Content-Type": "application/pdf",+ "Content-Disposition": `inline; filename="${company.data.name} - ${shipment.data.shipmentId}.pdf"`+ });+ return new Response(new Uint8Array(transferBody), {+ status: 200,+ headers: transferHeaders+ });+ }default:throw new Error("Invalid source document");}