Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: crud for extra quote line costs
Brad Barbin81fa4c30f436
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsxindex 7165f1a13d..4c5c36f103 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx@@ -8,6 +8,8 @@ import {Enumerable,HStack,Input,+ NumberField,+ NumberInput,Table,Tbody,Td,@@ -284,12 +286,11 @@ const QuoteLineCosting = ({[]);- const parsedAdditionalCharges = quoteLineAdditionalChargesValidator.safeParse(- additionalChargesJson- );- const additionalCharges = parsedAdditionalCharges.success- ? parsedAdditionalCharges.data- : {};+ const additionalCharges = useMemo(() => {+ const parsedAdditionalCharges =+ quoteLineAdditionalChargesValidator.safeParse(additionalChargesJson);+ return parsedAdditionalCharges.success ? parsedAdditionalCharges.data : {};+ }, [additionalChargesJson]);const additionalChargesByQuantity = quantities.map((quantity) => {const charges = Object.values(additionalCharges).reduce((acc, charge) => {@@ -299,6 +300,50 @@ const QuoteLineCosting = ({return charges;});+ const onUpdateChargeDescription = useCallback(+ (chargeId: string, description: string) => {+ const updatedCharges = {+ ...additionalCharges,+ [chargeId]: {+ ...additionalCharges[chargeId],+ description,+ },+ };++ const formData = new FormData();++ formData.set("additionalCharges", JSON.stringify(updatedCharges));+ fetcher.submit(formData, {+ method: "post",+ action: path.to.quoteLineCost(quoteId, lineId),+ });+ },+ [additionalCharges, fetcher, lineId, quoteId]+ );++ const onUpdateChargeAmount = useCallback(+ (chargeId: string, quantity: number, amount: number) => {+ const updatedCharges = {+ ...additionalCharges,+ [chargeId]: {+ ...additionalCharges[chargeId],+ amounts: {+ ...additionalCharges[chargeId].amounts,+ [quantity]: amount,+ },+ },+ };++ const formData = new FormData();+ formData.set("additionalCharges", JSON.stringify(updatedCharges));+ fetcher.submit(formData, {+ method: "post",+ action: path.to.quoteLineCost(quoteId, lineId),+ });+ },+ [additionalCharges, fetcher, lineId, quoteId]+ );+return (<Card><CardHeader>@@ -318,7 +363,7 @@ const QuoteLineCosting = ({<Tr><Td className="border-r border-border"><HStack className="w-full justify-between ">- <span>Total Raw Material</span>+ <span className="whitespace-nowrap">Total Raw Material</span><Enumerable value="Material" /></HStack></Td>@@ -344,7 +389,9 @@ const QuoteLineCosting = ({<Tr><Td className="border-r border-border"><HStack className="w-full justify-between ">- <span>Total Labor & Overhead</span>+ <span className="whitespace-nowrap">+ Total Labor & Overhead+ </span><Enumerable value="Labor" /></HStack></Td>@@ -411,6 +458,11 @@ const QuoteLineCosting = ({defaultValue={charge.description}size="sm"className="border-0 -ml-3 shadow-none"+ onBlur={(e) => {+ if (e.target.value !== charge.description) {+ onUpdateChargeDescription(chargeId, e.target.value);+ }+ }}/><HStack spacing={1}><fetcher.Form@@ -443,16 +495,24 @@ const QuoteLineCosting = ({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>+ <NumberField+ defaultValue={amount}+ formatOptions={{+ style: "currency",+ currency: "USD",+ }}+ onChange={(value) => {+ if (value !== amount) {+ onUpdateChargeAmount(chargeId, quantity, value);+ }+ }}+ >+ <NumberInput+ className="border-0 -ml-3 shadow-none"+ size="sm"+ min={0}+ />+ </NumberField></VStack></Td>);diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.update.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.update.tsxnew file mode 100644index 0000000000..cf57bd49c5--- /dev/null+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.cost.update.tsx@@ -0,0 +1,55 @@+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 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/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex f219a58018..225761982e 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -556,6 +556,8 @@ export const path = {generatePath(`${x}/quote/${id}/internal`),quoteLine: (quoteId: string, id: string) =>generatePath(`${x}/quote/${quoteId}/${id}/details`),+ quoteLineCost: (quoteId: string, lineId: string) =>+ generatePath(`${x}/quote/${quoteId}/${lineId}/cost/update`),quoteLineMaterial: (quoteId: string,lineId: string,