import isEmpty from 'lodash/isEmpty'; import { Box } from '../lib/layout/Box'; import { Text } from '../lib/text/Text'; import { Stack } from '../lib/layout/Stack'; import { Group } from '../lib/layout/Group'; import { DefaultPdfTemplateTerms, DefaultPdfTemplateItemDescription, DefaultPdfTemplateStatement, DefaultPdfTemplateItemName, DefaultPdfTemplateAddressBilledTo, DefaultPdfTemplateAddressBilledFrom, } from './_constants'; import { PaperTemplate, PaperTemplateProps, PaperTemplateTotalBorder, } from './PaperTemplate'; import { theme } from '../constants'; export interface EstimatePaperTemplateProps extends PaperTemplateProps { // # Company showCompanyLogo?: boolean; companyLogoUri?: string; // # Estimate number estimateNumebr?: string; estimateNumberLabel?: string; showEstimateNumber?: boolean; // # Expiration date expirationDate?: string; showExpirationDate?: boolean; expirationDateLabel?: string; // # Estimate date estimateDateLabel?: string; showEstimateDate?: boolean; estimateDate?: string; // # Customer name companyName?: string; // Address showCustomerAddress?: boolean; customerAddress?: string; showCompanyAddress?: boolean; companyAddress?: string; billedToLabel?: string; // Total total?: string; showTotal?: boolean; totalLabel?: string; // # Discount discount?: string; showDiscount?: boolean; discountLabel?: string; // # Adjustment adjustment?: string; showAdjustment?: boolean; adjustmentLabel?: string; // # Subtotal subtotal?: string; showSubtotal?: boolean; subtotalLabel?: string; // # Statements showCustomerNote?: boolean; customerNote?: string; customerNoteLabel?: string; // # Terms & conditions showTermsConditions?: boolean; termsConditions?: string; termsConditionsLabel?: string; lines?: Array<{ item: string; description: string; rate: string; quantity: string; total: string; }>; // Lines lineItemLabel?: string; lineQuantityLabel?: string; lineRateLabel?: string; lineTotalLabel?: string; } export function EstimatePaperTemplate({ primaryColor, secondaryColor, // # Company logo showCompanyLogo = true, companyLogoUri = '', companyName, // # Company address companyAddress = DefaultPdfTemplateAddressBilledFrom, showCompanyAddress = true, // # Customer address customerAddress = DefaultPdfTemplateAddressBilledTo, showCustomerAddress = true, billedToLabel = 'Billed To', // # Total total = '$1000.00', totalLabel = 'Total', showTotal = true, // # Discount discount = '0.00', discountLabel = 'Discount', showDiscount = true, // # Subtotal subtotal = '1000/00', subtotalLabel = 'Subtotal', showSubtotal = true, // # Adjustment adjustment = '', showAdjustment = true, adjustmentLabel = 'Adjustment', // # Customer Note showCustomerNote = true, customerNote = DefaultPdfTemplateStatement, customerNoteLabel = 'Customer Note', // # Terms & Conditions showTermsConditions = true, termsConditions = DefaultPdfTemplateTerms, termsConditionsLabel = 'Terms & Conditions', lines = [ { item: DefaultPdfTemplateItemName, description: DefaultPdfTemplateItemDescription, rate: '1', quantity: '1000', total: '$1000.00', }, ], // Estimate number showEstimateNumber = true, estimateNumberLabel = 'Estimate Number', estimateNumebr = '346D3D40-0001', // Estimate date estimateDate = 'September 3, 2024', showEstimateDate = true, estimateDateLabel = 'Estimate Date', // Expiration date expirationDateLabel = 'Expiration Date', showExpirationDate = true, expirationDate = 'September 3, 2024', // Entries lineItemLabel = 'Item', lineQuantityLabel = 'Qty', lineRateLabel = 'Rate', lineTotalLabel = 'Total', }: EstimatePaperTemplateProps) { return ( {showEstimateNumber && ( {estimateNumebr} )} {showEstimateDate && ( {estimateDate} )} {showExpirationDate && ( {expirationDate} )} {companyLogoUri && showCompanyLogo && ( )} {showCompanyAddress && ( )} {showCustomerAddress && ( {billedToLabel} )} ( {data.item} {data.description} ), thStyle: { width: '60%' }, }, { label: lineQuantityLabel, accessor: 'quantity' }, { label: lineRateLabel, accessor: 'rate', align: 'right' }, { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines} /> {showSubtotal && ( )} {showDiscount && !isEmpty(discount) && ( )} {showAdjustment && !isEmpty(adjustment) && ( )} {showTotal && ( )} {showCustomerNote && !isEmpty(customerNote) && ( {customerNote} )} {showTermsConditions && !isEmpty(termsConditions) && ( {termsConditions} )} ); }