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: show sales orders and customers in MES

Brad Barbind90a1b956ce9
diff --git a/apps/mes/app/components/Kanban/components/ItemCard.tsx b/apps/mes/app/components/Kanban/components/ItemCard.tsx
index b892f2bede..80e454b623 100644
--- a/apps/mes/app/components/Kanban/components/ItemCard.tsx
+++ b/apps/mes/app/components/Kanban/components/ItemCard.tsx
@@ -18,6 +18,7 @@ import {
LuCheckCircle,
LuClipboardCheck,
LuTimer,
+ LuUserSquare,
LuXCircle,
} from "react-icons/lu";
@@ -27,6 +28,8 @@ import { AlmostDoneIcon } from "~/assets/icons/AlmostDoneIcon";
import { InProgressStatusIcon } from "~/assets/icons/InProgressStatusIcon";
import { TodoStatusIcon } from "~/assets/icons/TodoStatusIcon";
+import { useRouteData } from "@carbon/remix";
+import Avatar from "~/components/Avatar";
import { DeadlineIcon } from "~/components/Icons";
import { getPrivateUrl, path } from "~/utils/path";
import type { DisplaySettings, Item } from "../types";
@@ -85,6 +88,14 @@ export function ItemCard({
showSalesOrder,
showThumbnail,
}: ItemCardProps) {
+ const routeData = useRouteData<{
+ customers: { id: string; name: string }[];
+ }>("/x/operations");
+
+ const customer = showCustomer
+ ? routeData?.customers.find((c) => c.id === item.customerId)
+ : undefined;
+
const isOverdue =
item.deadlineType !== "No Deadline" && item.dueDate
? new Date(item.dueDate) < new Date()
@@ -203,6 +214,16 @@ export function ItemCard({
<span className="text-sm">{item.salesOrderReadableId}</span>
</HStack>
)}
+
+ {showCustomer && item.customerId && (
+ <HStack className="justify-start space-x-2">
+ <LuUserSquare className="text-muted-foreground" />
+ <HStack className="truncate no-underline hover:no-underline">
+ <Avatar size="xs" name={customer?.name ?? ""} />
+ <span>{customer?.name}</span>
+ </HStack>
+ </HStack>
+ )}
</CardContent>
</Card>
</Link>
diff --git a/apps/mes/app/routes/x+/operations.tsx b/apps/mes/app/routes/x+/operations.tsx
index 22a9c463d6..0bab170e99 100644
--- a/apps/mes/app/routes/x+/operations.tsx
+++ b/apps/mes/app/routes/x+/operations.tsx
@@ -29,6 +29,7 @@ import { getLocation } from "~/services/location.server";
import { getFilters, setFilters } from "~/services/operation.server";
import {
getActiveJobOperationsByLocation,
+ getCustomers,
getProcessesList,
getWorkCentersByLocation,
} from "~/services/operations.service";
@@ -162,6 +163,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
return true;
}) ?? [];
+ const customerIds = filteredOperations.map((op) => op.jobCustomerId);
+ const customers = await getCustomers(serviceRole, companyId, customerIds);
+
return json(
{
columns: filteredWorkCenters
@@ -201,6 +205,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
}) ?? []) satisfies Item[],
processes: processes.data ?? [],
workCenters: workCenters.data ?? [],
+ customers: customers.data ?? [],
},
{ headers }
);
@@ -210,7 +215,7 @@ export default function ScheduleRoute() {
return (
<ClientOnly
fallback={
- <div className="flex h-screen w-[calc(100dvw-var(--sidebar-width))] items-center justify-center">
+ <div className="flex h-screen w-[calc(100dvw-var(--sidebar-width-icon))] items-center justify-center">
<Spinner className="h-8 w-8" />
</div>
}
@@ -279,7 +284,7 @@ function KanbanSchedule() {
}, [processes, workCenters]);
return (
- <div className="flex flex-col h-screen w-full">
+ <div className="flex flex-col h-screen w-[calc(100dvw-var(--sidebar-width-icon))]">
<header className="sticky top-0 z-10 flex h-[var(--header-height)] shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12 border-b bg-background">
<div className="flex items-center gap-2 px-2">
<SidebarTrigger />
@@ -419,7 +424,6 @@ function KanbanSchedule() {
{...displaySettings}
showEmployee={false}
showProgress={false}
- showSalesOrder={false}
/>
) : hasFilters ? (
<div className="flex flex-col w-full h-full items-center justify-center gap-4">
diff --git a/apps/mes/app/services/operations.service.ts b/apps/mes/app/services/operations.service.ts
index 5998cf74f5..a75ad33aee 100644
--- a/apps/mes/app/services/operations.service.ts
+++ b/apps/mes/app/services/operations.service.ts
@@ -63,6 +63,18 @@ export async function getActiveJobCount(
});
}
+export async function getCustomers(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ customerIds: string[]
+) {
+ return client
+ .from("customer")
+ .select("id, name")
+ .in("id", customerIds)
+ .eq("companyId", companyId);
+}
+
export function getFileType(fileName: string): (typeof documentTypes)[number] {
const extension = fileName.split(".").pop()?.toLowerCase() ?? "";
if (["zip", "rar", "7z", "tar", "gz"].includes(extension)) {