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: update configuration from make method

Brad Barbin12a38b73eba3
diff --git a/apps/carbon/app/hooks/useSwaggerDocs.tsx b/apps/carbon/app/hooks/useSwaggerDocs.tsx
index d98a11ae30..a717c98735 100644
--- a/apps/carbon/app/hooks/useSwaggerDocs.tsx
+++ b/apps/carbon/app/hooks/useSwaggerDocs.tsx
@@ -14,7 +14,5 @@ export const useSwaggerDocs = () => {
docsFetcher.load(path.to.api.docs);
});
- const swaggerDocs = docsFetcher.data;
-
- return swaggerDocs;
+ return docsFetcher.data;
};
diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
index 95254b3b7c..16e6f816c0 100644
--- a/apps/carbon/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
+++ b/apps/carbon/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
@@ -1,3 +1,4 @@
+import { useCarbon } from "@carbon/auth";
import { ValidatedForm } from "@carbon/form";
import {
Alert,
@@ -23,16 +24,18 @@ import {
useMount,
VStack,
} from "@carbon/react";
-import { useFetcher, useLocation, useParams } from "@remix-run/react";
+import { Await, useFetcher, useLocation, useParams } from "@remix-run/react";
import type { PostgrestResponse } from "@supabase/supabase-js";
-import { useEffect, useMemo, useState } from "react";
+import { Suspense, useEffect, useMemo, useState } from "react";
import {
LuAlertTriangle,
LuDownload,
+ LuSettings,
LuSquareStack,
LuUpload,
} from "react-icons/lu";
import { RiProgress4Line } from "react-icons/ri";
+import { ConfiguratorModal } from "~/components/Configurator/ConfiguratorForm";
import {
Hidden,
Item,
@@ -42,6 +45,10 @@ import {
} from "~/components/Form";
import type { Tree } from "~/components/TreeView";
import { usePermissions, useRouteData } from "~/hooks";
+import type {
+ ConfigurationParameter,
+ ConfigurationParameterGroup,
+} from "~/modules/items";
import { path } from "~/utils/path";
import { getJobMethodValidator } from "../../production.models";
import type { Job, JobMethod } from "../../types";
@@ -55,6 +62,10 @@ const JobBreadcrumbs = () => {
const routeData = useRouteData<{
job: Job;
method: Tree<JobMethod>;
+ configurationParameters: Promise<{
+ groups: ConfigurationParameterGroup[];
+ parameters: ConfigurationParameter[];
+ }>;
}>(path.to.job(jobId));
const isDisabled = ["Completed", "Cancelled", "In Progress"].includes(
@@ -90,6 +101,39 @@ const JobBreadcrumbs = () => {
materialId &&
pathname === path.to.jobMakeMethod(jobId, methodId, materialId);
+ const { carbon } = useCarbon();
+
+ const configuratorModal = useDisclosure();
+ const [isConfigured, setIsConfigured] = useState(false);
+ const getIsConfigured = async () => {
+ if (isJobMethod && routeData?.job.itemId && carbon) {
+ const { data, error } = await carbon
+ .from("itemReplenishment")
+ .select("requiresConfiguration")
+ .eq("itemId", routeData.job.itemId)
+ .single();
+
+ if (error) {
+ console.error(error);
+ }
+
+ setIsConfigured(data?.requiresConfiguration ?? false);
+ }
+ };
+
+ useMount(() => {
+ getIsConfigured();
+ });
+
+ const saveConfiguration = async (configuration: Record<string, any>) => {
+ configuratorModal.onClose();
+ fetcher.submit(JSON.stringify(configuration), {
+ method: "post",
+ action: path.to.jobConfigure(jobId),
+ encType: "application/json",
+ });
+ };
+
return (
<>
{permissions.can("update", "production") &&
@@ -115,6 +159,23 @@ const JobBreadcrumbs = () => {
>
Get Method
</MenubarItem>
+ {isConfigured && isJobMethod && (
+ <MenubarItem
+ leftIcon={<LuSettings />}
+ isDisabled={
+ isDisabled || !permissions.can("update", "production")
+ }
+ isLoading={
+ fetcher.state !== "idle" &&
+ fetcher.formAction === path.to.jobConfigure(jobId)
+ }
+ onClick={() => {
+ configuratorModal.onOpen();
+ }}
+ >
+ Configure
+ </MenubarItem>
+ )}
</HStack>
</HStack>
</Menubar>
@@ -303,6 +364,27 @@ const JobBreadcrumbs = () => {
</ModalContent>
</Modal>
)}
+
+ {configuratorModal.isOpen && (
+ <Suspense fallback={null}>
+ <Await resolve={routeData?.configurationParameters}>
+ {(configurationParameters) => (
+ <ConfiguratorModal
+ open
+ initialValues={
+ (routeData?.job.configuration || {}) as Record<string, any>
+ }
+ groups={configurationParameters?.groups ?? []}
+ parameters={configurationParameters?.parameters ?? []}
+ onClose={configuratorModal.onClose}
+ onSubmit={(config: Record<string, any>) => {
+ saveConfiguration(config);
+ }}
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
</>
);
};
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 0d742759a3..f233b2cd8d 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -257,6 +257,47 @@ export async function deleteSalesRFQLine(
return client.from("salesRfqLine").delete().eq("id", salesRFQLineId);
}
+export async function getConfigurationParametersByQuoteLineId(
+ client: SupabaseClient<Database>,
+ quoteLineId: string,
+ companyId: string
+) {
+ const quoteLine = await client
+ .from("quoteLine")
+ .select("itemId")
+ .eq("id", quoteLineId)
+ .single();
+
+ if (quoteLine.error || !quoteLine.data) {
+ return { groups: [], parameters: [] };
+ }
+
+ const [parameters, groups] = await Promise.all([
+ client
+ .from("configurationParameter")
+ .select("*")
+ .eq("itemId", quoteLine.data.itemId)
+ .eq("companyId", companyId),
+ client
+ .from("configurationParameterGroup")
+ .select("*")
+ .eq("itemId", quoteLine.data.itemId)
+ .eq("companyId", companyId),
+ ]);
+
+ if (parameters.error) {
+ console.error(parameters.error);
+ return { groups: [], parameters: [] };
+ }
+
+ if (groups.error) {
+ console.error(groups.error);
+ return { groups: [], parameters: [] };
+ }
+
+ return { groups: groups.data ?? [], parameters: parameters.data ?? [] };
+}
+
export async function getCustomer(
client: SupabaseClient<Database>,
customerId: string
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
index f749cc3076..981f381f62 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
@@ -1,3 +1,4 @@
+import { useCarbon } from "@carbon/auth";
import { ValidatedForm } from "@carbon/form";
import {
Alert,
@@ -16,14 +17,25 @@ import {
ModalTitle,
toast,
useDisclosure,
+ useMount,
VStack,
} from "@carbon/react";
-import { useFetcher, useLocation, useParams } from "@remix-run/react";
-import { useEffect, useState } from "react";
-import { LuAlertTriangle, LuDownload, LuUpload } from "react-icons/lu";
+import { Await, useFetcher, useLocation, useParams } from "@remix-run/react";
+import { Suspense, useEffect, useState } from "react";
+import {
+ LuAlertTriangle,
+ LuDownload,
+ LuSettings,
+ LuUpload,
+} from "react-icons/lu";
+import { ConfiguratorModal } from "~/components/Configurator/ConfiguratorForm";
import { Hidden, Item, Submit } from "~/components/Form";
import type { Tree } from "~/components/TreeView";
import { usePermissions, useRouteData } from "~/hooks";
+import type {
+ ConfigurationParameter,
+ ConfigurationParameterGroup,
+} from "~/modules/items";
import { path } from "~/utils/path";
import { getLineMethodValidator, getMethodValidator } from "../../sales.models";
import type { Quotation, QuotationLine, QuoteMethod } from "../../types";
@@ -39,6 +51,14 @@ const QuoteMakeMethodTools = () => {
lines: QuotationLine[];
methods: Promise<Tree<QuoteMethod>[]> | Tree<QuoteMethod>[];
}>(path.to.quote(quoteId));
+
+ const lineData = useRouteData<{
+ configurationParameters: Promise<{
+ groups: ConfigurationParameterGroup[];
+ parameters: ConfigurationParameter[];
+ }>;
+ }>(path.to.quoteLineMethod(quoteId, lineId!, methodId!));
+
const line = routeData?.lines.find((line) => line.id === lineId);
const { pathname } = useLocation();
@@ -73,6 +93,39 @@ const QuoteMakeMethodTools = () => {
pathname ===
path.to.quoteLineMakeMethod(quoteId, lineId!, methodId, materialId);
+ const { carbon } = useCarbon();
+
+ const configuratorModal = useDisclosure();
+ const [isConfigured, setIsConfigured] = useState(false);
+ const getIsConfigured = async () => {
+ if (isQuoteLineMethod && line?.itemId && carbon) {
+ const { data, error } = await carbon
+ .from("itemReplenishment")
+ .select("requiresConfiguration")
+ .eq("itemId", line.itemId)
+ .single();
+
+ if (error) {
+ console.error(error);
+ }
+
+ setIsConfigured(data?.requiresConfiguration ?? false);
+ }
+ };
+
+ useMount(() => {
+ getIsConfigured();
+ });
+
+ const saveConfiguration = async (configuration: Record<string, any>) => {
+ configuratorModal.onClose();
+ fetcher.submit(JSON.stringify(configuration), {
+ method: "post",
+ action: path.to.quoteLineConfigure(quoteId, lineId!),
+ encType: "application/json",
+ });
+ };
+
return (
<>
{line &&
@@ -99,6 +152,22 @@ const QuoteMakeMethodTools = () => {
>
Save Method
</MenubarItem>
+ {isConfigured && isQuoteLineMethod && (
+ <MenubarItem
+ leftIcon={<LuSettings />}
+ isDisabled={!permissions.can("update", "sales")}
+ isLoading={
+ fetcher.state !== "idle" &&
+ fetcher.formAction ===
+ path.to.quoteLineConfigure(quoteId, lineId!)
+ }
+ onClick={() => {
+ configuratorModal.onOpen();
+ }}
+ >
+ Configure
+ </MenubarItem>
+ )}
</HStack>
</HStack>
</Menubar>
@@ -274,6 +343,27 @@ const QuoteMakeMethodTools = () => {
</ModalContent>
</Modal>
)}
+
+ {configuratorModal.isOpen && (
+ <Suspense fallback={null}>
+ <Await resolve={lineData?.configurationParameters}>
+ {(configurationParameters) => (
+ <ConfiguratorModal
+ open
+ initialValues={
+ (line?.configuration || {}) as Record<string, any>
+ }
+ groups={configurationParameters?.groups ?? []}
+ parameters={configurationParameters?.parameters ?? []}
+ onClose={configuratorModal.onClose}
+ onSubmit={(config: Record<string, any>) => {
+ saveConfiguration(config);
+ }}
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
</>
);
};
diff --git a/apps/carbon/app/routes/x+/api+/_layout.tsx b/apps/carbon/app/routes/x+/api+/_layout.tsx
index 82b513a6da..723d0cb9e5 100644
--- a/apps/carbon/app/routes/x+/api+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/api+/_layout.tsx
@@ -88,6 +88,8 @@ export default function ApiDocsRoute() {
const tableBlacklist = new Set([
"apiKey",
"documentTransaction",
+ "feedback",
+ "groups_recursive",
"invite",
"oauthClient",
"oauthCode",
diff --git a/apps/carbon/app/routes/x+/job+/$jobId.configure.tsx b/apps/carbon/app/routes/x+/job+/$jobId.configure.tsx
new file mode 100644
index 0000000000..5c09f3980c
--- /dev/null
+++ b/apps/carbon/app/routes/x+/job+/$jobId.configure.tsx
@@ -0,0 +1,41 @@
+import { error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { redirect, type ActionFunctionArgs } from "@vercel/remix";
+import { path, requestReferrer } from "~/utils/path";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { client, userId } = await requirePermissions(request, {
+ update: "production",
+ role: "employee",
+ });
+ const { jobId } = params;
+ if (!jobId) throw new Error("Could not find jobId");
+
+ const configuration = await request.json();
+
+ if (configuration) {
+ const result = await client
+ .from("job")
+ .update({
+ configuration,
+ updatedAt: new Date().toISOString(),
+ updatedBy: userId,
+ })
+ .eq("id", jobId);
+
+ if (result.error) {
+ throw redirect(
+ requestReferrer(request) ?? path.to.job(jobId),
+ await flash(request, error("Failed to update job"))
+ );
+ }
+ } else {
+ throw new Error("No configuration provided");
+ }
+
+ throw redirect(
+ requestReferrer(request) ?? path.to.job(jobId),
+ await flash(request, success("Updated job"))
+ );
+}
diff --git a/apps/carbon/app/routes/x+/job+/$jobId.tsx b/apps/carbon/app/routes/x+/job+/$jobId.tsx
index d65790c46e..8e1207e724 100644
--- a/apps/carbon/app/routes/x+/job+/$jobId.tsx
+++ b/apps/carbon/app/routes/x+/job+/$jobId.tsx
@@ -15,6 +15,7 @@ import { Suspense } from "react";
import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";
import { ExplorerSkeleton } from "~/components/Skeletons";
import { flattenTree } from "~/components/TreeView";
+import { getConfigurationParameters } from "~/modules/items";
import {
getJob,
getJobDocuments,
@@ -65,6 +66,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
tags: tags.data ?? [],
files: getJobDocuments(serviceRole, companyId, job.data),
method: getJobMethodTree(serviceRole, jobId), // returns a promise
+ configurationParameters: getConfigurationParameters(
+ serviceRole,
+ job.data.itemId!,
+ companyId
+ ),
});
}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.configure.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.configure.tsx
new file mode 100644
index 0000000000..8e27389a19
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.configure.tsx
@@ -0,0 +1,40 @@
+import { error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { redirect, type ActionFunctionArgs } from "@vercel/remix";
+import { path, requestReferrer } from "~/utils/path";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { client, userId } = await requirePermissions(request, {
+ update: "production",
+ role: "employee",
+ });
+ const { quoteId, lineId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const configuration = await request.json();
+ if (configuration) {
+ const result = await client
+ .from("quoteLine")
+ .update({
+ configuration,
+ updatedAt: new Date().toISOString(),
+ updatedBy: userId,
+ })
+ .eq("id", lineId);
+
+ if (result.error) {
+ throw redirect(
+ requestReferrer(request) ?? path.to.quoteLine(quoteId, lineId),
+ await flash(request, error("Failed to update quote line"))
+ );
+ }
+ } else {
+ throw new Error("No configuration provided");
+ }
+ throw redirect(
+ requestReferrer(request) ?? path.to.quoteLine(quoteId, lineId),
+ await flash(request, success("Updated quote line"))
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
index 30b80e5e38..b55c156416 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
@@ -1,8 +1,9 @@
import type { JSONContent } from "@carbon/react";
import { VStack } from "@carbon/react";
-import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
+import { defer, redirect, useLoaderData, useParams } from "@remix-run/react";
import {
+ getConfigurationParametersByQuoteLineId,
getQuoteMaterialsByMethodId,
getQuoteOperationsByMethodId,
} from "~/modules/sales";
@@ -19,7 +20,7 @@ import { flash } from "@carbon/auth/session.server";
import type { LoaderFunctionArgs } from "@vercel/remix";
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
+ const { client, companyId } = await requirePermissions(request, {
view: "sales",
});
@@ -53,7 +54,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- return json({
+ return defer({
materials:
materials?.data.map((m) => ({
...m,
@@ -72,6 +73,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
quoteMakeMethodId: o.quoteMakeMethodId ?? methodId,
workInstruction: o.workInstruction as JSONContent,
})) ?? [],
+ configurationParameters: getConfigurationParametersByQuoteLineId(
+ client,
+ lineId,
+ companyId
+ ),
});
}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index e883c39d39..ac207c2d21 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -397,6 +397,7 @@ export const path = {
itemPostingGroups: `${x}/items/groups`,
job: (id: string) => generatePath(`${x}/job/${id}`),
jobComplete: (id: string) => generatePath(`${x}/job/${id}/complete`),
+ jobConfigure: (id: string) => generatePath(`${x}/job/${id}/configure`),
jobDetails: (id: string) => generatePath(`${x}/job/${id}/details`),
jobMaterial: (jobId: string, id: string) =>
generatePath(`${x}/job/methods/${jobId}/material/${id}`),
@@ -680,6 +681,8 @@ export const path = {
generatePath(`${x}/quote/${id}/internal`),
quoteLine: (quoteId: string, id: string) =>
generatePath(`${x}/quote/${quoteId}/${id}/details`),
+ quoteLineConfigure: (quoteId: string, lineId: string) =>
+ generatePath(`${x}/quote/${quoteId}/${lineId}/configure`),
quoteLineCost: (quoteId: string, lineId: string) =>
generatePath(`${x}/quote/${quoteId}/${lineId}/cost/update`),
quoteLineMethodMaterial: (
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 883c023fef..daf3360d9a 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -7603,6 +7603,7 @@ export type Database = {
Row: {
assignee: string | null
companyId: string
+ configuration: Json | null
createdAt: string
createdBy: string
customerId: string | null
@@ -7634,6 +7635,7 @@ export type Database = {
Insert: {
assignee?: string | null
companyId: string
+ configuration?: Json | null
createdAt?: string
createdBy: string
customerId?: string | null
@@ -7665,6 +7667,7 @@ export type Database = {
Update: {
assignee?: string | null
companyId?: string
+ configuration?: Json | null
createdAt?: string
createdBy?: string
customerId?: string | null
@@ -15558,6 +15561,7 @@ export type Database = {
Row: {
additionalCharges: Json | null
companyId: string
+ configuration: Json | null
createdBy: string
customerPartId: string | null
customerPartRevision: string | null
@@ -15588,6 +15592,7 @@ export type Database = {
Insert: {
additionalCharges?: Json | null
companyId: string
+ configuration?: Json | null
createdBy: string
customerPartId?: string | null
customerPartRevision?: string | null
@@ -15618,6 +15623,7 @@ export type Database = {
Update: {
additionalCharges?: Json | null
companyId?: string
+ configuration?: Json | null
createdBy?: string
customerPartId?: string | null
customerPartRevision?: string | null
@@ -26474,6 +26480,7 @@ export type Database = {
assignee: string | null
autodeskUrn: string | null
companyId: string | null
+ configuration: Json | null
createdAt: string | null
createdBy: string | null
customerId: string | null
@@ -28690,6 +28697,7 @@ export type Database = {
additionalCharges: Json | null
autodeskUrn: string | null
companyId: string | null
+ configuration: Json | null
createdBy: string | null
customerPartId: string | null
customerPartRevision: string | null
@@ -32501,6 +32509,7 @@ export type Database = {
Enums: {
accountingPeriodStatus: "Inactive" | "Active"
configurationParameterDataType: "text" | "numeric" | "boolean" | "list"
+ configurationSourceDocument: "Quote Line" | "Job"
costLedgerType:
| "Direct Cost"
| "Revaluation"
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 883c023fef..daf3360d9a 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -7603,6 +7603,7 @@ export type Database = {
Row: {
assignee: string | null
companyId: string
+ configuration: Json | null
createdAt: string
createdBy: string
customerId: string | null
@@ -7634,6 +7635,7 @@ export type Database = {
Insert: {
assignee?: string | null
companyId: string
+ configuration?: Json | null
createdAt?: string
createdBy: string
customerId?: string | null
@@ -7665,6 +7667,7 @@ export type Database = {
Update: {
assignee?: string | null
companyId?: string
+ configuration?: Json | null
createdAt?: string
createdBy?: string
customerId?: string | null
@@ -15558,6 +15561,7 @@ export type Database = {
Row: {
additionalCharges: Json | null
companyId: string
+ configuration: Json | null
createdBy: string
customerPartId: string | null
customerPartRevision: string | null
@@ -15588,6 +15592,7 @@ export type Database = {
Insert: {
additionalCharges?: Json | null
companyId: string
+ configuration?: Json | null
createdBy: string
customerPartId?: string | null
customerPartRevision?: string | null
@@ -15618,6 +15623,7 @@ export type Database = {
Update: {
additionalCharges?: Json | null
companyId?: string
+ configuration?: Json | null
createdBy?: string
customerPartId?: string | null
customerPartRevision?: string | null
@@ -26474,6 +26480,7 @@ export type Database = {
assignee: string | null
autodeskUrn: string | null
companyId: string | null
+ configuration: Json | null
createdAt: string | null
createdBy: string | null
customerId: string | null
@@ -28690,6 +28697,7 @@ export type Database = {
additionalCharges: Json | null
autodeskUrn: string | null
companyId: string | null
+ configuration: Json | null
createdBy: string | null
customerPartId: string | null
customerPartRevision: string | null
@@ -32501,6 +32509,7 @@ export type Database = {
Enums: {
accountingPeriodStatus: "Inactive" | "Active"
configurationParameterDataType: "text" | "numeric" | "boolean" | "list"
+ configurationSourceDocument: "Quote Line" | "Job"
costLedgerType:
| "Direct Cost"
| "Revaluation"
diff --git a/packages/database/supabase/migrations/20241227143403_configuration-instances.sql b/packages/database/supabase/migrations/20241227143403_configuration-instances.sql
index b10e91f40f..a07a305f2b 100644
--- a/packages/database/supabase/migrations/20241227143403_configuration-instances.sql
+++ b/packages/database/supabase/migrations/20241227143403_configuration-instances.sql
@@ -14,4 +14,63 @@ CREATE POLICY "Employees can view configuration groups" ON "configurationParamet
FOR SELECT
USING (
has_role('employee', "companyId")
- );
\ No newline at end of file
+ );
+
+DROP VIEW IF EXISTS "jobs";
+CREATE OR REPLACE VIEW "jobs" WITH(SECURITY_INVOKER=true) AS
+WITH job_model AS (
+ SELECT
+ j.id AS job_id,
+ COALESCE(j."modelUploadId", i."modelUploadId") AS model_upload_id
+ FROM "job" j
+ INNER JOIN "item" i ON j."itemId" = i."id"
+)
+SELECT
+ j.*,
+ i.name,
+ i."readableId" as "itemReadableId",
+ i.type as "itemType",
+ i.name as "description",
+ i."itemTrackingType",
+ i.active,
+ i."replenishmentSystem",
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ so."salesOrderId" as "salesOrderReadableId",
+ qo."quoteId" as "quoteReadableId"
+FROM "job" j
+INNER JOIN "item" i ON j."itemId" = i."id"
+LEFT JOIN job_model jm ON j.id = jm.job_id
+LEFT JOIN "modelUpload" mu ON mu.id = jm.model_upload_id
+LEFT JOIN "salesOrder" so on j."salesOrderId" = so.id
+LEFT JOIN "quote" qo ON j."quoteId" = qo.id;
+
+-- Update quoteLines view
+DROP VIEW IF EXISTS "quoteLines";
+CREATE OR REPLACE VIEW "quoteLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ ql.*,
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ COALESCE(mu.id, imu.id) as "modelId",
+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",
+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",
+ COALESCE(mu."name", imu."name") as "modelName",
+ COALESCE(mu."size", imu."size") as "modelSize",
+ ic."unitCost" as "unitCost"
+ FROM "quoteLine" ql
+ LEFT JOIN "modelUpload" mu ON ql."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = ql."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+);
\ No newline at end of file