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: convert to order wizard

Brad Barbindcc551cbe0fc
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
index 3bdf522536..08006cb38f 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -252,14 +252,16 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
: item
)
);
- await supabase
- ?.from("methodOperationWorkInstruction")
- .update({
- content,
- updatedAt: today(getLocalTimeZone()).toString(),
- updatedBy: userId,
- })
- .eq("methodOperationId", selectedItemId!);
+
+ if (selectedItemId !== null && !isTemporaryId(selectedItemId))
+ await supabase
+ ?.from("methodOperationWorkInstruction")
+ .update({
+ content,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("methodOperationId", selectedItemId!);
}, 2000);
const onUploadImage = async (file: File) => {
@@ -318,7 +320,6 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
{
id: 1,
label: "Work Instructions",
- disabled: isTemporaryId(item.id),
content: (
<div className="flex flex-col">
<motion.div
@@ -516,6 +517,7 @@ function OperationForm({
setSelectedItemId: Dispatch<SetStateAction<string | null>>;
}) {
const methodOperationFetcher = useFetcher<{ id: string }>();
+ const { id: userId } = useUser();
const { supabase } = useSupabase();
const permissions = usePermissions();
@@ -538,17 +540,40 @@ function OperationForm({
)
);
});
- setSelectedItemId(null);
+ // save the work instructions
+ if (isTemporaryId(item.id) && supabase) {
+ supabase
+ .from("quoteOperationWorkInstruction")
+ .update({
+ content: item.data.methodOperationWorkInstruction.content,
+ createdAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("quoteOperationId", methodOperationFetcher.data.id)
+ .then(() => {
+ setSelectedItemId(null);
+ });
+ } else {
+ setSelectedItemId(null);
+ }
}
- }, [item.id, methodOperationFetcher.data, setItems, setSelectedItemId]);
+ }, [
+ item.data.methodOperationWorkInstruction.content,
+ item.id,
+ methodOperationFetcher.data,
+ setItems,
+ setSelectedItemId,
+ supabase,
+ userId,
+ ]);
- const [showSetup, setShowSetup] = useState((item.data.setupTime ?? 0) > 0);
const [showMachine, setShowMachine] = useState(
(item.data.machineTime ?? 0) > 0
);
- const [showLabor, setShowLabor] = useState(
- (item.data.laborTime ?? 0) > 0 ||
- (showSetup === false && showMachine === false)
+ const [showLabor, setShowLabor] = useState((item.data.laborTime ?? 0) > 0);
+ const [showSetup, setShowSetup] = useState(
+ (item.data.setupTime ?? 0) > 0 ||
+ (showLabor === false && showMachine === false)
);
const [processData, setProcessData] = useState<{
@@ -738,122 +763,122 @@ function OperationForm({
<div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4">
<HStack
className="w-full justify-between cursor-pointer"
- onClick={() => setShowLabor(!showLabor)}
+ onClick={() => setShowSetup(!showSetup)}
>
<HStack>
- <TimeTypeIcon type="Labor" />
- <Label>Labor</Label>
+ <TimeTypeIcon type="Setup" />
+ <Label>Setup</Label>
</HStack>
<LuChevronDown
className={`transition-transform ${
- showLabor ? "rotate-180" : ""
+ showSetup ? "rotate-180" : ""
}`}
/>
</HStack>
<div
className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
- showLabor ? "" : "hidden"
+ showSetup ? "" : "hidden"
}`}
>
<UnitHint
- name="laborHint"
- label="Labor"
- value={processData.laborUnitHint}
+ name="setupHint"
+ label="Setup"
+ value={processData.setupUnitHint}
onChange={(hint) => {
setProcessData((d) => ({
...d,
- laborUnitHint: hint,
- laborUnit:
+ setupUnitHint: hint,
+ setupUnit:
hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
}));
}}
/>
<NumberControlled
- name="laborTime"
- label="Labor Time"
+ name="setupTime"
+ label="Setup Time"
minValue={0}
- value={processData.laborTime}
+ value={processData.setupTime}
onChange={(newValue) =>
setProcessData((d) => ({
...d,
- laborTime: newValue,
+ setupTime: newValue,
}))
}
/>
<StandardFactor
- name="laborUnit"
- label="Labor Unit"
- hint={processData.laborUnitHint}
- value={processData.laborUnit}
+ name="setupUnit"
+ label="Setup Unit"
+ hint={processData.setupUnitHint}
+ value={processData.setupUnit}
onChange={(newValue) => {
setProcessData((d) => ({
...d,
- laborUnit: newValue?.value ?? "Total Minutes",
+ setupUnit: newValue?.value ?? "Total Minutes",
}));
}}
/>
</div>
</div>
+
<div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4">
<HStack
className="w-full justify-between cursor-pointer"
- onClick={() => setShowSetup(!showSetup)}
+ onClick={() => setShowLabor(!showLabor)}
>
<HStack>
- <TimeTypeIcon type="Setup" />
- <Label>Setup</Label>
+ <TimeTypeIcon type="Labor" />
+ <Label>Labor</Label>
</HStack>
<LuChevronDown
className={`transition-transform ${
- showSetup ? "rotate-180" : ""
+ showLabor ? "rotate-180" : ""
}`}
/>
</HStack>
<div
className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
- showSetup ? "" : "hidden"
+ showLabor ? "" : "hidden"
}`}
>
<UnitHint
- name="setupHint"
- label="Setup"
- value={processData.setupUnitHint}
+ name="laborHint"
+ label="Labor"
+ value={processData.laborUnitHint}
onChange={(hint) => {
setProcessData((d) => ({
...d,
- setupUnitHint: hint,
- setupUnit:
+ laborUnitHint: hint,
+ laborUnit:
hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
}));
}}
/>
<NumberControlled
- name="setupTime"
- label="Setup Time"
+ name="laborTime"
+ label="Labor Time"
minValue={0}
- value={processData.setupTime}
+ value={processData.laborTime}
onChange={(newValue) =>
setProcessData((d) => ({
...d,
- setupTime: newValue,
+ laborTime: newValue,
}))
}
/>
<StandardFactor
- name="setupUnit"
- label="Setup Unit"
- hint={processData.setupUnitHint}
- value={processData.setupUnit}
+ name="laborUnit"
+ label="Labor Unit"
+ hint={processData.laborUnitHint}
+ value={processData.laborUnit}
onChange={(newValue) => {
setProcessData((d) => ({
...d,
- setupUnit: newValue?.value ?? "Total Minutes",
+ laborUnit: newValue?.value ?? "Total Minutes",
}));
}}
/>
</div>
</div>
-
<div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4">
<HStack
className="w-full justify-between cursor-pointer"
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index f3b83be386..f167dcea59 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -536,6 +536,7 @@ function OperationForm({
setSelectedItemId: Dispatch<SetStateAction<string | null>>;
}) {
const { quoteId, lineId } = useParams();
+ const { id: userId } = useUser();
if (!quoteId) throw new Error("quoteId not found");
if (!lineId) throw new Error("lineId not found");
@@ -561,18 +562,43 @@ function OperationForm({
)
);
});
- setSelectedItemId(null);
+
+ // save the work instructions
+ if (isTemporaryId(item.id) && supabase) {
+ supabase
+ .from("quoteOperationWorkInstruction")
+ .update({
+ content: item.data.quoteOperationWorkInstruction.content,
+ createdAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("quoteOperationId", fetcher.data.id)
+ .then(() => {
+ setSelectedItemId(null);
+ });
+ } else {
+ setSelectedItemId(null);
+ }
}
- }, [item.id, fetcher.data, setItems, setSelectedItemId]);
+ }, [
+ item.id,
+ fetcher.data,
+ setItems,
+ setSelectedItemId,
+ item.data.quoteOperationWorkInstruction.content,
+ supabase,
+ userId,
+ ]);
- const [showSetup, setShowSetup] = useState((item.data.setupTime ?? 0) > 0);
const [showMachine, setShowMachine] = useState(
(item.data.machineTime ?? 0) > 0
);
- const [showLabor, setShowLabor] = useState(
- (item.data.laborTime ?? 0) > 0 ||
- (showSetup === false && showMachine === false)
+ const [showLabor, setShowLabor] = useState((item.data.laborTime ?? 0) > 0);
+ const [showSetup, setShowSetup] = useState(
+ (item.data.setupTime ?? 0) > 0 ||
+ (showLabor === false && showMachine === false)
);
+
const [showCost, setShowCost] = useState(false);
const [processData, setProcessData] = useState<{
@@ -887,57 +913,57 @@ function OperationForm({
<div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4">
<HStack
className="w-full justify-between cursor-pointer"
- onClick={() => setShowLabor(!showLabor)}
+ onClick={() => setShowSetup(!showSetup)}
>
<HStack>
- <TimeTypeIcon type="Labor" />
- <Label>Labor</Label>
+ <TimeTypeIcon type="Setup" />
+ <Label>Setup</Label>
</HStack>
<LuChevronDown
className={`transition-transform ${
- showLabor ? "rotate-180" : ""
+ showSetup ? "rotate-180" : ""
}`}
/>
</HStack>
<div
className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
- showLabor ? "" : "hidden"
+ showSetup ? "" : "hidden"
}`}
>
<UnitHint
- name="laborHint"
- label="Labor"
- value={processData.laborUnitHint}
+ name="setupHint"
+ label="Setup"
+ value={processData.setupUnitHint}
onChange={(hint) => {
setProcessData((d) => ({
...d,
- laborUnitHint: hint,
- laborUnit:
+ setupUnitHint: hint,
+ setupUnit:
hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
}));
}}
/>
<NumberControlled
- name="laborTime"
- label="Labor Time"
+ name="setupTime"
+ label="Setup Time"
minValue={0}
- value={processData.laborTime}
+ value={processData.setupTime}
onChange={(newValue) =>
setProcessData((d) => ({
...d,
- laborTime: newValue,
+ setupTime: newValue,
}))
}
/>
<StandardFactor
- name="laborUnit"
- label="Labor Unit"
- hint={processData.laborUnitHint}
- value={processData.laborUnit}
+ name="setupUnit"
+ label="Setup Unit"
+ hint={processData.setupUnitHint}
+ value={processData.setupUnit}
onChange={(newValue) => {
setProcessData((d) => ({
...d,
- laborUnit: newValue?.value ?? "Total Minutes",
+ setupUnit: newValue?.value ?? "Total Minutes",
}));
}}
/>
@@ -946,57 +972,57 @@ function OperationForm({
<div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4">
<HStack
className="w-full justify-between cursor-pointer"
- onClick={() => setShowSetup(!showSetup)}
+ onClick={() => setShowLabor(!showLabor)}
>
<HStack>
- <TimeTypeIcon type="Setup" />
- <Label>Setup</Label>
+ <TimeTypeIcon type="Labor" />
+ <Label>Labor</Label>
</HStack>
<LuChevronDown
className={`transition-transform ${
- showSetup ? "rotate-180" : ""
+ showLabor ? "rotate-180" : ""
}`}
/>
</HStack>
<div
className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
- showSetup ? "" : "hidden"
+ showLabor ? "" : "hidden"
}`}
>
<UnitHint
- name="setupHint"
- label="Setup"
- value={processData.setupUnitHint}
+ name="laborHint"
+ label="Labor"
+ value={processData.laborUnitHint}
onChange={(hint) => {
setProcessData((d) => ({
...d,
- setupUnitHint: hint,
- setupUnit:
+ laborUnitHint: hint,
+ laborUnit:
hint === "Fixed" ? "Total Minutes" : "Minutes/Piece",
}));
}}
/>
<NumberControlled
- name="setupTime"
- label="Setup Time"
+ name="laborTime"
+ label="Labor Time"
minValue={0}
- value={processData.setupTime}
+ value={processData.laborTime}
onChange={(newValue) =>
setProcessData((d) => ({
...d,
- setupTime: newValue,
+ laborTime: newValue,
}))
}
/>
<StandardFactor
- name="setupUnit"
- label="Setup Unit"
- hint={processData.setupUnitHint}
- value={processData.setupUnit}
+ name="laborUnit"
+ label="Labor Unit"
+ hint={processData.laborUnitHint}
+ value={processData.laborUnit}
onChange={(newValue) => {
setProcessData((d) => ({
...d,
- setupUnit: newValue?.value ?? "Total Minutes",
+ laborUnit: newValue?.value ?? "Total Minutes",
}));
}}
/>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx
index 695759648a..902ef484ae 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx
@@ -177,14 +177,14 @@ const QuoteHeader = () => {
onClose={finalizeModal.onClose}
/>
)}
- {convertToOrderModal.isOpen && (
- <QuoteToOrderModal
- onClose={convertToOrderModal.onClose}
- quote={routeData?.quote!}
- lines={routeData?.lines ?? []}
- pricing={routeData?.prices ?? []}
- />
- )}
+ {/* we use isOpen so we don't lose state */}
+ <QuoteToOrderModal
+ isOpen={convertToOrderModal.isOpen}
+ onClose={convertToOrderModal.onClose}
+ quote={routeData?.quote!}
+ lines={routeData?.lines ?? []}
+ pricing={routeData?.prices ?? []}
+ />
</>
);
};
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
index 0d41fb35e5..4d09cc9acf 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
@@ -446,7 +446,7 @@ const QuoteLineCosting = ({
<Td className="border-r border-border ">
<HStack className="w-full justify-between ">
<span>Total Indirect Cost</span>
- <Enumerable value="Overhead" />
+ <Enumerable value="Indirect" />
</HStack>
</Td>
{quantityCosts.map(({ quantity, costs }, index) => {
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx
index 0b9a2287ee..face5b2a14 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx
@@ -1,5 +1,6 @@
import {
Button,
+ cn,
Drawer,
DrawerBody,
DrawerContent,
@@ -8,6 +9,7 @@ import {
DrawerTitle,
Heading,
HStack,
+ Label,
NumberField,
NumberInput,
RadioGroup,
@@ -22,12 +24,22 @@ import {
} from "@carbon/react";
import { Form } from "@remix-run/react";
import { useMemo, useState } from "react";
-import { LuImage } from "react-icons/lu";
+import { useDropzone } from "react-dropzone";
+import {
+ LuBan,
+ LuChevronDown,
+ LuCreditCard,
+ LuImage,
+ LuTruck,
+ LuUpload,
+ LuUserSquare,
+} from "react-icons/lu";
import { useCurrencyFormatter } from "~/hooks/useCurrencyFormatter";
import { path } from "~/utils/path";
import type { Quotation, QuotationLine, QuotationPrice } from "../../types";
type QuoteToOrderDrawerProps = {
+ isOpen: boolean;
quote: Quotation;
lines: QuotationLine[];
pricing: QuotationPrice[];
@@ -35,20 +47,14 @@ type QuoteToOrderDrawerProps = {
};
const QuoteToOrderDrawer = ({
+ isOpen,
quote,
lines,
pricing,
onClose,
}: QuoteToOrderDrawerProps) => {
- const pricingByLine = useMemo(
- () =>
- lines.reduce<Record<string, QuotationPrice[]>>((acc, line) => {
- acc[line.id!] = pricing.filter((p) => p.quoteLineId === line.id);
- return acc;
- }, {}),
- [lines, pricing]
- );
- const formatter = useCurrencyFormatter();
+ const [step, setStep] = useState(0);
+ const [purchaseOrder, setPurchaseOrder] = useState<File | null>(null);
const [selectedLines, setSelectedLines] = useState<
Record<
string,
@@ -60,10 +66,95 @@ const QuoteToOrderDrawer = ({
}
>
>({});
+ const [customerDetails, setCustomerDetails] = useState({});
+ const [paymentDetails, setPaymentDetails] = useState({
+ // Add default payment details from customerPayment table
+ });
+ const [shippingDetails, setShippingDetails] = useState({
+ // Add default shipping details from customerShipping table
+ });
+
+ const onDrop = (acceptedFiles: File[]) => {
+ if (acceptedFiles.length > 0) {
+ setPurchaseOrder(acceptedFiles[0]);
+ }
+ };
+
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
+ onDrop,
+ accept: { "application/pdf": [".pdf"] },
+ maxFiles: 1,
+ });
+
+ const titles = [
+ "Upload Purchase Order",
+ "Select Quantities",
+ "Confirm Details",
+ ];
+ const renderStep = () => {
+ switch (step) {
+ case 0:
+ return (
+ <VStack spacing={4}>
+ <div
+ {...getRootProps()}
+ className={cn(
+ "w-full border-2 border-dashed rounded-lg p-8 text-center cursor-pointer",
+ isDragActive ? "border-primary" : "border-muted"
+ )}
+ >
+ <input {...getInputProps()} />
+ {purchaseOrder ? (
+ <p>{purchaseOrder.name}</p>
+ ) : (
+ <p>Drag and drop a PDF file here, or click to select a file</p>
+ )}
+ <LuUpload className="mx-auto mt-4 h-12 w-12 text-muted-foreground" />
+ </div>
+ <Button
+ className="w-full"
+ leftIcon={<LuBan />}
+ size="lg"
+ variant="secondary"
+ onClick={() => setStep(1)}
+ >
+ Skip
+ </Button>
+ </VStack>
+ );
+ case 1:
+ return (
+ <LinePricingForm
+ lines={lines}
+ pricing={pricing}
+ setSelectedLines={setSelectedLines}
+ />
+ );
+ case 2:
+ return (
+ <VStack spacing={4}>
+ <CustomerDetailsForm
+ customerDetails={customerDetails}
+ setCustomerDetails={setCustomerDetails}
+ />
+ <PaymentDetailsForm
+ paymentDetails={paymentDetails}
+ setPaymentDetails={setPaymentDetails}
+ />
+ <ShippingDetailsForm
+ shippingDetails={shippingDetails}
+ setShippingDetails={setShippingDetails}
+ />
+ </VStack>
+ );
+ default:
+ return null;
+ }
+ };
return (
<Drawer
- open
+ open={isOpen}
onOpenChange={(open) => {
if (!open) {
onClose();
@@ -71,54 +162,38 @@ const QuoteToOrderDrawer = ({
}}
>
<Form action={path.to.convertQuoteToOrder(quote.id!)} method="post">
- <DrawerContent size="xl">
+ <DrawerContent size={step === 1 ? "xl" : "md"}>
<input type="hidden" name="quoteId" value={quote.id!} />
<input
type="hidden"
name="selectedLines"
value={JSON.stringify(selectedLines)}
/>
+ <input
+ type="hidden"
+ name="paymentDetails"
+ value={JSON.stringify(paymentDetails)}
+ />
+ <input
+ type="hidden"
+ name="shippingDetails"
+ value={JSON.stringify(shippingDetails)}
+ />
<DrawerHeader>
- <DrawerTitle>Convert to Order</DrawerTitle>
+ <DrawerTitle>{titles[step]}</DrawerTitle>
</DrawerHeader>
- <DrawerBody>
- <VStack spacing={8}>
- {lines.map((line) => (
- <VStack key={line.id}>
- <HStack spacing={2} className="items-start">
- {line.thumbnailPath ? (
- <img
- alt={line.itemReadableId!}
- className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent"
- src={`/file/preview/private/${line.thumbnailPath}`}
- />
- ) : (
- <div className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2">
- <LuImage className="w-16 h-16 text-muted-foreground" />
- </div>
- )}
-
- <VStack spacing={0}>
- <Heading>{line.itemReadableId}</Heading>
- <span className="text-muted-foreground text-base truncate">
- {line.description}
- </span>
- </VStack>
- </HStack>
- <LinePricingForm
- line={line}
- options={pricingByLine[line.id!]}
- formatter={formatter}
- />
- </VStack>
- ))}
- </VStack>
- </DrawerBody>
+ <DrawerBody>{renderStep()}</DrawerBody>
<DrawerFooter>
- <Button variant="secondary" onClick={onClose}>
- Cancel
- </Button>
- <Button>Convert</Button>
+ {step > 0 && (
+ <Button variant="secondary" onClick={() => setStep(step - 1)}>
+ Back
+ </Button>
+ )}
+ {step < 2 ? (
+ <Button onClick={() => setStep(step + 1)}>Next</Button>
+ ) : (
+ <Button type="submit">Convert</Button>
+ )}
</DrawerFooter>
</DrawerContent>
</Form>
@@ -129,11 +204,99 @@ const QuoteToOrderDrawer = ({
export default QuoteToOrderDrawer;
type LinePricingFormProps = {
+ lines: QuotationLine[];
+ pricing: QuotationPrice[];
+ setSelectedLines: React.Dispatch<
+ React.SetStateAction<
+ Record<
+ string,
+ {
+ quantity: number;
+ unitPrice: number;
+ totalPrice: number;
+ leadTime: number;
+ }
+ >
+ >
+ >;
+};
+
+const LinePricingForm = ({
+ lines,
+ pricing,
+ setSelectedLines,
+}: LinePricingFormProps) => {
+ const pricingByLine = useMemo(
+ () =>
+ lines.reduce<Record<string, QuotationPrice[]>>((acc, line) => {
+ acc[line.id!] = pricing.filter((p) => p.quoteLineId === line.id);
+ return acc;
+ }, {}),
+ [lines, pricing]
+ );
+ const formatter = useCurrencyFormatter();
+
+ return (
+ <VStack spacing={8}>
+ {lines.map((line) => (
+ <VStack key={line.id}>
+ <HStack spacing={2} className="items-start">
+ {line.thumbnailPath ? (
+ <img
+ alt={line.itemReadableId!}
+ className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent"
+ src={`/file/preview/private/${line.thumbnailPath}`}
+ />
+ ) : (
+ <div className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2">
+ <LuImage className="w-16 h-16 text-muted-foreground" />
+ </div>
+ )}
+
+ <VStack spacing={0}>
+ <Heading>{line.itemReadableId}</Heading>
+ <span className="text-muted-foreground text-base truncate">
+ {line.description}
+ </span>
+ </VStack>
+ </HStack>
+ <LinePricingOptions
+ line={line}
+ options={pricingByLine[line.id!]}
+ formatter={formatter}
+ setSelectedLines={setSelectedLines}
+ />
+ </VStack>
+ ))}
+ </VStack>
+ );
+};
+
+type LinePricingOptionsProps = {
line: QuotationLine;
options: QuotationPrice[];
formatter: Intl.NumberFormat;
+ setSelectedLines: React.Dispatch<
+ React.SetStateAction<
+ Record<
+ string,
+ {
+ quantity: number;
+ unitPrice: number;
+ totalPrice: number;
+ leadTime: number;
+ }
+ >
+ >
+ >;
};
-function LinePricingForm({ line, options, formatter }: LinePricingFormProps) {
+
+const LinePricingOptions = ({
+ line,
+ options,
+ formatter,
+ setSelectedLines,
+}: LinePricingOptionsProps) => {
const [showOverride, setShowOverride] = useState(false);
const [overridePricing, setOverridePricing] = useState({
quantity: 1,
@@ -181,6 +344,19 @@ function LinePricingForm({ line, options, formatter }: LinePricingFormProps) {
<RadioGroupItem
value={option.quantity.toString()}
id={`${line.id}:${option.quantity.toString()}`}
+ onChange={() =>
+ setSelectedLines((prev) => ({
+ ...prev,
+ [line.id!]: {
+ quantity: option.quantity,
+ unitPrice: option.unitPrice,
+ totalPrice:
+ option.unitPrice * option.quantity +
+ additionalChargesByQuantity[index],
+ leadTime: option.leadTime,
+ },
+ }))
+ }
/>
<label
htmlFor={`${line.id}:${option.quantity.toString()}`}
@@ -291,4 +467,93 @@ function LinePricingForm({ line, options, formatter }: LinePricingFormProps) {
)}
</VStack>
);
+};
+
+interface PaymentDetailsFormProps {
+ paymentDetails: PaymentDetails;
+ setPaymentDetails: React.Dispatch<React.SetStateAction<PaymentDetails>>;
+}
+
+function PaymentDetailsForm({
+ paymentDetails,
+ setPaymentDetails,
+}: PaymentDetailsFormProps) {
+ const [isExpanded, setIsExpanded] = useState(false);
+
+ return (
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={() => setIsExpanded(!isExpanded)}
+ >
+ <HStack>
+ <LuCreditCard />
+ <Label>Payment Terms</Label>
+ </HStack>
+ <LuChevronDown
+ className={`transition-transform ${isExpanded ? "rotate-180" : ""}`}
+ />
+ </HStack>
+ {isExpanded && <div className="py-4"></div>}
+ </div>
+ );
+}
+interface CustomerDetailsFormProps {
+ customerDetails: CustomerDetails;
+ setCustomerDetails: React.Dispatch<React.SetStateAction<CustomerDetails>>;
+}
+
+function CustomerDetailsForm({
+ customerDetails,
+ setCustomerDetails,
+}: CustomerDetailsFormProps) {
+ const [isExpanded, setIsExpanded] = useState(false);
+
+ return (
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={() => setIsExpanded(!isExpanded)}
+ >
+ <HStack>
+ <LuUserSquare />
+ <Label>Customer Details</Label>
+ </HStack>
+ <LuChevronDown
+ className={`transition-transform ${isExpanded ? "rotate-180" : ""}`}
+ />
+ </HStack>
+ {isExpanded && <div className="py-4"></div>}
+ </div>
+ );
+}
+
+interface ShippingDetailsFormProps {
+ shippingDetails: ShippingDetails;
+ setShippingDetails: React.Dispatch<React.SetStateAction<ShippingDetails>>;
+}
+
+function ShippingDetailsForm({
+ shippingDetails,
+ setShippingDetails,
+}: ShippingDetailsFormProps) {
+ const [isExpanded, setIsExpanded] = useState(false);
+
+ return (
+ <div className="border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 w-full">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={() => setIsExpanded(!isExpanded)}
+ >
+ <HStack>
+ <LuTruck />
+ <Label>Shipping</Label>
+ </HStack>
+ <LuChevronDown
+ className={`transition-transform ${isExpanded ? "rotate-180" : ""}`}
+ />
+ </HStack>
+ {isExpanded && <div className="py-4"></div>}
+ </div>
+ );
}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
index cd8673466a..c16cfd6b07 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
@@ -92,6 +92,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
...o,
description: o.description ?? "",
workCenterId: o.workCenterId ?? undefined,
+ laborRate: o.laborRate ?? 0,
+ machineRate: o.machineRate ?? 0,
+ operationSupplierProcessId: o.operationSupplierProcessId ?? undefined,
quoteMakeMethodId: o.quoteMakeMethodId ?? methodId,
quoteOperationWorkInstruction: {
content: (o.quoteOperationWorkInstruction?.content ??
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
index 6801328f67..bc544d1938 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
@@ -63,6 +63,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
...o,
description: o.description ?? "",
workCenterId: o.workCenterId ?? undefined,
+ laborRate: o.laborRate ?? 0,
+ machineRate: o.machineRate ?? 0,
+ operationSupplierProcessId: o.operationSupplierProcessId ?? undefined,
quoteMakeMethodId: o.quoteMakeMethodId ?? methodId,
quoteOperationWorkInstruction: {
content: (o.quoteOperationWorkInstruction?.content ??
diff --git a/package-lock.json b/package-lock.json
index 4006f92ea8..c602b112cb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,6 +9,9 @@
"ci",
"packages/*"
],
+ "dependencies": {
+ "@xyflow/react": "^12.2.0"
+ },
"devDependencies": {
"eslint": "^8.23.1",
"eslint-config-carbon": "*",
@@ -10520,6 +10523,14 @@
"resolved": "https://registry.npmjs.org/@types/d3-delaunay/-/d3-delaunay-6.0.1.tgz",
"integrity": "sha512-tLxQ2sfT0p6sxdG75c6f/ekqxjyYR0+LwPrsO1mbC9YDBzPJhs2HbJJRrn8Ez1DBoHRo2yx7YEATI+8V1nGMnQ=="
},
+ "node_modules/@types/d3-drag": {
+ "version": "3.0.7",
+ "resolved": "https://registry.npmjs.org/@types/d3-drag/-/d3-drag-3.0.7.tgz",
+ "integrity": "sha512-HE3jVKlzU9AaMazNufooRJ5ZpWmLIoc90A37WU2JMmeq28w1FQqCZswHZ3xR+SuxYftzHq6WU6KJHvqxKzTxxQ==",
+ "dependencies": {
+ "@types/d3-selection": "*"
+ }
+ },
"node_modules/@types/d3-format": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/d3-format/-/d3-format-3.0.1.tgz",
@@ -10551,6 +10562,11 @@
"resolved": "https://registry.npmjs.org/@types/d3-scale-chromatic/-/d3-scale-chromatic-3.0.3.tgz",
"integrity": "sha512-laXM4+1o5ImZv3RpFAsTRn3TEkzqkytiOY0Dz0sq5cnd1dtNlk6sHLon4OvqaiJb28T0S/TdsBI3Sjsy+keJrw=="
},
+ "node_modules/@types/d3-selection": {
+ "version": "3.0.10",
+ "resolved": "https://registry.npmjs.org/@types/d3-selection/-/d3-selection-3.0.10.tgz",
+ "integrity": "sha512-cuHoUgS/V3hLdjJOLTT691+G2QoqAjCVLmr4kJXR4ha56w1Zdu8UUQ5TxLRqudgNjwXeQxKMq4j+lyf9sWuslg=="
+ },
"node_modules/@types/d3-shape": {
"version": "1.3.12",
"resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-1.3.12.tgz",
@@ -10569,6 +10585,23 @@
"resolved": "https://registry.npmjs.org/@types/d3-time-format/-/d3-time-format-2.1.0.tgz",
"integrity": "sha512-/myT3I7EwlukNOX2xVdMzb8FRgNzRMpsZddwst9Ld/VFe6LyJyRp0s32l/V9XoUzk+Gqu56F/oGk6507+8BxrA=="
},
+ "node_modules/@types/d3-transition": {
+ "version": "3.0.8",
+ "resolved": "https://registry.npmjs.org/@types/d3-transition/-/d3-transition-3.0.8.tgz",
+ "integrity": "sha512-ew63aJfQ/ms7QQ4X7pk5NxQ9fZH/z+i24ZfJ6tJSfqxJMrYLiK01EAs2/Rtw/JreGUsS3pLPNV644qXFGnoZNQ==",
+ "dependencies": {
+ "@types/d3-selection": "*"
+ }
+ },
+ "node_modules/@types/d3-zoom": {
+ "version": "3.0.8",
+ "resolved": "https://registry.npmjs.org/@types/d3-zoom/-/d3-zoom-3.0.8.tgz",
+ "integrity": "sha512-iqMC4/YlFCSlO8+2Ii1GGGliCAY4XdeG748w5vQUbevlbDu0zSjH/+jojorQVBK/se0j6DUFNPBGSqD3YWYnDw==",
+ "dependencies": {
+ "@types/d3-interpolate": "*",
+ "@types/d3-selection": "*"
+ }
+ },
"node_modules/@types/debug": {
"version": "4.1.12",
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz",
@@ -11572,6 +11605,34 @@
"resolved": "https://registry.npmjs.org/@web3-storage/multipart-parser/-/multipart-parser-1.0.0.tgz",
"integrity": "sha512-BEO6al7BYqcnfX15W2cnGR+Q566ACXAT9UQykORCWW80lmkpWsnEob6zJS1ZVBKsSJC8+7vJkHwlp+lXG1UCdw=="
},
+ "node_modules/@xyflow/react": {
+ "version": "12.2.0",
+ "resolved": "https://registry.npmjs.org/@xyflow/react/-/react-12.2.0.tgz",
+ "integrity": "sha512-aQ1636zCfTey+k2d4xxkQrfwMWe0uazIJoKUXyCoVTX+KH5/ep9wxr7yGlSW4s1XIGzmP3f+qUwTk0GvxvP0Rg==",
+ "dependencies": {
+ "@xyflow/system": "0.0.40",
+ "classcat": "^5.0.3",
+ "zustand": "^4.4.0"
+ },
+ "peerDependencies": {
+ "react": ">=17",
+ "react-dom": ">=17"
+ }
+ },
+ "node_modules/@xyflow/system": {
+ "version": "0.0.40",
+ "resolved": "https://registry.npmjs.org/@xyflow/system/-/system-0.0.40.tgz",
+ "integrity": "sha512-pS4m6J+Q+kUoUV73rKMfGPm+FOA9OajHyADrTlTE6VaG4/vMV2gHS/ZMVZb295jkY/ZpZkpQZKp1sRm0m31Jpw==",
+ "dependencies": {
+ "@types/d3-drag": "^3.0.7",
+ "@types/d3-selection": "^3.0.10",
+ "@types/d3-transition": "^3.0.8",
+ "@types/d3-zoom": "^3.0.8",
+ "d3-drag": "^3.0.0",
+ "d3-selection": "^3.0.0",
+ "d3-zoom": "^3.0.0"
+ }
+ },
"node_modules/@zxing/text-encoding": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz",
@@ -13073,6 +13134,11 @@
"node": ">=6"
}
},
+ "node_modules/classcat": {
+ "version": "5.0.5",
+ "resolved": "https://registry.npmjs.org/classcat/-/classcat-5.0.5.tgz",
+ "integrity": "sha512-JhZUT7JFcQy/EzW605k/ktHtncoo9vnyW/2GspNYwFlN1C/WmjuV/xtS04e9SOkL2sTdw0VAZ2UGCcQ9lR6p6w=="
+ },
"node_modules/classnames": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
diff --git a/package.json b/package.json
index 341e45056a..0b0222383d 100755
--- a/package.json
+++ b/package.json
@@ -65,5 +65,8 @@
"apps/*",
"ci",
"packages/*"
- ]
+ ],
+ "dependencies": {
+ "@xyflow/react": "^12.2.0"
+ }
}
diff --git a/packages/utils/src/duration.ts b/packages/utils/src/duration.ts
index 7bd45d7116..a1750bea71 100644
--- a/packages/utils/src/duration.ts
+++ b/packages/utils/src/duration.ts
@@ -30,6 +30,7 @@ export function formatDurationHours(
hours: number,
options?: DurationOptions
): string {
+ if (hours === 0) return "-";
return formatDurationMilliseconds(hours * 1000 * 60 * 60, options);
}