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: add additional charges and quote line quantities

Brad Barbin3dc6fa11b961
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index 392cd502f3..84be7f53de 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -91,6 +91,13 @@ export const quoteValidator = z.object({
expirationDate: zfd.text(z.string().optional()),
});
+export const quoteLineAdditionalChargesValidator = z.record(
+ z.object({
+ description: z.string(),
+ amounts: z.record(z.number()),
+ })
+);
+
export const quoteLineValidator = z.object({
id: zfd.text(z.string().optional()),
quoteId: z.string(),
@@ -109,6 +116,9 @@ export const quoteLineValidator = z.object({
unitOfMeasureCode: zfd.text(
z.string().min(1, { message: "Unit of measure is required" })
),
+ quantity: z.array(
+ zfd.numeric(z.number().min(0.00001, { message: "Quantity is required" }))
+ ),
modelUploadId: zfd.text(z.string().optional()),
});
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 7ec1bfa4d9..063795ccee 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -15,6 +15,7 @@ import type {
customerTypeValidator,
customerValidator,
quotationPricingValidator,
+ quoteLineAdditionalChargesValidator,
quoteLineValidator,
quoteMaterialValidator,
quoteOperationValidator,
@@ -1339,6 +1340,17 @@ export async function upsertQuoteLine(
return client.from("quoteLine").insert([quotationLine]).select("*").single();
}
+export async function upsertQuoteLineAdditionalCharges(
+ client: SupabaseClient<Database>,
+ lineId: string,
+ update: {
+ additionalCharges: z.infer<typeof quoteLineAdditionalChargesValidator>;
+ updatedBy: string;
+ }
+) {
+ return client.from("quoteLine").update(update).eq("id", lineId);
+}
+
export async function updateQuoteLinePrice(
client: SupabaseClient<Database>,
quoteLinePrice: z.infer<typeof quotationPricingValidator> & {
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
index a57842abf0..7165f1a13d 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
@@ -1,10 +1,13 @@
+import type { Json } from "@carbon/database";
import {
+ Button,
Card,
CardContent,
CardHeader,
CardTitle,
Enumerable,
HStack,
+ Input,
Table,
Tbody,
Td,
@@ -14,10 +17,16 @@ import {
Tr,
VStack,
} from "@carbon/react";
-import { useParams } from "@remix-run/react";
-import { useCallback, useMemo, useState } from "react";
+import { useFetcher, useParams } from "@remix-run/react";
+import { useCallback, useMemo } from "react";
+import { LuPlus, LuTrash } from "react-icons/lu";
import type { Tree } from "~/components/TreeView";
-import type { QuotationOperation, QuoteMethod } from "~/modules/sales";
+import {
+ quoteLineAdditionalChargesValidator,
+ type QuotationOperation,
+ type QuoteMethod,
+} from "~/modules/sales";
+import { path } from "~/utils/path";
type Costs = {
materialCost: number;
@@ -248,12 +257,20 @@ function useLineCosts({
const QuoteLineCosting = ({
methodTree,
operations,
+ quantities,
+ additionalCharges: additionalChargesJson,
}: {
methodTree?: Tree<QuoteMethod>;
operations: QuotationOperation[];
+ quantities: number[];
+ additionalCharges?: Json;
}) => {
+ const { quoteId, lineId } = useParams();
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const fetcher = useFetcher<{ id: string }>();
const getLineCosts = useLineCosts({ methodTree, operations });
- const [quantities] = useState([1, 25, 50, 100]);
const quantityCosts = quantities.map((quantity) => ({
quantity,
@@ -267,6 +284,21 @@ const QuoteLineCosting = ({
[]
);
+ const parsedAdditionalCharges = quoteLineAdditionalChargesValidator.safeParse(
+ additionalChargesJson
+ );
+ const additionalCharges = parsedAdditionalCharges.success
+ ? parsedAdditionalCharges.data
+ : {};
+
+ const additionalChargesByQuantity = quantities.map((quantity) => {
+ const charges = Object.values(additionalCharges).reduce((acc, charge) => {
+ const amount = charge.amounts?.[quantity] ?? 0;
+ return acc + amount;
+ }, 0);
+ return charges;
+ });
+
return (
<Card>
<CardHeader>
@@ -278,9 +310,7 @@ const QuoteLineCosting = ({
<Tr>
<Th />
{quantities.map((quantity) => (
- <Th key={quantity.toString()} className="font-mono">
- {quantity}
- </Th>
+ <Th key={quantity.toString()}>{quantity}</Th>
))}
</Tr>
</Thead>
@@ -294,7 +324,7 @@ const QuoteLineCosting = ({
</Td>
{quantityCosts.map(({ quantity, costs }) => {
return (
- <Td key={quantity.toString()} className="font-mono">
+ <Td key={quantity.toString()}>
<VStack spacing={0}>
<span>
{costs.materialCost
@@ -320,7 +350,7 @@ const QuoteLineCosting = ({
</Td>
{quantityCosts.map(({ quantity, costs }) => {
return (
- <Td key={quantity.toString()} className="font-mono">
+ <Td key={quantity.toString()}>
<VStack spacing={0}>
<span>
{costs.overheadCost
@@ -350,7 +380,7 @@ const QuoteLineCosting = ({
</Td>
{quantityCosts.map(({ quantity, costs }) => {
return (
- <Td key={quantity.toString()} className="font-mono">
+ <Td key={quantity.toString()} >
<VStack spacing={0}>
<span>
{costs.outsideCost
@@ -367,18 +397,122 @@ const QuoteLineCosting = ({
);
})}
</Tr> */}
+ {Object.entries(additionalCharges).map(([chargeId, charge]) => {
+ const isDeleting =
+ fetcher.state === "loading" &&
+ fetcher.formAction ===
+ path.to.deleteQuoteLineCost(quoteId, lineId) &&
+ fetcher.formData?.get("id") === chargeId;
+ return (
+ <Tr key={chargeId}>
+ <Td className="border-r border-border">
+ <HStack className="w-full justify-between ">
+ <Input
+ defaultValue={charge.description}
+ size="sm"
+ className="border-0 -ml-3 shadow-none"
+ />
+ <HStack spacing={1}>
+ <fetcher.Form
+ method="post"
+ action={path.to.deleteQuoteLineCost(quoteId, lineId)}
+ >
+ <input type="hidden" name="id" value={chargeId} />
+ <input
+ type="hidden"
+ name="additionalCharges"
+ value={JSON.stringify(additionalCharges ?? {})}
+ />
+ <Button
+ type="submit"
+ aria-label="Delete"
+ size="sm"
+ variant="secondary"
+ isDisabled={isDeleting}
+ isLoading={isDeleting}
+ >
+ <LuTrash className="w-3 h-3" />
+ </Button>
+ </fetcher.Form>
+ <Enumerable value="Extra" />
+ </HStack>
+ </HStack>
+ </Td>
+ {quantityCosts.map(({ quantity }) => {
+ const amount = charge.amounts?.[quantity] ?? 0;
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {amount
+ ? formatter.format(amount)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {amount && quantity > 0
+ ? formatter.format(amount / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ );
+ })}
+ <Tr>
+ <Td className="border-r border-border">
+ <HStack className="w-full justify-between ">
+ <fetcher.Form
+ method="post"
+ action={path.to.newQuoteLineCost(quoteId, lineId)}
+ >
+ <input
+ type="hidden"
+ name="additionalCharges"
+ value={JSON.stringify(additionalCharges ?? {})}
+ />
+ <Button
+ className="-ml-3"
+ type="submit"
+ rightIcon={<LuPlus />}
+ variant="ghost"
+ isLoading={
+ fetcher.formAction ===
+ path.to.newQuoteLineCost(quoteId, lineId) &&
+ fetcher.state === "loading"
+ }
+ isDisabled={
+ fetcher.formAction ===
+ path.to.newQuoteLineCost(quoteId, lineId) &&
+ fetcher.state === "loading"
+ }
+ >
+ Add
+ </Button>
+ </fetcher.Form>
+ </HStack>
+ </Td>
+ {quantityCosts.map(({ quantity }) => {
+ return <Td key={quantity.toString()}></Td>;
+ })}
+ </Tr>
<Tr className="font-bold">
<Td className="border-r border-border">
<HStack className="w-full justify-between ">
<span>Total Cost</span>
+ <Enumerable value="Total" />
</HStack>
</Td>
- {quantityCosts.map(({ quantity, costs }) => {
+ {quantityCosts.map(({ quantity, costs }, index) => {
const totalCost =
- // costs.materialCost +
- costs.laborCost + costs.overheadCost + costs.outsideCost;
+ costs.materialCost +
+ costs.laborCost +
+ costs.overheadCost +
+ costs.outsideCost +
+ additionalChargesByQuantity[index];
return (
- <Td key={quantity.toString()} className="font-mono">
+ <Td key={quantity.toString()}>
<VStack spacing={0}>
<span>
{totalCost
@@ -400,7 +534,7 @@ const QuoteLineCosting = ({
{/* <Tr className="font-bold">
<Td className="border-r border-border" />
{quantityCosts.map(({ quantity }) => (
- <Td key={quantity} className="font-mono">
+ <Td key={quantity} >
<Button variant="secondary">Add</Button>
</Td>
))}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
index 790394c830..17ae355813 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
@@ -26,6 +26,7 @@ import { BsThreeDotsVertical } from "react-icons/bs";
import { LuDownload, LuTrash, LuUpload } from "react-icons/lu";
import type { z } from "zod";
import {
+ ArrayNumeric,
CustomFormFields,
Hidden,
Input,
@@ -194,59 +195,68 @@ const QuoteLineForm = ({
/>
<VStack>
<div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
- <Item
- name="itemId"
- type="Part"
- label="Part"
- onChange={(value) => {
- onItemChange(value?.value as string);
- }}
- />
+ <div className="col-span-2 grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-2 auto-rows-min">
+ <Item
+ name="itemId"
+ type="Part"
+ label="Part"
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ />
- <InputControlled
- name="description"
- label="Description"
- value={itemData.description}
- onChange={(newValue) =>
- setItemData((d) => ({ ...d, description: newValue }))
- }
- />
+ <InputControlled
+ name="description"
+ label="Description"
+ value={itemData.description}
+ onChange={(newValue) =>
+ setItemData((d) => ({ ...d, description: newValue }))
+ }
+ />
- <SelectControlled
- name="methodType"
- label="Method"
- options={
- methodType.map((m) => ({
- label: m,
- value: m,
- })) ?? []
- }
- value={itemData.methodType}
- onChange={(newValue) => {
- if (newValue)
- setItemData((d) => ({
- ...d,
- methodType: newValue?.value,
- }));
- }}
- />
+ <SelectControlled
+ name="methodType"
+ label="Method"
+ options={
+ methodType.map((m) => ({
+ label: m,
+ value: m,
+ })) ?? []
+ }
+ value={itemData.methodType}
+ onChange={(newValue) => {
+ if (newValue)
+ setItemData((d) => ({
+ ...d,
+ methodType: newValue?.value,
+ }));
+ }}
+ />
- <Input name="customerPartId" label="Customer Part ID" />
- <Input
- name="customerPartRevision"
- label="Customer Part Revision"
- />
+ <Input name="customerPartId" label="Customer Part ID" />
+ <Input
+ name="customerPartRevision"
+ label="Customer Part Revision"
+ />
- <Select
- name="status"
- label="Line Status"
- options={quoteLineStatusType.map((s) => ({
- label: s,
- value: s,
- }))}
- />
+ <Select
+ name="status"
+ label="Line Status"
+ options={quoteLineStatusType.map((s) => ({
+ label: s,
+ value: s,
+ }))}
+ />
- <CustomFormFields table="quoteLine" />
+ <CustomFormFields table="quoteLine" />
+ </div>
+ <div className="flex gap-y-4">
+ <ArrayNumeric
+ name="quantity"
+ label="Quantity"
+ defaults={[1, 25, 50, 100]}
+ />
+ </div>
</div>
</VStack>
</ModalCardBody>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
index d2012079a3..414840b562 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
@@ -7,7 +7,12 @@ import {
toast,
VStack,
} from "@carbon/react";
-import { useFetcher, useNavigate, useParams } from "@remix-run/react";
+import {
+ useFetcher,
+ useLocation,
+ useNavigate,
+ useParams,
+} from "@remix-run/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useEffect, useState } from "react";
@@ -23,7 +28,7 @@ import {
Submit,
UnitOfMeasure,
} from "~/components/Form";
-import { useOptimisticLocation, usePermissions } from "~/hooks";
+import { usePermissions } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
import type { quoteOperationValidator } from "~/modules/sales";
import { quoteMaterialValidator } from "~/modules/sales";
@@ -46,7 +51,7 @@ const QuoteMaterialForm = ({
const { supabase } = useSupabase();
const permissions = usePermissions();
const navigate = useNavigate();
- const location = useOptimisticLocation();
+ const location = useLocation();
const { quoteId, lineId, materialId } = useParams();
if (!quoteId) throw new Error("quoteId not found");
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
index a7d838fd97..c3a0c0e891 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
@@ -717,38 +717,40 @@ function SalesRFQLineForm({
/>
<VStack className="pt-4">
<div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
- <Input
- name="customerPartNumber"
- label="Customer Part Number"
- autoFocus
- />
- <Input name="customerRevisionId" label="Customer Revision" />
- <Item
- name="itemId"
- label="Part"
- type="Part"
- onChange={(value) => {
- onItemChange(value?.value as string);
- }}
- />
- <InputControlled
- name="description"
- label="Description"
- value={itemData.description}
- onChange={(newValue) => {
- setItemData((d) => ({ ...d, description: newValue }));
- }}
- />
- <UnitOfMeasure
- name="unitOfMeasureCode"
- value={itemData.unitOfMeasureCode}
- onChange={(newValue) =>
- setItemData((d) => ({
- ...d,
- unitOfMeasureCode: newValue?.value ?? "EA",
- }))
- }
- />
+ <div className="col-span-2 grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-2 auto-rows-min">
+ <Input
+ name="customerPartNumber"
+ label="Customer Part Number"
+ autoFocus
+ />
+ <Input name="customerRevisionId" label="Customer Revision" />
+ <Item
+ name="itemId"
+ label="Part"
+ type="Part"
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ />
+ <InputControlled
+ name="description"
+ label="Description"
+ value={itemData.description}
+ onChange={(newValue) => {
+ setItemData((d) => ({ ...d, description: newValue }));
+ }}
+ />
+ <UnitOfMeasure
+ name="unitOfMeasureCode"
+ value={itemData.unitOfMeasureCode}
+ onChange={(newValue) =>
+ setItemData((d) => ({
+ ...d,
+ unitOfMeasureCode: newValue?.value ?? "EA",
+ }))
+ }
+ />
+ </div>
<ArrayNumeric
name="quantity"
label="Quantity"
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.delete.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.delete.tsx
new file mode 100644
index 0000000000..a7bc2ccbad
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.delete.tsx
@@ -0,0 +1,57 @@
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import {
+ quoteLineAdditionalChargesValidator,
+ upsertQuoteLineAdditionalCharges,
+} from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { assertIsPost } from "~/utils/http";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+
+ const { client, userId } = await requirePermissions(request, {
+ update: "sales",
+ });
+
+ const { lineId } = params;
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const formData = await request.formData();
+ const id = formData.get("id") as string;
+ const additionalCharges = JSON.parse(
+ (formData.get("additionalCharges") ?? "{}") as string
+ );
+ if (!additionalCharges)
+ return json(
+ {
+ data: null,
+ errors: { additionalCharges: "Additional charges are required" },
+ },
+ { status: 400 }
+ );
+
+ const parsedCharges =
+ quoteLineAdditionalChargesValidator.safeParse(additionalCharges);
+ if (parsedCharges.success === false) {
+ return json(
+ { data: null, errors: parsedCharges.error.errors?.[0].message },
+ { status: 400 }
+ );
+ }
+
+ delete parsedCharges.data[id];
+
+ const { error } = await upsertQuoteLineAdditionalCharges(client, lineId, {
+ additionalCharges: parsedCharges.data,
+ updatedBy: userId,
+ });
+
+ if (error) {
+ return json(
+ { data: null, errors: { form: error.message } },
+ { status: 400 }
+ );
+ }
+
+ return json({ data: { id }, error: null });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx
new file mode 100644
index 0000000000..af4e3a9ffe
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx
@@ -0,0 +1,62 @@
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { nanoid } from "nanoid";
+import {
+ quoteLineAdditionalChargesValidator,
+ upsertQuoteLineAdditionalCharges,
+} from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { assertIsPost } from "~/utils/http";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+
+ const { client, userId } = await requirePermissions(request, {
+ update: "sales",
+ });
+
+ const { lineId } = params;
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const formData = await request.formData();
+ const additionalCharges = JSON.parse(
+ (formData.get("additionalCharges") ?? "{}") as string
+ );
+ if (!additionalCharges)
+ return json(
+ {
+ data: null,
+ errors: { additionalCharges: "Additional charges are required" },
+ },
+ { status: 400 }
+ );
+
+ const parsedCharges =
+ quoteLineAdditionalChargesValidator.safeParse(additionalCharges);
+ if (parsedCharges.success === false) {
+ return json(
+ { data: null, errors: parsedCharges.error.errors?.[0].message },
+ { status: 400 }
+ );
+ }
+
+ const id = nanoid();
+ const { error } = await upsertQuoteLineAdditionalCharges(client, lineId, {
+ additionalCharges: {
+ ...parsedCharges.data,
+ [id]: {
+ description: "Additional Charges",
+ amounts: {},
+ },
+ },
+ updatedBy: userId,
+ });
+
+ if (error) {
+ return json(
+ { data: null, errors: { form: error.message } },
+ { status: 400 }
+ );
+ }
+
+ return json({ data: { id }, error: null });
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx
index 87eeb0b150..7a91fd3a60 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx
@@ -2,7 +2,7 @@ import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet, useLoaderData, useParams } from "@remix-run/react";
-import { useMemo } from "react";
+import { Fragment, useMemo } from "react";
import type { Tree } from "~/components/TreeView";
import { usePermissions, useRealtime, useRouteData } from "~/hooks";
import { CadModel } from "~/modules/items";
@@ -148,26 +148,24 @@ export default function QuoteLine() {
...line,
id: line.id ?? undefined,
quoteId: line.quoteId ?? "",
- estimatorId: line.estimatorId ?? "",
customerPartId: line.customerPartId ?? "",
customerPartRevision: line.customerPartRevision ?? "",
- status: line.status ?? "Draft",
+ description: line.description ?? "",
+ estimatorId: line.estimatorId ?? "",
itemId: line.itemId ?? "",
itemReadableId: line.itemReadableId ?? "",
- description: line.description ?? "",
methodType: line.methodType ?? "Make",
- unitOfMeasureCode: line.unitOfMeasureCode ?? "",
modelUploadId: line.modelUploadId ?? undefined,
+ status: line.status ?? "Draft",
+ quantity: line.quantity ?? [1],
+ unitOfMeasureCode: line.unitOfMeasureCode ?? "",
};
return (
- <>
- <QuoteLineForm key={initialValues.id} initialValues={initialValues} />
+ <Fragment key={lineId}>
+ <QuoteLineForm key={lineId} initialValues={initialValues} />
{permissions.is("employee") && (
- <>
- {line.methodType === "Make" && (
- <QuoteLineCosting methodTree={methodTree} operations={operations} />
- )}
+ <Fragment key={lineId}>
<div className="grid grid-cols-1 xl:grid-cols-2 w-full flex-grow gap-2 ">
<CadModel
autodeskUrn={line?.autodeskUrn ?? null}
@@ -184,10 +182,18 @@ export default function QuoteLine() {
modelUpload={line ?? undefined}
/>
</div>
+ {line.methodType === "Make" && (
+ <QuoteLineCosting
+ methodTree={methodTree}
+ operations={operations}
+ quantities={line.quantity ?? [1]}
+ additionalCharges={line.additionalCharges ?? {}}
+ />
+ )}
<QuoteLineNotes line={line} />
<Outlet />
- </>
+ </Fragment>
)}
- </>
+ </Fragment>
);
}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
index d1e11945b6..9ec33afbec 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
@@ -134,12 +134,13 @@ function QuoteExplorer() {
const { id: userId } = useUser();
const quoteLineInitialValues = {
quoteId,
+ description: "",
+ estimatorId: userId,
itemId: "",
itemReadableId: "",
- status: "Draft" as const,
- estimatorId: userId,
- description: "",
methodType: "Make" as const,
+ status: "Draft" as const,
+ quantity: [1],
unitOfMeasureCode: "",
};
@@ -264,7 +265,7 @@ function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
<img
alt="P2392303"
className={cn(
- "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border border-transparent",
+ "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent",
line.status === "Complete" && "border-green-500",
line.status === "In Progress" && "border-yellow-500"
)}
@@ -273,7 +274,7 @@ function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
) : (
<div
className={cn(
- "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border border-transparent p-2",
+ "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2",
line.status === "Complete" && "border-green-500",
line.status === "In Progress" && "border-yellow-500"
)}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 9eae21ee01..f219a58018 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -233,6 +233,8 @@ export const path = {
deleteQuote: (id: string) => generatePath(`${x}/quote/delete/${id}`),
deleteQuoteLine: (id: string, lineId: string) =>
generatePath(`${x}/quote/${id}/${lineId}/delete`),
+ deleteQuoteLineCost: (quoteId: string, lineId: string) =>
+ generatePath(`${x}/quote/${quoteId}/${lineId}/cost/delete`),
deleteQuoteMaterial: (quoteId: string, lineId: string, id: string) =>
generatePath(
`${x}/quote/methods/${quoteId}/${lineId}/material/delete/${id}`
@@ -436,8 +438,8 @@ export const path = {
generatePath(`${x}/purchase-order/${id}/lines/new`),
newQuote: `${x}/quote/new`,
newQuoteLine: (id: string) => generatePath(`${x}/quote/${id}/new`),
- newQuoteLineQuantity: (id: string, lineId: string) =>
- generatePath(`${x}/quote/${id}/lines/${lineId}/new`),
+ newQuoteLineCost: (id: string, lineId: string) =>
+ generatePath(`${x}/quote/${id}/${lineId}/cost/new`),
newQuoteOperation: (quoteId: string, lineId: string) =>
generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/new`),
newQuoteMaterial: (quoteId: string, lineId: string) =>
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index c7bf761d37..9f3377f512 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -12816,6 +12816,7 @@ export type Database = {
}
quoteLine: {
Row: {
+ additionalCharges: Json | null
companyId: string
createdBy: string
customerPartId: string | null
@@ -12830,6 +12831,7 @@ export type Database = {
methodType: Database["public"]["Enums"]["methodType"]
modelUploadId: string | null
notes: Json | null
+ quantity: number[] | null
quoteId: string
quoteRevisionId: number
status: Database["public"]["Enums"]["quoteLineStatus"]
@@ -12838,6 +12840,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ additionalCharges?: Json | null
companyId: string
createdBy: string
customerPartId?: string | null
@@ -12852,6 +12855,7 @@ export type Database = {
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
notes?: Json | null
+ quantity?: number[] | null
quoteId: string
quoteRevisionId?: number
status?: Database["public"]["Enums"]["quoteLineStatus"]
@@ -12860,6 +12864,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ additionalCharges?: Json | null
companyId?: string
createdBy?: string
customerPartId?: string | null
@@ -12874,6 +12879,7 @@ export type Database = {
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
notes?: Json | null
+ quantity?: number[] | null
quoteId?: string
quoteRevisionId?: number
status?: Database["public"]["Enums"]["quoteLineStatus"]
@@ -13061,47 +13067,50 @@ export type Database = {
}
quoteLinePrice: {
Row: {
+ additionalCharges: Json | null
createdAt: string
createdBy: string
discountPercent: number
extendedPrice: number
- id: string
leadTime: number
markupPercent: number
quantity: number
quoteId: string
quoteLineId: string
unitCost: number
+ unitPrice: number
updatedAt: string | null
updatedBy: string | null
}
Insert: {
+ additionalCharges?: Json | null
createdAt?: string
createdBy: string
discountPercent?: number
extendedPrice?: number
- id?: string
leadTime?: number
markupPercent?: number
quantity?: number
quoteId: string
quoteLineId: string
unitCost?: number
+ unitPrice?: number
updatedAt?: string | null
updatedBy?: string | null
}
Update: {
+ additionalCharges?: Json | null
createdAt?: string
createdBy?: string
discountPercent?: number
extendedPrice?: number
- id?: string
leadTime?: number
markupPercent?: number
quantity?: number
quoteId?: string
quoteLineId?: string
unitCost?: number
+ unitPrice?: number
updatedAt?: string | null
updatedBy?: string | null
}
@@ -22900,6 +22909,7 @@ export type Database = {
}
quoteLines: {
Row: {
+ additionalCharges: Json | null
autodeskUrn: string | null
companyId: string | null
createdBy: string | null
@@ -22919,12 +22929,7 @@ export type Database = {
modelSize: number | null
modelUploadId: string | null
notes: Json | null
- pricingDiscountPercent: number | null
- pricingExtendedPrice: number | null
- pricingLeadTime: number | null
- pricingMarkupPercent: number | null
- pricingQuantity: number | null
- pricingUnitCost: number | null
+ quantity: number[] | null
quoteId: string | null
quoteRevisionId: number | null
status: Database["public"]["Enums"]["quoteLineStatus"] | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index c7bf761d37..9f3377f512 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -12816,6 +12816,7 @@ export type Database = {
}
quoteLine: {
Row: {
+ additionalCharges: Json | null
companyId: string
createdBy: string
customerPartId: string | null
@@ -12830,6 +12831,7 @@ export type Database = {
methodType: Database["public"]["Enums"]["methodType"]
modelUploadId: string | null
notes: Json | null
+ quantity: number[] | null
quoteId: string
quoteRevisionId: number
status: Database["public"]["Enums"]["quoteLineStatus"]
@@ -12838,6 +12840,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ additionalCharges?: Json | null
companyId: string
createdBy: string
customerPartId?: string | null
@@ -12852,6 +12855,7 @@ export type Database = {
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
notes?: Json | null
+ quantity?: number[] | null
quoteId: string
quoteRevisionId?: number
status?: Database["public"]["Enums"]["quoteLineStatus"]
@@ -12860,6 +12864,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ additionalCharges?: Json | null
companyId?: string
createdBy?: string
customerPartId?: string | null
@@ -12874,6 +12879,7 @@ export type Database = {
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
notes?: Json | null
+ quantity?: number[] | null
quoteId?: string
quoteRevisionId?: number
status?: Database["public"]["Enums"]["quoteLineStatus"]
@@ -13061,47 +13067,50 @@ export type Database = {
}
quoteLinePrice: {
Row: {
+ additionalCharges: Json | null
createdAt: string
createdBy: string
discountPercent: number
extendedPrice: number
- id: string
leadTime: number
markupPercent: number
quantity: number
quoteId: string
quoteLineId: string
unitCost: number
+ unitPrice: number
updatedAt: string | null
updatedBy: string | null
}
Insert: {
+ additionalCharges?: Json | null
createdAt?: string
createdBy: string
discountPercent?: number
extendedPrice?: number
- id?: string
leadTime?: number
markupPercent?: number
quantity?: number
quoteId: string
quoteLineId: string
unitCost?: number
+ unitPrice?: number
updatedAt?: string | null
updatedBy?: string | null
}
Update: {
+ additionalCharges?: Json | null
createdAt?: string
createdBy?: string
discountPercent?: number
extendedPrice?: number
- id?: string
leadTime?: number
markupPercent?: number
quantity?: number
quoteId?: string
quoteLineId?: string
unitCost?: number
+ unitPrice?: number
updatedAt?: string | null
updatedBy?: string | null
}
@@ -22900,6 +22909,7 @@ export type Database = {
}
quoteLines: {
Row: {
+ additionalCharges: Json | null
autodeskUrn: string | null
companyId: string | null
createdBy: string | null
@@ -22919,12 +22929,7 @@ export type Database = {
modelSize: number | null
modelUploadId: string | null
notes: Json | null
- pricingDiscountPercent: number | null
- pricingExtendedPrice: number | null
- pricingLeadTime: number | null
- pricingMarkupPercent: number | null
- pricingQuantity: number | null
- pricingUnitCost: number | null
+ quantity: number[] | null
quoteId: string | null
quoteRevisionId: number | null
status: Database["public"]["Enums"]["quoteLineStatus"] | null
diff --git a/packages/database/supabase/migrations/20240802114117_quote-line-quantities.sql b/packages/database/supabase/migrations/20240802114117_quote-line-quantities.sql
new file mode 100644
index 0000000000..e4b7023a5f
--- /dev/null
+++ b/packages/database/supabase/migrations/20240802114117_quote-line-quantities.sql
@@ -0,0 +1,27 @@
+ALTER TABLE "quoteLine"
+ ADD COLUMN "quantity" NUMERIC(20, 2)[] DEFAULT ARRAY[1]::NUMERIC(20, 2)[],
+ ADD COLUMN "additionalCharges" JSONB DEFAULT '{}';
+
+DROP VIEW "quoteLines";
+CREATE OR REPLACE VIEW "quoteLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ ql.*,
+ COALESCE(mu.id, imu.id) as "modelId",
+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",
+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",
+ COALESCE(mu."thumbnailPath", imu."thumbnailPath") as "thumbnailPath",
+ COALESCE(mu."name", imu."name") as "modelName",
+ COALESCE(mu."size", imu."size") as "modelSize"
+ FROM "quoteLine" ql
+ LEFT JOIN "modelUpload" mu ON ql."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = ql."itemId"
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+);
+
+COMMIT;
+
+ALTER TABLE "quoteLinePrice"
+ DROP COLUMN "id",
+ ADD COLUMN "unitPrice" NUMERIC(10,5) NOT NULL DEFAULT 0,
+ ADD COLUMN "additionalCharges" JSONB DEFAULT '{}',
+ ADD CONSTRAINT "quoteLinePrice_pkey" PRIMARY KEY ("quoteLineId", "quantity");
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index 75a5f41899..08c9825436 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -102,7 +102,7 @@ const QuotePDF = ({
{getLineDescriptionDetails(line)}
</Text>
</View>
- <Text style={styles.tableCol2}>{line.pricingQuantity}</Text>
+ {/* <Text style={styles.tableCol2}>{line.pricingQuantity}</Text>
<Text style={styles.tableCol3}>
<Text>
{line.pricingQuantity
@@ -117,7 +117,7 @@ const QuotePDF = ({
</Text>
<Text style={styles.tableCol4}>
<Text>{formatter.format(line.pricingExtendedPrice ?? 0)}</Text>
- </Text>
+ </Text> */}
</View>
))}
<View style={styles.tfoot}>