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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: remove itemReadableId from tables and compute it instead
Brad Barbinb601d9c5abc7
diff --git a/apps/erp/app/modules/accounting/accounting.models.ts b/apps/erp/app/modules/accounting/accounting.models.tsindex bdc3ca1a52..cea903c204 100644--- a/apps/erp/app/modules/accounting/accounting.models.ts+++ b/apps/erp/app/modules/accounting/accounting.models.ts@@ -350,7 +350,6 @@ export const costLedgerValidator = z.object({documentType: z.union([z.enum(itemLedgerDocumentTypes), z.undefined()]),documentId: z.string().optional(),itemId: zfd.text(z.string()),- itemReadableId: zfd.text(z.string()),quantity: z.number(),cost: z.number(),costPostedToGL: z.number(),diff --git a/apps/erp/app/modules/inventory/inventory.models.ts b/apps/erp/app/modules/inventory/inventory.models.tsindex 9d6551012c..d3974eb76d 100644--- a/apps/erp/app/modules/inventory/inventory.models.ts+++ b/apps/erp/app/modules/inventory/inventory.models.ts@@ -100,7 +100,6 @@ export const itemLedgerValidator = z.object({documentType: z.union([z.enum(itemLedgerDocumentTypes), z.undefined()]),documentId: z.string().optional(),itemId: z.string().min(1, { message: "Item is required" }),- itemReadableId: z.string().optional(),locationId: z.string().optional(),shelfId: z.string().optional(),quantity: z.number(),diff --git a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptPostModal.tsx b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptPostModal.tsxindex 3518b25449..4a3fffc668 100644--- a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptPostModal.tsx+++ b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptPostModal.tsx@@ -22,6 +22,8 @@ import { useFetcher, useNavigation, useParams } from "@remix-run/react";import { useEffect, useRef, useState } from "react";import { LuTriangleAlert } from "react-icons/lu";import { useUser } from "~/hooks";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import { getReceiptTracking } from "../../inventory.service";import type { ReceiptLine } from "../../types";@@ -30,6 +32,7 @@ const ReceiptPostModal = ({ onClose }: { onClose: () => void }) => {const { receiptId } = useParams();if (!receiptId) throw new Error("receiptId not found");+ const [items] = useItems();const routeData = useRouteData<{receiptLines: ReceiptLine[];}>(path.to.receipt(receiptId));@@ -94,7 +97,7 @@ const ReceiptPostModal = ({ onClose }: { onClose: () => void }) => {| undefined;if (!attributes?.["Batch Number"]) {errors.push({- itemReadableId: line.itemReadableId,+ itemReadableId: getItemReadableId(items, line.itemId) ?? null,receivedQuantity: line.receivedQuantity ?? 0,receivedQuantityError: "Batch number is required",});@@ -117,7 +120,7 @@ const ReceiptPostModal = ({ onClose }: { onClose: () => void }) => {if (quantityWithSerial !== line.receivedQuantity) {errors.push({- itemReadableId: line.itemReadableId,+ itemReadableId: getItemReadableId(items, line.itemId) ?? null,receivedQuantity: line.receivedQuantity ?? 0,receivedQuantityError: "Serial numbers are missing",});diff --git a/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx b/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsxindex e8b4eb909f..da6850f20c 100644--- a/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx+++ b/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx@@ -71,6 +71,7 @@ import type {import { splitValidator } from "~/modules/inventory";import type { action as shipmentLinesUpdateAction } from "~/routes/x+/shipment+/lines.update";import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";const ShipmentLines = () => {@@ -78,6 +79,7 @@ const ShipmentLines = () => {if (!shipmentId) throw new Error("shipmentId not found");const fetcher = useFetcher<typeof shipmentLinesUpdateAction>();+ const [items] = useItems();const routeData = useRouteData<{shipment: Shipment;@@ -224,8 +226,12 @@ const ShipmentLines = () => {<Empty className="py-6" />) : (shipmentLines+ .map((line) => ({+ ...line,+ itemReadableId: getItemReadableId(items, line.itemId) ?? "",+ })).sort((a, b) =>- (a.itemReadableId || "").localeCompare(b.itemReadableId || "")+ a.itemReadableId.localeCompare(b.itemReadableId)).map((line, index) => {const tracking = routeData?.shipmentLineTracking?.find(diff --git a/apps/erp/app/modules/inventory/ui/Shipments/ShipmentPostModal.tsx b/apps/erp/app/modules/inventory/ui/Shipments/ShipmentPostModal.tsxindex fa1d99db8f..6d12a41d6b 100644--- a/apps/erp/app/modules/inventory/ui/Shipments/ShipmentPostModal.tsx+++ b/apps/erp/app/modules/inventory/ui/Shipments/ShipmentPostModal.tsx@@ -22,6 +22,8 @@ import { useFetcher, useNavigation, useParams } from "@remix-run/react";import { useEffect, useRef, useState } from "react";import { LuTriangleAlert } from "react-icons/lu";import { useUser } from "~/hooks";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { ShipmentLine } from "../..";import { getShipmentTracking } from "../..";@@ -30,6 +32,7 @@ const ShipmentPostModal = ({ onClose }: { onClose: () => void }) => {const { shipmentId } = useParams();if (!shipmentId) throw new Error("shipmentId not found");+ const [items] = useItems();const routeData = useRouteData<{shipmentLines: ShipmentLine[];}>(path.to.shipment(shipmentId));@@ -90,7 +93,7 @@ const ShipmentPostModal = ({ onClose }: { onClose: () => void }) => {if (trackedEntity?.status !== "Available") {errors.push({- itemReadableId: line.itemReadableId,+ itemReadableId: getItemReadableId(items, line.itemId) ?? null,shippedQuantity: line.shippedQuantity ?? 0,shippedQuantityError: "Tracked entity is not available",});@@ -113,7 +116,7 @@ const ShipmentPostModal = ({ onClose }: { onClose: () => void }) => {if (quantityAvailable !== line.shippedQuantity) {errors.push({- itemReadableId: line.itemReadableId,+ itemReadableId: getItemReadableId(items, line.itemId) ?? null,shippedQuantity: line.shippedQuantity ?? 0,shippedQuantityError: "Serial numbers are missing or unavailable",});diff --git a/apps/erp/app/modules/invoicing/invoicing.models.ts b/apps/erp/app/modules/invoicing/invoicing.models.tsindex b5fb2eea22..045d1e1f89 100644--- a/apps/erp/app/modules/invoicing/invoicing.models.ts+++ b/apps/erp/app/modules/invoicing/invoicing.models.ts@@ -87,7 +87,6 @@ export const purchaseInvoiceLineValidator = zpurchaseOrderId: zfd.text(z.string().optional()),purchaseOrderLineId: zfd.text(z.string().optional()),itemId: zfd.text(z.string().optional()),- itemReadableId: zfd.text(z.string().optional()),accountNumber: zfd.text(z.string().optional()),assetId: zfd.text(z.string().optional()),description: zfd.text(z.string().optional()),@@ -204,7 +203,6 @@ export const salesInvoiceLineValidator = zpurchaseOrderId: zfd.text(z.string().optional()),purchaseOrderLineId: zfd.text(z.string().optional()),itemId: zfd.text(z.string().optional()),- itemReadableId: zfd.text(z.string().optional()),accountNumber: zfd.text(z.string().optional()),assetId: zfd.text(z.string().optional()),description: zfd.text(z.string().optional()),diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceExplorer.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceExplorer.tsxindex d35e65b676..e2ef748fba 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceExplorer.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceExplorer.tsx@@ -31,6 +31,8 @@ import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { Supplier } from "~/modules/purchasing/types";import type { MethodItemType } from "~/modules/shared";import { methodItemType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { PurchaseInvoice, PurchaseInvoiceLine } from "../../types";import DeletePurchaseInvoiceLine from "./DeletePurchaseInvoiceLine";@@ -172,6 +174,7 @@ function PurchaseInvoiceLineItem({if (!invoiceId) throw new Error("Could not find invoiceId");const permissions = usePermissions();const location = useOptimisticLocation();+ const [items] = useItems();const isSelected =location.pathname === path.to.purchaseInvoiceLine(invoiceId, line.id!);@@ -194,7 +197,7 @@ function PurchaseInvoiceLineItem({<ItemThumbnail thumbnailPath={line.thumbnailPath} type="Part" /><VStack spacing={0} className="min-w-0"><span className="font-semibold line-clamp-1">- {line.itemReadableId}+ {getItemReadableId(items, line.itemId) ?? ""}</span><span className="text-muted-foreground text-xs truncate line-clamp-1">{line.description}diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsxindex 919a5ed3b2..6affb42708 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx@@ -28,6 +28,8 @@ import { usePermissions, useRouteData } from "~/hooks";import type { PurchaseInvoice, PurchaseInvoiceLine } from "~/modules/invoicing";import { PurchaseInvoicingStatus } from "~/modules/invoicing";import type { action as statusAction } from "~/routes/x+/purchase-invoice+/$invoiceId.status";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import PurchaseInvoicePostModal from "./PurchaseInvoicePostModal";@@ -49,6 +51,7 @@ const PurchaseInvoiceHeader = () => {if (!invoiceId) throw new Error("invoiceId not found");+ const [items] = useItems();const routeData = useRouteData<{purchaseInvoice: PurchaseInvoice;purchaseInvoiceLines: PurchaseInvoiceLine[];@@ -106,7 +109,7 @@ const PurchaseInvoiceHeader = () => {if (!carbon) throw new Error("carbon not found");const { data, error } = await carbon.from("purchaseInvoiceLine")- .select("itemId, itemReadableId, description, quantity, conversionFactor")+ .select("itemId, description, quantity, conversionFactor").eq("invoiceId", invoiceId).in("invoiceLineType", ["Part", "Material", "Tool", "Consumable"]).is("purchaseOrderLineId", null);@@ -119,6 +122,7 @@ const PurchaseInvoiceHeader = () => {setLinesNotAssociatedWithPO(data?.map((d) => ({...d,+ itemReadableId: getItemReadableId(items, d.itemId) ?? null,description: d.description ?? "",quantity: d.quantity * (d.conversionFactor ?? 1),})) ?? []diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsxindex 8dd770f7e0..bcaf9a0d2e 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx@@ -34,6 +34,8 @@ import { usePermissions, useRouteData, useUser } from "~/hooks";import type { PurchaseInvoice } from "~/modules/invoicing";import { purchaseInvoiceLineValidator } from "~/modules/invoicing";import type { MethodItemType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";type PurchaseInvoiceLineFormProps = {@@ -52,6 +54,7 @@ const PurchaseInvoiceLineForm = ({const permissions = usePermissions();const { carbon } = useCarbon();+ const [items] = useItems();const { company, defaults } = useUser();const { invoiceId } = useParams();@@ -71,7 +74,6 @@ const PurchaseInvoiceLineForm = ({const [locationId, setLocationId] = useState(defaults.locationId ?? "");const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;description: string;quantity: number;supplierUnitPrice: number;@@ -85,7 +87,6 @@ const PurchaseInvoiceLineForm = ({taxPercent: number;}>({itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",description: initialValues.description ?? "",quantity: initialValues.quantity ?? 1,supplierUnitPrice: initialValues.supplierUnitPrice ?? 0,@@ -129,7 +130,6 @@ const PurchaseInvoiceLineForm = ({setItemType(t as MethodItemType);setItemData({itemId: "",- itemReadableId: "",description: "",quantity: 1,supplierUnitPrice: 0,@@ -183,7 +183,6 @@ const PurchaseInvoiceLineForm = ({setItemData({itemId: itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",quantity: supplierPart?.data?.minimumOrderQuantity ?? 1,supplierUnitPrice:@@ -259,13 +258,11 @@ const PurchaseInvoiceLineForm = ({<ModalCardHeader><ModalCardTitleclassName={cn(- isEditing &&- !itemData?.itemReadableId &&- "text-muted-foreground"+ isEditing && !itemData?.itemId && "text-muted-foreground")}>{isEditing- ? itemData?.itemReadableId || "..."+ ? getItemReadableId(items, itemData?.itemId) ?? "...": "New Purchase Invoice Line"}</ModalCardTitle><ModalCardDescription>@@ -277,7 +274,6 @@ const PurchaseInvoiceLineForm = ({<ModalCardBody><Hidden name="id" /><Hidden name="invoiceId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} /><Hidden name="invoiceLineType" value={itemType} /><Hidden name="description" value={itemData.description} /><Hiddendiff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal.tsxindex cb390806ae..a309c9eb99 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal.tsx@@ -20,6 +20,8 @@ import {import { useFetcher } from "@remix-run/react";import { useEffect } from "react";import type { action } from "~/routes/x+/purchase-invoice+/$invoiceId.post";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";type PurchaseInvoicePostModalProps = {@@ -28,7 +30,6 @@ type PurchaseInvoicePostModalProps = {invoiceId: string;linesToReceive: {itemId: string | null;- itemReadableId: string | null;description: string | null;quantity: number;}[];@@ -40,6 +41,7 @@ const PurchaseInvoicePostModal = ({invoiceId,linesToReceive,}: PurchaseInvoicePostModalProps) => {+ const [items] = useItems();const hasLinesToReceive = linesToReceive.length > 0;const fetcher = useFetcher<typeof action>();@@ -83,7 +85,9 @@ const PurchaseInvoicePostModal = ({<Tr key={line.itemId} className="text-sm"><Td><VStack spacing={0}>- <span>{line.itemReadableId}</span>+ <span>+ {getItemReadableId(items, line.itemId) ?? ""}+ </span>{line.description && (<span className="text-xs text-muted-foreground">{line.description}diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceSummary.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceSummary.tsxindex 8d1be394b0..98a2454749 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceSummary.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceSummary.tsx@@ -27,6 +27,8 @@ import {useRouteData,useUser,} from "~/hooks";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { getPrivateUrl, path } from "~/utils/path";import type {PurchaseInvoice,@@ -49,6 +51,7 @@ const LineItems = ({purchaseInvoiceLines: PurchaseInvoiceLine[];shouldConvertCurrency: boolean;}) => {+ const [items] = useItems();const { invoiceId } = useParams();if (!invoiceId) throw new Error("Could not find invoiceId");@@ -67,6 +70,7 @@ const LineItems = ({{purchaseInvoiceLines.map((line) => {if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);const lineTotal = (line.unitPrice ?? 0) * (line.quantity ?? 0);const supplierLineTotal =(line.supplierUnitPrice ?? 0) * (line.quantity ?? 0);@@ -88,7 +92,7 @@ const LineItems = ({<HStack spacing={4} className="items-start">{line.thumbnailPath ? (<img- alt={line.itemReadableId!}+ alt={itemReadableId ?? ""}className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg"src={getPrivateUrl(line.thumbnailPath)}/>@@ -105,9 +109,7 @@ const LineItems = ({><div className="flex items-center gap-x-4 justify-between flex-grow min-w-0"><HStack spacing={2} className="min-w-0 flex-shrink">- <Heading className="truncate">- {line.itemReadableId}- </Heading>+ <Heading className="truncate">{itemReadableId}</Heading><ButtonasChilddiff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/DeleteSalesInvoiceLine.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/DeleteSalesInvoiceLine.tsxindex ea21b4b1c2..b5053cf1e6 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/DeleteSalesInvoiceLine.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/DeleteSalesInvoiceLine.tsx@@ -1,5 +1,7 @@import { useParams } from "@remix-run/react";import { ConfirmDelete } from "~/components/Modals";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { SalesInvoiceLine } from "../../types";@@ -10,15 +12,18 @@ export default function DeleteSalesInvoiceLine({line: SalesInvoiceLine;onCancel: () => void;}) {+ const [items] = useItems();const { invoiceId } = useParams();if (!invoiceId) throw new Error("id not found");if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);+return (<ConfirmDeleteaction={path.to.deleteSalesInvoiceLine(invoiceId, line.id)}- name={line.itemReadableId ?? "this line"}- text={`Are you sure you want to delete the line: ${line.itemReadableId}? This cannot be undone.`}+ name={itemReadableId ?? "this line"}+ text={`Are you sure you want to delete the line: ${itemReadableId}? This cannot be undone.`}onCancel={onCancel}onSubmit={onCancel}/>diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsxindex a8be9164fc..af62503402 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx@@ -31,6 +31,8 @@ import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { Supplier } from "~/modules/purchasing/types";import type { MethodItemType } from "~/modules/shared";import { methodItemType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { SalesInvoice, SalesInvoiceLine } from "../../types";import DeleteSalesInvoiceLine from "./DeleteSalesInvoiceLine";@@ -165,6 +167,7 @@ function SalesInvoiceLineItem({isDisabled,onDelete,}: SalesInvoiceLineItemProps) {+ const [items] = useItems();const { invoiceId } = useParams();if (!invoiceId) throw new Error("Could not find invoiceId");const permissions = usePermissions();@@ -191,7 +194,7 @@ function SalesInvoiceLineItem({<ItemThumbnail thumbnailPath={line.thumbnailPath} type="Part" /><VStack spacing={0} className="min-w-0"><span className="font-semibold line-clamp-1">- {line.itemReadableId}+ {getItemReadableId(items, line.itemId) ?? ""}</span><span className="text-muted-foreground text-xs truncate line-clamp-1">{line.description}diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceHeader.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceHeader.tsxindex a164422896..961894fad7 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceHeader.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceHeader.tsx@@ -32,6 +32,8 @@ import type { SalesInvoice, SalesInvoiceLine } from "~/modules/invoicing";import { salesInvoiceStatusType } from "~/modules/invoicing";import type { action } from "~/routes/x+/sales-invoice+/$invoiceId.post";import type { action as statusAction } from "~/routes/x+/sales-invoice+/$invoiceId.status";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import SalesInvoicePostModal from "./SalesInvoicePostModal";import SalesInvoiceStatus from "./SalesInvoiceStatus";@@ -55,6 +57,7 @@ const SalesInvoiceHeader = () => {if (!invoiceId) throw new Error("invoiceId not found");+ const [items] = useItems();const routeData = useRouteData<{salesInvoice: SalesInvoice;salesInvoiceLines: SalesInvoiceLine[];@@ -113,7 +116,7 @@ const SalesInvoiceHeader = () => {if (!carbon) throw new Error("carbon not found");const { data, error } = await carbon.from("salesInvoiceLine")- .select("itemId, itemReadableId, description, quantity")+ .select("itemId, description, quantity").eq("invoiceId", invoiceId).in("invoiceLineType", ["Part", "Material", "Tool", "Consumable"]).is("salesOrderLineId", null);@@ -126,6 +129,7 @@ const SalesInvoiceHeader = () => {setLinesNotAssociatedWithSO(data?.map((d) => ({...d,+ itemReadableId: getItemReadableId(items, d.itemId) ?? null,description: d.description ?? "",quantity: d.quantity,})) ?? []diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsxindex e4feaa2190..68abc1b349 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx@@ -37,6 +37,8 @@ import type { SalesInvoice } from "~/modules/invoicing";import { salesInvoiceLineValidator } from "~/modules/invoicing";import type { MethodItemType } from "~/modules/shared";import { methodType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";type SalesInvoiceLineFormProps = {@@ -60,6 +62,7 @@ const SalesInvoiceLineForm = ({if (!invoiceId) throw new Error("invoiceId not found");+ const [items] = useItems();const routeData = useRouteData<{salesInvoice: SalesInvoice;}>(path.to.salesInvoice(invoiceId));@@ -72,7 +75,6 @@ const SalesInvoiceLineForm = ({const [locationId, setLocationId] = useState(defaults.locationId ?? "");const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;methodType: string;description: string;quantity: number;@@ -84,7 +86,6 @@ const SalesInvoiceLineForm = ({taxPercent: number;}>({itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",methodType: initialValues.methodType ?? "",description: initialValues.description ?? "",quantity: initialValues.quantity ?? 1,@@ -128,7 +129,6 @@ const SalesInvoiceLineForm = ({setItemType(t as MethodItemType);setItemData({itemId: "",- itemReadableId: "",methodType: "",description: "",quantity: 1,@@ -187,7 +187,6 @@ const SalesInvoiceLineForm = ({toast.error(errorMessage);setItemData({itemId: "",- itemReadableId: "",methodType: "",description: "",quantity: 1,@@ -204,7 +203,6 @@ const SalesInvoiceLineForm = ({setItemData((prev) => ({...prev,itemId: itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",methodType: item.data?.defaultMethodType ?? "",unitPrice:@@ -271,13 +269,11 @@ const SalesInvoiceLineForm = ({<ModalCardHeader><ModalCardTitleclassName={cn(- isEditing &&- !itemData?.itemReadableId &&- "text-muted-foreground"+ isEditing && !itemData?.itemId && "text-muted-foreground")}>{isEditing- ? itemData?.itemReadableId || "..."+ ? getItemReadableId(items, itemData?.itemId) ?? "...": "New Sales Invoice Line"}</ModalCardTitle><ModalCardDescription>@@ -289,7 +285,6 @@ const SalesInvoiceLineForm = ({<ModalCardBody><Hidden name="id" /><Hidden name="invoiceId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} /><Hidden name="invoiceLineType" value={itemType} /><Hidden name="description" value={itemData.description} /><Hiddendiff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsxindex fdffd76f1a..6117bec8f2 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx@@ -27,6 +27,8 @@ import {useRouteData,useUser,} from "~/hooks";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { getPrivateUrl, path } from "~/utils/path";import type {SalesInvoice,@@ -52,6 +54,7 @@ const LineItems = ({const { invoiceId } = useParams();if (!invoiceId) throw new Error("Could not find invoiceId");+ const [items] = useItems();const percentFormatter = usePercentFormatter();const [openItems, setOpenItems] = useState<string[]>([]);const unitOfMeasures = useUnitOfMeasure();@@ -67,6 +70,7 @@ const LineItems = ({{salesInvoiceLines.map((line) => {if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);const lineSubtotal = (line.unitPrice ?? 0) * (line.quantity ?? 0);const customerSubtotal =(line.convertedUnitPrice ?? 0) * (line.quantity ?? 0);@@ -100,7 +104,7 @@ const LineItems = ({<HStack spacing={4} className="items-start">{line.thumbnailPath ? (<img- alt={line.itemReadableId!}+ alt={itemReadableId ?? ""}className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg"src={getPrivateUrl(line.thumbnailPath)}/>@@ -117,9 +121,7 @@ const LineItems = ({><div className="flex items-center gap-x-4 justify-between flex-grow min-w-0"><HStack spacing={2} className="min-w-0 flex-shrink">- <Heading className="truncate">- {line.itemReadableId}- </Heading>+ <Heading className="truncate">{itemReadableId}</Heading><ButtonasChilddiff --git a/apps/erp/app/modules/items/items.models.ts b/apps/erp/app/modules/items/items.models.tsindex bcc35bcc38..2a99e2f972 100644--- a/apps/erp/app/modules/items/items.models.ts+++ b/apps/erp/app/modules/items/items.models.ts@@ -195,103 +195,29 @@ export const materialValidatorWithGeneratedIds = z.object({dimensionId: zfd.text(z.string().optional()),});-export const methodMaterialValidator = z- .object({- id: zfd.text(z.string().optional()),- makeMethodId: z.string().min(20, { message: "Make method is required" }),- order: zfd.numeric(z.number().min(0)),- itemType: z.enum(methodItemType, {- errorMap: (issue, ctx) => ({- message: "Item type is required",- }),+export const methodMaterialValidator = z.object({+ id: zfd.text(z.string().optional()),+ makeMethodId: z.string().min(20, { message: "Make method is required" }),+ order: zfd.numeric(z.number().min(0)),+ itemType: z.enum(methodItemType, {+ errorMap: (issue, ctx) => ({+ message: "Item type is required",}),- kit: zfd.text(z.string().optional()).transform((value) => value === "true"),- methodType: z.enum(methodType, {- errorMap: (issue, ctx) => ({- message: "Method type is required",- }),+ }),+ kit: zfd.text(z.string().optional()).transform((value) => value === "true"),+ methodType: z.enum(methodType, {+ errorMap: (issue, ctx) => ({+ message: "Method type is required",}),- itemId: z.string().optional(),- itemReadableId: z.string().optional(),- methodOperationId: zfd.text(z.string().optional()),- // description: z.string().min(1, { message: "Description is required" }),- quantity: zfd.numeric(z.number().min(0)),- unitOfMeasureCode: z- .string()- .min(1, { message: "Unit of Measure is required" }),- })- .refine(- (data) => {- if (data.itemType === "Part") {- return !!data.itemReadableId;- }- return true;- },- {- message: "Part ID is required",- path: ["itemId"],- }- )- .refine(- (data) => {- if (data.itemType === "Material") {- return !!data.itemReadableId;- }- return true;- },- {- message: "Material ID is required",- path: ["itemId"],- }- )- // .refine(- // (data) => {- // if (data.itemType === "Fixture") {- // return !!data.itemReadableId;- // }- // return true;- // },- // {- // message: "Fixture ID is required",- // path: ["itemId"],- // }- // )- .refine(- (data) => {- if (data.itemType === "Tool") {- return !!data.itemReadableId;- }- return true;- },- {- message: "Tool ID is required",- path: ["itemId"],- }- )- .refine(- (data) => {- if (data.itemType === "Consumable") {- return !!data.itemReadableId;- }- return true;- },- {- message: "Consumable ID is required",- path: ["itemId"],- }- );-// .refine(-// (data) => {-// if (data.itemType === "Service") {-// return !!data.itemReadableId;-// }-// return true;-// },-// {-// message: "Service ID is required",-// path: ["itemId"],-// }-// );+ }),+ itemId: z.string().optional(),+ methodOperationId: zfd.text(z.string().optional()),+ // description: z.string().min(1, { message: "Description is required" }),+ quantity: zfd.numeric(z.number().min(0)),+ unitOfMeasureCode: z+ .string()+ .min(1, { message: "Unit of Measure is required" }),+});export const methodOperationValidator = z.object({diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.tsindex 299a817e95..e0c7fbc4dc 100644--- a/apps/erp/app/modules/items/items.service.ts+++ b/apps/erp/app/modules/items/items.service.ts@@ -702,7 +702,7 @@ export async function getMaterialUsedIn(client.from("quoteMaterial").select(- "id, methodType, documentParentId:quoteId, documentId:quoteLineId, ...quoteLine(documentReadableId:itemReadableId)"+ "id, methodType, documentParentId:quoteId, documentId:quoteLineId, ...quoteLine(...item(documentReadableId:readableIdWithRevision))").eq("itemId", itemId).eq("companyId", companyId),@@ -1072,7 +1072,7 @@ export async function getMethodMaterials(.eq("companyId", companyId);if (args?.search) {- query = query.ilike("itemReadableId", `%${args.search}%`);+ query = query.ilike("item.readableIdWithRevision", `%${args.search}%`);}if (args) {@@ -1391,7 +1391,7 @@ export async function getPartUsedIn(client.from("quoteMaterial").select(- "id, methodType, documentParentId:quoteId, documentId:quoteLineId, ...quoteLine(documentReadableId:itemReadableId)"+ "id, methodType, documentParentId:quoteId, documentId:quoteLineId, ...quoteLine(...item(documentReadableId:readableIdWithRevision))").eq("itemId", itemId).eq("companyId", companyId),@@ -1687,7 +1687,6 @@ export async function updateDefaultRevision(.from("methodMaterial").update({itemId: item.data.id,- itemReadableId: item.data.readableId,materialMakeMethodId: makeMethod.data?.id,}).in("itemId", itemIds);@@ -2363,7 +2362,6 @@ export async function upsertMethodMaterial({...methodMaterial,itemId: methodMaterial.itemId!,- itemReadableId: methodMaterial.itemReadableId!,materialMakeMethodId,},])diff --git a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsxindex 4b71d939aa..6f0ccb71d8 100644--- a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx+++ b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx@@ -72,7 +72,8 @@ import {type MethodItemType,type MethodType,} from "~/modules/shared";-import { useBom } from "~/stores";+import { useBom, useItems, type Item as ItemType } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { methodOperationValidator } from "../../items.models";import { methodMaterialValidator } from "../../items.models";@@ -122,7 +123,7 @@ const initialMethodMaterial: Omit<Material, "makeMethodId" | "order"> & {description: string;} = {itemId: "",- itemReadableId: "",+// @ts-expect-erroritemType: "Item" as const,methodType: "Buy" as const,@@ -144,6 +145,7 @@ const BillOfMaterial = ({permissions.can("update", "parts") === false ||makeMethod.status !== "Draft";+ const [items] = useItems();const fetcher = useFetcher<{}>();const [searchParams] = useSearchParams();@@ -195,6 +197,7 @@ const BillOfMaterial = ({});const materials = makeItems(+ items,Array.from(materialsById.values()),orderState,checkedState@@ -493,7 +496,11 @@ const BillOfMaterial = ({)?.code,returnType: {type: "list",- listOptions: materials.map((m) => m.data.itemReadableId!),+ listOptions: materials+ .map(+ (m) => getItemReadableId(items, m.data.itemId) ?? ""+ )+ .filter(Boolean),},})}@@ -591,7 +598,6 @@ function MaterialForm({const [itemType, setItemType] = useState<MethodItemType>(item.data.itemType);const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;methodType: MethodType;description: string;unitOfMeasureCode: string;@@ -599,7 +605,6 @@ function MaterialForm({kit: boolean;}>({itemId: item.data.itemId ?? "",- itemReadableId: item.data.itemReadableId ?? "",methodType: item.data.methodType ?? "Buy",description: item.data.description ?? "",unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",@@ -613,7 +618,6 @@ function MaterialForm({setItemData({itemId: "",- itemReadableId: "",methodType: "" as "Buy",quantity: 1,description: "",@@ -646,7 +650,6 @@ function MaterialForm({setItemData((d) => ({...d,itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",methodType: item.data?.defaultMethodType ?? "Buy",@@ -680,7 +683,6 @@ function MaterialForm({<div><Hidden name="id" /><Hidden name="makeMethodId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} /><Hidden name="order" /><Hidden name="kit" value={itemData.kit.toString()} /></div>@@ -876,6 +878,7 @@ function MaterialForm({}function makeItems(+ items: ItemType[],materials: Material[],orderState: OrderState,checkedState: CheckedState@@ -885,11 +888,12 @@ function makeItems(? orderState[material.id] ?? material.order: material.order;const checked = material.id ? checkedState[material.id] ?? false : false;- return makeItem(material, order, checked);+ return makeItem(items, material, order, checked);});}function makeItem(+ items: ItemType[],material: Material,order: number,checked: boolean@@ -899,7 +903,9 @@ function makeItem(title: (<VStack spacing={0} className="py-1 cursor-pointer"><div className="flex items-center gap-2 group">- <h3 className="font-semibold truncate">{material.itemReadableId}</h3>+ <h3 className="font-semibold truncate">+ {getItemReadableId(items, material.itemId) ?? ""}+ </h3>{material.itemId && material.itemType && (<Link to={getLinkToItemDetails(material.itemType, material.itemId)}><LuExternalLink className="h-4 w-4 opacity-0 group-hover:opacity-100" />diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.tsindex d62a900eea..61dad801c4 100644--- a/apps/erp/app/modules/production/production.models.ts+++ b/apps/erp/app/modules/production/production.models.ts@@ -570,7 +570,6 @@ const baseMaterialValidator = z.object({}),}),itemId: z.string().min(1, { message: "Item is required" }),- itemReadableId: z.string().min(1, { message: "Item ID is required" }),kit: zfd.text(z.string().optional()).transform((value) => value === "true"),order: zfd.numeric(z.number().min(0)),quantity: zfd.numeric(z.number().min(0)),@@ -593,7 +592,7 @@ export const jobMaterialValidator = baseMaterialValidator.refine((data) => {if (data.itemType === "Part") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -605,7 +604,7 @@ export const jobMaterialValidator = baseMaterialValidator.refine((data) => {if (data.itemType === "Material") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -617,7 +616,7 @@ export const jobMaterialValidator = baseMaterialValidator.refine((data) => {if (data.itemType === "Tool") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -629,7 +628,7 @@ export const jobMaterialValidator = baseMaterialValidator.refine((data) => {if (data.itemType === "Consumable") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -646,7 +645,7 @@ export const jobMaterialValidatorForReleasedJob = baseMaterialValidator.refine((data) => {if (data.itemType === "Part") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -658,7 +657,7 @@ export const jobMaterialValidatorForReleasedJob = baseMaterialValidator.refine((data) => {if (data.itemType === "Material") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -670,7 +669,7 @@ export const jobMaterialValidatorForReleasedJob = baseMaterialValidator.refine((data) => {if (data.itemType === "Tool") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -682,7 +681,7 @@ export const jobMaterialValidatorForReleasedJob = baseMaterialValidator.refine((data) => {if (data.itemType === "Consumable") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.tsindex 632087e63d..6db0a81f06 100644--- a/apps/erp/app/modules/production/production.service.ts+++ b/apps/erp/app/modules/production/production.service.ts@@ -265,14 +265,14 @@ export async function getJobMaterialsWithQuantityOnHand() {let query = client.from("jobMaterial")- .select("id", {+ .select("id, ...item(readableIdWithRevision)", {count: "exact",}).eq("jobId", jobId);if (args?.search) {query = query.or(- `itemReadableId.ilike.%${args.search}%,description.ilike.%${args.search}%`+ `item.readableIdWithRevision.ilike.%${args.search}%,description.ilike.%${args.search}%`);}diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsxindex 47ae34f26c..02ea2193cf 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx@@ -54,7 +54,8 @@ import { SortableList, SortableListItem } from "~/components/SortableList";import { usePermissions, useRouteData, useUser } from "~/hooks";import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { MethodItemType, MethodType } from "~/modules/shared";-import { useBom } from "~/stores";+import { useBom, useItems, type Item as ItemType } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { jobOperationValidator } from "../../production.models";import {@@ -93,6 +94,7 @@ type TemporaryItems = {};function makeItems(+ items: ItemType[],materials: Material[],orderState: OrderState,checkedState: CheckedState@@ -102,21 +104,23 @@ function makeItems(? orderState[material.id] ?? material.order: material.order;const checked = material.id ? checkedState[material.id] ?? false : false;- return makeItem(material, order, checked);+ return makeItem(items, material, order, checked);});}function makeItem(+ items: ItemType[],material: Material,order: number,checked: boolean): ItemWithData {+ const itemReadableId = getItemReadableId(items, material.itemId);return {id: material.id!,title: (<VStack spacing={0} className="py-1 cursor-pointer"><div className="flex items-center gap-2 group">- <h3 className="font-semibold truncate">{material.itemReadableId}</h3>+ <h3 className="font-semibold truncate">{itemReadableId ?? ""}</h3>{material.itemId && material.itemType && (<Link to={getLinkToItemDetails(material.itemType, material.itemId)}><LuExternalLink className="h-4 w-4 opacity-0 group-hover:opacity-100" />@@ -184,7 +188,6 @@ const initialMethodMaterial: Omit<Material, "jobMakeMethodId" | "order"> & {description: string;} = {itemId: "",- itemReadableId: "",// @ts-ignoreitemType: "Item" as const,methodType: "Buy" as const,@@ -273,7 +276,9 @@ const JobBillOfMaterial = ({materialsById.set(id, material);});+ const [storeItems] = useItems();const items = makeItems(+ storeItems,Array.from(materialsById.values()),orderState,checkedState@@ -637,7 +642,6 @@ function MaterialForm({const [itemType, setItemType] = useState<MethodItemType>(item.data.itemType);const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;methodType: MethodType;description: string;unitCost: number;@@ -648,7 +652,6 @@ function MaterialForm({requiresSerialTracking: boolean;}>({itemId: item.data.itemId ?? "",- itemReadableId: item.data.itemReadableId ?? "",methodType: item.data.methodType ?? "Buy",description: item.data.description ?? "",unitCost: item.data.unitCost ?? 0,@@ -665,7 +668,6 @@ function MaterialForm({setItemData({itemId: "",- itemReadableId: "",methodType: "" as "Buy",quantity: 1,unitCost: 0,@@ -704,7 +706,6 @@ function MaterialForm({setItemData((d) => ({...d,itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",unitCost: itemCost.data?.unitCost ?? 0,unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",@@ -743,7 +744,6 @@ function MaterialForm({><Hidden name="id" /><Hidden name="jobMakeMethodId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} /><Hidden name="kit" value={itemData.kit.toString()} /><Hidden name="order" /><Hiddendiff --git a/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx b/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsxindex bc31e6d1c4..e81035ed8b 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx@@ -47,11 +47,13 @@ import { useEffect, useState } from "react";import { LuCircleChevronRight, LuNotebook } from "react-icons/lu";import { EmployeeAvatar, EmployeeAvatarGroup } from "~/components";import { useCurrencyFormatter, usePercentFormatter, useUser } from "~/hooks";+import { useItems } from "~/stores";import { makeDurations } from "~/utils/duration";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { jobOperationValidator } from "../../production.models";+import type { getJobMaterialsByMethodId } from "../../production.service";import type {- JobMaterial,JobOperation,ProductionEvent,ProductionQuantity,@@ -63,11 +65,14 @@ type Operation = z.infer<typeof jobOperationValidator> & {operationQuantity: number | null;};+type JobMaterial = NonNullable<+ Awaited<ReturnType<typeof getJobMaterialsByMethodId>>["data"]+>[number];+type Material = Pick<JobMaterial,| "id"| "itemId"- | "itemReadableId"| "estimatedQuantity"| "methodType"| "quantityIssued"@@ -95,6 +100,7 @@ const JobEstimatesVsActuals = ({const user = useUser();if (!jobId) throw new Error("Could not find jobId");+ const [items] = useItems();const currencyFormatter = useCurrencyFormatter();const percentFormatter = usePercentFormatter();const detailsDisclosure = useDisclosure();@@ -562,7 +568,9 @@ const JobEstimatesVsActuals = ({{material.methodType}</TooltipContent></Tooltip>- <span>{material.itemReadableId}</span>+ <span>+ {getItemReadableId(items, material.itemId)}+ </span></HStack></Td><Td>{material.estimatedQuantity}</Td>diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsxindex 80d9d86eed..1d24b9088e 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx@@ -33,7 +33,8 @@ import {} from "~/components/Form";import { usePermissions, useRouteData } from "~/hooks";import type { MethodItemType, MethodType } from "~/modules/shared";-import { useBom } from "~/stores";+import { useBom, useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { jobOperationValidator } from "../../production.models";import { jobMaterialValidator } from "../../production.models";@@ -67,7 +68,6 @@ const JobMaterialForm = ({);const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;methodType: MethodType;description: string;unitCost: number;@@ -75,7 +75,6 @@ const JobMaterialForm = ({quantity: number;}>({itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",methodType: initialValues.methodType ?? "Buy",description: initialValues.description ?? "",unitCost: initialValues.unitCost ?? 0,@@ -88,7 +87,6 @@ const JobMaterialForm = ({setItemType(value as MethodItemType);setItemData({itemId: "",- itemReadableId: "",methodType: "" as "Buy",quantity: 1,description: "",@@ -119,7 +117,6 @@ const JobMaterialForm = ({setItemData((d) => ({...d,itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",unitCost: itemCost.data?.unitCost ?? 0,unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",@@ -136,8 +133,7 @@ const JobMaterialForm = ({useEffect(() => {const newPath = path.to.jobMakeMethod(jobId,- initialValues.jobMakeMethodId!,- initialValues.id!+ initialValues.jobMakeMethodId!);setSelectedMaterialId(initialValues.id ?? null);@@ -158,6 +154,9 @@ const JobMaterialForm = ({jobData?.job?.status ?? "");+ const [items] = useItems();+ const itemReadableId = getItemReadableId(items, itemData.itemId);+return (<Card><ValidatedForm@@ -170,12 +169,11 @@ const JobMaterialForm = ({<CardHeader><CardTitle className="line-clamp-2">{itemData.description}</CardTitle><CardDescription className="flex items-center gap-2">- {itemData.itemReadableId} <Copy text={itemData.itemReadableId} />+ {itemReadableId} <Copy text={itemReadableId ?? ""} /></CardDescription></CardHeader><CardContent><Hidden name="jobMakeMethodId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} />{itemData.methodType === "Make" && (<Hidden name="unitCost" value={itemData.unitCost} />)}diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsxindex 56756fea3b..6ce5ca7849 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx@@ -58,11 +58,7 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {<VStack spacing={0}><Hyperlink- to={path.to.jobMakeMethod(- jobId,- row.original.jobMakeMethodId,- row.original.id- )}+ to={path.to.jobMakeMethod(jobId, row.original.jobMakeMethodId)}onClick={() => {setSelectedMaterialId(row.original.id ?? null);}}diff --git a/apps/erp/app/modules/purchasing/purchasing.models.ts b/apps/erp/app/modules/purchasing/purchasing.models.tsindex e74e0493f6..b6826027ed 100644--- a/apps/erp/app/modules/purchasing/purchasing.models.ts+++ b/apps/erp/app/modules/purchasing/purchasing.models.ts@@ -146,7 +146,6 @@ export const purchaseOrderLineValidator = z}),}),itemId: zfd.text(z.string().optional()),- itemReadableId: zfd.text(z.string().optional()),accountNumber: zfd.text(z.string().optional()),assetId: zfd.text(z.string().optional()),conversionFactor: zfd.numeric(z.number().optional()),@@ -335,7 +334,6 @@ export const supplierQuoteLineValidator = z.object({id: zfd.text(z.string().optional()),supplierQuoteId: z.string(),itemId: z.string().min(1, { message: "Part is required" }),- itemReadableId: zfd.text(z.string().optional()),description: z.string().min(1, { message: "Description is required" }),supplierPartId: zfd.text(z.string().optional()),inventoryUnitOfMeasureCode: zfd.text(diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/DeletePurchaseOrderLine.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/DeletePurchaseOrderLine.tsxindex 0fbb69009a..00f1729508 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/DeletePurchaseOrderLine.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/DeletePurchaseOrderLine.tsx@@ -1,5 +1,7 @@import { useParams } from "@remix-run/react";import { ConfirmDelete } from "~/components/Modals";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { PurchaseOrderLine } from "../../types";@@ -10,15 +12,18 @@ export default function DeletePurchaseOrderLine({line: PurchaseOrderLine;onCancel: () => void;}) {+ const [items] = useItems();const { orderId } = useParams();if (!orderId) throw new Error("id not found");if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);+return (<ConfirmDeleteaction={path.to.deletePurchaseOrderLine(orderId, line.id)}- name={line.itemReadableId ?? "this line"}- text={`Are you sure you want to delete the line: ${line.itemReadableId}? This cannot be undone.`}+ name={itemReadableId ?? "this line"}+ text={`Are you sure you want to delete the line: ${itemReadableId}? This cannot be undone.`}onCancel={onCancel}onSubmit={onCancel}/>diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderExplorer.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderExplorer.tsxindex eb39d6e666..7f6d6e0197 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderExplorer.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderExplorer.tsx@@ -31,6 +31,8 @@ import {import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { MethodItemType } from "~/modules/shared";import { methodItemType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { PurchaseOrder, PurchaseOrderLine, Supplier } from "../../types";import DeletePurchaseOrderLine from "./DeletePurchaseOrderLine";@@ -161,6 +163,7 @@ function PurchaseOrderLineItem({isDisabled,onDelete,}: PurchaseOrderLineItemProps) {+ const [items] = useItems();const { orderId, lineId } = useParams();if (!orderId) throw new Error("Could not find orderId");const permissions = usePermissions();@@ -197,7 +200,7 @@ function PurchaseOrderLineItem({<VStack spacing={0} className="min-w-0"><span className="font-semibold line-clamp-1">- {line.itemReadableId}+ {getItemReadableId(items, line.itemId)}</span><span className="text-muted-foreground text-xs truncate line-clamp-1">{line.description}diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsxindex 9e09e2281c..dcb0c98104 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx@@ -39,6 +39,8 @@ import type { PurchaseOrder, PurchaseOrderLine } from "~/modules/purchasing";import { purchaseOrderLineValidator } from "~/modules/purchasing";import type { MethodItemType } from "~/modules/shared";import type { action } from "~/routes/x+/purchase-order+/$orderId.$lineId.details";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import DeletePurchaseOrderLine from "./DeletePurchaseOrderLine";@@ -55,7 +57,7 @@ const PurchaseOrderLineForm = ({}: PurchaseOrderLineFormProps) => {const permissions = usePermissions();const { carbon } = useCarbon();-+ const [items] = useItems();const { company } = useUser();const { orderId } = useParams();const fetcher = useFetcher<typeof action>();@@ -76,7 +78,6 @@ const PurchaseOrderLineForm = ({const [locationId, setLocationId] = useState(initialValues.locationId);const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;description: string;purchaseQuantity: number;supplierUnitPrice: number;@@ -90,7 +91,6 @@ const PurchaseOrderLineForm = ({taxPercent: number;}>({itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",description: initialValues.description ?? "",purchaseQuantity: initialValues.purchaseQuantity ?? 1,supplierUnitPrice: initialValues.supplierUnitPrice ?? 0,@@ -145,7 +145,6 @@ const PurchaseOrderLineForm = ({setItemType(t as MethodItemType);setItemData({itemId: "",- itemReadableId: "",description: "",purchaseQuantity: 1,supplierUnitPrice: 0,@@ -199,7 +198,6 @@ const PurchaseOrderLineForm = ({setItemData({itemId: itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",purchaseQuantity: supplierPart?.data?.minimumOrderQuantity ?? 1,supplierUnitPrice:@@ -277,13 +275,11 @@ const PurchaseOrderLineForm = ({<ModalCardHeader><ModalCardTitleclassName={cn(- isEditing &&- !itemData?.itemReadableId &&- "text-muted-foreground"+ isEditing && !itemData?.itemId && "text-muted-foreground")}>{isEditing- ? itemData?.itemReadableId || "..."+ ? getItemReadableId(items, itemData?.itemId) || "...": "New Purchase Order Line"}</ModalCardTitle><ModalCardDescription>@@ -299,7 +295,7 @@ const PurchaseOrderLineForm = ({<ModalCardBody><Hidden name="id" /><Hidden name="purchaseOrderId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} />+<Hidden name="purchaseOrderLineType" value={itemType} /><Hidden name="description" value={itemData.description} /><Hiddendiff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSummary.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSummary.tsxindex 725d37f170..12c51793ad 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSummary.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSummary.tsx@@ -27,6 +27,8 @@ import {useRouteData,useUser,} from "~/hooks";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { getPrivateUrl, path } from "~/utils/path";import type {PurchaseOrder,@@ -50,6 +52,7 @@ const LineItems = ({lines: PurchaseOrderLine[];shouldConvertCurrency: boolean;}) => {+ const [items] = useItems();const { orderId } = useParams();if (!orderId) throw new Error("Could not find orderId");@@ -68,6 +71,7 @@ const LineItems = ({{lines.map((line) => {if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);const lineTotal = (line.unitPrice ?? 0) * (line.purchaseQuantity ?? 0);const supplierLineTotal =(line.supplierUnitPrice ?? 0) * (line.purchaseQuantity ?? 0);@@ -89,7 +93,7 @@ const LineItems = ({<HStack spacing={4} className="items-start">{line.thumbnailPath ? (<img- alt={line.itemReadableId!}+ alt={itemReadableId!}className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg"src={getPrivateUrl(line.thumbnailPath)}/>@@ -106,9 +110,7 @@ const LineItems = ({><div className="flex items-center gap-x-4 justify-between flex-grow min-w-0"><HStack spacing={2} className="min-w-0 flex-shrink ">- <Heading className="truncate">- {line.itemReadableId}- </Heading>+ <Heading className="truncate">{itemReadableId}</Heading><ButtonasChilddiff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/DeleteSupplierQuoteLine.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/DeleteSupplierQuoteLine.tsxindex 54ff754834..15c2575915 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/DeleteSupplierQuoteLine.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/DeleteSupplierQuoteLine.tsx@@ -1,23 +1,28 @@import { useParams } from "@remix-run/react";import { ConfirmDelete } from "~/components/Modals";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";export default function DeleteSupplierQuoteLine({line,onCancel,}: {- line: { itemReadableId: string; id: string };+ line: { itemId: string; id: string };onCancel: () => void;}) {+ const [items] = useItems();const { id } = useParams();if (!id) throw new Error("id not found");if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);+return (<ConfirmDeleteaction={path.to.deleteSupplierQuoteLine(id, line.id)}- name={line.itemReadableId ?? "this line"}- text={`Are you sure you want to delete the line: ${line.itemReadableId}? This cannot be undone.`}+ name={itemReadableId ?? "this line"}+ text={`Are you sure you want to delete the line: ${itemReadableId}? This cannot be undone.`}onCancel={onCancel}onSubmit={onCancel}/>diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteExplorer.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteExplorer.tsxindex fa756b3820..72f8b910c5 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteExplorer.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteExplorer.tsx@@ -25,6 +25,8 @@ import { Empty, ItemThumbnail, MethodItemTypeIcon } from "~/components";import { useOptimisticLocation, usePermissions, useRouteData } from "~/hooks";import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { MethodItemType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { Supplier, SupplierQuote, SupplierQuoteLine } from "../../types";import DeleteSupplierQuoteLine from "./DeleteSupplierQuoteLine";@@ -140,7 +142,7 @@ export default function SupplierQuoteExplorer() {{deleteLineDisclosure.isOpen && deleteLine?.id && (<DeleteSupplierQuoteLineline={{- itemReadableId: deleteLine?.itemReadableId ?? "",+ itemId: deleteLine?.itemId ?? "",id: deleteLine.id,}}onCancel={onDeleteCancel}@@ -163,6 +165,7 @@ function SupplierQuoteLineItem({}: SupplierQuoteLineItemProps) {const { id, lineId } = useParams();if (!id) throw new Error("Could not find id");+ const [items] = useItems();const permissions = usePermissions();const disclosure = useDisclosure();const location = useOptimisticLocation();@@ -197,7 +200,7 @@ function SupplierQuoteLineItem({<VStack spacing={0} className="min-w-0"><span className="font-semibold line-clamp-1">- {line.itemReadableId}+ {getItemReadableId(items, line.itemId)}</span><span className="text-muted-foreground text-xs truncate line-clamp-1">{line.description}diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsxindex e39a68f2c1..3b5b546df6 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx@@ -333,7 +333,7 @@ const SupplierQuoteLineForm = ({{isEditing && deleteDisclosure.isOpen && initialValues.id && (<DeleteSupplierQuoteLineline={{- itemReadableId: itemData.itemReadableId ?? "",+ itemId: itemData.itemId ?? "",id: initialValues.id,}}onCancel={deleteDisclosure.onClose}diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsxindex d51bf6410b..840c602d53 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx@@ -24,6 +24,8 @@ import { LuChevronRight, LuImage } from "react-icons/lu";import { SupplierAvatar } from "~/components";import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";import { useCurrencyFormatter, useRouteData, useUser } from "~/hooks";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { getPrivateUrl, path } from "~/utils/path";import type {PurchaseOrderLine,@@ -45,6 +47,7 @@ const LineItems = ({const { id } = useParams();if (!id) throw new Error("Could not find quote id");+ const [items] = useItems();const routeData = useRouteData<{quote: SupplierQuote;lines: SupplierQuoteLine[];@@ -87,6 +90,7 @@ const LineItems = ({{routeData?.lines?.map((line) => {const prices = pricingByLine[line.id!];+ const itemReadableId = getItemReadableId(items, line.itemId);if (!line || !prices || !line.id) {return null;}@@ -102,7 +106,7 @@ const LineItems = ({<HStack spacing={4} className="items-start">{line.thumbnailPath ? (<img- alt={line.itemReadableId!}+ alt={itemReadableId!}className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg"src={getPrivateUrl(line.thumbnailPath)}/>@@ -119,9 +123,7 @@ const LineItems = ({><div className="flex items-center gap-x-4 justify-between flex-grow"><HStack spacing={2} className="min-w-0 flex-shrink">- <Heading className="truncate">- {line.itemReadableId}- </Heading>+ <Heading className="truncate">{itemReadableId}</Heading><ButtonasChildvariant="link"diff --git a/apps/erp/app/modules/quality/ui/Issue/IssueAssociations.tsx b/apps/erp/app/modules/quality/ui/Issue/IssueAssociations.tsxindex d75fd34356..b1c20d5062 100644--- a/apps/erp/app/modules/quality/ui/Issue/IssueAssociations.tsx+++ b/apps/erp/app/modules/quality/ui/Issue/IssueAssociations.tsx@@ -50,6 +50,8 @@ import { ConfirmDelete } from "~/components/Modals";import { LevelLine } from "~/components/TreeView";import { usePermissions } from "~/hooks";import type { action as associationAction } from "~/routes/x+/issue+/$id.association.new";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import { issueAssociationValidator } from "../../quality.models";import type { IssueAssociationKey, IssueAssociationNode } from "../../types";@@ -599,6 +601,7 @@ function NewSalesOrderLineAssociation({ itemId }: { itemId?: string }) {function NewShipmentLineAssociation({ itemId }: { itemId?: string }) {const { carbon } = useCarbon();+ const [items] = useItems();const [shipments, setShipments] = useState<{ label: string; value: string }[]>([]);@@ -638,7 +641,7 @@ function NewShipmentLineAssociation({ itemId }: { itemId?: string }) {let query = carbon.from("shipmentLine")- .select("id, itemId, itemReadableId")+ .select("id, itemId").eq("shipmentId", shipmentId);if (itemId) {@@ -653,7 +656,7 @@ function NewShipmentLineAssociation({ itemId }: { itemId?: string }) {setShipmentLines(data?.map((line) => ({- label: line.itemReadableId ?? `Line ${line.id}`,+ label: getItemReadableId(items, line.itemId) ?? `Line ${line.id}`,value: line.id,})) ?? []);@@ -694,6 +697,7 @@ function NewShipmentLineAssociation({ itemId }: { itemId?: string }) {function NewReceiptLineAssociation({ itemId }: { itemId?: string }) {const { carbon } = useCarbon();+ const [items] = useItems();const [receipts, setReceipts] = useState<{ label: string; value: string }[]>([]);@@ -733,7 +737,7 @@ function NewReceiptLineAssociation({ itemId }: { itemId?: string }) {let query = carbon.from("receiptLine")- .select("id, itemId, itemReadableId")+ .select("id, itemId").eq("receiptId", receiptId);if (itemId) {@@ -748,7 +752,7 @@ function NewReceiptLineAssociation({ itemId }: { itemId?: string }) {setReceiptLines(data?.map((line) => ({- label: line.itemReadableId ?? `Line ${line.id}`,+ label: getItemReadableId(items, line.itemId) ?? `Line ${line.id}`,value: line.id,})) ?? []);diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.tsindex 4f2baf4ede..5dab4b9a8e 100644--- a/apps/erp/app/modules/sales/sales.models.ts+++ b/apps/erp/app/modules/sales/sales.models.ts@@ -187,7 +187,6 @@ export const quoteLineValidator = z.object({id: zfd.text(z.string().optional()),quoteId: z.string(),itemId: z.string().min(1, { message: "Part is required" }),- itemReadableId: zfd.text(z.string().optional()),status: z.enum(quoteLineStatusType, {errorMap: () => ({ message: "Status is required" }),}),@@ -230,7 +229,6 @@ export const quoteMaterialValidator = z}),}),itemId: z.string().min(1, { message: "Item is required" }),- itemReadableId: z.string().min(1, { message: "Item ID is required" }),kit: zfd.text(z.string().optional()).transform((value) => value === "true"),description: z.string().min(1, { message: "Description is required" }),quoteOperationId: zfd.text(z.string().optional()),@@ -243,7 +241,7 @@ export const quoteMaterialValidator = z.refine((data) => {if (data.itemType === "Part") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -255,7 +253,7 @@ export const quoteMaterialValidator = z.refine((data) => {if (data.itemType === "Material") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -267,7 +265,7 @@ export const quoteMaterialValidator = z.refine((data) => {if (data.itemType === "Tool") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -279,7 +277,7 @@ export const quoteMaterialValidator = z.refine((data) => {if (data.itemType === "Consumable") {- return !!data.itemReadableId;+ return !!data.itemId;}return true;},@@ -288,18 +286,6 @@ export const quoteMaterialValidator = zpath: ["itemId"],});-// .refine(-// (data) => {-// if (data.itemType === "Service") {-// return !!data.itemReadableId;-// }-// return true;-// },-// {-// message: "Service ID is required",-// path: ["itemId"],-// }-// );export const quoteOperationValidator = z.object({@@ -626,7 +612,6 @@ export const salesOrderLineValidator = zassetId: zfd.text(z.string().optional()),description: zfd.text(z.string().optional()),itemId: zfd.text(z.string().optional()),- itemReadableId: zfd.text(z.string().optional()),locationId: z.string().min(0, { message: "Location is required" }),methodType: z.enum(methodType, {diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.tsindex d4c5bc2850..c3edaf1948 100644--- a/apps/erp/app/modules/sales/sales.service.ts+++ b/apps/erp/app/modules/sales/sales.service.ts@@ -819,7 +819,7 @@ export async function getQuoteLinesList() {return client.from("quoteLine")- .select("id, itemReadableId, description")+ .select("id, description, ...item(readableIdWithRevision)").eq("quoteId", quoteId);}diff --git a/apps/erp/app/modules/sales/ui/Quotes/DeleteQuoteLine.tsx b/apps/erp/app/modules/sales/ui/Quotes/DeleteQuoteLine.tsxindex bf6b9e96cc..30bffc7db3 100644--- a/apps/erp/app/modules/sales/ui/Quotes/DeleteQuoteLine.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/DeleteQuoteLine.tsx@@ -1,5 +1,7 @@import { useParams } from "@remix-run/react";import { ConfirmDelete } from "~/components/Modals";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { QuotationLine } from "../../types";@@ -10,15 +12,18 @@ export default function DeleteQuoteLine({line: QuotationLine;onCancel: () => void;}) {+ const [items] = useItems();const { quoteId } = useParams();if (!quoteId) throw new Error("id not found");if (!line.id) return null;+ const itemReadableId = getItemReadableId(items, line.itemId);+return (<ConfirmDeleteaction={path.to.deleteQuoteLine(quoteId, line.id)}- name={line.itemReadableId ?? "this line"}- text={`Are you sure you want to delete the line: ${line.itemReadableId}? This cannot be undone.`}+ name={itemReadableId ?? "this line"}+ text={`Are you sure you want to delete the line: ${itemReadableId}? This cannot be undone.`}onCancel={onCancel}onSubmit={onCancel}/>diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsxindex 058eb81d4f..841c5dfbf5 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx@@ -55,7 +55,8 @@ import { SortableList, SortableListItem } from "~/components/SortableList";import { usePermissions, useRouteData, useUser } from "~/hooks";import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { MethodItemType, MethodType } from "~/modules/shared";-import { useBom } from "~/stores";+import { useBom, useItems, type Item as ItemType } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { quoteOperationValidator } from "../../sales.models";import { quoteMaterialValidator } from "../../sales.models";@@ -93,6 +94,7 @@ type TemporaryItems = {};function makeItems(+ items: ItemType[],materials: Material[],orderState: OrderState,checkedState: CheckedState@@ -102,21 +104,23 @@ function makeItems(? orderState[material.id] ?? material.order: material.order;const checked = material.id ? checkedState[material.id] ?? false : false;- return makeItem(material, order, checked);+ return makeItem(items, material, order, checked);});}function makeItem(+ items: ItemType[],material: Material,order: number,checked: boolean): ItemWithData {+ const itemReadableId = getItemReadableId(items, material.itemId);return {id: material.id!,title: (<VStack spacing={0} className="py-1 cursor-pointer"><div className="flex items-center gap-2 group">- <h3 className="font-semibold truncate">{material.itemReadableId}</h3>+ <h3 className="font-semibold truncate">{itemReadableId}</h3>{material.itemId && material.itemType && (<Link to={getLinkToItemDetails(material.itemType, material.itemId)}><LuExternalLink className="h-4 w-4 opacity-0 group-hover:opacity-100" />@@ -280,7 +284,10 @@ const QuoteBillOfMaterial = ({materialsById.set(id, material);});+ const [storedItems] = useItems();+const items = makeItems(+ storedItems,Array.from(materialsById.values()),orderState,checkedState@@ -630,7 +637,6 @@ function MaterialForm({const [itemType, setItemType] = useState<MethodItemType>(item.data.itemType);const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;methodType: MethodType;description: string;unitCost: number;@@ -639,7 +645,6 @@ function MaterialForm({kit: boolean;}>({itemId: item.data.itemId ?? "",- itemReadableId: item.data.itemReadableId ?? "",methodType: item.data.methodType ?? "Buy",description: item.data.description ?? "",unitCost: item.data.unitCost ?? 0,@@ -653,7 +658,6 @@ function MaterialForm({setItemType(value as MethodItemType);setItemData({itemId: "",- itemReadableId: "",methodType: "" as "Buy",quantity: 1,unitCost: 0,@@ -690,7 +694,6 @@ function MaterialForm({setItemData((d) => ({...d,itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",unitCost: itemCost.data?.unitCost ?? 0,unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",@@ -722,7 +725,6 @@ function MaterialForm({><Hidden name="id" /><Hidden name="quoteMakeMethodId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} /><Hidden name="order" /><Hidden name="kit" value={itemData.kit.toString()} />{itemData.methodType === "Make" && (diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteExplorer.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteExplorer.tsxindex 72afd2f853..a07194a34e 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteExplorer.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteExplorer.tsx@@ -80,7 +80,6 @@ export default function QuoteExplorer({ methods }: QuoteExplorerProps) {description: "",estimatorId: userId,itemId: "",- itemReadableId: "",locationId: quoteData?.quote?.locationId ?? defaults.locationId ?? "",methodType: "Make" as const,status: "Not Started" as const,diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsxindex 498780523f..9210c63d77 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx@@ -52,6 +52,8 @@ import type {import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import { methodType } from "~/modules/shared";import type { action } from "~/routes/x+/quote+/$quoteId.new";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import { quoteLineStatusType, quoteLineValidator } from "../../sales.models";import DeleteQuoteLine from "./DeleteQuoteLine";@@ -76,6 +78,7 @@ const QuoteLineForm = ({if (!quoteId) throw new Error("quoteId not found");+ const [items] = useItems();const routeData = useRouteData<{quote: Quotation;}>(path.to.quote(quoteId));@@ -91,7 +94,6 @@ const QuoteLineForm = ({customerPartRevision: string;description: string;itemId: string;- itemReadableId: string;methodType: string;modelUploadId: string | null;uom: string;@@ -99,7 +101,6 @@ const QuoteLineForm = ({customerPartId: initialValues.customerPartId ?? "",customerPartRevision: initialValues.customerPartRevision ?? "",itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",description: initialValues.description ?? "",methodType: initialValues.methodType ?? "",uom: initialValues.unitOfMeasureCode ?? "",@@ -193,7 +194,6 @@ const QuoteLineForm = ({const newItemData = {...itemData,itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",methodType: item.data?.defaultMethodType ?? "",uom: item.data?.unitOfMeasureCode ?? "",@@ -263,7 +263,8 @@ const QuoteLineForm = ({<ModalCardHeader><ModalCardTitle>{isEditing- ? itemData?.itemReadableId ?? "Quote Line"+ ? getItemReadableId(items, itemData?.itemId) ??+ "Quote Line": "New Quote Line"}</ModalCardTitle><ModalCardDescription>@@ -308,10 +309,6 @@ const QuoteLineForm = ({<ModalCardBody><Hidden name="id" /><Hidden name="quoteId" />- <Hidden- name="itemReadableId"- value={itemData?.itemReadableId}- /><Hidden name="unitOfMeasureCode" value={itemData?.uom} /><Hiddenname="modelUploadId"diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsxindex 936a0f9669..e13d764b58 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx@@ -33,7 +33,8 @@ import {} from "~/components/Form";import { usePermissions } from "~/hooks";import type { MethodItemType, MethodType } from "~/modules/shared";-import { useBom } from "~/stores";+import { useBom, useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import type { quoteOperationValidator } from "../../sales.models";import { quoteMaterialValidator } from "../../sales.models";@@ -65,7 +66,6 @@ const QuoteMaterialForm = ({);const [itemData, setItemData] = useState<{itemId: string;- itemReadableId: string;methodType: MethodType;description: string;unitCost: number;@@ -73,7 +73,6 @@ const QuoteMaterialForm = ({quantity: number;}>({itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",methodType: initialValues.methodType ?? "Buy",description: initialValues.description ?? "",unitCost: initialValues.unitCost ?? 0,@@ -86,7 +85,6 @@ const QuoteMaterialForm = ({setItemType(value as MethodItemType);setItemData({itemId: "",- itemReadableId: "",methodType: "" as "Buy",quantity: 1,description: "",@@ -117,7 +115,6 @@ const QuoteMaterialForm = ({setItemData((d) => ({...d,itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",unitCost: itemCost.data?.unitCost ?? 0,unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",@@ -149,6 +146,9 @@ const QuoteMaterialForm = ({setSelectedMaterialId,]);+ const [items] = useItems();+ const itemReadableId = getItemReadableId(items, itemData.itemId);+return (<Card><ValidatedForm@@ -161,12 +161,12 @@ const QuoteMaterialForm = ({<CardHeader><CardTitle className="line-clamp-2">{itemData.description}</CardTitle><CardDescription className="flex items-center gap-2">- {itemData.itemReadableId} <Copy text={itemData.itemReadableId} />+ {itemReadableId} <Copy text={itemReadableId ?? ""} /></CardDescription></CardHeader><CardContent><Hidden name="quoteMakeMethodId" />- <Hidden name="itemReadableId" value={itemData.itemReadableId} />+{itemData.methodType === "Make" && (<Hidden name="unitCost" value={itemData.unitCost} />)}diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsxindex aa0eb2aff0..d3ea1e45d5 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx@@ -51,7 +51,9 @@ import {import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";import type { MethodItemType } from "~/modules/shared";import { methodItemType } from "~/modules/shared";+import { useItems } from "~/stores/items";import { path } from "~/utils/path";+import { getItemReadableId } from "~/utils/items";import type {Customer,SalesOrder,@@ -244,6 +246,7 @@ function SalesOrderLineItem({const { orderId, lineId } = useParams();if (!orderId) throw new Error("Could not find orderId");+ const [items] = useItems();const permissions = usePermissions();const disclosure = useDisclosure();const location = useOptimisticLocation();@@ -282,7 +285,7 @@ function SalesOrderLineItem({<VStack spacing={0} className="min-w-0"><span className="font-semibold line-clamp-1">- {line.itemReadableId}+ {getItemReadableId(items, line.itemId)}</span><span className="text-muted-foreground text-xs truncate line-clamp-1">{line.description}diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsxindex aceb6aecbb..61b4a44d18 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx@@ -45,6 +45,8 @@ import { usePermissions, useRouteData, useUser } from "~/hooks";import { useCarbon } from "@carbon/auth";import { methodType } from "~/modules/shared";+import { useItems } from "~/stores";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";import { salesOrderLineValidator } from "../../sales.models";import type {@@ -86,7 +88,6 @@ const SalesOrderLineForm = ({const [locationId, setLocationId] = useState(initialValues.locationId ?? "");const [itemData, setItemData] = useState<{itemId: string;- itemReadableId?: string;methodType: string;description: string;unitPrice: number;@@ -95,7 +96,6 @@ const SalesOrderLineForm = ({modelUploadId: string | null;}>({itemId: initialValues.itemId ?? "",- itemReadableId: initialValues.itemReadableId ?? "",description: initialValues.description ?? "",methodType: initialValues.methodType ?? "",unitPrice: initialValues.unitPrice ?? 0,@@ -111,7 +111,6 @@ const SalesOrderLineForm = ({setLineType(t);setItemData({itemId: "",- itemReadableId: "",description: "",unitPrice: 0,methodType: "",@@ -150,7 +149,6 @@ const SalesOrderLineForm = ({setItemData({itemId,- itemReadableId: item.data?.readableIdWithRevision ?? "",description: item.data?.name ?? "",methodType: item.data?.defaultMethodType ?? "",unitPrice: price.data?.unitSalePrice ?? 0,@@ -182,6 +180,7 @@ const SalesOrderLineForm = ({};const deleteDisclosure = useDisclosure();+ const [items] = useItems();return (<>@@ -206,13 +205,11 @@ const SalesOrderLineForm = ({<ModalCardHeader><ModalCardTitleclassName={cn(- isEditing &&- !itemData?.itemReadableId &&- "text-muted-foreground"+ isEditing && !itemData?.itemId && "text-muted-foreground")}>{isEditing- ? itemData?.itemReadableId || "..."+ ? getItemReadableId(items, itemData?.itemId) || "...": "New Sales Order Line"}</ModalCardTitle><ModalCardDescription>@@ -247,10 +244,7 @@ const SalesOrderLineForm = ({<ModalCardBody><Hidden name="id" /><Hidden name="salesOrderId" />- <Hidden- name="itemReadableId"- value={itemData?.itemReadableId}- />+ <Hidden name="itemId" value={itemData?.itemId} />{!isEditing && (<Hiddenname="description"diff --git a/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsx b/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsxindex b4d8a6b5e0..2826812da7 100644--- a/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsx+++ b/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsx@@ -75,7 +75,6 @@ export default function SalesRFQExplorer() {customerPartRevision: "",description: "",itemId: "",- itemReadableId: "",quantity: [1],order: 1,unitOfMeasureCode: "EA",diff --git a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsxindex 55e6d0452b..7790b650c5 100644--- a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx@@ -154,7 +154,6 @@ export default function JobMakeMethodRoute() {<Await resolve={productionData}>{(resolvedProductionData) => (<JobEstimatesVsActuals- // @ts-expect-errormaterials={materials ?? []}// @ts-expect-erroroperations={operations}diff --git a/apps/erp/app/routes/x+/material+/new.tsx b/apps/erp/app/routes/x+/material+/new.tsxindex 80056c168c..cc700e8803 100644--- a/apps/erp/app/routes/x+/material+/new.tsx+++ b/apps/erp/app/routes/x+/material+/new.tsx@@ -31,10 +31,9 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- console.log(validation.data);-const createMaterial = await upsertMaterial(client, {...validation.data,+ active: true,companyId,customFields: setCustomFields(formData),createdBy: userId,diff --git a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.$lineId.details.tsx b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.$lineId.details.tsxindex 11a39b18ff..9cc069e947 100644--- a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.$lineId.details.tsx@@ -20,7 +20,9 @@ import {SupplierInteractionLineDocuments,SupplierInteractionLineNotes,} from "~/modules/purchasing/ui/SupplierInteraction";+import { useItems } from "~/stores";import { getCustomFields, setCustomFields } from "~/utils/form";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";export async function loader({ request, params }: LoaderFunctionArgs) {@@ -105,6 +107,7 @@ export default function EditPurchaseInvoiceLineRoute() {if (!invoiceId) throw notFound("invoiceId not found");if (!lineId) throw notFound("lineId not found");+ const [items] = useItems();const { purchaseInvoiceLine, files } = useLoaderData<typeof loader>();const initialValues = {@@ -112,7 +115,7 @@ export default function EditPurchaseInvoiceLineRoute() {invoiceId: purchaseInvoiceLine?.invoiceId ?? "",invoiceLineType: (purchaseInvoiceLine?.invoiceLineType ?? "Part") as "Part",itemId: purchaseInvoiceLine?.itemId ?? "",- itemReadableId: purchaseInvoiceLine?.itemReadableId ?? "",+accountNumber: purchaseInvoiceLine?.accountNumber ?? "",assetId: purchaseInvoiceLine?.assetId ?? "",description: purchaseInvoiceLine?.description ?? "",@@ -141,7 +144,7 @@ export default function EditPurchaseInvoiceLineRoute() {id={purchaseInvoiceLine?.id ?? ""}table="purchaseInvoiceLine"title="Notes"- subTitle={purchaseInvoiceLine?.itemReadableId ?? ""}+ subTitle={getItemReadableId(items, purchaseInvoiceLine?.itemId) ?? ""}internalNotes={purchaseInvoiceLine?.internalNotes as JSONContent}/>diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsxindex 182cbffedf..9ee23ffc63 100644--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsx@@ -124,7 +124,6 @@ export default function EditPurchaseOrderLineRoute() {purchaseOrderId: line?.purchaseOrderId ?? "",purchaseOrderLineType: (line?.purchaseOrderLineType ?? "Part") as "Part",itemId: line?.itemId ?? "",- itemReadableId: line?.itemReadableId ?? "",accountNumber: line?.accountNumber ?? "",assetId: line?.assetId ?? "",description: line?.description ?? "",diff --git a/apps/erp/app/routes/x+/purchasing+/planning.update.tsx b/apps/erp/app/routes/x+/purchasing+/planning.update.tsxindex e1822d1869..393ed93400 100644--- a/apps/erp/app/routes/x+/purchasing+/planning.update.tsx+++ b/apps/erp/app/routes/x+/purchasing+/planning.update.tsx@@ -259,7 +259,6 @@ export async function action({ request }: ActionFunctionArgs) {{purchaseOrderId: purchaseOrder.id,itemId: item.id,- itemReadableId: order.itemReadableId,description: order.description,purchaseOrderLineType: "Part",purchaseQuantity: order.quantity,@@ -295,7 +294,6 @@ export async function action({ request }: ActionFunctionArgs) {id: order.existingLineId,purchaseOrderId: order.existingId,itemId: item.id,- itemReadableId: order.itemReadableId,description: order.description,purchaseOrderLineType: "Part",purchaseQuantity: order.quantity,@@ -329,7 +327,6 @@ export async function action({ request }: ActionFunctionArgs) {{purchaseOrderId: order.existingId,itemId: item.id,- itemReadableId: order.itemReadableId,description: order.description,purchaseOrderLineType: "Part",purchaseQuantity: order.quantity,diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.details.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.details.tsxindex 908fbcc843..4896caa283 100644--- a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.details.tsx@@ -160,7 +160,6 @@ export default function QuoteLine() {description: line.description ?? "",estimatorId: line.estimatorId ?? "",itemId: line.itemId ?? "",- itemReadableId: line.itemReadableId ?? "",methodType: line.methodType ?? "Make",modelUploadId: line.modelUploadId ?? undefined,noQuoteReason: line.noQuoteReason ?? undefined,diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsxindex 8b892be900..1f6bd74ca4 100644--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx@@ -20,7 +20,9 @@ import {OpportunityLineDocuments,OpportunityLineNotes,} from "~/modules/sales/ui/Opportunity";+import { useItems } from "~/stores";import { getCustomFields, setCustomFields } from "~/utils/form";+import { getItemReadableId } from "~/utils/items";import { path } from "~/utils/path";export async function loader({ request, params }: LoaderFunctionArgs) {@@ -113,7 +115,6 @@ export default function EditSalesInvoiceLineRoute() {invoiceLineType: (salesInvoiceLine?.invoiceLineType ?? "Part") as "Part",methodType: (salesInvoiceLine?.methodType ?? "Pick") as "Pick",itemId: salesInvoiceLine?.itemId ?? "",- itemReadableId: salesInvoiceLine?.itemReadableId ?? "",accountNumber: salesInvoiceLine?.accountNumber ?? "",assetId: salesInvoiceLine?.assetId ?? "",description: salesInvoiceLine?.description ?? "",@@ -127,6 +128,8 @@ export default function EditSalesInvoiceLineRoute() {...getCustomFields(salesInvoiceLine?.customFields),};+ const [items] = useItems();+return (<Fragment key={salesInvoiceLine?.id}><SalesInvoiceLineForm@@ -137,7 +140,7 @@ export default function EditSalesInvoiceLineRoute() {id={salesInvoiceLine?.id ?? ""}table="salesInvoiceLine"title="Notes"- subTitle={salesInvoiceLine?.itemReadableId ?? ""}+ subTitle={getItemReadableId(items, salesInvoiceLine?.itemId) ?? ""}internalNotes={salesInvoiceLine?.internalNotes as JSONContent}/>diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsxindex fb773a35a2..f39a2fcdc0 100644--- a/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx@@ -157,7 +157,6 @@ export default function EditSalesOrderLineRoute() {addOnCost: line?.addOnCost ?? 0,assetId: line?.assetId ?? "",description: line?.description ?? "",- itemReadableId: line?.itemReadableId ?? "",locationId: line?.locationId ?? "",methodType: line?.methodType ?? "Make",promisedDate: line?.promisedDate ?? undefined,diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.details.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.details.tsxindex 4fbb4e9653..a5c5947921 100644--- a/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.details.tsx@@ -133,7 +133,6 @@ export default function SupplierQuoteLine() {supplierPartRevision: line.supplierPartRevision ?? "",description: line.description ?? "",itemId: line.itemId ?? "",- itemReadableId: line.itemReadableId ?? "",quantity: line.quantity ?? [1],inventoryUnitOfMeasureCode: line.inventoryUnitOfMeasureCode ?? "",purchaseUnitOfMeasureCode: line.purchaseUnitOfMeasureCode ?? "",diff --git a/apps/erp/app/utils/items.ts b/apps/erp/app/utils/items.tsnew file mode 100644index 0000000000..0fea996e59--- /dev/null+++ b/apps/erp/app/utils/items.ts@@ -0,0 +1,26 @@+import type { Item } from "~/stores/items";++/**+ * Get the readable ID for an item given its ID+ * @param items - Array of items from useItems hook+ * @param itemId - The item ID to look up+ * @returns The readable ID with revision, or undefined if not found+ */+export function getItemReadableId(+ items: Item[],+ itemId?: string | null+): string | undefined {+ if (!itemId) return undefined;+ const item = items.find((item) => item.id === itemId);+ return item?.readableIdWithRevision;+}++/**+ * Get an item by its ID+ * @param items - Array of items from useItems hook+ * @param itemId - The item ID to look up+ * @returns The item, or undefined if not found+ */+export function getItemById(items: Item[], itemId: string): Item | undefined {+ return items.find((item) => item.id === itemId);+}diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsxindex 8f6ddd479c..90c486f042 100644--- a/apps/mes/app/components/JobOperation.tsx+++ b/apps/mes/app/components/JobOperation.tsx@@ -194,6 +194,7 @@ import type {} from "~/services/inventory.service";import { getFileType } from "~/services/operations.service";import { useItems, usePeople } from "~/stores";+import { getItemReadableId } from "~/utils/items";import FileDropzone from "./FileDropzone";import ItemThumbnail from "./ItemThumbnail";import ScrapReason from "./ScrapReason";@@ -243,6 +244,7 @@ export const JobOperation = ({const navigate = useNavigate();+ const [items] = useItems();const { downloadFile, downloadModel, getFilePath } = useFiles(job);const attributeRecordModal = useDisclosure();@@ -763,7 +765,10 @@ export const JobOperation = ({><VStack spacing={0}><span className="font-semibold">- {material.itemReadableId}+ {getItemReadableId(+ items,+ material.itemId ?? ""+ )}</span><span className="text-muted-foreground text-xs">{material.description}@@ -887,9 +892,10 @@ export const JobOperation = ({><VStack spacing={0}><span className="font-semibold">- {- kittedChild.itemReadableId- }+ {getItemReadableId(+ items,+ kittedChild.itemId+ )}</span><span className="text-muted-foreground text-xs">{kittedChild.description}@@ -3302,10 +3308,14 @@ function SerialIssueModal({});}, []);+ const [items] = useItems();+return (<Modal open onOpenChange={onClose}><ModalContent>- <ModalTitle>{material?.itemReadableId}</ModalTitle>+ <ModalTitle>+ {getItemReadableId(items, material?.itemId) ?? "Material"}+ </ModalTitle><ModalDescription>{material?.description}</ModalDescription><ModalBody><Tabs value={activeTab} onValueChange={setActiveTab}>@@ -3876,11 +3886,15 @@ function BatchIssueModal({// eslint-disable-next-line react-hooks/exhaustive-deps}, [unconsumedBatch, material?.id, parentId, trackedInputs]);+ const [items] = useItems();+return (<Modal open onOpenChange={onClose}><ModalContent><ModalHeader>- <ModalTitle>{material?.itemReadableId}</ModalTitle>+ <ModalTitle>+ {getItemReadableId(items, material?.itemId) ?? "Material"}+ </ModalTitle><ModalDescription>{material?.description}</ModalDescription></ModalHeader><ModalBody>diff --git a/apps/mes/app/utils/items.ts b/apps/mes/app/utils/items.tsnew file mode 100644index 0000000000..0fea996e59--- /dev/null+++ b/apps/mes/app/utils/items.ts@@ -0,0 +1,26 @@+import type { Item } from "~/stores/items";++/**+ * Get the readable ID for an item given its ID+ * @param items - Array of items from useItems hook+ * @param itemId - The item ID to look up+ * @returns The readable ID with revision, or undefined if not found+ */+export function getItemReadableId(+ items: Item[],+ itemId?: string | null+): string | undefined {+ if (!itemId) return undefined;+ const item = items.find((item) => item.id === itemId);+ return item?.readableIdWithRevision;+}++/**+ * Get an item by its ID+ * @param items - Array of items from useItems hook+ * @param itemId - The item ID to look up+ * @returns The item, or undefined if not found+ */+export function getItemById(items: Item[], itemId: string): Item | undefined {+ return items.find((item) => item.id === itemId);+}diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 1a562d1559..357895d0f0 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -8249,7 +8249,6 @@ export type Database = {externalDocumentId: string | nullid: stringitemId: string- itemReadableId: string | nulllocationId: string | nullpostingDate: stringquantity: number@@ -8270,7 +8269,6 @@ export type Database = {externalDocumentId?: string | nullid?: stringitemId: string- itemReadableId?: string | nulllocationId?: string | nullpostingDate?: stringquantity: number@@ -8291,7 +8289,6 @@ export type Database = {externalDocumentId?: string | nullid?: stringitemId?: string- itemReadableId?: string | nulllocationId?: string | nullpostingDate?: stringquantity?: number@@ -9917,7 +9914,6 @@ export type Database = {estimatedQuantity: number | nullid: stringitemId: string- itemReadableId: stringitemType: stringjobId: stringjobMakeMethodId: string@@ -9947,7 +9943,6 @@ export type Database = {estimatedQuantity?: number | nullid?: stringitemId: string- itemReadableId: stringitemType?: stringjobId: stringjobMakeMethodId: string@@ -9977,7 +9972,6 @@ export type Database = {estimatedQuantity?: number | nullid?: stringitemId?: string- itemReadableId?: stringitemType?: stringjobId?: stringjobMakeMethodId?: string@@ -12771,7 +12765,6 @@ export type Database = {customFields: Json | nullid: stringitemId: string- itemReadableId: stringitemType: stringkit: booleanmakeMethodId: string@@ -12794,7 +12787,6 @@ export type Database = {customFields?: Json | nullid?: stringitemId: string- itemReadableId: stringitemType?: stringkit?: booleanmakeMethodId: string@@ -12817,7 +12809,6 @@ export type Database = {customFields?: Json | nullid?: stringitemId?: string- itemReadableId?: stringitemType?: stringkit?: booleanmakeMethodId?: string@@ -20146,7 +20137,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["payableLineType"]itemId: string | null- itemReadableId: string | nulljobOperationId: string | nulllocationId: string | nullmodelUploadId: string | null@@ -20186,7 +20176,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["payableLineType"]itemId?: string | null- itemReadableId?: string | nulljobOperationId?: string | nulllocationId?: string | nullmodelUploadId?: string | null@@ -20226,7 +20215,6 @@ export type Database = {invoiceId?: stringinvoiceLineType?: Database["public"]["Enums"]["payableLineType"]itemId?: string | null- itemReadableId?: string | nulljobOperationId?: string | nulllocationId?: string | nullmodelUploadId?: string | null@@ -21303,7 +21291,6 @@ export type Database = {inventoryUnitOfMeasureCode: string | nullinvoicedComplete: booleanitemId: string | null- itemReadableId: string | nulljobId: string | nulljobOperationId: string | nulllocationId: string | null@@ -21351,7 +21338,6 @@ export type Database = {inventoryUnitOfMeasureCode?: string | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulljobId?: string | nulljobOperationId?: string | nulllocationId?: string | null@@ -21399,7 +21385,6 @@ export type Database = {inventoryUnitOfMeasureCode?: string | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulljobId?: string | nulljobOperationId?: string | nulllocationId?: string | null@@ -22607,7 +22592,6 @@ export type Database = {id: stringinternalNotes: Json | nullitemId: string- itemReadableId: string | nullitemType: stringlocationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]@@ -22638,7 +22622,6 @@ export type Database = {id?: stringinternalNotes?: Json | nullitemId: string- itemReadableId?: string | nullitemType?: stringlocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]@@ -22669,7 +22652,6 @@ export type Database = {id?: stringinternalNotes?: Json | nullitemId?: string- itemReadableId?: string | nullitemType?: stringlocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]@@ -23339,7 +23321,6 @@ export type Database = {description: stringid: stringitemId: string- itemReadableId: stringitemType: stringkit: booleanmethodType: Database["public"]["Enums"]["methodType"]@@ -23365,7 +23346,6 @@ export type Database = {description: stringid?: stringitemId: string- itemReadableId: stringitemType?: stringkit?: booleanmethodType?: Database["public"]["Enums"]["methodType"]@@ -23391,7 +23371,6 @@ export type Database = {description?: stringid?: stringitemId?: string- itemReadableId?: stringitemType?: stringkit?: booleanmethodType?: Database["public"]["Enums"]["methodType"]@@ -24965,7 +24944,6 @@ export type Database = {createdBy: stringid: stringitemId: string- itemReadableId: string | nulllineId: string | nulllocationId: string | nullorderQuantity: number@@ -24987,7 +24965,6 @@ export type Database = {createdBy: stringid?: stringitemId: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity: number@@ -25009,7 +24986,6 @@ export type Database = {createdBy?: stringid?: stringitemId?: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity?: number@@ -25475,7 +25451,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["salesInvoiceLineType"]itemId: string | null- itemReadableId: string | nulllocationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]modelUploadId: string | null@@ -25512,7 +25487,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["salesInvoiceLineType"]itemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -25549,7 +25523,6 @@ export type Database = {invoiceId?: stringinvoiceLineType?: Database["public"]["Enums"]["salesInvoiceLineType"]itemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -26402,7 +26375,6 @@ export type Database = {internalNotes: Json | nullinvoicedComplete: booleanitemId: string | null- itemReadableId: string | nulllocationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]modelUploadId: string | null@@ -26445,7 +26417,6 @@ export type Database = {internalNotes?: Json | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -26488,7 +26459,6 @@ export type Database = {internalNotes?: Json | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -29040,7 +29010,6 @@ export type Database = {fulfillmentId: string | nullid: stringitemId: string- itemReadableId: string | nulllineId: string | nulllocationId: string | nullorderQuantity: number@@ -29062,7 +29031,6 @@ export type Database = {fulfillmentId?: string | nullid?: stringitemId: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity?: number@@ -29084,7 +29052,6 @@ export type Database = {fulfillmentId?: string | nullid?: stringitemId?: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity?: number@@ -31260,7 +31227,6 @@ export type Database = {internalNotes: Json | nullinventoryUnitOfMeasureCode: string | nullitemId: string- itemReadableId: string | nullpurchaseUnitOfMeasureCode: string | nullquantity: number[] | nullsupplierPartId: string | null@@ -31282,7 +31248,6 @@ export type Database = {internalNotes?: Json | nullinventoryUnitOfMeasureCode?: string | nullitemId: string- itemReadableId?: string | nullpurchaseUnitOfMeasureCode?: string | nullquantity?: number[] | nullsupplierPartId?: string | null@@ -31304,7 +31269,6 @@ export type Database = {internalNotes?: Json | nullinventoryUnitOfMeasureCode?: string | nullitemId?: string- itemReadableId?: string | nullpurchaseUnitOfMeasureCode?: string | nullquantity?: number[] | nullsupplierPartId?: string | null@@ -36777,7 +36741,6 @@ export type Database = {estimatedQuantity: number | nullid: string | nullitemId: string | null- itemReadableId: string | nullitemType: string | nulljobId: string | nulljobMakeMethodId: string | null@@ -38915,14 +38878,14 @@ export type Database = {},{foreignKeyName: "partner_id_fkey"- columns: ["id"]+ columns: ["supplierLocationId"]isOneToOne: falsereferencedRelation: "supplierLocation"referencedColumns: ["id"]},{foreignKeyName: "partner_id_fkey"- columns: ["supplierLocationId"]+ columns: ["id"]isOneToOne: falsereferencedRelation: "supplierLocation"referencedColumns: ["id"]@@ -39369,6 +39332,7 @@ export type Database = {itemId: string | nullitemName: string | nullitemReadableId: string | null+ jobOperationId: string | nulllocationId: string | nullmodelUploadId: string | nullpurchaseOrderId: string | null@@ -39394,6 +39358,27 @@ export type Database = {updatedBy: string | null}Relationships: [+ {+ foreignKeyName: "purchaseInvoiceLine_jobOperationId_fkey"+ columns: ["jobOperationId"]+ isOneToOne: false+ referencedRelation: "jobOperation"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "purchaseInvoiceLine_jobOperationId_fkey"+ columns: ["jobOperationId"]+ isOneToOne: false+ referencedRelation: "jobOperationsWithDependencies"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "purchaseInvoiceLine_jobOperationId_fkey"+ columns: ["jobOperationId"]+ isOneToOne: false+ referencedRelation: "jobOperationsWithMakeMethods"+ referencedColumns: ["id"]+ },{foreignKeyName: "purchaseInvoiceLine_modelUploadId_fkey"columns: ["modelUploadId"]@@ -39971,6 +39956,7 @@ export type Database = {modelPath: string | nullmodelSize: number | nullmodelUploadId: string | null+ promisedDate: string | nullpurchaseOrderId: string | nullpurchaseOrderLineType:| Database["public"]["Enums"]["purchaseOrderLineType"]@@ -40260,14 +40246,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -41436,7 +41422,6 @@ export type Database = {description: string | nullid: string | nullitemId: string | null- itemReadableId: string | nullitemType: string | nullkit: boolean | nullmethodType: Database["public"]["Enums"]["methodType"] | null@@ -42716,14 +42701,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["invoiceCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["invoiceCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -43259,14 +43244,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.tsindex 5825dad357..f49ea3eaf3 100644--- a/packages/database/supabase/functions/convert/index.ts+++ b/packages/database/supabase/functions/convert/index.ts@@ -333,7 +333,6 @@ serve(async (req: Request) => {purchaseOrderId: line.purchaseOrderId,purchaseOrderLineId: line.id,itemId: line.itemId,- itemReadableId: line.itemReadableId,locationId: line.locationId,shelfId: line.shelfId,accountNumber: line.accountNumber,@@ -495,7 +494,6 @@ serve(async (req: Request) => {addOnCost: selectedLines![line.id!].addOn,description: line.description,itemId: line.itemId,- itemReadableId: line.itemReadableId,locationId: line.locationId ?? quote.data.locationId,methodType: line.methodType,internalNotes: line.internalNotes,@@ -720,7 +718,6 @@ serve(async (req: Request) => {salesOrderLineId: line.id,methodType: line.methodType,itemId: line.itemId,- itemReadableId: line.itemReadableId,locationId: line.locationId,shelfId: line.shelfId,accountNumber: line.accountNumber,@@ -1016,7 +1013,6 @@ serve(async (req: Request) => {id: line.id ?? undefined,quoteId: quote.id!,itemId: line.itemId!,- itemReadableId: line.itemReadableId!,customerPartId: line.customerPartId,customerPartRevision: line.customerPartRevision,description: line.description ?? line.itemName ?? "",@@ -1277,7 +1273,6 @@ serve(async (req: Request) => {salesOrderLineId: line.id,methodType: line.methodType,itemId: line.itemId,- itemReadableId: line.itemReadableId,locationId: line.locationId,shelfId: line.shelfId,accountNumber: line.accountNumber,@@ -1448,7 +1443,6 @@ serve(async (req: Request) => {purchaseOrderLineType: line.item?.type as "Part",description: line.description,itemId: line.itemId,- itemReadableId: line.itemReadableId,locationId: employeeJob.data?.locationId,shelfId:pickMethods.data?.find(diff --git a/packages/database/supabase/functions/create/index.ts b/packages/database/supabase/functions/create/index.tsindex dec9c7b8a6..e44a1cd30a 100644--- a/packages/database/supabase/functions/create/index.ts+++ b/packages/database/supabase/functions/create/index.ts@@ -535,6 +535,7 @@ serve(async (req: Request) => {.insertInto("supplierInteraction").values({companyId,+ supplierId: supplier,}).returning(["id"]).execute();@@ -648,7 +649,6 @@ serve(async (req: Request) => {purchaseOrderId,purchaseOrderLineType: item.type,itemId: item.id,- itemReadableId: item.readableIdWithRevision,description: item.name || item.description,purchaseQuantity: operation.operationQuantity || 1,purchaseUnitOfMeasureCode: item.unitOfMeasureCode,@@ -855,7 +855,6 @@ serve(async (req: Request) => {lineId: d.id,companyId: companyId,itemId: d.itemId,- itemReadableId: d.itemReadableId,orderQuantity: d.purchaseQuantity * (d.conversionFactor ?? 1),outstandingQuantity:outstandingQuantity * (d.conversionFactor ?? 1),@@ -1278,7 +1277,6 @@ serve(async (req: Request) => {lineId: purchaseOrderLine.id,companyId: companyId,itemId: purchaseOrderLine.itemId,- itemReadableId: purchaseOrderLine.itemReadableId,orderQuantity: purchaseOrderLine.purchaseQuantity,outstandingQuantity: outstandingQuantity,shippedQuantity: outstandingQuantity ?? 0,@@ -1527,7 +1525,6 @@ serve(async (req: Request) => {companyId: companyId,fulfillmentId,itemId: salesOrderLine.itemId,- itemReadableId: salesOrderLine.itemReadableId,orderQuantity: salesOrderLine.saleQuantity,outstandingQuantity:salesOrderLine.quantityToSend ??@@ -1604,7 +1601,6 @@ serve(async (req: Request) => {lineId: salesOrderLine.id,companyId: companyId,itemId: salesOrderLine.itemId,- itemReadableId: salesOrderLine.itemReadableId,orderQuantity: salesOrderLine.saleQuantity,outstandingQuantity: outstandingQuantity,shippedQuantity: outstandingQuantity ?? 0,@@ -1815,7 +1811,6 @@ serve(async (req: Request) => {companyId: companyId,fulfillmentId,itemId: salesOrderLine.data.itemId,- itemReadableId: salesOrderLine.data.itemReadableId,orderQuantity: quantityAvailable,outstandingQuantity: quantityAvailable,shippedQuantity: quantityAvailable,@@ -1890,7 +1885,6 @@ serve(async (req: Request) => {lineId: salesOrderLineId,companyId: companyId,itemId: salesOrderLine.data.itemId!,- itemReadableId: salesOrderLine.data.itemReadableId,orderQuantity: salesOrderLine.data.saleQuantity ?? 0,outstandingQuantity: outstandingQuantity!,shippedQuantity: outstandingQuantity!,diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.tsindex 25bb22c5a6..2ebd2b5136 100644--- a/packages/database/supabase/functions/get-method/index.ts+++ b/packages/database/supabase/functions/get-method/index.ts@@ -691,7 +691,6 @@ serve(async (req: Request) => {}),]);- let itemReadableId = child.data.itemReadableId;let itemType = child.data.itemType;let unitCost = child.data.unitCost;let requiresSerialTracking =@@ -709,8 +708,6 @@ serve(async (req: Request) => {.eq("companyId", companyId).single();if (item.data) {- itemReadableId =- item.data.readableIdWithRevision ?? item.data.readableId;itemType = item.data.type;unitCost =item.data.itemCost[0]?.unitCost ?? child.data.unitCost;@@ -732,7 +729,6 @@ serve(async (req: Request) => {jobOperationId:methodOperationsToJobOperations[child.data.operationId],itemId,- itemReadableId,itemType,kit: child.data.kit,methodType,@@ -768,8 +764,7 @@ serve(async (req: Request) => {materialsWithConfiguredFields = bomConfiguration.map((readableIdWithRevision, index) => {const material = materialsWithConfiguredFields.find(- (material) =>- material.itemReadableId === readableIdWithRevision+ (material) => material.itemId === itemId);if (material) {return {@@ -792,7 +787,7 @@ serve(async (req: Request) => {const madeChildren = madeMaterials.map((material, index) => {const childIndex = materialsWithConfiguredFields.findIndex(- (m) => m.itemReadableId === material.itemReadableId+ (m) => m.itemId === material.itemId);return node.children[childIndex];});@@ -1061,7 +1056,6 @@ serve(async (req: Request) => {methodOperationsToJobOperations[child.data.operationId],itemId: child.data.itemId,kit: child.data.kit,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,methodType: child.data.methodType,order: child.data.order,@@ -1565,7 +1559,6 @@ serve(async (req: Request) => {}),]);- let itemReadableId = child.data.itemReadableId;let itemType = child.data.itemType;let unitCost = child.data.unitCost;@@ -1581,8 +1574,6 @@ serve(async (req: Request) => {.eq("companyId", companyId).single();if (item.data) {- itemReadableId =- item.data.readableIdWithRevision ?? item.data.readableId;itemType = item.data.type;unitCost =item.data.itemCost[0]?.unitCost ?? child.data.unitCost;@@ -1602,7 +1593,6 @@ serve(async (req: Request) => {methodOperationsToQuoteOperations[child.data.operationId],order: child.data.order,itemId,- itemReadableId,itemType,kit: child.data.kit,methodType,@@ -1635,8 +1625,7 @@ serve(async (req: Request) => {materialsWithConfiguredFields = bomConfiguration.map((readableIdWithRevision, index) => {const material = materialsWithConfiguredFields.find(- (material) =>- material.itemReadableId === readableIdWithRevision+ (material) => material.itemId === itemId);if (material) {return {@@ -1659,7 +1648,7 @@ serve(async (req: Request) => {const madeChildren = madeMaterials.map((material, index) => {const childIndex = materialsWithConfiguredFields.findIndex(- (m) => m.itemReadableId === material.itemReadableId+ (m) => m.itemId === material.itemId);return node.children[childIndex];});@@ -1924,7 +1913,6 @@ serve(async (req: Request) => {quoteOperationId:methodOperationsToQuoteOperations[child.data.operationId],itemId: child.data.itemId,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,kit: child.data.kit,methodType: child.data.methodType,@@ -2089,7 +2077,6 @@ serve(async (req: Request) => {makeMethodId: makeMethodByItemId[node.data.itemId],materialMakeMethodId: makeMethodByItemId[child.data.itemId],itemId: child.data.itemId,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,kit: child.data.kit,methodType: child.data.methodType,@@ -2357,7 +2344,6 @@ serve(async (req: Request) => {makeMethodId: makeMethodByItemId[node.data.itemId],materialMakeMethodId: makeMethodByItemId[child.data.itemId],itemId: child.data.itemId,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,kit: child.data.kit,methodType: child.data.methodType,@@ -2926,7 +2912,6 @@ serve(async (req: Request) => {makeMethodId: makeMethodByItemId[node.data.itemId],materialMakeMethodId: makeMethodByItemId[child.data.itemId],itemId: child.data.itemId,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,kit: child.data.kit,methodType: child.data.methodType,@@ -3206,7 +3191,6 @@ serve(async (req: Request) => {materialMakeMethodId: makeMethodByItemId[child.data.itemId],itemId: child.data.itemId,kit: child.data.kit,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,methodType: child.data.methodType,order: child.data.order,@@ -3431,6 +3415,16 @@ serve(async (req: Request) => {quoteMaterials.error ||quoteOperations.error) {+ if (quoteMakeMethod.error) {+ console.log("quoteMakeMethodError");+ console.log(quoteMakeMethod.error);+ }+ if (quoteMaterials.error) {+ console.log(quoteMaterials.error);+ }+ if (quoteOperations.error) {+ console.log(quoteOperations.error);+ }throw new Error("Failed to fetch quote data");}@@ -3481,7 +3475,6 @@ serve(async (req: Request) => {id: newMaterialId,jobId,itemId: child.data.itemId,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,kit: child.data.kit,methodType: child.data.methodType,@@ -3772,7 +3765,6 @@ serve(async (req: Request) => {quoteLineId: targetQuoteLineId,itemId: child.data.itemId,kit: child.data.kit,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,methodType: child.data.methodType,order: child.data.order,@@ -4042,6 +4034,7 @@ serve(async (req: Request) => {.insertInto("opportunity").values({companyId,+ customerId: sourceQuote.data?.customerId,}).returning(["id"]).executeTakeFirstOrThrow();@@ -4248,7 +4241,6 @@ serve(async (req: Request) => {quoteLineId: newLineId,itemId: child.data.itemId,kit: child.data.kit,- itemReadableId: child.data.itemReadableId,itemType: child.data.itemType,methodType: child.data.methodType,order: child.data.order,diff --git a/packages/database/supabase/functions/issue/index.ts b/packages/database/supabase/functions/issue/index.tsindex b5f01fd607..4565a8200e 100644--- a/packages/database/supabase/functions/issue/index.ts+++ b/packages/database/supabase/functions/issue/index.ts@@ -189,7 +189,6 @@ serve(async (req: Request) => {documentId: jobId,companyId,itemId: job?.itemId!,- itemReadableId: item?.readableIdWithRevision,quantity: quantityReceivedToInventory,locationId,shelfId,@@ -215,7 +214,6 @@ serve(async (req: Request) => {documentId: jobId,companyId,itemId: job?.itemId!,- itemReadableId: item?.readableIdWithRevision,quantity: 1,locationId,shelfId,@@ -242,7 +240,6 @@ serve(async (req: Request) => {documentId: jobId,companyId,itemId: job?.itemId!,- itemReadableId: item?.readableIdWithRevision,quantity: quantityReceivedToInventory,locationId,shelfId,@@ -365,7 +362,6 @@ serve(async (req: Request) => {documentLineId: id,companyId,itemId: material.itemId,- itemReadableId: material.itemReadableId,quantity: -Number(material.quantityToIssue),locationId: job?.locationId,shelfId: material.defaultShelf@@ -783,7 +779,6 @@ serve(async (req: Request) => {description: item?.name,estimatedQuantity: 0,itemId: itemId!,- itemReadableId: item?.readableIdWithRevision,itemType: item?.type,jobId: jobOperation?.jobId!,jobMakeMethodId: jobOperation?.jobMakeMethodId,@@ -857,6 +852,13 @@ serve(async (req: Request) => {.selectAll().executeTakeFirst();+ // Get item details+ const item = await trx+ .selectFrom("item")+ .where("id", "=", jobMaterial?.itemId!)+ .select(["readableIdWithRevision"])+ .executeTakeFirst();+// Get job locationconst job = await trx.selectFrom("job")@@ -890,7 +892,7 @@ serve(async (req: Request) => {type: "Consume",sourceDocument: "Job Material",sourceDocumentId: materialId,- sourceDocumentReadableId: jobMaterial?.itemReadableId,+ sourceDocumentReadableId: item?.readableIdWithRevision ?? "",attributes: {Job: job?.id!,"Job Make Method": jobMaterial?.jobMakeMethodId!,@@ -1039,7 +1041,6 @@ serve(async (req: Request) => {documentId: splitActivityId,companyId,itemId: trackedEntity.sourceDocumentId,- itemReadableId: trackedEntity.sourceDocumentReadableId,quantity: -Number(trackedEntity.quantity),locationId: job?.locationId,shelfId: itemLedgers.find(@@ -1055,7 +1056,6 @@ serve(async (req: Request) => {documentId: splitActivityId,companyId,itemId: trackedEntity.sourceDocumentId,- itemReadableId: trackedEntity.sourceDocumentReadableId,quantity: quantity,locationId: job?.locationId,shelfId: itemLedgers.find(@@ -1071,7 +1071,6 @@ serve(async (req: Request) => {documentId: splitActivityId,companyId,itemId: trackedEntity.sourceDocumentId,- itemReadableId: trackedEntity.sourceDocumentReadableId,quantity: remainingQuantity,locationId: job?.locationId,shelfId: itemLedgers.find(@@ -1109,7 +1108,6 @@ serve(async (req: Request) => {documentId: job?.id!,companyId,itemId: trackedEntity.sourceDocumentId,- itemReadableId: trackedEntity.sourceDocumentReadableId,quantity: -quantity,locationId: job?.locationId,shelfId: itemLedgers.find(@@ -1212,6 +1210,13 @@ serve(async (req: Request) => {.selectAll().executeTakeFirst();+ // Get item details+ const item = await trx+ .selectFrom("item")+ .where("id", "=", jobMaterial?.itemId!)+ .select(["readableIdWithRevision"])+ .executeTakeFirst();+// Get job locationconst job = await trx.selectFrom("job")@@ -1245,7 +1250,7 @@ serve(async (req: Request) => {type: "Unconsume",sourceDocument: "Job Material",sourceDocumentId: materialId,- sourceDocumentReadableId: jobMaterial?.itemReadableId,+ sourceDocumentReadableId: item?.readableIdWithRevision ?? "",attributes: {Job: job?.id!,"Job Make Method": jobMaterial?.jobMakeMethodId!,@@ -1306,7 +1311,6 @@ serve(async (req: Request) => {documentId: job?.id!,companyId,itemId: trackedEntity.sourceDocumentId,- itemReadableId: trackedEntity.sourceDocumentReadableId,quantity: quantity,locationId: job?.locationId,shelfId: itemLedgers.find(diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 1a562d1559..357895d0f0 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -8249,7 +8249,6 @@ export type Database = {externalDocumentId: string | nullid: stringitemId: string- itemReadableId: string | nulllocationId: string | nullpostingDate: stringquantity: number@@ -8270,7 +8269,6 @@ export type Database = {externalDocumentId?: string | nullid?: stringitemId: string- itemReadableId?: string | nulllocationId?: string | nullpostingDate?: stringquantity: number@@ -8291,7 +8289,6 @@ export type Database = {externalDocumentId?: string | nullid?: stringitemId?: string- itemReadableId?: string | nulllocationId?: string | nullpostingDate?: stringquantity?: number@@ -9917,7 +9914,6 @@ export type Database = {estimatedQuantity: number | nullid: stringitemId: string- itemReadableId: stringitemType: stringjobId: stringjobMakeMethodId: string@@ -9947,7 +9943,6 @@ export type Database = {estimatedQuantity?: number | nullid?: stringitemId: string- itemReadableId: stringitemType?: stringjobId: stringjobMakeMethodId: string@@ -9977,7 +9972,6 @@ export type Database = {estimatedQuantity?: number | nullid?: stringitemId?: string- itemReadableId?: stringitemType?: stringjobId?: stringjobMakeMethodId?: string@@ -12771,7 +12765,6 @@ export type Database = {customFields: Json | nullid: stringitemId: string- itemReadableId: stringitemType: stringkit: booleanmakeMethodId: string@@ -12794,7 +12787,6 @@ export type Database = {customFields?: Json | nullid?: stringitemId: string- itemReadableId: stringitemType?: stringkit?: booleanmakeMethodId: string@@ -12817,7 +12809,6 @@ export type Database = {customFields?: Json | nullid?: stringitemId?: string- itemReadableId?: stringitemType?: stringkit?: booleanmakeMethodId?: string@@ -20146,7 +20137,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["payableLineType"]itemId: string | null- itemReadableId: string | nulljobOperationId: string | nulllocationId: string | nullmodelUploadId: string | null@@ -20186,7 +20176,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["payableLineType"]itemId?: string | null- itemReadableId?: string | nulljobOperationId?: string | nulllocationId?: string | nullmodelUploadId?: string | null@@ -20226,7 +20215,6 @@ export type Database = {invoiceId?: stringinvoiceLineType?: Database["public"]["Enums"]["payableLineType"]itemId?: string | null- itemReadableId?: string | nulljobOperationId?: string | nulllocationId?: string | nullmodelUploadId?: string | null@@ -21303,7 +21291,6 @@ export type Database = {inventoryUnitOfMeasureCode: string | nullinvoicedComplete: booleanitemId: string | null- itemReadableId: string | nulljobId: string | nulljobOperationId: string | nulllocationId: string | null@@ -21351,7 +21338,6 @@ export type Database = {inventoryUnitOfMeasureCode?: string | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulljobId?: string | nulljobOperationId?: string | nulllocationId?: string | null@@ -21399,7 +21385,6 @@ export type Database = {inventoryUnitOfMeasureCode?: string | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulljobId?: string | nulljobOperationId?: string | nulllocationId?: string | null@@ -22607,7 +22592,6 @@ export type Database = {id: stringinternalNotes: Json | nullitemId: string- itemReadableId: string | nullitemType: stringlocationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]@@ -22638,7 +22622,6 @@ export type Database = {id?: stringinternalNotes?: Json | nullitemId: string- itemReadableId?: string | nullitemType?: stringlocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]@@ -22669,7 +22652,6 @@ export type Database = {id?: stringinternalNotes?: Json | nullitemId?: string- itemReadableId?: string | nullitemType?: stringlocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]@@ -23339,7 +23321,6 @@ export type Database = {description: stringid: stringitemId: string- itemReadableId: stringitemType: stringkit: booleanmethodType: Database["public"]["Enums"]["methodType"]@@ -23365,7 +23346,6 @@ export type Database = {description: stringid?: stringitemId: string- itemReadableId: stringitemType?: stringkit?: booleanmethodType?: Database["public"]["Enums"]["methodType"]@@ -23391,7 +23371,6 @@ export type Database = {description?: stringid?: stringitemId?: string- itemReadableId?: stringitemType?: stringkit?: booleanmethodType?: Database["public"]["Enums"]["methodType"]@@ -24965,7 +24944,6 @@ export type Database = {createdBy: stringid: stringitemId: string- itemReadableId: string | nulllineId: string | nulllocationId: string | nullorderQuantity: number@@ -24987,7 +24965,6 @@ export type Database = {createdBy: stringid?: stringitemId: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity: number@@ -25009,7 +24986,6 @@ export type Database = {createdBy?: stringid?: stringitemId?: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity?: number@@ -25475,7 +25451,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["salesInvoiceLineType"]itemId: string | null- itemReadableId: string | nulllocationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]modelUploadId: string | null@@ -25512,7 +25487,6 @@ export type Database = {invoiceId: stringinvoiceLineType: Database["public"]["Enums"]["salesInvoiceLineType"]itemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -25549,7 +25523,6 @@ export type Database = {invoiceId?: stringinvoiceLineType?: Database["public"]["Enums"]["salesInvoiceLineType"]itemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -26402,7 +26375,6 @@ export type Database = {internalNotes: Json | nullinvoicedComplete: booleanitemId: string | null- itemReadableId: string | nulllocationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]modelUploadId: string | null@@ -26445,7 +26417,6 @@ export type Database = {internalNotes?: Json | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -26488,7 +26459,6 @@ export type Database = {internalNotes?: Json | nullinvoicedComplete?: booleanitemId?: string | null- itemReadableId?: string | nulllocationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | null@@ -29040,7 +29010,6 @@ export type Database = {fulfillmentId: string | nullid: stringitemId: string- itemReadableId: string | nulllineId: string | nulllocationId: string | nullorderQuantity: number@@ -29062,7 +29031,6 @@ export type Database = {fulfillmentId?: string | nullid?: stringitemId: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity?: number@@ -29084,7 +29052,6 @@ export type Database = {fulfillmentId?: string | nullid?: stringitemId?: string- itemReadableId?: string | nulllineId?: string | nulllocationId?: string | nullorderQuantity?: number@@ -31260,7 +31227,6 @@ export type Database = {internalNotes: Json | nullinventoryUnitOfMeasureCode: string | nullitemId: string- itemReadableId: string | nullpurchaseUnitOfMeasureCode: string | nullquantity: number[] | nullsupplierPartId: string | null@@ -31282,7 +31248,6 @@ export type Database = {internalNotes?: Json | nullinventoryUnitOfMeasureCode?: string | nullitemId: string- itemReadableId?: string | nullpurchaseUnitOfMeasureCode?: string | nullquantity?: number[] | nullsupplierPartId?: string | null@@ -31304,7 +31269,6 @@ export type Database = {internalNotes?: Json | nullinventoryUnitOfMeasureCode?: string | nullitemId?: string- itemReadableId?: string | nullpurchaseUnitOfMeasureCode?: string | nullquantity?: number[] | nullsupplierPartId?: string | null@@ -36777,7 +36741,6 @@ export type Database = {estimatedQuantity: number | nullid: string | nullitemId: string | null- itemReadableId: string | nullitemType: string | nulljobId: string | nulljobMakeMethodId: string | null@@ -38915,14 +38878,14 @@ export type Database = {},{foreignKeyName: "partner_id_fkey"- columns: ["id"]+ columns: ["supplierLocationId"]isOneToOne: falsereferencedRelation: "supplierLocation"referencedColumns: ["id"]},{foreignKeyName: "partner_id_fkey"- columns: ["supplierLocationId"]+ columns: ["id"]isOneToOne: falsereferencedRelation: "supplierLocation"referencedColumns: ["id"]@@ -39369,6 +39332,7 @@ export type Database = {itemId: string | nullitemName: string | nullitemReadableId: string | null+ jobOperationId: string | nulllocationId: string | nullmodelUploadId: string | nullpurchaseOrderId: string | null@@ -39394,6 +39358,27 @@ export type Database = {updatedBy: string | null}Relationships: [+ {+ foreignKeyName: "purchaseInvoiceLine_jobOperationId_fkey"+ columns: ["jobOperationId"]+ isOneToOne: false+ referencedRelation: "jobOperation"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "purchaseInvoiceLine_jobOperationId_fkey"+ columns: ["jobOperationId"]+ isOneToOne: false+ referencedRelation: "jobOperationsWithDependencies"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "purchaseInvoiceLine_jobOperationId_fkey"+ columns: ["jobOperationId"]+ isOneToOne: false+ referencedRelation: "jobOperationsWithMakeMethods"+ referencedColumns: ["id"]+ },{foreignKeyName: "purchaseInvoiceLine_modelUploadId_fkey"columns: ["modelUploadId"]@@ -39971,6 +39956,7 @@ export type Database = {modelPath: string | nullmodelSize: number | nullmodelUploadId: string | null+ promisedDate: string | nullpurchaseOrderId: string | nullpurchaseOrderLineType:| Database["public"]["Enums"]["purchaseOrderLineType"]@@ -40260,14 +40246,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -41436,7 +41422,6 @@ export type Database = {description: string | nullid: string | nullitemId: string | null- itemReadableId: string | nullitemType: string | nullkit: boolean | nullmethodType: Database["public"]["Enums"]["methodType"] | null@@ -42716,14 +42701,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["invoiceCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["invoiceCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -43259,14 +43244,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]diff --git a/packages/database/supabase/functions/mcp/tools.ee.ts b/packages/database/supabase/functions/mcp/tools.ee.tsindex cec9e147d2..5b72cfbc44 100644--- a/packages/database/supabase/functions/mcp/tools.ee.ts+++ b/packages/database/supabase/functions/mcp/tools.ee.ts@@ -204,7 +204,6 @@ const createPurchaseOrder = tool({.values({purchaseOrderId: purchaseOrderId,itemId: part.partId,- itemReadableId: item.readableIdWithRevision,description: item.name,purchaseOrderLineType: item.type,purchaseQuantity: part.quantity,diff --git a/packages/database/supabase/functions/post-purchase-invoice/index.ts b/packages/database/supabase/functions/post-purchase-invoice/index.tsindex ada19b449a..b492cec79c 100644--- a/packages/database/supabase/functions/post-purchase-invoice/index.ts+++ b/packages/database/supabase/functions/post-purchase-invoice/index.ts@@ -405,7 +405,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: invoiceLine.itemId!,- itemReadableId: invoiceLine.itemReadableId!,quantity: invoiceLineQuantityInInventoryUnit,locationId: invoiceLine.locationId,shelfId: invoiceLine.shelfId,diff --git a/packages/database/supabase/functions/post-receipt/index.ts b/packages/database/supabase/functions/post-receipt/index.tsindex b5ebc4d12b..127f2e3e13 100644--- a/packages/database/supabase/functions/post-receipt/index.ts+++ b/packages/database/supabase/functions/post-receipt/index.ts@@ -753,7 +753,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: receiptLine.itemId,- itemReadableId: receiptLine.itemReadableId ?? "",quantity: receivedQuantity,locationId: receiptLine.locationId,shelfId: receiptLine.shelfId,@@ -773,7 +772,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: receiptLine.itemId,- itemReadableId: receiptLine.itemReadableId ?? "",quantity: receivedQuantity,locationId: receiptLine.locationId,shelfId: receiptLine.shelfId,@@ -818,7 +816,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: receiptLine.itemId,- itemReadableId: receiptLine.itemReadableId ?? "",quantity: quantityPerEntry,locationId: receiptLine.locationId,shelfId: receiptLine.shelfId,diff --git a/packages/database/supabase/functions/post-sales-invoice/index.ts b/packages/database/supabase/functions/post-sales-invoice/index.tsindex 92cecb164d..4aad930891 100644--- a/packages/database/supabase/functions/post-sales-invoice/index.ts+++ b/packages/database/supabase/functions/post-sales-invoice/index.ts@@ -340,7 +340,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: invoiceLine.itemId!,- itemReadableId: invoiceLine.itemReadableId!,quantity: -invoiceLineQuantityInInventoryUnit,locationId: invoiceLine.locationId,shelfId: invoiceLine.shelfId,diff --git a/packages/database/supabase/functions/post-shipment/index.ts b/packages/database/supabase/functions/post-shipment/index.tsindex 72fb5408a9..c4edf07a77 100644--- a/packages/database/supabase/functions/post-shipment/index.ts+++ b/packages/database/supabase/functions/post-shipment/index.ts@@ -260,7 +260,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: shipmentLine.itemId,- itemReadableId: shipmentLine.itemReadableId ?? "",quantity: -shippedQuantity,locationId: shipmentLine.locationId ?? locationId,shelfId: shipmentLine.shelfId,@@ -277,7 +276,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: shipmentLine.itemId,- itemReadableId: shipmentLine.itemReadableId ?? "",quantity: -shippedQuantity,locationId: shipmentLine.locationId ?? locationId,shelfId: shipmentLine.shelfId,@@ -308,7 +306,6 @@ serve(async (req: Request) => {itemLedgerInserts.push({postingDate: today,itemId: shipmentLine.itemId,- itemReadableId: shipmentLine.itemReadableId ?? "",quantity: -1,locationId: shipmentLine.locationId ?? locationId,shelfId: shipmentLine.shelfId,@@ -657,14 +654,6 @@ serve(async (req: Request) => {"Shipment Line"])?.itemId!,- itemReadableId:- shipmentLines.data.find(- (sl) =>- sl.id ===- (splitInfo.attributes as TrackedEntityAttributes)?.[- "Shipment Line"- ]- )?.itemReadableId ?? "",quantity: -splitInfo.originalQuantity,locationId: locationId,shelfId: shipmentLines.data.find(@@ -691,14 +680,6 @@ serve(async (req: Request) => {"Shipment Line"])?.itemId!,- itemReadableId:- shipmentLines.data.find(- (sl) =>- sl.id ===- (splitInfo.attributes as TrackedEntityAttributes)?.[- "Shipment Line"- ]- )?.itemReadableId ?? "",quantity: splitInfo.shippedQuantity,locationId: locationId,shelfId: shipmentLines.data.find(@@ -725,14 +706,6 @@ serve(async (req: Request) => {"Shipment Line"])?.itemId!,- itemReadableId:- shipmentLines.data.find(- (sl) =>- sl.id ===- (splitInfo.attributes as TrackedEntityAttributes)?.[- "Shipment Line"- ]- )?.itemReadableId ?? "",quantity: splitInfo.remainingQuantity,locationId: locationId,shelfId: shipmentLines.data.find(diff --git a/packages/database/supabase/functions/sync/index.ts b/packages/database/supabase/functions/sync/index.tsindex 177c5e7a66..4de2918863 100644--- a/packages/database/supabase/functions/sync/index.ts+++ b/packages/database/supabase/functions/sync/index.ts@@ -313,9 +313,6 @@ serve(async (req: Request) => {materialMakeMethodId,methodType: defaultMethodType,order: index,- itemReadableId:- existingItemsByItemId.get(itemId)?.readableIdWithRevision ??- partId,itemType: existingItemsByItemId.get(itemId)?.type ?? "Part",unitOfMeasureCode:existingItemsByItemId.get(itemId)?.unitOfMeasureCode ?? "EA",diff --git a/packages/database/supabase/migrations/20250723000000_remove-itemreadableid-columns.sql b/packages/database/supabase/migrations/20250723000000_remove-itemreadableid-columns.sqlnew file mode 100644index 0000000000..a913a7239b--- /dev/null+++ b/packages/database/supabase/migrations/20250723000000_remove-itemreadableid-columns.sql@@ -0,0 +1,323 @@+DROP VIEW IF EXISTS "jobMaterialWithMakeMethodId";+DROP VIEW IF EXISTS "purchaseInvoiceLines";+DROP VIEW IF EXISTS "purchaseOrderLines";+DROP VIEW IF EXISTS "quoteLines";+DROP VIEW IF EXISTS "quoteLinePrices";+DROP VIEW IF EXISTS "quoteMaterialWithMakeMethodId";+DROP VIEW IF EXISTS "receiptLines";+DROP VIEW IF EXISTS "salesInvoices";+DROP VIEW IF EXISTS "salesInvoiceLines";+DROP VIEW IF EXISTS "salesOrderLines";+DROP VIEW IF EXISTS "shipmentLines";+DROP VIEW IF EXISTS "supplierQuoteLines";+++-- Remove stored itemReadableId columns from all tables+-- These will be replaced with lookups from the item table or calculated fields in views++-- costLedger+ALTER TABLE "costLedger" DROP COLUMN IF EXISTS "itemReadableId";++-- itemLedger+ALTER TABLE "itemLedger" DROP COLUMN IF EXISTS "itemReadableId";++-- jobMaterial+ALTER TABLE "jobMaterial" DROP COLUMN IF EXISTS "itemReadableId";++-- methodMaterial+ALTER TABLE "methodMaterial" DROP COLUMN IF EXISTS "itemReadableId";++-- purchaseInvoiceLine+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "itemReadableId";++-- purchaseOrderLine+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "itemReadableId";++-- quoteLine+ALTER TABLE "quoteLine" DROP COLUMN IF EXISTS "itemReadableId";++-- quoteMaterial+ALTER TABLE "quoteMaterial" DROP COLUMN IF EXISTS "itemReadableId";++-- receiptLine+ALTER TABLE "receiptLine" DROP COLUMN IF EXISTS "itemReadableId";++-- salesInvoiceLine+ALTER TABLE "salesInvoiceLine" DROP COLUMN IF EXISTS "itemReadableId";++-- salesOrderLine+ALTER TABLE "salesOrderLine" DROP COLUMN IF EXISTS "itemReadableId";++-- shipmentLine+ALTER TABLE "shipmentLine" DROP COLUMN IF EXISTS "itemReadableId";++-- supplierQuoteLine+ALTER TABLE "supplierQuoteLine" DROP COLUMN IF EXISTS "itemReadableId";++DROP VIEW IF EXISTS "jobMaterialWithMakeMethodId";+CREATE OR REPLACE VIEW "jobMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true) AS+ SELECT+ jm.*,+ jmm."id" AS "jobMaterialMakeMethodId",+ jmm.version AS "version",+ i."readableIdWithRevision" as "itemReadableId"+ FROM "jobMaterial" jm+ LEFT JOIN "jobMakeMethod" jmm+ ON jmm."parentMaterialId" = jm."id"+ INNER JOIN "item" i ON i.id = jm."itemId";++DROP VIEW IF EXISTS "purchaseInvoiceLines";+CREATE OR REPLACE VIEW "purchaseInvoiceLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ pl.*,+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ i."readableIdWithRevision" as "itemReadableId",+ i.name as "itemName",+ i.description as "itemDescription",+ ic."unitCost" as "unitCost",+ sp."supplierPartId"+ FROM "purchaseInvoiceLine" pl+ INNER JOIN "purchaseInvoice" pi ON pi.id = pl."invoiceId"+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = pl."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = pi."supplierId" AND sp."itemId" = i.id+);++DROP VIEW IF EXISTS "purchaseOrderLines";+CREATE OR REPLACE VIEW "purchaseOrderLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT DISTINCT ON (pl.id)+ pl.*,+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ i.name as "itemName",+ i."readableIdWithRevision" as "itemReadableId",+ i.description as "itemDescription",+ COALESCE(mu.id, imu.id) as "modelId",+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",+ COALESCE(mu."name", imu."name") as "modelName",+ COALESCE(mu."size", imu."size") as "modelSize",+ ic."unitCost" as "unitCost",+ sp."supplierPartId"+ FROM "purchaseOrderLine" pl+ INNER JOIN "purchaseOrder" so ON so.id = pl."purchaseOrderId"+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = pl."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = so."supplierId" AND sp."itemId" = i.id+);++DROP VIEW IF EXISTS "quoteLines";+CREATE OR REPLACE VIEW "quoteLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ ql.*,+ i."readableIdWithRevision" as "itemReadableId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ COALESCE(mu.id, imu.id) as "modelId",+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",+ COALESCE(mu."name", imu."name") as "modelName",+ COALESCE(mu."size", imu."size") as "modelSize",+ ic."unitCost" as "unitCost"+ FROM "quoteLine" ql+ LEFT JOIN "modelUpload" mu ON ql."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = ql."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+);++DROP VIEW IF EXISTS "quoteLinePrices";+CREATE OR REPLACE VIEW "quoteLinePrices" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ ql.*,+ i."readableIdWithRevision" as "itemReadableId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ COALESCE(mu.id, imu.id) as "modelId",+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",+ COALESCE(mu."name", imu."name") as "modelName",+ COALESCE(mu."size", imu."size") as "modelSize",+ ic."unitCost" as "unitCost",+ qlp."quantity" as "qty",+ qlp."unitPrice",+ CASE+ WHEN q."revisionId" > 0 THEN q."quoteId" || '-' || q."revisionId"::text+ ELSE q."quoteId"+ END as "quoteReadableId",+ q."createdAt" as "quoteCreatedAt",+ q."customerId"+ FROM "quoteLine" ql+ INNER JOIN "quote" q ON q.id = ql."quoteId"+ LEFT JOIN "modelUpload" mu ON ql."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = ql."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+ LEFT JOIN "quoteLinePrice" qlp ON qlp."quoteLineId" = ql.id+);++DROP VIEW IF EXISTS "quoteMaterialWithMakeMethodId";+CREATE OR REPLACE VIEW "quoteMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true) AS+ SELECT+ qm.*,+ qmm."id" AS "quoteMaterialMakeMethodId",+ qmm.version AS "version"+ FROM "quoteMaterial" qm+ LEFT JOIN "quoteMakeMethod" qmm+ ON qmm."parentMaterialId" = qm."id";++DROP VIEW IF EXISTS "receiptLines";+CREATE OR REPLACE VIEW "receiptLines" WITH(SECURITY_INVOKER=true) AS+ SELECT+ rl.*,+ i."readableIdWithRevision" as "itemReadableId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ ELSE i."thumbnailPath"+ END AS "thumbnailPath",+ i."name" as "description"+ FROM "receiptLine" rl+ INNER JOIN "item" i ON i."id" = rl."itemId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId";+++DROP VIEW IF EXISTS "salesInvoices";+CREATE OR REPLACE VIEW "salesInvoices" WITH(SECURITY_INVOKER=true) AS+ SELECT+ si.*,+ sil."thumbnailPath",+ sil."itemType",+ sil."invoiceTotal" + COALESCE(ss."shippingCost", 0) AS "invoiceTotal",+ sil."lines"+ FROM "salesInvoice" si+ LEFT JOIN (+ SELECT+ sil."invoiceId",+ MIN(CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ ELSE i."thumbnailPath"+ END) AS "thumbnailPath",+ SUM(+ DISTINCT (1+COALESCE(sil."taxPercent", 0))*(COALESCE(sil."quantity", 0)*(COALESCE(sil."unitPrice", 0)) + COALESCE(sil."shippingCost", 0) + COALESCE(sil."addOnCost", 0))+ ) AS "invoiceTotal",+ SUM(COALESCE(sil."shippingCost", 0)) AS "shippingCost",+ MIN(i."type") AS "itemType",+ ARRAY_AGG(+ json_build_object(+ 'id', sil.id,+ 'invoiceLineType', sil."invoiceLineType",+ 'quantity', sil."quantity",+ 'unitPrice', sil."unitPrice",+ 'itemId', sil."itemId"+ )+ ) AS "lines"+ FROM "salesInvoiceLine" sil+ LEFT JOIN "item" i+ ON i."id" = sil."itemId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"+ GROUP BY sil."invoiceId"+ ) sil ON sil."invoiceId" = si."id"+ JOIN "salesInvoiceShipment" ss ON ss."id" = si."id";+++DROP VIEW IF EXISTS "salesInvoiceLines";+CREATE OR REPLACE VIEW "salesInvoiceLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ sl.*,+ i."readableIdWithRevision" as "itemReadableId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ i.name as "itemName",+ i.description as "itemDescription",+ ic."unitCost" as "unitCost",+ (SELECT cp."customerPartId"+ FROM "customerPartToItem" cp+ WHERE cp."customerId" = si."customerId" AND cp."itemId" = i.id+ LIMIT 1) as "customerPartId"+ FROM "salesInvoiceLine" sl+ INNER JOIN "salesInvoice" si ON si.id = sl."invoiceId"+ LEFT JOIN "modelUpload" mu ON sl."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = sl."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+);+++DROP VIEW IF EXISTS "salesOrderLines";+CREATE OR REPLACE VIEW "salesOrderLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ sl.*,+ i."readableIdWithRevision" as "itemReadableId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ COALESCE(mu.id, imu.id) as "modelId",+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",+ COALESCE(mu."name", imu."name") as "modelName",+ COALESCE(mu."size", imu."size") as "modelSize",+ ic."unitCost" as "unitCost",+ cp."customerPartId",+ cp."customerPartRevision",+ so."orderDate",+ so."customerId",+ so."salesOrderId" as "salesOrderReadableId"+ FROM "salesOrderLine" sl+ INNER JOIN "salesOrder" so ON so.id = sl."salesOrderId"+ LEFT JOIN "modelUpload" mu ON sl."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = sl."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+ LEFT JOIN "customerPartToItem" cp ON cp."customerId" = so."customerId" AND cp."itemId" = i.id+);+++DROP VIEW IF EXISTS "shipmentLines";+CREATE OR REPLACE VIEW "shipmentLines" WITH(SECURITY_INVOKER=true) AS+ SELECT+ sl.*,+ i."readableIdWithRevision" as "itemReadableId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ ELSE i."thumbnailPath"+ END AS "thumbnailPath",+ i."name" as "description"+ FROM "shipmentLine" sl+ INNER JOIN "item" i ON i."id" = sl."itemId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId";++DROP VIEW IF EXISTS "supplierQuoteLines";+CREATE OR REPLACE VIEW "supplierQuoteLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ ql.*,+ i."readableIdWithRevision" as "itemReadableId",+ i."type" as "itemType",+ COALESCE(i."thumbnailPath", mu."thumbnailPath") as "thumbnailPath",+ ic."unitCost" as "unitCost"+ FROM "supplierQuoteLine" ql+ INNER JOIN "item" i ON i.id = ql."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"+);\ No newline at end of filediff --git a/packages/documents/src/pdf/PackingSlipPDF.tsx b/packages/documents/src/pdf/PackingSlipPDF.tsxindex 25039094cc..9bbe0349fa 100644--- a/packages/documents/src/pdf/PackingSlipPDF.tsx+++ b/packages/documents/src/pdf/PackingSlipPDF.tsx@@ -263,7 +263,7 @@ const PackingSlipPDF = ({};function getLineQuantity(- line: Database["public"]["Tables"]["shipmentLine"]["Row"]+ line: Database["public"]["Views"]["shipmentLines"]["Row"]) {if (line.shippedQuantity === line.orderQuantity) {return `${line.shippedQuantity} ${line.unitOfMeasure}`;@@ -272,7 +272,7 @@ function getLineQuantity(}function getLineDescription(- line: Database["public"]["Tables"]["shipmentLine"]["Row"]+ line: Database["public"]["Views"]["shipmentLines"]["Row"]) {return line.itemReadableId;}