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: purchasing module settings

Brad Barbin8b8c499c866a
diff --git a/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx b/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
index 609b7ebb5b..8357f9529d 100644
--- a/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
+++ b/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
@@ -1,10 +1,10 @@
import {
LuCrown,
LuFactory,
- LuFileText,
LuImage,
LuLayoutDashboard,
LuSheet,
+ LuShoppingCart,
LuWorkflow,
} from "react-icons/lu";
import { usePermissions } from "~/hooks";
@@ -27,13 +27,6 @@ const settingsRoutes: AuthenticatedRouteGroup[] = [
role: "employee",
icon: <LuImage />,
},
-
- {
- name: "Standard Terms",
- to: path.to.terms,
- role: "employee",
- icon: <LuFileText />,
- },
],
},
{
@@ -45,6 +38,12 @@ const settingsRoutes: AuthenticatedRouteGroup[] = [
role: "employee",
icon: <LuCrown />,
},
+ {
+ name: "Purchasing",
+ to: path.to.purchasingSettings,
+ role: "employee",
+ icon: <LuShoppingCart />,
+ },
],
},
{
diff --git a/apps/erp/app/routes/x+/settings+/terms.tsx b/apps/erp/app/routes/x+/settings+/purchasing.tsx
similarity index 67%
rename from apps/erp/app/routes/x+/settings+/terms.tsx
rename to apps/erp/app/routes/x+/settings+/purchasing.tsx
index d107cbdf0c..8b3b4bd5e6 100644
--- a/apps/erp/app/routes/x+/settings+/terms.tsx
+++ b/apps/erp/app/routes/x+/settings+/purchasing.tsx
@@ -27,8 +27,8 @@ import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
export const handle: Handle = {
- breadcrumb: "Terms",
- to: path.to.terms,
+ breadcrumb: "Purchasing",
+ to: path.to.purchasingSettings,
};
export async function loader({ request }: LoaderFunctionArgs) {
@@ -61,9 +61,6 @@ export default function Terms() {
const [purchasingTermsStatus, setPurchasingTermsStatus] = useState<
"saved" | "draft"
>("saved");
- const [salesTermsStatus, setSalesTermsStatus] = useState<"saved" | "draft">(
- "saved"
- );
const handleUpdatePurchasingTerms = (content: JSONContent) => {
setPurchasingTermsStatus("draft");
@@ -86,28 +83,6 @@ export default function Terms() {
true
);
- const handleUpdateSalesTerms = (content: JSONContent) => {
- setSalesTermsStatus("draft");
- onUpdateSalesTerms(content);
- };
-
- const onUpdateSalesTerms = useDebounce(
- async (content: JSONContent) => {
- setSalesTermsStatus("draft");
- await carbon
- ?.from("terms")
- .update({
- salesTerms: content,
- updatedAt: today(getLocalTimeZone()).toString(),
- updatedBy: userId,
- })
- .eq("id", companyId);
- setSalesTermsStatus("saved");
- },
- 2500,
- true
- );
-
const onUploadImage = async (file: File) => {
// Implement image upload logic here
// This is a placeholder function
@@ -150,39 +125,6 @@ export default function Terms() {
)}
</CardContent>
</Card>
- <Card>
- <HStack className="justify-between items-start">
- <CardHeader>
- <CardTitle>Sales Terms &amp; Conditions</CardTitle>
- <CardDescription>
- Define the terms and conditions for quotes and sales orders
- </CardDescription>
- </CardHeader>
- <CardAction className="py-6">
- {salesTermsStatus === "draft" ? (
- <Badge variant="secondary">Draft</Badge>
- ) : (
- <LuCircleCheck className="w-4 h-4 text-emerald-500" />
- )}
- </CardAction>
- </HStack>
- <CardContent>
- {permissions.can("update", "settings") ? (
- <Editor
- initialValue={(terms.salesTerms ?? {}) as JSONContent}
- onUpload={onUploadImage}
- onChange={handleUpdateSalesTerms}
- />
- ) : (
- <div
- className="prose dark:prose-invert"
- dangerouslySetInnerHTML={{
- __html: generateHTML(terms.salesTerms as JSONContent),
- }}
- />
- )}
- </CardContent>
- </Card>
</VStack>
);
}
diff --git a/apps/erp/app/routes/x+/settings+/sales.tsx b/apps/erp/app/routes/x+/settings+/sales.tsx
index 052705fd34..489202bac0 100644
--- a/apps/erp/app/routes/x+/settings+/sales.tsx
+++ b/apps/erp/app/routes/x+/settings+/sales.tsx
@@ -1,19 +1,23 @@
import {
+ Badge,
Card,
+ CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
+ HStack,
Label,
ScrollArea,
toast,
+ useDebounce,
VStack,
} from "@carbon/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
-import { error } from "@carbon/auth";
+import { error, useCarbon } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { Boolean, Submit, ValidatedForm, validator } from "@carbon/form";
@@ -23,6 +27,7 @@ import { Users } from "~/components/Form";
import {
digitalQuoteValidator,
getCompanySettings,
+ getTerms,
rfqReadyValidator,
updateDigitalQuoteSetting,
updateRfqReadySetting,
@@ -30,6 +35,12 @@ import {
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
+import type { JSONContent } from "@carbon/react";
+import { Editor, generateHTML } from "@carbon/react/Editor";
+import { getLocalTimeZone, today } from "@internationalized/date";
+import { LuCircleCheck } from "react-icons/lu";
+import { usePermissions, useUser } from "~/hooks";
+
export const handle: Handle = {
breadcrumb: "Sales",
to: path.to.salesSettings,
@@ -40,7 +51,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
view: "settings",
});
- const companySettings = await getCompanySettings(client, companyId);
+ const [companySettings, terms] = await Promise.all([
+ getCompanySettings(client, companyId),
+ getTerms(client, companyId),
+ ]);
if (!companySettings.data)
throw redirect(
path.to.settings,
@@ -49,7 +63,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
error(companySettings.error, "Failed to get company settings")
)
);
- return json({ companySettings: companySettings.data });
+ return json({ companySettings: companySettings.data, terms: terms.data });
}
export async function action({ request }: ActionFunctionArgs) {
@@ -103,7 +117,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function SalesSettingsRoute() {
- const { companySettings } = useLoaderData<typeof loader>();
+ const { companySettings, terms } = useLoaderData<typeof loader>();
const fetcher = useFetcher<typeof action>();
const [digitalQuoteEnabled, setDigitalQuoteEnabled] = useState(
companySettings.digitalQuoteEnabled ?? false
@@ -119,6 +133,46 @@ export default function SalesSettingsRoute() {
}
}, [fetcher.data?.message, fetcher.data?.success]);
+ const permissions = usePermissions();
+ const { carbon } = useCarbon();
+ const {
+ id: userId,
+ company: { id: companyId },
+ } = useUser();
+
+ const [salesTermsStatus, setSalesTermsStatus] = useState<"saved" | "draft">(
+ "saved"
+ );
+
+ const handleUpdateSalesTerms = (content: JSONContent) => {
+ setSalesTermsStatus("draft");
+ onUpdateSalesTerms(content);
+ };
+
+ const onUpdateSalesTerms = useDebounce(
+ async (content: JSONContent) => {
+ setSalesTermsStatus("draft");
+ await carbon
+ ?.from("terms")
+ .update({
+ salesTerms: content,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("id", companyId);
+ setSalesTermsStatus("saved");
+ },
+ 2500,
+ true
+ );
+
+ const onUploadImage = async (file: File) => {
+ // Implement image upload logic here
+ // This is a placeholder function
+ console.error("Image upload not implemented", file);
+ return "";
+ };
+
return (
<ScrollArea className="w-full h-[calc(100dvh-49px)]">
<VStack spacing={2} className="p-2 h-full">
@@ -210,6 +264,40 @@ export default function SalesSettingsRoute() {
</CardFooter>
</ValidatedForm>
</Card>
+
+ <Card>
+ <HStack className="justify-between items-start">
+ <CardHeader>
+ <CardTitle>Sales Terms &amp; Conditions</CardTitle>
+ <CardDescription>
+ Define the terms and conditions for quotes and sales orders
+ </CardDescription>
+ </CardHeader>
+ <CardAction className="py-6">
+ {salesTermsStatus === "draft" ? (
+ <Badge variant="secondary">Draft</Badge>
+ ) : (
+ <LuCircleCheck className="w-4 h-4 text-emerald-500" />
+ )}
+ </CardAction>
+ </HStack>
+ <CardContent>
+ {permissions.can("update", "settings") ? (
+ <Editor
+ initialValue={(terms?.salesTerms ?? {}) as JSONContent}
+ onUpload={onUploadImage}
+ onChange={handleUpdateSalesTerms}
+ />
+ ) : (
+ <div
+ className="prose dark:prose-invert"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(terms?.salesTerms as JSONContent),
+ }}
+ />
+ )}
+ </CardContent>
+ </Card>
</VStack>
</ScrollArea>
);
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 79b681bcac..403a8b18b7 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -699,6 +699,7 @@ export const path = {
generatePath(`${x}/purchase-order/${id}/status`),
purchaseOrders: `${x}/purchasing/orders`,
purchasing: `${x}/purchasing`,
+ purchasingSettings: `${x}/settings/purchasing`,
quote: (id: string) => generatePath(`${x}/quote/${id}`),
quoteAssembly: (quoteId: string, lineId: string, assemblyId: string) =>
generatePath(
@@ -890,7 +891,6 @@ export const path = {
tableSequence: (id: string) =>
generatePath(`${x}/settings/sequences/${id}`),
tags: `${x}/settings/tags`,
- terms: `${x}/settings/terms`,
theme: `${x}/account/theme`,
timecards: `${x}/timecards`,
tool: (id: string) => generatePath(`${x}/tool/${id}`),