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: jobs crud
Brad Barbinb8062fda528c
diff --git a/apps/carbon/app/components/Layout/Topbar/useCreate.tsx b/apps/carbon/app/components/Layout/Topbar/useCreate.tsxindex e928d559f6..8c4bc4593e 100644--- a/apps/carbon/app/components/Layout/Topbar/useCreate.tsx+++ b/apps/carbon/app/components/Layout/Topbar/useCreate.tsx@@ -2,6 +2,7 @@ import { useMemo } from "react";import {LuComponent,LuContainer,+ LuHardHat,LuShoppingCart,LuUserSquare,LuUsers,@@ -29,6 +30,14 @@ export default function useCreate(): Route[] {});}+ if (permissions.can("create", "production")) {+ links.push({+ name: "Job",+ to: path.to.newJob,+ icon: <LuHardHat />,+ });+ }+if (permissions.can("create", "purchasing")) {links.push({name: "Purchase Order",diff --git a/apps/carbon/app/modules/items/items.models.ts b/apps/carbon/app/modules/items/items.models.tsindex 07e610bf31..d8188d8bab 100644--- a/apps/carbon/app/modules/items/items.models.ts+++ b/apps/carbon/app/modules/items/items.models.ts@@ -411,6 +411,7 @@ export const partManufacturingValidator = z.object({manufacturingBlocked: zfd.checkbox(),// requiresConfiguration: zfd.checkbox(),lotSize: zfd.numeric(z.number().min(0)),+ scrapPercentage: zfd.numeric(z.number().min(0)),});export const pickMethodValidator = z.object({diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsxindex 9450aef98c..69ec28f742 100644--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx@@ -279,8 +279,6 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {return `/file/preview/private/${result.data.path}`;};- console.log({ items });-const [tabChangeRerender, setTabChangeRerender] = useState<number>(1);const renderListItem = ({item,diff --git a/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx b/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsxindex 3e53f47471..4af94248b7 100644--- a/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx+++ b/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx@@ -63,6 +63,13 @@ const PartManufacturingForm = ({value={routeData?.partSummary?.name ?? ""}/><Number name="lotSize" label="Lot Size" />+ <Number+ name="scrapPercentage"+ label="Scrap Percent"+ formatOptions={{+ style: "percent",+ }}+ /><Booleanname="manufacturingBlocked"label="Manufacturing Blocked"diff --git a/apps/carbon/app/modules/production/production.models.ts b/apps/carbon/app/modules/production/production.models.tsindex 9837e3442b..efc7834b9f 100644--- a/apps/carbon/app/modules/production/production.models.ts+++ b/apps/carbon/app/modules/production/production.models.ts@@ -1,12 +1,11 @@import { z } from "zod";import { zfd } from "zod-form-data";-import { methodItemType } from "../shared";export const deadlineTypes = [- "No Deadline","ASAP",- "Soft Deadline","Hard Deadline",+ "Soft Deadline",+ "No Deadline",] as const;export const jobStatus = [@@ -18,26 +17,36 @@ export const jobStatus = ["Cancelled",] as const;-export const jobValidator = z.object({- id: zfd.text(z.string().optional()),- jobId: zfd.text(z.string().optional()),- itemId: z.string().min(1, { message: "Item is required" }),- itemType: z.enum(methodItemType).optional(),- customerId: zfd.text(z.string().optional()),- description: zfd.text(z.string().optional()),- dueDate: zfd.text(z.string().optional()),- deadlineType: z.enum(deadlineTypes, {- errorMap: () => ({ message: "Deadline type is required" }),- }),- locationId: z.string().min(1, { message: "Location is required" }),- quantity: zfd.numeric(z.number().min(0)),- status: z- .enum(jobStatus, {- errorMap: () => ({ message: "Status is required" }),- })- .optional(),- unitOfMeasureCode: z- .string()- .min(1, { message: "Unit of measure is required" }),- modelUploadId: zfd.text(z.string().optional()),-});+export const jobValidator = z+ .object({+ id: zfd.text(z.string().optional()),+ jobId: zfd.text(z.string().optional()),+ itemId: z.string().min(1, { message: "Item is required" }),+ customerId: zfd.text(z.string().optional()),+ dueDate: zfd.text(z.string().optional()),+ deadlineType: z.enum(deadlineTypes, {+ errorMap: () => ({ message: "Deadline type is required" }),+ }),+ locationId: z.string().min(1, { message: "Location is required" }),+ quantity: zfd.numeric(z.number().min(0)),+ scrapQuantity: zfd.numeric(z.number().min(0)),+ unitOfMeasureCode: z+ .string()+ .min(1, { message: "Unit of measure is required" }),+ modelUploadId: zfd.text(z.string().optional()),+ })+ .refine(+ (data) => {+ if (+ ["Hard Deadline", "Soft Deadline"].includes(data.deadlineType) &&+ !data.dueDate+ ) {+ return false;+ }+ return true;+ },+ {+ message: "Due date is required",+ path: ["dueDate"],+ }+ );diff --git a/apps/carbon/app/modules/production/production.service.ts b/apps/carbon/app/modules/production/production.service.tsindex f3ec35b6f4..2328699d1b 100644--- a/apps/carbon/app/modules/production/production.service.ts+++ b/apps/carbon/app/modules/production/production.service.ts@@ -6,10 +6,26 @@ import { setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import type { jobValidator } from "./production.models";+export async function deleteJob(+ client: SupabaseClient<Database>,+ jobId: string+) {+ return client.from("job").delete().eq("id", jobId);+}+export async function getJob(client: SupabaseClient<Database>, id: string) {return client.from("jobs").select("*").eq("id", id).single();}+export async function getJobDocuments(+ client: SupabaseClient<Database>,+ companyId: string,+ jobId: string+) {+ // TODO: get documents from sales order/quote line+ return client.storage.from("private").list(`${companyId}/job/${jobId}`);+}+export async function getJobs(client: SupabaseClient<Database>,companyId: string,diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobForm.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobForm.tsxindex d21381a298..eaa57d11a5 100644--- a/apps/carbon/app/modules/production/ui/Jobs/JobForm.tsx+++ b/apps/carbon/app/modules/production/ui/Jobs/JobForm.tsx@@ -28,10 +28,15 @@ import {} from "~/components/Form";import { usePermissions, useUser } from "~/hooks";import { useSupabase } from "~/lib/supabase";+import type { jobStatus } from "~/modules/production";import { deadlineTypes, jobValidator } from "~/modules/production";import { type MethodItemType } from "~/modules/shared";-type JobFormValues = z.infer<typeof jobValidator>;+type JobFormValues = z.infer<typeof jobValidator> & {+ description: string;+ status: (typeof jobStatus)[number];+ itemType: MethodItemType;+};type JobFormProps = {initialValues: JobFormValues;@@ -50,11 +55,18 @@ const JobForm = ({ initialValues }: JobFormProps) => {description: string;uom: string;quantity: number;+ scrapQuantity: number;+ scrapPercentage: number;modelUploadId: string | null;}>({itemId: initialValues.itemId ?? "",description: initialValues.description ?? "",quantity: initialValues.quantity ?? 0,+ scrapQuantity: initialValues.scrapQuantity ?? 0,+ scrapPercentage:+ (initialValues.quantity ?? 0) === 0+ ? 0+ : (initialValues.scrapQuantity ?? 0) / initialValues.scrapQuantity,uom: initialValues.unitOfMeasureCode ?? "",modelUploadId: initialValues.modelUploadId ?? null,});@@ -69,6 +81,8 @@ const JobForm = ({ initialValues }: JobFormProps) => {description: "",uom: "EA",quantity: 0,+ scrapPercentage: 0,+ scrapQuantity: 0,modelUploadId: null,});};@@ -87,7 +101,7 @@ const JobForm = ({ initialValues }: JobFormProps) => {.single(),supabase.from("itemReplenishment")- .select("lotSize")+ .select("lotSize, scrapPercentage").eq("itemId", itemId).single(),]);@@ -98,6 +112,11 @@ const JobForm = ({ initialValues }: JobFormProps) => {uom: item.data?.unitOfMeasureCode ?? "EA",quantity: manufacturing?.data?.lotSize ?? 0,modelUploadId: item.data?.modelUploadId ?? null,+ scrapPercentage: manufacturing?.data?.scrapPercentage ?? 0,+ scrapQuantity: Math.ceil(+ (manufacturing?.data?.lotSize ?? 0) *+ ((manufacturing?.data?.scrapPercentage ?? 0) / 100)+ ),});};@@ -143,6 +162,8 @@ const JobForm = ({ initialValues }: JobFormProps) => {isOptional/>+ {isEditing && <div className="col-span-1" />}+<Itemname="itemId"label={type}@@ -154,7 +175,18 @@ const JobForm = ({ initialValues }: JobFormProps) => {}}onTypeChange={onTypeChange}/>- <Location name="locationId" label="Location" />+ {!isEditing && (+ <UnitOfMeasure+ name="unitOfMeasureCode"+ value={itemData.uom}+ onChange={(value) => {+ if (value?.value) {+ setItemData((prev) => ({ ...prev, uom: value.value }));+ }+ }}+ />+ )}+<InputControlledname="description"label="Description"@@ -167,19 +199,39 @@ const JobForm = ({ initialValues }: JobFormProps) => {label="Quantity"value={itemData.quantity}onChange={(value) =>- setItemData((prev) => ({ ...prev, quantity: value }))+ setItemData((prev) => ({+ ...prev,+ quantity: value,+ scrapQuantity: Math.ceil(value * prev.scrapPercentage),+ }))}minValue={0}/>- <UnitOfMeasure- name="unitOfMeasureCode"- value={itemData.uom}- onChange={(value) => {- if (value?.value) {- setItemData((prev) => ({ ...prev, uom: value.value }));- }- }}+ <NumberControlled+ name="scrapQuantity"+ label="Scrap Quantity"+ value={itemData.scrapQuantity}+ onChange={(value) =>+ setItemData((prev) => ({+ ...prev,+ scrapQuantity: value,+ scrapPercentage:+ prev.quantity > 0 ? value / prev.quantity : 1,+ }))+ }+ minValue={0}/>+ {isEditing && (+ <UnitOfMeasure+ name="unitOfMeasureCode"+ value={itemData.uom}+ onChange={(value) => {+ if (value?.value) {+ setItemData((prev) => ({ ...prev, uom: value.value }));+ }+ }}+ />+ )}<DatePickername="dueDate"@@ -194,6 +246,7 @@ const JobForm = ({ initialValues }: JobFormProps) => {label: d,}))}/>+ <Location name="locationId" label="Location" /><CustomFormFields table="job" /></div></VStack>diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsxnew file mode 100644index 0000000000..c1829f29f8--- /dev/null+++ b/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx@@ -0,0 +1,35 @@+import { Badge, HStack, Heading, VStack } from "@carbon/react";++import { Link, useParams } from "@remix-run/react";+import { useRouteData } from "~/hooks";+import { MethodItemTypeIcon } from "~/modules/shared";+import { path } from "~/utils/path";+import type { Job } from "../../types";++const JobHeader = () => {+ // const links = useJobavigation();+ const { jobId } = useParams();+ if (!jobId) throw new Error("jobId not found");++ const routeData = useRouteData<{ job: Job }>(path.to.job(jobId));++ return (+ <div className="flex flex-shrink-0 items-center justify-between px-4 py-2 bg-card border-b border-border">+ <VStack spacing={0} className="flex-grow">+ <HStack>+ <Link to={path.to.jobDetails(jobId)}>+ <Heading size="h2">{routeData?.job?.jobId}</Heading>+ </Link>+ <Badge variant="secondary">+ <MethodItemTypeIcon type="Job" />+ </Badge>+ </HStack>+ </VStack>+ <VStack spacing={0} className="flex-shrink justify-center items-end">+ {/* <DetailsTopbar links={links} /> */}+ </VStack>+ </div>+ );+};++export default JobHeader;diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsxindex 6553253a87..ebe5cec246 100644--- a/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx+++ b/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx@@ -16,6 +16,7 @@ import { usePermissions, useUrlParams } from "~/hooks";import { useCustomColumns } from "~/hooks/useCustomColumns";import type { Job } from "~/modules/production";import {+ deadlineTypes,getDeadlineIcon,getDeadlineText,jobStatus,@@ -91,8 +92,8 @@ const JobsTable = memo(({ data, count, locations }: JobsTableProps) => {filter: {type: "static",options: items?.map((item) => ({- value: item.name,- label: item.name,+ value: item.readableId,+ label: item.readableId,})),},},@@ -170,6 +171,20 @@ const JobsTable = memo(({ data, count, locations }: JobsTableProps) => {</div>);},+ meta: {+ filter: {+ type: "static",+ options: deadlineTypes.map((type) => ({+ value: type,+ label: (+ <div className="flex gap-1 items-center">+ {getDeadlineIcon(type, false)}+ <span>{getDeadlineText(type)}</span>+ </div>+ ),+ })),+ },+ },},{accessorKey: "orderQuantity",diff --git a/apps/carbon/app/modules/production/ui/Jobs/index.ts b/apps/carbon/app/modules/production/ui/Jobs/index.tsindex 8f3f756d4f..14a13f1373 100644--- a/apps/carbon/app/modules/production/ui/Jobs/index.ts+++ b/apps/carbon/app/modules/production/ui/Jobs/index.ts@@ -1,6 +1,14 @@import { getDeadlineIcon, getDeadlineText } from "./Deadline";import JobForm from "./JobForm";+import JobHeader from "./JobHeader";import JobsTable from "./JobsTable";import JobStatus from "./JobStatus";-export { getDeadlineIcon, getDeadlineText, JobForm, JobsTable, JobStatus };+export {+ getDeadlineIcon,+ getDeadlineText,+ JobForm,+ JobHeader,+ JobsTable,+ JobStatus,+};diff --git a/apps/carbon/app/routes/x+/job+/$jobId.delete.tsx b/apps/carbon/app/routes/x+/job+/$jobId.delete.tsxnew file mode 100644index 0000000000..07115e25c8--- /dev/null+++ b/apps/carbon/app/routes/x+/job+/$jobId.delete.tsx@@ -0,0 +1,30 @@+import { json, redirect } from "@remix-run/react";++import type { ActionFunctionArgs } from "@remix-run/node";+import { deleteJob } from "~/modules/production";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { assertIsPost } from "~/utils/http";+import { path } from "~/utils/path";+import { error } from "~/utils/result";++export async function action({ request, params }: ActionFunctionArgs) {+ assertIsPost(request);+ const { client } = await requirePermissions(request, {+ delete: "production",+ });++ const { jobId } = params;+ if (!jobId) throw new Error("Could not find jobId");++ const quoteDelete = await deleteJob(client, jobId);++ if (quoteDelete.error) {+ return json(+ path.to.jobs,+ await flash(request, error(quoteDelete.error, "Failed to delete job"))+ );+ }++ throw redirect(path.to.jobs);+}diff --git a/apps/carbon/app/routes/x+/job+/$jobId.details.tsx b/apps/carbon/app/routes/x+/job+/$jobId.details.tsxnew file mode 100644index 0000000000..673274a0e3--- /dev/null+++ b/apps/carbon/app/routes/x+/job+/$jobId.details.tsx@@ -0,0 +1,104 @@+import { validationError, validator } from "@carbon/form";+import { VStack } from "@carbon/react";+import type { ActionFunctionArgs } from "@remix-run/node";+import { redirect } from "@remix-run/node";+import { useParams } from "@remix-run/react";+import type { FileObject } from "@supabase/storage-js";+import { useRouteData } from "~/hooks";+import type { Job } from "~/modules/production";+import { JobForm, jobValidator, upsertJob } from "~/modules/production";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { getCustomFields, setCustomFields } from "~/utils/form";+import { assertIsPost } from "~/utils/http";+import { path } from "~/utils/path";+import { error, success } from "~/utils/result";++export async function action({ request, params }: ActionFunctionArgs) {+ assertIsPost(request);+ const { client, userId } = await requirePermissions(request, {+ update: "production",+ });++ const { jobId: id } = params;+ if (!id) throw new Error("Could not find jobId");++ const formData = await request.formData();+ const validation = await validator(jobValidator).validate(formData);++ if (validation.error) {+ return validationError(validation.error);+ }++ const { jobId, ...data } = validation.data;+ if (!jobId) throw new Error("Could not find jobId in payload");++ const updateJob = await upsertJob(client, {+ ...data,+ id: id,+ jobId,+ customFields: setCustomFields(formData),+ updatedBy: userId,+ });+ if (updateJob.error) {+ throw redirect(+ path.to.job(id),+ await flash(request, error(updateJob.error, "Failed to update job"))+ );+ }++ throw redirect(path.to.job(id), await flash(request, success("Updated job")));+}++export default function JobDetailsRoute() {+ const { jobId } = useParams();+ if (!jobId) throw new Error("Could not find jobId");++ const jobData = useRouteData<{+ job: Job;+ files: FileObject[];+ }>(path.to.job(jobId));++ if (!jobData) throw new Error("Could not find job data");+ // const permissions = usePermissions();++ const jobInitialValues = {+ id: jobData.job?.id ?? "",+ jobId: jobData.job?.jobId ?? "",+ customerId: jobData.job?.customerId ?? "",+ deadlineType: jobData.job?.deadlineType ?? ("No Deadline" as "No Deadline"),+ description: jobData.job?.description ?? "",+ dueDate: jobData.job?.dueDate ?? "",+ itemId: jobData.job?.itemId ?? "",+ itemType: jobData.job?.itemType ?? ("Part" as const),+ locationId: jobData.job?.locationId ?? "",+ quantity: jobData.job?.quantity ?? 0,+ scrapQuantity: jobData.job?.scrapQuantity ?? 0,+ status: jobData.job?.status ?? ("Draft" as const),+ unitOfMeasureCode: jobData.job?.unitOfMeasureCode ?? "EA",+ ...getCustomFields(jobData.job?.customFields ?? {}),+ };++ return (+ <VStack spacing={2} className="p-2">+ <JobForm key={jobInitialValues.id} initialValues={jobInitialValues} />+ {/* {permissions.is("employee") && (+ <div className="grid grid-cols-1 md:grid-cols-2 w-full flex-grow gap-2">+ <CadModel+ autodeskUrn={jobData?.jobSummary?.autodeskUrn ?? null}+ isReadOnly={!permissions.can("update", "jobs")}+ metadata={{ jobId }}+ modelPath={jobData?.jobSummary?.modelPath ?? null}+ title="CAD Model"+ />+ <ItemDocuments+ files={jobData?.files ?? []}+ jobId={jobId}+ modelUpload={jobData.jobSummary ?? undefined}+ type="Job"+ />+ </div>+ )} */}+ </VStack>+ );+}diff --git a/apps/carbon/app/routes/x+/job+/$jobId.tsx b/apps/carbon/app/routes/x+/job+/$jobId.tsxindex 820495ecf2..5a6d5733aa 100644--- a/apps/carbon/app/routes/x+/job+/$jobId.tsx+++ b/apps/carbon/app/routes/x+/job+/$jobId.tsx@@ -7,16 +7,9 @@ import {VStack,} from "@carbon/react";import type { LoaderFunctionArgs } from "@remix-run/node";-import { json, redirect } from "@remix-run/node";-import { Outlet, useParams } from "@remix-run/react";-import {- getJob,- getJobDocuments,- getJobMethodTrees,- JobBreadcrumbs,- JobExplorer,- JobHeader,-} from "~/modules/sales";+import { json, Outlet, redirect, useParams } from "@remix-run/react";+import { getJob, getJobDocuments, JobHeader } from "~/modules/production";+import {} from "~/modules/sales";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";import type { Handle } from "~/utils/handle";@@ -30,17 +23,17 @@ export const handle: Handle = {};export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "production",});const { jobId } = params;if (!jobId) throw new Error("Could not find jobId");- const [job, methods, files] = await Promise.all([+ const [job, files] = await Promise.all([getJob(client, jobId),- getJobMethodTrees(client, jobId),- getJobDocuments(client, jobId),+ getJobDocuments(client, companyId, jobId),+ // getJobMethodTrees(client, jobId),]);if (job.error) {@@ -50,17 +43,17 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- if (methods.error) {- throw redirect(- path.to.jobs,- await flash(request, error(methods.error, "Failed to load job method"))- );- }+ // if (methods.error) {+ // throw redirect(+ // path.to.jobs,+ // await flash(request, error(methods.error, "Failed to load job method"))+ // );+ // }return json({job: job.data,- methods: methods.data ?? [],files: files.data ?? [],+ // methods: methods.data ?? [],});}@@ -86,7 +79,7 @@ export default function JobRoute() {><ScrollArea className="h-[calc(100vh-99px)]"><div className="grid w-full h-full overflow-hidden">- <JobExplorer />+ {/* <JobExplorer /> */}</div></ScrollArea></ResizablePanel>@@ -94,7 +87,6 @@ export default function JobRoute() {<ResizablePanel order={2}><ScrollArea className="h-[calc(100vh-99px)]"><VStack spacing={2} className="p-2">- <JobBreadcrumbs /><Outlet /></VStack></ScrollArea>diff --git a/apps/carbon/app/routes/x+/job+/new.tsx b/apps/carbon/app/routes/x+/job+/new.tsxindex 1c697eb14f..dadffd59c9 100644--- a/apps/carbon/app/routes/x+/job+/new.tsx+++ b/apps/carbon/app/routes/x+/job+/new.tsx@@ -48,9 +48,10 @@ export async function action({ request }: ActionFunctionArgs) {}if (!jobId) throw new Error("jobId is not defined");+ const { id, ...data } = validation.data;const createJob = await upsertJob(client, {- ...validation.data,+ ...data,jobId,companyId,createdBy: userId,@@ -66,6 +67,7 @@ export async function action({ request }: ActionFunctionArgs) {);}+ console.log("redirecting to " + path.to.job(createJob.data?.id!));throw redirect(path.to.job(createJob.data?.id!));}@@ -77,12 +79,15 @@ export default function JobNewRoute() {const initialValues = {customerId: customerId ?? "",deadlineType: "No Deadline" as const,+ description: "",dueDate: "",itemId: "",itemType: "Part" as const,jobId: undefined,locationId: defaults?.locationId ?? "",quantity: 0,+ scrapQuantity: 0,+ status: "Draft" as const,unitOfMeasureCode: "EA",};diff --git a/apps/carbon/app/routes/x+/production+/jobs.tsx b/apps/carbon/app/routes/x+/production+/jobs.tsxindex 5b911db075..03a8bad9d4 100644--- a/apps/carbon/app/routes/x+/production+/jobs.tsx+++ b/apps/carbon/app/routes/x+/production+/jobs.tsx@@ -56,8 +56,6 @@ export async function loader({ request }: LoaderFunctionArgs) {export default function JobsRoute() {const { count, locations, jobs } = useLoaderData<typeof loader>();- console.log({ jobs });-return (<VStack spacing={0} className="h-full"><JobsTable data={jobs} count={count} locations={locations} />diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 4cd03acba9..f351843fc0 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -231,7 +231,7 @@ export const path = {deleteItem: (id: string) => generatePath(`${x}/items/delete/${id}`),deleteItemPostingGroup: (id: string) =>generatePath(`${x}/items/groups/delete/${id}`),- deleteJob: (id: string) => generatePath(`${x}/production/jobs/${id}`),+ deleteJob: (id: string) => generatePath(`${x}/job/${id}/delete`),deleteMaterialForm: (id: string) =>generatePath(`${x}/items/forms/delete/${id}`),deleteMaterialSubstance: (id: string) =>diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.tsindex d474d532ec..079e987d2b 100644--- a/packages/database/src/swagger-docs-schema.ts+++ b/packages/database/src/swagger-docs-schema.ts@@ -3363,6 +3363,12 @@ export default {{$ref: "#/parameters/rowFilter.methodMaterial.methodOperationId",},+ {+ $ref: "#/parameters/rowFilter.methodMaterial.scrapQuantity",+ },+ {+ $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",+ },{$ref: "#/parameters/select",},@@ -3473,6 +3479,12 @@ export default {{$ref: "#/parameters/rowFilter.methodMaterial.methodOperationId",},+ {+ $ref: "#/parameters/rowFilter.methodMaterial.scrapQuantity",+ },+ {+ $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",+ },{$ref: "#/parameters/preferReturn",},@@ -3537,6 +3549,12 @@ export default {{$ref: "#/parameters/rowFilter.methodMaterial.methodOperationId",},+ {+ $ref: "#/parameters/rowFilter.methodMaterial.scrapQuantity",+ },+ {+ $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",+ },{$ref: "#/parameters/body.methodMaterial",},@@ -3873,6 +3891,12 @@ export default {{$ref: "#/parameters/rowFilter.quoteMaterial.quoteOperationId",},+ {+ $ref: "#/parameters/rowFilter.quoteMaterial.scrapQuantity",+ },+ {+ $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",+ },{$ref: "#/parameters/select",},@@ -3992,6 +4016,12 @@ export default {{$ref: "#/parameters/rowFilter.quoteMaterial.quoteOperationId",},+ {+ $ref: "#/parameters/rowFilter.quoteMaterial.scrapQuantity",+ },+ {+ $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",+ },{$ref: "#/parameters/preferReturn",},@@ -4065,6 +4095,12 @@ export default {{$ref: "#/parameters/rowFilter.quoteMaterial.quoteOperationId",},+ {+ $ref: "#/parameters/rowFilter.quoteMaterial.scrapQuantity",+ },+ {+ $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",+ },{$ref: "#/parameters/body.quoteMaterial",},@@ -11475,17 +11511,14 @@ export default {$ref: "#/parameters/rowFilter.job.deadlineType",},{- $ref: "#/parameters/rowFilter.job.orderQuantity",+ $ref: "#/parameters/rowFilter.job.quantity",},{- $ref: "#/parameters/rowFilter.job.inventoryQuantity",+ $ref: "#/parameters/rowFilter.job.scrapQuantity",},{$ref: "#/parameters/rowFilter.job.productionQuantity",},- {- $ref: "#/parameters/rowFilter.job.scrapQuantity",- },{$ref: "#/parameters/rowFilter.job.quantityComplete",},@@ -11507,6 +11540,9 @@ export default {{$ref: "#/parameters/rowFilter.job.quoteLineId",},+ {+ $ref: "#/parameters/rowFilter.job.modelUploadId",+ },{$ref: "#/parameters/rowFilter.job.notes",},@@ -11618,17 +11654,14 @@ export default {$ref: "#/parameters/rowFilter.job.deadlineType",},{- $ref: "#/parameters/rowFilter.job.orderQuantity",+ $ref: "#/parameters/rowFilter.job.quantity",},{- $ref: "#/parameters/rowFilter.job.inventoryQuantity",+ $ref: "#/parameters/rowFilter.job.scrapQuantity",},{$ref: "#/parameters/rowFilter.job.productionQuantity",},- {- $ref: "#/parameters/rowFilter.job.scrapQuantity",- },{$ref: "#/parameters/rowFilter.job.quantityComplete",},@@ -11650,6 +11683,9 @@ export default {{$ref: "#/parameters/rowFilter.job.quoteLineId",},+ {+ $ref: "#/parameters/rowFilter.job.modelUploadId",+ },{$ref: "#/parameters/rowFilter.job.notes",},@@ -11715,17 +11751,14 @@ export default {$ref: "#/parameters/rowFilter.job.deadlineType",},{- $ref: "#/parameters/rowFilter.job.orderQuantity",+ $ref: "#/parameters/rowFilter.job.quantity",},{- $ref: "#/parameters/rowFilter.job.inventoryQuantity",+ $ref: "#/parameters/rowFilter.job.scrapQuantity",},{$ref: "#/parameters/rowFilter.job.productionQuantity",},- {- $ref: "#/parameters/rowFilter.job.scrapQuantity",- },{$ref: "#/parameters/rowFilter.job.quantityComplete",},@@ -11747,6 +11780,9 @@ export default {{$ref: "#/parameters/rowFilter.job.quoteLineId",},+ {+ $ref: "#/parameters/rowFilter.job.modelUploadId",+ },{$ref: "#/parameters/rowFilter.job.notes",},@@ -18426,17 +18462,14 @@ export default {$ref: "#/parameters/rowFilter.jobs.deadlineType",},{- $ref: "#/parameters/rowFilter.jobs.orderQuantity",+ $ref: "#/parameters/rowFilter.jobs.quantity",},{- $ref: "#/parameters/rowFilter.jobs.inventoryQuantity",+ $ref: "#/parameters/rowFilter.jobs.scrapQuantity",},{$ref: "#/parameters/rowFilter.jobs.productionQuantity",},- {- $ref: "#/parameters/rowFilter.jobs.scrapQuantity",- },{$ref: "#/parameters/rowFilter.jobs.quantityComplete",},@@ -18458,6 +18491,9 @@ export default {{$ref: "#/parameters/rowFilter.jobs.quoteLineId",},+ {+ $ref: "#/parameters/rowFilter.jobs.modelUploadId",+ },{$ref: "#/parameters/rowFilter.jobs.notes",},@@ -18489,7 +18525,7 @@ export default {$ref: "#/parameters/rowFilter.jobs.itemReadableId",},{- $ref: "#/parameters/rowFilter.jobs.type",+ $ref: "#/parameters/rowFilter.jobs.itemType",},{$ref: "#/parameters/rowFilter.jobs.description",@@ -26993,6 +27029,9 @@ export default {{$ref: "#/parameters/rowFilter.itemReplenishment.customFields",},+ {+ $ref: "#/parameters/rowFilter.itemReplenishment.scrapPercentage",+ },{$ref: "#/parameters/select",},@@ -27097,6 +27136,9 @@ export default {{$ref: "#/parameters/rowFilter.itemReplenishment.customFields",},+ {+ $ref: "#/parameters/rowFilter.itemReplenishment.scrapPercentage",+ },{$ref: "#/parameters/preferReturn",},@@ -27155,6 +27197,9 @@ export default {{$ref: "#/parameters/rowFilter.itemReplenishment.customFields",},+ {+ $ref: "#/parameters/rowFilter.itemReplenishment.scrapPercentage",+ },{$ref: "#/parameters/body.itemReplenishment",},@@ -35317,6 +35362,7 @@ export default {"createdBy","itemReadableId","order",+ "scrapQuantity",],properties: {id: {@@ -35407,6 +35453,15 @@ export default {format: "text",type: "string",},+ scrapQuantity: {+ default: 0,+ format: "numeric",+ type: "number",+ },+ productionQuantity: {+ format: "numeric",+ type: "number",+ },},type: "object",},@@ -35575,6 +35630,7 @@ export default {"createdAt","createdBy","quoteMakeMethodId",+ "scrapQuantity",],properties: {id: {@@ -35681,6 +35737,15 @@ export default {format: "text",type: "string",},+ scrapQuantity: {+ default: 0,+ format: "numeric",+ type: "number",+ },+ productionQuantity: {+ format: "numeric",+ type: "number",+ },},type: "object",},@@ -39102,9 +39167,7 @@ export default {"locationId","status","deadlineType",- "orderQuantity",- "inventoryQuantity",- "productionQuantity",+ "quantity","scrapQuantity","quantityComplete","quantityShipped",@@ -39169,23 +39232,17 @@ export default {format: 'public."deadlineType"',type: "string",},- orderQuantity: {+ quantity: {default: 0,format: "numeric",type: "number",},- inventoryQuantity: {+ scrapQuantity: {default: 0,format: "numeric",type: "number",},productionQuantity: {- default: 0,- format: "numeric",- type: "number",- },- scrapQuantity: {- default: 0,format: "numeric",type: "number",},@@ -39228,6 +39285,12 @@ export default {format: "text",type: "string",},+ modelUploadId: {+ description:+ "Note:\nThis is a Foreign Key to `modelUpload.id`.<fk table='modelUpload' column='id'/>",+ format: "text",+ type: "string",+ },notes: {format: "jsonb",},@@ -42278,11 +42341,11 @@ export default {format: 'public."deadlineType"',type: "string",},- orderQuantity: {+ quantity: {format: "numeric",type: "number",},- inventoryQuantity: {+ scrapQuantity: {format: "numeric",type: "number",},@@ -42290,10 +42353,6 @@ export default {format: "numeric",type: "number",},- scrapQuantity: {- format: "numeric",- type: "number",- },quantityComplete: {format: "numeric",type: "number",@@ -42330,6 +42389,12 @@ export default {format: "text",type: "string",},+ modelUploadId: {+ description:+ "Note:\nThis is a Foreign Key to `modelUpload.id`.<fk table='modelUpload' column='id'/>",+ format: "text",+ type: "string",+ },notes: {format: "jsonb",},@@ -42376,7 +42441,7 @@ export default {format: "text",type: "string",},- type: {+ itemType: {enum: ["Part","Material",@@ -46121,6 +46186,7 @@ export default {"companyId","createdBy","createdAt",+ "scrapPercentage",],properties: {itemId: {@@ -46198,6 +46264,11 @@ export default {customFields: {format: "jsonb",},+ scrapPercentage: {+ default: 0,+ format: "numeric",+ type: "number",+ },},type: "object",},@@ -50561,6 +50632,20 @@ export default {in: "query",type: "string",},+ "rowFilter.methodMaterial.scrapQuantity": {+ name: "scrapQuantity",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },+ "rowFilter.methodMaterial.productionQuantity": {+ name: "productionQuantity",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },"body.processes": {name: "processes",description: "processes",@@ -50882,6 +50967,20 @@ export default {in: "query",type: "string",},+ "rowFilter.quoteMaterial.scrapQuantity": {+ name: "scrapQuantity",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },+ "rowFilter.quoteMaterial.productionQuantity": {+ name: "productionQuantity",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },"body.contractorAbility": {name: "contractorAbility",description: "contractorAbility",@@ -55354,15 +55453,15 @@ export default {in: "query",type: "string",},- "rowFilter.job.orderQuantity": {- name: "orderQuantity",+ "rowFilter.job.quantity": {+ name: "quantity",required: false,format: "numeric",in: "query",type: "string",},- "rowFilter.job.inventoryQuantity": {- name: "inventoryQuantity",+ "rowFilter.job.scrapQuantity": {+ name: "scrapQuantity",required: false,format: "numeric",in: "query",@@ -55375,13 +55474,6 @@ export default {in: "query",type: "string",},- "rowFilter.job.scrapQuantity": {- name: "scrapQuantity",- required: false,- format: "numeric",- in: "query",- type: "string",- },"rowFilter.job.quantityComplete": {name: "quantityComplete",required: false,@@ -55431,6 +55523,13 @@ export default {in: "query",type: "string",},+ "rowFilter.job.modelUploadId": {+ name: "modelUploadId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"rowFilter.job.notes": {name: "notes",required: false,@@ -59459,15 +59558,15 @@ export default {in: "query",type: "string",},- "rowFilter.jobs.orderQuantity": {- name: "orderQuantity",+ "rowFilter.jobs.quantity": {+ name: "quantity",required: false,format: "numeric",in: "query",type: "string",},- "rowFilter.jobs.inventoryQuantity": {- name: "inventoryQuantity",+ "rowFilter.jobs.scrapQuantity": {+ name: "scrapQuantity",required: false,format: "numeric",in: "query",@@ -59480,13 +59579,6 @@ export default {in: "query",type: "string",},- "rowFilter.jobs.scrapQuantity": {- name: "scrapQuantity",- required: false,- format: "numeric",- in: "query",- type: "string",- },"rowFilter.jobs.quantityComplete": {name: "quantityComplete",required: false,@@ -59536,6 +59628,13 @@ export default {in: "query",type: "string",},+ "rowFilter.jobs.modelUploadId": {+ name: "modelUploadId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"rowFilter.jobs.notes": {name: "notes",required: false,@@ -59606,8 +59705,8 @@ export default {in: "query",type: "string",},- "rowFilter.jobs.type": {- name: "type",+ "rowFilter.jobs.itemType": {+ name: "itemType",required: false,format: 'public."itemType"',in: "query",@@ -64654,6 +64753,13 @@ export default {in: "query",type: "string",},+ "rowFilter.itemReplenishment.scrapPercentage": {+ name: "scrapPercentage",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },"body.documentLabel": {name: "documentLabel",description: "documentLabel",diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex f81b9c6ad6..2d6e41f1f6 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -6482,6 +6482,7 @@ export type Database = {purchasingLeadTime: numberpurchasingUnitOfMeasureCode: string | nullrequiresConfiguration: boolean+ scrapPercentage: numberupdatedAt: string | nullupdatedBy: string | null}@@ -6499,6 +6500,7 @@ export type Database = {purchasingLeadTime?: numberpurchasingUnitOfMeasureCode?: string | nullrequiresConfiguration?: boolean+ scrapPercentage?: numberupdatedAt?: string | nullupdatedBy?: string | null}@@ -6516,6 +6518,7 @@ export type Database = {purchasingLeadTime?: numberpurchasingUnitOfMeasureCode?: string | nullrequiresConfiguration?: boolean+ scrapPercentage?: numberupdatedAt?: string | nullupdatedBy?: string | null}@@ -6862,13 +6865,13 @@ export type Database = {deadlineType: Database["public"]["Enums"]["deadlineType"]dueDate: string | nullid: string- inventoryQuantity: numberitemId: stringjobId: stringlocationId: string+ modelUploadId: string | nullnotes: Json | null- orderQuantity: number- productionQuantity: number+ productionQuantity: number | null+ quantity: numberquantityComplete: numberquantityReceivedToInventory: numberquantityShipped: number@@ -6892,13 +6895,13 @@ export type Database = {deadlineType?: Database["public"]["Enums"]["deadlineType"]dueDate?: string | nullid?: string- inventoryQuantity?: numberitemId: stringjobId: stringlocationId: string+ modelUploadId?: string | nullnotes?: Json | null- orderQuantity?: number- productionQuantity?: number+ productionQuantity?: number | null+ quantity?: numberquantityComplete?: numberquantityReceivedToInventory?: numberquantityShipped?: number@@ -6922,13 +6925,13 @@ export type Database = {deadlineType?: Database["public"]["Enums"]["deadlineType"]dueDate?: string | nullid?: string- inventoryQuantity?: numberitemId?: stringjobId?: stringlocationId?: string+ modelUploadId?: string | nullnotes?: Json | null- orderQuantity?: number- productionQuantity?: number+ productionQuantity?: number | null+ quantity?: numberquantityComplete?: numberquantityReceivedToInventory?: numberquantityShipped?: number@@ -7104,6 +7107,41 @@ export type Database = {referencedRelation: "salesOrders"referencedColumns: ["locationId"]},+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "fixtures"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "jobs"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "modelUpload"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "parts"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "salesRfqLines"+ referencedColumns: ["modelId"]+ },{foreignKeyName: "job_quoteId_fkey"columns: ["quoteId"]@@ -8576,7 +8614,9 @@ export type Database = {methodOperationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]order: number+ productionQuantity: number | nullquantity: number+ scrapQuantity: numberunitOfMeasureCode: stringupdatedAt: string | nullupdatedBy: string | null@@ -8595,7 +8635,9 @@ export type Database = {methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity: number+ scrapQuantity?: numberunitOfMeasureCode: stringupdatedAt?: string | nullupdatedBy?: string | null@@ -8614,7 +8656,9 @@ export type Database = {methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity?: number+ scrapQuantity?: numberunitOfMeasureCode?: stringupdatedAt?: string | nullupdatedBy?: string | null@@ -14256,11 +14300,13 @@ export type Database = {itemType: stringmethodType: Database["public"]["Enums"]["methodType"]order: number+ productionQuantity: number | nullquantity: numberquoteId: stringquoteLineId: stringquoteMakeMethodId: stringquoteOperationId: string | null+ scrapQuantity: numberunitCost: numberunitOfMeasureCode: string | nullupdatedAt: string | null@@ -14278,11 +14324,13 @@ export type Database = {itemType?: stringmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity?: numberquoteId: stringquoteLineId: stringquoteMakeMethodId: stringquoteOperationId?: string | null+ scrapQuantity?: numberunitCost?: numberunitOfMeasureCode?: string | nullupdatedAt?: string | null@@ -14300,11 +14348,13 @@ export type Database = {itemType?: stringmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity?: numberquoteId?: stringquoteLineId?: stringquoteMakeMethodId?: stringquoteOperationId?: string | null+ scrapQuantity?: numberunitCost?: numberunitOfMeasureCode?: string | nullupdatedAt?: string | null@@ -23049,22 +23099,23 @@ export type Database = {description: string | nulldueDate: string | nullid: string | null- inventoryQuantity: number | nullitemId: string | nullitemReadableId: string | nullitemTrackingType:| Database["public"]["Enums"]["itemTrackingType"]| null+ itemType: Database["public"]["Enums"]["itemType"] | nulljobId: string | nulllocationId: string | nullmodelId: string | nullmodelName: string | nullmodelPath: string | nullmodelSize: number | null+ modelUploadId: string | nullname: string | nullnotes: Json | null- orderQuantity: number | nullproductionQuantity: number | null+ quantity: number | nullquantityComplete: number | nullquantityReceivedToInventory: number | nullquantityShipped: number | null@@ -23080,7 +23131,6 @@ export type Database = {scrapQuantity: number | nullstatus: Database["public"]["Enums"]["jobStatus"] | nullthumbnailPath: string | null- type: Database["public"]["Enums"]["itemType"] | nullunitOfMeasureCode: string | nullupdatedAt: string | nullupdatedBy: string | null@@ -23247,6 +23297,41 @@ export type Database = {referencedRelation: "salesOrders"referencedColumns: ["locationId"]},+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "modelUpload"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "fixtures"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "jobs"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "parts"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "salesRfqLines"+ referencedColumns: ["modelId"]+ },{foreignKeyName: "job_quoteId_fkey"columns: ["quoteId"]diff --git a/packages/database/supabase/functions/lib/seed.ts b/packages/database/supabase/functions/lib/seed.tsindex f1b933920c..75d7a28b1e 100644--- a/packages/database/supabase/functions/lib/seed.ts+++ b/packages/database/supabase/functions/lib/seed.ts@@ -2032,6 +2032,15 @@ export const postingGroupSales = {};export const sequences = [+ {+ table: "job",+ name: "Job",+ prefix: "WO",+ suffix: null,+ next: 0,+ size: 6,+ step: 1,+ },{table: "purchaseOrder",name: "Purchase Order",diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex f81b9c6ad6..2d6e41f1f6 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -6482,6 +6482,7 @@ export type Database = {purchasingLeadTime: numberpurchasingUnitOfMeasureCode: string | nullrequiresConfiguration: boolean+ scrapPercentage: numberupdatedAt: string | nullupdatedBy: string | null}@@ -6499,6 +6500,7 @@ export type Database = {purchasingLeadTime?: numberpurchasingUnitOfMeasureCode?: string | nullrequiresConfiguration?: boolean+ scrapPercentage?: numberupdatedAt?: string | nullupdatedBy?: string | null}@@ -6516,6 +6518,7 @@ export type Database = {purchasingLeadTime?: numberpurchasingUnitOfMeasureCode?: string | nullrequiresConfiguration?: boolean+ scrapPercentage?: numberupdatedAt?: string | nullupdatedBy?: string | null}@@ -6862,13 +6865,13 @@ export type Database = {deadlineType: Database["public"]["Enums"]["deadlineType"]dueDate: string | nullid: string- inventoryQuantity: numberitemId: stringjobId: stringlocationId: string+ modelUploadId: string | nullnotes: Json | null- orderQuantity: number- productionQuantity: number+ productionQuantity: number | null+ quantity: numberquantityComplete: numberquantityReceivedToInventory: numberquantityShipped: number@@ -6892,13 +6895,13 @@ export type Database = {deadlineType?: Database["public"]["Enums"]["deadlineType"]dueDate?: string | nullid?: string- inventoryQuantity?: numberitemId: stringjobId: stringlocationId: string+ modelUploadId?: string | nullnotes?: Json | null- orderQuantity?: number- productionQuantity?: number+ productionQuantity?: number | null+ quantity?: numberquantityComplete?: numberquantityReceivedToInventory?: numberquantityShipped?: number@@ -6922,13 +6925,13 @@ export type Database = {deadlineType?: Database["public"]["Enums"]["deadlineType"]dueDate?: string | nullid?: string- inventoryQuantity?: numberitemId?: stringjobId?: stringlocationId?: string+ modelUploadId?: string | nullnotes?: Json | null- orderQuantity?: number- productionQuantity?: number+ productionQuantity?: number | null+ quantity?: numberquantityComplete?: numberquantityReceivedToInventory?: numberquantityShipped?: number@@ -7104,6 +7107,41 @@ export type Database = {referencedRelation: "salesOrders"referencedColumns: ["locationId"]},+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "fixtures"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "jobs"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "modelUpload"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "parts"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "salesRfqLines"+ referencedColumns: ["modelId"]+ },{foreignKeyName: "job_quoteId_fkey"columns: ["quoteId"]@@ -8576,7 +8614,9 @@ export type Database = {methodOperationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]order: number+ productionQuantity: number | nullquantity: number+ scrapQuantity: numberunitOfMeasureCode: stringupdatedAt: string | nullupdatedBy: string | null@@ -8595,7 +8635,9 @@ export type Database = {methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity: number+ scrapQuantity?: numberunitOfMeasureCode: stringupdatedAt?: string | nullupdatedBy?: string | null@@ -8614,7 +8656,9 @@ export type Database = {methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity?: number+ scrapQuantity?: numberunitOfMeasureCode?: stringupdatedAt?: string | nullupdatedBy?: string | null@@ -14256,11 +14300,13 @@ export type Database = {itemType: stringmethodType: Database["public"]["Enums"]["methodType"]order: number+ productionQuantity: number | nullquantity: numberquoteId: stringquoteLineId: stringquoteMakeMethodId: stringquoteOperationId: string | null+ scrapQuantity: numberunitCost: numberunitOfMeasureCode: string | nullupdatedAt: string | null@@ -14278,11 +14324,13 @@ export type Database = {itemType?: stringmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity?: numberquoteId: stringquoteLineId: stringquoteMakeMethodId: stringquoteOperationId?: string | null+ scrapQuantity?: numberunitCost?: numberunitOfMeasureCode?: string | nullupdatedAt?: string | null@@ -14300,11 +14348,13 @@ export type Database = {itemType?: stringmethodType?: Database["public"]["Enums"]["methodType"]order?: number+ productionQuantity?: number | nullquantity?: numberquoteId?: stringquoteLineId?: stringquoteMakeMethodId?: stringquoteOperationId?: string | null+ scrapQuantity?: numberunitCost?: numberunitOfMeasureCode?: string | nullupdatedAt?: string | null@@ -23049,22 +23099,23 @@ export type Database = {description: string | nulldueDate: string | nullid: string | null- inventoryQuantity: number | nullitemId: string | nullitemReadableId: string | nullitemTrackingType:| Database["public"]["Enums"]["itemTrackingType"]| null+ itemType: Database["public"]["Enums"]["itemType"] | nulljobId: string | nulllocationId: string | nullmodelId: string | nullmodelName: string | nullmodelPath: string | nullmodelSize: number | null+ modelUploadId: string | nullname: string | nullnotes: Json | null- orderQuantity: number | nullproductionQuantity: number | null+ quantity: number | nullquantityComplete: number | nullquantityReceivedToInventory: number | nullquantityShipped: number | null@@ -23080,7 +23131,6 @@ export type Database = {scrapQuantity: number | nullstatus: Database["public"]["Enums"]["jobStatus"] | nullthumbnailPath: string | null- type: Database["public"]["Enums"]["itemType"] | nullunitOfMeasureCode: string | nullupdatedAt: string | nullupdatedBy: string | null@@ -23247,6 +23297,41 @@ export type Database = {referencedRelation: "salesOrders"referencedColumns: ["locationId"]},+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "modelUpload"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "fixtures"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "jobs"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "parts"+ referencedColumns: ["modelId"]+ },+ {+ foreignKeyName: "job_modelUploadId_fkey"+ columns: ["modelUploadId"]+ isOneToOne: false+ referencedRelation: "salesRfqLines"+ referencedColumns: ["modelId"]+ },{foreignKeyName: "job_quoteId_fkey"columns: ["quoteId"]diff --git a/packages/database/supabase/migrations/20240909194622_jobs.sql b/packages/database/supabase/migrations/20240909194622_jobs.sqlindex 6184766779..3a17ed7deb 100644--- a/packages/database/supabase/migrations/20240909194622_jobs.sql+++ b/packages/database/supabase/migrations/20240909194622_jobs.sql@@ -93,6 +93,8 @@ CREATE TABLE "public"."job" ("dueDate" DATE,"deadlineType" "deadlineType" NOT NULL DEFAULT 'No Deadline',"quantity" NUMERIC(10, 4) NOT NULL DEFAULT 0,+ "scrapQuantity" NUMERIC(10, 4) NOT NULL DEFAULT 0,+ "productionQuantity" NUMERIC(10, 4) GENERATED ALWAYS AS ("quantity" + "scrapQuantity") STORED,"quantityComplete" NUMERIC(10, 4) NOT NULL DEFAULT 0,"quantityShipped" NUMERIC(10, 4) NOT NULL DEFAULT 0,"quantityReceivedToInventory" NUMERIC(10, 4) NOT NULL DEFAULT 0,@@ -272,8 +274,8 @@ CREATE OR REPLACE VIEW "jobs" WITH(SECURITY_INVOKER=true) ASj.*,i.name,i."readableId" as "itemReadableId",- i.type,- i.description,+ i.type as "itemType",+ i.name as "description",i."itemTrackingType",i.active,i."replenishmentSystem",@@ -293,4 +295,177 @@ CREATE OR REPLACE VIEW "jobs" WITH(SECURITY_INVOKER=true) ASINSERT INTO "customFieldTable" ("table", "name", "module")-VALUES ('job', 'Job', 'Production');\ No newline at end of file+VALUES ('job', 'Job', 'Production');++-- job sequence for existing companies+INSERT INTO "sequence" (+ "table",+ "name",+ "prefix",+ "suffix",+ "next",+ "size",+ "step",+ "companyId"+)+SELECT+ 'job',+ 'Job',+ 'WO',+ null,+ 0,+ 6,+ 1,+ id+FROM "company"+ON CONFLICT DO NOTHING;++ALTER TABLE "itemReplenishment"+ ADD COLUMN "scrapPercentage" NUMERIC(5, 2) DEFAULT 0 NOT NULL;++ALTER TABLE "methodMaterial"+ ADD COLUMN "scrapQuantity" NUMERIC(10, 4) NOT NULL DEFAULT 0,+ ADD COLUMN "productionQuantity" NUMERIC(10, 4) GENERATED ALWAYS AS ("quantity" + "scrapQuantity") STORED;++ALTER TABLE "quoteMaterial"+ ADD COLUMN "scrapQuantity" NUMERIC(10, 4) NOT NULL DEFAULT 0,+ ADD COLUMN "productionQuantity" NUMERIC(10, 4) GENERATED ALWAYS AS ("quantity" + "scrapQuantity") STORED;+++ALTER TABLE "job" ENABLE ROW LEVEL SECURITY;++CREATE POLICY "Employees can view jobs" ON "job"+ FOR SELECT+ USING (+ has_role('employee', "companyId")+ AND "companyId" = ANY(+ SELECT "companyId" from "userToCompany" where "userId" = auth.uid()::text+ )+ );++CREATE POLICY "Employees with production_create can insert jobs" ON "job"+ FOR INSERT+ WITH CHECK (+ has_role('employee', "companyId")+ AND has_company_permission('production_create', "companyId")+ );++CREATE POLICY "Employees with production_update can update jobs" ON "job"+ FOR UPDATE+ USING (+ has_role('employee', "companyId")+ AND has_company_permission('production_update', "companyId")+ );++CREATE POLICY "Employees with production_delete can delete jobs" ON "job"+ FOR DELETE+ USING (+ has_role('employee', "companyId")+ AND has_company_permission('production_delete', "companyId")+ );++CREATE POLICY "Customers with production_view can view their own jobs" ON "job"+ FOR SELECT+ USING (+ has_role('customer', "companyId") AND+ has_company_permission('production_view', "companyId") AND+ "customerId" IN (+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()+ )+ );++-- Search++CREATE FUNCTION public.create_job_search_result()+RETURNS TRIGGER AS $$+BEGIN+ INSERT INTO public.search(name, entity, uuid, link, "companyId")+ VALUES (new."jobId", 'Job', new.id, '/x/job/' || new.id, new."companyId");+ RETURN new;+END;+$$ LANGUAGE plpgsql SECURITY DEFINER;++CREATE TRIGGER create_job_search_result+ AFTER INSERT on public."job"+ FOR EACH ROW EXECUTE PROCEDURE public.create_job_search_result();++CREATE FUNCTION public.update_job_search_result()+RETURNS TRIGGER AS $$+BEGIN+ IF (old."jobId" <> new."jobId") THEN+ UPDATE public.search SET name = new."jobId"+ WHERE entity = 'Job' AND uuid = new.id AND "companyId" = new."companyId";+ END IF;+ RETURN new;+END;+$$ LANGUAGE plpgsql SECURITY DEFINER;++CREATE TRIGGER update_job_search_result+ AFTER UPDATE on public."job"+ FOR EACH ROW EXECUTE PROCEDURE public.update_job_search_result();++CREATE FUNCTION public.delete_job_search_result()+RETURNS TRIGGER AS $$+BEGIN+ DELETE FROM public.search WHERE entity = 'Job' AND uuid = old.id AND "companyId" = old."companyId";+ RETURN old;+END;+$$ LANGUAGE plpgsql SECURITY DEFINER;++CREATE TRIGGER delete_job_search_result+ AFTER DELETE on public."job"+ FOR EACH ROW EXECUTE PROCEDURE public.delete_job_search_result();++CREATE POLICY "Employees with production_view can search for jobs" ON "search"+ FOR SELECT+ USING (+ has_role('employee', "companyId") AND+ has_company_permission('production_view', "companyId") AND+ entity = 'Job'+ );++CREATE POLICY "Customers with production_view can search for their own jobs" ON "search"+ FOR SELECT+ USING (+ has_role('customer', "companyId") AND+ has_company_permission('production_view', "companyId") AND+ entity = 'Job' AND+ uuid IN (+ SELECT id FROM "job" WHERE "customerId" IN (+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()+ )+ )+ );+++CREATE POLICY "Job documents view requires production_view" ON storage.objects+FOR SELECT USING (+ bucket_id = 'private'+ AND has_role('employee', (storage.foldername(name))[1])+ AND has_company_permission('production_view', (storage.foldername(name))[1])+ AND (storage.foldername(name))[2] = 'job'+);++CREATE POLICY "Job documents insert requires production_create" ON storage.objects+FOR INSERT WITH CHECK (+ bucket_id = 'private'+ AND has_role('employee', (storage.foldername(name))[1])+ AND has_company_permission('production_create', (storage.foldername(name))[1])+ AND (storage.foldername(name))[2] = 'job'+);++CREATE POLICY "Job documents update requires production_update" ON storage.objects+FOR UPDATE USING (+ bucket_id = 'private'+ AND has_role('employee', (storage.foldername(name))[1])+ AND has_company_permission('production_update', (storage.foldername(name))[1])+ AND (storage.foldername(name))[2] = 'job'+);++CREATE POLICY "Job documents delete requires production_delete" ON storage.objects+FOR DELETE USING (+ bucket_id = 'private'+ AND has_role('employee', (storage.foldername(name))[1])+ AND has_company_permission('production_delete', (storage.foldername(name))[1])+ AND (storage.foldername(name))[2] = 'job'+);\ No newline at end of file