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.

refactor: client side updates for quote line pricing table

Brad Barbin91632fac2c4b
diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx
index 649f285bdc..023f7e8783 100644
--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx
+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx
@@ -1,3 +1,4 @@
+import { useCarbon } from "@carbon/auth";
import {
Card,
CardContent,
@@ -15,8 +16,8 @@ import {
Tr,
VStack,
} from "@carbon/react";
-import { useFetcher, useParams } from "@remix-run/react";
-import { useEffect, useState } from "react";
+import { useParams } from "@remix-run/react";
+import { useCallback, useEffect, useState } from "react";
import { Enumerable } from "~/components/Enumerable";
import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";
import {
@@ -48,11 +49,17 @@ const SupplierQuoteLinePricing = ({
const { id, lineId } = useParams();
if (!id) throw new Error("Could not find id");
if (!lineId) throw new Error("Could not find lineId");
- const [prices, setPrices] =
- useState<Record<number, SupplierQuoteLinePrice>>(pricesByQuantity);
+
+ // Consolidated state for all editable fields
+ const [editableFields, setEditableFields] = useState({
+ prices: pricesByQuantity,
+ });
useEffect(() => {
- setPrices(pricesByQuantity);
+ setEditableFields((prev) => ({
+ ...prev,
+ prices: pricesByQuantity,
+ }));
}, [pricesByQuantity]);
const routeData = useRouteData<{
@@ -62,13 +69,7 @@ const SupplierQuoteLinePricing = ({
permissions.can("update", "purchasing") &&
["Active"].includes(routeData?.quote?.status ?? "");
- const fetcher = useFetcher<{ id?: string; error: string | null }>();
- useEffect(() => {
- if (fetcher.data?.error) {
- toast.error(fetcher.data.error);
- }
- }, [fetcher.data]);
-
+ const { carbon } = useCarbon();
const { id: userId, company } = useUser();
const baseCurrency = company?.baseCurrencyCode ?? "USD";
@@ -77,52 +78,70 @@ const SupplierQuoteLinePricing = ({
currency: routeData?.quote?.currencyCode ?? baseCurrency,
});
- const onUpdatePrice = async (
- key:
- | "leadTime"
- | "supplierUnitPrice"
- | "supplierShippingCost"
- | "supplierTaxAmount",
- quantity: number,
- value: number
- ) => {
- const hasPrice = !!prices[quantity];
+ const onUpdatePrice = useCallback(
+ async (
+ key:
+ | "leadTime"
+ | "supplierUnitPrice"
+ | "supplierShippingCost"
+ | "supplierTaxAmount",
+ quantity: number,
+ value: number
+ ) => {
+ const hasPrice = !!editableFields.prices[quantity];
+
+ const oldPrices = { ...editableFields.prices };
+ const newPrices = { ...oldPrices };
+ if (!hasPrice) {
+ newPrices[quantity] = {
+ supplierQuoteId: id,
+ supplierQuoteLineId: lineId,
+ quantity,
+ leadTime: 0,
+ exchangeRate: exchangeRate ?? 1,
+ supplierUnitPrice: 0,
+ supplierShippingCost: 0,
+ supplierTaxAmount: 0,
+ createdBy: userId,
+ } as unknown as SupplierQuoteLinePrice;
+ }
+ newPrices[quantity] = { ...newPrices[quantity], [key]: value };
- const oldPrices = { ...prices };
- const newPrices = { ...oldPrices };
- if (!hasPrice) {
- newPrices[quantity] = {
- supplierQuoteId: id,
- supplierQuoteLineId: lineId,
- quantity,
- leadTime: 0,
- exchangeRate: exchangeRate ?? 1,
- supplierUnitPrice: 0,
- supplierShippingCost: 0,
- supplierTaxAmount: 0,
- createdBy: userId,
- } as unknown as SupplierQuoteLinePrice;
- }
- newPrices[quantity] = { ...newPrices[quantity], [key]: value };
+ setEditableFields((prev) => ({
+ ...prev,
+ prices: newPrices,
+ }));
- setPrices(newPrices);
+ if (hasPrice) {
+ const update = await carbon
+ ?.from("supplierQuoteLinePrice")
+ .update({
+ [key]: value,
+ supplierQuoteLineId: lineId,
+ quantity,
+ })
+ .eq("supplierQuoteLineId", lineId)
+ .eq("quantity", quantity);
- const formData = new FormData();
- formData.append("hasPrice", hasPrice ? "true" : "false");
- formData.append("quantity", quantity.toString());
- formData.append("supplierQuoteLineId", lineId);
- if (hasPrice) {
- formData.append("key", key);
- formData.append("value", value.toString());
- } else {
- formData.append("price", JSON.stringify(newPrices[quantity]));
- }
+ if (update?.error) {
+ console.error(update.error);
+ toast.error("Failed to update supplier quote line");
+ }
+ } else {
+ const insert = await carbon?.from("supplierQuoteLinePrice").insert({
+ ...newPrices[quantity],
+ supplierQuoteLineId: lineId,
+ quantity,
+ });
- fetcher.submit(formData, {
- method: "post",
- action: path.to.supplierQuoteLinePriceUpdate(id, lineId),
- });
- };
+ if (insert?.error) {
+ console.error(insert.error);
+ toast.error("Failed to insert supplier quote line");
+ }
+ }
+ },
+ [editableFields.prices, id, lineId, exchangeRate, userId, carbon]
+ );
const unitOfMeasures = useUnitOfMeasure();
@@ -150,7 +169,7 @@ const SupplierQuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity) => {
- const leadTime = prices[quantity]?.leadTime ?? 0;
+ const leadTime = editableFields.prices[quantity]?.leadTime ?? 0;
return (
<Td
key={quantity.toString()}
@@ -197,7 +216,8 @@ const SupplierQuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity) => {
- const price = prices[quantity]?.supplierUnitPrice ?? 0;
+ const price =
+ editableFields.prices[quantity]?.supplierUnitPrice ?? 0;
return (
<Td key={quantity.toString()}>
<NumberField
@@ -240,7 +260,7 @@ const SupplierQuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity, index) => {
- const price = prices[quantity]?.unitPrice ?? 0;
+ const price = editableFields.prices[quantity]?.unitPrice ?? 0;
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
@@ -261,7 +281,7 @@ const SupplierQuoteLinePricing = ({
</Td>
{quantities.map((quantity) => {
const shippingCost =
- prices[quantity]?.supplierShippingCost ?? 0;
+ editableFields.prices[quantity]?.supplierShippingCost ?? 0;
return (
<Td key={quantity.toString()}>
<NumberField
@@ -301,7 +321,8 @@ const SupplierQuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity, index) => {
- const taxAmount = prices[quantity]?.supplierTaxAmount ?? 0;
+ const taxAmount =
+ editableFields.prices[quantity]?.supplierTaxAmount ?? 0;
return (
<Td key={index} className="group-hover:bg-muted/50">
<NumberField
@@ -337,9 +358,11 @@ const SupplierQuoteLinePricing = ({
</Td>
{quantities.map((quantity, index) => {
const subtotal =
- (prices[quantity]?.supplierUnitPrice ?? 0) * quantity +
- (prices[quantity]?.supplierShippingCost ?? 0);
- const tax = prices[quantity]?.supplierTaxAmount ?? 0;
+ (editableFields.prices[quantity]?.supplierUnitPrice ?? 0) *
+ quantity +
+ (editableFields.prices[quantity]?.supplierShippingCost ?? 0);
+ const tax =
+ editableFields.prices[quantity]?.supplierTaxAmount ?? 0;
const price = subtotal + tax;
return (
@@ -361,7 +384,9 @@ const SupplierQuoteLinePricing = ({
</Td>
{quantities.map((quantity, index) => {
const rate =
- prices[quantity]?.exchangeRate ?? exchangeRate ?? 1;
+ editableFields.prices[quantity]?.exchangeRate ??
+ exchangeRate ??
+ 1;
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
@@ -379,12 +404,16 @@ const SupplierQuoteLinePricing = ({
</Td>
{quantities.map((quantity, index) => {
const subtotal =
- ((prices[quantity]?.supplierUnitPrice ?? 0) * quantity +
- (prices[quantity]?.supplierShippingCost ?? 0)) /
- (prices[quantity]?.exchangeRate ?? 1);
+ ((editableFields.prices[quantity]?.supplierUnitPrice ??
+ 0) *
+ quantity +
+ (editableFields.prices[quantity]
+ ?.supplierShippingCost ?? 0)) /
+ (editableFields.prices[quantity]?.exchangeRate ?? 1);
const tax =
- (prices[quantity]?.supplierTaxAmount ?? 0) /
- (prices[quantity]?.exchangeRate ?? 1);
+ (editableFields.prices[quantity]?.supplierTaxAmount ??
+ 0) /
+ (editableFields.prices[quantity]?.exchangeRate ?? 1);
const price = subtotal + tax;
return (
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
index 9c24b3952c..afdd6c179b 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
@@ -1,3 +1,4 @@
+import { useCarbon } from "@carbon/auth";
import {
Button,
Card,
@@ -28,7 +29,8 @@ import {
Tr,
VStack,
} from "@carbon/react";
-import { useFetcher, useParams, useSubmit } from "@remix-run/react";
+import { getLocalTimeZone, today } from "@internationalized/date";
+import { useFetcher, useParams } from "@remix-run/react";
import { useCallback, useEffect, useMemo, useState } from "react";
import {
LuChevronDown,
@@ -37,7 +39,6 @@ import {
LuRefreshCcw,
LuTrash,
} from "react-icons/lu";
-import type { z } from "zod";
import {
useCurrencyFormatter,
usePermissions,
@@ -81,8 +82,6 @@ const QuoteLinePricing = ({
taxPercent: line.taxPercent ?? 0,
});
- const submit = useSubmit();
-
useEffect(() => {
setEditableFields((prev) => ({
...prev,
@@ -116,22 +115,7 @@ const QuoteLinePricing = ({
}
}, [fetcher.data]);
- const optimisticUnitCost = useMemo<number>(() => {
- if (!line.itemId) return editableFields.unitCost;
- if (fetcher.formAction === path.to.itemCostUpdate(line.itemId)) {
- const submitted = fetcher.formData?.get("unitCost");
- if (submitted) {
- return Number(submitted);
- }
- }
- return editableFields.unitCost;
- }, [
- line.itemId,
- editableFields.unitCost,
- fetcher.formAction,
- fetcher.formData,
- ]);
-
+ const { carbon } = useCarbon();
const { id: userId, company } = useUser();
const baseCurrency = company?.baseCurrencyCode ?? "USD";
@@ -146,25 +130,13 @@ const QuoteLinePricing = ({
});
const additionalCharges = useMemo(() => {
- if (fetcher.formAction === path.to.quoteLineCost(quoteId, lineId)) {
- // get the optimistic update
- return JSON.parse(
- (fetcher.formData?.get("additionalCharges") as string) ?? "{}"
- ) as z.infer<typeof quoteLineAdditionalChargesValidator>;
- }
const parsedAdditionalCharges =
quoteLineAdditionalChargesValidator.safeParse(
editableFields.additionalCharges
);
return parsedAdditionalCharges.success ? parsedAdditionalCharges.data : {};
- }, [
- editableFields.additionalCharges,
- fetcher.formAction,
- fetcher.formData,
- lineId,
- quoteId,
- ]);
+ }, [editableFields.additionalCharges]);
const additionalChargesByQuantity = quantities.map((quantity) => {
const charges = Object.values(additionalCharges).reduce((acc, charge) => {
@@ -174,29 +146,8 @@ const QuoteLinePricing = ({
return charges;
});
- // Submission function using useSubmit with fetcherKey
- const submitFieldUpdates = useCallback(
- (action: string, data: Record<string, any>) => {
- const formData = new FormData();
- Object.entries(data).forEach(([key, value]) => {
- formData.append(
- key,
- typeof value === "object" ? JSON.stringify(value) : String(value)
- );
- });
-
- submit(formData, {
- method: "post",
- action,
- navigate: false,
- fetcherKey: `quote-line-pricing-${lineId}`,
- });
- },
- [submit, lineId]
- );
-
const onUpdateChargeDescription = useCallback(
- (chargeId: string, description: string) => {
+ async (chargeId: string, description: string) => {
const updatedCharges = {
...additionalCharges,
[chargeId]: {
@@ -205,22 +156,30 @@ const QuoteLinePricing = ({
},
};
- // Update local state
- setEditableFields((prev) => ({
- ...prev,
- additionalCharges: updatedCharges,
- }));
-
- // Submit using the new submission function
- submitFieldUpdates(path.to.quoteLineCost(quoteId, lineId), {
- additionalCharges: updatedCharges,
+ setEditableFields((prev) => {
+ return {
+ ...prev,
+ additionalCharges: updatedCharges,
+ };
});
+
+ const costUpdate = await carbon
+ ?.from("quoteLine")
+ .update({
+ additionalCharges: updatedCharges,
+ })
+ .eq("id", lineId);
+
+ if (costUpdate?.error) {
+ console.error(costUpdate.error);
+ toast.error("Failed to update quote line");
+ }
},
- [additionalCharges, submitFieldUpdates, lineId, quoteId]
+ [additionalCharges, lineId, carbon]
);
const onUpdateChargeAmount = useCallback(
- (chargeId: string, quantity: number, amount: number) => {
+ async (chargeId: string, quantity: number, amount: number) => {
const updatedCharges = {
...additionalCharges,
[chargeId]: {
@@ -232,18 +191,24 @@ const QuoteLinePricing = ({
},
};
- // Update local state
setEditableFields((prev) => ({
...prev,
additionalCharges: updatedCharges,
}));
- // Submit using the new submission function
- submitFieldUpdates(path.to.quoteLineCost(quoteId, lineId), {
- additionalCharges: updatedCharges,
- });
+ const costUpdate = await carbon
+ ?.from("quoteLine")
+ .update({
+ additionalCharges: updatedCharges,
+ })
+ .eq("id", lineId);
+
+ if (costUpdate?.error) {
+ console.error(costUpdate.error);
+ toast.error("Failed to update quote line");
+ }
},
- [additionalCharges, submitFieldUpdates, lineId, quoteId]
+ [additionalCharges, carbon, lineId]
);
const unitCostsByQuantity = quantities.map((quantity, index) => {
@@ -290,25 +255,34 @@ const QuoteLinePricing = ({
};
const onUpdateCost = useCallback(
- (value: number) => {
+ async (value: number) => {
if (!line.itemId) return;
- // Update local state
setEditableFields((prev) => ({
...prev,
unitCost: value,
}));
- // Submit using the new submission function
- submitFieldUpdates(path.to.itemCostUpdate(line.itemId), {
- unitCost: value,
- });
+ const costUpdate = await carbon
+ ?.from("itemCost")
+ .update({
+ unitCost: value,
+ costIsAdjusted: true,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ })
+ .eq("itemId", line.itemId)
+ .single();
+
+ if (costUpdate?.error) {
+ console.error(costUpdate.error);
+ toast.error("Failed to update item cost");
+ }
},
- [line.itemId, submitFieldUpdates]
+ [carbon, line.itemId]
);
const onUpdatePrice = useCallback(
- (
+ async (
key: "leadTime" | "unitPrice" | "discountPercent" | "shippingCost",
quantity: number,
value: number
@@ -338,39 +312,46 @@ const QuoteLinePricing = ({
}
newPrices[quantity] = { ...newPrices[quantity], [key]: roundedValue };
- // Update local state
setEditableFields((prev) => ({
...prev,
prices: newPrices,
}));
- // Submit using the new submission function
- const submitData: Record<string, any> = {
- hasPrice: hasPrice.toString(),
- quantity: quantity.toString(),
- quoteLineId: lineId,
- };
-
if (hasPrice) {
- submitData.key = key;
- submitData.value = roundedValue.toString();
+ const update = await carbon
+ ?.from("quoteLinePrice")
+ .update({
+ [key]: roundedValue,
+ quoteLineId: lineId,
+ quantity,
+ })
+ .eq("quoteLineId", lineId)
+ .eq("quantity", quantity);
+ if (update?.error) {
+ console.error(update.error);
+ toast.error("Failed to update quote line");
+ }
} else {
- submitData.price = JSON.stringify(newPrices[quantity]);
- }
+ const insert = await carbon?.from("quoteLinePrice").insert({
+ ...newPrices[quantity],
+ quoteLineId: lineId,
+ quantity,
+ });
- submitFieldUpdates(
- path.to.quoteLinePriceUpdate(quoteId, lineId),
- submitData
- );
+ if (insert?.error) {
+ console.error(insert.error);
+ toast.error("Failed to insert quote line");
+ }
+ }
},
[
- editableFields.prices,
line.unitPricePrecision,
+ editableFields.prices,
quoteId,
lineId,
exchangeRate,
userId,
- submitFieldUpdates,
+ carbon,
]
);
@@ -553,14 +534,17 @@ const QuoteLinePricing = ({
) : (
<Td key={index} className="group-hover:bg-muted/50">
<NumberField
- value={optimisticUnitCost}
+ value={editableFields.unitCost}
formatOptions={{
style: "currency",
currency: baseCurrency,
}}
minValue={0}
onChange={(value) => {
- if (Number.isFinite(value) && value !== cost) {
+ if (
+ Number.isFinite(value) &&
+ value !== editableFields.unitCost
+ ) {
onUpdateCost(value);
}
}}
@@ -997,13 +981,7 @@ const QuoteLinePricing = ({
taxPercent: value,
}));
- // Use the quote line update endpoint for tax percent
- submitFieldUpdates(
- path.to.quoteLine(quoteId, lineId),
- {
- taxPercent: value,
- }
- );
+ // TODO: handle mutation
}
}}
>
diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.update.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.update.tsx
deleted file mode 100644
index e63329432f..0000000000
--- a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.update.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import { assertIsPost } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { json, type ActionFunctionArgs } from "@vercel/remix";
-import {
- quoteLineAdditionalChargesValidator,
- upsertQuoteLineAdditionalCharges,
-} from "~/modules/sales";
-
-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 { 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: parsedCharges, error: null });
-}
diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.price.update.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.price.update.tsx
deleted file mode 100644
index bd45277f46..0000000000
--- a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.price.update.tsx
+++ /dev/null
@@ -1,86 +0,0 @@
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { validator } from "@carbon/form";
-import { json, type ActionFunctionArgs } from "@vercel/remix";
-import { z } from "zod";
-import { zfd } from "zod-form-data";
-
-const priceUpdateValidator = z.object({}).and(
- z.discriminatedUnion("hasPrice", [
- z.object({
- hasPrice: z.literal("true"),
- quantity: zfd.numeric(z.number()),
- quoteLineId: z.string(),
- key: z.enum(["unitPrice", "leadTime", "discountPercent", "shippingCost"]),
- value: zfd.numeric(z.number()),
- }),
- z.object({
- hasPrice: z.literal("false"),
- quantity: zfd.numeric(z.number()),
- quoteLineId: z.string(),
- price: z.string(),
- }),
- ])
-);
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- update: "sales",
- });
-
- const { quoteId, lineId } = params;
- if (!quoteId) throw new Error("Could not find quoteId");
- if (!lineId) throw new Error("Could not find lineId");
-
- const formData = await request.formData();
-
- const validation = await validator(priceUpdateValidator).validate(formData);
-
- if (validation.error) {
- return json({ error: "Invalid form data" }, { status: 400 });
- }
-
- const { hasPrice, quantity, quoteLineId } = validation.data;
- if (hasPrice === "true") {
- const { key, value } = validation.data;
- const update = await client
- .from("quoteLinePrice")
- .update({
- [key]: value,
- quoteLineId,
- quantity,
- })
- .eq("quoteLineId", quoteLineId)
- .eq("quantity", quantity);
-
- if (update.error) {
- console.error(update.error);
- return json(
- { error: "Failed to update quote line price" },
- { status: 500 }
- );
- }
- } else {
- const { price } = validation.data;
- try {
- const parsedPrice = JSON.parse(price);
- const insert = await client.from("quoteLinePrice").insert({
- ...parsedPrice,
- quoteLineId,
- quantity,
- });
-
- if (insert.error) {
- console.error(insert.error);
- return json(
- { error: "Failed to update quote line price" },
- { status: 500 }
- );
- }
- } catch (error) {
- console.error(error);
- return json({ error: "Invalid price data format" }, { status: 400 });
- }
- }
-
- return json({});
-}
diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.price.update.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.price.update.tsx
deleted file mode 100644
index ec924fb803..0000000000
--- a/apps/erp/app/routes/x+/supplier-quote+/$id.$lineId.price.update.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { validator } from "@carbon/form";
-import { json, type ActionFunctionArgs } from "@vercel/remix";
-import { z } from "zod";
-import { zfd } from "zod-form-data";
-
-const priceUpdateValidator = z.object({}).and(
- z.discriminatedUnion("hasPrice", [
- z.object({
- hasPrice: z.literal("true"),
- quantity: zfd.numeric(z.number()),
- supplierQuoteLineId: z.string(),
- key: z.enum([
- "leadTime",
- "supplierUnitPrice",
- "supplierShippingCost",
- "supplierTaxAmount",
- ]),
- value: zfd.numeric(z.number()),
- }),
- z.object({
- hasPrice: z.literal("false"),
- quantity: zfd.numeric(z.number()),
- supplierQuoteLineId: z.string(),
- price: z.string(),
- }),
- ])
-);
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- update: "purchasing",
- });
-
- const { id, lineId } = params;
- if (!id) throw new Error("Could not find id");
- if (!lineId) throw new Error("Could not find lineId");
-
- const formData = await request.formData();
-
- const validation = await validator(priceUpdateValidator).validate(formData);
-
- if (validation.error) {
- console.error(validation.error);
- return json({ error: "Invalid form data" }, { status: 400 });
- }
-
- const { hasPrice, quantity, supplierQuoteLineId } = validation.data;
- if (hasPrice === "true") {
- const { key, value } = validation.data;
- const update = await client
- .from("supplierQuoteLinePrice")
- .update({
- [key]: value,
- supplierQuoteLineId,
- quantity,
- })
- .eq("supplierQuoteLineId", supplierQuoteLineId)
- .eq("quantity", quantity);
-
- if (update.error) {
- console.error(update.error);
- return json(
- { error: "Failed to update quote line price" },
- { status: 500 }
- );
- }
- } else {
- const { price } = validation.data;
- try {
- const parsedPrice = JSON.parse(price);
- const insert = await client.from("supplierQuoteLinePrice").insert({
- ...parsedPrice,
- supplierQuoteLineId,
- quantity,
- });
-
- if (insert.error) {
- console.error(insert.error);
- return json(
- { error: "Failed to update quote line price" },
- { status: 500 }
- );
- }
- } catch (error) {
- console.error(error);
- return json({ error: "Invalid price data format" }, { status: 400 });
- }
- }
-
- return json({});
-}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 02a068db82..e6ee1b4559 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -1140,9 +1140,6 @@ export const path = {
generatePath(`${x}/quote/${quoteId}/${id}/details`),
quoteLineConfigure: (quoteId: string, lineId: string) =>
generatePath(`${x}/quote/${quoteId}/${lineId}/configure`),
- quoteLineCost: (quoteId: string, lineId: string) =>
- generatePath(`${x}/quote/${quoteId}/${lineId}/cost/update`),
-
quoteLineMakeMethod: (
quoteId: string,
lineId: string,
@@ -1150,8 +1147,6 @@ export const path = {
) => generatePath(`${x}/quote/${quoteId}/${lineId}/make/${makeMethodId}`),
quoteLineMethod: (quoteId: string, quoteLineId: string, methodId: string) =>
generatePath(`${x}/quote/${quoteId}/${quoteLineId}/method/${methodId}`),
- quoteLinePriceUpdate: (quoteId: string, lineId: string) =>
- generatePath(`${x}/quote/${quoteId}/${lineId}/price/update`),
quoteLineRecalculatePrice: (quoteId: string, lineId: string) =>
generatePath(`${x}/quote/${quoteId}/${lineId}/recalculate-price`),
quoteLineUpdatePrecision: (quoteId: string, lineId: string) =>
@@ -1347,8 +1342,6 @@ export const path = {
generatePath(`${x}/supplier-quote/${id}/exchange-rate`),
supplierQuoteLine: (id: string, lineId: string) =>
generatePath(`${x}/supplier-quote/${id}/${lineId}/details`),
- supplierQuoteLinePriceUpdate: (id: string, lineId: string) =>
- generatePath(`${x}/supplier-quote/${id}/${lineId}/price/update`),
supplierRoot: `${x}/supplier`,
supplierStatus: (id: string) =>
generatePath(`${x}/purchasing/supplier-statuses/${id}`),