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: combine job travelers into a single pdf
Brad Barbinc0ebfe21d1d2
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsxindex b0691d4e04..f6e167ae70 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx@@ -48,6 +48,8 @@ import {LuClipboardList,LuClock,LuEllipsisVertical,+ LuEye,+ LuFile,LuHardHat,LuList,LuLoaderCircle,@@ -228,6 +230,30 @@ const JobHeader = () => {</DropdownMenuContent></DropdownMenu>+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ leftIcon={<LuEye />}+ variant="secondary"+ rightIcon={<LuChevronDown />}+ >+ Preview+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent>+ <DropdownMenuItem asChild>+ <a+ target="_blank"+ href={path.to.file.jobTravelerByJobId(jobId)}+ rel="noreferrer"+ >+ <DropdownMenuIcon icon={<LuFile />} />+ Job Traveler+ </a>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+{status !== "Paused" ? (<statusFetcher.Form method="post" action={path.to.jobStatus(jobId)}><input type="hidden" name="status" value="Paused" />diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsxindex 593eb0a35c..190a9f74b0 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx@@ -32,7 +32,6 @@ import {LuGitBranch,LuGitFork,LuGitMerge,- LuListChecks,LuQrCode,LuSquareStack,LuTriangleAlert@@ -287,17 +286,6 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {</Link></MenubarItem>)}- {makeMethod?.id && (- <MenubarItem leftIcon={<LuListChecks />} asChild>- <a- href={path.to.file.jobTraveler(makeMethod.id)}- target="_blank"- rel="noreferrer"- >- Job Traveler- </a>- </MenubarItem>- )}{makeMethod &&(makeMethod.requiresSerialTracking ||makeMethod.requiresBatchTracking) && (diff --git a/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsx b/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsxnew file mode 100644index 0000000000..65d0238426--- /dev/null+++ b/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsx@@ -0,0 +1,202 @@+import { getCarbonServiceRole } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { JobTravelerPageContent } from "@carbon/documents/pdf";+import type { JSONContent } from "@carbon/react";+import {+ Document,+ Font,+ Page,+ renderToStream,+ StyleSheet+} from "@react-pdf/renderer";+import { type LoaderFunctionArgs } from "react-router";+import {+ getJob,+ getJobOperationsByMethodId,+ getTrackedEntityByJobId+} from "~/modules/production/production.service";+import { getCompany } from "~/modules/settings";+import { getBase64ImageFromSupabase } from "~/modules/shared";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const { companyId } = await requirePermissions(request, {});++ const { jobId } = params;+ if (!jobId) throw new Error("Could not find job id");++ const serviceRole = await getCarbonServiceRole();++ // Get the job first+ const job = await getJob(serviceRole, jobId);+ if (job.error || !job.data) {+ console.error(job.error);+ throw new Error("Failed to load job");+ }++ // Verify job belongs to this company+ if (job.data.companyId !== companyId) {+ throw new Error("Job does not belong to this company");+ }++ // Get all make methods for this job+ const jobMakeMethods = await serviceRole+ .from("jobMakeMethod")+ .select("*, ...item(itemType:type)")+ .eq("jobId", jobId)+ .order("createdAt", { ascending: true });++ if (jobMakeMethods.error || !jobMakeMethods.data) {+ console.error(jobMakeMethods.error);+ throw new Error("Failed to load job make methods");+ }++ const company = await getCompany(serviceRole, job.data.companyId ?? "");+ if (company.error) {+ console.error(company.error);+ throw new Error("Failed to load company");+ }++ const customer = await serviceRole+ .from("customer")+ .select("*")+ .eq("id", job.data.customerId ?? "")+ .maybeSingle();++ // Get job notes if they exist+ const jobNotes = job.data.notes as JSONContent | undefined;++ // For each make method, get operations and item data+ const makeMethodsWithData = await Promise.all(+ jobMakeMethods.data.map(async (makeMethod) => {+ const [operations, item] = await Promise.all([+ getJobOperationsByMethodId(serviceRole, makeMethod.id),+ serviceRole+ .from("item")+ .select("*, modelUpload(thumbnailPath)")+ .eq("id", makeMethod.itemId ?? "")+ .single()+ ]);++ if (operations.error || !operations.data) {+ console.error(operations.error);+ throw new Error(+ `Failed to load operations for make method ${makeMethod.id}`+ );+ }++ if (item.error || !item.data) {+ console.error(item.error);+ throw new Error(`Failed to load item for make method ${makeMethod.id}`);+ }++ // Get thumbnail if it exists+ let thumbnail: string | null = null;+ if (item.data.thumbnailPath || item.data.modelUpload?.thumbnailPath) {+ thumbnail = await getBase64ImageFromSupabase(+ serviceRole,+ item.data.thumbnailPath ?? item.data.modelUpload?.thumbnailPath ?? ""+ );+ }++ // Get batch number if item is tracked+ let batchNumber: string | undefined;+ if (+ ["Batch", "Serial"].includes(item.data.itemTrackingType) &&+ makeMethod.parentMaterialId === null+ ) {+ const trackedEntity = await getTrackedEntityByJobId(+ serviceRole,+ job.data!.id!+ );+ if (!trackedEntity.error && trackedEntity.data) {+ batchNumber = trackedEntity.data.readableId ?? undefined;+ }+ }++ return {+ makeMethod,+ operations: operations.data,+ item: item.data,+ thumbnail,+ batchNumber+ };+ })+ );++ // Register fonts (same as Template component)+ Font.register({+ family: "Inter",+ fonts: [+ {+ src: "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfMZhrib2Bg-4.ttf"+ },+ {+ src: "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuOKfMZhrib2Bg-4.ttf",+ fontWeight: 300+ },+ {+ src: "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuI6fMZhrib2Bg-4.ttf",+ fontWeight: 500+ },+ {+ src: "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuFuYMZhrib2Bg-4.ttf",+ fontWeight: 700+ },+ {+ src: "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuBWYMZhrib2Bg-4.ttf",+ fontWeight: 900+ }+ ]+ });++ const styles = StyleSheet.create({+ body: {+ fontFamily: "Inter",+ padding: "20px 40px",+ color: "#000000",+ backgroundColor: "#FFFFFF"+ }+ });++ // Render multiple pages - one per make method+ const stream = await renderToStream(+ <Document+ title="Job Traveler"+ author="Carbon"+ subject="Job Traveler"+ keywords="job traveler, manufacturing"+ >+ {makeMethodsWithData.map((data, index) => (+ <Page key={data.makeMethod.id} size="A4" style={styles.body}>+ <JobTravelerPageContent+ company={company.data}+ job={job.data}+ jobOperations={data.operations}+ customer={customer.data}+ item={data.item}+ batchNumber={data.batchNumber}+ notes={index === 0 ? jobNotes : undefined}+ thumbnail={data.thumbnail}+ />+ </Page>+ ))}+ </Document>+ );++ const body: Buffer = await new Promise((resolve, reject) => {+ const buffers: Uint8Array[] = [];+ stream.on("data", (data) => {+ buffers.push(data);+ });+ stream.on("end", () => {+ resolve(Buffer.concat(buffers));+ });+ stream.on("error", reject);+ });++ const headers = new Headers({+ "Content-Type": "application/pdf",+ "Content-Disposition": `inline; filename="${job.data.jobId}.pdf"`+ });+ return new Response(body, { status: 200, headers });+}diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.tsindex 41b00ced2c..18ac381d1d 100644--- a/apps/erp/app/utils/path.ts+++ b/apps/erp/app/utils/path.ts@@ -200,6 +200,8 @@ export const path = {kanbanQrCode: (id: string, action: "order" | "start" | "complete") =>generatePath(`${file}/kanban/${id}/${action}.png`),jobTraveler: (id: string) => generatePath(`${file}/traveler/${id}.pdf`),+ jobTravelerByJobId: (jobId: string) =>+ generatePath(`${file}/job/${jobId}/traveler.pdf`),nonConformance: (id: string) => generatePath(`${file}/issue/${id}.pdf`),operationLabelsPdf: (id: string,diff --git a/packages/documents/src/pdf/JobTravelerPDF.tsx b/packages/documents/src/pdf/JobTravelerPDF.tsxindex 0b674d98f7..15399c8dad 100644--- a/packages/documents/src/pdf/JobTravelerPDF.tsx+++ b/packages/documents/src/pdf/JobTravelerPDF.tsx@@ -216,19 +216,17 @@ const JobHeader = ({);};-const JobTravelerPDF = ({+// Page content component without Document/Template wrapper (for combining multiple make methods)+export const JobTravelerPageContent = ({company,job,- jobMakeMethod,jobOperations,customer,item,batchNumber,- meta,notes,- thumbnail,- title = "Job Traveler"-}: JobTravelerProps) => {+ thumbnail+}: Omit<JobTravelerProps, "meta" | "title" | "locale" | "jobMakeMethod">) => {const subtitle = batchNumber? batchNumber: (item.name ?? item.readableIdWithRevision);@@ -237,151 +235,170 @@ const JobTravelerPDF = ({: undefined;return (- <Template- title={title}- meta={{- author: meta?.author ?? "Carbon",- keywords: meta?.keywords ?? "job traveler, manufacturing",- subject: meta?.subject ?? "Job Traveler"- }}- >- <View style={tw("flex flex-col")}>- {/* Original Header Section with company logo and job title */}- <View style={tw("mb-6")}>- <Header- title={job.jobId}- subtitle={subtitle}- tertiaryTitle={tertiaryTitle}- company={company}- />- </View>+ <View style={tw("flex flex-col")}>+ {/* Original Header Section with company logo and job title */}+ <View style={tw("mb-6")}>+ <Header+ title={job.jobId}+ subtitle={subtitle}+ tertiaryTitle={tertiaryTitle}+ company={company}+ />+ </View>- {/* Job Header Section with detailed information */}- <View style={tw("mb-6")}>- <JobHeader- company={company}- job={job}- customer={customer}- item={item}- batchNumber={batchNumber}- thumbnail={thumbnail}- />+ {/* Job Header Section with detailed information */}+ <View style={tw("mb-6")}>+ <JobHeader+ company={company}+ job={job}+ customer={customer}+ item={item}+ batchNumber={batchNumber}+ thumbnail={thumbnail}+ />+ </View>++ {/* Job Information Section */}+ <View style={tw("mb-6 text-xs")}>+ <View+ style={tw(+ "flex flex-row justify-between items-center py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase page-break-inside-avoid"+ )}+ >+ <Text style={tw("w-1/12 text-left")}>Seq</Text>+ <Text style={tw("w-3/12 text-left")}>Operation</Text>+ <Text style={tw("w-2/3 text-right pr-4")}>Actions</Text></View>- {/* Job Information Section */}- <View style={tw("mb-6 text-xs")}>- <View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase page-break-inside-avoid"- )}- >- <Text style={tw("w-1/12 text-left")}>Seq</Text>- <Text style={tw("w-3/12 text-left")}>Operation</Text>- <Text style={tw("w-2/3 text-right pr-4")}>Actions</Text>- </View>+ {jobOperations+ .sort((a, b) => a.order - b.order)+ .map((operation, index) => {+ const isInside = operation.operationType === "Inside";+ const setupQrCode =+ operation.setupTime > 0+ ? generateQRCode(`${getStartPath(operation.id)}?type=Setup`, 10)+ : null;+ let laborQrCode =+ operation.laborTime > 0+ ? generateQRCode(`${getStartPath(operation.id)}?type=Labor`, 10)+ : null;+ let machiningQrCode =+ operation.machineTime > 0+ ? generateQRCode(+ `${getStartPath(operation.id)}?type=Machine`,+ 10+ )+ : null;+ let completeQrCode = generateQRCode(getEndPath(operation.id), 10);- {jobOperations- .sort((a, b) => a.order - b.order)- .map((operation, index) => {- const isInside = operation.operationType === "Inside";- const setupQrCode =- operation.setupTime > 0- ? generateQRCode(- `${getStartPath(operation.id)}?type=Setup`,- 10- )- : null;- let laborQrCode =- operation.laborTime > 0- ? generateQRCode(- `${getStartPath(operation.id)}?type=Labor`,- 10- )- : null;- let machiningQrCode =- operation.machineTime > 0- ? generateQRCode(- `${getStartPath(operation.id)}?type=Machine`,- 10- )- : null;- let completeQrCode = generateQRCode(getEndPath(operation.id), 10);-- if (- setupQrCode === null &&- laborQrCode === null &&- machiningQrCode === null- ) {- laborQrCode = generateQRCode(- `${getStartPath(operation.id)}?type=Labor`,- 10- );- }-- return (- <View- style={tw(- "flex flex-col border-b border-gray-300 py-4 px-[6px] page-break-inside-avoid"- )}- key={operation.id}- wrap={false}- >- <View style={tw("flex flex-row justify-between items-start")}>- <Text style={tw("w-1/12 text-left")}>- {getParallelizedOrder(index, operation, jobOperations)}- </Text>- <View style={tw("w-3/12 text-left")}>- <Text style={tw("font-bold")}>- {operation.description}- </Text>- </View>- <View style={tw("w-2/3 flex flex-row justify-end gap-2")}>- {isInside && setupQrCode && (- <View style={tw("flex flex-col items-center w-1/4")}>- <>- <Image src={setupQrCode} style={tw("w-16 h-16")} />- <Text style={tw("text-[8px] mt-1")}>Setup</Text>- </>- </View>- )}-- {isInside && laborQrCode && (- <View style={tw("flex flex-col items-center w-1/4")}>- <>- <Image src={laborQrCode} style={tw("w-16 h-16")} />- <Text style={tw("text-[8px] mt-1")}>Labor</Text>- </>- </View>- )}- {isInside && machiningQrCode && (- <View style={tw("flex flex-col items-center w-1/4")}>- <>- <Image- src={machiningQrCode}- style={tw("w-16 h-16")}- />- <Text style={tw("text-[8px] mt-1")}>Machine</Text>- </>- </View>- )}+ if (+ setupQrCode === null &&+ laborQrCode === null &&+ machiningQrCode === null+ ) {+ laborQrCode = generateQRCode(+ `${getStartPath(operation.id)}?type=Labor`,+ 10+ );+ }++ return (+ <View+ style={tw(+ "flex flex-col border-b border-gray-300 py-4 px-[6px] page-break-inside-avoid"+ )}+ key={operation.id}+ wrap={false}+ >+ <View style={tw("flex flex-row justify-between items-start")}>+ <Text style={tw("w-1/12 text-left")}>+ {getParallelizedOrder(index, operation, jobOperations)}+ </Text>+ <View style={tw("w-3/12 text-left")}>+ <Text style={tw("font-bold")}>{operation.description}</Text>+ </View>+ <View style={tw("w-2/3 flex flex-row justify-end gap-2")}>+ {isInside && setupQrCode && (+ <View style={tw("flex flex-col items-center w-1/4")}>+ <>+ <Image src={setupQrCode} style={tw("w-16 h-16")} />+ <Text style={tw("text-[8px] mt-1")}>Setup</Text>+ </>+ </View>+ )}++ {isInside && laborQrCode && (+ <View style={tw("flex flex-col items-center w-1/4")}>+ <>+ <Image src={laborQrCode} style={tw("w-16 h-16")} />+ <Text style={tw("text-[8px] mt-1")}>Labor</Text>+ </>+ </View>+ )}+ {isInside && machiningQrCode && (<View style={tw("flex flex-col items-center w-1/4")}>- <Image src={completeQrCode} style={tw("w-16 h-16")} />- <Text style={tw("text-[8px] mt-1")}>Complete</Text>+ <>+ <Image+ src={machiningQrCode}+ style={tw("w-16 h-16")}+ />+ <Text style={tw("text-[8px] mt-1")}>Machine</Text>+ </></View>+ )}+ <View style={tw("flex flex-col items-center w-1/4")}>+ <Image src={completeQrCode} style={tw("w-16 h-16")} />+ <Text style={tw("text-[8px] mt-1")}>Complete</Text></View></View></View>- );- })}+ </View>+ );+ })}+ </View>++ {/* Notes Section */}+ {notes && (+ <View style={tw("mb-6")}>+ <Note title="Job Notes" content={notes} /></View>+ )}+ </View>+ );+};- {/* Notes Section */}- {notes && (- <View style={tw("mb-6")}>- <Note title="Job Notes" content={notes} />- </View>- )}- </View>+const JobTravelerPDF = ({+ company,+ job,+ jobMakeMethod,+ jobOperations,+ customer,+ item,+ batchNumber,+ meta,+ notes,+ thumbnail,+ title = "Job Traveler"+}: JobTravelerProps) => {+ return (+ <Template+ title={title}+ meta={{+ author: meta?.author ?? "Carbon",+ keywords: meta?.keywords ?? "job traveler, manufacturing",+ subject: meta?.subject ?? "Job Traveler"+ }}+ >+ <JobTravelerPageContent+ company={company}+ job={job}+ jobOperations={jobOperations}+ customer={customer}+ item={item}+ batchNumber={batchNumber}+ notes={notes}+ thumbnail={thumbnail}+ /></Template>);};diff --git a/packages/documents/src/pdf/index.ts b/packages/documents/src/pdf/index.tsindex 7c1288ba6b..ec23fcbd73 100644--- a/packages/documents/src/pdf/index.ts+++ b/packages/documents/src/pdf/index.ts@@ -1,5 +1,5 @@import IssuePDF from "./IssuePDF";-import JobTravelerPDF from "./JobTravelerPDF";+import JobTravelerPDF, { JobTravelerPageContent } from "./JobTravelerPDF";import KanbanLabelPDF from "./KanbanLabelPDF";import PackingSlipPDF from "./PackingSlipPDF";import ProductLabelPDF from "./ProductLabelPDF";@@ -10,6 +10,7 @@ import SalesOrderPDF from "./SalesOrderPDF";import StockTransferPDF from "./StockTransferPDF";export {IssuePDF,+ JobTravelerPageContent,JobTravelerPDF,KanbanLabelPDF,PackingSlipPDF,