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 data point to last day in graph

Brad Barbin440da025117d
diff --git a/apps/erp/app/modules/items/ui/Item/ItemCostHistoryChart.tsx b/apps/erp/app/modules/items/ui/Item/ItemCostHistoryChart.tsx
index 523b99d33b..db55f6cbad 100644
--- a/apps/erp/app/modules/items/ui/Item/ItemCostHistoryChart.tsx
+++ b/apps/erp/app/modules/items/ui/Item/ItemCostHistoryChart.tsx
@@ -90,13 +90,28 @@ export function ItemCostHistoryChart({
let entries = itemCostHistory?.filter(
(h) => h.postingDate === dateString
);
- if (index === 0 && entries?.length === 0 && itemCostHistory?.[0]) {
+ // If the first date is empty, fill it with the first item cost history entry
+ if (
+ index === 0 &&
+ (entries === undefined || entries.length === 0) &&
+ itemCostHistory?.[0]
+ ) {
entries = [
itemCostHistory.find(
(h) => new Date(h.postingDate) <= new Date(dateString)
) ?? itemCostHistory[0],
];
}
+
+ // If the last date is empty, fill it with the last item cost history entry
+ if (
+ index === allDates.length - 1 &&
+ (entries === undefined || entries.length === 0) &&
+ itemCostHistory?.[itemCostHistory.length - 1]
+ ) {
+ entries = [itemCostHistory[itemCostHistory.length - 1]];
+ }
+
const totalCost =
entries?.reduce((sum, entry) => sum + entry.cost, 0) ?? 0;
const totalQuantity =