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.

style: update job operation status icons

Brad Barbine4e95b69aa64
diff --git a/apps/erp/app/assets/icons/AlmostDoneIcon.tsx b/apps/erp/app/assets/icons/AlmostDoneIcon.tsx
index da9e451fea..f81976c5e5 100644
--- a/apps/erp/app/assets/icons/AlmostDoneIcon.tsx
+++ b/apps/erp/app/assets/icons/AlmostDoneIcon.tsx
@@ -13,7 +13,7 @@ export function AlmostDoneIcon({ className }: { className?: string }) {
cy="7"
r="6"
fill="none"
- stroke="#10b981"
+ stroke="#155dfc"
strokeWidth="2"
strokeDasharray="3.14 0"
strokeDashoffset="-0.7"
@@ -23,7 +23,7 @@ export function AlmostDoneIcon({ className }: { className?: string }) {
cy="7"
r="2"
fill="none"
- stroke="#10b981"
+ stroke="#155dfc"
strokeWidth="4"
strokeDasharray="9.377654070965532 100"
strokeDashoffset="0"
diff --git a/apps/erp/app/assets/icons/TodoStatusIcon.tsx b/apps/erp/app/assets/icons/TodoStatusIcon.tsx
index 839bd62c05..e53ba75c1b 100644
--- a/apps/erp/app/assets/icons/TodoStatusIcon.tsx
+++ b/apps/erp/app/assets/icons/TodoStatusIcon.tsx
@@ -13,7 +13,7 @@ export function TodoStatusIcon({ className }: { className?: string }) {
cy="7"
r="6"
fill="none"
- stroke="#e2e2e2"
+ stroke="currentColor"
strokeWidth="2"
strokeDasharray="3.14 0"
strokeDashoffset="-0.7"
@@ -24,7 +24,7 @@ export function TodoStatusIcon({ className }: { className?: string }) {
cy="7"
r="2"
fill="none"
- stroke="#e2e2e2"
+ stroke="currentColor"
strokeWidth="4"
strokeDasharray="0 100"
strokeDashoffset="0"
diff --git a/apps/erp/app/components/Icons.tsx b/apps/erp/app/components/Icons.tsx
index a2afab62e3..f65cc63e81 100644
--- a/apps/erp/app/components/Icons.tsx
+++ b/apps/erp/app/components/Icons.tsx
@@ -173,14 +173,15 @@ export function OperationStatusIcon({
className?: string;
}) {
switch (status) {
- case "Ready":
case "Todo":
return <TodoStatusIcon className={cn("text-foreground", className)} />;
+ case "Ready":
+ return <TodoStatusIcon className={cn("text-blue-600", className)} />;
case "Waiting":
case "Canceled":
return <LuCircleX className={cn("text-red-600", className)} />;
case "Done":
- return <LuCircleCheck className={cn("text-blue-600", className)} />;
+ return <LuCircleCheck className={cn("text-green-600", className)} />;
case "In Progress":
return <AlmostDoneIcon className={className} />;
case "Paused":
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
index b81ab6cec9..a657867283 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -270,7 +270,7 @@ const JobHeader = () => {
onClick={releaseModal.onOpen}
isLoading={
statusFetcher.state !== "idle" &&
- ["Ready", "Planned"].includes(status ?? "")
+ statusFetcher.formData?.get("status") === "Ready"
}
isDisabled={
!["Draft", "Planned"].includes(status ?? "") ||
diff --git a/apps/mes/app/assets/icons/AlmostDoneIcon.tsx b/apps/mes/app/assets/icons/AlmostDoneIcon.tsx
index da9e451fea..f81976c5e5 100644
--- a/apps/mes/app/assets/icons/AlmostDoneIcon.tsx
+++ b/apps/mes/app/assets/icons/AlmostDoneIcon.tsx
@@ -13,7 +13,7 @@ export function AlmostDoneIcon({ className }: { className?: string }) {
cy="7"
r="6"
fill="none"
- stroke="#10b981"
+ stroke="#155dfc"
strokeWidth="2"
strokeDasharray="3.14 0"
strokeDashoffset="-0.7"
@@ -23,7 +23,7 @@ export function AlmostDoneIcon({ className }: { className?: string }) {
cy="7"
r="2"
fill="none"
- stroke="#10b981"
+ stroke="#155dfc"
strokeWidth="4"
strokeDasharray="9.377654070965532 100"
strokeDashoffset="0"
diff --git a/apps/mes/app/assets/icons/TodoStatusIcon.tsx b/apps/mes/app/assets/icons/TodoStatusIcon.tsx
index 58458ad63c..e285f07aa2 100644
--- a/apps/mes/app/assets/icons/TodoStatusIcon.tsx
+++ b/apps/mes/app/assets/icons/TodoStatusIcon.tsx
@@ -13,7 +13,7 @@ export function TodoStatusIcon({ className }: { className?: string }) {
cy="7"
r="6"
fill="none"
- stroke="#e2e2e2"
+ stroke="currentColor"
strokeWidth="2"
strokeDasharray="3.14 0"
strokeDashoffset="-0.7"
@@ -24,7 +24,7 @@ export function TodoStatusIcon({ className }: { className?: string }) {
cy="7"
r="2"
fill="none"
- stroke="#e2e2e2"
+ stroke="currentColor"
strokeWidth="4"
strokeDasharray="0 100"
strokeDashoffset="0"
diff --git a/apps/mes/app/components/Icons.tsx b/apps/mes/app/components/Icons.tsx
index cb8f1dacc3..30df9e4071 100644
--- a/apps/mes/app/components/Icons.tsx
+++ b/apps/mes/app/components/Icons.tsx
@@ -194,14 +194,15 @@ export function OperationStatusIcon({
status: Operation["operationStatus"];
}) {
switch (status) {
- case "Ready":
case "Todo":
return <TodoStatusIcon className="text-foreground" />;
+ case "Ready":
+ return <TodoStatusIcon className="text-blue-600" />;
case "Waiting":
case "Canceled":
return <LuCircleX className="text-muted-foreground" />;
case "Done":
- return <LuCircleCheck className="text-blue-600" />;
+ return <LuCircleCheck className="text-green-600" />;
case "In Progress":
return <AlmostDoneIcon />;
case "Paused":
diff --git a/packages/database/supabase/migrations/20251009000041_finish-job-quantity.sql b/packages/database/supabase/migrations/20251009000041_finish-job-quantity.sql
new file mode 100644
index 0000000000..14a10fd87f
--- /dev/null
+++ b/packages/database/supabase/migrations/20251009000041_finish-job-quantity.sql
@@ -0,0 +1,155 @@
+CREATE OR REPLACE FUNCTION finish_job_operation()
+RETURNS TRIGGER AS $$
+BEGIN
+ -- Set endTime for all open production events
+ UPDATE "productionEvent"
+ SET "endTime" = NOW()
+ WHERE "jobOperationId" = NEW.id AND "endTime" IS NULL;
+
+ -- Find all operations that depend on this one and might be ready
+ UPDATE "jobOperation" op
+ SET status = 'Ready'
+ WHERE EXISTS (
+ SELECT 1
+ FROM "jobOperationDependency" dep
+ WHERE dep."operationId" = op.id
+ AND dep."dependsOnId" = NEW.id
+ AND op.status = 'Waiting'
+ )
+ AND NOT EXISTS (
+ -- Check no other dependencies are incomplete
+ SELECT 1
+ FROM "jobOperationDependency" dep2
+ JOIN "jobOperation" jo2 ON jo2.id = dep2."dependsOnId"
+ WHERE dep2."operationId" = op.id
+ AND jo2.status != 'Done'
+ AND jo2.id != NEW.id
+ );
+
+ -- Set the job operation status to Done
+ NEW.status = 'Done';
+
+ -- If this is the last operation, mark the job as Done
+ IF is_last_job_operation(NEW.id) THEN
+ DECLARE
+ request_id TEXT;
+ notify_url TEXT;
+ api_url TEXT;
+ anon_key TEXT;
+ group_ids TEXT[];
+ assigned_to TEXT;
+ sales_order_id TEXT;
+ BEGIN
+ -- Get job details
+ DECLARE
+ job_item_id TEXT;
+ job_quantity_to_produce INTEGER;
+ job_location_id TEXT;
+ job_shelf_id TEXT;
+ job_quantity INTEGER;
+ quantity_complete INTEGER;
+
+ BEGIN
+
+
+ SELECT "locationId", "shelfId", "quantity"
+ INTO job_location_id, job_shelf_id, job_quantity
+ FROM "job"
+ WHERE "id" = NEW."jobId";
+
+ -- Use full job quantity if quantityComplete is 0
+ quantity_complete := CASE
+ WHEN NEW."quantityComplete" = 0 THEN job_quantity
+ ELSE NEW."quantityComplete"
+ END;
+
+
+
+ -- Get sales order info
+ SELECT "salesOrderId" INTO sales_order_id FROM "job" WHERE "id" = NEW."jobId";
+
+ IF sales_order_id IS NOT NULL THEN
+ -- Make-to-order: just update job status with quantityComplete
+ UPDATE "job"
+ SET status = 'Completed',
+ "completedDate" = NOW(),
+ "quantityComplete" = quantity_complete,
+ "updatedAt" = NOW(),
+ "updatedBy" = NEW."updatedBy"
+ WHERE id = NEW."jobId";
+ ELSE
+ -- Make-to-stock: update job status to Done and invoke edge function for inventory
+ UPDATE "job"
+ SET status = 'Completed',
+ "completedDate" = NOW(),
+ "updatedAt" = NOW(),
+ "updatedBy" = NEW."updatedBy"
+ WHERE id = NEW."jobId";
+
+ -- Invoke the issue edge function to handle inventory
+ PERFORM util.invoke_edge_function(
+ name => 'issue',
+ body => CASE
+ WHEN job_shelf_id IS NOT NULL THEN
+ jsonb_build_object(
+ 'type', 'jobCompleteInventory',
+ 'jobId', NEW."jobId",
+ 'companyId', NEW."companyId",
+ 'userId', NEW."updatedBy",
+ 'quantityComplete', quantity_complete,
+ 'locationId', job_location_id,
+ 'shelfId', job_shelf_id
+ )
+ ELSE
+ jsonb_build_object(
+ 'type', 'jobCompleteInventory',
+ 'jobId', NEW."jobId",
+ 'companyId', NEW."companyId",
+ 'userId', NEW."updatedBy",
+ 'quantityComplete', quantity_complete,
+ 'locationId', job_location_id
+ )
+ END
+ );
+ END IF;
+ END;
+
+ SELECT "apiUrl", "anonKey" INTO api_url, anon_key FROM "config" LIMIT 1;
+ notify_url := api_url || '/functions/v1/trigger';
+
+ SELECT "assignee", "salesOrderId" INTO assigned_to, sales_order_id FROM "job" WHERE "id" = NEW."jobId";
+
+ IF sales_order_id IS NULL THEN
+ SELECT "inventoryJobCompletedNotificationGroup" INTO group_ids FROM "companySettings" WHERE "id" = NEW."companyId";
+ ELSE
+ SELECT "salesJobCompletedNotificationGroup" INTO group_ids FROM "companySettings" WHERE "id" = NEW."companyId";
+ END IF;
+
+ IF assigned_to IS NOT NULL THEN
+ SELECT array_append(group_ids, assigned_to) INTO group_ids;
+ END IF;
+
+ IF array_length(group_ids, 1) > 0 THEN
+ SELECT net.http_post(
+ notify_url,
+ jsonb_build_object(
+ 'type', 'notify',
+ 'event', 'job-completed',
+ 'documentId', NEW."jobId",
+ 'companyId', NEW."companyId",
+ 'recipient', jsonb_build_object(
+ 'type', 'group',
+ 'groupIds', group_ids
+ )
+ )::jsonb,
+ '{}'::jsonb,
+ jsonb_build_object('Content-Type', 'application/json', 'Authorization', 'Bearer ' || anon_key)
+ ) INTO request_id;
+ END IF;
+
+ END;
+ END IF;
+
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
\ No newline at end of file