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
Sales Order PDF (#38)
Brad Barbin22f062c66a88
diff --git a/apps/carbon/app/components/Assignee.tsx b/apps/carbon/app/components/Assignee.tsxindex 21f0ddd56b..6c9607d777 100644--- a/apps/carbon/app/components/Assignee.tsx+++ b/apps/carbon/app/components/Assignee.tsx@@ -12,6 +12,7 @@ import {import { useFetcher, useFetchers } from "@remix-run/react";import type { ComponentPropsWithoutRef } from "react";import { forwardRef, useMemo, useState } from "react";+import { LuUser } from "react-icons/lu";import { RxCheck } from "react-icons/rx";import { useUser } from "~/hooks";import { usePeople } from "~/stores";@@ -98,7 +99,10 @@ const Assign = forwardRef<HTMLButtonElement, AssigneeProps>({value ? (<EmployeeAvatar size={size ?? "xs"} employeeId={value ?? null} />) : (- <span className="text-sm">Unassigned</span>+ <div className="flex items-center justify-start gap-2">+ <LuUser className="w-4 h-4" />+ <span className="text-sm">Unassigned</span>+ </div>)}</button></PopoverTrigger>diff --git a/apps/carbon/app/components/Form/CustomerLocation.tsx b/apps/carbon/app/components/Form/CustomerLocation.tsxindex e929343638..3798dc34a1 100644--- a/apps/carbon/app/components/Form/CustomerLocation.tsx+++ b/apps/carbon/app/components/Form/CustomerLocation.tsx@@ -1,5 +1,5 @@import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo, useRef } from "react";+import { useEffect, useMemo, useRef, useState } from "react";import {CustomerLocationForm,type CustomerLocation as CustomerLocationType,@@ -25,7 +25,7 @@ const CustomerLocation = (props: CustomerLocationSelectProps) => {useFetcher<Awaited<ReturnType<typeof getCustomerLocations>>>();const newLocationModal = useDisclosure();- // const [created, setCreated] = useState<string>("");+ const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);useEffect(() => {@@ -71,7 +71,7 @@ const CustomerLocation = (props: CustomerLocationSelectProps) => {onChange={onChange}onCreateOption={(option) => {newLocationModal.onOpen();- // setCreated(option);+ setCreated(option);}}/>{newLocationModal.isOpen && (@@ -79,11 +79,11 @@ const CustomerLocation = (props: CustomerLocationSelectProps) => {customerId={props.customer!}type="modal"onClose={() => {- // setCreated("");+ setCreated("");newLocationModal.onClose();triggerRef.current?.click();}}- initialValues={{ name: "" }}+ initialValues={{ name: created }}/>)}</>diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.tsindex 5b4545a8e3..8684e1a923 100644--- a/apps/carbon/app/modules/sales/sales.models.ts+++ b/apps/carbon/app/modules/sales/sales.models.ts@@ -547,6 +547,11 @@ export const salesOrderLineValidator = zitemId: zfd.text(z.string().optional()),itemReadableId: zfd.text(z.string().optional()),locationId: zfd.text(z.string().optional()),+ methodType: z+ .enum(methodType, {+ errorMap: () => ({ message: "Method is required" }),+ })+ .optional(),modelUploadId: zfd.text(z.string().optional()),promisedDate: zfd.text(z.string().optional()),saleQuantity: zfd.numeric(z.number().optional()),@@ -566,6 +571,34 @@ export const salesOrderLineValidator = zmessage: "Comment is required",path: ["description"], // path of error}+ )+ .refine(+ (data) => {+ if (+ data.salesOrderLineType !== "Comment" &&+ data.salesOrderLineType !== "Fixed Asset"+ ) {+ return !!data.itemId;+ }+ return true;+ },+ {+ message: "Item is required for this line type",+ path: ["itemId"],+ }+ )+ .refine(+ (data) => {+ // If sales order line type is not "Comment", we require a method type+ if (data.salesOrderLineType !== "Comment" && !data.methodType) {+ return false;+ }+ return true;+ },+ {+ message: "Method type is required",+ path: ["methodType"],+ });export const salesOrderPaymentValidator = z.object({diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex a92e8b59ee..07bcf2bb3f 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -604,6 +604,17 @@ export async function getQuoteLines(return client.from("quoteLines").select("*").eq("quoteId", quoteId);}+export async function getSalesOrderCustomerDetails(+ client: SupabaseClient<Database>,+ salesOrderId: string+) {+ return client+ .from("salesOrderLocations")+ .select("*")+ .eq("id", salesOrderId)+ .single();+}+export async function getSalesOrderExternalDocuments(client: SupabaseClient<Database>,companyId: string,diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsxindex da9b88ebbc..075679db35 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx@@ -7,6 +7,7 @@ import {CardTitle,HStack,} from "@carbon/react";+import { useParams } from "@remix-run/react";import { useState } from "react";import type { z } from "zod";import {@@ -18,7 +19,8 @@ import {PaymentTerm,Submit,} from "~/components/Form";-import { usePermissions } from "~/hooks";+import { usePermissions, useRouteData } from "~/hooks";+import type { Quotation } from "~/modules/sales";import { quotePaymentValidator } from "~/modules/sales";import { path } from "~/utils/path";@@ -32,7 +34,16 @@ const QuotePaymentForm = ({ initialValues }: QuotePaymentFormProps) => {initialValues.invoiceCustomerId);- const isDisabled = !permissions.can("update", "sales");+ const { quoteId } = useParams();+ if (!quoteId) throw new Error("quoteId not found");+ const routeData = useRouteData<{+ quote: Quotation;+ }>(path.to.quote(quoteId));++ const isEditable = ["Draft", "To Review"].includes(+ routeData?.quote?.status ?? ""+ );+ const isDisabled = !isEditable || !permissions.can("update", "sales");return (<Card isCollapsible defaultCollapsed>diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsxindex d33491e9eb..008a1575fa 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx@@ -6,6 +6,7 @@ import {CardHeader,CardTitle,} from "@carbon/react";+import { useParams } from "@remix-run/react";import type { z } from "zod";import {DatePicker,@@ -14,7 +15,8 @@ import {ShippingMethod,Submit,} from "~/components/Form";-import { usePermissions } from "~/hooks";+import { usePermissions, useRouteData } from "~/hooks";+import type { Quotation } from "~/modules/sales";import { quoteShipmentValidator } from "~/modules/sales";import { path } from "~/utils/path";@@ -36,6 +38,16 @@ QuoteShipmentFormProps) => {const isCustomer = permissions.is("customer");+ const { quoteId } = useParams();+ if (!quoteId) throw new Error("quoteId not found");+ const routeData = useRouteData<{+ quote: Quotation;+ }>(path.to.quote(quoteId));++ const isEditable = ["Draft", "To Review"].includes(+ routeData?.quote?.status ?? ""+ );+return (<Card isCollapsible defaultCollapsed><ValidatedForm@@ -68,7 +80,11 @@ QuoteShipmentFormProps) => {</div></CardContent><CardFooter>- <Submit isDisabled={!permissions.can("update", "sales")}>Save</Submit>+ <Submit+ isDisabled={!permissions.can("update", "sales") || !isEditable}+ >+ Save+ </Submit></CardFooter></ValidatedForm></Card>diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteStatus.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteStatus.tsxindex 0d5e4089be..75a2a5d14f 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteStatus.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteStatus.tsx@@ -10,9 +10,10 @@ const QuoteStatus = ({ status }: QuoteStatusProps) => {case "Draft":return <Status color="gray">{status}</Status>;case "Sent":+ return <Status color="green">{status}</Status>;case "Ordered":case "Partial":- return <Status color="green">{status}</Status>;+ return <Status color="blue">{status}</Status>;case "Lost":case "Cancelled":case "Expired":diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderHeader.tsx b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderHeader.tsxindex c4a1f6cf51..50b453f0a4 100644--- a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderHeader.tsx+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderHeader.tsx@@ -53,7 +53,7 @@ const SalesOrderHeader = () => {className="h-8"isReadOnly={!permissions.can("update", "sales")}/>- <Button leftIcon={<LuEye />} isDisabled variant="secondary" asChild>+ <Button leftIcon={<LuEye />} variant="secondary" asChild><atarget="_blank"href={path.to.file.salesOrder(orderId)}diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsxindex 4e3d3e1fc0..9a098ba8ff 100644--- a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx@@ -1,5 +1,6 @@import {CardAction,+ cn,DropdownMenu,DropdownMenuContent,DropdownMenuIcon,@@ -30,11 +31,13 @@ import {CustomFormFields,DatePicker,Hidden,+ InputControlled,Item,Location,Number,NumberControlled,Select,+ SelectControlled,Submit,UnitOfMeasure,} from "~/components/Form";@@ -47,6 +50,7 @@ import type {SalesOrderLineType,} from "~/modules/sales";import { salesOrderLineType, salesOrderLineValidator } from "~/modules/sales";+import { methodType } from "~/modules/shared";import { path } from "~/utils/path";import DeleteSalesOrderLine from "./DeleteSalesOrderLine";@@ -81,6 +85,7 @@ const SalesOrderLineForm = ({const [itemData, setItemData] = useState<{itemId: string;itemReadableId?: string;+ methodType: string;description: string;unitPrice: number;uom: string;@@ -90,6 +95,7 @@ const SalesOrderLineForm = ({itemId: initialValues.itemId ?? "",itemReadableId: initialValues.itemReadableId ?? "",description: initialValues.description ?? "",+ methodType: initialValues.methodType ?? "",unitPrice: initialValues.unitPrice ?? 0,uom: initialValues.unitOfMeasureCode ?? "",shelfId: initialValues.shelfId ?? "",@@ -116,10 +122,12 @@ const SalesOrderLineForm = ({const isEditing = initialValues.id !== undefined;- const salesOrderLineTypeOptions = salesOrderLineType.map((type) => ({- label: type,- value: type,- }));+ const salesOrderLineTypeOptions = salesOrderLineType+ .filter((type) => type !== "Fixed Asset")+ .map((type) => ({+ label: type,+ value: type,+ }));const onTypeChange = (t: SalesOrderLineType) => {// @ts-ignore@@ -129,6 +137,7 @@ const SalesOrderLineForm = ({itemReadableId: "",description: "",unitPrice: 0,+ methodType: "",uom: "EA",shelfId: "",modelUploadId: null,@@ -141,7 +150,9 @@ const SalesOrderLineForm = ({const [item, shelf, price] = await Promise.all([supabase.from("item")- .select("name, readableId, unitOfMeasureCode, modelUploadId")+ .select(+ "name, readableId, defaultMethodType, unitOfMeasureCode, modelUploadId"+ ).eq("id", itemId).eq("companyId", company.id).single(),@@ -164,6 +175,7 @@ const SalesOrderLineForm = ({itemId,itemReadableId: item.data?.readableId,description: item.data?.name ?? "",+ methodType: item.data?.defaultMethodType ?? "",unitPrice: price.data?.unitSalePrice ?? 0,uom: item.data?.unitOfMeasureCode ?? "EA",shelfId: shelf.data?.defaultShelfId ?? "",@@ -215,14 +227,20 @@ const SalesOrderLineForm = ({><HStack className="w-full justify-between items-start"><ModalCardHeader>- <ModalCardTitle>+ <ModalCardTitle+ className={cn(+ isEditing &&+ !itemData?.itemReadableId &&+ "text-muted-foreground"+ )}+ >{isEditing- ? itemData?.itemReadableId ?? "Sales Order Line"+ ? itemData?.itemReadableId || "...": "New Sales Order Line"}</ModalCardTitle><ModalCardDescription>{isEditing- ? itemData?.description+ ? itemData?.description || lineType: "A sales order line contains order details for a particular item"}</ModalCardDescription></ModalCardHeader>@@ -280,18 +298,49 @@ const SalesOrderLineForm = ({<Itemname="itemId"label={lineType}- // @ts-ignore- type={lineType}+ type={lineType as "Part"}+ value={itemData.itemId}onChange={(value) => {onChange(value?.value as string);}}/>)}+ <InputControlled+ name="description"+ label="Description"+ value={itemData.description}+ onChange={(newValue) =>+ setItemData((d) => ({ ...d, description: newValue }))+ }+ />+{lineType !== "Comment" && (<>+ <SelectControlled+ name="methodType"+ label="Method"+ options={+ methodType.map((m) => ({+ label: m,+ value: m,+ })) ?? []+ }+ value={itemData.methodType}+ onChange={(newValue) => {+ if (newValue)+ setItemData((d) => ({+ ...d,+ methodType: newValue?.value,+ }));+ }}+ /><Number name="saleQuantity" label="Quantity" />-+ <UnitOfMeasure+ name="unitOfMeasureCode"+ label="Unit of Measure"+ value={itemData.uom}+ /><NumberControlledname="unitPrice"label="Unit Price"@@ -315,11 +364,7 @@ const SalesOrderLineForm = ({currency: "USD",}}/>- <UnitOfMeasure- name="unitOfMeasureCode"- label="Unit of Measure"- value={itemData.uom}- />+<DatePicker name="promisedDate" label="Promised Date" />{["Part",diff --git a/apps/carbon/app/routes/file+/sales-order+/$id[.]pdf.tsx b/apps/carbon/app/routes/file+/sales-order+/$id[.]pdf.tsxnew file mode 100644index 0000000000..85eb7b4da5--- /dev/null+++ b/apps/carbon/app/routes/file+/sales-order+/$id[.]pdf.tsx@@ -0,0 +1,82 @@+import { SalesOrderPDF } from "@carbon/documents";+import { renderToStream } from "@react-pdf/renderer";+import { type LoaderFunctionArgs } from "@remix-run/node";+import logger from "~/lib/logger";+import {+ getSalesOrder,+ getSalesOrderCustomerDetails,+ getSalesOrderLines,+} from "~/modules/sales";+import { getCompany } from "~/modules/settings";+import { requirePermissions } from "~/services/auth/auth.server";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const { client, companyId } = await requirePermissions(request, {+ view: "sales",+ });++ const { id } = params;+ if (!id) throw new Error("Could not find id");++ const [company, salesOrder, salesOrderLines, salesOrderLocations] =+ await Promise.all([+ getCompany(client, companyId),+ getSalesOrder(client, id),+ getSalesOrderLines(client, id),+ getSalesOrderCustomerDetails(client, id),+ ]);++ if (company.error) {+ logger.error(company.error);+ }++ if (salesOrder.error) {+ logger.error(salesOrder.error);+ }++ if (salesOrderLines.error) {+ logger.error(salesOrderLines.error);+ }++ if (salesOrderLocations.error) {+ logger.error(salesOrderLocations.error);+ }++ if (+ company.error ||+ salesOrder.error ||+ salesOrderLines.error ||+ salesOrderLocations.error+ ) {+ throw new Error("Failed to load sales order");+ }++ const stream = await renderToStream(+ <SalesOrderPDF+ company={company.data}+ meta={{+ author: "CarbonOS",+ keywords: "sales order",+ subject: "Sales Order",+ }}+ salesOrder={salesOrder.data}+ salesOrderLines={salesOrderLines.data ?? []}+ salesOrderLocations={salesOrderLocations.data}+ title="Sales Order"+ />+ );++ const body: Buffer = await new Promise((resolve, reject) => {+ const buffers: Uint8Array[] = [];+ stream.on("data", (data) => {+ buffers.push(data);+ });+ stream.on("end", () => {+ resolve(Buffer.concat(buffers));+ });+ stream.on("error", reject);+ });++ const headers = new Headers({ "Content-Type": "application/pdf" });+ return new Response(body, { status: 200, headers });+}diff --git a/apps/carbon/app/routes/oauth+/authorize.tsx b/apps/carbon/app/routes/oauth+/authorize.tsxindex 2e5923358b..3d883c2175 100644--- a/apps/carbon/app/routes/oauth+/authorize.tsx+++ b/apps/carbon/app/routes/oauth+/authorize.tsx@@ -1,4 +1,5 @@import { validator } from "@carbon/form";+import { Button } from "@carbon/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";import { Form, json, redirect, useLoaderData } from "@remix-run/react";import { z } from "zod";@@ -106,12 +107,7 @@ export default function AuthorizeRoute() {<input type="hidden" name="redirect_uri" value={redirectUri || ""} /><input type="hidden" name="response_type" value={responseType || ""} />{state && <input type="hidden" name="state" value={state} />}- <button- type="submit"- className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"- >- Authorize- </button>+ <Button>Authorize</Button></Form></div>);diff --git a/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx b/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsxindex 43bc750bb3..59370b3022 100644--- a/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx+++ b/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx@@ -112,6 +112,7 @@ export default function EditSalesOrderLineRoute() {description: line?.description ?? "",itemReadableId: line?.itemReadableId ?? "",locationId: line?.locationId ?? undefined,+ methodType: line?.methodType ?? "Make",promisedDate: line?.promisedDate ?? undefined,saleQuantity: line?.saleQuantity ?? 1,setupPrice: line?.setupPrice ?? 0,diff --git a/package-lock.json b/package-lock.jsonindex 23fe5d2680..35bbcd9eed 100644--- a/package-lock.json+++ b/package-lock.json@@ -26842,6 +26842,74 @@}}},+ "node_modules/react-pdf-tailwind": {+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/react-pdf-tailwind/-/react-pdf-tailwind-2.3.0.tgz",+ "integrity": "sha512-RREimnynuF0WAsATdYWhJATY5oNAUp9Ib07JE3Pl5oQW07R5T002xjfXk06e9BPh50DvMm9qZkDglZ7u4xzySQ==",+ "dependencies": {+ "@react-pdf/renderer": "^3.1.14",+ "tailwindcss": "^3.3.6"+ }+ },+ "node_modules/react-pdf-tailwind/node_modules/glob-parent": {+ "version": "6.0.2",+ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",+ "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==",+ "dependencies": {+ "is-glob": "^4.0.3"+ },+ "engines": {+ "node": ">=10.13.0"+ }+ },+ "node_modules/react-pdf-tailwind/node_modules/postcss-selector-parser": {+ "version": "6.1.2",+ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.1.2.tgz",+ "integrity": "sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==",+ "dependencies": {+ "cssesc": "^3.0.0",+ "util-deprecate": "^1.0.2"+ },+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/react-pdf-tailwind/node_modules/tailwindcss": {+ "version": "3.4.10",+ "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.10.tgz",+ "integrity": "sha512-KWZkVPm7yJRhdu4SRSl9d4AK2wM3a50UsvgHZO7xY77NQr2V+fIrEuoDGQcbvswWvFGbS2f6e+jC/6WJm1Dl0w==",+ "dependencies": {+ "@alloc/quick-lru": "^5.2.0",+ "arg": "^5.0.2",+ "chokidar": "^3.5.3",+ "didyoumean": "^1.2.2",+ "dlv": "^1.1.3",+ "fast-glob": "^3.3.0",+ "glob-parent": "^6.0.2",+ "is-glob": "^4.0.3",+ "jiti": "^1.21.0",+ "lilconfig": "^2.1.0",+ "micromatch": "^4.0.5",+ "normalize-path": "^3.0.0",+ "object-hash": "^3.0.0",+ "picocolors": "^1.0.0",+ "postcss": "^8.4.23",+ "postcss-import": "^15.1.0",+ "postcss-js": "^4.0.1",+ "postcss-load-config": "^4.0.1",+ "postcss-nested": "^6.0.1",+ "postcss-selector-parser": "^6.0.11",+ "resolve": "^1.22.2",+ "sucrase": "^3.32.0"+ },+ "bin": {+ "tailwind": "lib/cli.js",+ "tailwindcss": "lib/cli.js"+ },+ "engines": {+ "node": ">=14.0.0"+ }+ },"node_modules/react-phone-number-input": {"version": "3.4.5","resolved": "https://registry.npmjs.org/react-phone-number-input/-/react-phone-number-input-3.4.5.tgz",@@ -33696,7 +33764,8 @@"@react-email/components": "0.0.16","@react-pdf/renderer": "^3.1.14","react-hook-form": "7.51.2",- "react-icons": "^5.2.1"+ "react-icons": "^5.2.1",+ "react-pdf-tailwind": "~2.3.0"},"devDependencies": {"@carbon/database": "*",diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.tsindex f8b925c4dd..c8dbfd20ba 100644--- a/packages/database/src/swagger-docs-schema.ts+++ b/packages/database/src/swagger-docs-schema.ts@@ -4302,6 +4302,9 @@ export default {{$ref: "#/parameters/rowFilter.salesOrderLines.addOnCost",},+ {+ $ref: "#/parameters/rowFilter.salesOrderLines.methodType",+ },{$ref: "#/parameters/rowFilter.salesOrderLines.modelId",},@@ -4323,6 +4326,12 @@ export default {{$ref: "#/parameters/rowFilter.salesOrderLines.unitCost",},+ {+ $ref: "#/parameters/rowFilter.salesOrderLines.customerPartId",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLines.customerPartRevision",+ },{$ref: "#/parameters/select",},@@ -8724,6 +8733,9 @@ export default {{$ref: "#/parameters/rowFilter.salesOrderLine.addOnCost",},+ {+ $ref: "#/parameters/rowFilter.salesOrderLine.methodType",+ },{$ref: "#/parameters/select",},@@ -8876,6 +8888,9 @@ export default {{$ref: "#/parameters/rowFilter.salesOrderLine.addOnCost",},+ {+ $ref: "#/parameters/rowFilter.salesOrderLine.methodType",+ },{$ref: "#/parameters/preferReturn",},@@ -8982,6 +8997,9 @@ export default {{$ref: "#/parameters/rowFilter.salesOrderLine.addOnCost",},+ {+ $ref: "#/parameters/rowFilter.salesOrderLine.methodType",+ },{$ref: "#/parameters/body.salesOrderLine",},@@ -27015,6 +27033,93 @@ export default {tags: ["itemCost"],},},+ "/salesOrderLocations": {+ get: {+ parameters: [+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.id",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerName",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerAddressLine1",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerAddressLine2",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerCity",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerState",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerPostalCode",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.customerCountryCode",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentCustomerName",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentAddressLine1",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentAddressLine2",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentCity",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentState",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentPostalCode",+ },+ {+ $ref: "#/parameters/rowFilter.salesOrderLocations.paymentCountryCode",+ },+ {+ $ref: "#/parameters/select",+ },+ {+ $ref: "#/parameters/order",+ },+ {+ $ref: "#/parameters/range",+ },+ {+ $ref: "#/parameters/rangeUnit",+ },+ {+ $ref: "#/parameters/offset",+ },+ {+ $ref: "#/parameters/limit",+ },+ {+ $ref: "#/parameters/preferCount",+ },+ ],+ responses: {+ "200": {+ description: "OK",+ schema: {+ items: {+ $ref: "#/definitions/salesOrderLocations",+ },+ type: "array",+ },+ },+ "206": {+ description: "Partial Content",+ },+ },+ tags: ["salesOrderLocations"],+ },+ },"/oauthCode": {get: {parameters: [@@ -34826,6 +34931,11 @@ export default {format: "numeric",type: "number",},+ methodType: {+ enum: ["Buy", "Make", "Pick"],+ format: 'public."methodType"',+ type: "string",+ },modelId: {format: "text",type: "string",@@ -34854,6 +34964,14 @@ export default {format: "numeric",type: "number",},+ customerPartId: {+ format: "text",+ type: "string",+ },+ customerPartRevision: {+ format: "text",+ type: "string",+ },},type: "object",},@@ -36748,6 +36866,7 @@ export default {"createdBy","status","addOnCost",+ "methodType",],properties: {id: {@@ -36903,6 +37022,12 @@ export default {format: "numeric",type: "number",},+ methodType: {+ default: "Make",+ enum: ["Buy", "Make", "Pick"],+ format: 'public."methodType"',+ type: "string",+ },},type: "object",},@@ -44771,6 +44896,76 @@ export default {},type: "object",},+ salesOrderLocations: {+ properties: {+ id: {+ description: "Note:\nThis is a Primary Key.<pk/>",+ format: "text",+ type: "string",+ },+ customerName: {+ format: "text",+ type: "string",+ },+ customerAddressLine1: {+ format: "text",+ type: "string",+ },+ customerAddressLine2: {+ format: "text",+ type: "string",+ },+ customerCity: {+ format: "text",+ type: "string",+ },+ customerState: {+ format: "text",+ type: "string",+ },+ customerPostalCode: {+ format: "text",+ type: "string",+ },+ customerCountryCode: {+ description:+ "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",+ format: "integer",+ type: "integer",+ },+ paymentCustomerName: {+ format: "text",+ type: "string",+ },+ paymentAddressLine1: {+ format: "text",+ type: "string",+ },+ paymentAddressLine2: {+ format: "text",+ type: "string",+ },+ paymentCity: {+ format: "text",+ type: "string",+ },+ paymentState: {+ format: "text",+ type: "string",+ },+ paymentPostalCode: {+ format: "text",+ type: "string",+ },+ paymentCountryCode: {+ description:+ "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",+ format: "integer",+ type: "integer",+ },+ },+ type: "object",+ },oauthCode: {required: ["id",@@ -49373,6 +49568,13 @@ export default {in: "query",type: "string",},+ "rowFilter.salesOrderLines.methodType": {+ name: "methodType",+ required: false,+ format: 'public."methodType"',+ in: "query",+ type: "string",+ },"rowFilter.salesOrderLines.modelId": {name: "modelId",required: false,@@ -49422,6 +49624,20 @@ export default {in: "query",type: "string",},+ "rowFilter.salesOrderLines.customerPartId": {+ name: "customerPartId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLines.customerPartRevision": {+ name: "customerPartRevision",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"body.journalLine": {name: "journalLine",description: "journalLine",@@ -52103,6 +52319,13 @@ export default {in: "query",type: "string",},+ "rowFilter.salesOrderLine.methodType": {+ name: "methodType",+ required: false,+ format: 'public."methodType"',+ in: "query",+ type: "string",+ },"body.salesOrderTransaction": {name: "salesOrderTransaction",description: "salesOrderTransaction",@@ -62389,6 +62612,120 @@ export default {in: "query",type: "string",},+ "body.salesOrderLocations": {+ name: "salesOrderLocations",+ description: "salesOrderLocations",+ required: false,+ in: "body",+ schema: {+ $ref: "#/definitions/salesOrderLocations",+ },+ },+ "rowFilter.salesOrderLocations.id": {+ name: "id",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerName": {+ name: "customerName",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerAddressLine1": {+ name: "customerAddressLine1",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerAddressLine2": {+ name: "customerAddressLine2",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerCity": {+ name: "customerCity",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerState": {+ name: "customerState",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerPostalCode": {+ name: "customerPostalCode",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.customerCountryCode": {+ name: "customerCountryCode",+ required: false,+ format: "integer",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentCustomerName": {+ name: "paymentCustomerName",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentAddressLine1": {+ name: "paymentAddressLine1",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentAddressLine2": {+ name: "paymentAddressLine2",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentCity": {+ name: "paymentCity",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentState": {+ name: "paymentState",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentPostalCode": {+ name: "paymentPostalCode",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.salesOrderLocations.paymentCountryCode": {+ name: "paymentCountryCode",+ required: false,+ format: "integer",+ in: "query",+ type: "string",+ },"body.oauthCode": {name: "oauthCode",description: "oauthCode",diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 54d5c09675..8ae35e6a1e 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -8888,6 +8888,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "opportunity_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "opportunity_salesOrderId_fkey"columns: ["salesOrderId"]@@ -15300,6 +15307,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderFavorites_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderFavorites_salesOrderId_fkey"columns: ["salesOrderId"]@@ -15359,6 +15373,7 @@ export type Database = {itemId: string | nullitemReadableId: string | nulllocationId: string | null+ methodType: Database["public"]["Enums"]["methodType"]modelUploadId: string | nullpromisedDate: string | nullquantityInvoiced: number | null@@ -15392,6 +15407,7 @@ export type Database = {itemId?: string | nullitemReadableId?: string | nulllocationId?: string | null+ methodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | nullpromisedDate?: string | nullquantityInvoiced?: number | null@@ -15425,6 +15441,7 @@ export type Database = {itemId?: string | nullitemReadableId?: string | nulllocationId?: string | null+ methodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | nullpromisedDate?: string | nullquantityInvoiced?: number | null@@ -15515,6 +15532,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderLine_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderLine_salesOrderId_fkey"columns: ["salesOrderId"]@@ -15656,6 +15680,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderPayment_id_fkey"+ columns: ["id"]+ isOneToOne: true+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderPayment_id_fkey"columns: ["id"]@@ -15870,6 +15901,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderShipment_id_fkey"+ columns: ["id"]+ isOneToOne: true+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderShipment_id_fkey"columns: ["id"]@@ -16021,6 +16059,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderStatusHistory_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderStatusHistory_salesOrderId_fkey"columns: ["salesOrderId"]@@ -16060,6 +16105,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderTransaction_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderTransaction_salesOrderId_fkey"columns: ["salesOrderId"]@@ -23529,14 +23581,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["id"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["id"]@@ -24539,6 +24591,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "opportunity_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "opportunity_salesOrderId_fkey"columns: ["salesOrderId"]@@ -25097,6 +25156,8 @@ export type Database = {companyId: string | nullcreatedAt: string | nullcreatedBy: string | null+ customerPartId: string | null+ customerPartRevision: string | nullcustomFields: Json | nulldescription: string | nullid: string | null@@ -25104,6 +25165,7 @@ export type Database = {itemId: string | nullitemReadableId: string | nulllocationId: string | null+ methodType: Database["public"]["Enums"]["methodType"] | nullmodelId: string | nullmodelName: string | nullmodelPath: string | null@@ -25202,6 +25264,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderLine_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderLine_salesOrderId_fkey"columns: ["salesOrderId"]@@ -25260,6 +25329,41 @@ export type Database = {},]}+ salesOrderLocations: {+ Row: {+ customerAddressLine1: string | null+ customerAddressLine2: string | null+ customerCity: string | null+ customerCountryCode: number | null+ customerName: string | null+ customerPostalCode: string | null+ customerState: string | null+ id: string | null+ paymentAddressLine1: string | null+ paymentAddressLine2: string | null+ paymentCity: string | null+ paymentCountryCode: number | null+ paymentCustomerName: string | null+ paymentPostalCode: string | null+ paymentState: string | null+ }+ Relationships: [+ {+ foreignKeyName: "address_countryCode_fkey"+ columns: ["paymentCountryCode"]+ isOneToOne: false+ referencedRelation: "country"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "address_countryCode_fkey"+ columns: ["customerCountryCode"]+ isOneToOne: false+ referencedRelation: "country"+ referencedColumns: ["id"]+ },+ ]+ }salesOrders: {Row: {assignee: string | null@@ -25736,6 +25840,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "opportunity_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "opportunity_salesOrderId_fkey"columns: ["salesOrderId"]diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.tsindex ca49622b27..9a090de28f 100644--- a/packages/database/supabase/functions/convert/index.ts+++ b/packages/database/supabase/functions/convert/index.ts@@ -137,14 +137,16 @@ serve(async (req: Request) => {id: line.id,salesOrderId: insertedSalesOrderId,salesOrderLineType: line.itemType as "Part",- status: "Ordered",+ addOnCost: selectedLines![line.id!].addOn,+ description: line.description,itemId: line.itemId,itemReadableId: line.itemReadableId,- unitOfMeasureCode: line.unitOfMeasureCode,locationId: quote.data.locationId,+ methodType: line.methodType,saleQuantity: selectedLines![line.id!].quantity,+ status: "Ordered",+ unitOfMeasureCode: line.unitOfMeasureCode,unitPrice: selectedLines![line.id!].unitPrice,- addOnCost: selectedLines![line.id!].addOn,promisedDate: format(new Date(Date.now() +diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 54d5c09675..8ae35e6a1e 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -8888,6 +8888,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "opportunity_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "opportunity_salesOrderId_fkey"columns: ["salesOrderId"]@@ -15300,6 +15307,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderFavorites_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderFavorites_salesOrderId_fkey"columns: ["salesOrderId"]@@ -15359,6 +15373,7 @@ export type Database = {itemId: string | nullitemReadableId: string | nulllocationId: string | null+ methodType: Database["public"]["Enums"]["methodType"]modelUploadId: string | nullpromisedDate: string | nullquantityInvoiced: number | null@@ -15392,6 +15407,7 @@ export type Database = {itemId?: string | nullitemReadableId?: string | nulllocationId?: string | null+ methodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | nullpromisedDate?: string | nullquantityInvoiced?: number | null@@ -15425,6 +15441,7 @@ export type Database = {itemId?: string | nullitemReadableId?: string | nulllocationId?: string | null+ methodType?: Database["public"]["Enums"]["methodType"]modelUploadId?: string | nullpromisedDate?: string | nullquantityInvoiced?: number | null@@ -15515,6 +15532,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderLine_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderLine_salesOrderId_fkey"columns: ["salesOrderId"]@@ -15656,6 +15680,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderPayment_id_fkey"+ columns: ["id"]+ isOneToOne: true+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderPayment_id_fkey"columns: ["id"]@@ -15870,6 +15901,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderShipment_id_fkey"+ columns: ["id"]+ isOneToOne: true+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderShipment_id_fkey"columns: ["id"]@@ -16021,6 +16059,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderStatusHistory_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderStatusHistory_salesOrderId_fkey"columns: ["salesOrderId"]@@ -16060,6 +16105,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderTransaction_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderTransaction_salesOrderId_fkey"columns: ["salesOrderId"]@@ -23529,14 +23581,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["id"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["id"]@@ -24539,6 +24591,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "opportunity_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "opportunity_salesOrderId_fkey"columns: ["salesOrderId"]@@ -25097,6 +25156,8 @@ export type Database = {companyId: string | nullcreatedAt: string | nullcreatedBy: string | null+ customerPartId: string | null+ customerPartRevision: string | nullcustomFields: Json | nulldescription: string | nullid: string | null@@ -25104,6 +25165,7 @@ export type Database = {itemId: string | nullitemReadableId: string | nulllocationId: string | null+ methodType: Database["public"]["Enums"]["methodType"] | nullmodelId: string | nullmodelName: string | nullmodelPath: string | null@@ -25202,6 +25264,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "salesOrderLine_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "salesOrderLine_salesOrderId_fkey"columns: ["salesOrderId"]@@ -25260,6 +25329,41 @@ export type Database = {},]}+ salesOrderLocations: {+ Row: {+ customerAddressLine1: string | null+ customerAddressLine2: string | null+ customerCity: string | null+ customerCountryCode: number | null+ customerName: string | null+ customerPostalCode: string | null+ customerState: string | null+ id: string | null+ paymentAddressLine1: string | null+ paymentAddressLine2: string | null+ paymentCity: string | null+ paymentCountryCode: number | null+ paymentCustomerName: string | null+ paymentPostalCode: string | null+ paymentState: string | null+ }+ Relationships: [+ {+ foreignKeyName: "address_countryCode_fkey"+ columns: ["paymentCountryCode"]+ isOneToOne: false+ referencedRelation: "country"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "address_countryCode_fkey"+ columns: ["customerCountryCode"]+ isOneToOne: false+ referencedRelation: "country"+ referencedColumns: ["id"]+ },+ ]+ }salesOrders: {Row: {assignee: string | null@@ -25736,6 +25840,13 @@ export type Database = {referencedRelation: "salesOrder"referencedColumns: ["id"]},+ {+ foreignKeyName: "opportunity_salesOrderId_fkey"+ columns: ["salesOrderId"]+ isOneToOne: false+ referencedRelation: "salesOrderLocations"+ referencedColumns: ["id"]+ },{foreignKeyName: "opportunity_salesOrderId_fkey"columns: ["salesOrderId"]diff --git a/packages/database/supabase/migrations/20240904094118_sales-order-document.sql b/packages/database/supabase/migrations/20240904094118_sales-order-document.sqlnew file mode 100644index 0000000000..66a936b86c--- /dev/null+++ b/packages/database/supabase/migrations/20240904094118_sales-order-document.sql@@ -0,0 +1,59 @@+ALTER TABLE "salesOrderLine"+ ADD COLUMN "methodType" "methodType" NOT NULL DEFAULT 'Make';++CREATE OR REPLACE VIEW "salesOrderLocations" WITH(SECURITY_INVOKER=true) AS+ SELECT+ so.id,+ c.name AS "customerName",+ ca."addressLine1" AS "customerAddressLine1",+ ca."addressLine2" AS "customerAddressLine2",+ ca."city" AS "customerCity",+ ca."state" AS "customerState",+ ca."postalCode" AS "customerPostalCode",+ ca."countryCode" AS "customerCountryCode",+ pc.name AS "paymentCustomerName",+ pa."addressLine1" AS "paymentAddressLine1",+ pa."addressLine2" AS "paymentAddressLine2",+ pa."city" AS "paymentCity",+ pa."state" AS "paymentState",+ pa."postalCode" AS "paymentPostalCode",+ pa."countryCode" AS "paymentCountryCode"+ FROM "salesOrder" so+ INNER JOIN "customer" c+ ON c.id = so."customerId"+ LEFT OUTER JOIN "customerLocation" cl+ ON cl.id = so."customerLocationId"+ LEFT OUTER JOIN "address" ca+ ON ca.id = cl."addressId"+ LEFT OUTER JOIN "salesOrderPayment" sop+ ON sop.id = so.id+ LEFT OUTER JOIN "customer" pc+ ON pc.id = sop."invoiceCustomerId"+ LEFT OUTER JOIN "customerLocation" pl+ ON pl.id = sop."invoiceCustomerLocationId"+ LEFT OUTER JOIN "address" pa+ ON pa.id = pl."addressId";++DROP VIEW "salesOrderLines";+CREATE OR REPLACE VIEW "salesOrderLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT+ sl.*,+ COALESCE(mu.id, imu.id) as "modelId",+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",+ COALESCE(mu."thumbnailPath", imu."thumbnailPath") as "thumbnailPath",+ COALESCE(mu."name", imu."name") as "modelName",+ COALESCE(mu."size", imu."size") as "modelSize",+ ic."unitCost" as "unitCost",+ cp."customerPartId",+ cp."customerPartRevision"+ FROM "salesOrderLine" sl+ INNER JOIN "salesOrder" so ON so.id = sl."salesOrderId"+ LEFT JOIN "modelUpload" mu ON sl."modelUploadId" = mu."id"+ INNER JOIN "item" i ON i.id = sl."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+ LEFT JOIN "customerPartToItem" cp ON cp."customerId" = so."customerId" AND cp."itemId" = i.id+);++diff --git a/packages/documents/package.json b/packages/documents/package.jsonindex 82b958f9d4..e537b5cfed 100644--- a/packages/documents/package.json+++ b/packages/documents/package.json@@ -5,7 +5,8 @@"@react-email/components": "0.0.16","@react-pdf/renderer": "^3.1.14","react-icons": "^5.2.1",- "react-hook-form": "7.51.2"+ "react-hook-form": "7.51.2",+ "react-pdf-tailwind": "~2.3.0"},"devDependencies": {"@carbon/database": "*",diff --git a/packages/documents/src/email/PurchaseOrderEmail.tsx b/packages/documents/src/email/PurchaseOrderEmail.tsxindex dd3d90f181..9c57e8e31a 100644--- a/packages/documents/src/email/PurchaseOrderEmail.tsx+++ b/packages/documents/src/email/PurchaseOrderEmail.tsx@@ -11,6 +11,7 @@ import {Preview,Row,Section,+ Tailwind,Text,} from "@react-email/components";import type { Email } from "../types";@@ -56,350 +57,206 @@ const PurchaseOrderEmail = ({const reSubject = `Re: ${purchaseOrder.purchaseOrderId} from ${company.name}`;return (- <Html lang="en">+ <Html><Head /><Preview>{`${purchaseOrder.purchaseOrderId} from ${company.name}`}</Preview>-- <Body style={main}>- <Container style={container}>- <Section>- <Row>- <Column>- {company.logo ? (- <Img- src={company.logo}- width="auto"- height="42"- alt={`${company.name} Logo`}- />- ) : (- <Text style={logoText}>{company.name}</Text>- )}- </Column>-- <Column align="right" style={tableCell}>- <Text style={heading}>Purchase Order</Text>- </Column>- </Row>- </Section>- <Section>- <Text style={subtleText}>- Hi {recipient.firstName}, please see the attached purchase order- and let me know if you have any questions.- </Text>- </Section>- <Section style={informationTable}>- <Row style={informationTableRow}>- <Column colSpan={2}>- <Section>- <Row>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Buyer</Text>- <Link- style={{- ...informationTableValue,- color: "#15c",- textDecoration: "underline",- }}- href={`mailto:${sender.email}?subject=${reSubject}`}- >- {`${sender.firstName} ${sender.lastName}`}- </Link>- </Column>- </Row>-- <Row>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Payment Terms</Text>- <Text style={informationTableValue}>- {purchaseOrder.paymentTermName ?? "-"}- </Text>- </Column>- </Row>-- <Row>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Order ID</Text>- <Text style={informationTableValue}>- {purchaseOrder.purchaseOrderId}- </Text>- </Column>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Requested Date</Text>- <Text style={informationTableValue}>- {purchaseOrder.receiptRequestedDate ?? "-"}- </Text>- </Column>- </Row>- </Section>- </Column>- <Column style={informationTableColumn} colSpan={2}>- <Text style={informationTableLabel}>Ship To</Text>- {dropShipment ? (- <>- <Text style={informationTableValue}>{customerName}</Text>- {customerAddressLine1 && (- <Text style={informationTableValue}>- {customerAddressLine1}- </Text>- )}- {customerAddressLine2 && (- <Text style={informationTableValue}>- {customerAddressLine2}- </Text>- )}- <Text style={informationTableValue}>- {formatAddress(- customerCity,- customerState,- customerPostalCode- )}+ <Tailwind>+ <Body className="bg-white font-sans">+ <Container className="mx-auto py-5 px-0 w-[660px] max-w-full">+ <Section>+ <Row>+ <Column>+ {company.logo ? (+ <Img+ src={company.logo}+ width="auto"+ height="42"+ alt={`${company.name} Logo`}+ />+ ) : (+ <Text className="text-3xl font-bold text-gray-900">+ {company.name}</Text>- <Text style={informationTableValue}>- {customerCountryCode}- </Text>- </>- ) : (- <>- <Text style={informationTableValue}>{company.name}</Text>- <Text style={informationTableValue}>{deliveryName}</Text>- {deliveryAddressLine1 && (- <Text style={informationTableValue}>- {deliveryAddressLine1}- </Text>- )}- {deliveryAddressLine2 && (- <Text style={informationTableValue}>- {deliveryAddressLine2}+ )}+ </Column>+ <Column className="text-right">+ <Text className="text-3xl font-light text-gray-500">+ Purchase Order+ </Text>+ </Column>+ </Row>+ </Section>+ <Section>+ <Text className="text-left text-sm font-medium text-gray-900 my-9">+ Hi {recipient.firstName}, please see the attached purchase order+ and let me know if you have any questions.+ </Text>+ </Section>+ <Section className="bg-gray-50 rounded-lg text-xs">+ <Row>+ <Column className="p-5" colSpan={2}>+ <Section>+ <Row>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Buyer+ </Text>+ <Link+ href={`mailto:${sender.email}?subject=${reSubject}`}+ className="text-blue-600 underline"+ >+ {`${sender.firstName} ${sender.lastName}`}+ </Link>+ </Column>+ </Row>+ <Row>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Payment Terms+ </Text>+ <Text>{purchaseOrder.paymentTermName ?? "-"}</Text>+ </Column>+ </Row>+ <Row>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Order ID+ </Text>+ <Text>{purchaseOrder.purchaseOrderId}</Text>+ </Column>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Requested Date+ </Text>+ <Text>{purchaseOrder.receiptRequestedDate ?? "-"}</Text>+ </Column>+ </Row>+ </Section>+ </Column>+ <Column className="p-5" colSpan={2}>+ <Text className="text-gray-600 uppercase text-[10px]">+ Ship To+ </Text>+ {dropShipment ? (+ <>+ <Text>{customerName}</Text>+ {customerAddressLine1 && (+ <Text>{customerAddressLine1}</Text>+ )}+ {customerAddressLine2 && (+ <Text>{customerAddressLine2}</Text>+ )}+ <Text>+ {formatAddress(+ customerCity,+ customerState,+ customerPostalCode+ )}</Text>- )}- <Text style={informationTableValue}>- {formatAddress(- deliveryCity,- deliveryState,- deliveryPostalCode+ <Text>{customerCountryCode}</Text>+ </>+ ) : (+ <>+ <Text>{company.name}</Text>+ <Text>{deliveryName}</Text>+ {deliveryAddressLine1 && (+ <Text>{deliveryAddressLine1}</Text>)}- </Text>- <Text>{deliveryCountryCode}</Text>- </>- )}- </Column>- </Row>- </Section>- <Section style={linesHeader}>- <Text style={{ ...informationTableLabel, paddingLeft: "20px" }}>- Purchase Order Lines- </Text>- </Section>- <Section>- {purchaseOrderLines.map((line) => (- <Row key={line.id} style={lineRow}>- <Column- style={{- paddingLeft: "5px",- }}- >- <Text style={lineTitle}>{getLineDescription(line)}</Text>- {getLineDescriptionDetails(line)- ?.split("\n")- .map((l, i) => (- <Text key={i} style={lineDescription}>- {l}+ {deliveryAddressLine2 && (+ <Text>{deliveryAddressLine2}</Text>+ )}+ <Text>+ {formatAddress(+ deliveryCity,+ deliveryState,+ deliveryPostalCode+ )}</Text>- ))}+ <Text>{deliveryCountryCode}</Text>+ </>+ )}</Column>- <Column style={lineValueWrapper} align="right">- <Text style={lineValue}>- {line.purchaseOrderLineType === "Comment"- ? ""- : `(${line.purchaseQuantity} ${line.purchaseUnitOfMeasureCode})`}+ </Row>+ </Section>+ <Section className="mt-8 mb-4">+ <Text className="text-gray-600 uppercase text-[10px] pl-5">+ Purchase Order Lines+ </Text>+ </Section>+ <Section>+ {purchaseOrderLines.map((line) => (+ <Row key={line.id} className="mb-2.5 pl-5">+ <Column>+ <Text className="text-xs font-semibold">+ {getLineDescription(line)}+ </Text>+ {getLineDescriptionDetails(line)+ ?.split("\n")+ .map((l, i) => (+ <Text key={i} className="text-xs text-gray-600">+ {l}+ </Text>+ ))}+ </Column>+ <Column className="text-right pr-5 align-top w-[100px]">+ <Text className="text-xs font-semibold">+ {line.purchaseOrderLineType === "Comment"+ ? ""+ : `(${line.purchaseQuantity} ${line.purchaseUnitOfMeasureCode})`}+ </Text>+ </Column>+ <Column className="text-right pr-5 align-top w-[100px]">+ <Text className="text-xs font-semibold">+ {line.purchaseOrderLineType === "Comment"+ ? "-"+ : line.unitPrice+ ? `$${line.unitPrice.toFixed(2)}`+ : "-"}+ </Text>+ </Column>+ </Row>+ ))}+ </Section>+ <Hr className="my-8" />+ <Section className="text-right">+ <Row>+ <Column className="pr-8">+ <Text className="text-[10px] font-semibold text-gray-600">+ TOTAL</Text></Column>- <Column style={lineValueWrapper} align="right">- <Text style={lineValue}>- {line.purchaseOrderLineType === "Comment"- ? "-"- : line.unitPrice- ? `$${line.unitPrice.toFixed(2)}`- : "-"}+ <Column className="border-l border-gray-200 h-12"></Column>+ <Column className="w-[90px] pr-5">+ <Text className="text-base font-semibold whitespace-nowrap">+ {`$${getTotal(purchaseOrderLines)}`}</Text></Column></Row>- ))}- </Section>- <Hr style={priceLine} />- <Section align="right">- <Row>- <Column style={tableCell} align="right">- <Text style={priceTotal}>TOTAL</Text>- </Column>- <Column style={priceVerticalLine}></Column>- <Column style={priceLargeWrapper}>- <Text style={priceLarge}>- {`$${getTotal(purchaseOrderLines)}`}- </Text>- </Column>- </Row>- </Section>- <Hr style={priceLineBottom} />- <Section>- <Row>- <Column align="center" style={block}>- {company.logo ? (- <Img- src={company.logo}- width="60"- height="auto"- alt={`${company.name} Logo`}- />- ) : (- <Text style={logoText}>{company.name}</Text>- )}- </Column>- </Row>- </Section>- </Container>- </Body>+ </Section>+ <Hr className="mb-20" />+ <Section>+ <Row>+ <Column className="text-center">+ {company.logo ? (+ <Img+ src={company.logo}+ width="60"+ height="auto"+ alt={`${company.name} Logo`}+ />+ ) : (+ <Text className="text-3xl font-bold text-gray-900">+ {company.name}+ </Text>+ )}+ </Column>+ </Row>+ </Section>+ </Container>+ </Body>+ </Tailwind></Html>);};export default PurchaseOrderEmail;--const main = {- fontFamily: '"Helvetica Neue",Helvetica,Arial,sans-serif',- backgroundColor: "#ffffff",-};--const resetText = {- margin: "0",- padding: "0",- lineHeight: 1.4,-};--const container = {- margin: "0 auto",- padding: "20px 0 48px",- width: "660px",- maxWidth: "100%",-};--const tableCell = { display: "table-cell" };--const logoText = {- fontSize: "32px",- fontWeight: "700",- color: "#111111",-};--const heading = {- fontSize: "32px",- fontWeight: "300",- color: "#888888",-};--const subtleText = {- textAlign: "left" as const,- margin: "36px 0 40px 0",- fontSize: "14px",- fontWeight: "500",- color: "#111111",-};--const informationTable = {- borderCollapse: "collapse" as const,- borderSpacing: "0px",- color: "rgb(51,51,51)",- backgroundColor: "rgb(250,250,250)",- borderRadius: "6px",- fontSize: "12px",-};--const informationTableRow = {- height: "46px",-};--const informationTableColumn = {- paddingLeft: "20px",- borderStyle: "solid",- borderColor: "white",- borderWidth: "0px 1px 1px 0px",- height: "44px",-};--const informationTableLabel = {- ...resetText,- color: "rgb(102,102,102)",- fontSize: "10px",- textTransform: "uppercase" as const,-};--const informationTableValue = {- fontSize: "12px",- margin: "0",- padding: "0",- lineHeight: 1.4,-};--const linesHeader = {- ...informationTable,- margin: "30px 0 15px 0",- height: "24px",-};--const lineTitle = { fontSize: "12px", fontWeight: "600", ...resetText };--const lineDescription = {- fontSize: "12px",- color: "rgb(102,102,102)",- ...resetText,-};--const lineRow = {- marginBottom: "10px",- paddingLeft: "20px",-};--const priceTotal = {- margin: "0",- color: "rgb(102,102,102)",- fontSize: "10px",- fontWeight: "600",- padding: "0px 30px 0px 0px",- textAlign: "right" as const,-};--const lineValue = {- fontSize: "12px",- fontWeight: "600",- margin: "0",-};--const priceLarge = {- margin: "0px 20px 0px 0px",- fontSize: "16px",- fontWeight: "600",- whiteSpace: "nowrap" as const,- textAlign: "right" as const,-};--const lineValueWrapper = {- display: "table-cell",- padding: "0px 20px 0px 0px",- width: "100px",- verticalAlign: "top",-};--const priceLine = { margin: "30px 0 0 0" };--const priceVerticalLine = {- height: "48px",- borderLeft: "1px solid",- borderColor: "rgb(238,238,238)",-};--const priceLargeWrapper = { display: "table-cell", width: "90px" };--const priceLineBottom = { margin: "0 0 75px 0" };--const block = { display: "block" };diff --git a/packages/documents/src/email/QuoteEmail.tsx b/packages/documents/src/email/QuoteEmail.tsxindex ac552e360e..5d95ae4046 100644--- a/packages/documents/src/email/QuoteEmail.tsx+++ b/packages/documents/src/email/QuoteEmail.tsx@@ -10,6 +10,7 @@ import {Preview,Row,Section,+ Tailwind,Text,} from "@react-email/components";import type { Email } from "../types";@@ -26,178 +27,107 @@ const QuoteEmail = ({ company, quote, recipient, sender }: QuoteEmailProps) => {<Head /><Preview>{`${quote.quoteId} from ${company.name}`}</Preview>- <Body style={main}>- <Container style={container}>- <Section>- <Row>- <Column>- {company.logo ? (- <Img- src={company.logo}- width="auto"- height="42"- alt={`${company.name} Logo`}- />- ) : (- <Text style={logoText}>{company.name}</Text>- )}- </Column>-- <Column align="right" style={tableCell}>- <Text style={heading}>Quote</Text>- </Column>- </Row>- </Section>- <Section>- <Text style={subtleText}>- Hi {recipient.firstName}, please see the attached quote.- </Text>- </Section>- <Section style={informationTable}>- <Row style={informationTableRow}>- <Column colSpan={2}>- <Section>- <Row>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Quoter</Text>- <Link- style={{- ...informationTableValue,- color: "#15c",- textDecoration: "underline",- }}- href={`mailto:${sender.email}?subject=${reSubject}`}- >- {`${sender.firstName} ${sender.lastName}`}- </Link>- </Column>- </Row>-- <Row>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>- Reference Number- </Text>- <Text style={informationTableValue}>- {quote.customerReference ?? "-"}- </Text>- </Column>- </Row>-- <Row>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Quote ID</Text>- <Text style={informationTableValue}>{quote.quoteId}</Text>- </Column>- <Column style={informationTableColumn}>- <Text style={informationTableLabel}>Expiration Date</Text>- <Text style={informationTableValue}>- {quote.expirationDate ?? "-"}- </Text>- </Column>- </Row>- </Section>- </Column>- </Row>- </Section>-- <Section>- <Row>- <Column align="center" style={block}>- {company.logo ? (- <Img- src={company.logo}- width="60"- height="auto"- alt={`${company.name} Logo`}- />- ) : (- <Text style={logoText}>{company.name}</Text>- )}- </Column>- </Row>- </Section>- </Container>- </Body>+ <Tailwind>+ <Body className="bg-white font-sans">+ <Container className="mx-auto my-[20px] w-[660px] max-w-full">+ <Section>+ <Row>+ <Column>+ {company.logo ? (+ <Img+ src={company.logo}+ width="auto"+ height="42"+ alt={`${company.name} Logo`}+ />+ ) : (+ <Text className="text-[32px] font-bold text-gray-900">+ {company.name}+ </Text>+ )}+ </Column>++ <Column className="text-right">+ <Text className="text-[32px] font-light text-gray-500">+ Quote+ </Text>+ </Column>+ </Row>+ </Section>+ <Section>+ <Text className="mt-9 mb-10 text-left text-sm font-medium text-gray-900">+ Hi {recipient.firstName}, please see the attached quote.+ </Text>+ </Section>+ <Section className="rounded-lg bg-gray-50 text-xs">+ <Row>+ <Column className="p-5" colSpan={2}>+ <Section>+ <Row>+ <Column>+ <Text className="text-[10px] uppercase text-gray-600">+ Quoter+ </Text>+ <Link+ className="text-blue-600 underline"+ href={`mailto:${sender.email}?subject=${reSubject}`}+ >+ {`${sender.firstName} ${sender.lastName}`}+ </Link>+ </Column>+ </Row>++ <Row>+ <Column>+ <Text className="text-[10px] uppercase text-gray-600">+ Reference Number+ </Text>+ <Text>{quote.customerReference ?? "-"}</Text>+ </Column>+ </Row>++ <Row>+ <Column>+ <Text className="text-[10px] uppercase text-gray-600">+ Quote ID+ </Text>+ <Text>{quote.quoteId}</Text>+ </Column>+ <Column>+ <Text className="text-[10px] uppercase text-gray-600">+ Expiration Date+ </Text>+ <Text>{quote.expirationDate ?? "-"}</Text>+ </Column>+ </Row>+ </Section>+ </Column>+ </Row>+ </Section>++ <Section>+ <Row>+ <Column className="text-center">+ {company.logo ? (+ <Img+ src={company.logo}+ width="60"+ height="auto"+ alt={`${company.name} Logo`}+ />+ ) : (+ <Text className="text-[32px] font-bold text-gray-900">+ {company.name}+ </Text>+ )}+ </Column>+ </Row>+ </Section>+ </Container>+ </Body>+ </Tailwind></Html>);};export default QuoteEmail;--const main = {- fontFamily: '"Helvetica Neue",Helvetica,Arial,sans-serif',- backgroundColor: "#ffffff",-};--const resetText = {- margin: "0",- padding: "0",- lineHeight: 1.4,-};--const container = {- margin: "0 auto",- padding: "20px 0 48px",- width: "660px",- maxWidth: "100%",-};--const tableCell = { display: "table-cell" };--const logoText = {- fontSize: "32px",- fontWeight: "700",- color: "#111111",-};--const heading = {- fontSize: "32px",- fontWeight: "300",- color: "#888888",-};--const subtleText = {- textAlign: "left" as const,- margin: "36px 0 40px 0",- fontSize: "14px",- fontWeight: "500",- color: "#111111",-};--const informationTable = {- borderCollapse: "collapse" as const,- borderSpacing: "0px",- color: "rgb(51,51,51)",- backgroundColor: "rgb(250,250,250)",- borderRadius: "6px",- fontSize: "12px",-};--const informationTableRow = {- height: "46px",-};--const informationTableColumn = {- paddingLeft: "20px",- borderStyle: "solid",- borderColor: "white",- borderWidth: "0px 1px 1px 0px",- height: "44px",-};--const informationTableLabel = {- ...resetText,- color: "rgb(102,102,102)",- fontSize: "10px",- textTransform: "uppercase" as const,-};--const informationTableValue = {- fontSize: "12px",- margin: "0",- padding: "0",- lineHeight: 1.4,-};--const block = { display: "block" };diff --git a/packages/documents/src/email/SalesOrderEmail.tsx b/packages/documents/src/email/SalesOrderEmail.tsxnew file mode 100644index 0000000000..74db0fd779--- /dev/null+++ b/packages/documents/src/email/SalesOrderEmail.tsx@@ -0,0 +1,245 @@+import type { Database } from "@carbon/database";+import {+ Body,+ Column,+ Container,+ Head,+ Hr,+ Html,+ Img,+ Link,+ Preview,+ Row,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";+import type { Email } from "../types";+import {+ getLineDescription,+ getLineDescriptionDetails,+ getLineTotal,+ getTotal,+} from "../utils/sales-order";+import { formatAddress } from "../utils/shared";++interface SalesOrderEmailProps extends Email {+ salesOrder: Database["public"]["Views"]["salesOrders"]["Row"];+ salesOrderLines: Database["public"]["Views"]["salesOrderLines"]["Row"][];+ salesOrderLocations: Database["public"]["Views"]["salesOrderLocations"]["Row"];+}++const formatter = new Intl.NumberFormat("en-US", {+ style: "currency",+ currency: "USD",+});++const SalesOrderEmail = ({+ company,+ salesOrder,+ salesOrderLines,+ salesOrderLocations,+ recipient,+ sender,+}: SalesOrderEmailProps) => {+ const {+ customerName,+ customerAddressLine1,+ customerAddressLine2,+ customerCity,+ customerState,+ customerPostalCode,+ customerCountryCode,+ // paymentCustomerName,+ // paymentAddressLine1,+ // paymentAddressLine2,+ // paymentCity,+ // paymentState,+ // paymentPostalCode,+ // paymentCountryCode,+ } = salesOrderLocations;++ const reSubject = `Re: ${salesOrder.salesOrderId} from ${company.name}`;++ return (+ <Html>+ <Head />+ <Preview>{`${salesOrder.salesOrderId} from ${company.name}`}</Preview>+ <Tailwind>+ <Body className="bg-white font-sans">+ <Container className="mx-auto py-5 px-0 w-[660px] max-w-full">+ <Section>+ <Row>+ <Column>+ {company.logo ? (+ <Img+ src={company.logo}+ width="auto"+ height="42"+ alt={`${company.name} Logo`}+ />+ ) : (+ <Text className="text-3xl font-bold text-gray-900">+ {company.name}+ </Text>+ )}+ </Column>+ <Column className="text-right">+ <Text className="text-3xl font-light text-gray-500">+ Sales Order+ </Text>+ </Column>+ </Row>+ </Section>+ <Section>+ <Text className="text-left text-sm font-medium text-gray-900 my-9">+ Hi {recipient.firstName}, please see the attached sales order+ and let me know if you have any questions.+ </Text>+ </Section>+ <Section className="bg-gray-50 rounded-lg text-xs">+ <Row>+ <Column className="p-5" colSpan={2}>+ <Section>+ <Row>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Seller+ </Text>+ <Link+ href={`mailto:${sender.email}?subject=${reSubject}`}+ className="text-blue-600 underline"+ >+ {`${sender.firstName} ${sender.lastName}`}+ </Link>+ </Column>+ </Row>+ <Row>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Payment Terms+ </Text>+ <Text>{salesOrder.paymentTermName ?? "-"}</Text>+ </Column>+ </Row>+ <Row>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Order ID+ </Text>+ <Text>{salesOrder.salesOrderId}</Text>+ </Column>+ <Column>+ <Text className="text-gray-600 uppercase text-[10px]">+ Requested Date+ </Text>+ <Text>{salesOrder.receiptRequestedDate ?? "-"}</Text>+ </Column>+ </Row>+ </Section>+ </Column>+ <Column className="p-5" colSpan={2}>+ <Text className="text-gray-600 uppercase text-[10px]">+ Ship To+ </Text>+ <Text>{customerName}</Text>+ {customerAddressLine1 && <Text>{customerAddressLine1}</Text>}+ {customerAddressLine2 && <Text>{customerAddressLine2}</Text>}+ <Text>+ {formatAddress(+ customerCity,+ customerState,+ customerPostalCode+ )}+ </Text>+ <Text>{customerCountryCode}</Text>+ </Column>+ </Row>+ </Section>+ <Section className="mt-8 mb-4">+ <Text className="text-gray-600 uppercase text-[10px] pl-5">+ Sales Order Lines+ </Text>+ </Section>+ <Section>+ {salesOrderLines.map((line) => (+ <Row key={line.id} className="mb-2.5 pl-5">+ <Column>+ <Text className="text-xs font-semibold">+ {getLineDescription(line)}+ </Text>+ {getLineDescriptionDetails(line)+ ?.split("\n")+ .map((l, i) => (+ <Text key={i} className="text-xs text-gray-600">+ {l}+ </Text>+ ))}+ </Column>+ <Column className="text-right pr-5 align-top w-[100px]">+ <Text className="text-xs font-semibold">+ {line.salesOrderLineType === "Comment"+ ? ""+ : `(${line.saleQuantity} ${line.unitOfMeasureCode})`}+ </Text>+ </Column>+ <Column className="text-right pr-5 align-top w-[100px]">+ <Text className="text-xs font-semibold">+ {line.salesOrderLineType === "Comment"+ ? "-"+ : formatter.format(line.unitPrice ?? 0)}+ </Text>+ </Column>+ <Column className="text-right pr-5 align-top w-[100px]">+ <Text className="text-xs font-semibold">+ {line.salesOrderLineType === "Comment"+ ? "-"+ : formatter.format(getLineTotal(line))}+ </Text>+ </Column>+ </Row>+ ))}+ </Section>+ <Hr className="my-8" />+ <Section className="text-right">+ <Row>+ <Column className="pr-8">+ <Text className="text-[10px] font-semibold text-gray-600">+ TOTAL+ </Text>+ </Column>+ <Column className="border-l border-gray-200 h-12"></Column>+ <Column className="w-[90px] pr-5">+ <Text className="text-base font-semibold whitespace-nowrap">+ {formatter.format(getTotal(salesOrderLines))}+ </Text>+ </Column>+ </Row>+ </Section>+ <Hr className="mb-20" />+ <Section>+ <Row>+ <Column className="text-center">+ {company.logo ? (+ <Img+ src={company.logo}+ width="60"+ height="auto"+ alt={`${company.name} Logo`}+ />+ ) : (+ <Text className="text-3xl font-bold text-gray-900">+ {company.name}+ </Text>+ )}+ </Column>+ </Row>+ </Section>+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+};++export default SalesOrderEmail;diff --git a/packages/documents/src/pdf/PurchaseOrderPDF.tsx b/packages/documents/src/pdf/PurchaseOrderPDF.tsxindex 4938f0c3a9..333c0b22e6 100644--- a/packages/documents/src/pdf/PurchaseOrderPDF.tsx+++ b/packages/documents/src/pdf/PurchaseOrderPDF.tsx@@ -1,5 +1,6 @@import type { Database } from "@carbon/database";-import { StyleSheet, Text, View } from "@react-pdf/renderer";+import { Text, View } from "@react-pdf/renderer";+import { createTw } from "react-pdf-tailwind";import type { PDF } from "../types";import {@@ -23,6 +24,22 @@ const formatter = new Intl.NumberFormat("en-US", {currency: "USD",});+// Initialize tailwind-styled-components+const tw = createTw({+ theme: {+ fontFamily: {+ sans: ["Helvetica", "Arial", "sans-serif"],+ },+ extend: {+ colors: {+ gray: {+ 500: "#7d7d7d",+ },+ },+ },+ },+});+const PurchaseOrderPDF = ({company,meta,@@ -80,9 +97,9 @@ const PurchaseOrderPDF = ({},]}/>- <View style={styles.row}>- <View style={styles.colThird}>- <Text style={styles.label}>Supplier</Text>+ <View style={tw("flex flex-row justify-between mb-5")}>+ <View style={tw("flex flex-col w-1/3 text-sm gap-1")}>+ <Text style={tw("text-gray-500 text-xs")}>Supplier</Text><Text>{supplierName}</Text>{supplierAddressLine1 && <Text>{supplierAddressLine1}</Text>}{supplierAddressLine2 && <Text>{supplierAddressLine2}</Text>}@@ -92,8 +109,8 @@ const PurchaseOrderPDF = ({<Text>{supplierCountryCode}</Text></View>{dropShipment ? (- <View style={styles.colThird}>- <Text style={styles.label}>Ship To</Text>+ <View style={tw("flex flex-col text-sm gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Ship To</Text><Text>{customerName}</Text>{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}{customerAddressLine2 && <Text>{customerAddressLine2}</Text>}@@ -103,8 +120,8 @@ const PurchaseOrderPDF = ({<Text>{customerCountryCode}</Text></View>) : (- <View style={styles.colThird}>- <Text style={styles.label}>Ship To</Text>+ <View style={tw("flex flex-col text-sm gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Ship To</Text><Text>{deliveryName}</Text>{deliveryAddressLine1 && <Text>{deliveryAddressLine1}</Text>}{deliveryAddressLine2 && <Text>{deliveryAddressLine2}</Text>}@@ -115,80 +132,93 @@ const PurchaseOrderPDF = ({</View>)}</View>- <View style={styles.row}>- <View style={styles.colThird}>- <Text style={styles.label}>Supplier Order #</Text>+ <View style={tw("flex flex-row justify-between mb-5 text-sm")}>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Supplier Order #</Text><Text>{purchaseOrder?.supplierReference}</Text></View>- <View style={styles.colThird}>- <Text style={styles.label}>Requested Date</Text>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Requested Date</Text><Text>{purchaseOrder?.receiptRequestedDate}</Text></View>- <View style={styles.colThird}>- <Text style={styles.label}>Promised Date</Text>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Promised Date</Text><Text>{purchaseOrder?.receiptPromisedDate}</Text></View></View>- <View style={styles.row}>- <View style={styles.colThird}>- <Text style={styles.label}>Shipping Method</Text>+ <View style={tw("flex flex-row justify-between mb-5")}>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Shipping Method</Text><Text>{purchaseOrder?.shippingMethodName}</Text></View>- <View style={styles.colThird}>- <Text style={styles.label}>Shipping Terms</Text>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Shipping Terms</Text><Text>{purchaseOrder?.shippingTermName}</Text></View>- <View style={styles.colThird}>- <Text style={styles.label}>Payment Terms</Text>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Payment Terms</Text><Text>{purchaseOrder?.paymentTermName}</Text></View></View>- <View style={styles.table}>- <View style={styles.thead}>- <Text style={styles.tableCol1}>Description</Text>- <Text style={styles.tableCol2}>Qty</Text>- <Text style={styles.tableCol3}>Price</Text>- <Text style={styles.tableCol4}>Total</Text>+ <View style={tw("mb-5 text-xs")}>+ <View+ style={tw(+ "flex flex-row justify-between items-center py-1.5 px-[6px] border-t border-b border-gray-300 font-bold text-gray-500 uppercase"+ )}+ >+ <Text style={tw("w-1/2")}>Description</Text>+ <Text style={tw("w-1/6 text-right")}>Qty</Text>+ <Text style={tw("w-1/6 text-right")}>Price</Text>+ <Text style={tw("w-1/5 text-right")}>Total</Text></View>{purchaseOrderLines.map((line) => (- <View style={styles.tr} key={line.id}>- <View style={styles.tableCol1}>- <Text style={{ ...styles.bold, marginBottom: 4 }}>+ <View+ style={tw(+ "flex flex-row justify-between py-1.5 px-[6px] border-b border-gray-300"+ )}+ key={line.id}+ >+ <View style={tw("w-1/2")}>+ <Text style={tw("font-bold mb-1")}>{getLineDescription(line)}</Text>- <Text style={{ fontSize: 9, opacity: 0.8 }}>+ <Text style={tw("text-[9px] opacity-80")}>{getLineDescriptionDetails(line)}</Text></View>- <Text style={styles.tableCol2}>+ <Text style={tw("w-1/6 text-right")}>{line.purchaseOrderLineType === "Comment"? "": `${line.purchaseQuantity} ${line.purchaseUnitOfMeasureCode}`}</Text>- <Text style={styles.tableCol3}>+ <Text style={tw("w-1/6 text-right")}>{line.purchaseOrderLineType === "Comment"? null: formatter.format(line.unitPrice ?? 0)}</Text>- <Text style={styles.tableCol4}>+ <Text style={tw("w-1/5 text-right")}>{line.purchaseOrderLineType === "Comment"? null: formatter.format(getLineTotal(line))}</Text></View>))}- <View style={styles.tfoot}>+ <View+ style={tw(+ "flex flex-row justify-between items-center py-1.5 px-[6px] border-b border-gray-300 font-bold text-gray-500 uppercase"+ )}+ ><Text>Total</Text>- <Text style={styles.bold}>+ <Text style={tw("font-bold text-black")}>{formatter.format(getTotal(purchaseOrderLines))}</Text></View></View>{purchaseOrder?.notes && (- <View style={styles.row}>- <View style={styles.colHalf}>- <Text style={styles.label}>Notes</Text>- <Text>{purchaseOrder?.notes}</Text>+ <View style={tw("flex flex-row mb-5")}>+ <View style={tw("w-1/2")}>+ <Text style={tw("text-gray-500 text-xs")}>Notes</Text>+ <Text style={tw("text-sm")}>{purchaseOrder?.notes}</Text></View></View>)}@@ -198,104 +228,3 @@ const PurchaseOrderPDF = ({};export default PurchaseOrderPDF;--const styles = StyleSheet.create({- row: {- display: "flex",- alignItems: "flex-start",- flexDirection: "row",- justifyContent: "space-between",- marginBottom: 20,- width: "100%",- },- colFull: {- display: "flex",- flexDirection: "column",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "100%",- },- colHalf: {- display: "flex",- flexDirection: "column",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "50%",- },- colThird: {- display: "flex",- flexDirection: "column",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "32%",- },- label: {- color: "#7d7d7d",- },- bold: {- fontWeight: 700,- color: "#000000",- },- table: {- marginBottom: 20,- fontSize: 10,- },- thead: {- flexGrow: 1,- flexDirection: "row",- justifyContent: "space-between",- alignItems: "center",- marginTop: "20px",- padding: "6px 3px 6px 3px",- borderTop: 1,- borderTopColor: "#CCCCCC",- borderTopStyle: "solid",- borderBottom: 1,- borderBottomColor: "#CCCCCC",- borderBottomStyle: "solid",- fontWeight: 700,- color: "#7d7d7d",- textTransform: "uppercase",- },- tr: {- flexGrow: 1,- flexDirection: "row",- justifyContent: "space-between",- padding: "6px 3px 6px 3px",- borderBottom: 1,- borderBottomColor: "#CCCCCC",- },- tfoot: {- flexGrow: 1,- flexDirection: "row",- justifyContent: "space-between",- alignItems: "center",- padding: "6px 3px 6px 3px",- borderTopStyle: "solid",- borderBottom: 1,- borderBottomColor: "#CCCCCC",- borderBottomStyle: "solid",- fontWeight: 700,- color: "#7d7d7d",- textTransform: "uppercase",- },- tableCol1: {- width: "50%",- textAlign: "left",- },- tableCol2: {- width: "15%",- textAlign: "right",- },- tableCol3: {- width: "15%",- textAlign: "right",- },- tableCol4: {- width: "20%",- textAlign: "right",- },-});diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsxindex bd1fc9ff69..ec127a0969 100644--- a/packages/documents/src/pdf/QuotePDF.tsx+++ b/packages/documents/src/pdf/QuotePDF.tsx@@ -1,6 +1,7 @@import type { Database } from "@carbon/database";import { getLocalTimeZone, today } from "@internationalized/date";-import { Image, StyleSheet, Text, View } from "@react-pdf/renderer";+import { Image, Text, View } from "@react-pdf/renderer";+import { createTw } from "react-pdf-tailwind";import type { JSONContent } from "@carbon/react";import type { PDF } from "../types";@@ -26,6 +27,21 @@ const formatter = new Intl.NumberFormat("en-US", {currency: "USD",});+const tw = createTw({+ theme: {+ fontFamily: {+ sans: ["Helvetica", "Arial", "sans-serif"],+ },+ extend: {+ colors: {+ gray: {+ 500: "#7d7d7d",+ },+ },+ },+ },+});+const QuotePDF = ({company,meta,@@ -119,9 +135,9 @@ const QuotePDF = ({},]}/>- <View style={styles.row}>- <View style={{ ...styles.colThird, ...styles.header }}>- <Text style={styles.label}>Customer</Text>+ <View style={tw("flex flex-row mb-5")}>+ <View style={tw("flex flex-col gap-1 w-1/3 text-xs")}>+ <Text style={tw("text-gray-500 font-bold text-xs")}>Customer</Text><Text>{customerName}</Text>{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}{customerAddressLine2 && <Text>{customerAddressLine2}</Text>}@@ -132,17 +148,21 @@ const QuotePDF = ({</View></View>- <View style={styles.table}>- <View style={styles.thead}>- <View style={styles.rowForty}>+ <View style={tw("mb-5 text-xs")}>+ <View+ style={tw(+ "flex flex-row justify-between items-center py-1.5 px-[6px] border-t border-b border-gray-300 text-gray-500 font-bold uppercase"+ )}+ >+ <View style={tw("w-2/5")}><Text>Description</Text></View>- <View style={styles.rowSixty}>- <Text style={styles.cell15}>Qty</Text>- <Text style={styles.cell20}>Unit Price</Text>- <Text style={styles.cell20}>Add-Ons</Text>- <Text style={styles.cell20}>Lead Time</Text>- <Text style={styles.cell25}>Extended Price</Text>+ <View style={tw("w-3/5 flex flex-row")}>+ <Text style={tw("w-1/5 text-right")}>Qty</Text>+ <Text style={tw("w-1/5 text-right")}>Unit Price</Text>+ <Text style={tw("w-1/5 text-right")}>Add-Ons</Text>+ <Text style={tw("w-1/5 text-right")}>Lead Time</Text>+ <Text style={tw("w-1/5 text-right")}>Extended Price</Text></View></View>{quoteLines.map((line) => {@@ -161,29 +181,34 @@ const QuotePDF = ({);return (- <View style={styles.tr} key={line.id}>- <View style={styles.colForty}>- <View style={styles.col}>- <Text style={{ ...styles.bold, marginBottom: 4 }}>+ <View+ style={tw(+ "flex flex-row justify-between py-1.5 px-[6px] border-b border-gray-300"+ )}+ key={line.id}+ >+ <View style={tw("w-2/5")}>+ <View>+ <Text style={tw("font-bold mb-1")}>{getLineDescription(line)}</Text>- <Text style={{ fontSize: 9, opacity: 0.8 }}>+ <Text style={tw("text-[9px] opacity-80")}>{getLineDescriptionDetails(line)}</Text></View>{thumbnails && line.id in thumbnails && (- <View style={styles.row}>+ <View style={tw("mt-2")}><Imagesrc={thumbnails[line.id]!}- style={{ width: "100%", height: "auto" }}+ style={tw("w-full h-auto")}/></View>)}{Object.keys(additionalCharges).length > 0 && (- <View style={{ ...styles.col, marginTop: 10 }}>- <Text style={{ fontSize: 9, fontWeight: 700 }}>+ <View style={tw("mt-2.5")}>+ <Text style={tw("text-[9px] font-bold")}>Additional Charges</Text>{Object.values(additionalCharges)@@ -194,7 +219,7 @@ const QuotePDF = ({return charge.description ? (<Textkey={charge.description}- style={{ fontSize: 9, opacity: 0.8 }}+ style={tw("text-[9px] opacity-80")}>- {charge.description}</Text>@@ -203,7 +228,7 @@ const QuotePDF = ({</View>)}</View>- <View style={styles.colSixty}>+ <View style={tw("w-3/5")}>{line.quantity.map((quantity, index) => {const prices = pricesByLine[line.id] ?? [];const price = prices.find(@@ -217,21 +242,20 @@ const QuotePDF = ({additionalChargesByQuantity[index] ?? 0;return (- <View key={quantity} style={styles.row}>- <Text style={styles.cell15}>{quantity}</Text>- <Text style={styles.cell20}>+ <View key={quantity} style={tw("flex flex-row")}>+ <Text style={tw("w-1/5 text-right")}>{quantity}</Text>+ <Text style={tw("w-1/5 text-right")}>{netPrice ? formatter.format(netPrice) : "-"}</Text>- <Text style={styles.cell20}>+ <Text style={tw("w-1/5 text-right")}>{additionalCharge? formatter.format(additionalCharge): "-"}</Text>- <Text style={styles.cell20}>+ <Text style={tw("w-1/5 text-right")}>{price ? `${price.leadTime} days` : "-"}</Text>-- <Text style={styles.cell25}>+ <Text style={tw("w-1/5 text-right")}>{netPrice? formatter.format(netPrice * quantity + additionalCharge@@ -253,120 +277,3 @@ const QuotePDF = ({};export default QuotePDF;--const styles = StyleSheet.create({- header: {- fontSize: 11,- },- row: {- display: "flex",- alignItems: "flex-start",- flexDirection: "row",- justifyContent: "space-between",- marginBottom: 20,- width: "100%",- },- rowForty: {- display: "flex",- flexDirection: "row",- columnGap: 3,- width: "40%",- },- rowSixty: {- display: "flex",- flexDirection: "row",- columnGap: 3,- width: "60%",- },- colForty: {- display: "flex",- flexDirection: "column",- rowGap: 3,- width: "40%",- },- colSixty: {- display: "flex",- flexDirection: "column",- columnGap: 3,- width: "66%",- },- colThird: {- display: "flex",- flexDirection: "column",- rowGap: 3,- width: "32%",- },- label: {- color: "#7d7d7d",- fontWeight: 700,- },- bold: {- fontWeight: 700,- color: "#000000",- },- table: {- marginBottom: 20,- fontSize: 10,- },- thead: {- flexGrow: 1,- flexDirection: "row",- justifyContent: "space-between",- alignItems: "center",- marginTop: "20px",- padding: "6px 3px 6px 3px",- borderTop: 1,- borderTopColor: "#CCCCCC",- borderTopStyle: "solid",- borderBottom: 1,- borderBottomColor: "#CCCCCC",- borderBottomStyle: "solid",- fontSize: 9,- fontWeight: 700,- color: "#7d7d7d",- textTransform: "uppercase",- },-- tr: {- flexGrow: 1,- flexDirection: "row",- justifyContent: "space-between",- padding: "6px 3px 6px 3px",- borderBottom: 1,- borderBottomColor: "#CCCCCC",- fontSize: 10,- fontWeight: 400,- },- tfoot: {- flexGrow: 1,- flexDirection: "row",- justifyContent: "space-between",- alignItems: "center",- padding: "6px 3px 6px 3px",- borderTopStyle: "solid",- borderBottom: 1,- borderBottomColor: "#CCCCCC",- borderBottomStyle: "solid",- fontWeight: 700,- color: "#7d7d7d",- textTransform: "uppercase",- },- col: {- display: "flex",- flexDirection: "column",- width: "100%",- rowGap: 3,- },- cell15: {- width: "15%",- textAlign: "right",- },- cell20: {- width: "20%",- textAlign: "right",- },- cell25: {- width: "25%",- textAlign: "right",- },-});diff --git a/packages/documents/src/pdf/SalesOrderPDF.tsx b/packages/documents/src/pdf/SalesOrderPDF.tsxnew file mode 100644index 0000000000..f50d125e77--- /dev/null+++ b/packages/documents/src/pdf/SalesOrderPDF.tsx@@ -0,0 +1,219 @@+import type { Database } from "@carbon/database";+import { Text, View } from "@react-pdf/renderer";+import { createTw } from "react-pdf-tailwind";++import type { PDF } from "../types";+import {+ getLineDescription,+ getLineDescriptionDetails,+ getLineTotal,+ getTotal,+} from "../utils/sales-order";+import { formatAddress } from "../utils/shared";+import { Header, Summary, Template } from "./components";++interface SalesOrderPDFProps extends PDF {+ salesOrder: Database["public"]["Views"]["salesOrders"]["Row"];+ salesOrderLines: Database["public"]["Views"]["salesOrderLines"]["Row"][];+ salesOrderLocations: Database["public"]["Views"]["salesOrderLocations"]["Row"];+}++// TODO: format currency based on settings+const formatter = new Intl.NumberFormat("en-US", {+ style: "currency",+ currency: "USD",+});++// Initialize tailwind-styled-components+const tw = createTw({+ theme: {+ fontFamily: {+ sans: ["Helvetica", "Arial", "sans-serif"],+ },+ extend: {+ colors: {+ gray: {+ 500: "#7d7d7d",+ },+ },+ },+ },+});++const SalesOrderPDF = ({+ company,+ meta,+ salesOrder,+ salesOrderLines,+ salesOrderLocations,+ title = "Sales Order",+}: SalesOrderPDFProps) => {+ const {+ customerName,+ customerAddressLine1,+ customerAddressLine2,+ customerCity,+ customerState,+ customerPostalCode,+ customerCountryCode,+ paymentCustomerName,+ paymentAddressLine1,+ paymentAddressLine2,+ paymentCity,+ paymentState,+ paymentPostalCode,+ paymentCountryCode,+ } = salesOrderLocations;++ return (+ <Template+ title={title}+ meta={{+ author: meta?.author ?? "CarbonOS",+ keywords: meta?.keywords ?? "sales order",+ subject: meta?.subject ?? "Sales Order",+ }}+ >+ <View>+ <Header title={title} company={company} />+ <Summary+ company={company}+ items={[+ {+ label: "Date",+ value: salesOrder?.orderDate,+ },+ {+ label: "SO #",+ value: salesOrder?.salesOrderId,+ },+ ]}+ />+ <View style={tw("flex flex-row justify-between mb-5")}>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Ship To</Text>+ <Text style={tw("text-sm")}>{customerName}</Text>+ {customerAddressLine1 && (+ <Text style={tw("text-sm")}>{customerAddressLine1}</Text>+ )}+ {customerAddressLine2 && (+ <Text style={tw("text-sm")}>{customerAddressLine2}</Text>+ )}+ <Text style={tw("text-sm")}>+ {formatAddress(customerCity, customerState, customerPostalCode)}+ </Text>+ <Text style={tw("text-sm")}>{customerCountryCode}</Text>+ </View>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Bill To</Text>+ <Text style={tw("text-sm")}>{paymentCustomerName}</Text>+ {paymentAddressLine1 && (+ <Text style={tw("text-sm")}>{paymentAddressLine1}</Text>+ )}+ {paymentAddressLine2 && (+ <Text style={tw("text-sm")}>{paymentAddressLine2}</Text>+ )}+ <Text style={tw("text-sm")}>+ {formatAddress(paymentCity, paymentState, paymentPostalCode)}+ </Text>+ <Text style={tw("text-sm")}>{paymentCountryCode}</Text>+ </View>+ </View>+ <View style={tw("flex flex-row justify-between mb-5")}>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Customer Order #</Text>+ <Text style={tw("text-sm")}>{salesOrder?.customerReference}</Text>+ </View>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Requested Date</Text>+ <Text style={tw("text-sm")}>+ {salesOrder?.receiptRequestedDate}+ </Text>+ </View>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Promised Date</Text>+ <Text style={tw("text-sm")}>{salesOrder?.receiptPromisedDate}</Text>+ </View>+ </View>+ <View style={tw("flex flex-row justify-between mb-5")}>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Shipping Method</Text>+ <Text style={tw("text-sm")}>{salesOrder?.shippingMethodName}</Text>+ </View>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Shipping Terms</Text>+ <Text style={tw("text-sm")}>{salesOrder?.shippingTermName}</Text>+ </View>+ <View style={tw("flex flex-col gap-1 w-1/3")}>+ <Text style={tw("text-gray-500 text-xs")}>Payment Terms</Text>+ <Text style={tw("text-sm")}>{salesOrder?.paymentTermName}</Text>+ </View>+ </View>+ <View style={tw("mb-5 text-xs")}>+ <View+ style={tw(+ "flex flex-row justify-between items-center mt-5 py-1.5 px-[6px] border-t border-b border-gray-300 font-bold text-gray-500 uppercase"+ )}+ >+ <Text style={tw("w-1/2 text-left")}>Description</Text>+ <Text style={tw("w-1/6 text-right")}>Qty</Text>+ <Text style={tw("w-1/6 text-right")}>Price</Text>+ <Text style={tw("w-1/5 text-right")}>Total</Text>+ </View>+ {salesOrderLines.map((line) => (+ <View+ style={tw(+ "flex flex-row justify-between py-1.5 px-[6px] border-b border-gray-300"+ )}+ key={line.id}+ >+ <View style={tw("w-1/2")}>+ <Text style={tw("font-bold mb-1")}>+ {getLineDescription(line)}+ </Text>+ <Text style={tw("text-[9px] opacity-80")}>+ {getLineDescriptionDetails(line)}+ </Text>+ </View>+ <Text style={tw("w-1/6 text-right")}>+ {line.salesOrderLineType === "Comment"+ ? ""+ : `${line.saleQuantity} ${line.unitOfMeasureCode}`}+ </Text>+ <Text style={tw("w-1/6 text-right")}>+ {line.salesOrderLineType === "Comment"+ ? null+ : formatter.format(line.unitPrice ?? 0)}+ </Text>+ <Text style={tw("w-1/5 text-right")}>+ {line.salesOrderLineType === "Comment"+ ? null+ : formatter.format(getLineTotal(line))}+ </Text>+ </View>+ ))}+ <View+ style={tw(+ "flex flex-row justify-between items-center py-1.5 px-[6px] border-b border-gray-300 font-bold text-gray-500 uppercase"+ )}+ >+ <Text>Total</Text>+ <Text style={tw("font-bold text-black")}>+ {formatter.format(getTotal(salesOrderLines))}+ </Text>+ </View>+ </View>+ {salesOrder?.notes && (+ <View style={tw("flex flex-row mb-5")}>+ <View style={tw("w-1/2")}>+ <Text style={tw("text-gray-500 text-xs")}>Notes</Text>+ <Text style={tw("text-sm")}>{salesOrder?.notes}</Text>+ </View>+ </View>+ )}+ </View>+ </Template>+ );+};++export default SalesOrderPDF;diff --git a/packages/documents/src/pdf/components/QuoteHeader.tsx b/packages/documents/src/pdf/components/QuoteHeader.tsxdeleted file mode 100644index d8a6eb694f..0000000000--- a/packages/documents/src/pdf/components/QuoteHeader.tsx+++ /dev/null@@ -1,48 +0,0 @@-import { Image, StyleSheet, Text, View } from "@react-pdf/renderer";-import type { Company } from "../../types";--type HeaderProps = {- company: Company;- quoteNumber?: string | null;- title: string;-};--const styles = StyleSheet.create({- header: {- fontSize: 11,- display: "flex",- flexDirection: "row-reverse",- justifyContent: "space-between",- alignItems: "flex-start",- marginBottom: 20,- height: 70,- },- logo: {- height: 70,- },- title: {- fontSize: 18,- letterSpacing: -1,- fontWeight: 500,- },-});--const QuoteHeader = ({ title, quoteNumber, company }: HeaderProps) => {- return (- <View style={styles.header}>- <View>- {company.logo && (- <View>- <Image src={company.logo} style={styles.logo} />- </View>- )}- </View>- <View>- <Text style={styles.title}>{title}</Text>- <Text>{quoteNumber}</Text>- </View>- </View>- );-};--export default QuoteHeader;diff --git a/packages/documents/src/pdf/components/QuoteSummary.tsx b/packages/documents/src/pdf/components/QuoteSummary.tsxdeleted file mode 100644index b3a5424b67..0000000000--- a/packages/documents/src/pdf/components/QuoteSummary.tsx+++ /dev/null@@ -1,110 +0,0 @@-import { StyleSheet, Text, View } from "@react-pdf/renderer";-import type { Company, QuoteCustomerDetails } from "../../types";--type SummaryProps = {- company: Company;- quoteCustomerDetails: QuoteCustomerDetails;- items: {- label: string;- value?: string | null;- }[];-};--const styles = StyleSheet.create({- summary: {- display: "flex",- flexDirection: "row",- justifyContent: "space-between",- alignItems: "flex-start",- marginBottom: 20,- },- companyDetails: {- display: "flex",- flexDirection: "column",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "68%",- },- companyName: {- fontSize: 13,- letterSpacing: -0.5,- color: "#000000",- fontWeight: 700,- },- documentSummary: {- display: "flex",- flexDirection: "column",- justifyContent: "flex-end",- rowGap: 3,- fontSize: 11,- fontWeight: 500,- width: "32%",- },- documentSummaryItem: {- display: "flex",- flexDirection: "row",- justifyContent: "flex-end",- alignItems: "flex-end",- marginBottom: 5,- },- documentSummaryLabel: {- color: "#7d7d7d",- // fontWeight: 700,- width: "30%",- },- documentSummaryValue: {- fontWeight: 500,- },-});--const QuoteSummary = ({- company,- quoteCustomerDetails,- items,-}: SummaryProps) => {- return (- <View style={styles.summary}>- <View style={styles.companyDetails}>- <Text style={styles.documentSummaryLabel}>From</Text>- <Text style={styles.companyName}>{company.name}</Text>- {company.addressLine1 && <Text>{company.addressLine1}</Text>}- {company.addressLine2 && <Text>{company.addressLine2}</Text>}- {company.city && company.state && company.postalCode && (- <Text>{`${company.city}, ${company.state}, ${company.postalCode}`}</Text>- )}- {company.phone && <Text>{company.phone}</Text>}- {company.email && <Text>{company.email}</Text>}- </View>- <View style={styles.companyDetails}>- <Text style={styles.documentSummaryLabel}>To</Text>- <Text style={styles.companyName}>- {quoteCustomerDetails.customerName}- </Text>- {quoteCustomerDetails.customerAddressLine1 && (- <Text>{quoteCustomerDetails.customerAddressLine1}</Text>- )}- {quoteCustomerDetails.customerAddressLine2 && (- <Text>{quoteCustomerDetails.customerAddressLine2}</Text>- )}- {quoteCustomerDetails.customerCity && (- <Text>{quoteCustomerDetails.customerCity}</Text>- )}- </View>- <View style={styles.documentSummary}>- {items.map((item) => (- <View key={item.label} style={styles.documentSummaryItem}>- {item.label !== "" ? (- <Text style={styles.documentSummaryLabel}>{item.label}:</Text>- ) : null}- {item.value ? (- <Text style={styles.documentSummaryValue}>{item.value}</Text>- ) : null}- </View>- ))}- </View>- </View>- );-};--export default QuoteSummary;diff --git a/packages/documents/src/pdf/components/index.ts b/packages/documents/src/pdf/components/index.tsindex 9ff3219a93..12e3ab9123 100644--- a/packages/documents/src/pdf/components/index.ts+++ b/packages/documents/src/pdf/components/index.ts@@ -1,8 +1,6 @@import Header from "./Header";import Note from "./Note";-import QuoteHeader from "./QuoteHeader";-import QuoteSummary from "./QuoteSummary";import Summary from "./Summary";import Template from "./Template";-export { Header, Note, QuoteHeader, QuoteSummary, Summary, Template };+export { Header, Note, Summary, Template };diff --git a/packages/documents/src/pdf/index.ts b/packages/documents/src/pdf/index.tsindex 21843f7731..1d2b7b35e4 100644--- a/packages/documents/src/pdf/index.ts+++ b/packages/documents/src/pdf/index.ts@@ -1,5 +1,5 @@import PurchaseOrderPDF from "./PurchaseOrderPDF";import QuotePDF from "./QuotePDF";-// const PurchaseOrderPDF = null;+import SalesOrderPDF from "./SalesOrderPDF";-export { PurchaseOrderPDF, QuotePDF };+export { PurchaseOrderPDF, QuotePDF, SalesOrderPDF };diff --git a/packages/documents/src/utils/sales-order.ts b/packages/documents/src/utils/sales-order.tsnew file mode 100644index 0000000000..c64e2e9ebb--- /dev/null+++ b/packages/documents/src/utils/sales-order.ts@@ -0,0 +1,61 @@+import type { Database } from "@carbon/database";++export function getLineDescription(+ line: Database["public"]["Views"]["salesOrderLines"]["Row"]+) {+ switch (line?.salesOrderLineType) {+ case "Fixed Asset":+ return line?.assetId;+ case "Comment":+ return line?.description;+ default:+ let customerPartNumber = line.customerPartId+ ? ` (${line.customerPartId}${+ line.customerPartRevision ? ` Rev ${line.customerPartRevision}` : ""+ })`+ : "";++ return line?.itemReadableId + customerPartNumber;+ }+}++export function getLineDescriptionDetails(+ line: Database["public"]["Views"]["salesOrderLines"]["Row"]+) {+ switch (line?.salesOrderLineType) {+ case "Fixed Asset":+ return line?.description;+ case "Comment":+ default:+ const itemDescription = line?.customerPartId+ ? `\n${line.customerPartId}${+ line.customerPartRevision ? ` Rev ${line.customerPartRevision}` : ""+ }`+ : "";+ return (line?.description ?? "") + itemDescription;+ }+}++export function getLineTotal(+ line: Database["public"]["Views"]["salesOrderLines"]["Row"]+) {+ if (line?.saleQuantity && line?.unitPrice) {+ return line.saleQuantity * (line.unitPrice + (line.addOnCost ?? 0));+ }++ return 0;+}++export function getTotal(+ lines: Database["public"]["Views"]["salesOrderLines"]["Row"][]+) {+ let total = 0;++ lines.forEach((line) => {+ if (line?.saleQuantity && line?.unitPrice) {+ total += line.saleQuantity * (line.unitPrice + (line.addOnCost ?? 0));+ }+ });++ return total;+}diff --git a/packages/form/src/components/CreatableCombobox.tsx b/packages/form/src/components/CreatableCombobox.tsxindex 4c846998e9..e6a851c325 100644--- a/packages/form/src/components/CreatableCombobox.tsx+++ b/packages/form/src/components/CreatableCombobox.tsx@@ -27,7 +27,8 @@ const CreatableCombobox = forwardRef<HTMLButtonElement, CreatableComboboxProps>(const [value, setValue] = useControlField<string | undefined>(name);useEffect(() => {- if (props.value) setValue(props.value);+ if (props.value !== null && props.value !== undefined)+ setValue(props.value);}, [props.value, setValue]);const onChange = (value: string) => {diff --git a/packages/form/src/components/CreatableMultiSelect.tsx b/packages/form/src/components/CreatableMultiSelect.tsxindex 791f2b0af7..ba058749ca 100644--- a/packages/form/src/components/CreatableMultiSelect.tsx+++ b/packages/form/src/components/CreatableMultiSelect.tsx@@ -30,7 +30,8 @@ const CreatableMultiSelect = forwardRef<const [value, setValue] = useControlField<string[] | undefined>(name);useEffect(() => {- if (props.value) setValue(props.value);+ if (props.value !== null && props.value !== undefined)+ setValue(props.value);}, [props.value, setValue]);const onChange = (value: string[]) => {diff --git a/packages/react/src/Badge.tsx b/packages/react/src/Badge.tsxindex 99b8464a6e..698b16772f 100644--- a/packages/react/src/Badge.tsx+++ b/packages/react/src/Badge.tsx@@ -21,7 +21,8 @@ const badgeVariants = cva(destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline: "text-foreground",- green: "border-transparent bg-green-100 text-green-800",+ green:+ "border-transparent bg-green-100 text-green-800 dark:bg-green-900 dark:text-white",yellow: "border-transparent bg-yellow-100 text-yellow-800",orange: "border-transparent bg-orange-100 text-orange-800",red: "border-transparent bg-red-100 text-red-800",diff --git a/packages/react/src/Select.tsx b/packages/react/src/Select.tsxindex 27b2fe10e0..12463b4634 100644--- a/packages/react/src/Select.tsx+++ b/packages/react/src/Select.tsx@@ -118,7 +118,7 @@ const SelectContent = forwardRef<className={cn("p-1",position === "popper" &&- "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] max-h-[300px] overflow-y-auto")}>{children}