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: use custom ids for sales and purchasing documents
Brad Barbin92f81fb6f1ca
diff --git a/apps/erp/app/components/Form/SequenceOrCustomId.tsx b/apps/erp/app/components/Form/SequenceOrCustomId.tsxindex cd89450c89..4f2a6d3d69 100644--- a/apps/erp/app/components/Form/SequenceOrCustomId.tsx+++ b/apps/erp/app/components/Form/SequenceOrCustomId.tsx@@ -50,7 +50,7 @@ const SequenceOrCustomId = forwardRef<<Buttonsize="md"variant="secondary"- className="flex-grow bg-muted text-muted-foreground justify-start pr-4 h-10 w-full"+ className="flex-grow bg-muted text-muted-foreground justify-start pr-4 h-10 w-full hover:scale-100 focus-visible:scale-100">Next Sequence</Button>diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm.tsxindex 01a9462468..32b75fb828 100644--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm.tsx@@ -21,6 +21,7 @@ import {Hidden,Input,Location,+ SequenceOrCustomId,Submit,Supplier,SupplierContact,@@ -154,7 +155,7 @@ const PurchaseInvoiceForm = ({ initialValues }: PurchaseInvoiceFormProps) => {</CardHeader><CardContent><Hidden name="id" />- <Hidden name="invoiceId" />+ {isEditing && <Hidden name="invoiceId" />}<VStack><divclassName={cn(@@ -164,6 +165,13 @@ const PurchaseInvoiceForm = ({ initialValues }: PurchaseInvoiceFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="invoiceId"+ label="Invoice ID"+ table="purchaseInvoice"+ />+ )}<Suppliername="supplierId"label="Supplier"diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceForm.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceForm.tsxindex 25c3508766..2b880ebaf2 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceForm.tsx@@ -24,6 +24,7 @@ import {Hidden,Input,Location,+ SequenceOrCustomId,Submit,} from "~/components/Form";import PaymentTerm from "~/components/Form/PaymentTerm";@@ -154,7 +155,7 @@ const SalesInvoiceForm = ({ initialValues }: SalesInvoiceFormProps) => {</CardHeader><CardContent><Hidden name="id" />- <Hidden name="invoiceId" />+ {isEditing && <Hidden name="invoiceId" />}<VStack><divclassName={cn(@@ -164,6 +165,13 @@ const SalesInvoiceForm = ({ initialValues }: SalesInvoiceFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="invoiceId"+ label="Invoice ID"+ table="salesInvoice"+ />+ )}<Customername="customerId"label="Customer"diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsxindex 5d0334eb8b..fb40901da9 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx@@ -19,6 +19,7 @@ import {CustomFormFields,Hidden,Input,+ SequenceOrCustomId,Submit,Supplier,SupplierContact,@@ -109,7 +110,7 @@ const PurchaseOrderForm = ({ initialValues }: PurchaseOrderFormProps) => {)}</CardHeader><CardContent>- <Hidden name="purchaseOrderId" />+ {isEditing && <Hidden name="purchaseOrderId" />}<VStack><divclassName={cn(@@ -119,6 +120,13 @@ const PurchaseOrderForm = ({ initialValues }: PurchaseOrderFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="purchaseOrderId"+ label="Purchase Order ID"+ table="purchaseOrder"+ />+ )}<SupplierautoFocus={!isEditing}name="supplierId"diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteForm.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteForm.tsxindex 5137c35fc4..badc98de6e 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteForm.tsx@@ -13,6 +13,7 @@ import {} from "@carbon/react";import { getLocalTimeZone, today } from "@internationalized/date";import { useFetcher } from "@remix-run/react";+import type { ReactNode } from "react";import { useState } from "react";import { flushSync } from "react-dom";import type { z } from "zod";@@ -22,6 +23,7 @@ import {DatePicker,Hidden,Input,+ SequenceOrCustomId,Submit,Supplier,SupplierContact,@@ -115,7 +117,7 @@ const SupplierQuoteForm = ({ initialValues }: SupplierQuoteFormProps) => {)}</CardHeader><CardContent>- <Hidden name="supplierQuoteId" />+ {isEditing && <Hidden name="supplierQuoteId" />}<VStack><divclassName={cn(@@ -125,6 +127,13 @@ const SupplierQuoteForm = ({ initialValues }: SupplierQuoteFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="supplierQuoteId"+ label="Supplier Quote ID"+ table="supplierQuote"+ />+ )}<SupplierautoFocus={!isEditing}name="supplierId"@@ -158,7 +167,7 @@ const SupplierQuoteForm = ({ initialValues }: SupplierQuoteFormProps) => {onChange={(newValue: {value: string | undefined;- label: string;+ label: ReactNode;} | null) => {if (newValue?.value) {diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteForm.tsxindex 1cffa5b4c3..f3053219d8 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteForm.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteForm.tsx@@ -27,6 +27,7 @@ import {Hidden,Input,Location,+ SequenceOrCustomId,Submit,} from "~/components/Form";import ExchangeRate from "~/components/Form/ExchangeRate";@@ -114,7 +115,7 @@ const QuoteForm = ({ initialValues }: QuoteFormProps) => {)}</CardHeader><CardContent>- <Hidden name="quoteId" />+ {isEditing && <Hidden name="quoteId" />}<VStack><divclassName={cn(@@ -124,6 +125,13 @@ const QuoteForm = ({ initialValues }: QuoteFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="quoteId"+ label="Quote ID"+ table="quote"+ />+ )}<CustomerautoFocus={!isEditing}name="customerId"diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsxindex ed2125095e..b0985a1dbe 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx@@ -26,6 +26,7 @@ import {Hidden,Input,Location,+ SequenceOrCustomId,Submit,} from "~/components/Form";import ExchangeRate from "~/components/Form/ExchangeRate";@@ -117,7 +118,7 @@ const SalesOrderForm = ({ initialValues }: SalesOrderFormProps) => {)}</CardHeader><CardContent>- <Hidden name="salesOrderId" />+ {isEditing && <Hidden name="salesOrderId" />}<Hidden name="status" /><VStack><div@@ -128,6 +129,13 @@ const SalesOrderForm = ({ initialValues }: SalesOrderFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="salesOrderId"+ label="Sales Order ID"+ table="salesOrder"+ />+ )}<CustomerautoFocus={!isEditing}name="customerId"diff --git a/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx b/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsxindex 01d0e068d1..d129b55aeb 100644--- a/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx@@ -21,6 +21,7 @@ import {Hidden,Input,Location,+ SequenceOrCustomId,Submit,} from "~/components/Form";import { usePermissions } from "~/hooks";@@ -60,7 +61,7 @@ const SalesRFQForm = ({ initialValues }: SalesRFQFormProps) => {)}</CardHeader><CardContent>- <Hidden name="rfqId" />+ {isEditing && <Hidden name="rfqId" />}<VStack><divclassName={cn(@@ -70,6 +71,13 @@ const SalesRFQForm = ({ initialValues }: SalesRFQFormProps) => {: "grid-cols-1 md:grid-cols-2")}>+ {!isEditing && (+ <SequenceOrCustomId+ name="rfqId"+ label="RFQ ID"+ table="salesRfq"+ />+ )}<CustomerautoFocus={!isEditing}name="customerId"diff --git a/apps/erp/app/routes/x+/purchase-invoice+/new.tsx b/apps/erp/app/routes/x+/purchase-invoice+/new.tsxindex 770eeec3ba..9873e758ed 100644--- a/apps/erp/app/routes/x+/purchase-invoice+/new.tsx+++ b/apps/erp/app/routes/x+/purchase-invoice+/new.tsx@@ -78,26 +78,33 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(- client,- "purchaseInvoice",- companyId- );- if (nextSequence.error) {- throw redirect(- path.to.newPurchaseInvoice,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )+ const { id, ...data } = validation.data;+ let invoiceId = data.invoiceId;+ const useNextSequence = !invoiceId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(+ client,+ "purchaseInvoice",+ companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newPurchaseInvoice,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ invoiceId = nextSequence.data;}- const { id, ...data } = validation.data;+ if (!invoiceId) throw new Error("invoiceId is not defined");const createPurchaseInvoice = await upsertPurchaseInvoice(client, {...data,- invoiceId: nextSequence.data,+ invoiceId,companyId,createdBy: userId,customFields: setCustomFields(formData),diff --git a/apps/erp/app/routes/x+/purchase-order+/new.tsx b/apps/erp/app/routes/x+/purchase-order+/new.tsxindex 03aa1d72d6..aed2af622c 100644--- a/apps/erp/app/routes/x+/purchase-order+/new.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/new.tsx@@ -37,24 +37,32 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(- client,- "purchaseOrder",- companyId- );- if (nextSequence.error) {- throw redirect(- path.to.newPurchaseOrder,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )+ let purchaseOrderId = validation.data.purchaseOrderId;+ const useNextSequence = !purchaseOrderId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(+ client,+ "purchaseOrder",+ companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newPurchaseOrder,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ purchaseOrderId = nextSequence.data;}+ if (!purchaseOrderId) throw new Error("purchaseOrderId is not defined");+const createPurchaseOrder = await upsertPurchaseOrder(client, {...validation.data,- purchaseOrderId: nextSequence.data,+ purchaseOrderId,companyId,createdBy: userId,customFields: setCustomFields(formData),diff --git a/apps/erp/app/routes/x+/quote+/new.tsx b/apps/erp/app/routes/x+/quote+/new.tsxindex ad9a677821..9e30d242a4 100644--- a/apps/erp/app/routes/x+/quote+/new.tsx+++ b/apps/erp/app/routes/x+/quote+/new.tsx@@ -34,20 +34,28 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(client, "quote", companyId);- if (nextSequence.error) {- throw redirect(- path.to.newQuote,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )- );+ let quoteId = validation.data.quoteId;+ const useNextSequence = !quoteId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(client, "quote", companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newQuote,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ quoteId = nextSequence.data;}+ if (!quoteId) throw new Error("quoteId is not defined");+const createQuote = await upsertQuote(client, {...validation.data,- quoteId: nextSequence.data,+ quoteId,companyId,createdBy: userId,customFields: setCustomFields(formData),diff --git a/apps/erp/app/routes/x+/sales-invoice+/new.tsx b/apps/erp/app/routes/x+/sales-invoice+/new.tsxindex f5f3e34c71..684b772bf7 100644--- a/apps/erp/app/routes/x+/sales-invoice+/new.tsx+++ b/apps/erp/app/routes/x+/sales-invoice+/new.tsx@@ -99,22 +99,33 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(client, "salesInvoice", companyId);- if (nextSequence.error) {- throw redirect(- path.to.newSalesInvoice,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )+ const { id, ...data } = validation.data;+ let invoiceId = data.invoiceId;+ const useNextSequence = !invoiceId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(+ client,+ "salesInvoice",+ companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newSalesInvoice,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ invoiceId = nextSequence.data;}- const { id, ...data } = validation.data;+ if (!invoiceId) throw new Error("invoiceId is not defined");const createSalesInvoice = await upsertSalesInvoice(client, {...data,- invoiceId: nextSequence.data,+ invoiceId,companyId,createdBy: userId,customFields: setCustomFields(formData),diff --git a/apps/erp/app/routes/x+/sales-order+/new.tsx b/apps/erp/app/routes/x+/sales-order+/new.tsxindex 4a68be6c53..3187f178ec 100644--- a/apps/erp/app/routes/x+/sales-order+/new.tsx+++ b/apps/erp/app/routes/x+/sales-order+/new.tsx@@ -32,22 +32,29 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(client, "salesOrder", companyId);- if (nextSequence.error) {- throw redirect(- path.to.newSalesOrder,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )- );+ const { id, ...data } = validation.data;+ let salesOrderId = data.salesOrderId;+ const useNextSequence = !salesOrderId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(client, "salesOrder", companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newSalesOrder,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ salesOrderId = nextSequence.data;}- const { id, salesOrderId, ...data } = validation.data;+ if (!salesOrderId) throw new Error("salesOrderId is not defined");const createSalesOrder = await upsertSalesOrder(client, {- salesOrderId: nextSequence.data,...data,+ salesOrderId,companyId,createdBy: userId,customFields: setCustomFields(formData),diff --git a/apps/erp/app/routes/x+/sales-rfq+/new.tsx b/apps/erp/app/routes/x+/sales-rfq+/new.tsxindex 1e68e96ab2..c8c924e327 100644--- a/apps/erp/app/routes/x+/sales-rfq+/new.tsx+++ b/apps/erp/app/routes/x+/sales-rfq+/new.tsx@@ -32,20 +32,28 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(client, "salesRfq", companyId);- if (nextSequence.error) {- throw redirect(- path.to.newSalesRFQ,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )- );+ let rfqId = validation.data.rfqId;+ const useNextSequence = !rfqId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(client, "salesRfq", companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newSalesRFQ,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ rfqId = nextSequence.data;}+ if (!rfqId) throw new Error("rfqId is not defined");+const createSalesRFQ = await upsertSalesRFQ(client, {...validation.data,- rfqId: nextSequence.data,+ rfqId,companyId,createdBy: userId,customFields: setCustomFields(formData),diff --git a/apps/erp/app/routes/x+/supplier-quote+/new.tsx b/apps/erp/app/routes/x+/supplier-quote+/new.tsxindex c811cfbb77..e7c0142929 100644--- a/apps/erp/app/routes/x+/supplier-quote+/new.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/new.tsx@@ -36,24 +36,32 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const nextSequence = await getNextSequence(- client,- "supplierQuote",- companyId- );- if (nextSequence.error) {- throw redirect(- path.to.newSupplierQuote,- await flash(- request,- error(nextSequence.error, "Failed to get next sequence")- )+ let supplierQuoteId = validation.data.supplierQuoteId;+ const useNextSequence = !supplierQuoteId;++ if (useNextSequence) {+ const nextSequence = await getNextSequence(+ client,+ "supplierQuote",+ companyId);+ if (nextSequence.error) {+ throw redirect(+ path.to.newSupplierQuote,+ await flash(+ request,+ error(nextSequence.error, "Failed to get next sequence")+ )+ );+ }+ supplierQuoteId = nextSequence.data;}+ if (!supplierQuoteId) throw new Error("supplierQuoteId is not defined");+const createSupplierQuote = await upsertSupplierQuote(client, {...validation.data,- supplierQuoteId: nextSequence.data,+ supplierQuoteId,companyId,createdBy: userId,customFields: setCustomFields(formData),