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 customer/supplier to sales/purchsaing dashboards, and completion time to production

Brad Barbinbc9ecd05443f
diff --git a/apps/erp/app/components/Table/components/TableHeader.tsx b/apps/erp/app/components/Table/components/TableHeader.tsx
index a33d422b9f..5062959cac 100644
--- a/apps/erp/app/components/Table/components/TableHeader.tsx
+++ b/apps/erp/app/components/Table/components/TableHeader.tsx
@@ -85,7 +85,7 @@ const TableHeader = <T extends object>({
className={cn(
compact
? "px-4 py-2 justify-between bg-card border-b w-full"
- : "px-4 md:px-0 py-6 md:py-8 justify-between bg-card w-full relative"
+ : "px-4 md:px-0 py-6 md:py-10 justify-between bg-card w-full relative"
)}
>
<HStack spacing={1}>
diff --git a/apps/erp/app/routes/api+/production.kpi.$key.ts b/apps/erp/app/routes/api+/production.kpi.$key.ts
index 051ab8eba4..c2a770d3c9 100644
--- a/apps/erp/app/routes/api+/production.kpi.$key.ts
+++ b/apps/erp/app/routes/api+/production.kpi.$key.ts
@@ -220,7 +220,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
{} as Record<string, typeof productionEvents.data>
);
- const data: { key: string; actual: number; estimate: number }[] = [];
+ const data: {
+ key: string;
+ actual: number;
+ estimate: number;
+ difference: number;
+ }[] = [];
// Calculate totals for each job
for (const job of jobs.data) {
@@ -247,15 +252,56 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
key: job.jobId,
actual: actualTime,
estimate: estimatedTime,
+ difference:
+ estimatedTime === 0
+ ? 0
+ : (actualTime - estimatedTime) / estimatedTime,
});
}
return json({
- data,
+ data: data.sort((a, b) => a.difference - b.difference),
previousPeriodData: [],
});
}
+ case "completionTime": {
+ const [jobs, previousJobs] = await Promise.all([
+ client
+ .from("job")
+ .select("id, jobId, secondsToComplete")
+ .eq("companyId", companyId)
+ .gte("completedDate", start)
+ .lte("completedDate", end)
+ .not("completedDate", "is", null)
+ .not("releasedDate", "is", null),
+ client
+ .from("job")
+ .select("id, jobId, secondsToComplete")
+ .eq("companyId", companyId)
+ .gte("completedDate", previousStart.toString())
+ .lte("completedDate", previousEnd.toString())
+ .not("completedDate", "is", null)
+ .not("releasedDate", "is", null),
+ ]);
+
+ const [data, previousPeriodData] = [
+ jobs.data ?? [],
+ previousJobs.data ?? [],
+ ].map((jobs) =>
+ jobs
+ .map((job) => ({
+ key: job.jobId,
+ value: (job.secondsToComplete ?? 0) * 1000,
+ }))
+ .sort((a, b) => b.value - a.value)
+ );
+
+ return json({
+ data,
+ previousPeriodData,
+ });
+ }
default:
throw new Error(`Invalid KPI key: ${key}`);
}
diff --git a/apps/erp/app/routes/api+/purchasing.kpi.$key.ts b/apps/erp/app/routes/api+/purchasing.kpi.$key.ts
index 5656a31bd3..0f7bcd64e4 100644
--- a/apps/erp/app/routes/api+/purchasing.kpi.$key.ts
+++ b/apps/erp/app/routes/api+/purchasing.kpi.$key.ts
@@ -1,5 +1,6 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { parseDateTime, toCalendarDateTime } from "@internationalized/date";
+import type { SupabaseClient } from "@supabase/supabase-js";
import { json, type LoaderFunctionArgs } from "@vercel/remix";
import { KPIs } from "~/modules/purchasing/purchasing.models";
import { months } from "~/modules/shared/shared.models";
@@ -14,6 +15,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const start = String(searchParams.get("start"));
const end = String(searchParams.get("end"));
+ const supplierId = searchParams.get("supplierId");
const startDate = toCalendarDateTime(parseDateTime(start));
const endDate = toCalendarDateTime(parseDateTime(end));
@@ -51,38 +53,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
case "purchaseOrderCount":
case "purchaseOrderAmount": {
const [orders, previousOrders] = await Promise.all([
- client
- .from("purchaseOrders")
- .select("orderTotal, orderDate", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", [
- "To Review",
- "To Receive",
- "To Invoice",
- "To Receive and Invoice",
- "Completed",
- ])
- .gt("orderDate", start)
- .lte("orderDate", end)
- .order("orderDate", { ascending: false }),
- client
- .from("purchaseOrders")
- .select("orderTotal, orderDate", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", [
- "To Review",
- "To Receive",
- "To Invoice",
- "To Receive and Invoice",
- "Completed",
- ])
- .gt("orderDate", previousStartDate.toString())
- .lte("orderDate", previousEndDate.toString())
- .order("orderDate", { ascending: false }),
+ getPurchaseOrdersQuery(client, {
+ companyId,
+ supplierId,
+ start,
+ end,
+ }),
+ getPurchaseOrdersQuery(client, {
+ companyId,
+ supplierId,
+ start: previousStartDate.toString(),
+ end: previousEndDate.toString(),
+ }),
]);
if (daysBetween < 60) {
@@ -151,40 +133,19 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
case "purchaseInvoiceCount":
case "purchaseInvoiceAmount": {
- const dateField = "dateIssued";
const [invoices, previousInvoices] = await Promise.all([
- client
- .from("purchaseInvoices")
- .select("orderTotal, dateIssued", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", [
- "Pending",
- "Partially Paid",
- "Paid",
- "Submitted",
- "Overdue",
- ])
- .gt(dateField, start)
- .lte(dateField, end)
- .order(dateField, { ascending: false }),
- client
- .from("purchaseInvoices")
- .select("orderTotal, dateIssued", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", [
- "Pending",
- "Partially Paid",
- "Paid",
- "Submitted",
- "Overdue",
- ])
- .gt(dateField, previousStartDate.toString())
- .lte(dateField, previousEndDate.toString())
- .order(dateField, { ascending: false }),
+ getPurchaseInvoicesQuery(client, {
+ companyId,
+ supplierId,
+ start,
+ end,
+ }),
+ getPurchaseInvoicesQuery(client, {
+ companyId,
+ supplierId,
+ start: previousStartDate.toString(),
+ end: previousEndDate.toString(),
+ }),
]);
if (daysBetween < 60) {
@@ -192,12 +153,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
groupDataByDay(invoices.data ?? [], {
start,
end,
- groupBy: dateField,
+ groupBy: "dateIssued",
}),
groupDataByDay(previousInvoices.data ?? [], {
start: previousStartDate.toString(),
end: previousEndDate.toString(),
- groupBy: dateField,
+ groupBy: "dateIssued",
}),
];
@@ -222,12 +183,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
groupDataByMonth(invoices.data ?? [], {
start,
end,
- groupBy: dateField,
+ groupBy: "dateIssued",
}),
groupDataByMonth(previousInvoices.data ?? [], {
start: previousStartDate.toString(),
end: previousEndDate.toString(),
- groupBy: dateField,
+ groupBy: "dateIssued",
}),
];
@@ -253,24 +214,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
case "supplierQuoteCount": {
const [quotes, previousQuotes] = await Promise.all([
- client
- .from("supplierQuote")
- .select("createdAt", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .gt("createdAt", start)
- .lte("createdAt", end)
- .order("createdAt", { ascending: false }),
- client
- .from("supplierQuote")
- .select("createdAt", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .gt("createdAt", previousStartDate.toString())
- .lte("createdAt", previousEndDate.toString())
- .order("createdAt", { ascending: false }),
+ getSupplierQuotesQuery(client, {
+ companyId,
+ supplierId,
+ start,
+ end,
+ }),
+ getSupplierQuotesQuery(client, {
+ companyId,
+ supplierId,
+ start: previousStartDate.toString(),
+ end: previousEndDate.toString(),
+ }),
]);
if (daysBetween < 60) {
@@ -355,3 +310,107 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
throw new Error(`Invalid KPI key: ${key}`);
}
}
+
+async function getPurchaseOrdersQuery(
+ client: SupabaseClient,
+ {
+ companyId,
+ supplierId,
+ start,
+ end,
+ }: {
+ companyId: string;
+ supplierId: string | null;
+ start: string;
+ end: string;
+ }
+) {
+ let query = client
+ .from("purchaseOrders")
+ .select("orderTotal, orderDate", {
+ count: "exact",
+ })
+ .eq("companyId", companyId)
+ .in("status", [
+ "To Review",
+ "To Receive",
+ "To Invoice",
+ "To Receive and Invoice",
+ "Completed",
+ ])
+ .gt("orderDate", start)
+ .lte("orderDate", end);
+
+ if (supplierId) {
+ query = query.eq("supplierId", supplierId);
+ }
+
+ query = query.order("orderDate", { ascending: false });
+
+ return query;
+}
+
+async function getPurchaseInvoicesQuery(
+ client: SupabaseClient,
+ {
+ companyId,
+ supplierId,
+ start,
+ end,
+ }: {
+ companyId: string;
+ supplierId: string | null;
+ start: string;
+ end: string;
+ }
+) {
+ let query = client
+ .from("purchaseInvoices")
+ .select("orderTotal, dateIssued", {
+ count: "exact",
+ })
+ .eq("companyId", companyId)
+ .in("status", ["Pending", "Partially Paid", "Paid", "Submitted", "Overdue"])
+ .gt("dateIssued", start)
+ .lte("dateIssued", end);
+
+ if (supplierId) {
+ query = query.eq("supplierId", supplierId);
+ }
+
+ query = query.order("dateIssued", { ascending: false });
+
+ return query;
+}
+
+async function getSupplierQuotesQuery(
+ client: SupabaseClient,
+ {
+ companyId,
+ supplierId,
+ start,
+ end,
+ }: {
+ companyId: string;
+ supplierId: string | null;
+ start: string;
+ end: string;
+ }
+) {
+ let query = client
+ .from("supplierQuote")
+ .select("createdAt", {
+ count: "exact",
+ })
+ .eq("companyId", companyId)
+ .gt("createdAt", start)
+ .lte("createdAt", end);
+
+ if (supplierId) {
+ query = query.eq("supplierId", supplierId);
+ }
+
+ query = query.order("createdAt", { ascending: false });
+
+ return query;
+}
diff --git a/apps/erp/app/routes/api+/sales.kpi.$key.ts b/apps/erp/app/routes/api+/sales.kpi.$key.ts
index 6f5ca62142..65ad1cde8d 100644
--- a/apps/erp/app/routes/api+/sales.kpi.$key.ts
+++ b/apps/erp/app/routes/api+/sales.kpi.$key.ts
@@ -1,5 +1,6 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { parseDateTime, toCalendarDateTime } from "@internationalized/date";
+import type { SupabaseClient } from "@supabase/supabase-js";
import { json, type LoaderFunctionArgs } from "@vercel/remix";
import { KPIs } from "~/modules/sales/sales.models";
import { months } from "~/modules/shared/shared.models";
@@ -14,6 +15,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const start = String(searchParams.get("start"));
const end = String(searchParams.get("end"));
+ const customerId = searchParams.get("customerId");
const startDate = toCalendarDateTime(parseDateTime(start));
const endDate = toCalendarDateTime(parseDateTime(end));
@@ -51,38 +53,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
case "salesOrderRevenue":
case "salesOrderCount": {
const [salesOrders, previousSalesOrders] = await Promise.all([
- client
- .from("salesOrders")
- .select("orderTotal, orderDate", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", [
- "In Progress",
- "Needs Approval",
- "Confirmed",
- "Completed",
- "Invoiced",
- ])
- .gt("orderDate", start)
- .lte("orderDate", end)
- .order("orderDate", { ascending: false }),
- client
- .from("salesOrders")
- .select("orderTotal, orderDate", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", [
- "In Progress",
- "Needs Approval",
- "Confirmed",
- "Completed",
- "Invoiced",
- ])
- .gt("orderDate", previousStartDate.toString())
- .lte("orderDate", previousEndDate.toString())
- .order("orderDate", { ascending: false }),
+ getSalesOrdersQuery(client, {
+ companyId,
+ customerId,
+ start,
+ end,
+ }),
+ getSalesOrdersQuery(client, {
+ companyId,
+ customerId,
+ start: previousStartDate.toString(),
+ end: previousEndDate.toString(),
+ }),
]);
if (daysBetween < 60) {
@@ -157,26 +139,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
case "quoteCount": {
const [quotes, previousQuotes] = await Promise.all([
- client
- .from("quote")
- .select("createdAt", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", ["Sent", "Ordered", "Partial", "Lost", "Expired"])
- .gt("createdAt", start)
- .lte("createdAt", end)
- .order("createdAt", { ascending: false }),
- client
- .from("quote")
- .select("createdAt", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", ["Sent", "Ordered", "Partial", "Lost", "Expired"])
- .gt("createdAt", previousStartDate.toString())
- .lte("createdAt", previousEndDate.toString())
- .order("createdAt", { ascending: false }),
+ getQuotesQuery(client, {
+ companyId,
+ customerId,
+ start,
+ end,
+ }),
+ getQuotesQuery(client, {
+ companyId,
+ customerId,
+ start: previousStartDate.toString(),
+ end: previousEndDate.toString(),
+ }),
]);
if (daysBetween < 60) {
@@ -259,26 +233,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
case "rfqCount": {
const [rfqs, previousRfqs] = await Promise.all([
- client
- .from("salesRfq")
- .select("createdAt", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", ["Ready for Quote", "Quoted", "Closed"])
- .gt("createdAt", start)
- .lte("createdAt", end)
- .order("createdAt", { ascending: false }),
- client
- .from("salesRfq")
- .select("createdAt", {
- count: "exact",
- })
- .eq("companyId", companyId)
- .in("status", ["Ready for Quote", "Quoted", "Closed"])
- .gt("createdAt", previousStartDate.toString())
- .lte("createdAt", previousEndDate.toString())
- .order("createdAt", { ascending: false }),
+ getRfqQuery(client, {
+ companyId,
+ customerId,
+ start,
+ end,
+ }),
+ getRfqQuery(client, {
+ companyId,
+ customerId,
+ start: previousStartDate.toString(),
+ end: previousEndDate.toString(),
+ }),
]);
if (daysBetween < 60) {
@@ -363,3 +329,108 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
throw new Error(`Invalid KPI key: ${key}`);
}
}
+
+async function getSalesOrdersQuery(
+ client: SupabaseClient,
+ {
+ companyId,
+ customerId,
+ start,
+ end,
+ }: {
+ companyId: string;
+ customerId: string | null;
+ start: string;
+ end: string;
+ }
+) {
+ let query = client
+ .from("salesOrders")
+ .select("orderTotal, orderDate", {
+ count: "exact",
+ })
+ .eq("companyId", companyId)
+ .in("status", [
+ "In Progress",
+ "Needs Approval",
+ "Confirmed",
+ "Completed",
+ "Invoiced",
+ ])
+ .gt("orderDate", start)
+ .lte("orderDate", end);
+
+ if (customerId) {
+ query = query.eq("customerId", customerId);
+ }
+
+ query = query.order("orderDate", { ascending: false });
+
+ return query;
+}
+
+async function getQuotesQuery(
+ client: SupabaseClient,
+ {
+ companyId,
+ customerId,
+ start,
+ end,
+ }: {
+ companyId: string;
+ customerId: string | null;
+ start: string;
+ end: string;
+ }
+) {
+ let query = client
+ .from("quote")
+ .select("createdAt", {
+ count: "exact",
+ })
+ .eq("companyId", companyId)
+ .in("status", ["Sent", "Ordered", "Partial", "Lost", "Expired"])
+ .gt("createdAt", start)
+ .lte("createdAt", end);
+
+ if (customerId) {
+ query = query.eq("customerId", customerId);
+ }
+
+ query = query.order("createdAt", { ascending: false });
+
+ return query;
+}
+
+async function getRfqQuery(
+ client: SupabaseClient,
+ {
+ companyId,
+ customerId,
+ start,
+ end,
+ }: {
+ companyId: string;
+ customerId: string | null;
+ start: string;
+ end: string;
+ }
+) {
+ let query = client
+ .from("salesRfq")
+ .select("createdAt", {
+ count: "exact",
+ })
+ .eq("companyId", companyId)
+ .in("status", ["Ready for Quote", "Quoted", "Closed"])
+ .gt("createdAt", start)
+ .lte("createdAt", end);
+
+ if (customerId) {
+ query = query.eq("customerId", customerId);
+ }
+
+ query = query.order("createdAt", { ascending: false });
+
+ return query;
+}
diff --git a/apps/erp/app/routes/x+/production+/_index.tsx b/apps/erp/app/routes/x+/production+/_index.tsx
index 4a6419e470..d805b57e75 100644
--- a/apps/erp/app/routes/x+/production+/_index.tsx
+++ b/apps/erp/app/routes/x+/production+/_index.tsx
@@ -27,7 +27,6 @@ import {
} from "@carbon/react/Chart";
import { formatDurationMilliseconds } from "@carbon/utils";
import { now, toCalendarDateTime } from "@internationalized/date";
-import { useNumberFormatter } from "@react-aria/i18n";
import type { DateRange } from "@react-types/datepicker";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useState } from "react";
@@ -56,12 +55,6 @@ export default function ProductionDashboard() {
const kpiFetcher = useFetcher<typeof kpiLoader>();
const isFetching = kpiFetcher.state !== "idle" || !kpiFetcher.data;
- const numberFormatter = useNumberFormatter({
- maximumFractionDigits: 0,
- notation: "compact",
- compactDisplay: "short",
- });
-
const [interval, setInterval] = useState("month");
const [selectedKpi, setSelectedKpi] = useState<
"utilization" | "completionTime" | "estimatesVsActuals"
@@ -120,6 +113,13 @@ export default function ProductionDashboard() {
// @ts-expect-error
return acc + item.value;
}, 0);
+ case "completionTime":
+ return data.length === 0
+ ? 0
+ : data.reduce((acc, item) => {
+ // @ts-expect-error
+ return acc + item.value;
+ }, 0) / data.length;
case "estimate":
return data.reduce((acc, item) => {
// @ts-expect-error
@@ -327,7 +327,7 @@ export default function ProductionDashboard() {
style={{
height: `${
(kpiFetcher.data?.data?.length ?? 5) *
- (selectedKpi === "utilization" ? 40 : 80)
+ (selectedKpi === "estimatesVsActuals" ? 80 : 40)
}px`,
}}
>
@@ -441,6 +441,25 @@ export default function ProductionDashboard() {
/>
</>
)}
+ {selectedKpi === "completionTime" && (
+ <>
+ <ChartTooltip
+ content={
+ <ChartTooltipContent
+ labelFormatter={(value) => value}
+ formatter={(value) =>
+ formatDurationMilliseconds(value as number)
+ }
+ />
+ }
+ />
+ <Bar
+ dataKey="value"
+ fill="var(--color-actual)"
+ radius={2}
+ />
+ </>
+ )}
</BarChart>
</ChartContainer>
</Loading>
diff --git a/apps/erp/app/routes/x+/purchasing+/_index.tsx b/apps/erp/app/routes/x+/purchasing+/_index.tsx
index 686b530f86..95613694ee 100644
--- a/apps/erp/app/routes/x+/purchasing+/_index.tsx
+++ b/apps/erp/app/routes/x+/purchasing+/_index.tsx
@@ -7,6 +7,7 @@ import {
CardDescription,
CardHeader,
CardTitle,
+ Combobox,
DateRangePicker,
DropdownMenu,
DropdownMenuContent,
@@ -66,17 +67,23 @@ import { PurchasingStatus } from "~/modules/purchasing/ui/PurchaseOrder";
import { SupplierQuoteStatus } from "~/modules/purchasing/ui/SupplierQuote";
import { chartIntervals } from "~/modules/shared/shared.models";
import type { loader as kpiLoader } from "~/routes/api+/purchasing.kpi.$key";
+import { useSuppliers } from "~/stores/suppliers";
import { path } from "~/utils/path";
-const OPEN_SUPPLIER_QUOTE_STATUSES = ["Active"];
-const OPEN_INVOICE_STATUSES = ["Draft", "Return", "Pending", "Partially Paid"];
+const OPEN_SUPPLIER_QUOTE_STATUSES = ["Active"] as const;
+const OPEN_INVOICE_STATUSES = [
+ "Draft",
+ "Return",
+ "Pending",
+ "Partially Paid",
+] as const;
const OPEN_PURCHASE_ORDER_STATUSES = [
"Draft",
"To Review",
"To Receive",
"To Receive and Invoice",
"To Invoice",
-];
+] as const;
const chartConfig = {
now: {
@@ -172,6 +179,18 @@ export default function PurchaseDashboard() {
compactDisplay: "short",
});
+ const [supplierId, setSupplierId] = useState<string>("all");
+ const [suppliers] = useSuppliers();
+ const supplierOptions = useMemo(() => {
+ return [
+ { label: "All Suppliers", value: "all" },
+ ...suppliers.map((supplier) => ({
+ label: supplier.name,
+ value: supplier.id,
+ })),
+ ];
+ }, [suppliers]);
+
const [interval, setInterval] = useState("month");
const [selectedKpi, setSelectedKpi] = useState("purchaseOrderAmount");
const [dateRange, setDateRange] = useState<DateRange | null>(() => {
@@ -188,10 +207,12 @@ export default function PurchaseDashboard() {
kpiFetcher.load(
`${path.to.api.purchasingKpi(
selectedKpiData.key
- )}?start=${dateRange?.start.toString()}&end=${dateRange?.end.toString()}&interval=${interval}`
+ )}?start=${dateRange?.start.toString()}&end=${dateRange?.end.toString()}&interval=${interval}${
+ supplierId === "all" ? "" : `&supplierId=${supplierId}`
+ }`
);
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selectedKpi, dateRange, interval, selectedKpiData.key]);
+ }, [selectedKpi, dateRange, interval, selectedKpiData.key, supplierId]);
const onIntervalChange = (value: string) => {
const end = toCalendarDateTime(now("UTC"));
@@ -398,6 +419,13 @@ export default function PurchaseDashboard() {
onChange={setDateRange}
/>
)}
+ <Combobox
+ value={supplierId}
+ onChange={setSupplierId}
+ options={supplierOptions}
+ size="sm"
+ className="font-medium text-sm min-w-[160px] gap-4"
+ />
</div>
<HStack className="text-sm text-muted-foreground pl-[3px] pt-1">
{isFetching ? (
diff --git a/apps/erp/app/routes/x+/sales+/_index.tsx b/apps/erp/app/routes/x+/sales+/_index.tsx
index b8c35f835c..245e74f6f8 100644
--- a/apps/erp/app/routes/x+/sales+/_index.tsx
+++ b/apps/erp/app/routes/x+/sales+/_index.tsx
@@ -180,10 +180,12 @@ export default function SalesDashboard() {
kpiFetcher.load(
`${path.to.api.salesKpi(
selectedKpiData.key
- )}?start=${dateRange?.start.toString()}&end=${dateRange?.end.toString()}&interval=${interval}`
+ )}?start=${dateRange?.start.toString()}&end=${dateRange?.end.toString()}&interval=${interval}${
+ customerId === "all" ? "" : `&customerId=${customerId}`
+ }`
);
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selectedKpi, dateRange, interval, selectedKpiData.key]);
+ }, [selectedKpi, dateRange, interval, selectedKpiData.key, customerId]);
const onIntervalChange = (value: string) => {
const end = today("UTC");
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 3dd30fd5e0..84ee859da4 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -7630,6 +7630,7 @@ export type Database = {
salesOrderId: string | null
salesOrderLineId: string | null
scrapQuantity: number
+ secondsToComplete: number | null
status: Database["public"]["Enums"]["jobStatus"]
tags: string[] | null
unitOfMeasureCode: string
@@ -7666,6 +7667,7 @@ export type Database = {
salesOrderId?: string | null
salesOrderLineId?: string | null
scrapQuantity?: number
+ secondsToComplete?: number | null
status?: Database["public"]["Enums"]["jobStatus"]
tags?: string[] | null
unitOfMeasureCode: string
@@ -7702,6 +7704,7 @@ export type Database = {
salesOrderId?: string | null
salesOrderLineId?: string | null
scrapQuantity?: number
+ secondsToComplete?: number | null
status?: Database["public"]["Enums"]["jobStatus"]
tags?: string[] | null
unitOfMeasureCode?: string
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 3dd30fd5e0..84ee859da4 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -7630,6 +7630,7 @@ export type Database = {
salesOrderId: string | null
salesOrderLineId: string | null
scrapQuantity: number
+ secondsToComplete: number | null
status: Database["public"]["Enums"]["jobStatus"]
tags: string[] | null
unitOfMeasureCode: string
@@ -7666,6 +7667,7 @@ export type Database = {
salesOrderId?: string | null
salesOrderLineId?: string | null
scrapQuantity?: number
+ secondsToComplete?: number | null
status?: Database["public"]["Enums"]["jobStatus"]
tags?: string[] | null
unitOfMeasureCode: string
@@ -7702,6 +7704,7 @@ export type Database = {
salesOrderId?: string | null
salesOrderLineId?: string | null
scrapQuantity?: number
+ secondsToComplete?: number | null
status?: Database["public"]["Enums"]["jobStatus"]
tags?: string[] | null
unitOfMeasureCode?: string