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(erp): phone job page and production dashboard — Structure tab, row-based estimates vs actual, one-line empty files/CAD/risks, bar-list KPIs and work center rows

aashub62b1f6b27ac
diff --git a/apps/erp/app/components/CadModel.tsx b/apps/erp/app/components/CadModel.tsx
index 7dd31fc3fc..b83ee5de7b 100644
--- a/apps/erp/app/components/CadModel.tsx
+++ b/apps/erp/app/components/CadModel.tsx
@@ -22,7 +22,8 @@ import {
Spinner,
toast,
useDisclosure,
- useMode
+ useMode,
+ useViewport
} from "@carbon/react";
import { getFileSizeLimit, MODEL_RAW_KEEP_MAX_BYTES } from "@carbon/utils";
import { ModelPreview } from "@carbon/viewer/model-preview";
@@ -32,7 +33,7 @@ import { Trans, useLingui } from "@lingui/react/macro";
import { nanoid } from "nanoid";
import { useState } from "react";
import { useDropzone } from "react-dropzone";
-import { LuCloudUpload, LuRefreshCw, LuZap } from "react-icons/lu";
+import { LuBox, LuCloudUpload, LuRefreshCw, LuZap } from "react-icons/lu";
import { useFetcher } from "react-router";
import { useModelUpload, useUser } from "~/hooks";
import type { ModelUpload } from "~/types";
@@ -459,6 +460,7 @@ const CadModelUpload = ({
onFileChange
}: CadModelUploadProps) => {
const hasFile = !!file;
+ const { isPhone } = useViewport();
const { getRootProps, getInputProps } = useDropzone({
disabled: hasFile,
@@ -495,6 +497,36 @@ const CadModelUpload = ({
}
});
+ // Phones: no model yet is one line with an Upload button, not a 400px drop zone.
+ if (isPhone && !hasFile) {
+ return (
+ <div className="flex w-full flex-col rounded-xl border border-border bg-card">
+ {title && (
+ <div className="flex items-center gap-2 border-b border-border px-4 py-3 font-medium">
+ {title}
+ {titleExtras}
+ </div>
+ )}
+ <div className="flex items-center gap-3 px-4 py-3">
+ <span className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground">
+ <LuBox className="size-4" />
+ </span>
+ <p className="min-w-0 flex-1 text-sm text-muted-foreground">
+ <Trans>No CAD model to preview.</Trans>
+ </p>
+ {!isReadOnly && (
+ <div {...getRootProps()}>
+ <input {...getInputProps()} name="file" className="sr-only" />
+ <Button variant="secondary" leftIcon={<LuCloudUpload />}>
+ <Trans>Upload</Trans>
+ </Button>
+ </div>
+ )}
+ </div>
+ </div>
+ );
+ }
+
// Read-only with no model yet: keep the section (and its title) so the reader
// knows it exists, but drop the drop zone entirely.
if (isReadOnly) {
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx b/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx
index 5397cc717b..6b2181d4d4 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx
@@ -32,6 +32,7 @@ import {
Thead,
Tr,
toast,
+ useViewport,
VStack
} from "@carbon/react";
import { MODEL_RAW_KEEP_MAX_BYTES } from "@carbon/utils";
@@ -357,6 +358,10 @@ const JobDocuments = ({
a.name.localeCompare(b.name)
) as FileObject[];
+ // Phones: an empty card is one line; the header's New uploads.
+ const { isPhone } = useViewport();
+ const isEmpty = allFiles.length === 0 && !modelUpload?.modelName;
+
return (
<>
<Card className="flex-grow">
@@ -373,230 +378,241 @@ const JobDocuments = ({
</CardAction>
</HStack>
<CardContent>
- <Table>
- <Thead>
- <Tr>
- <Th>Name</Th>
- <Th>Size</Th>
- <Th>Bucket</Th>
- <Th>Created</Th>
- <Th />
- </Tr>
- </Thead>
- <Tbody>
- {modelUpload?.modelName &&
- (modelUpload.modelSize ?? 0) <= MODEL_RAW_KEEP_MAX_BYTES && (
- <Tr>
- <Td>
- <HStack>
- <DocumentIcon type="Model" />
- <VStack>
- <Hyperlink
- target="_blank"
- to={getModelPath(modelUpload)}
+ {isPhone && isEmpty ? (
+ <p className="text-sm text-muted-foreground">
+ <Trans>No files</Trans>
+ </p>
+ ) : (
+ <Table>
+ <Thead>
+ <Tr>
+ <Th>Name</Th>
+ <Th>Size</Th>
+ <Th>Bucket</Th>
+ <Th>Created</Th>
+ <Th />
+ </Tr>
+ </Thead>
+ <Tbody>
+ {modelUpload?.modelName &&
+ (modelUpload.modelSize ?? 0) <= MODEL_RAW_KEEP_MAX_BYTES && (
+ <Tr>
+ <Td>
+ <HStack>
+ <DocumentIcon type="Model" />
+ <VStack>
+ <Hyperlink
+ target="_blank"
+ to={getModelPath(modelUpload)}
+ >
+ {modelUpload.modelName}
+ </Hyperlink>
+ </VStack>
+ <ModelOptimizedIndicator
+ modelPath={modelUpload.modelPath}
+ />
+ </HStack>
+ </Td>
+ <Td>
+ {modelUpload.modelSize
+ ? convertKbToString(
+ Math.floor((modelUpload.modelSize ?? 0) / 1024)
+ )
+ : "--"}
+ </Td>
+ <Td>
+ <Enumerable value="Job" />
+ </Td>
+ <Td className="text-xs font-mono">--</Td>
+ <Td>
+ <div className="flex justify-end w-full">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label={t`More`}
+ icon={<LuEllipsisVertical />}
+ variant="secondary"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ shortcut={MENU_ITEM_SHORTCUTS.view}
+ asChild
+ >
+ <Link to={getModelPath(modelUpload)}>
+ <Trans>View</Trans>
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ shortcut={MENU_ITEM_SHORTCUTS.download}
+ onClick={() => downloadModel(modelUpload)}
+ >
+ Download
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ destructive
+ disabled={!canDelete || isReadOnly}
+ onClick={() => deleteModel()}
+ >
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </Td>
+ </Tr>
+ )}
+ {allFiles.map((file) => {
+ const type = getDocumentType(file.name);
+ return (
+ <Tr key={file.id}>
+ <Td>
+ <HStack>
+ <DocumentIcon type={type} />
+ <span
+ className="font-medium cursor-pointer"
+ onClick={() => {
+ if (["PDF", "Image"].includes(type)) {
+ const bucket =
+ (file as any).bucket === "parts"
+ ? "parts"
+ : "job";
+ window.open(
+ path.to.file.previewFile(
+ `${"private"}/${getPath(
+ file,
+ bucket as "job" | "parts"
+ )}`
+ ),
+ "_blank"
+ );
+ } else {
+ download(file);
+ }
+ }}
>
- {modelUpload.modelName}
- </Hyperlink>
- </VStack>
- <ModelOptimizedIndicator
- modelPath={modelUpload.modelPath}
+ {["PDF", "Image"].includes(type) ? (
+ <DocumentPreview
+ bucket="private"
+ pathToFile={getPath(
+ file,
+ (file as any).bucket === "parts"
+ ? "parts"
+ : "job"
+ )}
+ // @ts-expect-error
+ type={type}
+ >
+ {file.name}
+ </DocumentPreview>
+ ) : (
+ file.name
+ )}
+ </span>
+ </HStack>
+ </Td>
+ <Td>
+ {convertKbToString(
+ Math.floor((file.metadata?.size ?? 0) / 1024)
+ )}
+ </Td>
+ <Td>
+ <Enumerable
+ value={
+ (file as any).bucket === "parts"
+ ? "Item"
+ : (file as any).bucket === "opportunity-line"
+ ? "Opportunity"
+ : "Job"
+ }
/>
- </HStack>
- </Td>
- <Td>
- {modelUpload.modelSize
- ? convertKbToString(
- Math.floor((modelUpload.modelSize ?? 0) / 1024)
- )
- : "--"}
- </Td>
- <Td>
- <Enumerable value="Job" />
- </Td>
- <Td className="text-xs font-mono">--</Td>
- <Td>
- <div className="flex justify-end w-full">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label={t`More`}
- icon={<LuEllipsisVertical />}
- variant="secondary"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
- shortcut={MENU_ITEM_SHORTCUTS.view}
- asChild
- >
- <Link to={getModelPath(modelUpload)}>
- <Trans>View</Trans>
- </Link>
- </DropdownMenuItem>
- <DropdownMenuItem
- shortcut={MENU_ITEM_SHORTCUTS.download}
- onClick={() => downloadModel(modelUpload)}
- >
- Download
- </DropdownMenuItem>
- <DropdownMenuItem
- destructive
- disabled={!canDelete || isReadOnly}
- onClick={() => deleteModel()}
- >
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- </Td>
- </Tr>
- )}
- {allFiles.map((file) => {
- const type = getDocumentType(file.name);
- return (
- <Tr key={file.id}>
- <Td>
- <HStack>
- <DocumentIcon type={type} />
- <span
- className="font-medium cursor-pointer"
- onClick={() => {
- if (["PDF", "Image"].includes(type)) {
- const bucket =
- (file as any).bucket === "parts"
- ? "parts"
- : "job";
- window.open(
- path.to.file.previewFile(
- `${"private"}/${getPath(
- file,
- bucket as "job" | "parts"
- )}`
- ),
- "_blank"
- );
- } else {
- download(file);
- }
- }}
- >
- {["PDF", "Image"].includes(type) ? (
- <DocumentPreview
- bucket="private"
- pathToFile={getPath(
- file,
- (file as any).bucket === "parts"
- ? "parts"
- : "job"
- )}
- // @ts-expect-error
- type={type}
- >
- {file.name}
- </DocumentPreview>
- ) : (
- file.name
- )}
- </span>
- </HStack>
- </Td>
- <Td>
- {convertKbToString(
- Math.floor((file.metadata?.size ?? 0) / 1024)
- )}
- </Td>
- <Td>
- <Enumerable
- value={
- (file as any).bucket === "parts"
- ? "Item"
- : (file as any).bucket === "opportunity-line"
- ? "Opportunity"
- : "Job"
- }
- />
- </Td>
- <Td className="text-xs font-mono">
- <DateTime
- value={file.created_at}
- variant="date"
- fallback="--"
- />
- </Td>
- <Td>
- <div className="flex justify-end w-full">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label={t`More`}
- icon={<LuEllipsisVertical />}
- variant="secondary"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
- shortcut={MENU_ITEM_SHORTCUTS.download}
- onClick={() => download(file)}
- >
- Download
- </DropdownMenuItem>
- {itemId &&
- (file as any).bucket !== "opportunity-line" && (
- <DropdownMenuSub>
- <DropdownMenuSubTrigger
- disabled={!canUpdate || isReadOnly}
- >
- Move to
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent>
- <DropdownMenuRadioGroup
- value={
- (file as any).bucket === "parts"
- ? "parts"
- : "job"
- }
- onValueChange={(value) =>
- moveFile(file, value as "job" | "parts")
- }
+ </Td>
+ <Td className="text-xs font-mono">
+ <DateTime
+ value={file.created_at}
+ variant="date"
+ fallback="--"
+ />
+ </Td>
+ <Td>
+ <div className="flex justify-end w-full">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label={t`More`}
+ icon={<LuEllipsisVertical />}
+ variant="secondary"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ shortcut={MENU_ITEM_SHORTCUTS.download}
+ onClick={() => download(file)}
+ >
+ Download
+ </DropdownMenuItem>
+ {itemId &&
+ (file as any).bucket !== "opportunity-line" && (
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger
+ disabled={!canUpdate || isReadOnly}
>
- <DropdownMenuRadioItem value="job">
- Job
- </DropdownMenuRadioItem>
- <DropdownMenuRadioItem value="parts">
- Item
- </DropdownMenuRadioItem>
- </DropdownMenuRadioGroup>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- )}
- <DropdownMenuItem
- destructive
- disabled={!canDelete || isReadOnly}
- onClick={() => deleteFile(file)}
- >
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
+ Move to
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ <DropdownMenuRadioGroup
+ value={
+ (file as any).bucket === "parts"
+ ? "parts"
+ : "job"
+ }
+ onValueChange={(value) =>
+ moveFile(
+ file,
+ value as "job" | "parts"
+ )
+ }
+ >
+ <DropdownMenuRadioItem value="job">
+ Job
+ </DropdownMenuRadioItem>
+ <DropdownMenuRadioItem value="parts">
+ Item
+ </DropdownMenuRadioItem>
+ </DropdownMenuRadioGroup>
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ )}
+ <DropdownMenuItem
+ destructive
+ disabled={!canDelete || isReadOnly}
+ onClick={() => deleteFile(file)}
+ >
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </Td>
+ </Tr>
+ );
+ })}
+ {allFiles.length === 0 && !modelUpload && (
+ <Tr>
+ <Td
+ colSpan={5}
+ className="py-8 text-muted-foreground text-center"
+ >
+ No files
</Td>
</Tr>
- );
- })}
- {allFiles.length === 0 && !modelUpload && (
- <Tr>
- <Td
- colSpan={5}
- className="py-8 text-muted-foreground text-center"
- >
- No files
- </Td>
- </Tr>
- )}
- </Tbody>
- </Table>
- {!isReadOnly && <FileDropzone onDrop={onDrop} />}
+ )}
+ </Tbody>
+ </Table>
+ )}
+ {!isReadOnly && !(isPhone && isEmpty) && (
+ <FileDropzone onDrop={onDrop} />
+ )}
</CardContent>
</Card>
</>
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx b/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx
index 8631e82c44..69a2385358 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx
@@ -32,6 +32,7 @@ import {
TooltipTrigger,
Tr,
toast,
+ useViewport,
VStack
} from "@carbon/react";
import { formatDurationMilliseconds, getItemReadableId } from "@carbon/utils";
@@ -42,6 +43,7 @@ import {
toZoned
} from "@internationalized/date";
import { Trans, useLingui } from "@lingui/react/macro";
+import type { ReactNode } from "react";
import { useEffect, useState } from "react";
import { LuCircleChevronRight, LuNotebook } from "react-icons/lu";
import { Link, useParams } from "react-router";
@@ -307,6 +309,21 @@ const JobEstimatesVsActuals = ({
const processesTotals = getProcessesTotals();
const materialsTotals = getMaterialsTotals();
+ // Phones: one row per operation or material instead of the wide table.
+ // A duration nobody has logged reads "–", not "0 milliseconds".
+ const { isPhone } = useViewport();
+ const duration = (ms: number) => (ms ? formatDurationMilliseconds(ms) : "–");
+ const ratio = (actual: number, estimated: number) =>
+ estimated ? percentFormatter.format(actual / estimated) : null;
+ const phoneTotal = (label: ReactNode, value: ReactNode, isOver: boolean) => (
+ <div className="flex items-center justify-between gap-3 py-3 font-semibold">
+ <span>{label}</span>
+ <span className={cn("tabular-nums", isOver && "text-red-500")}>
+ {value}
+ </span>
+ </div>
+ );
+
return (
<Tabs defaultValue="processes" className="w-full">
<Card>
@@ -329,430 +346,630 @@ const JobEstimatesVsActuals = ({
</HStack>
<CardContent>
<TabsContent value="processes">
- <Table>
- <Thead>
- <Tr>
- <Th className="px-2" />
- <Th className="px-2">Estimated</Th>
- <Th className="px-2">Actual</Th>
- <Th className="px-2">%</Th>
- <Th className="px-2">Complete</Th>
- <Th className="px-2">Scrap</Th>
- <Th className="px-2" />
- </Tr>
- </Thead>
- <Tbody>
+ {isPhone ? (
+ <div className="flex flex-col divide-y divide-border">
{operations.map((operation) => {
+ if (operation.operationType === "Outside Processing")
+ return null;
const estimated = getEstimatedTime(operation);
const actual = getActualTime(operation);
- const notes = getJobOperationNotes(operation);
-
- const isOutside =
- operation.operationType === "Outside Processing";
- if (isOutside) return null;
-
+ const isOver = actual.total > estimated.total;
return (
- <>
- <Tr key={operation.id} className="border-b border-border">
- <Td className="border-r border-border px-2">
- <HStack className="w-full justify-between ">
- <HStack spacing={2}>
- <span>{operation.description}</span>
- {operation.reworkId && (
- <Badge variant="red">Rework</Badge>
+ <div
+ key={operation.id}
+ className="flex flex-col gap-1.5 py-3"
+ >
+ <div className="flex min-w-0 items-center gap-2">
+ <JobOperationStatus operation={operation} />
+ <span className="min-w-0 flex-1 truncate font-medium">
+ {operation.description}
+ </span>
+ {operation.reworkId && (
+ <Badge variant="red">
+ <Trans>Rework</Trans>
+ </Badge>
+ )}
+ <span
+ className={cn(
+ "shrink-0 text-sm tabular-nums text-muted-foreground",
+ isOver && "text-red-500"
+ )}
+ >
+ {ratio(actual.total, estimated.total)}
+ </span>
+ <Link
+ to={`${path.to.jobProductionEvents(
+ jobId
+ )}?filter=jobOperationId:eq:${operation.id}`}
+ >
+ <IconButton
+ variant="ghost"
+ icon={<LuCircleChevronRight />}
+ aria-label={t`View Production Events`}
+ />
+ </Link>
+ </div>
+ <div className="flex flex-wrap gap-x-3 gap-y-1 text-sm text-muted-foreground">
+ <span>
+ <Trans>
+ Estimated{" "}
+ <span className="font-medium text-foreground tabular-nums">
+ {duration(estimated.total)}
+ </span>
+ </Trans>
+ </span>
+ <span>
+ <Trans>
+ Actual{" "}
+ <span
+ className={cn(
+ "font-medium text-foreground tabular-nums",
+ isOver && "text-red-500"
)}
- </HStack>
- <JobOperationStatus operation={operation} />
- </HStack>
- </Td>
- <Td className="px-2">
- <span className="flex-shrink-0">
- {formatDurationMilliseconds(estimated.total)}
- </span>
- </Td>
- <Td className="px-2">
- <span
- className={cn(
- "flex-shrink-0",
- actual.total > estimated.total && "text-red-500"
- )}
- >
- {formatDurationMilliseconds(actual.total)}
- </span>
- </Td>
- <Td className="px-2">
- <span
- className={cn(
- "line-clamp-1",
- actual.total > estimated.total && "text-red-500"
- )}
- >
- {estimated.total
- ? percentFormatter.format(
- actual.total / estimated.total
- )
- : null}
- </span>
- </Td>
- <Td className="px-2">
- {`${getCompleteQuantity(operation)}/${
- operation.targetQuantity ??
- operation.operationQuantity ??
- 0
- }`}
- </Td>
- <Td className="px-2">{getScrapQuantity(operation)}</Td>
- <Td className="px-2">
- <HStack spacing={0} className="justify-end">
- {notes && notes.length > 0 && (
- <Popover>
- <PopoverTrigger asChild>
- <IconButton
- variant="ghost"
- icon={<LuNotebook />}
- aria-label={t`Notes`}
- />
- </PopoverTrigger>
- <PopoverContent className="w-96 max-h-[300px] overflow-y-auto scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-gray-300">
- <div className="flex flex-col gap-3 p-2">
- {notes.map((note, index) => (
- <div
- key={index}
- className="flex gap-2 items-center"
- >
- <div className="flex-shrink-0">
- <EmployeeAvatar
- employeeId={note.createdBy}
- size="sm"
- withName={false}
- />
- </div>
- <div
- className={cn(
- "flex-1 rounded-lg p-2 text-sm",
- note.createdBy === user.id
- ? "bg-blue-500 text-white"
- : "bg-muted"
- )}
- >
- {note.note}
- </div>
- </div>
- ))}
- </div>
- </PopoverContent>
- </Popover>
- )}
- <Link
- to={`${path.to.jobProductionEvents(
- jobId
- )}?filter=jobOperationId:eq:${operation.id}`}
>
- <IconButton
- variant="ghost"
- icon={<LuCircleChevronRight />}
- aria-label={t`View Production Events`}
- />
- </Link>
- </HStack>
- </Td>
- </Tr>
-
+ {duration(actual.total)}
+ </span>
+ </Trans>
+ </span>
+ <span className="tabular-nums">
+ <Trans>
+ Complete {getCompleteQuantity(operation)}/
+ {operation.targetQuantity ??
+ operation.operationQuantity ??
+ 0}
+ </Trans>
+ </span>
+ {getScrapQuantity(operation) > 0 && (
+ <span className="tabular-nums">
+ <Trans>Scrap {getScrapQuantity(operation)}</Trans>
+ </span>
+ )}
+ </div>
{timeTypes.map((type) => {
- if (
- estimated[
- type.toLowerCase() as keyof typeof estimated
- ] === 0
- ) {
- return null;
- }
+ const key =
+ type.toLowerCase() as keyof typeof estimated;
+ if (estimated[key] === 0) return null;
const employeeIds = getEmployeeIds(operation, type);
- const notes = getNotes(operation, type);
return (
- <Tr key={type} className="border-b border-border">
- <Td className="border-r border-border pl-10">
- <HStack className="justify-between w-full">
- <HStack>
- <TimeTypeIcon type={type} />
- <span>{type}</span>
- </HStack>
- {employeeIds.length > 0 && (
- <EmployeeAvatarGroup
- employeeIds={employeeIds}
- size="xs"
- limit={3}
- />
+ <div
+ key={type}
+ className="flex items-center gap-2 text-sm text-muted-foreground"
+ >
+ <TimeTypeIcon type={type} />
+ <span>{type}</span>
+ {employeeIds.length > 0 && (
+ <EmployeeAvatarGroup
+ employeeIds={employeeIds}
+ size="xs"
+ limit={3}
+ />
+ )}
+ <span className="ml-auto tabular-nums">
+ <Trans>
+ {duration(actual[key])} of{" "}
+ {duration(estimated[key])}
+ </Trans>
+ </span>
+ </div>
+ );
+ })}
+ </div>
+ );
+ })}
+ {phoneTotal(
+ <Trans>Total</Trans>,
+ <Trans>
+ {duration(processesTotals.actual)} of{" "}
+ {duration(processesTotals.estimated)}
+ </Trans>,
+ processesTotals.actual > processesTotals.estimated
+ )}
+ </div>
+ ) : (
+ <Table>
+ <Thead>
+ <Tr>
+ <Th className="px-2" />
+ <Th className="px-2">Estimated</Th>
+ <Th className="px-2">Actual</Th>
+ <Th className="px-2">%</Th>
+ <Th className="px-2">Complete</Th>
+ <Th className="px-2">Scrap</Th>
+ <Th className="px-2" />
+ </Tr>
+ </Thead>
+ <Tbody>
+ {operations.map((operation) => {
+ const estimated = getEstimatedTime(operation);
+ const actual = getActualTime(operation);
+ const notes = getJobOperationNotes(operation);
+
+ const isOutside =
+ operation.operationType === "Outside Processing";
+ if (isOutside) return null;
+
+ return (
+ <>
+ <Tr
+ key={operation.id}
+ className="border-b border-border"
+ >
+ <Td className="border-r border-border px-2">
+ <HStack className="w-full justify-between ">
+ <HStack spacing={2}>
+ <span>{operation.description}</span>
+ {operation.reworkId && (
+ <Badge variant="red">Rework</Badge>
)}
</HStack>
- </Td>
- <Td className="px-2">
- {formatDurationMilliseconds(
- estimated[
- type.toLowerCase() as keyof typeof estimated
- ]
- )}
- </Td>
- <Td className="px-2">
- {formatDurationMilliseconds(
- actual[
- type.toLowerCase() as keyof typeof actual
- ]
+ <JobOperationStatus operation={operation} />
+ </HStack>
+ </Td>
+ <Td className="px-2">
+ <span className="flex-shrink-0">
+ {formatDurationMilliseconds(estimated.total)}
+ </span>
+ </Td>
+ <Td className="px-2">
+ <span
+ className={cn(
+ "flex-shrink-0",
+ actual.total > estimated.total && "text-red-500"
)}
- </Td>
- <Td className="px-2">
- {percentFormatter.format(
- actual[
- type.toLowerCase() as keyof typeof actual
- ] /
- estimated[
- type.toLowerCase() as keyof typeof estimated
- ]
+ >
+ {formatDurationMilliseconds(actual.total)}
+ </span>
+ </Td>
+ <Td className="px-2">
+ <span
+ className={cn(
+ "line-clamp-1",
+ actual.total > estimated.total && "text-red-500"
)}
- </Td>
- <Td className="px-2" />
- <Td className="px-2" />
- <Td className="px-2">
- <HStack spacing={0} className="justify-end">
- {notes && notes.length > 0 && (
- <Popover>
- <PopoverTrigger asChild>
- <IconButton
- variant="ghost"
- icon={<LuNotebook />}
- aria-label={t`Notes`}
- />
- </PopoverTrigger>
- <PopoverContent className="w-96 max-h-[300px] overflow-y-auto scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-gray-300">
- <div className="flex flex-col gap-3 p-2">
- {notes.map((note, index) => (
+ >
+ {estimated.total
+ ? percentFormatter.format(
+ actual.total / estimated.total
+ )
+ : null}
+ </span>
+ </Td>
+ <Td className="px-2">
+ {`${getCompleteQuantity(operation)}/${
+ operation.targetQuantity ??
+ operation.operationQuantity ??
+ 0
+ }`}
+ </Td>
+ <Td className="px-2">
+ {getScrapQuantity(operation)}
+ </Td>
+ <Td className="px-2">
+ <HStack spacing={0} className="justify-end">
+ {notes && notes.length > 0 && (
+ <Popover>
+ <PopoverTrigger asChild>
+ <IconButton
+ variant="ghost"
+ icon={<LuNotebook />}
+ aria-label={t`Notes`}
+ />
+ </PopoverTrigger>
+ <PopoverContent className="w-96 max-h-[300px] overflow-y-auto scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-gray-300">
+ <div className="flex flex-col gap-3 p-2">
+ {notes.map((note, index) => (
+ <div
+ key={index}
+ className="flex gap-2 items-center"
+ >
+ <div className="flex-shrink-0">
+ <EmployeeAvatar
+ employeeId={note.createdBy}
+ size="sm"
+ withName={false}
+ />
+ </div>
<div
- key={index}
- className="flex gap-2 items-center"
+ className={cn(
+ "flex-1 rounded-lg p-2 text-sm",
+ note.createdBy === user.id
+ ? "bg-blue-500 text-white"
+ : "bg-muted"
+ )}
>
- <div className="flex-shrink-0">
- <EmployeeAvatar
- employeeId={note.employeeId}
- size="sm"
- withName={false}
- />
- </div>
- <div className="flex-1 rounded-lg bg-muted p-2 text-sm">
- {note.notes}
- </div>
+ {note.note}
</div>
- ))}
- </div>
- </PopoverContent>
- </Popover>
+ </div>
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
+ )}
+ <Link
+ to={`${path.to.jobProductionEvents(
+ jobId
+ )}?filter=jobOperationId:eq:${operation.id}`}
+ >
+ <IconButton
+ variant="ghost"
+ icon={<LuCircleChevronRight />}
+ aria-label={t`View Production Events`}
+ />
+ </Link>
+ </HStack>
+ </Td>
+ </Tr>
+
+ {timeTypes.map((type) => {
+ if (
+ estimated[
+ type.toLowerCase() as keyof typeof estimated
+ ] === 0
+ ) {
+ return null;
+ }
+ const employeeIds = getEmployeeIds(operation, type);
+ const notes = getNotes(operation, type);
+ return (
+ <Tr key={type} className="border-b border-border">
+ <Td className="border-r border-border pl-10">
+ <HStack className="justify-between w-full">
+ <HStack>
+ <TimeTypeIcon type={type} />
+ <span>{type}</span>
+ </HStack>
+ {employeeIds.length > 0 && (
+ <EmployeeAvatarGroup
+ employeeIds={employeeIds}
+ size="xs"
+ limit={3}
+ />
+ )}
+ </HStack>
+ </Td>
+ <Td className="px-2">
+ {formatDurationMilliseconds(
+ estimated[
+ type.toLowerCase() as keyof typeof estimated
+ ]
)}
- <Link
- to={`${path.to.jobProductionEvents(
- jobId
- )}?filter=jobOperationId:eq:${
- operation.id
- }&filter=type:eq:${type}`}
- >
- <IconButton
- variant="ghost"
- icon={<LuCircleChevronRight />}
- aria-label={t`View Production Events`}
- />
- </Link>
- </HStack>
- </Td>
- </Tr>
- );
- })}
- </>
- );
- })}
- </Tbody>
- <Tfoot>
- <Tr className="font-bold bg-muted/50">
- <Td className="border-r border-border px-2">
- <Trans>Total</Trans>
- </Td>
- <Td className="px-2">
- {formatDurationMilliseconds(processesTotals.estimated)}
- </Td>
- <Td
- className={cn(
- "px-2",
- processesTotals.actual > processesTotals.estimated &&
- "text-red-500"
- )}
- >
- {formatDurationMilliseconds(processesTotals.actual)}
- </Td>
- <Td
- className={cn(
- processesTotals.actual > processesTotals.estimated &&
- "text-red-500"
- )}
- >
- {processesTotals.estimated > 0
- ? percentFormatter.format(processesTotals.percentage)
- : null}
- </Td>
- <Td className="px-2">{processesTotals.complete}</Td>
- <Td className="px-2">{processesTotals.scrap}</Td>
- <Td className="px-2" />
- </Tr>
- </Tfoot>
- </Table>
+ </Td>
+ <Td className="px-2">
+ {formatDurationMilliseconds(
+ actual[
+ type.toLowerCase() as keyof typeof actual
+ ]
+ )}
+ </Td>
+ <Td className="px-2">
+ {percentFormatter.format(
+ actual[
+ type.toLowerCase() as keyof typeof actual
+ ] /
+ estimated[
+ type.toLowerCase() as keyof typeof estimated
+ ]
+ )}
+ </Td>
+ <Td className="px-2" />
+ <Td className="px-2" />
+ <Td className="px-2">
+ <HStack spacing={0} className="justify-end">
+ {notes && notes.length > 0 && (
+ <Popover>
+ <PopoverTrigger asChild>
+ <IconButton
+ variant="ghost"
+ icon={<LuNotebook />}
+ aria-label={t`Notes`}
+ />
+ </PopoverTrigger>
+ <PopoverContent className="w-96 max-h-[300px] overflow-y-auto scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-gray-300">
+ <div className="flex flex-col gap-3 p-2">
+ {notes.map((note, index) => (
+ <div
+ key={index}
+ className="flex gap-2 items-center"
+ >
+ <div className="flex-shrink-0">
+ <EmployeeAvatar
+ employeeId={note.employeeId}
+ size="sm"
+ withName={false}
+ />
+ </div>
+ <div className="flex-1 rounded-lg bg-muted p-2 text-sm">
+ {note.notes}
+ </div>
+ </div>
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
+ )}
+ <Link
+ to={`${path.to.jobProductionEvents(
+ jobId
+ )}?filter=jobOperationId:eq:${
+ operation.id
+ }&filter=type:eq:${type}`}
+ >
+ <IconButton
+ variant="ghost"
+ icon={<LuCircleChevronRight />}
+ aria-label={t`View Production Events`}
+ />
+ </Link>
+ </HStack>
+ </Td>
+ </Tr>
+ );
+ })}
+ </>
+ );
+ })}
+ </Tbody>
+ <Tfoot>
+ <Tr className="font-bold bg-muted/50">
+ <Td className="border-r border-border px-2">
+ <Trans>Total</Trans>
+ </Td>
+ <Td className="px-2">
+ {formatDurationMilliseconds(processesTotals.estimated)}
+ </Td>
+ <Td
+ className={cn(
+ "px-2",
+ processesTotals.actual > processesTotals.estimated &&
+ "text-red-500"
+ )}
+ >
+ {formatDurationMilliseconds(processesTotals.actual)}
+ </Td>
+ <Td
+ className={cn(
+ processesTotals.actual > processesTotals.estimated &&
+ "text-red-500"
+ )}
+ >
+ {processesTotals.estimated > 0
+ ? percentFormatter.format(processesTotals.percentage)
+ : null}
+ </Td>
+ <Td className="px-2">{processesTotals.complete}</Td>
+ <Td className="px-2">{processesTotals.scrap}</Td>
+ <Td className="px-2" />
+ </Tr>
+ </Tfoot>
+ </Table>
+ )}
</TabsContent>
<TabsContent value="materials">
- <Table>
- <Thead>
- <Tr>
- <Th>Material</Th>
- <Th>Estimated</Th>
- <Th>Actual</Th>
- <Th>%</Th>
-
- <Th>Estimated</Th>
- <Th>Actual</Th>
- </Tr>
- </Thead>
- <Tbody>
+ {isPhone ? (
+ <div className="flex flex-col divide-y divide-border">
{materials?.map((material) => {
- const exceedsEstimate =
- material.quantityIssued &&
- material.quantityIssued > (material.estimatedQuantity ?? 0);
- const currentUnitCost =
- currentUnitCosts[material.itemId] ?? 0;
-
+ const isMade = material.methodType === "Make to Order";
+ const isOver =
+ (material.quantityIssued ?? 0) >
+ (material.estimatedQuantity ?? 0);
const estimatedTotalCost =
(material.estimatedQuantity ?? 0) *
(material.unitCost ?? 0);
const actualTotalCost =
- (material.quantityIssued ?? 0) * currentUnitCost;
-
+ (material.quantityIssued ?? 0) *
+ (currentUnitCosts[material.itemId] ?? 0);
return (
- <Tr key={material.id} className="border-b border-border">
- <Td className="border-r border-border">
- <HStack className="w-full justify-start">
- <Tooltip>
- <TooltipTrigger>
- <MethodIcon type={material.methodType} />
- </TooltipTrigger>
- <TooltipContent>
- {material.methodType}
- </TooltipContent>
- </Tooltip>
- <span>
- {getItemReadableId(items, material.itemId)}
+ <div key={material.id} className="flex flex-col gap-1 py-3">
+ <div className="flex min-w-0 items-center gap-2">
+ <MethodIcon type={material.methodType} />
+ <span className="min-w-0 flex-1 truncate font-medium">
+ {getItemReadableId(items, material.itemId)}
+ </span>
+ {!isMade && (
+ <span
+ className={cn(
+ "shrink-0 text-sm tabular-nums text-muted-foreground",
+ isOver && "text-red-500"
+ )}
+ >
+ {material.quantityIssued
+ ? ratio(
+ material.quantityIssued,
+ material.estimatedQuantity ?? 0
+ )
+ : null}
</span>
- </HStack>
- </Td>
- <Td>{material.estimatedQuantity}</Td>
- <Td className={cn(exceedsEstimate && "text-red-500")}>
- {material.methodType === "Make to Order" ? (
- <MethodIcon type="Make to Order" />
- ) : (
- material.quantityIssued
)}
- </Td>
-
- <Td className={cn(exceedsEstimate && "text-red-500")}>
- {material.methodType !== "Make to Order" &&
- material.estimatedQuantity &&
- material.quantityIssued
- ? percentFormatter.format(
- material.quantityIssued /
- material.estimatedQuantity
- )
- : null}
- </Td>
- <Td>
- {material.methodType === "Make to Order" ? null : (
- <VStack spacing={0} className="py-1">
- <span className="text-sm">
+ </div>
+ {!isMade && (
+ <div className="flex flex-wrap gap-x-3 gap-y-1 pl-6 text-sm text-muted-foreground tabular-nums">
+ <span className={cn(isOver && "text-red-500")}>
+ <Trans>
+ {material.quantityIssued ?? 0} of{" "}
+ {material.estimatedQuantity ?? 0}
+ </Trans>
+ </span>
+ <span
+ className={cn(
+ actualTotalCost > estimatedTotalCost &&
+ "text-red-500"
+ )}
+ >
+ <Trans>
+ {currencyFormatter.format(actualTotalCost)} of{" "}
{currencyFormatter.format(estimatedTotalCost)}
- </span>
- <span className="text-xxs">
- {currencyFormatter.format(material.unitCost ?? 0)}
- </span>
- </VStack>
- )}
- </Td>
- <Td>
- {material.methodType === "Make to Order" ? null : (
- <VStack spacing={0} className="py-1">
- <span
- className={cn(
- "text-sm",
- actualTotalCost > estimatedTotalCost &&
- "text-red-500"
- )}
- >
- {currencyFormatter.format(actualTotalCost)}
- </span>
- <span
- className={cn(
- "text-xxs",
- currentUnitCost > material.unitCost &&
- "text-red-500"
- )}
- >
- {currencyFormatter.format(currentUnitCost)}
- </span>
- </VStack>
- )}
- </Td>
- </Tr>
+ </Trans>
+ </span>
+ </div>
+ )}
+ </div>
);
})}
- </Tbody>
- <Tfoot>
- <Tr className="font-bold bg-muted/50">
- <Td className="border-r border-border">
- <Trans>Total</Trans>
- </Td>
- <Td>{materialsTotals.estimatedQty || null}</Td>
- <Td
- className={cn(
- materialsTotals.actualQty >
- materialsTotals.estimatedQty && "text-red-500"
- )}
- >
- {materialsTotals.actualQty || null}
- </Td>
- <Td
- className={cn(
- materialsTotals.actualQty >
- materialsTotals.estimatedQty && "text-red-500"
- )}
- >
- {materialsTotals.estimatedQty > 0
- ? percentFormatter.format(materialsTotals.percentage)
- : null}
- </Td>
- <Td>
- <VStack spacing={0} className="py-1">
- <span className="text-sm">
- {currencyFormatter.format(
- materialsTotals.estimatedCost
- )}
- </span>
- </VStack>
- </Td>
- <Td>
- <VStack spacing={0} className="py-1">
- <span
- className={cn(
- "text-sm",
- materialsTotals.actualCost >
- materialsTotals.estimatedCost && "text-red-500"
- )}
- >
- {currencyFormatter.format(materialsTotals.actualCost)}
- </span>
- </VStack>
- </Td>
- </Tr>
- </Tfoot>
- </Table>
+ {phoneTotal(
+ <Trans>Total</Trans>,
+ <Trans>
+ {currencyFormatter.format(materialsTotals.actualCost)} of{" "}
+ {currencyFormatter.format(materialsTotals.estimatedCost)}
+ </Trans>,
+ materialsTotals.actualCost > materialsTotals.estimatedCost
+ )}
+ </div>
+ ) : (
+ <Table>
+ <Thead>
+ <Tr>
+ <Th>Material</Th>
+ <Th>Estimated</Th>
+ <Th>Actual</Th>
+ <Th>%</Th>
+
+ <Th>Estimated</Th>
+ <Th>Actual</Th>
+ </Tr>
+ </Thead>
+ <Tbody>
+ {materials?.map((material) => {
+ const exceedsEstimate =
+ material.quantityIssued &&
+ material.quantityIssued >
+ (material.estimatedQuantity ?? 0);
+ const currentUnitCost =
+ currentUnitCosts[material.itemId] ?? 0;
+
+ const estimatedTotalCost =
+ (material.estimatedQuantity ?? 0) *
+ (material.unitCost ?? 0);
+ const actualTotalCost =
+ (material.quantityIssued ?? 0) * currentUnitCost;
+
+ return (
+ <Tr key={material.id} className="border-b border-border">
+ <Td className="border-r border-border">
+ <HStack className="w-full justify-start">
+ <Tooltip>
+ <TooltipTrigger>
+ <MethodIcon type={material.methodType} />
+ </TooltipTrigger>
+ <TooltipContent>
+ {material.methodType}
+ </TooltipContent>
+ </Tooltip>
+ <span>
+ {getItemReadableId(items, material.itemId)}
+ </span>
+ </HStack>
+ </Td>
+ <Td>{material.estimatedQuantity}</Td>
+ <Td className={cn(exceedsEstimate && "text-red-500")}>
+ {material.methodType === "Make to Order" ? (
+ <MethodIcon type="Make to Order" />
+ ) : (
+ material.quantityIssued
+ )}
+ </Td>
+
+ <Td className={cn(exceedsEstimate && "text-red-500")}>
+ {material.methodType !== "Make to Order" &&
+ material.estimatedQuantity &&
+ material.quantityIssued
+ ? percentFormatter.format(
+ material.quantityIssued /
+ material.estimatedQuantity
+ )
+ : null}
+ </Td>
+ <Td>
+ {material.methodType === "Make to Order" ? null : (
+ <VStack spacing={0} className="py-1">
+ <span className="text-sm">
+ {currencyFormatter.format(estimatedTotalCost)}
+ </span>
+ <span className="text-xxs">
+ {currencyFormatter.format(
+ material.unitCost ?? 0
+ )}
+ </span>
+ </VStack>
+ )}
+ </Td>
+ <Td>
+ {material.methodType === "Make to Order" ? null : (
+ <VStack spacing={0} className="py-1">
+ <span
+ className={cn(
+ "text-sm",
+ actualTotalCost > estimatedTotalCost &&
+ "text-red-500"
+ )}
+ >
+ {currencyFormatter.format(actualTotalCost)}
+ </span>
+ <span
+ className={cn(
+ "text-xxs",
+ currentUnitCost > material.unitCost &&
+ "text-red-500"
+ )}
+ >
+ {currencyFormatter.format(currentUnitCost)}
+ </span>
+ </VStack>
+ )}
+ </Td>
+ </Tr>
+ );
+ })}
+ </Tbody>
+ <Tfoot>
+ <Tr className="font-bold bg-muted/50">
+ <Td className="border-r border-border">
+ <Trans>Total</Trans>
+ </Td>
+ <Td>{materialsTotals.estimatedQty || null}</Td>
+ <Td
+ className={cn(
+ materialsTotals.actualQty >
+ materialsTotals.estimatedQty && "text-red-500"
+ )}
+ >
+ {materialsTotals.actualQty || null}
+ </Td>
+ <Td
+ className={cn(
+ materialsTotals.actualQty >
+ materialsTotals.estimatedQty && "text-red-500"
+ )}
+ >
+ {materialsTotals.estimatedQty > 0
+ ? percentFormatter.format(materialsTotals.percentage)
+ : null}
+ </Td>
+ <Td>
+ <VStack spacing={0} className="py-1">
+ <span className="text-sm">
+ {currencyFormatter.format(
+ materialsTotals.estimatedCost
+ )}
+ </span>
+ </VStack>
+ </Td>
+ <Td>
+ <VStack spacing={0} className="py-1">
+ <span
+ className={cn(
+ "text-sm",
+ materialsTotals.actualCost >
+ materialsTotals.estimatedCost && "text-red-500"
+ )}
+ >
+ {currencyFormatter.format(materialsTotals.actualCost)}
+ </span>
+ </VStack>
+ </Td>
+ </Tr>
+ </Tfoot>
+ </Table>
+ )}
</TabsContent>
</CardContent>
</Card>
diff --git a/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegisterCard.tsx b/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegisterCard.tsx
index 03b337cedc..738755d5c6 100644
--- a/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegisterCard.tsx
+++ b/apps/erp/app/modules/quality/ui/RiskRegister/RiskRegisterCard.tsx
@@ -16,7 +16,8 @@ import {
IconButton,
Loading,
toast,
- useDisclosure
+ useDisclosure,
+ useViewport
} from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { useCallback, useEffect, useState } from "react";
@@ -55,6 +56,7 @@ export default function RiskRegisterCard({
const [risks, setRisks] = useState<Risk[]>([]);
const [loading, setLoading] = useState(false);
+ const { isPhone } = useViewport();
const formDisclosure = useDisclosure();
const deleteDisclosure = useDisclosure();
const [selectedRisk, setSelectedRisk] = useState<Risk | undefined>(undefined);
@@ -125,7 +127,13 @@ export default function RiskRegisterCard({
<Loading isLoading={true} />
</div>
) : risks.length === 0 ? (
- <Empty className="py-8" />
+ isPhone ? (
+ <p className="text-sm text-muted-foreground">
+ <Trans>No risks</Trans>
+ </p>
+ ) : (
+ <Empty className="py-8" />
+ )
) : (
<div className="flex flex-col gap-4">
{risks.map((risk) => (
diff --git a/apps/erp/app/routes/x+/job+/$jobId.tsx b/apps/erp/app/routes/x+/job+/$jobId.tsx
index 11868587af..fcf733449c 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.tsx
@@ -177,7 +177,7 @@ export default function JobRoute() {
<div className="flex h-[calc(100dvh-var(--topbar-height)-var(--header-height)-var(--content-inset))] overflow-hidden w-full">
<div className="flex flex-grow overflow-hidden">
<ResizablePanels
- explorerLabel={t`Bill of Materials`}
+ explorerLabel={t`Structure`}
explorer={
<div className="w-full h-full p-2">
<Suspense fallback={<ExplorerSkeleton />}>
diff --git a/apps/erp/app/routes/x+/production+/_index.tsx b/apps/erp/app/routes/x+/production+/_index.tsx
index ece5a49257..819a77487d 100644
--- a/apps/erp/app/routes/x+/production+/_index.tsx
+++ b/apps/erp/app/routes/x+/production+/_index.tsx
@@ -76,6 +76,7 @@ import {
MetricCard
} from "~/components";
import { CSVLink } from "~/components/CSVLink";
+import { usePercentFormatter } from "~/hooks";
import { useUser } from "~/hooks/useUser";
import type { ActiveProductionEvent } from "~/modules/production";
import {
@@ -352,17 +353,19 @@ export default function ProductionDashboard() {
/>
<Card className="col-span-1 lg:col-span-6 max-md:col-span-2">
- <HStack className="flex-col items-start gap-2 sm:flex-row sm:justify-between sm:items-center">
- <CardHeader>
- <div className="flex w-full justify-start items-center gap-2">
+ <HStack className="flex-col items-start gap-2 sm:flex-row sm:justify-between sm:items-center max-md:flex-row max-md:items-center max-md:gap-1.5 max-md:px-3 max-md:pt-3">
+ <CardHeader className="max-md:min-w-0 max-md:flex-1 max-md:p-0">
+ <div className="flex w-full min-w-0 justify-start items-center gap-2">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="secondary"
rightIcon={<LuChevronDown />}
- className="hover:bg-background/80"
+ className="hover:bg-background/80 max-md:min-w-0 max-md:flex-1 max-md:justify-between"
>
- <span>{kpiLabels[selectedKpiData.key]}</span>
+ <span className="truncate">
+ {kpiLabels[selectedKpiData.key]}
+ </span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="start">
@@ -381,7 +384,7 @@ export default function ProductionDashboard() {
</DropdownMenu>
</div>
</CardHeader>
- <CardAction className="flex-row items-center gap-2">
+ <CardAction className="flex-row items-center gap-2 max-md:shrink-0 max-md:gap-1.5 max-md:p-0">
<DateSelect
value={interval}
onValueChange={onIntervalChange}
@@ -441,6 +444,14 @@ export default function ProductionDashboard() {
</p>
</Empty>
</div>
+ ) : isPhone ? (
+ <Loading isLoading={isFetching} className="w-full">
+ <KpiBarList
+ kpi={selectedKpi}
+ data={kpiFetcher.data?.data ?? []}
+ totalTimeInInterval={totalTimeInInterval}
+ />
+ </Loading>
) : (
<Loading isLoading={isFetching} className="w-full">
<ChartContainer
@@ -456,10 +467,7 @@ export default function ProductionDashboard() {
accessibilityLayer
data={kpiFetcher.data?.data ?? []}
layout="vertical"
- margin={{
- // Phones: room for the top bar's value label.
- right: isPhone ? 48 : 30
- }}
+ margin={{ right: 30 }}
>
<YAxis
dataKey="key"
@@ -609,6 +617,103 @@ export default function ProductionDashboard() {
);
}
+type KpiRow = {
+ key: string;
+ value?: number;
+ actual?: number;
+ estimate?: number;
+};
+
+/**
+ * Phones: the KPI chart as a list. A bar chart's category axis takes half of
+ * a phone's width, so each row puts its name and value on one line and draws
+ * the bar underneath at full width.
+ */
+function KpiBarList({
+ kpi,
+ data,
+ totalTimeInInterval
+}: {
+ kpi: (typeof KPIs)[number]["key"];
+ data: KpiRow[];
+ totalTimeInInterval: number;
+}) {
+ const percentFormatter = usePercentFormatter();
+ const isComparison = kpi === "estimatesVsActuals";
+ const max = Math.max(
+ 1,
+ ...data.map((row) =>
+ isComparison
+ ? Math.max(row.actual ?? 0, row.estimate ?? 0)
+ : (row.value ?? 0)
+ )
+ );
+ const width = (value = 0) => ({ width: `${(value / max) * 100}%` });
+
+ return (
+ <div className="flex w-full flex-col gap-3">
+ {isComparison && (
+ <div className="flex gap-4 text-xs text-muted-foreground">
+ <span className="inline-flex items-center gap-1.5">
+ <span className="size-2.5 rounded-sm bg-[hsl(var(--chart-1))]" />
+ <Trans>Actual</Trans>
+ </span>
+ <span className="inline-flex items-center gap-1.5">
+ <span className="size-2.5 rounded-sm bg-[hsl(var(--chart-2))]" />
+ <Trans>Estimate</Trans>
+ </span>
+ </div>
+ )}
+ {data.map((row) => (
+ <div key={row.key} className="flex flex-col gap-1.5">
+ <div className="flex items-baseline justify-between gap-2 text-sm">
+ <span className="truncate">{row.key}</span>
+ <span className="shrink-0 tabular-nums text-muted-foreground">
+ {isComparison ? (
+ <Trans>
+ {formatDurationMilliseconds(row.actual ?? 0)} of{" "}
+ {formatDurationMilliseconds(row.estimate ?? 0)}
+ </Trans>
+ ) : kpi === "utilization" ? (
+ `${formatDurationMilliseconds(row.value ?? 0)} · ${percentFormatter.format(
+ totalTimeInInterval === 0
+ ? 0
+ : (row.value ?? 0) / totalTimeInInterval
+ )}`
+ ) : (
+ formatDurationMilliseconds(row.value ?? 0)
+ )}
+ </span>
+ </div>
+ {isComparison ? (
+ <div className="flex flex-col gap-0.5">
+ <div className="h-2 overflow-hidden rounded bg-muted">
+ <div
+ className="h-full rounded bg-[hsl(var(--chart-1))]"
+ style={width(row.actual)}
+ />
+ </div>
+ <div className="h-2 overflow-hidden rounded bg-muted">
+ <div
+ className="h-full rounded bg-[hsl(var(--chart-2))]"
+ style={width(row.estimate)}
+ />
+ </div>
+ </div>
+ ) : (
+ <div className="h-2 overflow-hidden rounded bg-muted">
+ <div
+ className="h-full rounded bg-primary"
+ style={width(row.value)}
+ />
+ </div>
+ )}
+ </div>
+ ))}
+ </div>
+ );
+}
+
type JobOperationMetaData = {
customerId?: string | null;
deadlineType?: "No Deadline" | "ASAP" | "Soft Deadline" | "Hard Deadline";
@@ -635,6 +740,7 @@ function WorkCenterCards({
workCenters: WorkCenterWithBlocking[];
}) {
const { t } = useLingui();
+ const { isPhone } = useViewport();
const [events, setEvents] = useState<ActiveProductionEvent[]>(initialEvents);
const [jobOperationMetaData, setJobOperationMetaData] = useState<
Record<string, JobOperationMetaData>
@@ -783,193 +889,303 @@ function WorkCenterCards({
}
});
- return (
- <div className="w-full grid grid-cols-6 gap-4 max-md:gap-3">
- {workCenters.map((workCenter) => {
- const {
- hasEvents,
- customerId,
- deadlineType,
- description,
- descriptionCount,
- dueDate,
- employeeIds,
- jobCount,
- jobId,
- jobReadableId,
- salesOrderId,
- salesOrderReadableId,
- salesOrderLineId
- } = eventsByWorkCenterId[workCenter?.id ?? ""];
-
- const isOverdue =
- deadlineType !== "No Deadline" && dueDate
- ? new Date(dueDate) < new Date()
- : false;
-
- const isBlocked = workCenter.isBlocked && workCenter.blockingDispatchId;
-
- return (
- <Card
- key={workCenter.id}
- className={cn(
- "p-0 h-[300px] col-span-6 max-md:col-span-full lg:col-span-3 xl:col-span-2",
- isBlocked && "bg-red-100 dark:bg-red-900/50"
- )}
- >
- <HStack
- className={cn(
- "justify-between w-full relative",
- isBlocked && "text-red-800 dark:text-red-400"
- )}
- >
- <CardHeader>
- <CardTitle className="line-clamp-2 text-base">
- {workCenter.name}
- </CardTitle>
- {isBlocked && (
- <Tooltip>
- <TooltipTrigger asChild>
- <Link
- to={path.to.maintenanceDispatch(
- workCenter.blockingDispatchId!
- )}
- className="inline-flex items-center gap-1 text-xs font-normal"
- >
- <span>
- <Trans>
- Blocked by {workCenter.blockingDispatchReadableId}
- </Trans>
- </span>
- </Link>
- </TooltipTrigger>
- <TooltipContent>
- <p>
- <Trans>View maintenance dispatch</Trans>
- </p>
- </TooltipContent>
- </Tooltip>
+ const cards = workCenters.map((workCenter) => {
+ const {
+ hasEvents,
+ customerId,
+ deadlineType,
+ description,
+ descriptionCount,
+ dueDate,
+ employeeIds,
+ jobCount,
+ jobId,
+ jobReadableId,
+ salesOrderId,
+ salesOrderReadableId,
+ salesOrderLineId
+ } = eventsByWorkCenterId[workCenter?.id ?? ""];
+
+ const isOverdue =
+ deadlineType !== "No Deadline" && dueDate
+ ? new Date(dueDate) < new Date()
+ : false;
+
+ const isBlocked = workCenter.isBlocked && workCenter.blockingDispatchId;
+
+ const deadlineLabel = deadlineType
+ ? ["ASAP", "No Deadline"].includes(deadlineType)
+ ? deadlineType
+ : dueDate
+ ? t`Due ${formatRelativeTime(convertDateStringToIsoString(dueDate))}`
+ : "–"
+ : null;
+
+ if (isPhone) {
+ // Phones: one row per work center in a single card, with every
+ // fact the desktop card shows.
+ return (
+ <div
+ key={workCenter.id}
+ className={cn(
+ "flex items-start gap-3 px-4 py-3",
+ isBlocked && "bg-red-100 dark:bg-red-900/40"
+ )}
+ >
+ {isBlocked ? (
+ <span className="mt-2 size-2 shrink-0 rounded-full bg-red-500" />
+ ) : (
+ <PulsingDot inactive={!hasEvents} className="mt-2 shrink-0" />
+ )}
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5 text-sm">
+ <p className="truncate text-base font-medium">{workCenter.name}</p>
+ {isBlocked ? (
+ <Link
+ to={path.to.maintenanceDispatch(workCenter.blockingDispatchId!)}
+ className="text-red-800 dark:text-red-400"
+ >
+ <Trans>
+ Blocked by {workCenter.blockingDispatchReadableId}
+ </Trans>
+ </Link>
+ ) : !hasEvents ? (
+ <p className="text-muted-foreground">
+ <Trans>Inactive</Trans>
+ </p>
+ ) : (
+ <>
+ {(jobReadableId || description) && (
+ <p className="flex min-w-0 items-center gap-1.5 text-muted-foreground">
+ {jobId && jobReadableId && (
+ <Hyperlink to={path.to.job(jobId)} className="shrink-0">
+ {jobReadableId}
+ </Hyperlink>
+ )}
+ {jobCount !== undefined && jobCount > 1 && (
+ <span className="shrink-0 font-mono">{`+${jobCount - 1}`}</span>
+ )}
+ {description && (
+ <span className="truncate">{description}</span>
+ )}
+ {descriptionCount !== undefined && descriptionCount > 1 && (
+ <span className="shrink-0 font-mono">{`+${descriptionCount - 1}`}</span>
+ )}
+ </p>
)}
- </CardHeader>
- <CardAction className="pt-2">
- {!isBlocked && (
- <PulsingDot inactive={!hasEvents} className="mt-2" />
+ {(salesOrderReadableId || customerId) && (
+ <div className="flex min-w-0 items-center gap-2">
+ {salesOrderId &&
+ salesOrderLineId &&
+ salesOrderReadableId && (
+ <Hyperlink
+ to={path.to.salesOrderLine(
+ salesOrderId,
+ salesOrderLineId
+ )}
+ className="shrink-0"
+ >
+ {salesOrderReadableId}
+ </Hyperlink>
+ )}
+ {customerId && (
+ <span className="min-w-0 truncate">
+ <CustomerAvatar customerId={customerId} />
+ </span>
+ )}
+ </div>
)}
- </CardAction>
- </HStack>
- <CardContent
- className={cn(
- "flex items-start justify-start p-6 pt-3 border-t",
- // the content's own dark background is translucent; keep the
- // red card color from bleeding through it
- isBlocked && "dark:bg-card"
- )}
- >
- {!hasEvents ? (
- <p className="text-muted-foreground text-center w-full h-full flex flex-col gap-2 items-center justify-center text-sm">
- <Trans>Inactive</Trans>
- </p>
+ {deadlineType && (
+ <p
+ className={cn(
+ "flex items-center gap-1.5",
+ isOverdue ? "text-red-500" : "text-muted-foreground"
+ )}
+ >
+ {getDeadlineIcon(deadlineType)}
+ <span className="truncate">{deadlineLabel}</span>
+ </p>
+ )}
+ </>
+ )}
+ </div>
+ {employeeIds?.length ? (
+ <div className="shrink-0">
+ {employeeIds.length > 1 ? (
+ <EmployeeAvatarGroup
+ employeeIds={employeeIds.filter((id) => id !== null)}
+ />
) : (
- <div className="flex flex-col gap-2 items-start justify-start text-sm">
- {jobId && jobReadableId && (
- <HStack className="justify-start space-x-2">
- <LuCirclePlay className="text-muted-foreground flex-shrink-0" />
- <Hyperlink to={path.to.job(jobId)} className="truncate">
- {jobReadableId}
- </Hyperlink>
- {jobCount !== undefined &&
- Number.isInteger(jobCount) &&
- jobCount > 1 && (
- <div className="text-muted-foreground font-mono font-semibold flex items-center justify-center flex-shrink-0">
- {`+${jobCount - 1}`}
- </div>
- )}
- </HStack>
- )}
+ <EmployeeAvatar employeeId={employeeIds[0]} withName={false} />
+ )}
+ </div>
+ ) : null}
+ </div>
+ );
+ }
- {description && (
- <HStack className="justify-start space-x-2">
- <LuClipboardCheck className="text-muted-foreground flex-shrink-0" />
- <span className="text-sm line-clamp-1 truncate">
- {description}
- </span>
- {descriptionCount !== undefined &&
- Number.isInteger(descriptionCount) &&
- descriptionCount > 1 && (
- <div className="text-muted-foreground font-mono font-semibold flex items-center justify-center flex-shrink-0">
- {`+${descriptionCount - 1}`}
- </div>
- )}
- </HStack>
- )}
+ return (
+ <Card
+ key={workCenter.id}
+ className={cn(
+ "p-0 h-[300px] col-span-6 max-md:col-span-full lg:col-span-3 xl:col-span-2",
+ isBlocked && "bg-red-100 dark:bg-red-900/50"
+ )}
+ >
+ <HStack
+ className={cn(
+ "justify-between w-full relative",
+ isBlocked && "text-red-800 dark:text-red-400"
+ )}
+ >
+ <CardHeader>
+ <CardTitle className="line-clamp-2 text-base">
+ {workCenter.name}
+ </CardTitle>
+ {isBlocked && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Link
+ to={path.to.maintenanceDispatch(
+ workCenter.blockingDispatchId!
+ )}
+ className="inline-flex items-center gap-1 text-xs font-normal"
+ >
+ <span>
+ <Trans>
+ Blocked by {workCenter.blockingDispatchReadableId}
+ </Trans>
+ </span>
+ </Link>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>
+ <Trans>View maintenance dispatch</Trans>
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </CardHeader>
+ <CardAction className="pt-2">
+ {!isBlocked && (
+ <PulsingDot inactive={!hasEvents} className="mt-2" />
+ )}
+ </CardAction>
+ </HStack>
+ <CardContent
+ className={cn(
+ "flex items-start justify-start p-6 pt-3 border-t",
+ // the content's own dark background is translucent; keep the
+ // red card color from bleeding through it
+ isBlocked && "dark:bg-card"
+ )}
+ >
+ {!hasEvents ? (
+ <p className="text-muted-foreground text-center w-full h-full flex flex-col gap-2 items-center justify-center text-sm">
+ <Trans>Inactive</Trans>
+ </p>
+ ) : (
+ <div className="flex flex-col gap-2 items-start justify-start text-sm">
+ {jobId && jobReadableId && (
+ <HStack className="justify-start space-x-2">
+ <LuCirclePlay className="text-muted-foreground flex-shrink-0" />
+ <Hyperlink to={path.to.job(jobId)} className="truncate">
+ {jobReadableId}
+ </Hyperlink>
+ {jobCount !== undefined &&
+ Number.isInteger(jobCount) &&
+ jobCount > 1 && (
+ <div className="text-muted-foreground font-mono font-semibold flex items-center justify-center flex-shrink-0">
+ {`+${jobCount - 1}`}
+ </div>
+ )}
+ </HStack>
+ )}
- {salesOrderId && salesOrderLineId && salesOrderReadableId && (
- <HStack className="justify-start space-x-2">
- <RiProgress8Line className="text-muted-foreground flex-shrink-0" />
- <Hyperlink
- to={path.to.salesOrderLine(
- salesOrderId,
- salesOrderLineId
- )}
- className="truncate"
- >
- {salesOrderReadableId}
- </Hyperlink>
- </HStack>
- )}
+ {description && (
+ <HStack className="justify-start space-x-2">
+ <LuClipboardCheck className="text-muted-foreground flex-shrink-0" />
+ <span className="text-sm line-clamp-1 truncate">
+ {description}
+ </span>
+ {descriptionCount !== undefined &&
+ Number.isInteger(descriptionCount) &&
+ descriptionCount > 1 && (
+ <div className="text-muted-foreground font-mono font-semibold flex items-center justify-center flex-shrink-0">
+ {`+${descriptionCount - 1}`}
+ </div>
+ )}
+ </HStack>
+ )}
- {customerId && (
- <HStack className="justify-start space-x-2">
- <LuInbox className="text-muted-foreground flex-shrink-0" />
- <CustomerAvatar customerId={customerId} />
- </HStack>
- )}
+ {salesOrderId && salesOrderLineId && salesOrderReadableId && (
+ <HStack className="justify-start space-x-2">
+ <RiProgress8Line className="text-muted-foreground flex-shrink-0" />
+ <Hyperlink
+ to={path.to.salesOrderLine(salesOrderId, salesOrderLineId)}
+ className="truncate"
+ >
+ {salesOrderReadableId}
+ </Hyperlink>
+ </HStack>
+ )}
- {deadlineType && (
- <HStack className="justify-start space-x-2">
- {getDeadlineIcon(deadlineType)}
- <Tooltip>
- <TooltipTrigger>
- <span
- className={cn(
- "text-sm truncate",
- isOverdue ? "text-red-500" : ""
- )}
- >
- {["ASAP", "No Deadline"].includes(deadlineType)
- ? deadlineType
- : dueDate
- ? t`Due ${formatRelativeTime(
- convertDateStringToIsoString(dueDate)
- )}`
- : "–"}
- </span>
- </TooltipTrigger>
- <TooltipContent side="right">
- {deadlineType}
- </TooltipContent>
- </Tooltip>
- </HStack>
- )}
- </div>
+ {customerId && (
+ <HStack className="justify-start space-x-2">
+ <LuInbox className="text-muted-foreground flex-shrink-0" />
+ <CustomerAvatar customerId={customerId} />
+ </HStack>
)}
- </CardContent>
- {employeeIds?.length ? (
- <CardFooter className="border-t py-3 bg-muted/30 text-sm">
- {employeeIds.length > 1 ? (
- <EmployeeAvatarGroup
- employeeIds={employeeIds.filter((id) => id !== null)}
- />
- ) : (
- <EmployeeAvatar employeeId={employeeIds[0]} />
- )}
- </CardFooter>
+
+ {deadlineType && (
+ <HStack className="justify-start space-x-2">
+ {getDeadlineIcon(deadlineType)}
+ <Tooltip>
+ <TooltipTrigger>
+ <span
+ className={cn(
+ "text-sm truncate",
+ isOverdue ? "text-red-500" : ""
+ )}
+ >
+ {deadlineLabel}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="right">{deadlineType}</TooltipContent>
+ </Tooltip>
+ </HStack>
+ )}
+ </div>
+ )}
+ </CardContent>
+ {employeeIds?.length ? (
+ <CardFooter className="border-t py-3 bg-muted/30 text-sm">
+ {employeeIds.length > 1 ? (
+ <EmployeeAvatarGroup
+ employeeIds={employeeIds.filter((id) => id !== null)}
+ />
) : (
- <CardFooter className="h-[var(--topbar-height)]" />
+ <EmployeeAvatar employeeId={employeeIds[0]} />
)}
- </Card>
- );
- })}
- </div>
- );
+ </CardFooter>
+ ) : (
+ <CardFooter className="h-[var(--topbar-height)]" />
+ )}
+ </Card>
+ );
+ });
+
+ if (isPhone) {
+ return (
+ <section className="flex flex-col gap-2">
+ <h2 className="px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
+ <Trans>Work Centers</Trans>
+ </h2>
+ <Card className="divide-y divide-border overflow-hidden bg-card">
+ {cards}
+ </Card>
+ </section>
+ );
+ }
+
+ return <div className="w-full grid grid-cols-6 gap-4">{cards}</div>;
}