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.

fix: add job operation change ui

Sidwebworks9f05e21da271
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 55a080df06..9cf65b053f 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -2032,6 +2032,24 @@ export async function updateJobOperationStatus(
.single();
}
+export async function updateJobOperationDueDate(
+ client: SupabaseClient<Database>,
+ id: string,
+ dueDate: string | null,
+ updatedBy: string
+) {
+ return client
+ .from("jobOperation")
+ .update({
+ dueDate,
+ updatedBy,
+ updatedAt: new Date().toISOString()
+ })
+ .eq("id", id)
+ .select()
+ .single();
+}
+
export async function updateProcedureStepOrder(
client: SupabaseClient<Database>,
updates: {
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index f9f02809a8..04e95e4f3a 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -153,9 +153,11 @@ import {
import { getProductionEventsPage } from "../../production.service";
import type { Job, JobOperation } from "../../types";
import { JobOperationStatus, JobOperationTags } from "./JobOperationStatus";
+import { OperationDueDatePicker } from "./OperationDueDatePicker";
export type Operation = z.infer<typeof jobOperationValidator> & {
assignee: string | null;
+ dueDate?: string | null;
status: JobOperation["status"];
tags: string[] | null;
workInstruction: JSONContent | null;
@@ -265,6 +267,10 @@ function makeItem(
/>
</HStack>
<HStack>
+ <OperationDueDatePicker
+ operationId={operation.id!}
+ dueDate={operation.dueDate ?? null}
+ />
<JobOperationTags operation={operation} availableTags={tags} />
<Tooltip>
<TooltipTrigger asChild>
diff --git a/apps/erp/app/modules/production/ui/Jobs/OperationDueDatePicker.tsx b/apps/erp/app/modules/production/ui/Jobs/OperationDueDatePicker.tsx
new file mode 100644
index 0000000000..43a1ed5ddb
--- /dev/null
+++ b/apps/erp/app/modules/production/ui/Jobs/OperationDueDatePicker.tsx
@@ -0,0 +1,49 @@
+"use client";
+import { DatePicker as DatePickerInput } from "@carbon/react";
+import { formatDate } from "@carbon/utils";
+import { parseDate } from "@internationalized/date";
+import { useSubmit } from "react-router";
+import { path } from "~/utils/path";
+
+type OperationDueDatePickerProps = {
+ operationId: string;
+ dueDate: string | null;
+ onChange?: (dueDate: string | null) => void;
+};
+
+export function OperationDueDatePicker({
+ operationId,
+ dueDate,
+ onChange
+}: OperationDueDatePickerProps) {
+ const submit = useSubmit();
+
+ return (
+ <DatePickerInput
+ value={dueDate ? parseDate(dueDate) : null}
+ isPreviewInline
+ inline={
+ dueDate ? (
+ <span className="flex flex-grow line-clamp-1 items-center text-xs text-muted-foreground">
+ {formatDate(dueDate)}
+ </span>
+ ) : (
+ true
+ )
+ }
+ onChange={(value) => {
+ const dateStr = value?.toString() ?? null;
+ onChange?.(dateStr);
+ submit(
+ { id: operationId, dueDate: dateStr ?? "" },
+ {
+ method: "post",
+ action: path.to.jobOperationDueDate,
+ navigate: false,
+ fetcherKey: `jobOperationDueDate:${operationId}`
+ }
+ );
+ }}
+ />
+ );
+}
diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx
index 1b9c415ace..79f80a0030 100644
--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx
+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx
@@ -1,5 +1,5 @@
import { useCarbon } from "@carbon/auth";
-import { ValidatedForm } from "@carbon/form";
+import { DatePicker, ValidatedForm } from "@carbon/form";
import {
Badge,
BarProgress,
@@ -43,7 +43,6 @@ import {
import { useFetcher, useNavigate, useParams } from "react-router";
import { Assignee, Empty, Hyperlink, TimeTypeIcon } from "~/components";
import {
- DatePicker,
Hidden,
Location,
NumberControlled,
@@ -62,6 +61,7 @@ import { getDeadlineIcon } from "~/modules/production/ui/Jobs/Deadline";
import { JobStartModal } from "~/modules/production/ui/Jobs/JobHeader";
import { JobOperationStatus } from "~/modules/production/ui/Jobs/JobOperationStatus";
import JobStatus from "~/modules/production/ui/Jobs/JobStatus";
+import { OperationDueDatePicker } from "~/modules/production/ui/Jobs/OperationDueDatePicker";
import { path } from "~/utils/path";
import type {
Opportunity,
@@ -472,7 +472,11 @@ function JobDetails({ job }: { job: Job }) {
100,
100
)}
- value={`${operation.quantityComplete ?? 0}/${operation.targetQuantity ?? operation.operationQuantity ?? 0}`}
+ value={`${operation.quantityComplete ?? 0}/${
+ operation.targetQuantity ??
+ operation.operationQuantity ??
+ 0
+ }`}
/>
</div>
)}
@@ -511,6 +515,7 @@ function JobDetails({ job }: { job: Job }) {
);
}}
/>
+
<Assignee
id={operation.id!}
table="jobOperation"
@@ -526,6 +531,17 @@ function JobDetails({ job }: { job: Job }) {
}}
value={operation.assignee ?? undefined}
/>
+ <OperationDueDatePicker
+ operationId={operation.id!}
+ dueDate={operation.dueDate}
+ onChange={(dueDate) =>
+ setJobOperations((prev) =>
+ prev.map((op) =>
+ op.id === operation.id ? { ...op, dueDate } : op
+ )
+ )
+ }
+ />
</HStack>
</div>
</div>
diff --git a/apps/erp/app/routes/x+/job+/methods+/operation.due-date.tsx b/apps/erp/app/routes/x+/job+/methods+/operation.due-date.tsx
new file mode 100644
index 0000000000..5720169ea0
--- /dev/null
+++ b/apps/erp/app/routes/x+/job+/methods+/operation.due-date.tsx
@@ -0,0 +1,32 @@
+import { assertIsPost, error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type { ActionFunctionArgs } from "react-router";
+import { data } from "react-router";
+import { updateJobOperationDueDate } from "~/modules/production";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "production"
+ });
+
+ const formData = await request.formData();
+ const id = formData.get("id") as string;
+ const dueDate = formData.get("dueDate") as string | null;
+
+ const update = await updateJobOperationDueDate(
+ client,
+ id,
+ dueDate || null,
+ userId
+ );
+ if (update.error) {
+ return data(
+ {},
+ await flash(request, error(update.error, "Failed to update due date"))
+ );
+ }
+
+ return {};
+}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 00e217ecb2..392a35827f 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -890,6 +890,7 @@ export const path = {
jobOperationProcedureSync: `${x}/job/methods/operation/procedure/sync`,
jobOperationTool: (id: string) =>
generatePath(`${x}/job/methods/operation/tool/${id}`),
+ jobOperationDueDate: `${x}/job/methods/operation/due-date`,
jobOperationStatus: `${x}/job/methods/operation/status`,
jobOperationStepRecords: (id: string) =>
generatePath(`${x}/job/${id}/steps`),
diff --git a/packages/react/src/Date/DatePicker.tsx b/packages/react/src/Date/DatePicker.tsx
index 5e461d4524..7bd485074f 100644
--- a/packages/react/src/Date/DatePicker.tsx
+++ b/packages/react/src/Date/DatePicker.tsx
@@ -23,6 +23,7 @@ import DateField from "./components/DateField";
const DatePicker = (
props: DatePickerProps<CalendarDate> & {
inline?: ReactNode;
+ isPreviewInline?: boolean;
helperText?: string;
}
) => {
@@ -41,32 +42,50 @@ const DatePicker = (
<HStack className="w-full" spacing={0}>
{props.inline ? (
<>
- <div className="flex-grow">{props.inline}</div>
- <HStack spacing={0}>
- {props.helperText && (
- <Tooltip>
- <TooltipTrigger asChild>
- <IconButton
- icon={<LuInfo />}
- variant="ghost"
- size="sm"
- aria-label="Helper information"
- />
- </TooltipTrigger>
- <TooltipContent>{props.helperText}</TooltipContent>
- </Tooltip>
- )}
+ {props.isPreviewInline && typeof props.inline !== "boolean" ? (
<PopoverTrigger asChild>
- <IconButton
- icon={<LuCalendarClock />}
+ <Button
variant="secondary"
size="sm"
+ className="gap-1.5"
aria-label="Open date picker"
isDisabled={props.isDisabled}
{...buttonProps}
- />
+ >
+ {props.inline}
+ <LuCalendarClock />
+ </Button>
</PopoverTrigger>
- </HStack>
+ ) : (
+ <>
+ <div className="flex-grow">{props.inline}</div>
+ <HStack spacing={0}>
+ {props.helperText && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ icon={<LuInfo />}
+ variant="ghost"
+ size="sm"
+ aria-label="Helper information"
+ />
+ </TooltipTrigger>
+ <TooltipContent>{props.helperText}</TooltipContent>
+ </Tooltip>
+ )}
+ <PopoverTrigger asChild>
+ <IconButton
+ icon={<LuCalendarClock />}
+ variant="secondary"
+ size="sm"
+ aria-label="Open date picker"
+ isDisabled={props.isDisabled}
+ {...buttonProps}
+ />
+ </PopoverTrigger>
+ </HStack>
+ </>
+ )}
</>
) : (
<>