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 estimatedTime and actualTime to job table

Brad Barbin9f8a902abc5b
diff --git a/apps/erp/app/components/New.tsx b/apps/erp/app/components/New.tsx
index 7f3aad37bd..71ecfbab4e 100644
--- a/apps/erp/app/components/New.tsx
+++ b/apps/erp/app/components/New.tsx
@@ -30,13 +30,12 @@ const New = ({ label, to }: NewProps) => {
<TooltipTrigger>
<Button asChild leftIcon={<LuCirclePlus />} ref={buttonRef}>
<Link to={to} prefetch="intent">
- New
+ Add {label}
</Link>
</Button>
</TooltipTrigger>
<TooltipContent>
<HStack>
- <span>New {label}</span>
<Kbd>N</Kbd>
</HStack>
</TooltipContent>
diff --git a/apps/erp/app/routes/api+/production.kpi.$key.ts b/apps/erp/app/routes/api+/production.kpi.$key.ts
index b01d0d37a4..26a1f690ad 100644
--- a/apps/erp/app/routes/api+/production.kpi.$key.ts
+++ b/apps/erp/app/routes/api+/production.kpi.$key.ts
@@ -30,8 +30,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const daysBetween = endDate.compare(startDate);
// Calculate previous period dates
- const previousEndDate = startDate;
- const previousStartDate = startDate.add({ days: -daysBetween });
+ const previousEnd = startDate;
+ const previousStart = startDate.add({ days: -daysBetween });
const interval = searchParams.get("interval");
@@ -78,8 +78,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
.from("productionEvent")
.select("startTime, endTime, workCenterId")
.eq("companyId", companyId)
- .gt("startTime", previousStartDate.toString())
- .or(`endTime.lte.${previousEndDate.toString()},endTime.is.null`)
+ .gt("startTime", previousStart.toString())
+ .or(`endTime.lte.${previousEnd.toString()},endTime.is.null`)
.order("startTime", { ascending: false })
.order("endTime", { ascending: false }),
]);
@@ -167,6 +167,32 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
previousPeriodData,
});
}
+ case "estimatesVsActuals": {
+ const jobs = await client
+ .from("job")
+ .select(
+ "id, jobId, customerId, estimatedTime, actualTime, completedDate"
+ )
+ .eq("companyId", companyId)
+ .gte("completedDate", start)
+ .lte("completedDate", end)
+ .not("completedDate", "is", null);
+
+ const jobOperations = await client
+ .from("jobOperation")
+ .select(
+ "id, jobId, operationId, estimatedTime, actualTime, completedDate"
+ )
+ .eq("companyId", companyId)
+ .gte("completedDate", start)
+ .lte("completedDate", end)
+ .not("completedDate", "is", null);
+
+ return json({
+ data: [],
+ previousPeriodData: [],
+ });
+ }
default:
throw new Error(`Invalid KPI key: ${key}`);
diff --git a/apps/erp/app/routes/x+/production+/_index.tsx b/apps/erp/app/routes/x+/production+/_index.tsx
index 5e4215722d..2307176860 100644
--- a/apps/erp/app/routes/x+/production+/_index.tsx
+++ b/apps/erp/app/routes/x+/production+/_index.tsx
@@ -32,7 +32,7 @@ import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useState } from "react";
import { CSVLink } from "react-csv";
import { LuChevronDown, LuEllipsisVertical, LuFile } from "react-icons/lu";
-import { Bar, BarChart, XAxis, YAxis } from "recharts";
+import { Bar, BarChart, LabelList, XAxis, YAxis } from "recharts";
import { KPIs } from "~/modules/production";
import { chartIntervals } from "~/modules/shared";
import type { loader as kpiLoader } from "~/routes/api+/production.kpi.$key";
@@ -270,6 +270,7 @@ export default function ProductionDashboard() {
layout="vertical"
margin={{
left: -20,
+ right: 30,
}}
>
<YAxis
@@ -303,7 +304,23 @@ export default function ProductionDashboard() {
/>
}
/>
- <Bar dataKey="value" fill="var(--color-actual)" radius={2} />
+ <Bar dataKey="value" fill="var(--color-actual)" radius={2}>
+ <LabelList
+ dataKey="value"
+ position="right"
+ formatter={(value: number) => {
+ const percentage =
+ totalTimeInInterval === 0
+ ? "0.00"
+ : ((value / totalTimeInInterval) * 100).toFixed(2);
+
+ return `${percentage}%`;
+ }}
+ offset={8}
+ className="fill-foreground"
+ fontSize={12}
+ />
+ </Bar>
</BarChart>
</ChartContainer>
</Loading>
diff --git a/packages/database/supabase/migrations/20250111180304_job-estimates-vs-actuals-kpi.sql b/packages/database/supabase/migrations/20250111180304_job-estimates-vs-actuals-kpi.sql
new file mode 100644
index 0000000000..af502230d1
--- /dev/null
+++ b/packages/database/supabase/migrations/20250111180304_job-estimates-vs-actuals-kpi.sql
@@ -0,0 +1,3 @@
+ALTER TABLE job
+ADD COLUMN "estimatedTime" NUMERIC,
+ADD COLUMN "actualTime" NUMERIC;