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 operation preview on sales order
Brad Barbin0b36c9e0615d
diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceDeliveryForm.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceDeliveryForm.tsxindex 8114db25a1..1d6e1e97c9 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceDeliveryForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceDeliveryForm.tsx@@ -93,6 +93,7 @@ const PurchaseInvoiceDeliveryForm = forwardRef<<Numbername="supplierShippingCost"label="Shipping Cost"+ minValue={0}formatOptions={{style: "currency",currency: currencyCode,diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsxindex 748e39fbc6..258ee57a88 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx@@ -380,6 +380,7 @@ const PurchaseInvoiceLineForm = ({name="supplierShippingCost"label="Shipping"value={itemData.supplierShippingCost}+ minValue={0}formatOptions={{style: "currency",currency:diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsxindex e7ecc2b1e2..76e2ff1b60 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx@@ -76,7 +76,7 @@ import {LuWaypoints,LuX,} from "react-icons/lu";-import { z } from "zod";+import type { z } from "zod";import {Assignee,DirectionAwareTabs,@@ -96,7 +96,6 @@ import {StandardFactor,Submit,SupplierProcess,- Tags,Tool,UnitHint,WorkCenter,@@ -107,7 +106,6 @@ import { ConfirmDelete } from "~/components/Modals";import type { Item, SortableItemRenderProps } from "~/components/SortableList";import { SortableList, SortableListItem } from "~/components/SortableList";import { usePermissions, useRouteData, useUrlParams, useUser } from "~/hooks";-import { useTags } from "~/hooks/useTags";import type {OperationAttribute,OperationParameter,@@ -140,7 +138,7 @@ import type { Job, JobOperation } from "../../types";import UnitOfMeasure, {useUnitOfMeasure,} from "~/components/Form/UnitOfMeasure";-import { JobOperationStatus } from "./JobOperationStatus";+import { JobOperationStatus, JobOperationTags } from "./JobOperationStatus";import { ProcedureAttributeTypeIcon } from "~/components/Icons";import Procedure from "~/components/Form/Procedure";import { useNumberFormatter } from "@react-aria/i18n";@@ -242,6 +240,7 @@ function makeItem(value={operation.assignee ?? undefined}/></HStack>+<JobOperationTags operation={operation} availableTags={tags} /></HStack>),@@ -3048,34 +3047,3 @@ function OperationChat({ jobOperationId }: { jobOperationId: string }) {</div>);}--function JobOperationTags({- operation,- availableTags,-}: {- operation: Operation;- availableTags: { name: string }[];-}) {- const { onUpdateTags } = useTags({ id: operation.id, table: "jobOperation" });-- return (- <ValidatedForm- defaultValues={{- tags: operation.tags ?? [],- }}- validator={z.object({- tags: z.array(z.string()).optional(),- })}- >- <Tags- availableTags={availableTags}- label=""- name="tags"- table="operation"- maxPreview={3}- inline- onChange={onUpdateTags}- />- </ValidatedForm>- );-}diff --git a/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx b/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsxindex b1c4a280df..1f6b7a6f0a 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx@@ -15,6 +15,10 @@ import { usePermissions, useRouteData } from "~/hooks";import { path } from "~/utils/path";import { jobOperationStatus } from "../../production.models";import type { Job, JobOperation } from "../../types";+import { z } from "zod";+import { ValidatedForm } from "@carbon/form";+import { Tags } from "~/components/Form";+import { useTags } from "~/hooks/useTags";function useOptimisticJobStatus(operationId: string) {const fetchers = useFetchers();@@ -31,9 +35,11 @@ function useOptimisticJobStatus(operationId: string) {export function JobOperationStatus({operation,className,+ onChange,}: {operation: { id?: string; status: JobOperation["status"]; jobId?: string };className?: string;+ onChange?: (status: JobOperation["status"]) => void;}) {const params = useParams();const jobId = params.jobId ?? operation.jobId;@@ -49,6 +55,7 @@ export function JobOperationStatus({const onOperationStatusChange = useCallback((id: string, status: JobOperation["status"]) => {+ onChange?.(status);submit({id,@@ -62,7 +69,7 @@ export function JobOperationStatus({});},- [submit]+ [submit, onChange]);const currentStatus =@@ -105,3 +112,36 @@ export function JobOperationStatus({</DropdownMenu>);}++export function JobOperationTags({+ operation,+ availableTags,+}: {+ operation: { id?: string; tags: string[] | null };+ availableTags: { name: string }[];+}) {+ const { onUpdateTags } = useTags({ id: operation.id, table: "jobOperation" });++ if (!operation.id) return null;++ return (+ <ValidatedForm+ defaultValues={{+ tags: operation.tags ?? [],+ }}+ validator={z.object({+ tags: z.array(z.string()).optional(),+ })}+ >+ <Tags+ availableTags={availableTags}+ label=""+ name="tags"+ table="operation"+ maxPreview={3}+ inline+ onChange={onUpdateTags}+ />+ </ValidatedForm>+ );+}diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderDeliveryForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderDeliveryForm.tsxindex fb9739d512..93ff138d97 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderDeliveryForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderDeliveryForm.tsx@@ -104,6 +104,7 @@ const PurchaseOrderDeliveryForm = forwardRef<<Numbername="supplierShippingCost"label="Shipping Cost"+ minValue={0}formatOptions={{style: "currency",currency: currencyCode,diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsxindex ebb80b62a8..c51b7df0f3 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx@@ -40,7 +40,7 @@ import type { MethodItemType } from "~/modules/shared";import type { action } from "~/routes/x+/purchase-order+/$orderId.$lineId.details";import { path } from "~/utils/path";import DeletePurchaseOrderLine from "./DeletePurchaseOrderLine";-import { PostgrestResponse } from "@supabase/supabase-js";+import type { PostgrestResponse } from "@supabase/supabase-js";type PurchaseOrderLineFormProps = {initialValues: z.infer<typeof purchaseOrderLineValidator>;@@ -411,6 +411,7 @@ const PurchaseOrderLineForm = ({<NumberControlledname="supplierShippingCost"label="Shipping"+ minValue={0}value={itemData.supplierShippingCost}formatOptions={{style: "currency",diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsxindex a7818d7192..635d690eca 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx@@ -94,6 +94,7 @@ const QuoteShipmentForm = forwardRef<style: "currency",currency: company?.baseCurrencyCode,}}+ minValue={0}ref={shippingCostRef}/><Locationdiff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsxindex 1a7ed67251..262d10484c 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx@@ -338,6 +338,7 @@ const SalesOrderLineForm = ({<Numbername="shippingCost"label="Shipping Cost"+ minValue={0}formatOptions={{style: "currency",currency: baseCurrency,diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsxindex 5691297811..02e5a596f0 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx@@ -6,7 +6,10 @@ import {CardContent,CardHeader,CardTitle,+ cn,HStack,+ IconButton,+ Loading,Modal,ModalBody,ModalContent,@@ -14,17 +17,21 @@ import {ModalFooter,ModalHeader,ModalTitle,- Table,- Tbody,- Td,- Th,- Thead,- Tr,+ Progress,+ toast,useDisclosure,+ useMount,+ VStack,} from "@carbon/react";-import { useParams } from "@remix-run/react";+import { useNavigate, useParams } from "@remix-run/react";import { useState } from "react";-import { LuCirclePlus, LuHardHat } from "react-icons/lu";+import {+ LuChevronRight,+ LuChevronDown,+ LuCirclePlus,+ LuHardHat,+ LuSettings2,+} from "react-icons/lu";import { Assignee, Empty, Hyperlink } from "~/components";import {DatePicker,@@ -41,7 +48,7 @@ import {deadlineTypes,salesOrderToJobValidator,} from "~/modules/production/production.models";-import type { Job } from "~/modules/production/types";+import type { Job, JobOperation } from "~/modules/production/types";import JobStatus from "~/modules/production/ui/Jobs/JobStatus";import { path } from "~/utils/path";import type { Opportunity, SalesOrder, SalesOrderLine } from "../../types";@@ -49,6 +56,10 @@ import {getDeadlineIcon,getDeadlineText,} from "~/modules/production/ui/Jobs/Deadline";+import { useCarbon } from "@carbon/auth";+import { flushSync } from "react-dom";+import { SupplierProcessPreview } from "~/components/Form/SupplierProcess";+import { JobOperationStatus } from "~/modules/production/ui/Jobs/JobOperationStatus";type SalesOrderLineJobsProps = {salesOrder: SalesOrder;@@ -65,7 +76,6 @@ export function SalesOrderLineJobs({jobs,itemReplenishment,}: SalesOrderLineJobsProps) {- const permissions = usePermissions();const { orderId, lineId } = useParams();if (!orderId) throw new Error("orderId not found");if (!lineId) throw new Error("lineId not found");@@ -113,47 +123,21 @@ export function SalesOrderLineJobs({<CardContent>{jobs.length > 0 ? (- <Table>- <Thead>- <Tr>- <Th>Job ID</Th>- <Th>Status</Th>- <Th className="text-right">Complete</Th>- <Th className="text-right">Shipped</Th>- <Th>Assignee</Th>- </Tr>- </Thead>- <Tbody>- {jobs.map((job) => (- <Tr key={job.id}>- <Td>- <Hyperlink to={path.to.job(job.id!)}>- {job.jobId}- </Hyperlink>- </Td>- <Td>- <JobStatus status={job.status} />- </Td>-- <Td className="text-right">- {job.quantityComplete}/{job.productionQuantity}- </Td>- <Td className="text-right">- {job.quantityShipped}/{job.quantityComplete}- </Td>-- <Td>- <Assignee- id={job.id!}- table="job"- value={job.assignee ?? ""}- isReadOnly={!permissions.can("update", "production")}- />- </Td>- </Tr>+ <div className="border rounded-lg">+ {jobs+ .sort((a, b) => (a.jobId ?? "").localeCompare(b.jobId ?? ""))+ .map((job, index) => (+ <div+ key={job.id}+ className={cn(+ "border-b p-6",+ index === jobs.length - 1 && "border-b-0"+ )}+ >+ <SalesOrderJobItem job={job} />+ </div>))}- </Tbody>- </Table>+ </div>) : (<Empty className="pb-12"><Button@@ -268,3 +252,194 @@ export function SalesOrderLineJobs({</>);}++export function SalesOrderJobItem({ job }: { job: Job }) {+ const disclosure = useDisclosure();+ const permissions = usePermissions();++ return (+ <VStack>+ <HStack className="w-full justify-between">+ <HStack>+ <Hyperlink to={path.to.job(job.id!)}>+ <div className="flex flex-col gap-0">+ {job.jobId}+ <div>+ <JobStatus status={job.status} />+ </div>+ </div>+ </Hyperlink>+ <Assignee+ id={job.id!}+ table="job"+ size="sm"+ value={job.assignee ?? ""}+ isReadOnly={!permissions.can("update", "production")}+ />+ </HStack>+ <HStack className="justify-between items-center" spacing={8}>+ <div>+ <label className="text-xs text-muted-foreground">Complete</label>+ <p className="text-sm">+ {job.quantityComplete ?? 0}/{job.productionQuantity ?? 0}+ </p>+ </div>+ <div>+ <label className="text-xs text-muted-foreground">Shipped</label>+ <p className="text-sm">+ {job.quantityShipped ?? 0}/{job.quantityComplete ?? 0}+ </p>+ </div>+ </HStack>+ <IconButton+ aria-label={disclosure.isOpen ? "Collapse" : "Expand"}+ icon={disclosure.isOpen ? <LuChevronDown /> : <LuChevronRight />}+ variant="ghost"+ onClick={(e) => {+ e.stopPropagation();+ disclosure.onToggle();+ }}+ />+ </HStack>++ {disclosure.isOpen && <JobDetails job={job} />}+ </VStack>+ );+}++function JobDetails({ job }: { job: Job }) {+ const { carbon } = useCarbon();+ const navigate = useNavigate();+ const [isLoading, setIsLoading] = useState(true);+ const [jobOperations, setJobOperations] = useState<JobOperation[]>([]);++ const getJobOperations = async () => {+ if (!carbon) {+ toast.error("Failed to load job operations");+ return;+ }++ const [operations] = await Promise.all([+ carbon+ .from("jobOperation")+ .select("*, jobMakeMethod(parentMaterialId, item(readableId))")+ .eq("jobId", job.id!),+ ]);++ if (operations.error) {+ toast.error("Failed to load job operations");+ return;+ }++ flushSync(() => {+ setJobOperations(operations.data);+ setIsLoading(false);+ });+ };++ useMount(() => {+ getJobOperations();+ });++ if (jobOperations.length === 0 && !isLoading) {+ return <Empty>No operations found</Empty>;+ }++ return (+ <Loading isLoading={isLoading} className="min-h-[200px]">+ <VStack spacing={2} className="pt-4">+ {jobOperations+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))+ .map((operation) => (+ <div className="flex w-full items-center" key={operation.id}>+ <div className="grow h-full bg-muted/30 border border-border rounded-lg w-full">+ <div className="grid items-center justify-between grid-cols-[1fr_auto] w-full gap-2 px-3 md:px-4 py-2 md:py-3">+ <VStack spacing={0}>+ <h3 className="font-semibold truncate">+ {operation.description}+ </h3>+ {operation.operationType === "Outside" ? (+ <SupplierProcessPreview+ processId={operation.processId}+ supplierProcessId={+ operation.operationSupplierProcessId ?? undefined+ }+ />+ ) : (+ <div className="py-2 w-full">+ <Progress+ value={Math.min(+ ((operation.quantityComplete ?? 0) /+ (operation.operationQuantity ?? 0)) *+ 100,+ 100+ )}+ numerator={(+ operation.quantityComplete ?? 0+ ).toString()}+ denominator={(+ operation.operationQuantity ?? 0+ ).toString()}+ />+ </div>+ )}+ </VStack>++ <IconButton+ aria-label="Edit"+ icon={<LuSettings2 />}+ variant="ghost"+ onClick={() => {+ navigate(+ `${+ operation.jobMakeMethod?.parentMaterialId+ ? path.to.jobMakeMethod(+ operation.jobId,+ operation.jobMakeMethodId ?? "",+ operation.jobMakeMethod?.parentMaterialId+ )+ : path.to.jobMethod(+ operation.jobId,+ operation.jobMakeMethodId ?? ""+ )+ }?selectedOperation=${operation.id}`+ );+ }}+ />+ </div>+ <div className="flex w-full items-center justify-between border-t border-border px-3 md:px-4 py-2 md:py-3">+ <HStack>+ <JobOperationStatus+ operation={operation}+ onChange={(status) => {+ setJobOperations((prev) =>+ prev.map((op) =>+ op.id === operation.id ? { ...op, status } : op+ )+ );+ }}+ />+ <Assignee+ id={operation.id!}+ table="jobOperation"+ size="sm"+ onChange={(selected) => {+ setJobOperations((prev) =>+ prev.map((op) =>+ op.id === operation.id+ ? { ...op, assignee: selected }+ : op+ )+ );+ }}+ value={operation.assignee ?? undefined}+ />+ </HStack>+ </div>+ </div>+ </div>+ ))}+ </VStack>+ </Loading>+ );+}diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsxindex c0b1684037..d04c1100ab 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx@@ -98,6 +98,7 @@ const SalesOrderShipmentForm = forwardRef<<Numbername="shippingCost"label="Shipping Cost"+ minValue={0}formatOptions={{style: "currency",currency:diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsxindex 93fd04137d..e5ec45439e 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx@@ -6,13 +6,12 @@ import {CardDescription,CardHeader,CardTitle,+ cn,Heading,HStack,Table,Tbody,Td,- Th,- Thead,Tooltip,TooltipContent,TooltipTrigger,@@ -31,8 +30,8 @@ import {LuImage,LuInfo,} from "react-icons/lu";-import { Assignee, CustomerAvatar, Empty, Hyperlink } from "~/components";-import { usePercentFormatter, usePermissions, useRouteData } from "~/hooks";+import { CustomerAvatar, Hyperlink } from "~/components";+import { usePercentFormatter, useRouteData } from "~/hooks";import JobStatus from "~/modules/production/ui/Jobs/JobStatus";import { getPrivateUrl, path } from "~/utils/path";import type {@@ -42,6 +41,8 @@ import type {SalesOrderJob,SalesOrderLine,} from "../../types";+import { SalesOrderJobItem } from "./SalesOrderLineJobs";+import type { Job } from "~/modules/production/types";const SalesOrderSummary = ({onEditShippingCost,@@ -219,7 +220,6 @@ const SalesOrderSummary = ({function LineItems({currencyCode,- formatter,locale,lines,salesOrder,@@ -232,7 +232,6 @@ function LineItems({}) {const { orderId } = useParams();if (!orderId) throw new Error("Could not find orderId");- const permissions = usePermissions();const percentFormatter = usePercentFormatter();const [openItems, setOpenItems] = useState<string[]>([]);@@ -367,7 +366,7 @@ function LineItems({><Hyperlinkto={path.to.jobDetails(job.id)}- className="flex items-center justify-start gap-1"+ className="flex items-center justify-start gap-1 min-w-[200px]">{job.jobId}</Hyperlink>@@ -506,52 +505,24 @@ function LineItems({</Tbody></Table>- {isMade && (- <Table>- <Thead>- <Tr>- <Th>Job ID</Th>- <Th>Status</Th>- <Th>Quantity</Th>- <Th>Assignee</Th>- </Tr>- </Thead>- <Tbody>- {jobs.length > 0 ? (- jobs.map((job) => (- <Tr key={job.id}>- <Td>- <Hyperlink to={path.to.job(job.id!)}>- {job.jobId}- </Hyperlink>- </Td>- <Td>- <JobStatus status={job.status} />- </Td>- <Td>- {job.quantityComplete}/{job.productionQuantity}- </Td>- <Td>- <Assignee- id={job.id!}- table="job"- value={job.assignee ?? ""}- isReadOnly={- !permissions.can("update", "production")- }- />- </Td>- </Tr>- ))- ) : (- <Tr>- <Td colSpan={4} className="py-8">- <Empty />- </Td>- </Tr>- )}- </Tbody>- </Table>+ {isMade && jobs.length > 0 && (+ <div className="border rounded-lg">+ {jobs+ .sort((a, b) =>+ (a.jobId ?? "").localeCompare(b.jobId ?? "")+ )+ .map((job, index) => (+ <div+ key={job.id}+ className={cn(+ "border-b p-6",+ index === jobs.length - 1 && "border-b-0"+ )}+ >+ <SalesOrderJobItem job={job as Job} />+ </div>+ ))}+ </div>)}</div></motion.div>