import { UNIT_LABELS } from "../lib/types"; import { computeLineAmount } from "../lib/invoice"; import { formatAmount, formatDate } from "../lib/format"; import type { InvoicePdfProps } from "../pdf/InvoiceDocument"; const money = (n: number) => `₹${formatAmount(n)}`; /** On-screen preview that mirrors the exported PDF layout. */ export function InvoicePreview(props: InvoicePdfProps) { const { vendor, bank, logoDataUri, signatureDataUri, number, invoiceDate, dueDate, clientName, clientAddress, clientGstin, poNumber, placeOfSupplyStateCode, items, subtotal, discount, taxType, taxRate, cgst, sgst, igst, total, amountInWords, notes, } = props; const isTaxInvoice = taxType !== "none"; const contact = [vendor.vendorEmail, vendor.vendorPhone].filter(Boolean).join(" · "); return (
{logoDataUri ? : null}

{vendor.vendorName || "Vendor"}

{vendor.vendorAddress}

{contact ?

{contact}

: null} {vendor.vendorPan ?

PAN: {vendor.vendorPan}

: null}

GSTIN: {vendor.vendorGstin || "NA"}

{isTaxInvoice ? "Tax Invoice" : "Invoice"}

Invoice No. {number}
Date {formatDate(invoiceDate)}
{dueDate ? (
Due Date {formatDate(dueDate)}
) : null}

Billed To

{clientName || "—"}
{clientAddress ?
{clientAddress}
: null} {clientGstin ?
GSTIN: {clientGstin}
: null} {placeOfSupplyStateCode ?
Place of Supply: {placeOfSupplyStateCode}
: null}
{poNumber ? (

PO Number

{poNumber}
) : null}
{items.map((item, index) => ( ))}
Description Unit Price Qty Total
{item.description || "—"} {item.mode === "rate" ? `${money(item.rate)} ${UNIT_LABELS[item.unit]}` : "—"} {item.mode === "rate" ? item.quantity : 1} {money(computeLineAmount(item))}
Subtotal {money(subtotal)}
{discount > 0 ? (
Discount - {money(discount)}
) : null} {taxType === "cgst_sgst" ? ( <>
CGST ({(taxRate / 2).toFixed(2)}%) {money(cgst)}
SGST ({(taxRate / 2).toFixed(2)}%) {money(sgst)}
) : null} {taxType === "igst" ? (
IGST ({taxRate.toFixed(2)}%) {money(igst)}
) : null}
Total {money(total)}

Amount in words: {amountInWords}

{notes ? (

Notes

{notes}
) : null}
{bank ? ( <>

Pay To

{bank.accountName || vendor.vendorName}
{bank.bankName}
{bank.accountNo ?
Account No.: {bank.accountNo}
: null} {bank.branch ?
Branch: {bank.branch}
: null} {bank.ifsc ?
IFSC: {bank.ifsc}
: null} ) : null}
{signatureDataUri ? ( <> Signature
{vendor.vendorName}
) : ( <>
{vendor.vendorName}

Computer-generated invoice; no signature is required.

)}
{vendor.vendorName} Generated with Voiced — a Bongbetic product
); }