Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: quote and sales order summaries
Brad Barbin7d530df5daf2
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteSummary.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteSummary.tsxnew file mode 100644index 0000000000..a581194abb--- /dev/null+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteSummary.tsx@@ -0,0 +1,730 @@+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+ HStack,+ Heading,+ IconButton,+ RadioGroup,+ RadioGroupItem,+ Table,+ Tbody,+ Td,+ Th,+ Thead,+ Tr,+ VStack,+} from "@carbon/react";+import { formatDate } from "@carbon/utils";+import { useLocale } from "@react-aria/i18n";+import { Link, useParams } from "@remix-run/react";+import { motion } from "framer-motion";+import MotionNumber from "motion-number";+import type { Dispatch, SetStateAction } from "react";+import { useEffect, useMemo, useState } from "react";+import { LuChevronDown, LuExternalLink, LuImage } from "react-icons/lu";+import { CustomerAvatar } from "~/components";+import { usePercentFormatter, useRouteData, useUser } from "~/hooks";+import { getPrivateUrl, path } from "~/utils/path";+import type {+ Quotation,+ QuotationLine,+ QuotationPrice,+ QuotationShipment,+ SalesOrderLine,+} from "../../types";++type SelectedLine = {+ quantity: number;+ netUnitPrice: number;+ convertedNetUnitPrice: number;+ addOn: number;+ convertedAddOn: number;+ leadTime: number;+ shippingCost: number;+ convertedShippingCost: number;+ taxPercent: number;+};++const deselectedLine: SelectedLine = {+ addOn: 0,+ convertedAddOn: 0,+ netUnitPrice: 0,+ convertedNetUnitPrice: 0,+ quantity: 0,+ leadTime: 0,+ shippingCost: 0,+ convertedShippingCost: 0,+ taxPercent: 0,+};++const LineItems = ({+ currencyCode,+ formatter,+ locale,+ selectedLines,+ setSelectedLines,+}: {+ currencyCode: string;+ formatter: Intl.NumberFormat;+ locale: string;+ selectedLines: Record<string, SelectedLine>;+ setSelectedLines: Dispatch<SetStateAction<Record<string, SelectedLine>>>;+}) => {+ const { company } = useUser();+ const { quoteId } = useParams();+ if (!quoteId) throw new Error("Could not find quote id");+ const routeData = useRouteData<{+ quote: Quotation;+ lines: QuotationLine[];+ prices: QuotationPrice[];+ }>(path.to.quote(quoteId));++ const [openItems, setOpenItems] = useState<string[]>([]);++ useEffect(() => {+ Object.entries(selectedLines).forEach(([lineId, line]) => {+ if (line.quantity === 0 && openItems.includes(lineId)) {+ setOpenItems((prev) => prev.filter((item) => item !== lineId));+ }+ });+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [selectedLines]);++ const pricingByLine = useMemo(+ () =>+ routeData?.lines?.reduce<Record<string, QuotationPrice[]>>(+ (acc, line) => {+ if (!line.id) {+ return acc;+ }+ acc[line.id!] =+ routeData?.prices?.filter((p) => p.quoteLineId === line.id) ?? [];+ return acc;+ },+ {}+ ) ?? {},+ [routeData?.lines, routeData?.prices]+ );++ const toggleOpen = (id: string) => {+ setOpenItems((prev) =>+ prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]+ );+ };++ const shouldConvertCurrency =+ routeData?.quote.currencyCode !== company?.baseCurrencyCode;++ return (+ <VStack spacing={8} className="w-full overflow-hidden">+ {routeData?.lines?.map((line) => {+ const prices = pricingByLine[line.id!];++ if (!line || !prices || !line.id) {+ return null;+ }++ return (+ <motion.div+ key={line.id}+ initial={{ opacity: 0, y: 50 }}+ animate={{ opacity: 1, y: 0 }}+ transition={{ duration: 0.5 }}+ className="border-b border-input py-6 w-full"+ >+ <HStack spacing={4} className="items-start">+ {line.thumbnailPath ? (+ <img+ alt={line.itemReadableId!}+ className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent"+ src={getPrivateUrl(line.thumbnailPath)}+ />+ ) : (+ <div className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2">+ <LuImage className="w-16 h-16 text-muted-foreground" />+ </div>+ )}++ <VStack spacing={0} className="w-full">+ <div+ className="flex flex-col cursor-pointer w-full"+ onClick={() => toggleOpen(line.id!)}+ >+ <div className="flex items-center gap-x-4 justify-between flex-grow">+ <HStack spacing={0} className="min-w-0 flex-shrink">+ <Heading className="truncate">+ {line.itemReadableId}+ </Heading>+ <Link+ to={path.to.quoteLine(quoteId, line.id!)}+ className="text-muted-foreground"+ >+ <IconButton+ aria-label="View Line Item"+ icon={<LuExternalLink />}+ variant="ghost"+ />+ </Link>+ </HStack>+ <HStack spacing={4}>+ {/* <span className="font-medium text-xl">+ {formatter.format(+ (selectedLines[line.id!]?.convertedNetUnitPrice ??+ 0) *+ (selectedLines[line.id!]?.quantity ?? 0) ++ (selectedLines[line.id!]?.convertedAddOn ?? 0)+ )}+ </span> */}+ <MotionNumber+ className="font-bold text-xl"+ value={+ ((selectedLines[line.id!]?.convertedNetUnitPrice ??+ 0) *+ (selectedLines[line.id!]?.quantity ?? 0) ++ (selectedLines[line.id!]?.convertedAddOn ?? 0) ++ selectedLines[line.id!]?.convertedShippingCost) *+ (1 + selectedLines[line.id!]?.taxPercent)+ }+ format={{+ style: "currency",+ currency: currencyCode,+ }}+ locales={locale}+ />+ <motion.div+ animate={{+ rotate: openItems.includes(line.id) ? 180 : 0,+ }}+ transition={{ duration: 0.3 }}+ >+ <LuChevronDown size={24} />+ </motion.div>+ </HStack>+ </div>+ <span className="text-muted-foreground text-base truncate">+ {line.description}+ </span>+ </div>+ </VStack>+ </HStack>++ <motion.div+ initial="collapsed"+ animate={openItems.includes(line.id) ? "open" : "collapsed"}+ variants={{+ open: { opacity: 1, height: "auto", marginTop: 16 },+ collapsed: { opacity: 0, height: 0, marginTop: 0 },+ }}+ transition={{ duration: 0.3 }}+ className="w-full overflow-hidden"+ >+ <LinePricingOptions+ formatter={formatter}+ line={line}+ options={pricingByLine[line.id!]}+ quoteCurrency={routeData?.quote.currencyCode ?? "USD"}+ quoteExchangeRate={routeData?.quote.exchangeRate ?? 1}+ shouldConvertCurrency={shouldConvertCurrency}+ locale={locale}+ selectedLine={selectedLines[line.id!]}+ setSelectedLines={setSelectedLines}+ />+ </motion.div>+ </motion.div>+ );+ })}+ </VStack>+ );+};++type LinePricingOptionsProps = {+ line: QuotationLine;+ options: QuotationPrice[];+ quoteCurrency: string;+ shouldConvertCurrency: boolean;+ quoteExchangeRate: number;+ locale: string;+ formatter: Intl.NumberFormat;+ selectedLine: SelectedLine;+ setSelectedLines: Dispatch<SetStateAction<Record<string, SelectedLine>>>;+};++const LinePricingOptions = ({+ line,+ options,+ quoteCurrency,+ shouldConvertCurrency,+ quoteExchangeRate,+ locale,+ formatter,+ selectedLine,+ setSelectedLines,+}: LinePricingOptionsProps) => {+ const percentFormatter = usePercentFormatter();+ const { quoteId } = useParams();+ if (!quoteId) throw new Error("Could not find quote id");+ const routeData = useRouteData<{+ quote: Quotation;+ salesOrderLines: SalesOrderLine[];+ }>(path.to.quote(quoteId));++ const [selectedValue, setSelectedValue] = useState<string | null>(+ selectedLine?.quantity?.toString() ?? null+ );++ const additionalChargesByQuantity =+ line.quantity?.reduce(+ (acc, quantity) => {+ const charges = Object.values(line.additionalCharges ?? {}).reduce(+ (chargeAcc, charge) => {+ const amount = charge.amounts?.[quantity];+ return chargeAcc + amount;+ },+ 0+ );+ acc[quantity] = charges;+ return acc;+ },+ { 0: 0 } as Record<number, number>+ ) ?? {};++ const convertedAdditionalChargesByQuantity = Object.entries(+ additionalChargesByQuantity+ ).reduce<Record<number, number>>(+ (acc, [quantity, amount]) => {+ acc[Number(quantity)] = amount * quoteExchangeRate;+ return acc;+ },+ { 0: 0 }+ );++ const additionalCharges: { name: string; amount: number }[] = [];+ if (selectedLine.convertedShippingCost) {+ additionalCharges.push({+ name: "Shipping",+ amount: selectedLine.convertedShippingCost,+ });+ }+ Object.entries(line.additionalCharges ?? {}).forEach(([name, charge]) => {+ additionalCharges.push({+ name: charge.description,+ amount: charge.amounts?.[selectedLine.quantity] * quoteExchangeRate,+ });+ });++ return (+ <VStack spacing={4}>+ <RadioGroup+ className="w-full"+ value={selectedValue ?? undefined}+ disabled={["Ordered", "Partial", "Expired", "Cancelled"].includes(+ routeData?.quote.status ?? ""+ )}+ onValueChange={(value) => {+ const selectedOption =+ value === "0"+ ? deselectedLine+ : options.find((opt) => opt.quantity.toString() === value);++ if (selectedOption) {+ setSelectedLines((prev) => ({+ ...prev,+ [line.id!]: {+ quantity: selectedOption.quantity,+ netUnitPrice: selectedOption.netUnitPrice ?? 0,+ convertedNetUnitPrice:+ selectedOption.convertedNetUnitPrice ?? 0,+ addOn:+ additionalChargesByQuantity[selectedOption.quantity] || 0,+ convertedAddOn:+ convertedAdditionalChargesByQuantity[+ selectedOption.quantity+ ] || 0,+ leadTime: selectedOption.leadTime,+ shippingCost: selectedOption.shippingCost ?? 0,+ convertedShippingCost:+ selectedOption.convertedShippingCost ?? 0,+ taxPercent: line.taxPercent ?? 0,+ },+ }));+ setSelectedValue(value);+ }+ }}+ >+ <Table>+ <Thead>+ <Tr>+ <Th />+ <Th>Quantity</Th>+ <Th>Unit Price</Th>+ <Th>Add-Ons</Th>+ <Th>Lead Time</Th>+ <Th>Subtotal</Th>+ </Tr>+ </Thead>+ <Tbody>+ {!Array.isArray(options) || options.length === 0 ? (+ <Tr>+ <Td colSpan={6} className="text-center py-8">+ No pricing options found+ </Td>+ </Tr>+ ) : (+ options.map(+ (option, index) =>+ (line?.quantity?.includes(option.quantity) ||+ option.quantity === 0) && (+ <Tr key={index}>+ <Td>+ <RadioGroupItem+ value={option.quantity.toString()}+ id={`${line.id}:${option.quantity.toString()}`}+ />+ <label+ htmlFor={`${line.id}:${option.quantity.toString()}`}+ className="sr-only"+ >+ {option.quantity}+ </label>+ </Td>+ <Td>{option.quantity}</Td>+ <Td>+ {formatter.format(option.convertedNetUnitPrice ?? 0)}+ </Td>+ <Td>+ {formatter.format(+ convertedAdditionalChargesByQuantity[+ option.quantity+ ] + (option.convertedShippingCost ?? 0)+ )}+ </Td>+ <Td>+ {new Intl.NumberFormat(locale, {+ style: "unit",+ unit: "day",+ }).format(option.leadTime)}+ </Td>+ <Td>+ {formatter.format(+ (option.convertedNetUnitPrice ?? 0) *+ option.quantity ++ convertedAdditionalChargesByQuantity[+ option.quantity+ ] ++ (option.convertedShippingCost ?? 0)+ )}+ </Td>+ </Tr>+ )+ )+ )}+ </Tbody>+ </Table>+ </RadioGroup>++ {selectedLine.quantity !== 0 && (+ <div className="w-full">+ <Table>+ <Tbody>+ <Tr key="extended-price" className="border-b border-border">+ <Td>Extended Price</Td>+ <Td className="text-right">+ <MotionNumber+ value={+ (selectedLine.convertedNetUnitPrice ?? 0) *+ selectedLine.quantity+ }+ format={{ style: "currency", currency: quoteCurrency }}+ locales={locale}+ />+ </Td>+ </Tr>++ {additionalCharges.length > 0 &&+ additionalCharges.map((charge) => (+ <Tr+ key={charge.name}+ className={+ additionalCharges[additionalCharges.length - 1] === charge+ ? "border-b border-border"+ : ""+ }+ >+ <Td>{charge.name}</Td>+ <Td className="text-right">+ <MotionNumber+ value={charge.amount}+ format={{ style: "currency", currency: quoteCurrency }}+ locales={locale}+ />+ </Td>+ </Tr>+ ))}++ <Tr key="subtotal">+ <Td>Subtotal</Td>+ <Td className="text-right">+ <MotionNumber+ value={+ (selectedLine.convertedNetUnitPrice ?? 0) *+ selectedLine.quantity ++ selectedLine.convertedAddOn ++ selectedLine.convertedShippingCost+ }+ format={{+ style: "currency",+ currency: quoteCurrency,+ }}+ locales={locale}+ />+ </Td>+ </Tr>++ <Tr key="tax" className="border-b border-border">+ <Td>+ Tax ({percentFormatter.format(selectedLine.taxPercent)})+ </Td>+ <Td className="text-right">+ <MotionNumber+ value={+ ((selectedLine.convertedNetUnitPrice ?? 0) *+ selectedLine.quantity ++ selectedLine.convertedAddOn ++ selectedLine.convertedShippingCost) *+ selectedLine.taxPercent+ }+ format={{+ style: "currency",+ currency: quoteCurrency,+ }}+ locales={locale}+ />+ </Td>+ </Tr>++ <Tr key="total" className="font-bold">+ <Td>Total</Td>+ <Td className="text-right">+ <MotionNumber+ value={+ ((selectedLine.convertedNetUnitPrice ?? 0) *+ selectedLine.quantity ++ selectedLine.convertedAddOn ++ selectedLine.convertedShippingCost) *+ (1 + selectedLine.taxPercent)+ }+ format={{+ style: "currency",+ currency: quoteCurrency,+ }}+ locales={locale}+ />+ </Td>+ </Tr>+ </Tbody>+ </Table>+ </div>+ )}+ </VStack>+ );+};++const QuoteSummary = () => {+ const { quoteId } = useParams();+ if (!quoteId) throw new Error("Could not find quote id");+ const routeData = useRouteData<{+ quote: Quotation;+ lines: QuotationLine[];+ prices: QuotationPrice[];+ shipment: QuotationShipment;+ salesOrderLines: SalesOrderLine[];+ }>(path.to.quote(quoteId));++ console.log({ routeData });++ const { locale } = useLocale();+ const formatter = useMemo(+ () =>+ new Intl.NumberFormat(locale, {+ style: "currency",+ currency: routeData?.quote.currencyCode ?? "USD",+ }),+ [locale, routeData?.quote.currencyCode]+ );++ const [selectedLines, setSelectedLines] = useState<+ Record<string, SelectedLine>+ >(() => {+ return (+ routeData?.lines?.reduce<Record<string, SelectedLine>>((acc, line) => {+ const salesOrderLine = routeData?.salesOrderLines?.find(+ (salesOrderLine) => salesOrderLine.id === line.id+ );++ if (+ Array.isArray(routeData?.salesOrderLines) &&+ routeData?.salesOrderLines.length > 0 &&+ !salesOrderLine+ ) {+ acc[line.id!] = deselectedLine;+ return acc;+ }++ const price = salesOrderLine+ ? routeData?.prices?.find(+ (price) =>+ price.quoteLineId === salesOrderLine.id &&+ price.quantity === salesOrderLine.saleQuantity+ )+ : routeData?.prices?.find((price) => price.quoteLineId === line.id);+ if (!line.id) {+ return acc;+ }++ if (!price) {+ acc[line.id] = deselectedLine;+ return acc;+ }++ const additionalChargesByQuantity =+ line.quantity?.reduce((acc, quantity) => {+ const charges = Object.values(line.additionalCharges ?? {}).reduce(+ (chargeAcc, charge) => {+ const amount = charge.amounts?.[quantity];+ return chargeAcc + amount;+ },+ 0+ );+ acc[quantity] = charges;+ return acc;+ }, {} as Record<number, number>) ?? {};++ const convertedAdditionalChargesByQuantity =+ Object.entries(additionalChargesByQuantity).reduce<+ Record<number, number>+ >((acc, [quantity, amount]) => {+ acc[Number(quantity)] =+ amount * (routeData?.quote.exchangeRate ?? 1);+ return acc;+ }, {} as Record<number, number>) ?? {};++ acc[line.id] = {+ quantity: price.quantity ?? 0,+ netUnitPrice: price.netUnitPrice ?? 0,+ convertedNetUnitPrice: price.convertedNetUnitPrice ?? 0,+ addOn: additionalChargesByQuantity[price.quantity] || 0,+ convertedAddOn:+ convertedAdditionalChargesByQuantity[price.quantity] || 0,+ leadTime: price.leadTime,+ shippingCost: price.shippingCost ?? 0,+ convertedShippingCost: price.convertedShippingCost ?? 0,+ taxPercent: line.taxPercent ?? 0,+ };+ return acc;+ }, {}) ?? {}+ );+ });++ const subtotal = Object.values(selectedLines).reduce((acc, line) => {+ return (+ acc ++ line.convertedNetUnitPrice * line.quantity ++ line.convertedAddOn ++ line.convertedShippingCost+ );+ }, 0);+ const tax = Object.values(selectedLines).reduce((acc, line) => {+ return (+ acc ++ (line.convertedNetUnitPrice * line.quantity ++ line.convertedAddOn ++ line.convertedShippingCost) *+ (line.taxPercent ?? 0)+ );+ }, 0);+ const convertedShippingCost =+ (routeData?.quote.exchangeRate ?? 1) *+ (routeData?.shipment?.shippingCost ?? 0);+ const total = subtotal + tax + convertedShippingCost;++ return (+ <Card>+ <CardHeader>+ <HStack className="justify-between items-center">+ <div className="flex flex-col gap-1">+ <CardTitle>Summary</CardTitle>+ {routeData?.quote?.expirationDate && (+ <CardDescription>+ Expires {formatDate(routeData?.quote.expirationDate)}+ </CardDescription>+ )}+ </div>+ <CustomerAvatar customerId={routeData?.quote.customerId ?? null} />+ </HStack>+ </CardHeader>+ <CardContent>+ <LineItems+ currencyCode={routeData?.quote.currencyCode ?? "USD"}+ locale={locale}+ formatter={formatter}+ selectedLines={selectedLines}+ setSelectedLines={setSelectedLines}+ />++ <VStack spacing={2} className="mt-8">+ <HStack className="justify-between text-base text-muted-foreground w-full">+ <span>Subtotal:</span>+ <MotionNumber+ value={subtotal}+ format={{+ style: "currency",+ currency: routeData?.quote?.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ <HStack className="justify-between text-base text-muted-foreground w-full">+ <span>Tax:</span>+ <MotionNumber+ value={tax}+ format={{+ style: "currency",+ currency: routeData?.quote?.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ {convertedShippingCost > 0 && (+ <HStack className="justify-between text-base text-muted-foreground w-full">+ <span>Shipping:</span>+ <MotionNumber+ value={convertedShippingCost}+ format={{+ style: "currency",+ currency: routeData?.quote.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ )}+ <HStack className="justify-between text-xl font-bold w-full">+ <span>Total:</span>+ <MotionNumber+ value={total}+ format={{+ style: "currency",+ currency: routeData?.quote.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ </VStack>+ </CardContent>+ </Card>+ );+};++export default QuoteSummary;diff --git a/apps/carbon/app/modules/sales/ui/Quotes/index.ts b/apps/carbon/app/modules/sales/ui/Quotes/index.tsindex 31a1476b73..d7f09c5d41 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/index.ts+++ b/apps/carbon/app/modules/sales/ui/Quotes/index.ts@@ -13,6 +13,7 @@ import QuoteMaterialForm from "./QuoteMaterialForm";import QuotePaymentForm from "./QuotePaymentForm";import QuoteProperties from "./QuoteProperties";import QuoteShipmentForm from "./QuoteShipmentForm";+import QuoteSummary from "./QuoteSummary";import QuotesTable from "./QuotesTable";import { useLineCosts } from "./useLineCosts";@@ -33,5 +34,6 @@ export {QuoteProperties,QuoteShipmentForm,QuotesTable,+ QuoteSummary,useLineCosts,};diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsxnew file mode 100644index 0000000000..0e54380143--- /dev/null+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx@@ -0,0 +1,374 @@+import {+ Card,+ CardContent,+ CardHeader,+ CardTitle,+ Heading,+ HStack,+ IconButton,+ Table,+ Tbody,+ Td,+ Tr,+ VStack,+} from "@carbon/react";+import { useLocale } from "@react-aria/i18n";+import { Link, useParams } from "@remix-run/react";+import { motion } from "framer-motion";+import MotionNumber from "motion-number";+import { useMemo, useState } from "react";+import { LuChevronDown, LuExternalLink, LuImage } from "react-icons/lu";+import { CustomerAvatar } from "~/components";+import { usePercentFormatter, useRouteData } from "~/hooks";+import { getPrivateUrl, path } from "~/utils/path";+import type { SalesOrderLine } from "../../types";++const LineItems = ({+ currencyCode,+ formatter,+ locale,+ lines,+}: {+ currencyCode: string;+ formatter: Intl.NumberFormat;+ locale: string;+ lines: SalesOrderLine[];+}) => {+ const { orderId } = useParams();+ if (!orderId) throw new Error("Could not find orderId");++ const percentFormatter = usePercentFormatter();+ const [openItems, setOpenItems] = useState<string[]>([]);++ const toggleOpen = (id: string) => {+ setOpenItems((prev) =>+ prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]+ );+ };++ return (+ <VStack spacing={8} className="w-full overflow-hidden">+ {lines.map((line) => {+ if (!line.id) return null;+ return (+ <motion.div+ key={line.id}+ initial={{ opacity: 0, y: 50 }}+ animate={{ opacity: 1, y: 0 }}+ transition={{ duration: 0.5 }}+ className="border-b border-input py-6 w-full"+ >+ <HStack spacing={4} className="items-start">+ {line.thumbnailPath ? (+ <img+ alt={line.itemReadableId!}+ className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent"+ src={getPrivateUrl(line.thumbnailPath)}+ />+ ) : (+ <div className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2">+ <LuImage className="w-16 h-16 text-muted-foreground" />+ </div>+ )}++ <VStack spacing={0} className="w-full">+ <div+ className="flex flex-col cursor-pointer w-full"+ onClick={() => toggleOpen(line.id!)}+ >+ <div className="flex items-center gap-x-4 justify-between flex-grow min-w-0">+ <HStack spacing={0} className="min-w-0 flex-shrink ">+ <Heading className="truncate">+ {line.itemReadableId}+ </Heading>++ <Link+ to={path.to.salesOrderLine(orderId, line.id!)}+ className="text-muted-foreground flex-shrink-0"+ >+ <IconButton+ aria-label="View Line Item"+ icon={<LuExternalLink />}+ variant="ghost"+ />+ </Link>+ </HStack>+ <HStack spacing={4} className="flex-shrink-0 ml-4">+ <MotionNumber+ className="font-bold text-xl whitespace-nowrap"+ value={+ ((line?.convertedUnitPrice ?? 0) *+ (line?.saleQuantity ?? 0) ++ (line?.convertedAddOnCost ?? 0) ++ (line?.convertedShippingCost ?? 0)) *+ (1 + (line?.taxPercent ?? 0))+ }+ format={{+ style: "currency",+ currency: currencyCode,+ }}+ locales={locale}+ />+ <motion.div+ animate={{+ rotate: openItems.includes(line.id) ? 180 : 0,+ }}+ transition={{ duration: 0.3 }}+ >+ <LuChevronDown size={24} />+ </motion.div>+ </HStack>+ </div>+ <span className="text-muted-foreground text-base truncate">+ {line.description}+ </span>+ </div>+ </VStack>+ </HStack>++ <motion.div+ initial="collapsed"+ animate={openItems.includes(line.id) ? "open" : "collapsed"}+ variants={{+ open: { opacity: 1, height: "auto", marginTop: 16 },+ collapsed: { opacity: 0, height: 0, marginTop: 0 },+ }}+ transition={{ duration: 0.3 }}+ className="w-full overflow-hidden"+ >+ <div className="w-full">+ <Table>+ <Tbody>+ <Tr>+ <Td>Quantity</Td>+ <Td className="text-right">{line.saleQuantity}</Td>+ </Tr>+ <Tr>+ <Td>Unit Price</Td>+ <Td className="text-right">+ <MotionNumber+ value={line.convertedUnitPrice ?? 0}+ format={{ style: "currency", currency: currencyCode }}+ locales={locale}+ />+ </Td>+ </Tr>+ <Tr className="border-b border-border">+ <Td>Extended Price</Td>+ <Td className="text-right">+ <MotionNumber+ value={+ (line.convertedUnitPrice ?? 0) *+ (line.saleQuantity ?? 0)+ }+ format={{ style: "currency", currency: currencyCode }}+ locales={locale}+ />+ </Td>+ </Tr>++ {line.addOnCost && (+ <Tr>+ <Td>Additional Charges</Td>+ <Td className="text-right">+ <MotionNumber+ value={line.addOnCost}+ format={{+ style: "currency",+ currency: currencyCode,+ }}+ locales={locale}+ />+ </Td>+ </Tr>+ )}++ <Tr key="subtotal">+ <Td>Subtotal</Td>+ <Td className="text-right">+ <MotionNumber+ value={+ (line.convertedUnitPrice ?? 0) *+ (line.saleQuantity ?? 0) ++ (line.convertedAddOnCost ?? 0) ++ (line.convertedShippingCost ?? 0)+ }+ format={{+ style: "currency",+ currency: currencyCode,+ }}+ locales={locale}+ />+ </Td>+ </Tr>++ <Tr key="tax" className="border-b border-border">+ <Td>+ Tax ({percentFormatter.format(line.taxPercent ?? 0)})+ </Td>+ <Td className="text-right">+ <MotionNumber+ value={+ ((line.convertedUnitPrice ?? 0) *+ (line.saleQuantity ?? 0) ++ (line.convertedAddOnCost ?? 0) ++ (line.convertedShippingCost ?? 0)) *+ (line.taxPercent ?? 0)+ }+ format={{+ style: "currency",+ currency: currencyCode,+ }}+ locales={locale}+ />+ </Td>+ </Tr>++ <Tr key="total" className="font-bold">+ <Td>Total</Td>+ <Td className="text-right">+ <MotionNumber+ value={+ ((line.convertedUnitPrice ?? 0) *+ (line.saleQuantity ?? 0) ++ (line.convertedAddOnCost ?? 0) ++ (line.convertedShippingCost ?? 0)) *+ (1 + (line.taxPercent ?? 0))+ }+ format={{+ style: "currency",+ currency: currencyCode,+ }}+ locales={locale}+ />+ </Td>+ </Tr>+ </Tbody>+ </Table>+ </div>+ </motion.div>+ </motion.div>+ );+ })}+ </VStack>+ );+};++const SalesOrderSummary = () => {+ const { orderId } = useParams();+ if (!orderId) throw new Error("Could not find orderId");++ const routeData = useRouteData<{+ salesOrder: any;+ lines: any[];+ customer: any;+ }>(path.to.salesOrder(orderId));++ const { locale } = useLocale();+ const formatter = useMemo(+ () =>+ new Intl.NumberFormat(locale, {+ style: "currency",+ currency: routeData?.salesOrder?.currencyCode ?? "USD",+ }),+ [locale, routeData?.salesOrder?.currencyCode]+ );++ // Calculate totals+ const subtotal =+ routeData?.lines?.reduce((acc, line) => {+ const lineTotal =+ (line.convertedUnitPrice ?? 0) * (line.saleQuantity ?? 0);+ const addOns =+ (line.convertedAddOnCost ?? 0) + (line.convertedShippingCost ?? 0);+ return acc + lineTotal + addOns;+ }, 0) ?? 0;++ const tax =+ routeData?.lines?.reduce((acc, line) => {+ const lineTotal =+ (line.convertedUnitPrice ?? 0) * (line.saleQuantity ?? 0);+ const addOns =+ (line.convertedAddOnCost ?? 0) + (line.convertedShippingCost ?? 0);+ return acc + (lineTotal + addOns) * (line.taxPercent ?? 0);+ }, 0) ?? 0;++ const shippingCost =+ (routeData?.salesOrder?.shippingCost ?? 0) *+ (routeData?.salesOrder?.exchangeRate ?? 1);+ const total = subtotal + tax + shippingCost;++ return (+ <Card>+ <CardHeader>+ <HStack className="justify-between items-center">+ <div className="flex flex-col gap-1">+ <CardTitle>Summary</CardTitle>+ </div>+ <CustomerAvatar+ customerId={routeData?.salesOrder?.customerId ?? null}+ />+ </HStack>+ </CardHeader>+ <CardContent>+ <LineItems+ currencyCode={routeData?.salesOrder?.currencyCode ?? "USD"}+ locale={locale}+ formatter={formatter}+ lines={routeData?.lines ?? []}+ />++ <VStack spacing={2} className="mt-8">+ <HStack className="justify-between text-base text-muted-foreground w-full">+ <span>Subtotal:</span>+ <MotionNumber+ value={subtotal}+ format={{+ style: "currency",+ currency: routeData?.salesOrder?.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ <HStack className="justify-between text-base text-muted-foreground w-full">+ <span>Tax:</span>+ <MotionNumber+ value={tax}+ format={{+ style: "currency",+ currency: routeData?.salesOrder?.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ {shippingCost > 0 && (+ <HStack className="justify-between text-base text-muted-foreground w-full">+ <span>Shipping:</span>+ <MotionNumber+ value={shippingCost}+ format={{+ style: "currency",+ currency: routeData?.salesOrder?.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ )}+ <HStack className="justify-between text-xl font-bold w-full">+ <span>Total:</span>+ <MotionNumber+ value={total}+ format={{+ style: "currency",+ currency: routeData?.salesOrder?.currencyCode ?? "USD",+ }}+ locales={locale}+ />+ </HStack>+ </VStack>+ </CardContent>+ </Card>+ );+};++export default SalesOrderSummary;diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/index.ts b/apps/carbon/app/modules/sales/ui/SalesOrder/index.tsindex 9b0bf16797..f10e11f6ca 100644--- a/apps/carbon/app/modules/sales/ui/SalesOrder/index.ts+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/index.ts@@ -7,6 +7,7 @@ import SalesOrderPaymentForm from "./SalesOrderPaymentForm";import SalesOrderProperties from "./SalesOrderProperties";import SalesOrderShipmentForm from "./SalesOrderShipmentForm";import SalesOrdersTable from "./SalesOrdersTable";+import SalesOrderSummary from "./SalesOrderSummary";import SalesStatus from "./SalesStatus";import { useSalesOrderTotals } from "./useSalesOrderTotals";@@ -20,6 +21,7 @@ export {SalesOrderProperties,SalesOrderShipmentForm,SalesOrdersTable,+ SalesOrderSummary,SalesStatus,useSalesOrderTotals,};diff --git a/apps/carbon/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx b/apps/carbon/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsxindex 5601ecd9ea..b4f52ad0f9 100644--- a/apps/carbon/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx+++ b/apps/carbon/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx@@ -142,7 +142,7 @@ export default function JobMakeMethodRoute() {/><Suspensefallback={- <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">+ <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center min-h-[200px]"><Spinner className="h-10 w-10" /></div>}diff --git a/apps/carbon/app/routes/x+/job+/$jobId.method.$methodId.tsx b/apps/carbon/app/routes/x+/job+/$jobId.method.$methodId.tsxindex 71f1bd2298..1146be8993 100644--- a/apps/carbon/app/routes/x+/job+/$jobId.method.$methodId.tsx+++ b/apps/carbon/app/routes/x+/job+/$jobId.method.$methodId.tsx@@ -114,7 +114,7 @@ export default function JobMakeMethodRoute() {<Suspensefallback={- <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">+ <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center min-h-[200px]"><Spinner className="h-10 w-10" /></div>}diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsxindex c32420954b..3f9a17bea4 100644--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.details.tsx@@ -164,7 +164,7 @@ export default function QuoteLine() {<OpportunityLineNotesid={line.id}table="quoteLine"- title={quoteData?.quote.quoteId ?? ""}+ title="Notes"subTitle={line.itemReadableId ?? ""}notes={line.notes as JSONContent}/>diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsxindex 1312da8d7b..b649a1b7db 100644--- a/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx@@ -21,6 +21,7 @@ import {OpportunityState,QuotePaymentForm,QuoteShipmentForm,+ QuoteSummary,quoteValidator,upsertQuote,} from "~/modules/sales";@@ -121,10 +122,11 @@ export default function QuoteDetailsRoute() {key={`state-${initialValues.id}`}opportunity={quoteData?.opportunity!}/>+ <QuoteSummary key={quoteId} /><OpportunityNoteskey={`notes-${initialValues.id}`}id={quoteData.quote.id}- title={quoteData.quote.quoteId ?? ""}+ title="Notes"table="quote"internalNotes={quoteData.quote.internalNotes as JSONContent}externalNotes={quoteData.quote.externalNotes as JSONContent}diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.tsxindex bbc829a4df..af6e7c39a2 100644--- a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx@@ -3,12 +3,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { ClientOnly, VStack } from "@carbon/react";import { Outlet, useLoaderData, useParams } from "@remix-run/react";+import type { PostgrestResponse } from "@supabase/supabase-js";import type { LoaderFunctionArgs } from "@vercel/remix";import { defer, redirect } from "@vercel/remix";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import { getCurrencyByCode } from "~/modules/accounting";+import type { SalesOrderLine } from "~/modules/sales";import {- getCustomer,getOpportunityByQuote,getOpportunityDocuments,getQuote,@@ -17,6 +18,7 @@ import {getQuoteMethodTrees,getQuotePayment,getQuoteShipment,+ getSalesOrderLines,QuoteExplorer,QuoteHeader,QuoteProperties,@@ -88,9 +90,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}}- const customer = quote.data?.customerId- ? await getCustomer(serviceRole, quote.data.customerId)- : null;+ let salesOrderLines: PostgrestResponse<SalesOrderLine> | null = null;+ if (opportunity.data?.salesOrderId) {+ salesOrderLines = await getSalesOrderLines(+ serviceRole,+ opportunity.data.salesOrderId+ );+ }return defer({quote: quote.data,@@ -102,7 +108,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {payment: payment.data,opportunity: opportunity.data,exchangeRate,- customer: customer?.data ?? null,+ salesOrderLines: salesOrderLines?.data ?? null,});}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 c61edbee39..25f9c1e905 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@@ -204,7 +204,7 @@ export default function EditSalesOrderLineRoute() {<OpportunityLineNotesid={line.id}table="salesOrderLine"- title={orderData.salesOrder.salesOrderId ?? ""}+ title="Notes"subTitle={line.itemReadableId ?? ""}notes={line.notes as JSONContent}/>diff --git a/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx b/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsxindex e8a4a3892c..d9ca7885d8 100644--- a/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx+++ b/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx@@ -17,6 +17,7 @@ import {OpportunityState,SalesOrderPaymentForm,SalesOrderShipmentForm,+ SalesOrderSummary,salesOrderValidator,upsertSalesOrder,} from "~/modules/sales";@@ -174,12 +175,12 @@ export default function SalesOrderRoute() {return (<><OpportunityState opportunity={orderData.opportunity} />-+ <SalesOrderSummary /><OpportunityNoteskey={`notes-${orderId}`}id={orderData.salesOrder.id}table="salesOrder"- title={orderData.salesOrder.salesOrderId ?? ""}+ title="Notes"internalNotes={orderData.salesOrder.internalNotes as JSONContent}externalNotes={orderData.salesOrder.externalNotes as JSONContent}/>diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsxindex 45b59bedb6..89b86f10ac 100644--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx@@ -9,8 +9,7 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { defer, redirect } from "@vercel/remix";import { Fragment, Suspense } from "react";import { CadModel } from "~/components";-import { usePermissions, useRouteData } from "~/hooks";-import type { SalesRFQ } from "~/modules/sales";+import { usePermissions } from "~/hooks";import {getOpportunityLineDocuments,getSalesRFQLine,@@ -98,10 +97,6 @@ export default function SalesRFQLine() {if (!rfqId) throw new Error("Could not find rfqId");if (!lineId) throw new Error("Could not find lineId");- const rfqData = useRouteData<{- rfqSummary: SalesRFQ;- }>(path.to.salesRfq(rfqId));-const initialValues = {...line,id: line.id ?? undefined,@@ -122,7 +117,7 @@ export default function SalesRFQLine() {<OpportunityLineNotesid={line.id}table="salesRfqLine"- title={rfqData?.rfqSummary.rfqId ?? ""}+ title="Notes"subTitle={line.customerPartId ?? ""}notes={line.internalNotes as JSONContent}/>diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsxindex 126c932511..ddd77d47b7 100644--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx@@ -83,7 +83,7 @@ export default function SalesRFQDetailsRoute() {key={`notes-${rfqId}`}id={rfqData.rfqSummary.id}table="salesRfq"- title={rfqData.rfqSummary.rfqId ?? ""}+ title="Notes"internalNotes={rfqData.rfqSummary.internalNotes as JSONContent}externalNotes={rfqData.rfqSummary.externalNotes as JSONContent}/>