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: add ability to attach po to digital quote

Brad Barbin5d9be15117c6
diff --git a/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx b/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx
index e1d729cb90..85f53865d6 100644
--- a/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx
+++ b/apps/carbon/app/routes/api+/sales.digital-quote.$id.tsx
@@ -5,6 +5,7 @@ import type { ActionFunctionArgs } from "@vercel/remix";
import { json } from "@vercel/remix";
import {
convertQuoteToOrder,
+ getOpportunityByQuote,
getQuoteByExternalId,
selectedLinesValidator,
} from "~/modules/sales";
@@ -27,6 +28,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
const digitalQuoteAcceptedByEmail = String(
formData.get("digitalQuoteAcceptedByEmail")
);
+ const file = formData.get("file");
+
if (typeof selectedLinesRaw !== "string") {
return json({ success: false, message: "Invalid selected lines data" });
}
@@ -52,7 +55,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
message: "Quote not found",
});
}
- const [convert, company] = await Promise.all([
+ const [convert, company, opportunity] = await Promise.all([
convertQuoteToOrder(serviceRole, {
id: quote.data.id,
companyId: quote.data.companyId,
@@ -62,6 +65,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
digitalQuoteAcceptedByEmail,
}),
getCompany(serviceRole, quote.data.companyId),
+ getOpportunityByQuote(serviceRole, quote.data.id),
]);
if (convert.error) {
@@ -80,6 +84,14 @@ export async function action({ request, params }: ActionFunctionArgs) {
});
}
+ if (opportunity.error) {
+ console.error("Failed to get opportunity", opportunity.error);
+ return json({
+ success: false,
+ message: "Failed to send notification",
+ });
+ }
+
if (company.data?.digitalQuoteNotificationGroup?.length) {
try {
await tasks.trigger<typeof notifyTask>("notify", {
@@ -100,6 +112,33 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
}
+ if (file && file instanceof File) {
+ const purchaseOrderDocumentPath = `${company.data.id}/opportunity/${opportunity.data.id}/${file.name}`;
+
+ const fileUpload = await serviceRole.storage
+ .from("private")
+ .upload(purchaseOrderDocumentPath, file);
+
+ if (fileUpload.error) {
+ console.error("Failed to upload file", fileUpload.error);
+ return json({
+ success: false,
+ message: "Failed to upload file",
+ });
+ }
+
+ const updateOpportunity = await serviceRole
+ .from("opportunity")
+ .update({
+ purchaseOrderDocumentPath,
+ })
+ .eq("id", opportunity.data?.id!);
+
+ if (updateOpportunity.error) {
+ console.error("Failed to update opportunity", updateOpportunity.error);
+ }
+ }
+
return json({
success: true,
message: "Quote accepted!",
diff --git a/apps/carbon/app/routes/share+/quote.$id.tsx b/apps/carbon/app/routes/share+/quote.$id.tsx
index 7ad69801c2..a7fdcfc10e 100644
--- a/apps/carbon/app/routes/share+/quote.$id.tsx
+++ b/apps/carbon/app/routes/share+/quote.$id.tsx
@@ -7,6 +7,7 @@ import {
CardContent,
CardHeader,
CardTitle,
+ cn,
generateHTML,
Heading,
HStack,
@@ -41,11 +42,13 @@ import { motion } from "framer-motion";
import MotionNumber from "motion-number";
import type { Dispatch, SetStateAction } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
+import { useDropzone } from "react-dropzone";
import {
LuChevronDown,
LuCreditCard,
LuImage,
LuTruck,
+ LuUpload,
LuXCircle,
} from "react-icons/lu";
import { useMode } from "~/hooks/useMode";
@@ -885,6 +888,17 @@ const Quote = ({ data }: { data: QuoteData }) => {
const termsHTML = generateHTML(terms as JSONContent);
+ const [file, setFile] = useState<File | null>(null);
+ const onDrop = (acceptedFiles: File[]) => {
+ setFile(acceptedFiles[0]);
+ };
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
+ onDrop,
+ accept: { "application/pdf": [".pdf"] },
+ maxFiles: 1,
+ maxSize: 25 * 1024 * 1024, // 25MB limit
+ });
+
return (
<VStack spacing={8} className="w-full items-center p-2 md:p-8">
{logo && (
@@ -980,6 +994,7 @@ const Quote = ({ data }: { data: QuoteData }) => {
onSubmit={() => {
submitted.current = true;
}}
+ encType="multipart/form-data"
>
<ModalHeader>
<ModalTitle>Accept Quote</ModalTitle>
@@ -997,6 +1012,35 @@ const Quote = ({ data }: { data: QuoteData }) => {
name="digitalQuoteAcceptedByEmail"
label="Please enter your email address"
/>
+ <div
+ {...getRootProps()}
+ className={cn(
+ "w-full border-2 border-dashed rounded-lg p-8 text-center cursor-pointer",
+ isDragActive ? "border-primary" : "border-muted"
+ )}
+ >
+ <input name="file" {...getInputProps()} />
+ {file ? (
+ <>
+ <p>{file.name}</p>
+ <Button
+ variant="secondary"
+ size="sm"
+ onClick={() => setFile(null)}
+ >
+ Change
+ </Button>
+ </>
+ ) : (
+ <>
+ <p>
+ Drag and drop a Purchase Order PDF here, or click to
+ select a file
+ </p>
+ <LuUpload className="mx-auto mt-4 h-12 w-12 text-muted-foreground" />
+ </>
+ )}
+ </div>
</div>
</ModalBody>
<ModalFooter>
@@ -1008,6 +1052,7 @@ const Quote = ({ data }: { data: QuoteData }) => {
name="selectedLines"
value={JSON.stringify(selectedLines)}
/>
+
<Button
isLoading={fetcher.state !== "idle"}
isDisabled={fetcher.state !== "idle"}