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: move Customer fields Posting Group and Tax ID to a new Accounting tab
Rob Carrington67f6055fd1b8
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.tsindex f2b11e8c92..3c96ff83d6 100644--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts@@ -171,9 +171,7 @@ export const purchaseOrderReleaseValidator = zexport const supplierValidator = z.object({id: zfd.text(z.string().optional()),name: z.string().min(1, { message: "Name is required" }),- supplierTypeId: zfd.text(z.string().optional()),supplierStatusId: zfd.text(z.string().optional()),- taxId: zfd.text(z.string().optional()),accountManagerId: zfd.text(z.string().optional()),});diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.tsindex 84ab06c872..9f9b7b59b0 100644--- a/apps/carbon/app/modules/sales/sales.models.ts+++ b/apps/carbon/app/modules/sales/sales.models.ts@@ -14,12 +14,16 @@ export const salesRFQStatusType = [export const customerValidator = z.object({id: zfd.text(z.string().optional()),name: z.string().min(1, { message: "Name is required" }),- customerTypeId: zfd.text(z.string().optional()),customerStatusId: zfd.text(z.string().optional()),- taxId: zfd.text(z.string().optional()),accountManagerId: zfd.text(z.string().optional()),});+export const customerAccountingValidator = z.object({+ id: zfd.text(z.string()),+ customerTypeId: zfd.text(z.string().optional()),+ taxId: zfd.text(z.string().optional()),+});+export const customerContactValidator = z.object({id: zfd.text(z.string().optional()),...contact,diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 4953d30f50..da5ad95a47 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -8,6 +8,7 @@ import type { GenericQueryFilters } from "~/utils/query";import { setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import type {+ customerAccountingValidator,customerContactValidator,customerPaymentValidator,customerShippingValidator,@@ -1062,6 +1063,18 @@ export async function upsertCustomer(.single();}+export async function updateCustomerAccounting(+ client: SupabaseClient<Database>,+ customerAccounting: z.infer<typeof customerAccountingValidator> & {+ updatedBy: string;+ }+) {+ return client+ .from("customer")+ .update(sanitize(customerAccounting))+ .eq("id", customerAccounting.id);+}+export async function updateCustomerContact(client: SupabaseClient<Database>,customerContact: {diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerAccountingForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerAccountingForm.tsxnew file mode 100644index 0000000000..ad68f1dd52--- /dev/null+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerAccountingForm.tsx@@ -0,0 +1,57 @@+import {+ Card,+ CardContent,+ CardFooter,+ CardHeader,+ CardTitle,+ HStack,+} from "@carbon/react";+import { ValidatedForm } from "@carbon/remix-validated-form";+import type { z } from "zod";+import { CustomerType, Hidden, Input, Submit } from "~/components/Form";+import { usePermissions } from "~/hooks";+import { customerAccountingValidator } from "../../sales.models";++type CustomerPaymentFormProps = {+ initialValues: z.infer<typeof customerAccountingValidator>;+};++const CustomerAccountingForm = ({+ initialValues,+}: CustomerPaymentFormProps) => {+ const permissions = usePermissions();++ const isDisabled = !permissions.can("update", "sales");++ return (+ <ValidatedForm+ method="post"+ validator={customerAccountingValidator}+ defaultValues={initialValues}+ >+ <Card>+ <CardHeader>+ <CardTitle>Customer Accounting</CardTitle>+ </CardHeader>+ <CardContent>+ <Hidden name="id" />+ <div className="grid grid-cols-1 lg:grid-cols-3 gap-x-8 gap-y-4 w-full">+ <Input name="taxId" label="Tax ID" />+ <CustomerType+ name="customerTypeId"+ label="Posting Group"+ placeholder="Select Posting Group"+ />+ </div>+ </CardContent>+ <CardFooter>+ <HStack>+ <Submit isDisabled={isDisabled}>Save</Submit>+ </HStack>+ </CardFooter>+ </Card>+ </ValidatedForm>+ );+};++export default CustomerAccountingForm;diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsxindex 03dc4bc4ea..3d0ea693f7 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx@@ -19,7 +19,6 @@ import type { z } from "zod";import {CustomFormFields,CustomerStatus,- CustomerType,Employee,Hidden,Input,@@ -93,13 +92,7 @@ const CustomerForm = ({)}><Input name="name" label="Name" autoFocus={!isEditing} />- <Input name="taxId" label="Tax ID" />- <CustomerType- name="customerTypeId"- label="Posting Group"- placeholder="Select Posting Group"- /><CustomerStatusname="customerStatusId"label="Customer Status"diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsxindex ad6f6007bc..e1441d4443 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerSidebar/useCustomerSidebar.tsx@@ -1,11 +1,12 @@import { useParams } from "@remix-run/react";import {- BsBank,- BsCreditCard,- BsFillPersonLinesFill,- BsFillPinMapFill,- BsTruck,-} from "react-icons/bs";+ LuBuilding,+ LuContact,+ LuCreditCard,+ LuLandmark,+ LuMapPin,+ LuTruck,+} from "react-icons/lu";import { usePermissions } from "~/hooks";import type { Role } from "~/types";import { path } from "~/utils/path";@@ -23,7 +24,7 @@ export function useCustomerSidebar({ contacts, locations }: Props) {{name: "Details",to: path.to.customerDetails(customerId),- icon: BsBank,+ icon: LuBuilding,shortcut: "Command+Shift+d",},{@@ -31,7 +32,7 @@ export function useCustomerSidebar({ contacts, locations }: Props) {to: path.to.customerContacts(customerId),role: ["employee"],count: contacts,- icon: BsFillPersonLinesFill,+ icon: LuContact,shortcut: "Command+Shift+c",},{@@ -39,23 +40,30 @@ export function useCustomerSidebar({ contacts, locations }: Props) {to: path.to.customerLocations(customerId),role: ["employee", "customer"],count: locations,- icon: BsFillPinMapFill,+ icon: LuMapPin,shortcut: "Command+Shift+l",},{name: "Payments",to: path.to.customerPayment(customerId),role: ["employee"],- icon: BsCreditCard,+ icon: LuCreditCard,shortcut: "Command+Shift+p",},{name: "Shipping",to: path.to.customerShipping(customerId),role: ["employee"],- icon: BsTruck,+ icon: LuTruck,shortcut: "Command+Shift+s",},+ {+ name: "Accounting",+ to: path.to.customerAccounting(customerId),+ role: ["employee"],+ icon: LuLandmark,+ shortcut: "Command+Shift+a",+ },].filter((item) =>item.role === undefined ||diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.accounting.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.accounting.tsxnew file mode 100644index 0000000000..59de2d4659--- /dev/null+++ b/apps/carbon/app/routes/x+/customer+/$customerId.accounting.tsx@@ -0,0 +1,82 @@+import { validationError, validator } from "@carbon/remix-validated-form";+import type { ActionFunctionArgs } from "@remix-run/node";+import { json, redirect } from "@remix-run/node";+import { useParams } from "@remix-run/react";+import { useRouteData } from "~/hooks";+import type { CustomerDetail } from "~/modules/sales";+import {+ customerAccountingValidator,+ updateCustomerAccounting,+} from "~/modules/sales";+import CustomerAccountingForm from "~/modules/sales/ui/Customer/CustomerAccountingForm";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { getCustomFields } from "~/utils/form";+import { assertIsPost } from "~/utils/http";+import { path } from "~/utils/path";+import { error, success } from "~/utils/result";++export async function action({ request }: ActionFunctionArgs) {+ assertIsPost(request);+ const { client, userId } = await requirePermissions(request, {+ create: "purchasing",+ });+ const formData = await request.formData();+ const validation = await validator(customerAccountingValidator).validate(+ formData+ );++ if (validation.error) {+ return validationError(validation.error);+ }++ const { id, ...data } = validation.data;++ console.log({ data });++ if (!id) {+ throw redirect(+ path.to.customerAccounting(id),+ await flash(request, error(null, "Failed to update customer"))+ );+ }++ const update = await updateCustomerAccounting(client, {+ id,+ ...data,+ updatedBy: userId,+ });++ if (update.error) {+ throw redirect(+ path.to.customerAccounting(id),+ await flash(request, error(update.error, "Failed to update customer"))+ );+ }++ return json(null, await flash(request, success("Updated customer")));+}++export default function CustomerAccountingRoute() {+ const { customerId } = useParams();+ if (!customerId) throw new Error("Could not find customerId");+ const routeData = useRouteData<{ customer: CustomerDetail }>(+ path.to.customer(customerId)+ );++ if (!routeData?.customer) return null;++ const initialValues = {+ id: routeData?.customer?.id ?? undefined,+ customerTypeId: routeData?.customer?.customerTypeId ?? undefined,+ taxId: routeData?.customer?.taxId ?? "",+ ...getCustomFields(routeData?.customer?.customFields),+ };++ return (+ <CustomerAccountingForm+ key={initialValues.id}+ initialValues={initialValues}+ />+ );+}diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 924588f820..d119a2f584 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -142,6 +142,8 @@ export const path = {customerRoot: `${x}/customer`,customers: `${x}/sales/customers`,customerAccounts: `${x}/users/customers`,+ customerAccounting: (id: string) =>+ generatePath(`${x}/customer/${id}/accounting`),customerContact: (customerId: string, id: string) =>generatePath(`${x}/customer/${customerId}/contacts/${id}`),customerContacts: (id: string) =>@@ -659,6 +661,8 @@ export const path = {supplier: (id: string) => generatePath(`${x}/supplier/${id}`),suppliers: `${x}/purchasing/suppliers`,supplierAccounts: `${x}/users/suppliers`,+ supplierAccounting: (id: string) =>+ generatePath(`${x}/supplier/${id}/accounting`),supplierContact: (supplierId: string, id: string) =>generatePath(`${x}/supplier/${supplierId}/contacts/${id}`),supplierDetails: (id: string) =>@@ -673,8 +677,6 @@ export const path = {generatePath(`${x}/supplier/${id}/payments`),supplierShipping: (id: string) =>generatePath(`${x}/supplier/${id}/shipping`),- supplierAccounting: (id: string) =>- generatePath(`${x}/supplier/${id}/accounting`),supplierRoot: `${x}/supplier`,supplierStatus: (id: string) =>generatePath(`${x}/purchasing/supplier-statuses/${id}`),