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: job traveler
Brad Barbin0ed41c33b733
diff --git a/apps/erp/app/components/Layout/Topbar/Search.tsx b/apps/erp/app/components/Layout/Topbar/Search.tsxindex 62a597288c..9cf538d306 100644--- a/apps/erp/app/components/Layout/Topbar/Search.tsx+++ b/apps/erp/app/components/Layout/Topbar/Search.tsx@@ -51,6 +51,7 @@ import useItemsSubmodules from "~/modules/items/ui/useItemsSubmodules";import usePeopleSubmodules from "~/modules/people/ui/usePeopleSubmodules";import useProductionSubmodules from "~/modules/production/ui/useProductionSubmodules";import usePurchasingSubmodules from "~/modules/purchasing/ui/usePurchasingSubmodules";+import useQualitySubmodules from "~/modules/quality/ui/useQualitySubmodules";import useResourcesSubmodules from "~/modules/resources/ui/useResourcesSubmodules";import useSalesSubmodules from "~/modules/sales/ui/useSalesSubmodules";import useSettingsSubmodules from "~/modules/settings/ui/useSettingsSubmodules";@@ -334,9 +335,9 @@ function useGroupedSubmodules() {const users = useUsersSubmodules();const settings = useSettingsSubmodules();const people = usePeopleSubmodules();+ const quality = useQualitySubmodules();const resources = useResourcesSubmodules();const account = useAccountSubmodules();-const groupedSubmodules: Record<string,{@@ -351,6 +352,7 @@ function useGroupedSubmodules() {inventory,sales,purchasing,+ quality,accounting,invoicing,people,diff --git a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsxindex 4b99b86a04..b5246d721e 100644--- a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx+++ b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx@@ -152,14 +152,18 @@ const BoMExplorer = ({getMaterialLink(itemType,itemId,- node.data.makeMethodId+ node.data.methodType === "Make"+ ? node.data.materialMakeMethodId+ : node.data.makeMethodId)) {navigate(getMaterialLink(itemType,itemId,- node.data.makeMethodId+ node.data.methodType === "Make"+ ? node.data.materialMakeMethodId+ : node.data.makeMethodId));}diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsxindex ce3fbc234f..16c761aede 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx@@ -305,5 +305,7 @@ function NodePreview({ node }: { node: FlatTreeItem<JobMethod> }) {function getNodePath(node: FlatTreeItem<JobMethod>) {return node.data.isRoot? path.to.jobMethod(node.data.jobId, node.data.jobMaterialMakeMethodId)+ : node.data.methodType === "Make"+ ? path.to.jobMakeMethod(node.data.jobId, node.data.jobMaterialMakeMethodId): path.to.jobMakeMethod(node.data.jobId, node.data.jobMakeMethodId);}diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsxindex b268e2cb53..7e311ce346 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx@@ -39,6 +39,7 @@ import {LuGitBranch,LuGitFork,LuGitMerge,+ LuListChecks,LuQrCode,LuSquareStack,LuTriangleAlert,@@ -119,9 +120,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {const isJobMethod = pathname === path.to.jobMethod(jobId, methodId!);const isJobMakeMethod =- methodId &&- materialId &&- pathname === path.to.jobMakeMethod(jobId, methodId);+ methodId && pathname === path.to.jobMakeMethod(jobId, methodId);const { carbon } = useCarbon();@@ -186,6 +185,8 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {}};+ console.log({ makeMethod });+return (<>{permissions.can("update", "production") &&@@ -235,6 +236,17 @@ 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/modules/quality/ui/NonConformance/useNonConformanceNavigation.tsx b/apps/erp/app/modules/quality/ui/NonConformance/useNonConformanceNavigation.tsxindex 64997147ce..c903be8906 100644--- a/apps/erp/app/modules/quality/ui/NonConformance/useNonConformanceNavigation.tsx+++ b/apps/erp/app/modules/quality/ui/NonConformance/useNonConformanceNavigation.tsx@@ -2,7 +2,6 @@ import { useParams } from "@remix-run/react";import {LuClipboardPen,- LuContainer,LuFileText,LuListChecks,LuSearch,@@ -30,7 +29,7 @@ export function useNonConformanceNavigation() {const requiresManagementReview =routeData.nonConformance.approvalRequirements?.includes("MRB");- const isExternal = routeData.nonConformance.source === "External";+ // const isExternal = routeData.nonConformance.source === "External";return [{@@ -53,13 +52,13 @@ export function useNonConformanceNavigation() {shortcut: "Command+Shift+a",isDisabled: !hasActions,},- {- name: "Supplier",- to: path.to.nonConformanceSupplier(id),- icon: LuContainer,- shortcut: "Command+Shift+s",- isDisabled: !isExternal,- },+ // {+ // name: "Supplier",+ // to: path.to.nonConformanceSupplier(id),+ // icon: LuContainer,+ // shortcut: "Command+Shift+s",+ // isDisabled: !isExternal,+ // },{name: "Review",to: path.to.nonConformanceReview(id),diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsxindex 9eb2a090b2..3e48c08101 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx@@ -317,6 +317,12 @@ function getNodePath(node: FlatTreeItem<QuoteMethod>) {node.data.quoteLineId,node.data.quoteMaterialMakeMethodId)+ : node.data.methodType === "Make"+ ? path.to.quoteLineMakeMethod(+ node.data.quoteId,+ node.data.quoteLineId,+ node.data.quoteMaterialMakeMethodId+ ): path.to.quoteLineMakeMethod(node.data.quoteId,node.data.quoteLineId,diff --git a/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsxnew file mode 100644index 0000000000..2fd4215355--- /dev/null+++ b/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsx@@ -0,0 +1,106 @@+import { requirePermissions } from "@carbon/auth/auth.server";+import { JobTravelerPDF } from "@carbon/documents/pdf";+import type { JSONContent } from "@carbon/react";+import { renderToStream } from "@react-pdf/renderer";+import { type LoaderFunctionArgs } from "@vercel/remix";+import {+ getJob,+ getJobMakeMethodById,+ getJobOperationsByMethodId,+} from "~/modules/production/production.service";+import { getCompany } from "~/modules/settings";+import { getLocale } from "~/utils/request";++export const config = { runtime: "nodejs" };++export async function loader({ request, params }: LoaderFunctionArgs) {+ const { client } = await requirePermissions(request, {+ view: "production",+ });++ const { id } = params;+ if (!id) throw new Error("Could not find job make method id");++ const jobMakeMethod = await getJobMakeMethodById(client, id);+ if (jobMakeMethod.error) {+ console.error(jobMakeMethod.error);+ throw new Error("Failed to load job make method");+ }++ const [company, job] = await Promise.all([+ getCompany(client, jobMakeMethod.data?.companyId ?? ""),+ getJob(client, jobMakeMethod.data?.jobId ?? ""),+ ]);++ if (company.error) {+ console.error(company.error);+ throw new Error("Failed to load company");+ }++ if (job.error || !job.data) {+ console.error(job.error);+ throw new Error("Failed to load job");+ }++ const [jobOperations, customer, item] = await Promise.all([+ getJobOperationsByMethodId(client, id),+ client+ .from("customer")+ .select("*")+ .eq("id", job.data.customerId ?? "")+ .maybeSingle(),+ client+ .from("item")+ .select("*")+ .eq("id", jobMakeMethod.data.itemId ?? "")+ .single(),+ ]);++ if (jobOperations.error || !jobOperations.data) {+ console.error(jobOperations.error);+ throw new Error("Failed to load job operations");+ }++ if (item.error || !item.data) {+ console.error(item.error);+ throw new Error("Failed to load item");+ }++ // Get job notes if they exist+ const jobNotes = job.data.notes as JSONContent | undefined;++ const locale = getLocale(request);++ const stream = await renderToStream(+ <JobTravelerPDF+ company={company.data}+ job={job.data}+ jobMakeMethod={jobMakeMethod.data}+ jobOperations={jobOperations.data}+ customer={customer.data}+ item={item.data}+ locale={locale}+ meta={{+ author: "CarbonOS",+ keywords: "job traveler, manufacturing",+ subject: "Job Traveler",+ }}+ notes={jobNotes}+ title="Job Traveler"+ />+ );++ 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" });+ return new Response(body, { status: 200, headers });+}diff --git a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsxindex 75f2a538fe..b4cec3f7bc 100644--- a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx@@ -14,6 +14,7 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { Suspense } from "react";import { CadModel } from "~/components";+import { usePanels } from "~/components/Layout";import { usePermissions, useRouteData } from "~/hooks";import type { Job } from "~/modules/production";import {@@ -30,7 +31,6 @@ import {import JobMakeMethodTools from "~/modules/production/ui/Jobs/JobMakeMethodTools";import { getTagsList } from "~/modules/shared";import { path } from "~/utils/path";-import { usePanels } from "~/components/Layout";export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {@@ -42,10 +42,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {if (!jobId) throw new Error("Could not find jobId");if (!methodId) throw new Error("Could not find methodId");- const [materials, operations, tags] = await Promise.all([+ const [materials, operations, tags, makeMethod] = await Promise.all([getJobMaterialsByMethodId(client, methodId),getJobOperationsByMethodId(client, methodId),getTagsList(client, companyId, "operation"),+ getJobMakeMethodById(client, methodId),]);if (materials.error) {@@ -68,6 +69,16 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}+ if (makeMethod.error) {+ throw redirect(+ path.to.job(jobId),+ await flash(+ request,+ error(makeMethod.error, "Failed to load make method")+ )+ );+ }+return defer({materials:materials?.data.map((m) => ({@@ -87,7 +98,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {jobMakeMethodId: o.jobMakeMethodId ?? methodId,workInstruction: o.workInstruction as JSONContent,})) ?? [],- makeMethod: getJobMakeMethodById(client, methodId),+ makeMethod: makeMethod.data,productionData: getProductionDataByOperations(client,operations?.data?.map((o) => o.id)diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.tsindex e6e2f2c179..23ee7c5d5f 100644--- a/apps/erp/app/utils/path.ts+++ b/apps/erp/app/utils/path.ts@@ -111,6 +111,7 @@ export const path = {},file: {cadModel: (id: string) => generatePath(`${file}/model/${id}`),+ jobTraveler: (id: string) => generatePath(`${file}/traveler/${id}.pdf`),operationLabelsPdf: (id: string,{diff --git a/packages/database/supabase/functions/create/index.ts b/packages/database/supabase/functions/create/index.tsindex 8ad06b8dfb..703f3175ef 100644--- a/packages/database/supabase/functions/create/index.ts+++ b/packages/database/supabase/functions/create/index.ts@@ -32,7 +32,7 @@ const payloadValidator = z.discriminatedUnion("type", [}),z.object({type: z.literal("receiptFromPurchaseOrder"),- locationId: z.string(),+ locationId: z.string().optional(),purchaseOrderId: z.string(),receiptId: z.string().optional(),companyId: z.string(),@@ -789,7 +789,7 @@ serve(async (req: Request) => {"Fixture","Consumable",])- .eq("locationId", locationId),+ .or(`locationId.eq.${locationId},locationId.is.null`),client.from("receipt").select("*")diff --git a/packages/documents/src/pdf/JobTravelerPDF.tsx b/packages/documents/src/pdf/JobTravelerPDF.tsxnew file mode 100644index 0000000000..515ca98a86--- /dev/null+++ b/packages/documents/src/pdf/JobTravelerPDF.tsx@@ -0,0 +1,205 @@+import bwipjs from "@bwip-js/node";+import type { Database } from "@carbon/database";+import type { JSONContent } from "@carbon/react";+import { Image, Text, View } from "@react-pdf/renderer";+import { createTw } from "react-pdf-tailwind";+import type { PDF } from "../types";+import { Header, Note, Template } from "./components";++interface JobTravelerProps extends PDF {+ job: Database["public"]["Views"]["jobs"]["Row"];+ jobMakeMethod: Database["public"]["Tables"]["jobMakeMethod"]["Row"];+ jobOperations: Database["public"]["Tables"]["jobOperation"]["Row"][];+ customer: Database["public"]["Tables"]["customer"]["Row"] | null;+ item: Database["public"]["Tables"]["item"]["Row"];+ notes?: JSONContent;+}++function getStartPath(operationId: string) {+ return `https://mes.carbonos.dev/x/start/${operationId}`;+}++function getEndPath(operationId: string) {+ return `https://mes.carbonos.dev/x/end/${operationId}`;+}++// Initialize tailwind-styled-components+const tw = createTw({+ theme: {+ fontFamily: {+ sans: ["Helvetica", "Arial", "sans-serif"],+ },+ extend: {+ colors: {+ gray: {+ 500: "#7d7d7d",+ },+ },+ },+ },+});++const JobTravelerPDF = ({+ company,+ job,+ jobMakeMethod,+ jobOperations,+ customer,+ item,+ meta,+ notes,+ title = "Job Traveler",+}: JobTravelerProps) => {+ return (+ <Template+ title={title}+ meta={{+ author: meta?.author ?? "CarbonOS",+ keywords: meta?.keywords ?? "job traveler, manufacturing",+ subject: meta?.subject ?? "Job Traveler",+ }}+ >+ <View style={tw("flex flex-col")}>+ {/* Header Section - Always at the top */}+ <View style={tw("mb-6")}>+ <Header+ title={job.jobId}+ subtitle={item.readableId}+ tertiaryTitle={item.name}+ company={company}+ />+ {/* Subheader with Make Method Information */}+ </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.map((operation, index) => {+ const setupQrCode =+ operation.setupTime > 0+ ? generateQRCode(`${getStartPath(operation.id)}?type=Setup`)+ : null;+ let laborQrCode =+ operation.laborTime > 0+ ? generateQRCode(`${getStartPath(operation.id)}?type=Labor`)+ : null;+ let machiningQrCode =+ operation.machineTime > 0+ ? generateQRCode(`${getStartPath(operation.id)}?type=Machine`)+ : null;+ let completeQrCode = generateQRCode(getEndPath(operation.id));++ if (+ setupQrCode === null &&+ laborQrCode === null &&+ machiningQrCode === null+ ) {+ laborQrCode = generateQRCode(+ `${getStartPath(operation.id)}?type=Labor`+ );+ }++ return (+ <View+ style={tw(+ "flex flex-col border-b border-gray-300 py-4 px-[6px] page-break-inside-avoid"+ )}+ key={operation.id}+ >+ <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")}>+ {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>+ )}++ {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>+ )}+ {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>+ )}+ <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>+ </Template>+ );+};++async function generateQRCode(text: string): Promise<string> {+ const buffer = await bwipjs.toBuffer({+ bcid: "qrcode",+ text,+ scale: 2,+ height: 10,+ width: 10,+ });+ return `data:image/png;base64,${buffer.toString("base64")}`;+}++export default JobTravelerPDF;++type Operation = Database["public"]["Tables"]["jobOperation"]["Row"];++function getParallelizedOrder(+ index: number,+ item: Operation,+ items: Operation[]+) {+ if (item?.operationOrder !== "With Previous") return index + 1;+ // traverse backwards through the list of items to find the first item that is not "With Previous" and return its index + 1+ for (let i = index - 1; i >= 0; i--) {+ if (items[i].operationOrder !== "With Previous") {+ return i + 1;+ }+ }++ return 1;+}diff --git a/packages/documents/src/pdf/components/Header.tsx b/packages/documents/src/pdf/components/Header.tsxindex cc75a4581f..41556bb979 100644--- a/packages/documents/src/pdf/components/Header.tsx+++ b/packages/documents/src/pdf/components/Header.tsx@@ -4,6 +4,8 @@ import type { Company } from "../../types";type HeaderProps = {company: Company;title: string;+ subtitle?: string;+ tertiaryTitle?: string;};const styles = StyleSheet.create({@@ -18,15 +20,30 @@ const styles = StyleSheet.create({logo: {height: 70,},- title: {+ titleWithoutSubtitle: {height: 70,fontSize: 26,letterSpacing: -1,fontWeight: 700,},+ title: {+ fontSize: 26,+ letterSpacing: -1,+ fontWeight: 700,+ },+ subtitle: {+ fontSize: 18,+ fontWeight: 500,+ color: "gray",+ },+ tertiaryTitle: {+ fontSize: 12,+ fontWeight: 400,+ color: "gray",+ },});-const Header = ({ title, company }: HeaderProps) => {+const Header = ({ title, subtitle, tertiaryTitle, company }: HeaderProps) => {return (<View style={styles.header}><View>@@ -37,7 +54,13 @@ const Header = ({ title, company }: HeaderProps) => {)}</View><View>- <Text style={styles.title}>{title}</Text>+ <Text style={subtitle ? styles.title : styles.titleWithoutSubtitle}>+ {title}+ </Text>+ {subtitle && <Text style={styles.subtitle}>{subtitle}</Text>}+ {tertiaryTitle && (+ <Text style={styles.tertiaryTitle}>{tertiaryTitle}</Text>+ )}</View></View>);diff --git a/packages/documents/src/pdf/index.ts b/packages/documents/src/pdf/index.tsindex 30e9b07fd7..7eb16c17ea 100644--- a/packages/documents/src/pdf/index.ts+++ b/packages/documents/src/pdf/index.ts@@ -1,12 +1,14 @@+import JobTravelerPDF from "./JobTravelerPDF";import PackingSlipPDF from "./PackingSlipPDF";+import ProductLabelPDF from "./ProductLabelPDF";import PurchaseOrderPDF from "./PurchaseOrderPDF";import QuotePDF from "./QuotePDF";import SalesOrderPDF from "./SalesOrderPDF";-import ProductLabelPDF from "./ProductLabelPDF";export {+ JobTravelerPDF,PackingSlipPDF,+ ProductLabelPDF,PurchaseOrderPDF,QuotePDF,SalesOrderPDF,- ProductLabelPDF,};