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.

fix: add count to planning tables

Brad Barbine955be85bce7
diff --git a/apps/erp/app/modules/production/ui/Planning/ProductionPlanningTable.tsx b/apps/erp/app/modules/production/ui/Planning/ProductionPlanningTable.tsx
index ba0ac22cb7..e1ce8bc741 100644
--- a/apps/erp/app/modules/production/ui/Planning/ProductionPlanningTable.tsx
+++ b/apps/erp/app/modules/production/ui/Planning/ProductionPlanningTable.tsx
@@ -18,7 +18,7 @@ import { getLocalTimeZone, parseDate } from "@internationalized/date";
import { useDateFormatter, useNumberFormatter } from "@react-aria/i18n";
import { useFetcher } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
-import { memo, useCallback, useEffect, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import {
LuBookMarked,
LuBox,
@@ -54,439 +54,434 @@ type ProductionPlanningTableProps = {
periods: { id: string; startDate: string; endDate: string }[];
};
-const ProductionPlanningTable = memo(
- ({ data, count, locationId, periods }: ProductionPlanningTableProps) => {
- const permissions = usePermissions();
+const ProductionPlanningTable = ({
+ data,
+ count,
+ locationId,
+ periods,
+}: ProductionPlanningTableProps) => {
+ const permissions = usePermissions();
- const dateFormatter = useDateFormatter({
- month: "short",
- day: "numeric",
- });
+ const dateFormatter = useDateFormatter({
+ month: "short",
+ day: "numeric",
+ });
- const numberFormatter = useNumberFormatter();
- const locations = useLocations();
- const unitOfMeasures = useUnitOfMeasure();
+ const numberFormatter = useNumberFormatter();
+ const locations = useLocations();
+ const unitOfMeasures = useUnitOfMeasure();
- const mrpFetcher = useFetcher<typeof mrpAction>();
- const bulkUpdateFetcher = useFetcher<typeof bulkUpdateAction>();
+ const mrpFetcher = useFetcher<typeof mrpAction>();
+ const bulkUpdateFetcher = useFetcher<typeof bulkUpdateAction>();
- // Clear cache when MRP completes
- useEffect(() => {
- if (mrpFetcher.state === "idle" && mrpFetcher.data) {
- clearOrdersCache();
- setOrdersMap({}); // Reset local state to force recalculation
- }
- }, [mrpFetcher.state, mrpFetcher.data]);
-
- // Clear local state when data changes (e.g., filters, search)
- useEffect(() => {
- setOrdersMap({});
- }, [data]);
-
- useEffect(() => {
- if (
- bulkUpdateFetcher.data?.success === false &&
- bulkUpdateFetcher?.data?.message
- ) {
- toast.error(bulkUpdateFetcher.data.message);
- }
+ // Clear cache when MRP completes
+ useEffect(() => {
+ if (mrpFetcher.state === "idle" && mrpFetcher.data) {
+ clearOrdersCache();
+ setOrdersMap({}); // Reset local state to force recalculation
+ }
+ }, [mrpFetcher.state, mrpFetcher.data]);
- if (bulkUpdateFetcher.data?.success === true) {
- toast.success("Orders submitted");
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [bulkUpdateFetcher.data?.success]);
+ // Clear local state when data changes (e.g., filters, search)
+ useEffect(() => {
+ setOrdersMap({});
+ }, [data]);
- const isDisabled =
- !permissions.can("create", "production") ||
- bulkUpdateFetcher.state !== "idle" ||
- mrpFetcher.state !== "idle";
+ useEffect(() => {
+ if (
+ bulkUpdateFetcher.data?.success === false &&
+ bulkUpdateFetcher?.data?.message
+ ) {
+ toast.error(bulkUpdateFetcher.data.message);
+ }
- // Store orders in a map keyed by item id - calculate on-demand instead of eagerly
- const [ordersMap, setOrdersMap] = useState<
- Record<string, ProductionOrder[]>
- >({});
+ if (bulkUpdateFetcher.data?.success === true) {
+ toast.success("Orders submitted");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [bulkUpdateFetcher.data?.success]);
- const onBulkUpdate = useCallback(
- (selectedRows: typeof data, action: "order") => {
- const payload = {
- locationId,
- items: selectedRows
- .filter((row) => row.id)
- .map((row) => {
- const ordersWithPeriods = (ordersMap[row.id!] || []).map(
- (order) => {
- // If no due date or due date is before first period, use first period
- if (
- !order.dueDate ||
- parseDate(order.dueDate) < parseDate(periods[0].startDate)
- ) {
- return {
- ...order,
- periodId: periods[0].id,
- };
- }
+ const isDisabled =
+ !permissions.can("create", "production") ||
+ bulkUpdateFetcher.state !== "idle" ||
+ mrpFetcher.state !== "idle";
- // Find matching period based on due date
- const period = periods.find((p) => {
- const dueDate = parseDate(order.dueDate!);
- const startDate = parseDate(p.startDate);
- const endDate = parseDate(p.endDate);
- return dueDate >= startDate && dueDate <= endDate;
- });
+ // Store orders in a map keyed by item id - calculate on-demand instead of eagerly
+ const [ordersMap, setOrdersMap] = useState<Record<string, ProductionOrder[]>>(
+ {}
+ );
- // If no matching period found (date is after last period), use last period
+ const onBulkUpdate = useCallback(
+ (selectedRows: typeof data, action: "order") => {
+ const payload = {
+ locationId,
+ items: selectedRows
+ .filter((row) => row.id)
+ .map((row) => {
+ const ordersWithPeriods = (ordersMap[row.id!] || []).map(
+ (order) => {
+ // If no due date or due date is before first period, use first period
+ if (
+ !order.dueDate ||
+ parseDate(order.dueDate) < parseDate(periods[0].startDate)
+ ) {
return {
...order,
- periodId: period?.id ?? periods[periods.length - 1].id,
+ periodId: periods[0].id,
};
}
- );
- return {
- id: row.id,
- orders: ordersWithPeriods,
- };
- }),
- action: action,
- };
- bulkUpdateFetcher.submit(payload, {
- method: "post",
- action: path.to.bulkUpdateProductionPlanning,
- encType: "application/json",
- });
- },
- [bulkUpdateFetcher, locationId, ordersMap, periods]
- );
-
- const [selectedItem, setSelectedItem] =
- useState<ProductionPlanningItem | null>(null);
+ // Find matching period based on due date
+ const period = periods.find((p) => {
+ const dueDate = parseDate(order.dueDate!);
+ const startDate = parseDate(p.startDate);
+ const endDate = parseDate(p.endDate);
+ return dueDate >= startDate && dueDate <= endDate;
+ });
- const setOrders = useCallback(
- (item: ProductionPlanningItem, orders: ProductionOrder[]) => {
- if (item.id) {
- setOrdersMap((prev) => ({
- ...prev,
- [item.id!]: orders,
- }));
- }
- },
- []
- );
+ // If no matching period found (date is after last period), use last period
+ return {
+ ...order,
+ periodId: period?.id ?? periods[periods.length - 1].id,
+ };
+ }
+ );
- const columns = useMemo<ColumnDef<ProductionPlanningItem>[]>(() => {
- // Helper to get orders with on-demand calculation
- const getOrdersForItem = (itemId: string): ProductionOrder[] => {
- if (ordersMap[itemId]) {
- return ordersMap[itemId];
- }
- const item = data.find((i) => i.id === itemId);
- if (!item) return [];
- return getProductionOrdersFromPlanning(item, periods);
+ return {
+ id: row.id,
+ orders: ordersWithPeriods,
+ };
+ }),
+ action: action,
};
- const periodColumns: ColumnDef<ProductionPlanningItem>[] = periods.map(
- (period, index) => {
- const isCurrentWeek = index === 0;
- const weekNumber = index + 1;
- const weekKey = `week${weekNumber}` as keyof ProductionPlanningItem;
- const startDate = parseDate(period.startDate).toDate(
- getLocalTimeZone()
- );
- const endDate = parseDate(period.endDate).toDate(getLocalTimeZone());
+ bulkUpdateFetcher.submit(payload, {
+ method: "post",
+ action: path.to.bulkUpdateProductionPlanning,
+ encType: "application/json",
+ });
+ },
+ [bulkUpdateFetcher, locationId, ordersMap, periods]
+ );
- return {
- accessorKey: weekKey,
- header: () => (
- <VStack spacing={0}>
- <div>
- {isCurrentWeek ? "Present Week" : `Week ${weekNumber}`}
- </div>
- <div className="text-xs text-muted-foreground">
- {dateFormatter.format(startDate)} -{" "}
- {dateFormatter.format(endDate)}
- </div>
- </VStack>
- ),
- cell: ({ row }) => {
- const value = row.getValue<number>(weekKey);
- if (value === undefined) return "-";
- return (
- <span
- className={value < 0 ? "text-red-500 font-bold" : undefined}
- >
- {numberFormatter.format(value)}
- </span>
- );
- },
- };
- }
- );
+ const [selectedItem, setSelectedItem] =
+ useState<ProductionPlanningItem | null>(null);
- return [
- {
- accessorKey: "readableIdWithRevision",
- header: "Part ID",
- cell: ({ row }) => (
- <HStack
- className="py-1 cursor-pointer"
- onClick={() => {
- setSelectedItem(row.original);
- }}
- >
- <ItemThumbnail
- size="sm"
- thumbnailPath={row.original.thumbnailPath}
- // @ts-ignore
- type={row.original.type}
- />
+ const setOrders = useCallback(
+ (item: ProductionPlanningItem, orders: ProductionOrder[]) => {
+ if (item.id) {
+ setOrdersMap((prev) => ({
+ ...prev,
+ [item.id!]: orders,
+ }));
+ }
+ },
+ []
+ );
- <VStack spacing={0} className="font-medium">
- {row.original.readableIdWithRevision}
- <div className="w-full truncate text-muted-foreground text-xs">
- {row.original.name}
- </div>
- </VStack>
- </HStack>
- ),
- meta: {
- icon: <LuBookMarked />,
- },
- },
- {
- accessorKey: "unitOfMeasureCode",
- header: "",
- cell: ({ row }) => (
- <Enumerable
- value={
- unitOfMeasures.find(
- (uom) => uom.value === row.original.unitOfMeasureCode
- )?.label ?? null
- }
- />
+ const columns = useMemo<ColumnDef<ProductionPlanningItem>[]>(() => {
+ // Helper to get orders with on-demand calculation
+ const getOrdersForItem = (itemId: string): ProductionOrder[] => {
+ if (ordersMap[itemId]) {
+ return ordersMap[itemId];
+ }
+ const item = data.find((i) => i.id === itemId);
+ if (!item) return [];
+ return getProductionOrdersFromPlanning(item, periods);
+ };
+ const periodColumns: ColumnDef<ProductionPlanningItem>[] = periods.map(
+ (period, index) => {
+ const isCurrentWeek = index === 0;
+ const weekNumber = index + 1;
+ const weekKey = `week${weekNumber}` as keyof ProductionPlanningItem;
+ const startDate = parseDate(period.startDate).toDate(
+ getLocalTimeZone()
+ );
+ const endDate = parseDate(period.endDate).toDate(getLocalTimeZone());
+
+ return {
+ accessorKey: weekKey,
+ header: () => (
+ <VStack spacing={0}>
+ <div>{isCurrentWeek ? "Present Week" : `Week ${weekNumber}`}</div>
+ <div className="text-xs text-muted-foreground">
+ {dateFormatter.format(startDate)} -{" "}
+ {dateFormatter.format(endDate)}
+ </div>
+ </VStack>
),
- },
- {
- accessorKey: "reorderingPolicy",
- header: "Reorder Policy",
cell: ({ row }) => {
+ const value = row.getValue<number>(weekKey);
+ if (value === undefined) return "-";
return (
- <HStack>
- <Tooltip>
- <TooltipTrigger>
- <ItemReorderPolicy
- reorderingPolicy={row.original.reorderingPolicy}
- />
- </TooltipTrigger>
- <TooltipContent>
- {getReorderPolicyDescription(row.original)}
- </TooltipContent>
- </Tooltip>
- </HStack>
+ <span
+ className={value < 0 ? "text-red-500 font-bold" : undefined}
+ >
+ {numberFormatter.format(value)}
+ </span>
);
},
- meta: {
- filter: {
- type: "static",
- options: itemReorderingPolicies.map((policy) => ({
- label: <ItemReorderPolicy reorderingPolicy={policy} />,
- value: policy,
- })),
- },
- icon: <LuCircleCheck />,
- },
+ };
+ }
+ );
+
+ return [
+ {
+ accessorKey: "readableIdWithRevision",
+ header: "Part ID",
+ cell: ({ row }) => (
+ <HStack
+ className="py-1 cursor-pointer"
+ onClick={() => {
+ setSelectedItem(row.original);
+ }}
+ >
+ <ItemThumbnail
+ size="sm"
+ thumbnailPath={row.original.thumbnailPath}
+ // @ts-ignore
+ type={row.original.type}
+ />
+
+ <VStack spacing={0} className="font-medium">
+ {row.original.readableIdWithRevision}
+ <div className="w-full truncate text-muted-foreground text-xs">
+ {row.original.name}
+ </div>
+ </VStack>
+ </HStack>
+ ),
+ meta: {
+ icon: <LuBookMarked />,
},
- {
- accessorKey: "quantityOnHand",
- header: "On Hand",
- cell: ({ row }) =>
- numberFormatter.format(row.original.quantityOnHand),
- meta: {
- icon: <LuPackage />,
- },
+ },
+ {
+ accessorKey: "unitOfMeasureCode",
+ header: "",
+ cell: ({ row }) => (
+ <Enumerable
+ value={
+ unitOfMeasures.find(
+ (uom) => uom.value === row.original.unitOfMeasureCode
+ )?.label ?? null
+ }
+ />
+ ),
+ },
+ {
+ accessorKey: "reorderingPolicy",
+ header: "Reorder Policy",
+ cell: ({ row }) => {
+ return (
+ <HStack>
+ <Tooltip>
+ <TooltipTrigger>
+ <ItemReorderPolicy
+ reorderingPolicy={row.original.reorderingPolicy}
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ {getReorderPolicyDescription(row.original)}
+ </TooltipContent>
+ </Tooltip>
+ </HStack>
+ );
},
- ...periodColumns,
- {
- accessorKey: "type",
- header: "Type",
- cell: ({ row }) =>
- row.original.type && (
- <HStack>
- <MethodItemTypeIcon type={row.original.type} />
- <span>{row.original.type}</span>
- </HStack>
- ),
- meta: {
- filter: {
- type: "static",
- options: itemTypes
- .filter((t) => ["Part", "Tool"].includes(t))
- .map((type) => ({
- label: (
- <HStack spacing={2}>
- <MethodItemTypeIcon type={type} />
- <span>{type}</span>
- </HStack>
- ),
- value: type,
- })),
- },
- icon: <LuBox />,
+ meta: {
+ filter: {
+ type: "static",
+ options: itemReorderingPolicies.map((policy) => ({
+ label: <ItemReorderPolicy reorderingPolicy={policy} />,
+ value: policy,
+ })),
},
+ icon: <LuCircleCheck />,
},
- {
- id: "Order",
- header: "",
- cell: ({ row }) => {
- const orders = row.original.id
- ? getOrdersForItem(row.original.id)
- : [];
- const orderQuantity = orders.reduce(
- (acc, order) =>
- acc + (order.quantity - (order.existingQuantity ?? 0)),
- 0
- );
- const isBlocked = row.original.manufacturingBlocked;
- const hasOrders = orders.length > 0 && orderQuantity > 0;
- return (
- <div className="flex justify-end">
- <Button
- variant="secondary"
- leftIcon={hasOrders ? undefined : <LuCircleCheck />}
- isDisabled={isDisabled || isBlocked}
- onClick={() => {
- setSelectedItem(row.original);
- }}
- >
- {isBlocked ? (
- "Blocked"
- ) : hasOrders ? (
- <HStack>
- <PulsingDot />
- <span>Order {orderQuantity}</span>
- </HStack>
- ) : (
- "Order"
- )}
- </Button>
- </div>
- );
+ },
+ {
+ accessorKey: "quantityOnHand",
+ header: "On Hand",
+ cell: ({ row }) => numberFormatter.format(row.original.quantityOnHand),
+ meta: {
+ icon: <LuPackage />,
+ },
+ },
+ ...periodColumns,
+ {
+ accessorKey: "type",
+ header: "Type",
+ cell: ({ row }) =>
+ row.original.type && (
+ <HStack>
+ <MethodItemTypeIcon type={row.original.type} />
+ <span>{row.original.type}</span>
+ </HStack>
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: itemTypes
+ .filter((t) => ["Part", "Tool"].includes(t))
+ .map((type) => ({
+ label: (
+ <HStack spacing={2}>
+ <MethodItemTypeIcon type={type} />
+ <span>{type}</span>
+ </HStack>
+ ),
+ value: type,
+ })),
},
+ icon: <LuBox />,
},
- ];
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [
- periods,
- dateFormatter,
- numberFormatter,
- unitOfMeasures,
- isDisabled,
- // Note: ordersMap is intentionally not in deps to avoid column regeneration
- // getOrdersForItem inside the cell will access the latest ordersMap via closure
- ]);
+ },
+ {
+ id: "Order",
+ header: "",
+ cell: ({ row }) => {
+ const orders = row.original.id
+ ? getOrdersForItem(row.original.id)
+ : [];
+ const orderQuantity = orders.reduce(
+ (acc, order) =>
+ acc + (order.quantity - (order.existingQuantity ?? 0)),
+ 0
+ );
+ const isBlocked = row.original.manufacturingBlocked;
+ const hasOrders = orders.length > 0 && orderQuantity > 0;
+ return (
+ <div className="flex justify-end">
+ <Button
+ variant="secondary"
+ leftIcon={hasOrders ? undefined : <LuCircleCheck />}
+ isDisabled={isDisabled || isBlocked}
+ onClick={() => {
+ setSelectedItem(row.original);
+ }}
+ >
+ {isBlocked ? (
+ "Blocked"
+ ) : hasOrders ? (
+ <HStack>
+ <PulsingDot />
+ <span>Order {orderQuantity}</span>
+ </HStack>
+ ) : (
+ "Order"
+ )}
+ </Button>
+ </div>
+ );
+ },
+ },
+ ];
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [
+ periods,
+ dateFormatter,
+ numberFormatter,
+ unitOfMeasures,
+ isDisabled,
+ // Note: ordersMap is intentionally not in deps to avoid column regeneration
+ // getOrdersForItem inside the cell will access the latest ordersMap via closure
+ ]);
- const renderActions = useCallback(
- (selectedRows: typeof data) => {
- return (
- <DropdownMenuContent align="end" className="min-w-[200px]">
- <DropdownMenuLabel>Update</DropdownMenuLabel>
- <DropdownMenuSeparator />
+ const renderActions = useCallback(
+ (selectedRows: typeof data) => {
+ return (
+ <DropdownMenuContent align="end" className="min-w-[200px]">
+ <DropdownMenuLabel>Update</DropdownMenuLabel>
+ <DropdownMenuSeparator />
- <DropdownMenuItem
- onSelect={() => onBulkUpdate(selectedRows, "order")}
- disabled={bulkUpdateFetcher.state !== "idle"}
- >
- <DropdownMenuIcon icon={<LuSquareChartGantt />} />
- Order Parts
- </DropdownMenuItem>
- </DropdownMenuContent>
- );
- },
- [bulkUpdateFetcher.state, onBulkUpdate]
- );
+ <DropdownMenuItem
+ onSelect={() => onBulkUpdate(selectedRows, "order")}
+ disabled={bulkUpdateFetcher.state !== "idle"}
+ >
+ <DropdownMenuIcon icon={<LuSquareChartGantt />} />
+ Order Parts
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ );
+ },
+ [bulkUpdateFetcher.state, onBulkUpdate]
+ );
- const defaultColumnVisibility = {
- active: false,
- type: false,
- };
+ const defaultColumnVisibility = {
+ active: false,
+ type: false,
+ };
- const defaultColumnPinning = {
- left: ["readableIdWithRevision"],
- right: ["Order"],
- };
+ const defaultColumnPinning = {
+ left: ["readableIdWithRevision"],
+ right: ["Order"],
+ };
- return (
- <>
- <Table<ProductionPlanningItem>
- count={count}
- columns={columns}
- data={data}
- defaultColumnVisibility={defaultColumnVisibility}
- defaultColumnPinning={defaultColumnPinning}
- primaryAction={
- <div className="flex items-center gap-2">
- <Combobox
- asButton
- size="sm"
- value={locationId}
- options={locations}
- onChange={(selected) => {
- // hard refresh because initialValues update has no effect otherwise
- window.location.href = getLocationPath(selected);
- }}
- />
- <mrpFetcher.Form
- method="post"
- action={path.to.api.mrp(locationId)}
- >
- <Tooltip>
- <TooltipTrigger>
- <Button
- type="submit"
- variant="secondary"
- rightIcon={<LuCirclePlay />}
- isDisabled={mrpFetcher.state !== "idle"}
- isLoading={mrpFetcher.state !== "idle"}
- >
- Recalculate
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- MRP runs automatically every 3 hours, but you can run it
- manually here.
- </TooltipContent>
- </Tooltip>
- </mrpFetcher.Form>
- </div>
+ return (
+ <>
+ <Table<ProductionPlanningItem>
+ count={count}
+ columns={columns}
+ data={data}
+ defaultColumnVisibility={defaultColumnVisibility}
+ defaultColumnPinning={defaultColumnPinning}
+ primaryAction={
+ <div className="flex items-center gap-2">
+ <Combobox
+ asButton
+ size="sm"
+ value={locationId}
+ options={locations}
+ onChange={(selected) => {
+ // hard refresh because initialValues update has no effect otherwise
+ window.location.href = getLocationPath(selected);
+ }}
+ />
+ <mrpFetcher.Form method="post" action={path.to.api.mrp(locationId)}>
+ <Tooltip>
+ <TooltipTrigger>
+ <Button
+ type="submit"
+ variant="secondary"
+ rightIcon={<LuCirclePlay />}
+ isDisabled={mrpFetcher.state !== "idle"}
+ isLoading={mrpFetcher.state !== "idle"}
+ >
+ Recalculate
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ MRP runs automatically every 3 hours, but you can run it
+ manually here.
+ </TooltipContent>
+ </Tooltip>
+ </mrpFetcher.Form>
+ </div>
+ }
+ renderActions={renderActions}
+ title="Planning"
+ table="production-planning"
+ withSavedView
+ withSelectableRows
+ />
+
+ {selectedItem && (
+ <ProductionPlanningOrderDrawer
+ locationId={locationId}
+ row={selectedItem}
+ orders={
+ selectedItem.id
+ ? ordersMap[selectedItem.id] ||
+ getProductionOrdersFromPlanning(selectedItem, periods)
+ : []
}
- renderActions={renderActions}
- title="Planning"
- table="production-planning"
- withSavedView
- withSelectableRows
+ setOrders={setOrders}
+ periods={periods}
+ isOpen={!!selectedItem}
+ onClose={() => setSelectedItem(null)}
/>
-
- {selectedItem && (
- <ProductionPlanningOrderDrawer
- locationId={locationId}
- row={selectedItem}
- orders={
- selectedItem.id
- ? ordersMap[selectedItem.id] ||
- getProductionOrdersFromPlanning(selectedItem, periods)
- : []
- }
- setOrders={setOrders}
- periods={periods}
- isOpen={!!selectedItem}
- onClose={() => setSelectedItem(null)}
- />
- )}
- </>
- );
- }
-);
-
-ProductionPlanningTable.displayName = "ProductionPlanningTable";
+ )}
+ </>
+ );
+};
export default ProductionPlanningTable;
diff --git a/apps/erp/app/routes/x+/production+/planning.tsx b/apps/erp/app/routes/x+/production+/planning.tsx
index 3fd56ae8d3..8fcec7b92a 100644
--- a/apps/erp/app/routes/x+/production+/planning.tsx
+++ b/apps/erp/app/routes/x+/production+/planning.tsx
@@ -106,13 +106,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json({
items: (items.data ?? []) as ProductionPlanningItem[],
+ count: items.count ?? 0,
periods: periods.data ?? [],
locationId,
});
}
export default function ProductionPlanningRoute() {
- const { items, locationId, periods } = useLoaderData<typeof loader>();
+ const { items, count, locationId, periods } = useLoaderData<typeof loader>();
return (
<VStack spacing={0} className="h-full ">
@@ -125,7 +126,7 @@ export default function ProductionPlanningRoute() {
>
<ProductionPlanningTable
data={items}
- count={items.length}
+ count={count}
locationId={locationId}
periods={periods}
/>
diff --git a/apps/erp/app/routes/x+/purchasing+/planning.tsx b/apps/erp/app/routes/x+/purchasing+/planning.tsx
index d086d8cfeb..ac599d91fd 100644
--- a/apps/erp/app/routes/x+/purchasing+/planning.tsx
+++ b/apps/erp/app/routes/x+/purchasing+/planning.tsx
@@ -106,13 +106,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json({
items: (items.data ?? []) as PurchasingPlanningItem[],
+ count: items.count ?? 0,
periods: periods.data ?? [],
locationId,
});
}
export default function PurchasingPlanningRoute() {
- const { items, locationId, periods } = useLoaderData<typeof loader>();
+ const { items, count, locationId, periods } = useLoaderData<typeof loader>();
return (
<VStack spacing={0} className="h-full ">
@@ -125,7 +126,7 @@ export default function PurchasingPlanningRoute() {
>
<PurchasingPlanningTable
data={items}
- count={items.length}
+ count={count}
locationId={locationId}
periods={periods}
/>