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
Add lead time to quote shipments
Sidwebworks4c636aefd076
diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.tsindex 6d404b6511..c6919a7062 100644--- a/apps/erp/app/modules/sales/sales.models.ts+++ b/apps/erp/app/modules/sales/sales.models.ts@@ -510,7 +510,8 @@ export const quoteShipmentValidator = z.object({locationId: zfd.text(z.string().optional()),shippingMethodId: zfd.text(z.string().optional()),receiptRequestedDate: zfd.text(z.string().optional()),- shippingCost: zfd.numeric(z.number().optional())+ shippingCost: zfd.numeric(z.number().optional()),+ leadTime: zfd.numeric(z.number().optional())});export const salesOrderLineType = [diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsxindex 13931301a3..8a8241a588 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx@@ -107,6 +107,16 @@ const QuoteShipmentForm = forwardRef<<ShippingMethod name="shippingMethodId" label="Shipping Method" /><DatePicker name="receiptRequestedDate" label="Requested Date" />+ <Number+ name="leadTime"+ label="Lead Time"+ formatOptions={{+ style: "unit",+ unit: "day",+ unitDisplay: "long"+ }}+ minValue={0}+ /></div></CardContent><CardFooter>diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.details.tsxindex c5bcb85cf8..d410fc71f6 100644--- a/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx+++ b/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx@@ -136,7 +136,8 @@ export default function QuoteDetailsRoute() {shippingMethodId: quoteData?.shipment?.shippingMethodId ?? "",shippingTermId: quoteData?.shipment?.shippingTermId ?? "",receiptRequestedDate: quoteData?.shipment?.receiptRequestedDate ?? "",- shippingCost: quoteData?.shipment?.shippingCost ?? 0+ shippingCost: quoteData?.shipment?.shippingCost ?? 0,+ leadTime: quoteData?.shipment?.leadTime ?? 0};const paymentInitialValues = {diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.tsindex a4b99b1648..cc3c4680b8 100644--- a/packages/database/src/swagger-docs-schema.ts+++ b/packages/database/src/swagger-docs-schema.ts@@ -2328,6 +2328,9 @@ export default {{$ref: "#/parameters/rowFilter.quoteShipment.shippingCost",},+ {+ $ref: "#/parameters/rowFilter.quoteShipment.leadTime",+ },{$ref: "#/parameters/select",},@@ -2414,6 +2417,9 @@ export default {{$ref: "#/parameters/rowFilter.quoteShipment.shippingCost",},+ {+ $ref: "#/parameters/rowFilter.quoteShipment.leadTime",+ },{$ref: "#/parameters/preferReturn",},@@ -2454,6 +2460,9 @@ export default {{$ref: "#/parameters/rowFilter.quoteShipment.shippingCost",},+ {+ $ref: "#/parameters/rowFilter.quoteShipment.leadTime",+ },{$ref: "#/parameters/body.quoteShipment",},@@ -34410,6 +34419,9 @@ export default {{$ref: "#/parameters/rowFilter.quotes.shippingCost",},+ {+ $ref: "#/parameters/rowFilter.quotes.leadTime",+ },{$ref: "#/parameters/select",},@@ -68768,6 +68780,11 @@ export default {format: "numeric",type: "number",},+ leadTime: {+ default: 0,+ format: "numeric",+ type: "number",+ },},type: "object",},@@ -83843,6 +83860,10 @@ export default {format: "numeric",type: "number",},+ leadTime: {+ format: "numeric",+ type: "number",+ },},type: "object",},@@ -98918,6 +98939,12 @@ export default {in: "query",type: "string",},+ "rowFilter.quoteShipment.leadTime": {+ name: "leadTime",+ required: false,+ in: "query",+ type: "string",+ },"body.customerLocation": {name: "customerLocation",description: "customerLocation",@@ -115975,6 +116002,12 @@ export default {in: "query",type: "string",},+ "rowFilter.quotes.leadTime": {+ name: "leadTime",+ required: false,+ in: "query",+ type: "string",+ },"body.riskRegister": {name: "riskRegister",description: "riskRegister",diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 21fd9baa0e..107a2600e6 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -29319,6 +29319,7 @@ export type Database = {Row: {companyId: stringid: string+ leadTime: number | nulllocationId: string | nullreceiptRequestedDate: string | nullshippingCost: number | null@@ -29330,6 +29331,7 @@ export type Database = {Insert: {companyId: stringid: string+ leadTime?: number | nulllocationId?: string | nullreceiptRequestedDate?: string | nullshippingCost?: number | null@@ -29341,6 +29343,7 @@ export type Database = {Update: {companyId?: stringid?: string+ leadTime?: number | nulllocationId?: string | nullreceiptRequestedDate?: string | nullshippingCost?: number | null@@ -50863,6 +50866,7 @@ export type Database = {id: string | nullinternalNotes: Json | nullitemType: Database["public"]["Enums"]["itemType"] | null+ leadTime: number | nulllines: number | nulllocationId: string | nulllocationName: string | null@@ -52358,14 +52362,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 21fd9baa0e..107a2600e6 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -29319,6 +29319,7 @@ export type Database = {Row: {companyId: stringid: string+ leadTime: number | nulllocationId: string | nullreceiptRequestedDate: string | nullshippingCost: number | null@@ -29330,6 +29331,7 @@ export type Database = {Insert: {companyId: stringid: string+ leadTime?: number | nulllocationId?: string | nullreceiptRequestedDate?: string | nullshippingCost?: number | null@@ -29341,6 +29343,7 @@ export type Database = {Update: {companyId?: stringid?: string+ leadTime?: number | nulllocationId?: string | nullreceiptRequestedDate?: string | nullshippingCost?: number | null@@ -50863,6 +50866,7 @@ export type Database = {id: string | nullinternalNotes: Json | nullitemType: Database["public"]["Enums"]["itemType"] | null+ leadTime: number | nulllines: number | nulllocationId: string | nulllocationName: string | null@@ -52358,14 +52362,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]diff --git a/packages/database/supabase/migrations/20260206061346_quote-lead-time.sql b/packages/database/supabase/migrations/20260206061346_quote-lead-time.sqlnew file mode 100644index 0000000000..02be771829--- /dev/null+++ b/packages/database/supabase/migrations/20260206061346_quote-lead-time.sql@@ -0,0 +1,33 @@+ALTER TABLE "quoteShipment" ADD COLUMN "leadTime" NUMERIC DEFAULT 0;++DROP VIEW IF EXISTS "quotes";+CREATE OR REPLACE VIEW "quotes" WITH(SECURITY_INVOKER=true) AS+ SELECT+ q.*,+ ql."thumbnailPath",+ ql."itemType",+ l."name" AS "locationName",+ ql."lines",+ ql."completedLines",+ qs."shippingCost",+ qs."leadTime"+ FROM "quote" q+ LEFT JOIN (+ SELECT+ "quoteId",+ COUNT("quoteLine"."id") FILTER (WHERE "quoteLine"."status" != 'No Quote') AS "lines",+ COUNT("quoteLine"."id") FILTER (WHERE "quoteLine"."status" = 'Complete') AS "completedLines",+ MIN(CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ ELSE i."thumbnailPath"+ END) AS "thumbnailPath",+ MIN(i."type") AS "itemType"+ FROM "quoteLine"+ INNER JOIN "item" i+ ON i."id" = "quoteLine"."itemId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"+ GROUP BY "quoteId"+ ) ql ON ql."quoteId" = q.id+ LEFT JOIN "quoteShipment" qs ON qs."id" = q."id"+ LEFT JOIN "location" l+ ON l.id = q."locationId";diff --git a/packages/documents/src/pdf/PurchaseOrderPDF.tsx b/packages/documents/src/pdf/PurchaseOrderPDF.tsxindex 868889dbfc..f6c754c4cb 100644--- a/packages/documents/src/pdf/PurchaseOrderPDF.tsx+++ b/packages/documents/src/pdf/PurchaseOrderPDF.tsx@@ -11,7 +11,7 @@ import {getTotal} from "../utils/purchase-order";import { getCurrencyFormatter } from "../utils/shared";-import { Header, Note, Summary, Template } from "./components";+import { Note, Template } from "./components";interface PurchaseOrderPDFProps extends PDF {purchaseOrder: Database["public"]["Views"]["purchaseOrders"]["Row"];@@ -21,22 +21,42 @@ interface PurchaseOrderPDFProps extends PDF {thumbnails?: Record<string, string | null>;}-// Initialize tailwind-styled-componentsconst tw = createTw({theme: {fontFamily: {- sans: ["Helvetica", "Arial", "sans-serif"]+ sans: ["Inter", "Helvetica", "Arial", "sans-serif"]},extend: {colors: {+ blue: {+ 600: "#202278"+ },gray: {- 500: "#7d7d7d"+ 50: "#f9fafb",+ 200: "#e5e7eb",+ 400: "#9ca3af",+ 600: "#4b5563",+ 800: "#1f2937"}}}}});+const formatDate = (dateStr: string | null) => {+ if (!dateStr) return null;+ try {+ const date = new Date(dateStr);+ return date.toLocaleDateString("en-US", {+ year: "numeric",+ month: "long",+ day: "numeric"+ });+ } catch {+ return dateStr;+ }+};+const PurchaseOrderPDF = ({company,locale,@@ -84,6 +104,8 @@ const PurchaseOrderPDF = ({const shippingCost = purchaseOrder?.supplierShippingCost ?? 0;+ let rowIndex = 0;+return (<Templatetitle={title}@@ -93,214 +115,304 @@ const PurchaseOrderPDF = ({subject: meta?.subject ?? "Purchase Order"}}>- <View>- <Header title={title} company={company} />- <Summary- company={company}- items={[- {- label: "Date",- value: purchaseOrder?.orderDate- },- {- label: "PO #",- value: purchaseOrder?.purchaseOrderId- }- ]}- />- <View style={tw("flex flex-row justify-between mb-5")}>- <View style={tw("flex flex-col w-1/3 text-sm gap-2")}>- <Text style={tw("text-gray-500 text-xs")}>Supplier</Text>- <Text>{supplierName}</Text>- {supplierAddressLine1 && <Text>{supplierAddressLine1}</Text>}- {supplierAddressLine2 && <Text>{supplierAddressLine2}</Text>}- <Text>- {formatCityStatePostalCode(- supplierCity,- supplierStateProvince,- supplierPostalCode- )}- </Text>- <Text>{supplierCountryName}</Text>- </View>- {dropShipment ? (- <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>}- <Text>- {formatCityStatePostalCode(- customerCity,- customerStateProvince,- customerPostalCode- )}- </Text>- <Text>{customerCountryName}</Text>- </View>- ) : (- <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>}+ {/* Header */}+ <View style={tw("flex flex-row justify-between mb-1")}>+ <View style={tw("flex flex-col")}>+ <Text style={tw("text-xl font-bold text-blue-600")}>+ {company.name}+ </Text>+ <View style={tw("text-[10px] text-gray-600 mt-0.5")}>+ {company.addressLine1 && <Text>{company.addressLine1}</Text>}+ {(company.city || company.stateProvince || company.postalCode) && (<Text>{formatCityStatePostalCode(- deliveryCity,- deliveryStateProvince,- deliveryPostalCode+ company.city,+ company.stateProvince,+ company.postalCode)}</Text>- <Text>{deliveryCountryName}</Text>- </View>- )}- </View>- <View style={tw("flex flex-row justify-between mb-5 text-sm")}>- <View style={tw("flex flex-col gap-2 w-1/3")}>- <Text style={tw("text-gray-500 text-xs")}>Reference #</Text>- <Text>{purchaseOrder?.supplierReference}</Text>- </View>- <View style={tw("flex flex-col gap-2 w-1/3")}>- {/* <Text style={tw("text-gray-500 text-xs")}>Requested Date</Text>- <Text>{purchaseOrder?.receiptRequestedDate}</Text> */}- </View>- <View style={tw("flex flex-col gap-2 w-1/3")}>- <Text style={tw("text-gray-500 text-xs")}>Promised Date</Text>- <Text>{purchaseOrder?.receiptPromisedDate}</Text>+ )}+ {company.phone && <Text>{company.phone}</Text>}+ {company.website && <Text>{company.website}</Text>}</View></View>- {/* <View style={tw("flex flex-row justify-between mb-5")}>- <View style={tw("flex flex-col gap-2 w-1/3")}>- <Text style={tw("text-gray-500 text-xs")}>Shipping Method</Text>- <Text>{purchaseOrder?.shippingMethodName}</Text>- </View>- <View style={tw("flex flex-col gap-2 w-1/3")}>- <Text style={tw("text-gray-500 text-xs")}>Shipping Terms</Text>- <Text>{purchaseOrder?.shippingTermName}</Text>- </View>- <View style={tw("flex flex-col gap-2 w-1/3")}>- <Text style={tw("text-gray-500 text-xs")}>Payment Terms</Text>- <Text>{purchaseOrder?.paymentTermName}</Text>+ <View style={tw("flex flex-col items-end")}>+ <Text style={tw("text-2xl font-bold text-gray-800")}>+ PURCHASE ORDER+ </Text>+ <Text style={tw("text-sm font-bold text-gray-600")}>+ #{purchaseOrder?.purchaseOrderId}+ </Text>+ </View>+ </View>++ {/* Gray Divider */}+ <View style={tw("h-[2px] bg-gray-200 mb-4")} />++ {/* Supplier & Ship To Details */}+ <View style={tw("border border-gray-200 mb-4")}>+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Supplier+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {supplierName && (+ <Text style={tw("font-bold")}>{supplierName}</Text>+ )}+ {supplierAddressLine1 && <Text>{supplierAddressLine1}</Text>}+ {supplierAddressLine2 && <Text>{supplierAddressLine2}</Text>}+ {(supplierCity ||+ supplierStateProvince ||+ supplierPostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ supplierCity,+ supplierStateProvince,+ supplierPostalCode+ )}+ </Text>+ )}+ {supplierCountryName && <Text>{supplierCountryName}</Text>}+ </View></View>- </View> */}- <View style={tw("mb-5 text-xs")}>- <View- style={tw(- "flex flex-row justify-between items-center mt-5 py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase"- )}- >- <Text style={tw("w-[35%]")}>Description</Text>- <Text style={tw("w-[15%] text-right")}>Qty</Text>- <Text style={tw("w-[15%] text-right")}>Unit Price</Text>- <Text style={tw("w-[15%] text-right")}>Shipping</Text>- <Text style={tw("w-[20%] text-right")}>Total</Text>+ <View style={tw("w-1/2 p-3")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Ship To+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {dropShipment ? (+ <>+ {customerName && (+ <Text style={tw("font-bold")}>{customerName}</Text>+ )}+ {customerAddressLine1 && <Text>{customerAddressLine1}</Text>}+ {customerAddressLine2 && <Text>{customerAddressLine2}</Text>}+ {(customerCity ||+ customerStateProvince ||+ customerPostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ customerCity,+ customerStateProvince,+ customerPostalCode+ )}+ </Text>+ )}+ {customerCountryName && <Text>{customerCountryName}</Text>}+ </>+ ) : (+ <>+ {deliveryName && (+ <Text style={tw("font-bold")}>{deliveryName}</Text>+ )}+ {deliveryAddressLine1 && <Text>{deliveryAddressLine1}</Text>}+ {deliveryAddressLine2 && <Text>{deliveryAddressLine2}</Text>}+ {(deliveryCity ||+ deliveryStateProvince ||+ deliveryPostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ deliveryCity,+ deliveryStateProvince,+ deliveryPostalCode+ )}+ </Text>+ )}+ {deliveryCountryName && <Text>{deliveryCountryName}</Text>}+ </>+ )}+ </View></View>- {purchaseOrderLines.map((line) => (- <View- style={tw(- "flex flex-col w-full gap-4 py-3 px-[6px] border-b border-gray-300"+ </View>+ </View>++ {/* Order Details */}+ <View style={tw("border border-gray-200 mb-4")}>+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Order Details+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ <Text>Date: {formatDate(purchaseOrder?.orderDate)}</Text>+ {purchaseOrder?.supplierReference && (+ <Text>Reference: {purchaseOrder.supplierReference}</Text>)}- key={line.id}- wrap={false}+ </View>+ </View>+ <View style={tw("w-1/2 p-3")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}>- <View style={tw("flex flex-row justify-between")}>- <View style={tw("w-[35%]")}>- <Text style={tw("font-bold mb-1")}>- {getLineDescription(line)}+ Delivery+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {purchaseOrder?.receiptPromisedDate && (+ <Text>+ Promised Date: {formatDate(purchaseOrder.receiptPromisedDate)}+ </Text>+ )}+ </View>+ </View>+ </View>+ </View>++ {/* Line Items Table */}+ <View style={tw("mb-4")}>+ {/* Header */}+ <View+ style={tw(+ "flex flex-row bg-blue-600 py-2 px-3 text-white text-[9px] font-bold 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")}>Unit Price</Text>+ <Text style={tw("w-1/6 text-right")}>Total</Text>+ </View>++ {/* Rows */}+ {purchaseOrderLines.map((line) => {+ const isEven = rowIndex % 2 === 0;+ rowIndex++;++ return (+ <View key={line.id} wrap={false}>+ <View+ style={tw(+ `flex flex-col py-2 px-3 border-b border-gray-200 text-[10px] ${+ isEven ? "bg-white" : "bg-gray-50"+ }`+ )}+ >+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 pr-2")}>+ <Text style={tw("text-gray-800")}>+ {getLineDescription(line)}+ </Text>+ <Text style={tw("text-[8px] text-gray-400 mt-0.5")}>+ {getLineDescriptionDetails(line)}+ </Text>+ {purchaseOrder.purchaseOrderType === "Outside Processing" &&+ line.jobOperationDescription && (+ <Text style={tw("text-[8px] text-gray-400 mt-0.5")}>+ {line.jobOperationDescription}+ </Text>+ )}+ {thumbnails &&+ line.id in thumbnails &&+ thumbnails[line.id] && (+ <View style={tw("mt-1 w-16")}>+ <Image+ src={thumbnails[line.id]!}+ style={tw("w-full h-auto")}+ />+ </View>+ )}+ </View>+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ {line.purchaseOrderLineType === "Comment"+ ? ""+ : `${line.purchaseQuantity} ${line.purchaseUnitOfMeasureCode}`}</Text>- <Text style={tw("text-[9px] opacity-80")}>- {getLineDescriptionDetails(line)}+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ {line.purchaseOrderLineType === "Comment"+ ? ""+ : formatter.format(line.supplierUnitPrice ?? 0)}+ </Text>+ <Text+ style={tw("w-1/6 text-right text-gray-800 font-medium")}+ >+ {line.purchaseOrderLineType === "Comment"+ ? ""+ : formatter.format(getLineTotal(line))}</Text>- {purchaseOrder.purchaseOrderType === "Outside Processing" &&- line.jobOperationDescription && (- <Text style={tw("text-[9px] opacity-80 mt-1")}>- {line.jobOperationDescription}- </Text>- )}-- {thumbnails &&- line.id in thumbnails &&- thumbnails[line.id] && (- <View style={tw("mt-2")}>- <Image- src={thumbnails[line.id]!}- style={tw("w-full h-auto")}- />- </View>- )}</View>- <Text style={tw("w-[15%] text-right")}>- {line.purchaseOrderLineType === "Comment"- ? ""- : `${line.purchaseQuantity} ${line.purchaseUnitOfMeasureCode}`}- </Text>- <Text style={tw("w-[15%] text-right")}>- {line.purchaseOrderLineType === "Comment"- ? null- : formatter.format(line.supplierUnitPrice ?? 0)}- </Text>- <Text style={tw("w-[15%] text-right")}>- {line.purchaseOrderLineType === "Comment"- ? null- : formatter.format(line.supplierShippingCost ?? 0)}- </Text>- <Text style={tw("w-[20%] text-right")}>- {line.purchaseOrderLineType === "Comment"- ? null- : formatter.format(getLineTotal(line))}- </Text></View>{Object.keys(line.externalNotes ?? {}).length > 0 && (- <Note- key={`${line.id}-notes`}- content={line.externalNotes as JSONContent}- />+ <View style={tw("px-3 py-2 border-b border-gray-200")}>+ <Note+ key={`${line.id}-notes`}+ content={line.externalNotes as JSONContent}+ />+ </View>)}</View>- ))}- {taxAmount > 0 && (- <View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold uppercase"+ );+ })}++ {/* Summary */}+ <View>+ {/* Subtotal - before tax and shipping */}+ <View style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Subtotal</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(+ purchaseOrderLines.reduce((sum, line) => {+ if (line?.purchaseQuantity && line?.supplierUnitPrice) {+ return sum + line.purchaseQuantity * line.supplierUnitPrice;+ }+ return sum;+ }, 0))}+ </Text>+ </View>++ {/* Shipping */}+ {shippingCost > 0 && (+ <View+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>- <Text>Tax</Text>- <Text style={tw("font-normal text-gray-500")}>- {formatter.format(taxAmount)}+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Shipping</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(shippingCost)}</Text></View>)}- {shippingCost > 0 && (++ {/* Tax */}+ {taxAmount > 0 && (<View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold uppercase"- )}+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>- <Text>Shipping</Text>- <Text style={tw("font-normal text-gray-500")}>- {formatter.format(shippingCost)}+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Tax</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(taxAmount)}</Text></View>)}- <View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold uppercase"- )}- >- <Text>Total</Text>- <Text style={tw("font-bold text-black")}>++ <View style={tw("h-[2px] bg-gray-400")} />+ <View style={tw("flex flex-row py-2 px-3 text-[11px]")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-800 font-bold")}>+ Total+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-800 font-bold")}>{formatter.format(getTotal(purchaseOrderLines) + shippingCost)}</Text></View></View>- {purchaseOrder?.externalNotes && (+ </View>++ {/* Notes & Terms */}+ <View style={tw("flex flex-col gap-3 w-full")}>+ {Object.keys(purchaseOrder?.externalNotes ?? {}).length > 0 && (<Notetitle="Notes"content={(purchaseOrder.externalNotes ?? {}) as JSONContent}/>)}- </View>- <View style={tw("flex flex-col gap-4 w-full")}><Note title="Standard Terms & Conditions" content={terms} /></View></Template>diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsxindex d568412914..5edb203b5d 100644--- a/packages/documents/src/pdf/QuotePDF.tsx+++ b/packages/documents/src/pdf/QuotePDF.tsx@@ -226,7 +226,9 @@ const QuotePDF = ({</View><View style={tw("flex flex-col items-end")}><Text style={tw("text-2xl font-bold text-gray-800")}>QUOTE</Text>- <Text style={tw("text-xs text-gray-400")}>#{quote?.quoteId}</Text>+ <Text style={tw("text-sm font-bold text-gray-600")}>+ #{quote?.quoteId}+ </Text></View></View>@@ -281,7 +283,6 @@ const QuotePDF = ({{quote.customerReference && (<Text>Reference: {quote.customerReference}</Text>)}- {quote.status && <Text>Status: {quote.status}</Text>}</View></View></View>@@ -320,7 +321,7 @@ const QuotePDF = ({hasAnyLeadTime ? "w-2/12 text-right" : "w-1/6 text-right")}>- Item Total+ Total</Text></View>@@ -515,19 +516,23 @@ const QuotePDF = ({)}</View>- {/* Footer - Payment Terms */}- {paymentTerm && (+ {/* Footer - Lead Time & Payment Terms */}+ {(shipment?.leadTime || paymentTerm) && (<View style={tw("flex flex-row gap-8 mb-4 text-[10px]")}>- {/* {maxLeadTime > 0 && (+ {shipment?.leadTime ? (<View style={tw("flex flex-row")}><Text style={tw("font-bold text-gray-800")}>Lead Time: </Text>- <Text style={tw("text-gray-600")}>{maxLeadTime} days</Text>+ <Text style={tw("text-gray-600")}>+ {shipment.leadTime} {shipment.leadTime === 1 ? "day" : "days"}+ </Text></View>- )} */}- <View style={tw("flex flex-row")}>- <Text style={tw("font-bold text-gray-800")}>Payment Terms: </Text>- <Text style={tw("text-gray-600")}>{paymentTerm.name}</Text>- </View>+ ) : null}+ {paymentTerm && (+ <View style={tw("flex flex-row")}>+ <Text style={tw("font-bold text-gray-800")}>Payment Terms: </Text>+ <Text style={tw("text-gray-600")}>{paymentTerm.name}</Text>+ </View>+ )}</View>)}diff --git a/packages/documents/src/pdf/SalesInvoicePDF.tsx b/packages/documents/src/pdf/SalesInvoicePDF.tsxindex a45c02d89c..a6e5804083 100644--- a/packages/documents/src/pdf/SalesInvoicePDF.tsx+++ b/packages/documents/src/pdf/SalesInvoicePDF.tsx@@ -7,12 +7,12 @@ import type { PDF } from "../types";import {getLineDescription,getLineDescriptionDetails,- getLineTaxesAndFees,+ getLineSubtotal,getLineTotal,getTotal} from "../utils/sales-invoice";import { getCurrencyFormatter } from "../utils/shared";-import { Header, Note, Summary, Template } from "./components";+import { Note, Template } from "./components";interface SalesInvoicePDFProps extends PDF {salesInvoice: Database["public"]["Views"]["salesInvoices"]["Row"];@@ -25,16 +25,22 @@ interface SalesInvoicePDFProps extends PDF {thumbnails?: Record<string, string | null>;}-// Initialize tailwind-styled-componentsconst tw = createTw({theme: {fontFamily: {- sans: ["Helvetica", "Arial", "sans-serif"]+ sans: ["Inter", "Helvetica", "Arial", "sans-serif"]},extend: {colors: {+ blue: {+ 600: "#202278"+ },gray: {- 500: "#7d7d7d"+ 50: "#f9fafb",+ 200: "#e5e7eb",+ 400: "#9ca3af",+ 600: "#4b5563",+ 800: "#1f2937"}}}@@ -75,32 +81,29 @@ const SalesInvoicePDF = ({const currencyCode = salesInvoice.currencyCode ?? company.baseCurrencyCode;const formatter = getCurrencyFormatter(currencyCode, locale);- const summaryItems = [- {- label: "Date Issued",- value: salesInvoice?.dateIssued- },- {- label: "Invoice #",- value: salesInvoice?.invoiceId- }- ];+ const paymentTerm = paymentTerms?.find(+ (term) => term.id === salesInvoice?.paymentTermId+ );- if (salesInvoice?.paymentTermId) {- summaryItems.push({- label: "Payment Terms",- value: paymentTerms.find(- (term) => term.id === salesInvoice?.paymentTermId- )?.name- });- }+ const shippingMethod = shippingMethods?.find(+ (method) => method.id === salesInvoiceShipment?.shippingMethodId+ );- if (salesInvoice?.dateDue) {- summaryItems.push({- label: "Due Date",- value: salesInvoice?.dateDue- });- }+ const formatDate = (dateStr: string | null) => {+ if (!dateStr) return null;+ try {+ const date = new Date(dateStr);+ return date.toLocaleDateString("en-US", {+ year: "numeric",+ month: "long",+ day: "numeric"+ });+ } catch {+ return dateStr;+ }+ };++ let rowIndex = 0;return (<Template@@ -111,183 +114,285 @@ const SalesInvoicePDF = ({subject: meta?.subject ?? "Invoice"}}>- <View>- <Header title={title} company={company} />- <Summary company={company} items={summaryItems} />- <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")}>- {formatCityStatePostalCode(- customerCity,- customerStateProvince,- customerPostalCode- )}- </Text>- <Text style={tw("text-sm")}>{customerCountryName}</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")}>{invoiceCustomerName}</Text>- {invoiceAddressLine1 && (- <Text style={tw("text-sm")}>{invoiceAddressLine1}</Text>- )}- {invoiceAddressLine2 && (- <Text style={tw("text-sm")}>{invoiceAddressLine2}</Text>+ {/* Header */}+ <View style={tw("flex flex-row justify-between mb-1")}>+ <View style={tw("flex flex-col")}>+ <Text style={tw("text-xl font-bold text-blue-600")}>+ {company.name}+ </Text>+ <View style={tw("text-[10px] text-gray-600 mt-0.5")}>+ {company.addressLine1 && <Text>{company.addressLine1}</Text>}+ {(company.city || company.stateProvince || company.postalCode) && (+ <Text>+ {formatCityStatePostalCode(+ company.city,+ company.stateProvince,+ company.postalCode+ )}+ </Text>)}- <Text style={tw("text-sm")}>- {formatCityStatePostalCode(- invoiceCity,- invoiceStateProvince,- invoicePostalCode- )}- </Text>- <Text style={tw("text-sm")}>{invoiceCountryName}</Text>+ {company.phone && <Text>{company.phone}</Text>}+ {company.website && <Text>{company.website}</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 Invoice #</Text>- <Text style={tw("text-sm")}>{salesInvoice?.customerReference}</Text>+ <View style={tw("flex flex-col items-end")}>+ <Text style={tw("text-2xl font-bold text-gray-800")}>INVOICE</Text>+ <Text style={tw("text-sm font-bold text-gray-600")}>+ #{salesInvoice?.invoiceId}+ </Text>+ </View>+ </View>++ {/* Divider */}+ <View style={tw("h-[2px] bg-gray-200 mb-4")} />++ {/* Ship To & Bill To */}+ <View style={tw("border border-gray-200 mb-4")}>+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Ship To+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {customerName && (+ <Text style={tw("font-bold")}>{customerName}</Text>+ )}+ {customerAddressLine1 && (+ <Text style={tw("mt-1")}>{customerAddressLine1}</Text>+ )}+ {customerAddressLine2 && <Text>{customerAddressLine2}</Text>}+ {(customerCity ||+ customerStateProvince ||+ customerPostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ customerCity,+ customerStateProvince,+ customerPostalCode+ )}+ </Text>+ )}+ {customerCountryName && <Text>{customerCountryName}</Text>}+ </View></View>- <View style={tw("flex flex-col gap-1 w-1/3")}>- <Text style={tw("text-gray-500 text-xs")}>Due Date</Text>- <Text style={tw("text-sm")}>{salesInvoice?.dateDue}</Text>+ <View style={tw("w-1/2 p-3")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Bill To+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {invoiceCustomerName && (+ <Text style={tw("font-bold")}>{invoiceCustomerName}</Text>+ )}+ {invoiceAddressLine1 && (+ <Text style={tw("mt-1")}>{invoiceAddressLine1}</Text>+ )}+ {invoiceAddressLine2 && <Text>{invoiceAddressLine2}</Text>}+ {(invoiceCity || invoiceStateProvince || invoicePostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ invoiceCity,+ invoiceStateProvince,+ invoicePostalCode+ )}+ </Text>+ )}+ {invoiceCountryName && <Text>{invoiceCountryName}</Text>}+ </View></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")}>- {- shippingMethods.find(- (method) =>- method.id === salesInvoiceShipment?.shippingMethodId- )?.name- }+ </View>++ {/* Invoice Details */}+ <View style={tw("border border-gray-200 mb-4")}>+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Invoice Details</Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {salesInvoice?.dateIssued && (+ <Text>Date Issued: {formatDate(salesInvoice.dateIssued)}</Text>+ )}+ {salesInvoice?.dateDue && (+ <Text>Due Date: {formatDate(salesInvoice.dateDue)}</Text>+ )}+ {salesInvoice?.customerReference && (+ <Text>Customer Ref: {salesInvoice.customerReference}</Text>+ )}+ {paymentTerm && <Text>Payment Terms: {paymentTerm.name}</Text>}+ </View></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")}>- {salesInvoiceShipment?.shippingTermId}+ <View style={tw("w-1/2 p-3")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Shipping</Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {shippingMethod && <Text>Method: {shippingMethod.name}</Text>}+ {salesInvoiceShipment?.shippingTermId && (+ <Text>Terms: {salesInvoiceShipment.shippingTermId}</Text>+ )}+ </View></View></View>- <View style={tw("mb-5 text-xs")}>- <View- style={tw(- "flex flex-row justify-between items-center mt-5 py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase"- )}- >- <Text style={tw("w-5/12 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/6 text-right")}>Tax & Fees</Text>- <Text style={tw("w-1/6 text-right")}>Total</Text>- </View>- {salesInvoiceLines.map((line) => {- return (- <View- style={tw(- "flex flex-row justify-between py-3 px-[6px] border-b border-gray-300"- )}- key={line.id}- wrap={false}- >- <View style={tw("w-5/12")}>- <Text style={tw("font-bold mb-1")}>- {getLineDescription(line)}- </Text>- <Text style={tw("text-[9px] opacity-80")}>- {getLineDescriptionDetails(line)}- </Text>+ </View>- {thumbnails &&- line.id in thumbnails &&- thumbnails[line.id] && (- <View style={tw("mt-2")}>- <Image- src={thumbnails[line.id]!}- style={tw("w-full h-auto")}- />- </View>- )}+ {/* Line Items Table */}+ <View style={tw("mb-4")}>+ {/* Header */}+ <View+ style={tw(+ "flex flex-row bg-blue-600 py-2 px-3 text-white text-[9px] font-bold 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")}>Unit Price</Text>+ <Text style={tw("w-1/6 text-right")}>Total</Text>+ </View>- <View style={tw("mt-1")}>- {Object.keys(line.externalNotes ?? {}).length > 0 && (- <Note- key={`${line.id}-notes`}- content={line.externalNotes as JSONContent}- />- )}- </View>- </View>- <Text style={tw("w-1/6 text-right")}>- {line.invoiceLineType === "Comment"- ? ""- : `${line.quantity} ${line.unitOfMeasureCode}`}+ {/* Rows */}+ {salesInvoiceLines.map((line) => {+ const isEven = rowIndex % 2 === 0;+ rowIndex++;++ return (+ <View+ key={line.id}+ style={tw(+ `flex flex-row py-2 px-3 border-b border-gray-200 text-[10px] ${+ isEven ? "bg-white" : "bg-gray-50"+ }`+ )}+ wrap={false}+ >+ <View style={tw("w-1/2 pr-2")}>+ <Text style={tw("text-gray-800")}>+ {getLineDescription(line)}</Text>- <Text style={tw("w-1/6 text-right")}>- {line.invoiceLineType === "Comment"- ? null- : formatter.format(line.convertedUnitPrice ?? 0)}+ <Text style={tw("text-[8px] text-gray-400 mt-0.5")}>+ {getLineDescriptionDetails(line)}</Text>- <Text style={tw("w-1/6 text-right")}>- {line.invoiceLineType === "Comment"- ? null- : formatter.format(getLineTaxesAndFees(line))}+ {thumbnails && line.id in thumbnails && thumbnails[line.id] && (+ <View style={tw("mt-1 w-16")}>+ <Image+ src={thumbnails[line.id]!}+ style={tw("w-full h-auto")}+ />+ </View>+ )}+ {Object.keys(line.externalNotes ?? {}).length > 0 && (+ <View style={tw("mt-1")}>+ <Note+ key={`${line.id}-notes`}+ content={line.externalNotes as JSONContent}+ />+ </View>+ )}+ </View>+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ {line.invoiceLineType === "Comment"+ ? ""+ : `${line.quantity} ${line.unitOfMeasureCode ?? "EA"}`}+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ {line.invoiceLineType === "Comment"+ ? ""+ : formatter.format(line.convertedUnitPrice ?? 0)}+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-800 font-medium")}>+ {line.invoiceLineType === "Comment"+ ? ""+ : formatter.format(getLineTotal(line))}+ </Text>+ </View>+ );+ })}++ {/* Summary */}+ <View>+ {/* Subtotal - before tax */}+ <View style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Subtotal</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(+ salesInvoiceLines.reduce(+ (sum, line) => sum + getLineSubtotal(line),+ 0+ )+ )}+ </Text>+ </View>++ {/* Shipping */}+ {salesInvoiceShipment?.shippingCost &&+ salesInvoiceShipment.shippingCost > 0 && (+ <View+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}+ >+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ Shipping</Text>- <Text style={tw("w-1/6 text-right")}>- {line.invoiceLineType === "Comment"- ? null- : formatter.format(getLineTotal(line))}+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(+ (salesInvoiceShipment.shippingCost ?? 0) *+ (salesInvoice.exchangeRate ?? 1)+ )}</Text></View>- );- })}- {salesInvoiceShipment?.shippingCost && (+ )}++ {/* Taxes */}+ {salesInvoiceLines.some((line) => (line.taxPercent ?? 0) > 0) && (<View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold text-gray-500 uppercase"- )}+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>- <Text>Shipping</Text>- <Text style={tw("text-black")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Taxes</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>{formatter.format(- (salesInvoiceShipment.shippingCost ?? 0) *- (salesInvoice.exchangeRate ?? 1)+ salesInvoiceLines.reduce((sum, line) => {+ const taxPercent = line.taxPercent ?? 0;+ return sum + getLineSubtotal(line) * taxPercent;+ }, 0))}</Text></View>)}- <View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold uppercase"- )}- >- <Text>Total</Text>- <Text style={tw("font-bold text-black")}>++ <View style={tw("h-[2px] bg-gray-400")} />+ <View style={tw("flex flex-row py-2 px-3 text-[11px]")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-800 font-bold")}>+ Total+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-800 font-bold")}>{formatter.format(getTotal(salesInvoiceLines, salesInvoice, salesInvoiceShipment))}</Text></View></View>- <View style={tw("flex flex-col gap-4 w-full")}>+ </View>++ {/* Notes & Terms */}+ <View style={tw("flex flex-col gap-3 w-full")}>+ {Object.keys(salesInvoice.externalNotes ?? {}).length > 0 && (<Notetitle="Notes"content={(salesInvoice.externalNotes ?? {}) as JSONContent}/>- <Note title="Standard Terms & Conditions" content={terms} />- </View>+ )}+ <Note title="Standard Terms & Conditions" content={terms} /></View></Template>);diff --git a/packages/documents/src/pdf/SalesOrderPDF.tsx b/packages/documents/src/pdf/SalesOrderPDF.tsxindex a2a2c11445..da5b8648b3 100644--- a/packages/documents/src/pdf/SalesOrderPDF.tsx+++ b/packages/documents/src/pdf/SalesOrderPDF.tsx@@ -7,12 +7,12 @@ import type { PDF } from "../types";import {getLineDescription,getLineDescriptionDetails,- getLineTaxesAndFees,+ getLineSubtotal,getLineTotal,getTotal} from "../utils/sales-order";import { getCurrencyFormatter } from "../utils/shared";-import { Header, Note, Summary, Template } from "./components";+import { Note, Template } from "./components";interface SalesOrderPDFProps extends PDF {salesOrder: Database["public"]["Views"]["salesOrders"]["Row"];@@ -24,16 +24,22 @@ interface SalesOrderPDFProps extends PDF {thumbnails?: Record<string, string | null>;}-// Initialize tailwind-styled-componentsconst tw = createTw({theme: {fontFamily: {- sans: ["Helvetica", "Arial", "sans-serif"]+ sans: ["Inter", "Helvetica", "Arial", "sans-serif"]},extend: {colors: {+ blue: {+ 600: "#202278"+ },gray: {- 500: "#7d7d7d"+ 50: "#f9fafb",+ 200: "#e5e7eb",+ 400: "#9ca3af",+ 600: "#4b5563",+ 800: "#1f2937"}}}@@ -73,6 +79,30 @@ const SalesOrderPDF = ({const currencyCode = salesOrder.currencyCode ?? company.baseCurrencyCode;const formatter = getCurrencyFormatter(currencyCode, locale);+ const paymentTerm = paymentTerms?.find(+ (term) => term.id === salesOrder?.paymentTermId+ );++ const shippingMethod = shippingMethods?.find(+ (method) => method.id === salesOrder?.shippingMethodId+ );++ const formatDate = (dateStr: string | null) => {+ if (!dateStr) return null;+ try {+ const date = new Date(dateStr);+ return date.toLocaleDateString("en-US", {+ year: "numeric",+ month: "long",+ day: "numeric"+ });+ } catch {+ return dateStr;+ }+ };++ let rowIndex = 0;+return (<Templatetitle={title}@@ -82,181 +112,241 @@ const SalesOrderPDF = ({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")}>- {formatCityStatePostalCode(- customerCity,- customerStateProvince,- customerPostalCode- )}- </Text>- <Text style={tw("text-sm")}>{customerCountryName}</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>+ {/* Header */}+ <View style={tw("flex flex-row justify-between mb-1")}>+ <View style={tw("flex flex-col")}>+ <Text style={tw("text-xl font-bold text-blue-600")}>+ {company.name}+ </Text>+ <View style={tw("text-[10px] text-gray-600 mt-0.5")}>+ {company.addressLine1 && <Text>{company.addressLine1}</Text>}+ {(company.city || company.stateProvince || company.postalCode) && (+ <Text>+ {formatCityStatePostalCode(+ company.city,+ company.stateProvince,+ company.postalCode+ )}+ </Text>)}- <Text style={tw("text-sm")}>- {formatCityStatePostalCode(- paymentCity,- paymentStateProvince,- paymentPostalCode- )}- </Text>- <Text style={tw("text-sm")}>{paymentCountryName}</Text>+ {company.phone && <Text>{company.phone}</Text>}+ {company.website && <Text>{company.website}</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}+ <View style={tw("flex flex-col items-end")}>+ <Text style={tw("text-2xl font-bold text-gray-800")}>+ SALES ORDER+ </Text>+ <Text style={tw("text-sm font-bold text-gray-600")}>+ #{salesOrder?.salesOrderId}+ </Text>+ </View>+ </View>++ {/* Divider */}+ <View style={tw("h-[2px] bg-gray-200 mb-4")} />++ {/* Ship To & Bill To */}+ <View style={tw("border border-gray-200 mb-4")}>+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Ship To</Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {customerName && (+ <Text style={tw("font-bold")}>{customerName}</Text>+ )}+ {customerAddressLine1 && (+ <Text style={tw("mt-1")}>{customerAddressLine1}</Text>+ )}+ {customerAddressLine2 && <Text>{customerAddressLine2}</Text>}+ {(customerCity ||+ customerStateProvince ||+ customerPostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ customerCity,+ customerStateProvince,+ customerPostalCode+ )}+ </Text>+ )}+ {customerCountryName && <Text>{customerCountryName}</Text>}+ </View></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 style={tw("w-1/2 p-3")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Bill To+ </Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {paymentCustomerName && (+ <Text style={tw("font-bold")}>{paymentCustomerName}</Text>+ )}+ {paymentAddressLine1 && (+ <Text style={tw("mt-1")}>{paymentAddressLine1}</Text>+ )}+ {paymentAddressLine2 && <Text>{paymentAddressLine2}</Text>}+ {(paymentCity || paymentStateProvince || paymentPostalCode) && (+ <Text>+ {formatCityStatePostalCode(+ paymentCity,+ paymentStateProvince,+ paymentPostalCode+ )}+ </Text>+ )}+ {paymentCountryName && <Text>{paymentCountryName}</Text>}+ </View></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")}>- {- shippingMethods.find(- (method) => method.id === salesOrder?.shippingMethodId- )?.name- }+ </View>++ {/* Order Details */}+ <View style={tw("border border-gray-200 mb-4")}>+ <View style={tw("flex flex-row")}>+ <View style={tw("w-1/2 p-3 border-r border-gray-200")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Order Details</Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {salesOrder?.orderDate && (+ <Text>Date: {formatDate(salesOrder.orderDate)}</Text>+ )}+ {salesOrder?.customerReference && (+ <Text>Customer PO #: {salesOrder.customerReference}</Text>+ )}+ {salesOrder?.receiptRequestedDate && (+ <Text>+ Requested: {formatDate(salesOrder.receiptRequestedDate)}+ </Text>+ )}+ {salesOrder?.receiptPromisedDate && (+ <Text>+ Promised: {formatDate(salesOrder.receiptPromisedDate)}+ </Text>+ )}+ </View></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")}>- {- paymentTerms.find(- (term) => term.id === salesOrder?.paymentTermId- )?.name- }+ <View style={tw("w-1/2 p-3")}>+ <Text+ style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}+ >+ Shipping & Payment</Text>+ <View style={tw("text-[10px] text-gray-800")}>+ {shippingMethod && <Text>Method: {shippingMethod.name}</Text>}+ {salesOrder?.shippingTermName && (+ <Text>Terms: {salesOrder.shippingTermName}</Text>+ )}+ {paymentTerm && <Text>Payment: {paymentTerm.name}</Text>}+ </View></View></View>- <View style={tw("mb-5 text-xs")}>- <View- style={tw(- "flex flex-row justify-between items-center mt-5 py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase"- )}- >- <Text style={tw("w-5/12 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/6 text-right")}>Tax & Fees</Text>- <Text style={tw("w-1/6 text-right")}>Total</Text>- </View>- {salesOrderLines.map((line) => {- return (- <View- style={tw(- "flex flex-row justify-between py-3 px-[6px] border-b border-gray-300"- )}- key={line.id}- wrap={false}- >- <View style={tw("w-5/12")}>- <Text style={tw("font-bold mb-1")}>- {getLineDescription(line)}- </Text>- <Text style={tw("text-[9px] opacity-80")}>- {getLineDescriptionDetails(line)}- </Text>+ </View>- {thumbnails &&- line.id in thumbnails &&- thumbnails[line.id] && (- <View style={tw("mt-2")}>- <Image- src={thumbnails[line.id]!}- style={tw("w-full h-auto")}- />- </View>- )}+ {/* Line Items Table */}+ <View style={tw("mb-4")}>+ {/* Header */}+ <View+ style={tw(+ "flex flex-row bg-blue-600 py-2 px-3 text-white text-[9px] font-bold 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")}>Unit Price</Text>+ <Text style={tw("w-1/6 text-right")}>Total</Text>+ </View>- <View style={tw("mt-1")}>- {Object.keys(line.externalNotes ?? {}).length > 0 && (- <Note- key={`${line.id}-notes`}- content={line.externalNotes as JSONContent}- />- )}- </View>- </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.convertedUnitPrice ?? 0)}- </Text>- <Text style={tw("w-1/6 text-right")}>- {line.salesOrderLineType === "Comment"- ? null- : formatter.format(getLineTaxesAndFees(line))}+ {/* Rows */}+ {salesOrderLines.map((line) => {+ const isEven = rowIndex % 2 === 0;+ rowIndex++;++ return (+ <View+ key={line.id}+ style={tw(+ `flex flex-row py-2 px-3 border-b border-gray-200 text-[10px] ${+ isEven ? "bg-white" : "bg-gray-50"+ }`+ )}+ wrap={false}+ >+ <View style={tw("w-1/2 pr-2")}>+ <Text style={tw("text-gray-800")}>+ {getLineDescription(line)}</Text>- <Text style={tw("w-1/6 text-right")}>- {line.salesOrderLineType === "Comment"- ? null- : formatter.format(getLineTotal(line))}+ <Text style={tw("text-[8px] text-gray-400 mt-0.5")}>+ {getLineDescriptionDetails(line)}</Text>+ {thumbnails && line.id in thumbnails && thumbnails[line.id] && (+ <View style={tw("mt-1 w-16")}>+ <Image+ src={thumbnails[line.id]!}+ style={tw("w-full h-auto")}+ />+ </View>+ )}+ {Object.keys(line.externalNotes ?? {}).length > 0 && (+ <View style={tw("mt-1")}>+ <Note+ key={`${line.id}-notes`}+ content={line.externalNotes as JSONContent}+ />+ </View>+ )}</View>- );- })}- {salesOrder.shippingCost && (- <View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold text-gray-500 uppercase"+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ {line.salesOrderLineType === "Comment"+ ? ""+ : `${line.saleQuantity} ${line.unitOfMeasureCode ?? "EA"}`}+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-600")}>+ {line.salesOrderLineType === "Comment"+ ? ""+ : formatter.format(line.convertedUnitPrice ?? 0)}+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-800 font-medium")}>+ {line.salesOrderLineType === "Comment"+ ? ""+ : formatter.format(getLineTotal(line))}+ </Text>+ </View>+ );+ })}++ {/* Summary */}+ <View>+ {/* Subtotal - before tax */}+ <View style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Subtotal</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(+ salesOrderLines.reduce(+ (sum, line) => sum + getLineSubtotal(line),+ 0+ ))}+ </Text>+ </View>++ {/* Shipping */}+ {salesOrder.shippingCost && salesOrder.shippingCost > 0 && (+ <View+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>- <Text>Shipping</Text>- <Text style={tw("text-black")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Shipping</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>{formatter.format((salesOrder.shippingCost ?? 0) *(salesOrder.exchangeRate ?? 1)@@ -264,24 +354,47 @@ const SalesOrderPDF = ({</Text></View>)}- <View- style={tw(- "flex flex-row justify-between items-center py-3 px-[6px] border-b border-gray-300 font-bold uppercase"- )}- >- <Text>Total</Text>- <Text style={tw("font-bold text-black")}>++ {/* Taxes */}+ {salesOrderLines.some((line) => (line.taxPercent ?? 0) > 0) && (+ <View+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}+ >+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-600")}>Taxes</Text>+ <Text style={tw("w-1/6 text-right text-gray-800")}>+ {formatter.format(+ salesOrderLines.reduce((sum, line) => {+ const taxPercent = line.taxPercent ?? 0;+ return sum + getLineSubtotal(line) * taxPercent;+ }, 0)+ )}+ </Text>+ </View>+ )}++ <View style={tw("h-[2px] bg-gray-400")} />+ <View style={tw("flex flex-row py-2 px-3 text-[11px]")}>+ <View style={tw("w-4/6")} />+ <Text style={tw("w-1/6 text-right text-gray-800 font-bold")}>+ Total+ </Text>+ <Text style={tw("w-1/6 text-right text-gray-800 font-bold")}>{formatter.format(getTotal(salesOrderLines, salesOrder))}</Text></View></View>- <View style={tw("flex flex-col gap-4 w-full")}>+ </View>++ {/* Notes & Terms */}+ <View style={tw("flex flex-col gap-3 w-full")}>+ {Object.keys(salesOrder.externalNotes ?? {}).length > 0 && (<Notetitle="Notes"content={(salesOrder.externalNotes ?? {}) as JSONContent}/>- <Note title="Standard Terms & Conditions" content={terms} />- </View>+ )}+ <Note title="Standard Terms & Conditions" content={terms} /></View></Template>);