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: add metadata to job traveler and filter outside operations

Brad Barbinfc961a8225d9
diff --git a/apps/erp/app/routes/x+/job+/update.tsx b/apps/erp/app/routes/x+/job+/update.tsx
index 46f2e57861..7fdc54ee4f 100644
--- a/apps/erp/app/routes/x+/job+/update.tsx
+++ b/apps/erp/app/routes/x+/job+/update.tsx
@@ -132,6 +132,7 @@ export async function action({ request }: ActionFunctionArgs) {
case "dueDate":
case "jobId":
case "locationId":
+ case "startDate":
case "unitOfMeasureCode":
return json(
await client
diff --git a/apps/mes/app/components/AppSidebar.tsx b/apps/mes/app/components/AppSidebar.tsx
index ec9c979268..9474fea7c9 100644
--- a/apps/mes/app/components/AppSidebar.tsx
+++ b/apps/mes/app/components/AppSidebar.tsx
@@ -231,6 +231,7 @@ export function OperationsNav({ activeEvents }: { activeEvents: number }) {
];
const { pathname } = useLocation();
+ const { isMobile, setOpenMobile } = useSidebar();
return (
<SidebarGroup>
@@ -253,7 +254,10 @@ export function OperationsNav({ activeEvents }: { activeEvents: number }) {
isActive={isActive}
asChild
>
- <Link to={item.to}>
+ <Link
+ to={item.to}
+ onClick={() => isMobile && setOpenMobile(false)}
+ >
{item.icon && <item.icon />}
<span>{item.title}</span>
{item.label && (
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 33cb11edba..8765cfdf2e 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -2101,10 +2101,10 @@ function useOperation(
if (operation.setupDuration > 0) {
return "Setup";
}
- if (operation.laborDuration > 0) {
- return "Labor";
+ if (operation.machineDuration > 0) {
+ return "Machine";
}
- return "Machine";
+ return "Labor";
});
const [operationState, setOperationState] = useState(operation);
@@ -2638,6 +2638,7 @@ function StartStopButton({
trackedEntityId: string | undefined;
}) {
const fetcher = useFetcher<ProductionEvent>();
+
const isActive = useMemo(() => {
if (fetcher.formData?.get("action") === "End") {
return false;
diff --git a/apps/mes/app/routes/x+/end.$operationId.tsx b/apps/mes/app/routes/x+/end.$operationId.tsx
index 6522e409cd..b32ee4f645 100644
--- a/apps/mes/app/routes/x+/end.$operationId.tsx
+++ b/apps/mes/app/routes/x+/end.$operationId.tsx
@@ -1,4 +1,4 @@
-import { error, getCarbonServiceRole } from "@carbon/auth";
+import { error, getCarbonServiceRole, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { redirect, type LoaderFunctionArgs } from "@vercel/remix";
@@ -12,6 +12,7 @@ import { path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { userId, companyId } = await requirePermissions(request, {});
+
const { operationId } = params;
if (!operationId) throw new Error("Operation ID is required");
@@ -19,6 +20,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
let trackedEntityId = url.searchParams.get("trackedEntityId");
const serviceRole = await getCarbonServiceRole();
+
const [jobOperation, productionQuantities] = await Promise.all([
serviceRole
.from("jobOperation")
@@ -106,7 +108,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
if (trackedEntities.data && trackedEntities.data.length > 0) {
- // Use the last tracked entity if available
trackedEntityId =
trackedEntities.data[trackedEntities.data.length - 1].id;
}
@@ -198,5 +199,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- throw redirect(path.to.operations);
+ throw redirect(
+ path.to.operations,
+ await flash(request, success("Operation finished successfully"))
+ );
}
diff --git a/apps/mes/app/utils/durations.ts b/apps/mes/app/utils/durations.ts
index 7f0308ec0c..ca121c4b56 100644
--- a/apps/mes/app/utils/durations.ts
+++ b/apps/mes/app/utils/durations.ts
@@ -80,6 +80,12 @@ export function makeDurations<
// Calculate labor duration
switch (operation.laborUnit) {
+ case "Total Hours":
+ laborDuration = (operation.laborTime ?? 0) * 3600000; // Convert hours to milliseconds
+ break;
+ case "Total Minutes":
+ laborDuration = (operation.laborTime ?? 0) * 60000; // Convert minutes to milliseconds
+ break;
case "Hours/Piece":
laborDuration =
(operation.laborTime ?? 0) *
@@ -132,6 +138,12 @@ export function makeDurations<
// Calculate machine duration
switch (operation.machineUnit) {
+ case "Total Hours":
+ machineDuration = (operation.machineTime ?? 0) * 3600000; // Convert hours to milliseconds
+ break;
+ case "Total Minutes":
+ machineDuration = (operation.machineTime ?? 0) * 60000; // Convert minutes to milliseconds
+ break;
case "Hours/Piece":
machineDuration =
(operation.machineTime ?? 0) *
diff --git a/packages/documents/src/pdf/JobTravelerPDF.tsx b/packages/documents/src/pdf/JobTravelerPDF.tsx
index 98b4342946..fcc3094429 100644
--- a/packages/documents/src/pdf/JobTravelerPDF.tsx
+++ b/packages/documents/src/pdf/JobTravelerPDF.tsx
@@ -1,9 +1,9 @@
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 { Image, StyleSheet, Text, View } from "@react-pdf/renderer";
import { createTw } from "react-pdf-tailwind";
-import type { PDF } from "../types";
+import type { Company, PDF } from "../types";
import { Header, Note, Template } from "./components";
interface JobTravelerProps extends PDF {
@@ -40,6 +40,163 @@ const tw = createTw({
},
});
+// JobHeader styles
+const jobHeaderStyles = StyleSheet.create({
+ jobHeader: {
+ border: "1px solid #CCC",
+ borderRadius: 6,
+ padding: 16,
+ fontSize: 10,
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "flex-start",
+ marginBottom: 20,
+ gap: 60,
+ },
+ leftSection: {
+ flex: 1,
+ },
+ rightSection: {
+ flex: 1,
+ },
+ infoRow: {
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ marginBottom: 4,
+ },
+ label: {
+ fontSize: 9,
+ fontWeight: 600,
+ color: "#374151",
+ },
+ value: {
+ fontSize: 9,
+ fontWeight: 400,
+ color: "#111827",
+ },
+ sectionTitle: {
+ fontSize: 11,
+ fontWeight: 700,
+ marginBottom: 8,
+ color: "#111827",
+ borderBottom: "1px solid #d1d5db",
+ paddingBottom: 2,
+ },
+});
+
+type JobHeaderProps = {
+ company: Company;
+ job: Database["public"]["Views"]["jobs"]["Row"];
+ customer: Database["public"]["Tables"]["customer"]["Row"] | null;
+ item: Database["public"]["Tables"]["item"]["Row"];
+ batchNumber?: string;
+};
+
+const JobHeader = ({
+ company,
+ job,
+ customer,
+ item,
+ batchNumber,
+}: JobHeaderProps) => {
+ const getTargetInfo = () => {
+ if (job.salesOrderId && job.salesOrderLineId) {
+ return `Sales Order: ${job.salesOrderReadableId || "Make to Order"}`;
+ }
+ return "Inventory";
+ };
+
+ const getTrackingNumber = () => {
+ if (batchNumber) {
+ const trackingType = item.itemTrackingType;
+ return `${trackingType} Number: ${batchNumber}`;
+ }
+ return null;
+ };
+
+ return (
+ <View style={jobHeaderStyles.jobHeader}>
+ <View style={jobHeaderStyles.leftSection}>
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Job ID:</Text>
+ <Text style={jobHeaderStyles.value}>{job.jobId}</Text>
+ </View>
+
+ {getTrackingNumber() && (
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Tracking:</Text>
+ <Text style={jobHeaderStyles.value}>{getTrackingNumber()}</Text>
+ </View>
+ )}
+
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Target:</Text>
+ <Text style={jobHeaderStyles.value}>{getTargetInfo()}</Text>
+ </View>
+
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Item:</Text>
+ <Text style={jobHeaderStyles.value}>
+ {item.name || item.readableIdWithRevision}
+ </Text>
+ </View>
+
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Quantity:</Text>
+ <Text style={jobHeaderStyles.value}>
+ {job.quantity} {job.unitOfMeasureCode}
+ </Text>
+ </View>
+
+ {job.scrapQuantity && job.scrapQuantity > 0 && (
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Scrap Qty:</Text>
+ <Text style={jobHeaderStyles.value}>
+ {job.scrapQuantity} {job.unitOfMeasureCode}
+ </Text>
+ </View>
+ )}
+ </View>
+
+ <View style={jobHeaderStyles.rightSection}>
+ {customer && (
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Customer:</Text>
+ <Text style={jobHeaderStyles.value}>{customer.name}</Text>
+ </View>
+ )}
+
+ {job.startDate && (
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Start Date:</Text>
+ <Text style={jobHeaderStyles.value}>
+ {new Date(job.startDate).toLocaleDateString()}
+ </Text>
+ </View>
+ )}
+
+ {job.dueDate && (
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Due Date:</Text>
+ <Text style={jobHeaderStyles.value}>
+ {new Date(job.dueDate).toLocaleDateString()}
+ </Text>
+ </View>
+ )}
+
+ {job.deadlineType && (
+ <View style={jobHeaderStyles.infoRow}>
+ <Text style={jobHeaderStyles.label}>Deadline Type:</Text>
+ <Text style={jobHeaderStyles.value}>{job.deadlineType}</Text>
+ </View>
+ )}
+ </View>
+ </View>
+ );
+};
+
const JobTravelerPDF = ({
company,
job,
@@ -58,6 +215,7 @@ const JobTravelerPDF = ({
const tertiaryTitle = batchNumber
? `${item.name ?? item.readableIdWithRevision}`
: undefined;
+
return (
<Template
title={title}
@@ -68,7 +226,7 @@ const JobTravelerPDF = ({
}}
>
<View style={tw("flex flex-col")}>
- {/* Header Section - Always at the top */}
+ {/* Original Header Section with company logo and job title */}
<View style={tw("mb-6")}>
<Header
title={job.jobId}
@@ -76,7 +234,17 @@ const JobTravelerPDF = ({
tertiaryTitle={tertiaryTitle}
company={company}
/>
- {/* Subheader with Make Method Information */}
+ </View>
+
+ {/* Job Header Section with detailed information */}
+ <View style={tw("mb-6")}>
+ <JobHeader
+ company={company}
+ job={job}
+ customer={customer}
+ item={item}
+ batchNumber={batchNumber}
+ />
</View>
{/* Job Information Section */}
@@ -91,83 +259,87 @@ const JobTravelerPDF = ({
<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>
- )}
+ {jobOperations
+ .filter((operation) => operation.operationType === "Inside")
+ .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));
- {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 && (
+ 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={machiningQrCode}
- style={tw("w-16 h-16")}
- />
- <Text style={tw("text-[8px] mt-1")}>Machine</Text>
- </>
+ <Image src={completeQrCode} style={tw("w-16 h-16")} />
+ <Text style={tw("text-[8px] mt-1")}>Complete</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 */}
diff --git a/packages/documents/src/pdf/components/Header.tsx b/packages/documents/src/pdf/components/Header.tsx
index 41556bb979..86ba29d7b1 100644
--- a/packages/documents/src/pdf/components/Header.tsx
+++ b/packages/documents/src/pdf/components/Header.tsx
@@ -41,6 +41,45 @@ const styles = StyleSheet.create({
fontWeight: 400,
color: "gray",
},
+ jobHeader: {
+ fontSize: 10,
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "flex-start",
+ marginBottom: 20,
+ gap: 20,
+ },
+ leftSection: {
+ flex: 1,
+ },
+ rightSection: {
+ flex: 1,
+ },
+ infoRow: {
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ marginBottom: 4,
+ },
+ label: {
+ fontSize: 9,
+ fontWeight: 600,
+ color: "#374151",
+ },
+ value: {
+ fontSize: 9,
+ fontWeight: 400,
+ color: "#111827",
+ },
+ sectionTitle: {
+ fontSize: 11,
+ fontWeight: 700,
+ marginBottom: 8,
+ color: "#111827",
+ borderBottom: "1px solid #d1d5db",
+ paddingBottom: 2,
+ },
});
const Header = ({ title, subtitle, tertiaryTitle, company }: HeaderProps) => {
@@ -66,4 +105,4 @@ const Header = ({ title, subtitle, tertiaryTitle, company }: HeaderProps) => {
);
};
-export default Header;
+export { Header };
diff --git a/packages/documents/src/pdf/components/index.ts b/packages/documents/src/pdf/components/index.ts
index 12e3ab9123..4852933e18 100644
--- a/packages/documents/src/pdf/components/index.ts
+++ b/packages/documents/src/pdf/components/index.ts
@@ -1,6 +1,6 @@
-import Header from "./Header";
+import { Header, JobHeader } from "./Header";
import Note from "./Note";
import Summary from "./Summary";
import Template from "./Template";
-export { Header, Note, Summary, Template };
+export { Header, JobHeader, Note, Summary, Template };
diff --git a/packages/react/src/Sidebar.tsx b/packages/react/src/Sidebar.tsx
index e18811aa77..e59c5f3904 100644
--- a/packages/react/src/Sidebar.tsx
+++ b/packages/react/src/Sidebar.tsx
@@ -140,7 +140,7 @@ const SidebarProvider = React.forwardRef<
style={
{
"--sidebar-width": SIDEBAR_WIDTH,
- "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
+ "--sidebar-width-icon": isMobile ? 0 : SIDEBAR_WIDTH_ICON,
...style,
} as React.CSSProperties
}