Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: collapse sales/purchase line view by defualt when editing

Brad Barbinb6b4bf8a6d17
diff --git a/apps/erp/app/components/DirectionAwareTabs.tsx b/apps/erp/app/components/DirectionAwareTabs.tsx
index eade6aacc9..065d530d20 100644
--- a/apps/erp/app/components/DirectionAwareTabs.tsx
+++ b/apps/erp/app/components/DirectionAwareTabs.tsx
@@ -78,7 +78,7 @@ function DirectionAwareTabs({
>
<div
className={cn(
- "flex flex-wrap gap-1 rounded-lg cursor-pointer bg-muted p-1 shadow-inner-shadow w-auto",
+ "flex flex-wrap gap-1 rounded-lg cursor-pointer bg-muted p-1 shadow-inner w-auto",
className,
rounded
)}
@@ -101,7 +101,7 @@ function DirectionAwareTabs({
{activeTab === tab.id && (
<motion.span
layoutId="bubble"
- className="absolute inset-0 z-10 bg-background text-foreground rounded-md shadow-md"
+ className="absolute inset-0 z-10 bg-background text-foreground rounded-md border"
transition={{ type: "spring", bounce: 0, duration: 0.4 }}
/>
)}
diff --git a/apps/erp/app/modules/invoicing/invoicing.models.ts b/apps/erp/app/modules/invoicing/invoicing.models.ts
index 09665b05a3..e231265ed9 100644
--- a/apps/erp/app/modules/invoicing/invoicing.models.ts
+++ b/apps/erp/app/modules/invoicing/invoicing.models.ts
@@ -205,6 +205,7 @@ export const salesInvoiceLineValidator = z
itemId: zfd.text(z.string().optional()),
accountNumber: zfd.text(z.string().optional()),
assetId: zfd.text(z.string().optional()),
+ addOnCost: zfd.numeric(z.number().optional().default(0)),
description: zfd.text(z.string().optional()),
quantity: zfd.numeric(z.number().optional()),
unitOfMeasureCode: z
diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx
index 431625d8f2..b9f58c314d 100644
--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx
+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx
@@ -1,4 +1,5 @@
import {
+ Badge,
cn,
FormControl,
FormLabel,
@@ -31,7 +32,13 @@ import {
Submit,
UnitOfMeasure,
} from "~/components/Form";
-import { usePermissions, useRouteData, useUser } from "~/hooks";
+import {
+ useCurrencyFormatter,
+ usePercentFormatter,
+ usePermissions,
+ useRouteData,
+ useUser,
+} from "~/hooks";
import type { PurchaseInvoice } from "~/modules/invoicing";
import { purchaseInvoiceLineValidator } from "~/modules/invoicing";
import type { MethodItemType } from "~/modules/shared";
@@ -125,6 +132,9 @@ const PurchaseInvoiceLineForm = ({
? !permissions.can("update", "purchasing")
: !permissions.can("create", "purchasing");
+ const currencyFormatter = useCurrencyFormatter();
+ const percentFormatter = usePercentFormatter();
+
const onTypeChange = (t: MethodItemType | "Item") => {
if (t === itemType) return;
setItemType(t as MethodItemType);
@@ -239,7 +249,11 @@ const PurchaseInvoiceLineForm = ({
return (
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ defaultCollapsed={isEditing}
+ isCollapsible={isEditing}
+ >
<ModalCardContent size="xxlarge">
<ValidatedForm
defaultValues={initialValues}
@@ -266,9 +280,29 @@ const PurchaseInvoiceLineForm = ({
: "New Purchase Invoice Line"}
</ModalCardTitle>
<ModalCardDescription>
- {isEditing
- ? itemData?.description || itemType
- : "A purchase invoice line contains invoice details for a particular item"}
+ {isEditing ? (
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge variant="outline">{initialValues?.quantity}</Badge>
+ <Badge variant="green">
+ {currencyFormatter.format(
+ (initialValues?.supplierUnitPrice ?? 0) +
+ (initialValues?.supplierShippingCost ?? 0)
+ )}{" "}
+ {initialValues?.purchaseUnitOfMeasureCode}
+ </Badge>
+ {initialValues?.taxPercent > 0 ? (
+ <Badge variant="red">
+ {percentFormatter.format(initialValues?.taxPercent)}{" "}
+ Tax
+ </Badge>
+ ) : null}
+ </div>
+ </div>
+ ) : (
+ "A purchase invoice line contains invoice details for a particular item"
+ )}
</ModalCardDescription>
</ModalCardHeader>
<ModalCardBody>
diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
index 3ade2c603d..03c86fafe7 100644
--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
@@ -1,6 +1,7 @@
import {
Alert,
AlertTitle,
+ Badge,
cn,
FormControl,
FormLabel,
@@ -36,7 +37,13 @@ import {
Shelf,
Submit,
} from "~/components/Form";
-import { usePermissions, useRouteData, useUser } from "~/hooks";
+import {
+ useCurrencyFormatter,
+ usePercentFormatter,
+ usePermissions,
+ useRouteData,
+ useUser,
+} from "~/hooks";
import type { SalesInvoice } from "~/modules/invoicing";
import { salesInvoiceLineValidator } from "~/modules/invoicing";
import type { MethodItemType } from "~/modules/shared";
@@ -48,6 +55,7 @@ type SalesInvoiceLineFormProps = {
initialValues: z.infer<typeof salesInvoiceLineValidator> & {
taxPercent?: number;
};
+ isSalesOrderLine?: boolean;
type?: "card" | "modal";
onClose?: () => void;
};
@@ -55,6 +63,7 @@ type SalesInvoiceLineFormProps = {
const SalesInvoiceLineForm = ({
initialValues,
type,
+ isSalesOrderLine = false,
onClose,
}: SalesInvoiceLineFormProps) => {
const permissions = usePermissions();
@@ -121,7 +130,8 @@ const SalesInvoiceLineForm = ({
]);
const isEditing = initialValues.id !== undefined;
- const hasInvalidMethodType = itemData.methodType === "Make";
+ const hasInvalidMethodType =
+ itemData.methodType === "Make" && !isSalesOrderLine;
const isDisabled = !isEditable
? true
: hasInvalidMethodType
@@ -247,9 +257,16 @@ const SalesInvoiceLineForm = ({
}));
};
+ const currencyFormatter = useCurrencyFormatter();
+ const percentFormatter = usePercentFormatter();
+
return (
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ isCollapsible={isEditing}
+ defaultCollapsed={isEditing}
+ >
<ModalCardContent size="xxlarge">
<ValidatedForm
defaultValues={initialValues}
@@ -276,9 +293,36 @@ const SalesInvoiceLineForm = ({
: "New Sales Invoice Line"}
</ModalCardTitle>
<ModalCardDescription>
- {isEditing
- ? itemData?.description || itemType
- : "A sales invoice line contains invoice details for a particular item"}
+ {isEditing ? (
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge
+ variant="outline"
+ className="flex items-center gap-2"
+ >
+ {initialValues?.quantity}{" "}
+ <MethodIcon type={itemData.methodType} />
+ </Badge>
+ <Badge variant="green">
+ {currencyFormatter.format(
+ (initialValues?.unitPrice ?? 0) +
+ (initialValues?.addOnCost ?? 0) +
+ (initialValues?.shippingCost ?? 0)
+ )}{" "}
+ {initialValues?.unitOfMeasureCode}
+ </Badge>
+ {initialValues?.taxPercent > 0 ? (
+ <Badge variant="red">
+ {percentFormatter.format(initialValues?.taxPercent)}{" "}
+ Tax
+ </Badge>
+ ) : null}
+ </div>
+ </div>
+ ) : (
+ "A sales invoice line contains invoice details for a particular item"
+ )}
</ModalCardDescription>
</ModalCardHeader>
<ModalCardBody>
@@ -296,7 +340,7 @@ const SalesInvoiceLineForm = ({
/>
<VStack>
- {itemData.methodType === "Make" && (
+ {hasInvalidMethodType && (
<Alert variant="destructive" className="mb-4">
<LuCircleAlert className="w-4 h-4" />
<AlertTitle>
@@ -408,7 +452,16 @@ const SalesInvoiceLineForm = ({
}
/>
- <Number name="addOnCost" label="Add On Cost" />
+ <Number
+ name="addOnCost"
+ label="Add On Cost"
+ formatOptions={{
+ style: "currency",
+ currency:
+ routeData?.salesInvoice?.currencyCode ??
+ company.baseCurrencyCode,
+ }}
+ />
<NumberControlled
name="taxAmount"
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
index 968732608c..87c8544ae8 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -38,7 +38,7 @@ import { Editor, generateHTML } from "@carbon/react/Editor";
import { formatRelativeTime } from "@carbon/utils";
import { getLocalTimeZone, today } from "@internationalized/date";
import { useFetcher, useFetchers, useParams } from "@remix-run/react";
-import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
+import { AnimatePresence, LayoutGroup, motion, Reorder } from "framer-motion";
import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -47,6 +47,7 @@ import {
LuChevronRight,
LuCirclePlus,
LuEllipsisVertical,
+ LuGripVertical,
LuHammer,
LuInfo,
LuList,
@@ -1657,9 +1658,51 @@ function AttributesForm({
onConfigure?: (c: Configuration) => void;
}) {
const fetcher = useFetcher<typeof newMethodOperationParameterAction>();
+ const sortOrderFetcher = useFetcher<{ success: boolean }>();
const [type, setType] = useState<OperationStep["type"]>("Task");
const [description, setDescription] = useState<JSONContent>({});
const [numericControls, setNumericControls] = useState<string[]>([]);
+
+ // Initialize sort order state based on existing steps
+ const [sortOrder, setSortOrder] = useState<string[]>(() =>
+ [...steps]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((step) => step.id || "")
+ );
+
+ // Update sort order when steps change
+ useEffect(() => {
+ if (steps && steps.length > 0) {
+ const sorted = [...steps]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((step) => step.id || "");
+ setSortOrder(sorted);
+ }
+ }, [steps]);
+
+ const onReorder = (newOrder: string[]) => {
+ if (isDisabled) return;
+
+ const updates: Record<string, number> = {};
+ newOrder.forEach((id, index) => {
+ updates[id] = index + 1;
+ });
+ setSortOrder(newOrder);
+ updateSortOrder(updates);
+ };
+
+ const updateSortOrder = useDebounce(
+ (updates: Record<string, number>) => {
+ let formData = new FormData();
+ formData.append("updates", JSON.stringify(updates));
+ sortOrderFetcher.submit(formData, {
+ method: "post",
+ action: path.to.methodOperationStepOrder(operationId),
+ });
+ },
+ 1000,
+ true
+ );
const typeOptions = useMemo(
() =>
procedureStepType.map((type) => ({
@@ -1837,20 +1880,38 @@ function AttributesForm({
{steps.length > 0 && (
<div className="border bg-card rounded-lg">
- {[...steps]
- .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
- .map((a, index) => (
- <AttributesListItem
- key={a.id}
- attribute={a}
- operationId={operationId}
- typeOptions={typeOptions}
- className={index === steps.length - 1 ? "border-none" : ""}
- configurable={configurable}
- rulesByField={rulesByField}
- onConfigure={onConfigure}
- />
- ))}
+ <Reorder.Group
+ axis="y"
+ values={sortOrder}
+ onReorder={onReorder}
+ className="w-full"
+ >
+ {sortOrder.map((stepId) => {
+ const step = steps.find((s) => s.id === stepId);
+ if (!step) return null;
+ const index = sortOrder.indexOf(stepId);
+ return (
+ <Reorder.Item
+ key={stepId}
+ value={stepId}
+ dragListener={!isDisabled}
+ >
+ <AttributesListItem
+ attribute={step}
+ operationId={operationId}
+ typeOptions={typeOptions}
+ isDisabled={isDisabled}
+ className={
+ index === sortOrder.length - 1 ? "border-none" : ""
+ }
+ configurable={configurable}
+ rulesByField={rulesByField}
+ onConfigure={onConfigure}
+ />
+ </Reorder.Item>
+ );
+ })}
+ </Reorder.Group>
</div>
)}
{steps.length === 0 && isDisabled && (
@@ -1870,6 +1931,7 @@ function AttributesListItem({
configurable,
rulesByField,
onConfigure,
+ isDisabled = false,
}: {
attribute: OperationStep;
operationId: string;
@@ -1878,6 +1940,7 @@ function AttributesListItem({
configurable: boolean;
rulesByField: Map<string, ConfigurationRule>;
onConfigure?: (c: Configuration) => void;
+ isDisabled?: boolean;
}) {
const {
name,
@@ -2121,6 +2184,13 @@ function AttributesListItem({
) : (
<div className="flex flex-1 justify-between items-center w-full">
<HStack spacing={4} className="w-1/2">
+ <IconButton
+ aria-label="Drag handle"
+ icon={<LuGripVertical />}
+ variant="ghost"
+ disabled={isDisabled}
+ className="cursor-grab"
+ />
<HStack spacing={4} className="flex-1">
<div className="bg-muted border rounded-full flex items-center justify-center p-2">
<ProcedureStepTypeIcon type={type} />
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 4404c90ea3..288196ffbe 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -1102,6 +1102,57 @@ export async function updateJobOperationOrder(
return Promise.all(updatePromises);
}
+export async function updateJobOperationStepOrder(
+ client: SupabaseClient<Database>,
+ updates: {
+ id: string;
+ sortOrder: number;
+ updatedBy: string;
+ }[]
+) {
+ const updatePromises = updates.map(({ id, sortOrder, updatedBy }) =>
+ client
+ .from("jobOperationStep")
+ .update({ sortOrder, updatedBy })
+ .eq("id", id)
+ );
+ return Promise.all(updatePromises);
+}
+
+export async function updateQuoteOperationStepOrder(
+ client: SupabaseClient<Database>,
+ updates: {
+ id: string;
+ sortOrder: number;
+ updatedBy: string;
+ }[]
+) {
+ const updatePromises = updates.map(({ id, sortOrder, updatedBy }) =>
+ client
+ .from("quoteOperationStep")
+ .update({ sortOrder, updatedBy })
+ .eq("id", id)
+ );
+ return Promise.all(updatePromises);
+}
+
+export async function updateMethodOperationStepOrder(
+ client: SupabaseClient<Database>,
+ updates: {
+ id: string;
+ sortOrder: number;
+ updatedBy: string;
+ }[]
+) {
+ const updatePromises = updates.map(({ id, sortOrder, updatedBy }) =>
+ client
+ .from("methodOperationStep")
+ .update({ sortOrder, updatedBy })
+ .eq("id", id)
+ );
+ return Promise.all(updatePromises);
+}
+
export async function updateJobOperationStatus(
client: SupabaseClient<Database>,
id: string,
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index 2983017dbf..b8184841a3 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -16,6 +16,7 @@ import {
CardHeader,
CardTitle,
Checkbox,
+ cn,
Count,
DropdownMenu,
DropdownMenuContent,
@@ -33,17 +34,16 @@ import {
ModalHeader,
ModalTitle,
ScrollArea,
+ toast,
ToggleGroup,
ToggleGroupItem,
Tooltip,
TooltipContent,
TooltipTrigger,
- VStack,
- cn,
- toast,
useDebounce,
useDisclosure,
useMount,
+ VStack,
} from "@carbon/react";
import { Editor, generateHTML } from "@carbon/react/Editor";
import {
@@ -54,7 +54,7 @@ import {
import { getLocalTimeZone, today } from "@internationalized/date";
import { useFetcher, useFetchers, useParams } from "@remix-run/react";
import type { RealtimeChannel } from "@supabase/supabase-js";
-import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
+import { AnimatePresence, LayoutGroup, motion, Reorder } from "framer-motion";
import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -65,6 +65,7 @@ import {
LuCirclePlus,
LuDollarSign,
LuEllipsisVertical,
+ LuGripVertical,
LuHammer,
LuInfo,
LuListChecks,
@@ -158,7 +159,7 @@ type ItemWithData = Item & {
type JobOperationStep = OperationStep & {
jobOperationStepRecord?:
- | Database["public"]["Tables"]["jobOperationStepRecord"]["Row"]
+ | Database["public"]["Tables"]["jobOperationStepRecord"]["Row"][]
| null;
};
@@ -1003,9 +1004,52 @@ function StepsForm({
temporaryItems: TemporaryItems;
}) {
const fetcher = useFetcher<typeof newJobOperationParameterAction>();
+ const sortOrderFetcher = useFetcher<{ success: boolean }>();
const [type, setType] = useState<OperationStep["type"]>("Task");
const [description, setDescription] = useState<JSONContent>({});
const [numericControls, setNumericControls] = useState<string[]>([]);
+
+ // Initialize sort order state based on existing steps
+ const [sortOrder, setSortOrder] = useState<string[]>(() =>
+ [...steps]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((step) => step.id || "")
+ );
+
+ // Update sort order when steps change
+ useEffect(() => {
+ if (steps && steps.length > 0) {
+ const sorted = [...steps]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((step) => step.id || "");
+ setSortOrder(sorted);
+ }
+ }, [steps]);
+
+ const onReorder = (newOrder: string[]) => {
+ if (isDisabled) return;
+
+ const updates: Record<string, number> = {};
+ newOrder.forEach((id, index) => {
+ updates[id] = index + 1;
+ });
+ setSortOrder(newOrder);
+ updateSortOrder(updates);
+ };
+
+ const updateSortOrder = useDebounce(
+ (updates: Record<string, number>) => {
+ let formData = new FormData();
+ formData.append("updates", JSON.stringify(updates));
+ sortOrderFetcher.submit(formData, {
+ method: "post",
+ action: path.to.jobOperationStepOrder(operationId),
+ });
+ },
+ 1000,
+ true
+ );
+
const typeOptions = useMemo(
() =>
procedureStepType.map((type) => ({
@@ -1178,17 +1222,35 @@ function StepsForm({
{steps.length > 0 && (
<div className="border rounded-lg ">
- {[...steps]
- .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
- .map((a, index) => (
- <StepsListItem
- key={a.id}
- attribute={a}
- operationId={operationId}
- typeOptions={typeOptions}
- className={index === steps.length - 1 ? "border-none" : ""}
- />
- ))}
+ <Reorder.Group
+ axis="y"
+ values={sortOrder}
+ onReorder={onReorder}
+ className="w-full"
+ >
+ {sortOrder.map((stepId) => {
+ const step = steps.find((s) => s.id === stepId);
+ if (!step) return null;
+ const index = sortOrder.indexOf(stepId);
+ return (
+ <Reorder.Item
+ key={stepId}
+ value={stepId}
+ dragListener={!isDisabled}
+ >
+ <StepsListItem
+ attribute={step}
+ operationId={operationId}
+ typeOptions={typeOptions}
+ isDisabled={isDisabled}
+ className={
+ index === sortOrder.length - 1 ? "border-none" : ""
+ }
+ />
+ </Reorder.Item>
+ );
+ })}
+ </Reorder.Group>
</div>
)}
</Loading>
@@ -1199,11 +1261,13 @@ function StepsListItem({
attribute,
operationId,
typeOptions,
+ isDisabled = false,
className,
}: {
attribute: JobOperationStep;
operationId: string;
typeOptions: { label: JSX.Element; value: string }[];
+ isDisabled?: boolean;
className?: string;
}) {
const {
@@ -1391,93 +1455,103 @@ function StepsListItem({
</VStack>
</ValidatedForm>
) : (
- <div className="flex flex-1 justify-between items-center w-full">
- <HStack spacing={4} className="w-1/2">
- <HStack spacing={4} className="flex-1">
- <div className="bg-muted border rounded-full flex items-center justify-center p-2">
- <ProcedureStepTypeIcon type={type} />
- </div>
- <VStack spacing={0}>
- <HStack>
- <p className="text-foreground text-sm font-medium">
- {attribute.name}
- </p>
- {attribute.description &&
- Object.keys(attribute.description).length > 0 ? (
- <Tooltip>
- <TooltipTrigger>
- <LuInfo className="text-muted-foreground size-3" />
- </TooltipTrigger>
- <TooltipContent side="right">
- <p
- className="prose prose-sm dark:prose-invert text-foreground text-sm"
- dangerouslySetInnerHTML={{
- __html: generateHTML(attribute.description),
- }}
- />
- </TooltipContent>
- </Tooltip>
- ) : null}
- </HStack>
- {attribute.type === "Measurement" && (
- <span className="text-xs text-muted-foreground">
- {attribute.minValue !== null && attribute.maxValue !== null
- ? `Must be between ${attribute.minValue} and ${
- attribute.maxValue
- } ${
- unitOfMeasures.find(
- (u) => u.value === unitOfMeasureCode
- )?.label
- }`
- : attribute.minValue !== null
- ? `Must be > ${attribute.minValue} ${
- unitOfMeasures.find(
- (u) => u.value === unitOfMeasureCode
- )?.label
- }`
- : attribute.maxValue !== null
- ? `Must be < ${attribute.maxValue} ${
- unitOfMeasures.find(
- (u) => u.value === unitOfMeasureCode
- )?.label
- }`
- : null}
- </span>
- )}
- </VStack>
- {attribute.jobOperationStepRecord && (
- <PreviewStepRecord attribute={attribute} />
- )}
- </HStack>
- </HStack>
- <div className="flex items-center justify-end gap-2">
- <HStack spacing={2}>
- <span className="text-xs text-muted-foreground">
- {isUpdated ? "Updated" : "Created"} {formatRelativeTime(date)}
- </span>
- <EmployeeAvatar employeeId={person} withName={false} />
+ <div className="flex flex-col gap-2 w-full">
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <IconButton
+ aria-label="Drag handle"
+ icon={<LuGripVertical />}
+ variant="ghost"
+ disabled={isDisabled}
+ className="cursor-grab"
+ />
+ <HStack spacing={4} className="flex-1">
+ <div className="bg-muted border rounded-full flex items-center justify-center p-2">
+ <ProcedureStepTypeIcon type={type} />
+ </div>
+ <VStack spacing={0}>
+ <HStack>
+ <p className="text-foreground text-sm font-medium">
+ {attribute.name}
+ </p>
+ {attribute.description &&
+ Object.keys(attribute.description).length > 0 ? (
+ <Tooltip>
+ <TooltipTrigger>
+ <LuInfo className="text-muted-foreground size-3" />
+ </TooltipTrigger>
+ <TooltipContent side="right">
+ <p
+ className="prose prose-sm dark:prose-invert text-foreground text-sm"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(attribute.description),
+ }}
+ />
+ </TooltipContent>
+ </Tooltip>
+ ) : null}
+ </HStack>
+ {attribute.type === "Measurement" && (
+ <span className="text-xs text-muted-foreground">
+ {attribute.minValue !== null &&
+ attribute.maxValue !== null
+ ? `Must be between ${attribute.minValue} and ${
+ attribute.maxValue
+ } ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : attribute.minValue !== null
+ ? `Must be > ${attribute.minValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : attribute.maxValue !== null
+ ? `Must be < ${attribute.maxValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : null}
+ </span>
+ )}
+ </VStack>
+ </HStack>
</HStack>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label="Open menu"
- icon={<LuEllipsisVertical />}
- variant="ghost"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem onClick={disclosure.onOpen}>
- Edit
- </DropdownMenuItem>
- <DropdownMenuItem
- destructive
- onClick={deleteModalDisclosure.onOpen}
- >
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ <div className="flex items-center justify-end gap-2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ {isUpdated ? "Updated" : "Created"} {formatRelativeTime(date)}
+ </span>
+ <EmployeeAvatar employeeId={person} withName={false} />
+ </HStack>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="Open menu"
+ icon={<LuEllipsisVertical />}
+ variant="ghost"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={disclosure.onOpen}>
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ destructive
+ onClick={deleteModalDisclosure.onOpen}
+ >
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
</div>
+ {attribute.jobOperationStepRecord && (
+ <PreviewStepRecords attribute={attribute} />
+ )}
</div>
)}
{deleteModalDisclosure.isOpen && (
@@ -1498,42 +1572,90 @@ function StepsListItem({
);
}
-function PreviewStepRecord({ attribute }: { attribute: JobOperationStep }) {
+function PreviewStepRecords({ attribute }: { attribute: JobOperationStep }) {
+ if (
+ !attribute.jobOperationStepRecord ||
+ !Array.isArray(attribute.jobOperationStepRecord)
+ ) {
+ return null;
+ }
+
+ const records = attribute.jobOperationStepRecord;
+
+ return (
+ <div className="mt-4">
+ <div className="border rounded-lg overflow-hidden">
+ {records.map((record, index) => (
+ <div
+ key={record.id || index}
+ className={cn(
+ "flex flex-1 items-center justify-between px-3 py-2",
+ index !== records.length - 1 && "border-b"
+ )}
+ >
+ <div className="flex w-1/2 items-center justify-between gap-2">
+ <span className="text-xs text-muted-foreground font-medium">
+ Record {index + 1}
+ </span>
+ <div className="text-right font-medium">
+ <PreviewStepRecord attribute={attribute} record={record} />
+ </div>
+ </div>
+
+ <div className="flex items-center justify-end gap-2 w-1/2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ Created {formatRelativeTime(record.createdAt ?? "")}
+ </span>
+ <EmployeeAvatar
+ employeeId={record.createdBy}
+ withName={false}
+ />
+ </HStack>
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+}
+
+function PreviewStepRecord({
+ attribute,
+ record,
+}: {
+ attribute: JobOperationStep;
+ record: any;
+}) {
const unitOfMeasures = useUnitOfMeasure();
const [employees] = usePeople();
const numberFormatter = useNumberFormatter();
- if (!attribute.jobOperationStepRecord) return null;
return (
- <div className="min-w-[200px] truncate text-right font-medium">
- {attribute.type === "Checkbox" && (
- <Checkbox
- checked={attribute.jobOperationStepRecord.booleanValue ?? false}
- />
+ <>
+ {attribute.type === "Task" && (
+ <Checkbox checked={record.booleanValue ?? false} />
)}
- {attribute.type === "Value" && (
- <p className="text-sm">{attribute.jobOperationStepRecord.value}</p>
+ {attribute.type === "Checkbox" && (
+ <Checkbox checked={record.booleanValue ?? false} />
)}
+ {attribute.type === "Value" && <p className="text-sm">{record.value}</p>}
{attribute.type === "Measurement" &&
- typeof attribute.jobOperationStepRecord?.numericValue === "number" && (
+ typeof record.numericValue === "number" && (
<p
className={cn(
"text-sm",
attribute.minValue !== null &&
attribute.minValue !== undefined &&
- attribute.jobOperationStepRecord.numericValue <
- attribute.minValue &&
+ record.numericValue < attribute.minValue &&
"text-red-500",
attribute.maxValue !== null &&
attribute.maxValue !== undefined &&
- attribute.jobOperationStepRecord.numericValue >
- attribute.maxValue &&
+ record.numericValue > attribute.maxValue &&
"text-red-500"
)}
>
- {numberFormatter.format(
- attribute.jobOperationStepRecord.numericValue
- )}{" "}
+ {numberFormatter.format(record.numericValue)}{" "}
{
unitOfMeasures.find(
(u) => u.value === attribute.unitOfMeasureCode
@@ -1542,27 +1664,19 @@ function PreviewStepRecord({ attribute }: { attribute: JobOperationStep }) {
</p>
)}
{attribute.type === "Timestamp" && (
- <p className="text-sm">
- {formatDateTime(attribute.jobOperationStepRecord.value ?? "")}
- </p>
- )}
- {attribute.type === "List" && (
- <p className="text-sm">{attribute.jobOperationStepRecord.value}</p>
+ <p className="text-sm">{formatDateTime(record.value ?? "")}</p>
)}
+ {attribute.type === "List" && <p className="text-sm">{record.value}</p>}
{attribute.type === "Person" && (
<p className="text-sm">
- {
- employees.find(
- (e) => e.id === attribute.jobOperationStepRecord?.userValue
- )?.name
- }
+ {employees.find((e) => e.id === record.userValue)?.name}
</p>
)}
- {attribute.type === "File" && attribute.jobOperationStepRecord?.value && (
- <div className="flex justify-end gap-2 text-sm">
+ {attribute.type === "File" && record.value && (
+ <div className="flex justify-end gap-2 text-xs">
<LuPaperclip className="size-4 text-muted-foreground" />
<a
- href={getPrivateUrl(attribute.jobOperationStepRecord.value)}
+ href={getPrivateUrl(record.value)}
target="_blank"
rel="noopener noreferrer"
>
@@ -1570,7 +1684,7 @@ function PreviewStepRecord({ attribute }: { attribute: JobOperationStep }) {
</a>
</div>
)}
- </div>
+ </>
);
}
diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx
index 84ea1ba45c..33d1db6d4f 100644
--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx
+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx
@@ -35,7 +35,13 @@ import {
Submit,
UnitOfMeasure,
} from "~/components/Form";
-import { usePermissions, useRouteData, useUser } from "~/hooks";
+import {
+ useCurrencyFormatter,
+ usePercentFormatter,
+ usePermissions,
+ useRouteData,
+ useUser,
+} from "~/hooks";
import type { PurchaseOrder, PurchaseOrderLine } from "~/modules/purchasing";
import { purchaseOrderLineValidator } from "~/modules/purchasing";
import type { MethodItemType } from "~/modules/shared";
@@ -139,6 +145,8 @@ const PurchaseOrderLineForm = ({
: !permissions.can("create", "purchasing");
const deleteDisclosure = useDisclosure();
+ const currencyFormatter = useCurrencyFormatter();
+ const percentFormatter = usePercentFormatter();
const onTypeChange = (t: MethodItemType | "Item") => {
if (t === itemType) return;
@@ -255,7 +263,11 @@ const PurchaseOrderLineForm = ({
return (
<>
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ defaultCollapsed={isEditing}
+ isCollapsible={isEditing}
+ >
<ModalCardContent size="xxlarge">
<ValidatedForm
defaultValues={initialValues}
@@ -286,7 +298,27 @@ const PurchaseOrderLineForm = ({
{isOutsideProcessing ? (
<Badge variant="default">Outside Processing</Badge>
) : isEditing ? (
- itemData?.description || itemType
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge variant="outline">
+ {initialValues?.purchaseQuantity}
+ </Badge>
+ <Badge variant="green">
+ {currencyFormatter.format(
+ (initialValues?.supplierUnitPrice ?? 0) +
+ (initialValues?.supplierShippingCost ?? 0)
+ )}{" "}
+ {initialValues?.purchaseUnitOfMeasureCode}
+ </Badge>
+ {initialValues?.taxPercent > 0 ? (
+ <Badge variant="red">
+ {percentFormatter.format(initialValues?.taxPercent)}{" "}
+ Tax
+ </Badge>
+ ) : null}
+ </div>
+ </div>
) : (
"A purchase order line contains order details for a particular item"
)}
diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx
index b98c772dd2..dbb9965579 100644
--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx
+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLineForm.tsx
@@ -1,4 +1,5 @@
import {
+ Badge,
CardAction,
DropdownMenu,
DropdownMenuContent,
@@ -162,7 +163,11 @@ const SupplierQuoteLineForm = ({
return (
<>
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ defaultCollapsed={isEditing}
+ isCollapsible={isEditing}
+ >
<ModalCardContent size="xxlarge">
<ValidatedForm
defaultValues={initialValues}
@@ -186,19 +191,28 @@ const SupplierQuoteLineForm = ({
: "New Supplier Quote Line"}
</ModalCardTitle>
<ModalCardDescription>
- {isEditing
- ? itemData?.description
- : "A quote line contains pricing and lead times for a particular part"}
+ {isEditing ? (
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge variant="outline">
+ {initialValues?.quantity.join(", ")}
+ </Badge>
+ </div>
+ </div>
+ ) : (
+ "A quote line contains pricing and lead times for a particular part"
+ )}
</ModalCardDescription>
</ModalCardHeader>
{isEditing && permissions.can("update", "purchasing") && (
- <CardAction>
+ <CardAction className="pr-12">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
icon={<BsThreeDotsVertical />}
aria-label="More"
- variant="secondary"
+ variant="ghost"
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.ts
index 965fb18532..3f285bba11 100644
--- a/apps/erp/app/modules/sales/sales.service.ts
+++ b/apps/erp/app/modules/sales/sales.service.ts
@@ -993,7 +993,8 @@ export async function getQuoteLinePricesByItemIds(
.in("itemId", itemIds)
.neq("quoteId", currentQuoteId)
.order("quoteCreatedAt", { ascending: false })
- .order("qty", { ascending: true });
+ .order("qty", { ascending: true })
+ .limit(10);
}
export async function getQuoteMaterials(
@@ -1322,7 +1323,8 @@ export async function getSalesOrderLinesByItemIds(
.select("*")
.in("itemId", itemIds)
.order("orderDate", { ascending: false })
- .order("createdAt", { ascending: false });
+ .order("createdAt", { ascending: false })
+ .limit(10);
}
export async function getSalesOrderLine(
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index ad5866705c..83c5273bc7 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -37,7 +37,7 @@ import { Editor, generateHTML } from "@carbon/react/Editor";
import { formatRelativeTime } from "@carbon/utils";
import { getLocalTimeZone, today } from "@internationalized/date";
import { useFetcher, useFetchers, useParams } from "@remix-run/react";
-import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
+import { AnimatePresence, LayoutGroup, motion, Reorder } from "framer-motion";
import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -47,6 +47,7 @@ import {
LuCirclePlus,
LuDollarSign,
LuEllipsisVertical,
+ LuGripVertical,
LuHammer,
LuInfo,
LuList,
@@ -834,9 +835,51 @@ function AttributesForm({
temporaryItems: TemporaryItems;
}) {
const fetcher = useFetcher<typeof newQuoteOperationParameterAction>();
+ const sortOrderFetcher = useFetcher<{ success: boolean }>();
const [type, setType] = useState<OperationStep["type"]>("Task");
const [numericControls, setNumericControls] = useState<string[]>([]);
+ // Initialize sort order state based on existing steps
+ const [sortOrder, setSortOrder] = useState<string[]>(() =>
+ [...steps]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((step) => step.id || "")
+ );
+
+ // Update sort order when steps change
+ useEffect(() => {
+ if (steps && steps.length > 0) {
+ const sorted = [...steps]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((step) => step.id || "");
+ setSortOrder(sorted);
+ }
+ }, [steps]);
+
+ const onReorder = (newOrder: string[]) => {
+ if (isDisabled) return;
+
+ const updates: Record<string, number> = {};
+ newOrder.forEach((id, index) => {
+ updates[id] = index + 1;
+ });
+ setSortOrder(newOrder);
+ updateSortOrder(updates);
+ };
+
+ const updateSortOrder = useDebounce(
+ (updates: Record<string, number>) => {
+ let formData = new FormData();
+ formData.append("updates", JSON.stringify(updates));
+ sortOrderFetcher.submit(formData, {
+ method: "post",
+ action: path.to.quoteOperationStepOrder(operationId),
+ });
+ },
+ 1000,
+ true
+ );
+
const [description, setDescription] = useState<JSONContent>({});
const { carbon } = useCarbon();
@@ -1013,17 +1056,35 @@ function AttributesForm({
{steps.length > 0 && (
<div className="border bg-card rounded-lg">
- {[...steps]
- .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
- .map((a, index) => (
- <AttributesListItem
- key={a.id}
- attribute={a}
- operationId={operationId}
- typeOptions={typeOptions}
- className={index === steps.length - 1 ? "border-none" : ""}
- />
- ))}
+ <Reorder.Group
+ axis="y"
+ values={sortOrder}
+ onReorder={onReorder}
+ className="w-full"
+ >
+ {sortOrder.map((stepId) => {
+ const step = steps.find((s) => s.id === stepId);
+ if (!step) return null;
+ const index = sortOrder.indexOf(stepId);
+ return (
+ <Reorder.Item
+ key={stepId}
+ value={stepId}
+ dragListener={!isDisabled}
+ >
+ <AttributesListItem
+ attribute={step}
+ operationId={operationId}
+ typeOptions={typeOptions}
+ isDisabled={isDisabled}
+ className={
+ index === sortOrder.length - 1 ? "border-none" : ""
+ }
+ />
+ </Reorder.Item>
+ );
+ })}
+ </Reorder.Group>
</div>
)}
</Loading>
@@ -1034,11 +1095,13 @@ function AttributesListItem({
attribute,
operationId,
typeOptions,
+ isDisabled = false,
className,
}: {
attribute: OperationStep;
operationId: string;
typeOptions: { label: JSX.Element; value: string }[];
+ isDisabled?: boolean;
className?: string;
}) {
const {
@@ -1229,6 +1292,13 @@ function AttributesListItem({
) : (
<div className="flex flex-1 justify-between items-center w-full">
<HStack spacing={4} className="w-1/2">
+ <IconButton
+ aria-label="Drag handle"
+ icon={<LuGripVertical />}
+ variant="ghost"
+ disabled={isDisabled}
+ className="cursor-grab"
+ />
<HStack spacing={4} className="flex-1">
<div className="bg-muted border rounded-full flex items-center justify-center p-2">
<ProcedureStepTypeIcon type={type} />
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
index 69acc73d59..80ce4c84fe 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
@@ -1,4 +1,5 @@
import {
+ Badge,
Button,
CardAction,
DropdownMenu,
@@ -39,7 +40,12 @@ import {
SelectControlled,
Submit,
} from "~/components/Form";
-import { usePermissions, useRouteData, useUser } from "~/hooks";
+import {
+ usePercentFormatter,
+ usePermissions,
+ useRouteData,
+ useUser,
+} from "~/hooks";
import type { Quotation, QuotationLine } from "../../types";
import { getItemReadableId } from "@carbon/utils";
@@ -118,6 +124,8 @@ const QuoteLineForm = ({
Record<string, any> | ""
>("");
+ const percentFormatter = usePercentFormatter();
+
const onCustomerPartChange = async (customerPartId: string) => {
if (!carbon || !routeData?.quote?.customerId) return;
@@ -242,7 +250,11 @@ const QuoteLineForm = ({
return (
<>
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ defaultCollapsed={isEditing}
+ isCollapsible={isEditing}
+ >
<ModalCardContent size="xxlarge">
<ValidatedForm
fetcher={fetcher}
@@ -268,19 +280,40 @@ const QuoteLineForm = ({
: "New Quote Line"}
</ModalCardTitle>
<ModalCardDescription>
- {isEditing
- ? itemData?.description
- : "A quote line contains pricing and lead times for a particular part"}
+ {isEditing ? (
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge
+ variant="outline"
+ className="flex items-center gap-2"
+ >
+ <MethodIcon type={itemData.methodType} />
+ {initialValues?.quantity.join(", ")}
+ </Badge>
+ {initialValues?.taxPercent > 0 ? (
+ <Badge variant="red">
+ {percentFormatter.format(
+ initialValues?.taxPercent
+ )}{" "}
+ Tax
+ </Badge>
+ ) : null}
+ </div>
+ </div>
+ ) : (
+ "A quote line contains pricing and lead times for a particular part"
+ )}
</ModalCardDescription>
</ModalCardHeader>
{isEditing && permissions.can("update", "sales") && (
- <CardAction>
+ <CardAction className="pr-12">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
icon={<BsThreeDotsVertical />}
aria-label="More"
- variant="secondary"
+ variant="ghost"
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricingHistory.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricingHistory.tsx
index 2811bbdf64..e11075c8dd 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricingHistory.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricingHistory.tsx
@@ -104,7 +104,7 @@ const QuoteLinePricingHistory = ({
{relatedSalesOrderLines.map((line) => (
<CarouselItem
key={line.id}
- className="pl-4 basis-full lg:basis-1/2 xl:basis-1/3"
+ className="pl-4 basis-full lg:basis-1/2"
>
<Card className="w-full p-0 bg-gradient-to-b from-card to-card via-card dark:from-card dark:to-card dark:via-card">
<CardContent className="p-4">
diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx
index 8a93a51d78..2c5270e3d1 100644
--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx
+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx
@@ -1,4 +1,5 @@
import {
+ Badge,
CardAction,
cn,
DropdownMenu,
@@ -41,7 +42,13 @@ import {
Submit,
UnitOfMeasure,
} from "~/components/Form";
-import { usePermissions, useRouteData, useUser } from "~/hooks";
+import {
+ useCurrencyFormatter,
+ usePercentFormatter,
+ usePermissions,
+ useRouteData,
+ useUser,
+} from "~/hooks";
import { useCarbon } from "@carbon/auth";
import { getItemReadableId } from "@carbon/utils";
@@ -120,6 +127,9 @@ const SalesOrderLineForm = ({
});
};
+ const currencyFormatter = useCurrencyFormatter();
+ const percentFormatter = usePercentFormatter();
+
const onChange = async (itemId: string) => {
if (!itemId) return;
if (!carbon || !company.id) return;
@@ -185,7 +195,11 @@ const SalesOrderLineForm = ({
return (
<>
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ isCollapsible={isEditing}
+ defaultCollapsed={isEditing}
+ >
<ModalCardContent size="xxlarge">
<ValidatedForm
defaultValues={initialValues}
@@ -213,19 +227,48 @@ const SalesOrderLineForm = ({
: "New Sales Order Line"}
</ModalCardTitle>
<ModalCardDescription>
- {isEditing
- ? itemData?.description || lineType
- : "A sales order line contains order details for a particular item"}
+ {isEditing ? (
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge
+ variant="outline"
+ className="flex items-center gap-2"
+ >
+ {initialValues?.saleQuantity}
+ <MethodIcon type={itemData.methodType} />
+ </Badge>
+ <Badge variant="green">
+ {currencyFormatter.format(
+ (initialValues?.unitPrice ?? 0) +
+ (initialValues?.addOnCost ?? 0) +
+ (initialValues?.shippingCost ?? 0)
+ )}{" "}
+ {initialValues?.unitOfMeasureCode}
+ </Badge>
+ {initialValues?.taxPercent > 0 ? (
+ <Badge variant="red">
+ {percentFormatter.format(
+ initialValues?.taxPercent
+ )}{" "}
+ Tax
+ </Badge>
+ ) : null}
+ </div>
+ </div>
+ ) : (
+ "A sales order line contains order details for a particular item"
+ )}
</ModalCardDescription>
</ModalCardHeader>
{isEditing && permissions.can("update", "sales") && (
- <CardAction>
+ <CardAction className="pr-12">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
icon={<BsThreeDotsVertical />}
aria-label="More"
- variant="secondary"
+ variant="ghost"
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
diff --git a/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQLineForm.tsx b/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQLineForm.tsx
index dbbc5caf89..e1eff6bf10 100644
--- a/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQLineForm.tsx
+++ b/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQLineForm.tsx
@@ -1,4 +1,5 @@
import {
+ Badge,
CardAction,
DropdownMenu,
DropdownMenuContent,
@@ -179,7 +180,11 @@ const SalesRFQLineForm = ({
return (
<>
<ModalCardProvider type={type}>
- <ModalCard onClose={onClose}>
+ <ModalCard
+ onClose={onClose}
+ isCollapsible={isEditing}
+ defaultCollapsed={isEditing}
+ >
<ModalCardContent>
<ValidatedForm
defaultValues={initialValues}
@@ -199,23 +204,36 @@ const SalesRFQLineForm = ({
<ModalCardHeader>
<ModalCardTitle>
{isEditing
- ? itemData?.customerPartId ?? "RFQ Line"
+ ? `${itemData?.customerPartId}${
+ itemData?.customerPartRevision
+ ? `.${itemData?.customerPartRevision}`
+ : ""
+ }`
: "New RFQ Line"}
</ModalCardTitle>
<ModalCardDescription>
- {isEditing
- ? itemData?.description
- : "An RFQ line contains part and quantity information about the requested item"}
+ {isEditing ? (
+ <div className="flex flex-col items-start gap-1">
+ <span>{itemData?.description}</span>
+ <div className="flex items-center gap-2">
+ <Badge variant="outline">
+ {initialValues?.quantity.join(", ")}
+ </Badge>
+ </div>
+ </div>
+ ) : (
+ "An RFQ line contains part and quantity information about the requested item"
+ )}
</ModalCardDescription>
</ModalCardHeader>
{isEditing && permissions.can("update", "sales") && (
- <CardAction>
+ <CardAction className="pr-12">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
icon={<BsThreeDotsVertical />}
aria-label="More"
- variant="secondary"
+ variant="ghost"
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
diff --git a/apps/erp/app/routes/x+/items+/methods+/operation.$operationId.step.order.tsx b/apps/erp/app/routes/x+/items+/methods+/operation.$operationId.step.order.tsx
new file mode 100644
index 0000000000..5d228bd0e2
--- /dev/null
+++ b/apps/erp/app/routes/x+/items+/methods+/operation.$operationId.step.order.tsx
@@ -0,0 +1,54 @@
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+
+import { assertIsPost, error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { updateMethodOperationStepOrder } from "~/modules/production";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "parts",
+ });
+
+ const formData = await request.formData();
+ const updateMap = formData.get("updates") as string;
+
+ const { operationId } = params;
+ if (!operationId) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive an operation id"))
+ );
+ }
+
+ if (!updateMap) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive a new sort order"))
+ );
+ }
+
+ const updates = Object.entries(JSON.parse(updateMap)).map(
+ ([id, sortOrderString]) => ({
+ id,
+ sortOrder: Number(sortOrderString),
+ updatedBy: userId,
+ })
+ );
+
+ const updateSortOrders = await updateMethodOperationStepOrder(
+ client,
+ updates
+ );
+ if (updateSortOrders.some((update) => update.error))
+ return json(
+ {},
+ await flash(
+ request,
+ error(updateSortOrders, "Failed to update sort order")
+ )
+ );
+
+ return json({ success: true });
+}
diff --git a/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsx b/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsx
new file mode 100644
index 0000000000..bfe42f01dd
--- /dev/null
+++ b/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsx
@@ -0,0 +1,51 @@
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+
+import { assertIsPost, error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { updateJobOperationStepOrder } from "~/modules/production";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "production",
+ });
+
+ const formData = await request.formData();
+ const updateMap = formData.get("updates") as string;
+
+ const { operationId } = params;
+ if (!operationId) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive an operation id"))
+ );
+ }
+
+ if (!updateMap) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive a new sort order"))
+ );
+ }
+
+ const updates = Object.entries(JSON.parse(updateMap)).map(
+ ([id, sortOrderString]) => ({
+ id,
+ sortOrder: Number(sortOrderString),
+ updatedBy: userId,
+ })
+ );
+
+ const updateSortOrders = await updateJobOperationStepOrder(client, updates);
+ if (updateSortOrders.some((update) => update.error))
+ return json(
+ {},
+ await flash(
+ request,
+ error(updateSortOrders, "Failed to update sort order")
+ )
+ );
+
+ return json({ success: true });
+}
diff --git a/apps/erp/app/routes/x+/quote+/methods+/operation.$operationId.step.order.tsx b/apps/erp/app/routes/x+/quote+/methods+/operation.$operationId.step.order.tsx
new file mode 100644
index 0000000000..594c5f2541
--- /dev/null
+++ b/apps/erp/app/routes/x+/quote+/methods+/operation.$operationId.step.order.tsx
@@ -0,0 +1,51 @@
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+
+import { assertIsPost, error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { updateQuoteOperationStepOrder } from "~/modules/production";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "sales",
+ });
+
+ const formData = await request.formData();
+ const updateMap = formData.get("updates") as string;
+
+ const { operationId } = params;
+ if (!operationId) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive an operation id"))
+ );
+ }
+
+ if (!updateMap) {
+ return json(
+ {},
+ await flash(request, error(null, "Failed to receive a new sort order"))
+ );
+ }
+
+ const updates = Object.entries(JSON.parse(updateMap)).map(
+ ([id, sortOrderString]) => ({
+ id,
+ sortOrder: Number(sortOrderString),
+ updatedBy: userId,
+ })
+ );
+
+ const updateSortOrders = await updateQuoteOperationStepOrder(client, updates);
+ if (updateSortOrders.some((update) => update.error))
+ return json(
+ {},
+ await flash(
+ request,
+ error(updateSortOrders, "Failed to update sort order")
+ )
+ );
+
+ return json({ success: true });
+}
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.tsx
index 9ed682409c..347ba51121 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
@@ -118,6 +118,7 @@ export default function EditSalesInvoiceLineRoute() {
methodType: (salesInvoiceLine?.methodType ?? "Pick") as "Pick",
itemId: salesInvoiceLine?.itemId ?? "",
accountNumber: salesInvoiceLine?.accountNumber ?? "",
+ addOnCost: salesInvoiceLine?.addOnCost ?? 0,
assetId: salesInvoiceLine?.assetId ?? "",
description: salesInvoiceLine?.description ?? "",
quantity: salesInvoiceLine?.quantity ?? 1,
@@ -137,6 +138,7 @@ export default function EditSalesInvoiceLineRoute() {
<SalesInvoiceLineForm
key={initialValues.id}
initialValues={initialValues}
+ isSalesOrderLine={salesInvoiceLine?.salesOrderLineId !== undefined}
/>
<OpportunityLineNotes
id={salesInvoiceLine?.id ?? ""}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 12985317ed..8f221d608a 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -747,6 +747,8 @@ export const path = {
generatePath(`${x}/job/methods/${jobId}/operation/delete`),
jobOperationStep: (id: string) =>
generatePath(`${x}/job/methods/operation/step/${id}`),
+ jobOperationStepOrder: (operationId: string) =>
+ generatePath(`${x}/job/methods/operation/${operationId}/step/order`),
jobOperationParameter: (id: string) =>
generatePath(`${x}/job/methods/operation/parameter/${id}`),
jobOperationProcedureSync: `${x}/job/methods/operation/procedure/sync`,
@@ -821,6 +823,8 @@ export const path = {
methodOperationsDelete: `${x}/items/methods/operation/delete`,
methodOperationStep: (id: string) =>
generatePath(`${x}/items/methods/operation/step/${id}`),
+ methodOperationStepOrder: (operationId: string) =>
+ generatePath(`${x}/items/methods/operation/${operationId}/step/order`),
methodOperationParameter: (id: string) =>
generatePath(`${x}/items/methods/operation/parameter/${id}`),
methodOperationTool: (id: string) =>
@@ -1131,6 +1135,8 @@ export const path = {
quoteOperationsDelete: `${x}/quote/methods/operation/delete`,
quoteOperationStep: (id: string) =>
generatePath(`${x}/quote/methods/operation/step/${id}`),
+ quoteOperationStepOrder: (operationId: string) =>
+ generatePath(`${x}/quote/methods/operation/${operationId}/step/order`),
quoteOperationParameter: (id: string) =>
generatePath(`${x}/quote/methods/operation/parameter/${id}`),
quoteOperationTool: (id: string) =>
diff --git a/packages/react/src/Card.tsx b/packages/react/src/Card.tsx
index 34009b1ab9..d5eb7a5e70 100644
--- a/packages/react/src/Card.tsx
+++ b/packages/react/src/Card.tsx
@@ -1,6 +1,7 @@
import type { HTMLAttributes } from "react";
import { createContext, forwardRef, useContext, useState } from "react";
import { LuChevronDown, LuChevronUp } from "react-icons/lu";
+import { IconButton } from "./IconButton";
import { cn } from "./utils/cn";
interface CardProps extends HTMLAttributes<HTMLDivElement> {
@@ -51,17 +52,19 @@ const Card = forwardRef<HTMLDivElement, CardProps>(
{...props}
>
{isCollapsible && (
- <button
- type="button"
+ <IconButton
+ aria-label={isCollapsed ? "Expand" : "Collapse"}
+ variant="ghost"
onClick={toggle}
- className="absolute right-4 top-4 p-4 text-muted-foreground hover:text-foreground"
- >
- {isCollapsed ? (
- <LuChevronDown className="w-6 h-6" />
- ) : (
- <LuChevronUp className="w-6 h-6" />
- )}
- </button>
+ className="absolute right-8 top-8"
+ icon={
+ isCollapsed ? (
+ <LuChevronDown className="size-6" />
+ ) : (
+ <LuChevronUp className="size-6" />
+ )
+ }
+ />
)}
{children}
</div>