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: add tracking codes to packing slip
Brad Barbin78fe77b8711c
diff --git a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsxindex 97665b3d3a..d8534c6ace 100644--- a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx+++ b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx@@ -7,6 +7,7 @@ import { getPaymentTerm } from "~/modules/accounting";import {getShipment,getShipmentLinesWithDetails,+ getShipmentTracking,getShippingMethod,} from "~/modules/inventory";import {@@ -70,7 +71,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {getSalesOrderShipment(client, shipment.data.sourceDocumentId),]);- const [customer, customerLocation, paymentTerm, shippingMethod] =+ const [customer, customerLocation, paymentTerm, shippingMethod, shipmentTracking] =await Promise.all([client.from("customer")@@ -83,6 +84,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {client,salesOrderShipment.data?.shippingMethodId ?? ""),+ getShipmentTracking(client, shipment.data.id, companyId),]);if (customer.error) {@@ -109,6 +111,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {terms={(terms?.data?.salesTerms ?? {}) as JSONContent}paymentTerm={paymentTerm.data ?? { id: "", name: "" }}shippingMethod={shippingMethod.data ?? { id: "", name: "" }}+ trackedEntities={shipmentTracking.data ?? []}title="Packing Slip"/>);diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex ba1ff3c00b..43b1afa12f 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -31801,14 +31801,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -33459,14 +33459,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -34364,6 +34364,7 @@ export type Database = {createdAt: string | nullcreatedBy: string | nulldescription: string | null+ fulfillmentId: string | nullid: string | nullitemId: string | nullitemReadableId: string | null@@ -34418,6 +34419,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "shipmentLine_fulfillmentId_fkey"+ columns: ["fulfillmentId"]+ isOneToOne: false+ referencedRelation: "fulfillment"+ referencedColumns: ["id"]+ },{foreignKeyName: "shipmentLine_itemId_fkey"columns: ["itemId"]diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex ba1ff3c00b..43b1afa12f 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -31801,14 +31801,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -33459,14 +33459,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -34364,6 +34364,7 @@ export type Database = {createdAt: string | nullcreatedBy: string | nulldescription: string | null+ fulfillmentId: string | nullid: string | nullitemId: string | nullitemReadableId: string | null@@ -34418,6 +34419,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "shipmentLine_fulfillmentId_fkey"+ columns: ["fulfillmentId"]+ isOneToOne: false+ referencedRelation: "fulfillment"+ referencedColumns: ["id"]+ },{foreignKeyName: "shipmentLine_itemId_fkey"columns: ["itemId"]diff --git a/packages/database/supabase/functions/post-shipment/index.ts b/packages/database/supabase/functions/post-shipment/index.tsindex 4a0f7e68ac..8d2edde1d3 100644--- a/packages/database/supabase/functions/post-shipment/index.ts+++ b/packages/database/supabase/functions/post-shipment/index.ts@@ -518,6 +518,17 @@ serve(async (req: Request) => {"Split Entity ID": newTrackedEntityId,};+ // Remove Shipment and Shipment Line attributes from the new entity+ const updatedAttributesObj = { ...((originalEntity.attributes as TrackedEntityAttributes) || {}) };++ // Delete shipment-related attributes+ delete updatedAttributesObj["Shipment"];+ delete updatedAttributesObj["Shipment Line"];+ delete updatedAttributesObj["Shipment Line Index"];++ // Add the split entity reference+ updatedAttributesObj["Split Entity ID"] = newTrackedEntityId;+// Update the original entity with the reference to the new split entityawait trx.updateTable("trackedEntity")diff --git a/packages/database/supabase/migrations/20250312160738_fulfillment.sql b/packages/database/supabase/migrations/20250312160738_fulfillment.sqlindex fef9006842..9be69ac2ba 100644--- a/packages/database/supabase/migrations/20250312160738_fulfillment.sql+++ b/packages/database/supabase/migrations/20250312160738_fulfillment.sql@@ -79,4 +79,17 @@ ADD COLUMN "fulfillmentId" TEXT NULL;ALTER TABLE "shipmentLine"ADD CONSTRAINT "shipmentLine_fulfillmentId_fkey" FOREIGN KEY ("fulfillmentId") REFERENCES "fulfillment"("id") ON DELETE CASCADE ON UPDATE CASCADE;-CREATE INDEX "shipmentLine_fulfillmentId_idx" ON "shipmentLine" ("fulfillmentId");\ No newline at end of file+CREATE INDEX "shipmentLine_fulfillmentId_idx" ON "shipmentLine" ("fulfillmentId");++DROP VIEW IF EXISTS "shipmentLines";+CREATE OR REPLACE VIEW "shipmentLines" WITH(SECURITY_INVOKER=true) AS+ SELECT+ sl.*,+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ ELSE i."thumbnailPath"+ END AS "thumbnailPath",+ i."name" as "description"+ FROM "shipmentLine" sl+ INNER JOIN "item" i ON i."id" = sl."itemId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId";\ No newline at end of filediff --git a/packages/documents/src/pdf/PackingSlipPDF.tsx b/packages/documents/src/pdf/PackingSlipPDF.tsxindex 37b903e53d..fabb14538b 100644--- a/packages/documents/src/pdf/PackingSlipPDF.tsx+++ b/packages/documents/src/pdf/PackingSlipPDF.tsx@@ -2,7 +2,7 @@ import type { Database } from "@carbon/database";import { Text, View, Image } from "@react-pdf/renderer";import { createTw } from "react-pdf-tailwind";import bwipjs from "@bwip-js/node";-import { formatCityStatePostalCode } from "@carbon/utils";+import { formatCityStatePostalCode, TrackedEntityAttributes } from "@carbon/utils";import type { JSONContent } from "@carbon/react";import type { PDF } from "../types";import { Header, Note, Summary, Template } from "./components";@@ -17,6 +17,7 @@ interface PackingSlipProps extends PDF {paymentTerm: { id: string; name: string };shippingMethod: { id: string; name: string };terms: JSONContent;+ trackedEntities: Database["public"]["Tables"]["trackedEntity"]["Row"][];}// Initialize tailwind-styled-components@@ -48,6 +49,7 @@ const PackingSlipPDF = ({paymentTerm,shippingMethod,title = "Packing Slip",+ trackedEntities,}: PackingSlipProps) => {const {addressLine1,@@ -83,6 +85,8 @@ const PackingSlipPDF = ({});}+ const hasTrackedEntities = trackedEntities.length > 0;+return (<Templatetitle={title}@@ -92,17 +96,21 @@ const PackingSlipPDF = ({subject: meta?.subject ?? "Packing Slip",}}>- <View>- <Header title={title} company={company} />- <Summary company={company} items={details} />- {shipment?.trackingNumber && (- <View style={tw("flex flex-col gap-2 justify-between mb-5")}>- <Text style={tw("text-gray-500 text-xs")}>Tracking Number</Text>- <Text style={tw("text-sm")}>{shipment?.trackingNumber}</Text>- </View>- )}+ <View style={tw("flex flex-col")}>+ {/* Header Section - Always at the top */}+ <View style={tw("mb-4")}>+ <Header title={title} company={company} />+ <Summary company={company} items={details} />+ {shipment?.trackingNumber && (+ <View style={tw("flex flex-col gap-2 justify-between mb-5")}>+ <Text style={tw("text-gray-500 text-xs")}>Tracking Number</Text>+ <Text style={tw("text-sm")}>{shipment?.trackingNumber}</Text>+ </View>+ )}+ </View>- <View style={tw("flex flex-row justify-between mb-5")}>+ {/* Shipping Information Section */}+ <View style={tw("flex flex-row justify-between mb-6 page-break-inside-avoid")}><View style={tw("flex flex-col gap-2 w-1/3")}><Text style={tw("text-gray-500 text-xs")}>Ship To</Text><Text style={tw("text-sm")}>{customer.name}</Text>@@ -132,41 +140,70 @@ const PackingSlipPDF = ({<Text style={tw("text-sm")}>{paymentTerm.name}</Text></View></View>- <View style={tw("mb-5 text-xs")}>++ {/* Line Items Section */}+ <View style={tw("mb-6 text-xs")}><Viewstyle={tw(- "flex flex-row justify-between items-center mt-5 py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase"+ "flex flex-row justify-between items-center mt-5 py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase page-break-inside-avoid")}>- <Text style={tw("w-5/12 text-left")}>Description</Text>- <Text style={tw("w-1/6 text-center")}>Qty</Text>- <Text style={tw("w-1/6 text-right")}>Barcode</Text>+ <Text style={tw(`w-${hasTrackedEntities ? '7/12' : '9/12'} text-left`)}>Description</Text>+ <Text style={tw(`w-${hasTrackedEntities ? '1/6' : '3/12'} text-center`)}>Qty</Text>+ {hasTrackedEntities && (+ <Text style={tw("w-1/4 text-right")}>Serial/Batch</Text>+ )}</View>+{shipmentLines.map((line) => {const barcodeDataUrl = generateBarcode(line.itemReadableId);+ const trackedEntitiesForLine = trackedEntities.filter(+ (entity) => (entity.attributes as TrackedEntityAttributes)?.["Shipment Line"] === line.id+ );return (<Viewstyle={tw(- "flex flex-row justify-between py-3 px-[6px] border-b border-gray-300"+ "flex flex-row justify-between py-3 px-[6px] border-b border-gray-300 page-break-inside-avoid")}key={line.id}>- <View style={tw("w-1/2")}>+ <View style={tw(`w-${hasTrackedEntities ? '7/12' : '9/12'}`)}><Text style={tw("font-bold mb-1")}>{getLineDescription(line)}</Text>- <Text style={tw("text-[9px] opacity-80")}>+ <Text style={tw("text-[9px] opacity-80 mb-2")}>{getLineDescriptionDetails(line)}</Text>+ <Image src={barcodeDataUrl} style={tw("max-w-[50%]")} /></View>- <Text style={tw("w-1/4 text-center")}>+ <Text style={tw(`w-${hasTrackedEntities ? '1/6' : '3/12'} text-center`)}>{getLineQuantity(line)}</Text>- <Image style={tw("w-1/4 text-right")} src={barcodeDataUrl} />+ {hasTrackedEntities && (+ <View style={tw("flex flex-col gap-2 w-1/4 text-right")}>+ {trackedEntitiesForLine.length > 0 && (+ <View>+ {trackedEntitiesForLine.map((entity) => {+ const qrCodeDataUrl = generateQRCode(entity.id);+ return (+ <View key={entity.id} style={tw("mb-2 text-right")}>+ <Text style={tw("text-[8px] mb-1")}>+ {entity.id}+ </Text>+ <Image src={qrCodeDataUrl} style={tw("max-w-[80%] ml-auto")} />+ </View>+ );+ })}+ </View>+ )}+ </View>+ )}</View>);})}</View>++ {/* Notes and Terms Section */}<View style={tw("flex flex-col gap-4 w-full")}><Notetitle="Notes"@@ -200,6 +237,17 @@ function getLineDescriptionDetails(return line.description;}+async function generateQRCode(text: string): Promise<string> {+ const buffer = await bwipjs.toBuffer({+ bcid: "qrcode",+ text,+ scale: 2, // Reduced scale for smaller QR code+ height: 8, // Reduced height+ width: 8, // Reduced width+ });+ return `data:image/png;base64,${buffer.toString("base64")}`;+}+async function generateBarcode(text: string): Promise<string> {const buffer = await bwipjs.toBuffer({bcid: "code128", // Barcode type