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
- pushing before merge updates email and rendering
Gaurav Bhatt1cba99afce88
diff --git a/apps/erp/app/modules/purchasing/purchasing.models.ts b/apps/erp/app/modules/purchasing/purchasing.models.tsindex 17be2e278f..02ad8ab033 100644--- a/apps/erp/app/modules/purchasing/purchasing.models.ts+++ b/apps/erp/app/modules/purchasing/purchasing.models.ts@@ -59,6 +59,16 @@ export const purchaseOrderStatusType = ["Closed",] as const;+export const externalSupplierQuoteValidator = z.object({+ digitalSupplierQuoteSubmittedBy: zfd.text(+ z.string().min(1, { message: "Name is required" })+ ),+ digitalSupplierQuoteSubmittedByEmail: zfd.text(+ z.string().email({ message: "Email is invalid" })+ ),+ note: zfd.text(z.string().optional()),+});+export const plannedOrderValidator = z.object({startDate: zfd.text(z.string().nullable()),dueDate: zfd.text(z.string().nullable()),@@ -95,16 +105,6 @@ export const purchaseOrderValidator = z.object({exchangeRateUpdatedAt: zfd.text(z.string().optional()),});-export const externalSupplierQuoteValidator = z.object({- digitalSupplierQuoteSubmittedBy: zfd.text(- z.string().min(1, { message: "Name is required" })- ),- digitalSupplierQuoteSubmittedByEmail: zfd.text(- z.string().email({ message: "Email is invalid" })- ),- note: zfd.text(z.string().optional()),-});-export const supplierQuoteFinalizeValidator = z.object({notification: z.enum(["Email", "None"]).optional(),diff --git a/apps/erp/app/modules/purchasing/purchasing.service.ts b/apps/erp/app/modules/purchasing/purchasing.service.tsindex b0b2a1c22e..55521be305 100644--- a/apps/erp/app/modules/purchasing/purchasing.service.ts+++ b/apps/erp/app/modules/purchasing/purchasing.service.ts@@ -69,48 +69,6 @@ export async function convertSupplierQuoteToOrder(});}-export async function finalizeSupplierQuote(- client: SupabaseClient<Database>,- supplierQuoteId: string,- userId: string-) {- const quoteUpdate = await client- .from("supplierQuote")- .update({- status: "Active",- updatedAt: today(getLocalTimeZone()).toString(),- updatedBy: userId,- })- .eq("id", supplierQuoteId);-- if (quoteUpdate.error) {- return quoteUpdate;- }-- return quoteUpdate;-}--export async function sendSupplierQuote(- client: SupabaseClient<Database>,- supplierQuoteId: string,- userId: string-) {- // Send keeps status as Draft, just updates timestamp- const quoteUpdate = await client- .from("supplierQuote")- .update({- updatedAt: today(getLocalTimeZone()).toString(),- updatedBy: userId,- })- .eq("id", supplierQuoteId);-- if (quoteUpdate.error) {- return quoteUpdate;- }-- return quoteUpdate;-}-export async function deletePurchaseOrder(client: SupabaseClient<Database>,purchaseOrderId: string@@ -226,6 +184,27 @@ export async function getPurchaseOrder(.single();}+export async function finalizeSupplierQuote(+ client: SupabaseClient<Database>,+ supplierQuoteId: string,+ userId: string+) {+ const quoteUpdate = await client+ .from("supplierQuote")+ .update({+ status: "Active",+ updatedAt: today(getLocalTimeZone()).toString(),+ updatedBy: userId,+ })+ .eq("id", supplierQuoteId);++ if (quoteUpdate.error) {+ return quoteUpdate;+ }++ return { data: null, error: null };+}+export async function getPurchaseOrders(client: SupabaseClient<Database>,companyId: string,@@ -965,6 +944,27 @@ export async function finalizePurchaseOrder(.eq("id", purchaseOrderId);}+export async function sendSupplierQuote(+ client: SupabaseClient<Database>,+ supplierQuoteId: string,+ userId: string+) {+ // Send keeps status as Draft, just updates timestamp+ const quoteUpdate = await client+ .from("supplierQuote")+ .update({+ updatedAt: today(getLocalTimeZone()).toString(),+ updatedBy: userId,+ })+ .eq("id", supplierQuoteId);++ if (quoteUpdate.error) {+ return quoteUpdate;+ }++ return { data: null, error: null };+}+export async function updatePurchaseOrder(client: SupabaseClient<Database>,purchaseOrder: {@@ -1527,10 +1527,14 @@ export async function upsertSupplierQuote(});if (externalLink.data) {- await client+ const update = await client.from("supplierQuote").update({ externalLinkId: externalLink.data.id }).eq("id", supplierQuoteId);++ if (update.error) {+ return update;+ }}}diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteHeader.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteHeader.tsxindex 3b45fee6f8..12c7eb1082 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteHeader.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteHeader.tsx@@ -90,11 +90,14 @@ const SupplierQuoteHeader = () => {const statusFetcher = useFetcher<{}>();const hasLines = routeData?.lines && routeData.lines.length > 0;- const quoteStatus = routeData?.quote?.status ?? "";+ const quoteStatus: string = routeData?.quote?.status ?? "";const editableStatuses = ["Draft", "Active", "Declined"];const isEditableStatus = editableStatuses.includes(quoteStatus);const canShare = routeData?.quote.externalLinkId && isEditableStatus;+ const canPreview =+ routeData?.quote.externalLinkId &&+ ["Draft", "Declined"].includes(quoteStatus);const canSend =isEditableStatus && permissions.can("update", "purchasing") && hasLines;@@ -158,7 +161,7 @@ const SupplierQuoteHeader = () => {Share</Button>)}- {canShare && (+ {canPreview && (<DropdownMenu><DropdownMenuTrigger asChild><Button@@ -191,6 +194,7 @@ const SupplierQuoteHeader = () => {onClick={sendModal.onOpen}isLoading={sendFetcher.state !== "idle"}isDisabled={+ quoteStatus == "Active" ||sendFetcher.state !== "idle" ||!permissions.can("update", "purchasing") ||!hasLines@@ -322,11 +326,12 @@ const SupplierQuoteHeader = () => {quote={routeData?.quote}onClose={sendModal.onClose}fetcher={sendFetcher}+ externalLinkId={routeData?.quote?.externalLinkId ?? ""}/>)}<ShareQuoteModalid={id}- externalLinkId={(routeData?.quote as any)?.externalLinkId}+ externalLinkId={routeData?.quote?.externalLinkId || ""}onClose={shareModal.onClose}isOpen={shareModal.isOpen}/>diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSendModal.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSendModal.tsxindex 3876aa9aa5..e468f974c7 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSendModal.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSendModal.tsx@@ -1,6 +1,10 @@import { ValidatedForm } from "@carbon/form";import {Button,+ Copy,+ Input,+ InputGroup,+ InputRightElement,Modal,ModalBody,ModalContent,@@ -22,12 +26,14 @@ type SupplierQuoteSendModalProps = {onClose: () => void;quote?: SupplierQuote;fetcher: FetcherWithComponents<{}>;+ externalLinkId?: string;};const SupplierQuoteSendModal = ({quote,onClose,fetcher,+ externalLinkId,}: SupplierQuoteSendModalProps) => {const integrations = useIntegrations();const canEmail = integrations.has("resend");@@ -36,6 +42,48 @@ const SupplierQuoteSendModal = ({canEmail ? "Email" : "None");+ const digitalQuoteUrl =+ externalLinkId && typeof window !== "undefined"+ ? `${window.location.origin}${path.to.externalSupplierQuote(+ externalLinkId+ )}`+ : "";++ if (!canEmail) {+ return (+ <Modal+ open+ onOpenChange={(open) => {+ if (!open) {+ onClose();+ }+ }}+ >+ <ModalContent>+ <ModalHeader>+ <ModalTitle>Send {quote?.supplierQuoteId}</ModalTitle>+ <ModalDescription>+ Copy this link to share the quote with a supplier+ </ModalDescription>+ </ModalHeader>+ <ModalBody>+ <InputGroup>+ <Input value={digitalQuoteUrl} isReadOnly />+ <InputRightElement>+ <Copy text={digitalQuoteUrl} />+ </InputRightElement>+ </InputGroup>+ </ModalBody>+ <ModalFooter>+ <Button variant="secondary" onClick={onClose}>+ Close+ </Button>+ </ModalFooter>+ </ModalContent>+ </Modal>+ );+ }+return (<Modalopen@@ -49,7 +97,7 @@ const SupplierQuoteSendModal = ({<ValidatedFormmethod="post"validator={supplierQuoteFinalizeValidator}- action={path.to.supplierQuoteSend(quote?.id)}+ action={path.to.supplierQuoteSend(quote?.id || "")}onSubmit={onClose}defaultValues={{notification: notificationType as "Email" | "None",diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsxindex bc63495f8b..e087f9bc7d 100644--- a/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsx@@ -109,22 +109,27 @@ export async function action(args: ActionFunctionArgs) {const requestUrl = new URL(request.url);const baseUrl = `${requestUrl.protocol}//${requestUrl.host}`;- const externalQuoteUrl = `${baseUrl}${path.to.externalSupplierQuote(+ const externalQuoteUrl: string = `${baseUrl}${path.to.externalSupplierQuote(externalLink.data?.id ?? "")}`;const emailSubject = `Supplier Quote ${supplierQuote.data.supplierQuoteId} from ${company.data.name}`;- // Hey there,- // \n\nHere is the link to the supplier quote form. We’d appreciate it if you could provide your quote for the listed items. Please go ahead and fill out the form.- const emailMessage = `Hey there,\n\nHere is the link to the supplier quote ${supplierQuote.data.supplierQuoteId}. We’d appreciate it if you could provide your quote for the listed items. Please go ahead and fill out the form.`;+ const emailBody = `Hey ${supplierContact.data.contact.firstName},\n\nPlease provide pricing and lead time(s) for the linked quote:`;+ const emailSignature = `Thanks,\n${user.data.firstName} ${user.data.lastName}\n${company.data.name}`;await tasks.trigger<typeof sendEmailResendTask>("send-email-resend", {to: [user.data.email, supplierContact.data.contact.email],from: user.data.email,subject: emailSubject,- html: `${emailMessage}<br><br><a href="${externalQuoteUrl}">${externalQuoteUrl}</a>`,- text: `${emailMessage}\n\n${externalQuoteUrl}`,+ html: `${emailBody.replace(+ /\n/g,+ "<br>"+ )}<br><a href="${externalQuoteUrl}">${externalQuoteUrl}</a><br><br>${emailSignature.replace(+ /\n/g,+ "<br>"+ )}`,+ text: `${emailBody}\n\n${externalQuoteUrl}\n\n${emailSignature}`,companyId,});} catch (err) {