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: add ncr number to issue in mes

Brad Barbinbd5d74458248
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsx
index 262108fb5b..1bfaa3f04b 100644
--- a/apps/erp/app/components/Table/Table.tsx
+++ b/apps/erp/app/components/Table/Table.tsx
@@ -185,7 +185,7 @@ const AggregateSelector = ({
<DropdownMenu>
<DropdownMenuTrigger asChild>
<div className="flex justify-start items-center gap-2 cursor-pointer">
- {currentFunction?.icon}
+ <span className="text-muted-foreground">{currentFunction?.icon}</span>
<span className="font-medium">{formattedValue}</span>
</div>
</DropdownMenuTrigger>
diff --git a/apps/mes/app/components/JobOperation/JobOperation.tsx b/apps/mes/app/components/JobOperation/JobOperation.tsx
index 924b1e01d0..8ef7009bf0 100644
--- a/apps/mes/app/components/JobOperation/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation/JobOperation.tsx
@@ -139,6 +139,7 @@ type JobOperationProps = {
nonConformanceActions: Promise<
{
id: string;
+ nonConformanceId: string;
actionTypeName: string;
assignee: string;
notes: JSONContent;
@@ -300,7 +301,7 @@ export const JobOperation = ({
companyId,
createdBy: userId,
operationId,
- name: action.actionTypeName,
+ name: `${action.actionTypeName}-${action.nonConformanceId}`,
type: "Inspection" as const,
sortOrder: ++maxSortOrder,
nonConformanceActionId: actionId,
@@ -655,7 +656,16 @@ export const JobOperation = ({
<Separator />
<div className="flex flex-col items-start justify-between w-full">
<div className="flex flex-col gap-4 p-4 lg:p-6 w-full">
- <Heading size="h3">{action.actionTypeName}</Heading>
+ <div className="flex flex-col gap-0.5">
+ <Heading size="h3">
+ {action.actionTypeName}
+ </Heading>
+ <div>
+ <Badge variant="outline">
+ {action.nonConformanceId}
+ </Badge>
+ </div>
+ </div>
<div
className="prose dark:prose-invert prose-sm max-w-none"
dangerouslySetInnerHTML={{
diff --git a/apps/mes/app/services/operations.service.ts b/apps/mes/app/services/operations.service.ts
index 287746b942..2f15b9edd0 100644
--- a/apps/mes/app/services/operations.service.ts
+++ b/apps/mes/app/services/operations.service.ts
@@ -393,6 +393,7 @@ export async function getNonConformanceActions(
id: string;
actionTypeName: string;
assignee: string;
+ nonConformanceId: string;
notes: JSONContent;
}[];
}
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 7b1f0a9e7b..b842bdd3b4 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -14941,6 +14941,7 @@ export type Database = {
createdAt: string
createdBy: string
dueDate: string | null
+ externalId: Json | null
id: string
nonConformanceId: string
notes: Json
@@ -14959,6 +14960,7 @@ export type Database = {
createdAt?: string
createdBy: string
dueDate?: string | null
+ externalId?: Json | null
id?: string
nonConformanceId: string
notes?: Json
@@ -14977,6 +14979,7 @@ export type Database = {
createdAt?: string
createdBy?: string
dueDate?: string | null
+ externalId?: Json | null
id?: string
nonConformanceId?: string
notes?: Json
@@ -48811,6 +48814,7 @@ export type Database = {
actionTypeName: string
assignee: string
id: string
+ nonConformanceId: string
notes: Json
}[]
}
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 7b1f0a9e7b..b842bdd3b4 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -14941,6 +14941,7 @@ export type Database = {
createdAt: string
createdBy: string
dueDate: string | null
+ externalId: Json | null
id: string
nonConformanceId: string
notes: Json
@@ -14959,6 +14960,7 @@ export type Database = {
createdAt?: string
createdBy: string
dueDate?: string | null
+ externalId?: Json | null
id?: string
nonConformanceId: string
notes?: Json
@@ -14977,6 +14979,7 @@ export type Database = {
createdAt?: string
createdBy?: string
dueDate?: string | null
+ externalId?: Json | null
id?: string
nonConformanceId?: string
notes?: Json
@@ -48811,6 +48814,7 @@ export type Database = {
actionTypeName: string
assignee: string
id: string
+ nonConformanceId: string
notes: Json
}[]
}
diff --git a/packages/database/supabase/migrations/20251205002343_add-ncr-number-to-containment-aciton.sql b/packages/database/supabase/migrations/20251205002343_add-ncr-number-to-containment-aciton.sql
new file mode 100644
index 0000000000..6648618c43
--- /dev/null
+++ b/packages/database/supabase/migrations/20251205002343_add-ncr-number-to-containment-aciton.sql
@@ -0,0 +1,52 @@
+
+-- Function to get non-conformance action tasks by item and process
+-- Returns action tasks from non-complete issues that have the specified item and process
+DROP FUNCTION IF EXISTS get_action_tasks_by_item_and_process;
+CREATE OR REPLACE FUNCTION get_action_tasks_by_item_and_process(
+ p_item_id TEXT,
+ p_process_id TEXT,
+ p_company_id TEXT
+)
+RETURNS TABLE (
+ id TEXT,
+ "nonConformanceId" TEXT,
+ "actionTypeName" TEXT,
+ assignee TEXT,
+ notes JSONB
+)
+LANGUAGE sql
+STABLE
+AS $$
+ SELECT DISTINCT
+ ncat.id,
+ nc."nonConformanceId",
+ ncra.name AS "actionTypeName",
+ ncat.assignee,
+ ncat.notes::JSONB
+ FROM "nonConformanceActionTask" ncat
+ LEFT JOIN "nonConformanceRequiredAction" ncra
+ ON ncat."actionTypeId" = ncra."id"
+ AND ncat."companyId" = ncra."companyId"
+ INNER JOIN "nonConformance" nc ON ncat."nonConformanceId" = nc.id
+ WHERE ncat."companyId" = p_company_id
+ -- Match process through the junction table
+ AND EXISTS (
+ SELECT 1
+ FROM "nonConformanceActionProcess" ncap
+ WHERE ncap."actionTaskId" = ncat.id
+ AND ncap."processId" = p_process_id
+ AND ncap."companyId" = p_company_id
+ )
+ -- Match item and ensure non-conformance is not closed
+ AND EXISTS (
+ SELECT 1
+ FROM "nonConformance" nc
+ INNER JOIN "nonConformanceItem" nci
+ ON nc.id = nci."nonConformanceId"
+ AND nci."companyId" = p_company_id
+ WHERE nc.id = ncat."nonConformanceId"
+ AND nc."companyId" = p_company_id
+ AND nc.status != 'Closed'
+ AND nci."itemId" = p_item_id
+ );
+$$;
\ No newline at end of file