Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

3.7 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import { formatDate, isEoriCountry, pluralize } from "@carbon/utils";
import { getLocalTimeZone, today } from "@internationalized/date";
import { Text, View } from "@react-pdf/renderer";
import { AddressBlock } from "../../components";
import { useTw } from "../tw";
import type { QuoteData } from "./types";

export function PartiesBlock({ data }: { data: QuoteData }) {
  const tw = useTw();
  const {
    quote,
    quoteCustomerDetails,
    payment,
    paymentTerms,
    shipment,
    maxLeadTime,
    locale
  } = data;
  const {
    customerName,
    customerAddressLine1,
    customerAddressLine2,
    customerCity,
    customerStateProvince,
    customerPostalCode,
    customerCountryCode,
    customerCountryName,
    customerTaxId,
    customerVatNumber,
    customerEori,
    contactName,
    contactEmail
  } = quoteCustomerDetails;

  const paymentTerm = paymentTerms?.find(
    (pt) => pt.id === payment?.paymentTermId
  );

  return (
    <View style={tw("border border-gray-200 mb-4")}>
      <View style={tw("flex flex-row")}>
        {/* LEFT — To (customer) */}
        <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")}>
            To
          </Text>
          <View style={tw("text-[9px] text-gray-800")}>
            <AddressBlock
              name={customerName}
              addressLine1={customerAddressLine1}
              addressLine2={customerAddressLine2}
              city={customerCity}
              stateProvince={customerStateProvince}
              postalCode={customerPostalCode}
              country={customerCountryName ?? customerCountryCode}
            />
            {customerTaxId && !isEoriCountry(customerCountryCode) ? (
              <Text>Tax ID: {customerTaxId}</Text>
            ) : null}
            {customerVatNumber ? <Text>VAT: {customerVatNumber}</Text> : null}
            {customerEori ? <Text>EORI: {customerEori}</Text> : null}
            {contactName ? <Text>Contact: {contactName}</Text> : null}
            {contactEmail ? <Text>Email: {contactEmail}</Text> : null}
          </View>
        </View>

        {/* RIGHT — Quote Details */}
        <View style={tw("w-1/2 p-3")}>
          <Text style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}>
            Quote Details
          </Text>
          <View style={tw("text-[9px] text-gray-800")}>
            <Text>
              Date:{" "}
              {formatDate(
                today(getLocalTimeZone()).toString(),
                undefined,
                locale
              )}
            </Text>
            {quote.expirationDate ? (
              <Text style={tw("font-bold")}>
                Expires: {formatDate(quote.expirationDate, undefined, locale)}
              </Text>
            ) : null}
            {quote.customerReference ? (
              <Text>Reference: {quote.customerReference}</Text>
            ) : null}
            {maxLeadTime > 0 ? (
              <Text>
                Max Lead Time: {maxLeadTime} {pluralize(maxLeadTime, "day")}
              </Text>
            ) : null}
            {paymentTerm ? (
              <Text>Payment Terms: {paymentTerm.name}</Text>
            ) : null}
            {shipment?.incoterm ? (
              <Text>
                Incoterm: {shipment.incoterm}
                {shipment.incotermLocation
                  ? ` — ${shipment.incotermLocation}`
                  : ""}
              </Text>
            ) : null}
          </View>
        </View>
      </View>
    </View>
  );
}