QuotePDF.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. import { Document, Page, Text, View, Image } from '@react-pdf/renderer'
  2. import { formatCurrency, formatDateForPdf, DEFAULT_DATE_FORMAT } from '@/lib/format'
  3. import { createStyles, gray, getFontBold } from '@/features/vehicles/Components/invoice-pdf/styles'
  4. import type { TemplateConfig } from '@/features/vehicles/Components/invoice-pdf/types'
  5. function fillTemplate(template: string, values: Record<string, string>): string {
  6. return Object.entries(values).reduce(
  7. (str, [key, val]) => str.replace(`{${key}}`, val),
  8. template
  9. )
  10. }
  11. interface QuoteData {
  12. quoteNumber: string | null
  13. title: string
  14. description: string | null
  15. validUntil: Date | null
  16. createdAt: Date
  17. subtotal: number
  18. taxRate: number
  19. taxAmount: number
  20. discountType: string | null
  21. discountValue: number
  22. discountAmount: number
  23. totalAmount: number
  24. notes: string | null
  25. partItems: {
  26. partNumber: string | null
  27. name: string
  28. quantity: number
  29. unitPrice: number
  30. total: number
  31. excluded?: boolean
  32. }[]
  33. laborItems: { description: string; hours: number; rate: number; total: number; excluded?: boolean }[]
  34. customer: {
  35. name: string
  36. email: string | null
  37. phone: string | null
  38. address: string | null
  39. company: string | null
  40. } | null
  41. vehicle: {
  42. make: string
  43. model: string
  44. year: number
  45. vin: string | null
  46. licensePlate: string | null
  47. } | null
  48. }
  49. interface WorkshopInfo {
  50. name: string
  51. address: string
  52. phone: string
  53. email: string
  54. }
  55. interface ImageAttachmentPDF {
  56. fileName: string
  57. dataUri: string
  58. description?: string
  59. }
  60. interface OtherAttachmentPDF {
  61. fileName: string
  62. fileType: string
  63. }
  64. export function QuotePDF({
  65. data,
  66. workshop,
  67. currencyCode = 'USD',
  68. logoDataUri,
  69. torqvoiceLogoDataUri,
  70. dateFormat,
  71. timezone,
  72. template,
  73. portalUrl,
  74. imageAttachments = [],
  75. otherAttachments = [],
  76. pdfAttachmentNames = [],
  77. labels = {},
  78. }: {
  79. data: QuoteData
  80. workshop?: WorkshopInfo
  81. currencyCode?: string
  82. logoDataUri?: string
  83. torqvoiceLogoDataUri?: string
  84. dateFormat?: string
  85. timezone?: string
  86. template?: TemplateConfig
  87. portalUrl?: string
  88. imageAttachments?: ImageAttachmentPDF[]
  89. otherAttachments?: OtherAttachmentPDF[]
  90. pdfAttachmentNames?: string[]
  91. labels?: Record<string, string>
  92. }) {
  93. const primaryColor = template?.primaryColor || '#d97706'
  94. const fontFamily = template?.fontFamily || 'Helvetica'
  95. const headerStyle = template?.headerStyle || 'standard'
  96. const showLogo = template?.showLogo !== false
  97. const showCompanyName = template?.showCompanyName !== false
  98. const styles = createStyles(primaryColor, fontFamily)
  99. const fontBold = getFontBold(fontFamily)
  100. const quoteNum = data.quoteNumber || 'QUOTE'
  101. const df = dateFormat || DEFAULT_DATE_FORMAT
  102. const tz = timezone || undefined
  103. const createdDate = formatDateForPdf(data.createdAt, df, tz)
  104. const validDate = data.validUntil ? formatDateForPdf(data.validUntil, df, tz) : null
  105. const shopName = workshop?.name || 'Torqvoice'
  106. const renderCompactHeader = () => (
  107. <View style={{ marginBottom: 20 }}>
  108. <View
  109. style={{
  110. flexDirection: 'row',
  111. alignItems: 'center',
  112. justifyContent: 'space-between',
  113. paddingBottom: 10,
  114. borderBottomWidth: 1,
  115. borderBottomColor: '#e5e7eb',
  116. }}
  117. >
  118. <View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
  119. {showLogo && logoDataUri && (
  120. <Image
  121. src={logoDataUri}
  122. style={{ maxWidth: 40, maxHeight: 40, borderRadius: 4, objectFit: 'contain' }}
  123. />
  124. )}
  125. {showCompanyName && (
  126. <View>
  127. <Text style={{ fontSize: 16, fontFamily: fontBold, color: primaryColor }}>
  128. {shopName}
  129. </Text>
  130. {workshop?.address && (
  131. <Text style={{ fontSize: 8, color: gray }}>{workshop.address}</Text>
  132. )}
  133. </View>
  134. )}
  135. </View>
  136. <View style={{ alignItems: 'flex-end' }}>
  137. <Text style={{ fontSize: 14, fontFamily: fontBold, color: primaryColor }}>{labels.title || 'QUOTE'}</Text>
  138. <Text style={{ fontSize: 9, color: gray, marginTop: 2 }}>{quoteNum}</Text>
  139. <Text style={{ fontSize: 9, color: gray }}>{createdDate}</Text>
  140. {validDate && <Text style={{ fontSize: 9, color: gray }}>{labels.validUntil ? fillTemplate(labels.validUntil, { date: validDate }) : `Valid until: ${validDate}`}</Text>}
  141. </View>
  142. </View>
  143. <View
  144. style={{
  145. flexDirection: 'row',
  146. justifyContent: 'space-between',
  147. marginTop: 6,
  148. paddingHorizontal: 2,
  149. }}
  150. >
  151. <View style={{ flexDirection: 'row', gap: 12 }}>
  152. {workshop?.phone && (
  153. <Text style={{ fontSize: 8, color: gray }}>{labels.tel ? fillTemplate(labels.tel, { phone: workshop.phone }) : `Tel: ${workshop.phone}`}</Text>
  154. )}
  155. {workshop?.email && (
  156. <Text style={{ fontSize: 8, color: gray }}>{workshop.email}</Text>
  157. )}
  158. </View>
  159. {torqvoiceLogoDataUri && (
  160. <View style={{ flexDirection: 'row', alignItems: 'center', gap: 3 }}>
  161. <Image src={torqvoiceLogoDataUri} style={{ width: 12, height: 12 }} />
  162. <Text style={{ fontSize: 7, fontFamily: fontBold, color: gray }}>Torqvoice</Text>
  163. </View>
  164. )}
  165. </View>
  166. </View>
  167. )
  168. const renderModernHeader = () => (
  169. <View style={{ marginBottom: 24 }}>
  170. <View
  171. style={{
  172. backgroundColor: primaryColor,
  173. padding: 20,
  174. borderRadius: 4,
  175. marginHorizontal: -10,
  176. }}
  177. >
  178. <View
  179. style={{
  180. flexDirection: 'row',
  181. alignItems: 'center',
  182. justifyContent: 'center',
  183. gap: 12,
  184. }}
  185. >
  186. {showLogo && logoDataUri && (
  187. <Image
  188. src={logoDataUri}
  189. style={{ maxWidth: 50, maxHeight: 50, borderRadius: 4, objectFit: 'contain' }}
  190. />
  191. )}
  192. <View style={{ alignItems: 'center' }}>
  193. {showCompanyName && (
  194. <Text style={{ fontSize: 22, fontFamily: fontBold, color: 'white' }}>
  195. {shopName}
  196. </Text>
  197. )}
  198. {workshop?.address && (
  199. <Text style={{ fontSize: 9, color: 'rgba(255,255,255,0.8)', marginTop: 2 }}>
  200. {workshop.address}
  201. </Text>
  202. )}
  203. <View style={{ flexDirection: 'row', gap: 12, marginTop: 4 }}>
  204. {workshop?.phone && (
  205. <Text style={{ fontSize: 8, color: 'rgba(255,255,255,0.7)' }}>
  206. {labels.tel ? fillTemplate(labels.tel, { phone: workshop.phone }) : `Tel: ${workshop.phone}`}
  207. </Text>
  208. )}
  209. {workshop?.email && (
  210. <Text style={{ fontSize: 8, color: 'rgba(255,255,255,0.7)' }}>
  211. {workshop.email}
  212. </Text>
  213. )}
  214. </View>
  215. </View>
  216. </View>
  217. {torqvoiceLogoDataUri && (
  218. <View
  219. style={{
  220. flexDirection: 'row',
  221. alignItems: 'center',
  222. justifyContent: 'center',
  223. gap: 3,
  224. marginTop: 8,
  225. }}
  226. >
  227. <Image src={torqvoiceLogoDataUri} style={{ width: 12, height: 12 }} />
  228. <Text style={{ fontSize: 7, fontFamily: fontBold, color: 'rgba(255,255,255,0.7)' }}>
  229. Torqvoice
  230. </Text>
  231. </View>
  232. )}
  233. </View>
  234. <View
  235. style={{
  236. flexDirection: 'row',
  237. justifyContent: 'space-between',
  238. alignItems: 'center',
  239. marginTop: 12,
  240. paddingBottom: 8,
  241. }}
  242. >
  243. <Text style={{ fontSize: 18, fontFamily: fontBold, color: primaryColor }}>{labels.title || 'QUOTE'}</Text>
  244. <View style={{ flexDirection: 'row', gap: 16 }}>
  245. <Text style={{ fontSize: 9, color: gray }}>{quoteNum}</Text>
  246. <Text style={{ fontSize: 9, color: gray }}>{createdDate}</Text>
  247. {validDate && <Text style={{ fontSize: 9, color: gray }}>{labels.validUntil ? fillTemplate(labels.validUntil, { date: validDate }) : `Valid until: ${validDate}`}</Text>}
  248. </View>
  249. </View>
  250. </View>
  251. )
  252. const renderStandardHeader = () => (
  253. <View style={styles.header}>
  254. <View>
  255. {showLogo && logoDataUri && (
  256. <Image
  257. src={logoDataUri}
  258. style={{ width: 60, height: 60, marginBottom: 6, borderRadius: 4 }}
  259. />
  260. )}
  261. {showCompanyName && <Text style={styles.brandName}>{shopName}</Text>}
  262. {workshop?.address && <Text style={styles.brandSub}>{workshop.address}</Text>}
  263. {workshop?.phone && <Text style={styles.brandContact}>{labels.tel ? fillTemplate(labels.tel, { phone: workshop.phone }) : `Tel: ${workshop.phone}`}</Text>}
  264. {workshop?.email && <Text style={styles.brandContact}>{workshop.email}</Text>}
  265. </View>
  266. <View>
  267. {torqvoiceLogoDataUri && (
  268. <View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', gap: 3, marginBottom: 6 }}>
  269. <Image src={torqvoiceLogoDataUri} style={{ width: 16, height: 16 }} />
  270. <Text style={{ fontSize: 9, fontFamily: fontBold, color: gray }}>Torqvoice</Text>
  271. </View>
  272. )}
  273. <Text style={{ ...styles.invoiceTitle, color: primaryColor }}>{labels.title || 'QUOTE'}</Text>
  274. <Text style={styles.invoiceNumber}>{quoteNum}</Text>
  275. <Text style={styles.invoiceNumber}>{createdDate}</Text>
  276. {validDate && <Text style={styles.invoiceNumber}>{labels.validUntil ? fillTemplate(labels.validUntil, { date: validDate }) : `Valid until: ${validDate}`}</Text>}
  277. </View>
  278. </View>
  279. )
  280. return (
  281. <Document>
  282. <Page size="A4" style={styles.page}>
  283. {headerStyle === 'compact'
  284. ? renderCompactHeader()
  285. : headerStyle === 'modern'
  286. ? renderModernHeader()
  287. : renderStandardHeader()}
  288. <View style={styles.infoRow}>
  289. {data.customer && (
  290. <View style={styles.infoBox}>
  291. <Text style={styles.infoLabel}>{labels.to || 'To'}</Text>
  292. <Text style={styles.infoTextBold}>{data.customer.name}</Text>
  293. {data.customer.company && (
  294. <Text style={styles.infoText}>{data.customer.company}</Text>
  295. )}
  296. {data.customer.address && (
  297. <Text style={styles.infoTextSmall}>{data.customer.address}</Text>
  298. )}
  299. {data.customer.email && (
  300. <Text style={styles.infoTextSmall}>{data.customer.email}</Text>
  301. )}
  302. {data.customer.phone && (
  303. <Text style={styles.infoTextSmall}>{data.customer.phone}</Text>
  304. )}
  305. </View>
  306. )}
  307. {data.vehicle && (
  308. <View style={styles.infoBox}>
  309. <Text style={styles.infoLabel}>{labels.vehicle || 'Vehicle'}</Text>
  310. <Text style={styles.infoTextBold}>
  311. {data.vehicle.year} {data.vehicle.make} {data.vehicle.model}
  312. </Text>
  313. {data.vehicle.vin && (
  314. <Text style={styles.infoTextSmall}>{labels.vin ? fillTemplate(labels.vin, { vin: data.vehicle.vin }) : `VIN: ${data.vehicle.vin}`}</Text>
  315. )}
  316. {data.vehicle.licensePlate && (
  317. <Text style={styles.infoTextSmall}>{labels.plate ? fillTemplate(labels.plate, { plate: data.vehicle.licensePlate }) : `Plate: ${data.vehicle.licensePlate}`}</Text>
  318. )}
  319. </View>
  320. )}
  321. <View style={styles.infoBox}>
  322. <Text style={styles.infoLabel}>{labels.quoteDetails || 'Quote Details'}</Text>
  323. <Text style={styles.infoTextBold}>{data.title}</Text>
  324. </View>
  325. </View>
  326. {data.partItems.length > 0 && (
  327. <View>
  328. <Text style={styles.sectionTitle}>{labels.parts || 'Parts'}</Text>
  329. <View style={styles.table}>
  330. <View style={styles.tableHeader}>
  331. <Text style={{ ...styles.tableHeaderCell, width: '15%' }}>{labels.partNumber || 'Part #'}</Text>
  332. <Text style={{ ...styles.tableHeaderCell, width: '35%' }}>{labels.description || 'Description'}</Text>
  333. <Text style={{ ...styles.tableHeaderCell, width: '12%', textAlign: 'right' }}>
  334. {labels.qty || 'Qty'}
  335. </Text>
  336. <Text style={{ ...styles.tableHeaderCell, width: '18%', textAlign: 'right' }}>
  337. {labels.unitPrice || 'Unit Price'}
  338. </Text>
  339. <Text style={{ ...styles.tableHeaderCell, width: '20%', textAlign: 'right' }}>
  340. {labels.total || 'Total'}
  341. </Text>
  342. </View>
  343. {data.partItems.map((p, i) => (
  344. <View key={i} style={{ ...styles.tableRow, ...(p.excluded ? { opacity: 0.5 } : {}) }}>
  345. <Text style={{ ...styles.tableCell, width: '15%', ...(p.excluded ? { textDecoration: 'line-through' } : {}) }}>{p.partNumber || '-'}</Text>
  346. <Text style={{ ...styles.tableCell, width: '35%', ...(p.excluded ? { textDecoration: 'line-through' } : {}) }}>{p.name}</Text>
  347. <Text style={{ ...styles.tableCell, width: '12%', textAlign: 'right', ...(p.excluded ? { textDecoration: 'line-through' } : {}) }}>
  348. {p.quantity}
  349. </Text>
  350. <Text style={{ ...styles.tableCell, width: '18%', textAlign: 'right', ...(p.excluded ? { textDecoration: 'line-through' } : {}) }}>
  351. {formatCurrency(p.unitPrice, currencyCode)}
  352. </Text>
  353. <Text style={{ ...styles.tableCellBold, width: '20%', textAlign: 'right', ...(p.excluded ? { textDecoration: 'line-through' } : {}) }}>
  354. {formatCurrency(p.total, currencyCode)}
  355. </Text>
  356. </View>
  357. ))}
  358. </View>
  359. </View>
  360. )}
  361. {data.laborItems.length > 0 && (
  362. <View>
  363. <Text style={styles.sectionTitle}>{labels.labor || 'Labor'}</Text>
  364. <View style={styles.table}>
  365. <View style={styles.tableHeader}>
  366. <Text style={{ ...styles.tableHeaderCell, width: '45%' }}>{labels.description || 'Description'}</Text>
  367. <Text style={{ ...styles.tableHeaderCell, width: '15%', textAlign: 'right' }}>
  368. {labels.hours || 'Hours'}
  369. </Text>
  370. <Text style={{ ...styles.tableHeaderCell, width: '20%', textAlign: 'right' }}>
  371. {labels.rate || 'Rate'}
  372. </Text>
  373. <Text style={{ ...styles.tableHeaderCell, width: '20%', textAlign: 'right' }}>
  374. {labels.total || 'Total'}
  375. </Text>
  376. </View>
  377. {data.laborItems.map((l, i) => (
  378. <View key={i} style={{ ...styles.tableRow, ...(l.excluded ? { opacity: 0.5 } : {}) }}>
  379. <Text style={{ ...styles.tableCell, width: '45%', ...(l.excluded ? { textDecoration: 'line-through' } : {}) }}>{l.description}</Text>
  380. <Text style={{ ...styles.tableCell, width: '15%', textAlign: 'right', ...(l.excluded ? { textDecoration: 'line-through' } : {}) }}>
  381. {l.hours}
  382. </Text>
  383. <Text style={{ ...styles.tableCell, width: '20%', textAlign: 'right', ...(l.excluded ? { textDecoration: 'line-through' } : {}) }}>
  384. {labels.ratePerHour ? fillTemplate(labels.ratePerHour, { rate: formatCurrency(l.rate, currencyCode) }) : `${formatCurrency(l.rate, currencyCode)}/hr`}
  385. </Text>
  386. <Text style={{ ...styles.tableCellBold, width: '20%', textAlign: 'right', ...(l.excluded ? { textDecoration: 'line-through' } : {}) }}>
  387. {formatCurrency(l.total, currencyCode)}
  388. </Text>
  389. </View>
  390. ))}
  391. </View>
  392. </View>
  393. )}
  394. {(() => {
  395. const laborTotal = data.laborItems.reduce((sum, l) => l.excluded ? sum : sum + l.total, 0)
  396. const partsTotal = data.partItems.reduce((sum, p) => p.excluded ? sum : sum + p.total, 0)
  397. const sub = laborTotal + partsTotal
  398. const disc = data.discountType === 'percentage'
  399. ? sub * (data.discountValue / 100)
  400. : data.discountType === 'fixed'
  401. ? Math.min(data.discountValue, sub)
  402. : 0
  403. const tax = (sub - disc) * (data.taxRate / 100)
  404. const total = sub - disc + tax
  405. return (
  406. <View style={styles.totalsBox}>
  407. {data.laborItems.length > 0 && (
  408. <View style={styles.totalRow}>
  409. <Text style={styles.totalLabel}>{labels.labor || 'Labor'}</Text>
  410. <Text style={styles.totalValue}>
  411. {formatCurrency(laborTotal, currencyCode)}
  412. </Text>
  413. </View>
  414. )}
  415. {data.partItems.length > 0 && (
  416. <View style={styles.totalRow}>
  417. <Text style={styles.totalLabel}>{labels.parts || 'Parts'}</Text>
  418. <Text style={styles.totalValue}>
  419. {formatCurrency(partsTotal, currencyCode)}
  420. </Text>
  421. </View>
  422. )}
  423. {sub > 0 && (
  424. <View style={styles.totalRow}>
  425. <Text style={styles.totalLabel}>{labels.subtotal || 'Subtotal'}</Text>
  426. <Text style={styles.totalValue}>{formatCurrency(sub, currencyCode)}</Text>
  427. </View>
  428. )}
  429. {disc > 0 && (
  430. <View style={styles.totalRow}>
  431. <Text style={styles.totalLabel}>
  432. {data.discountType === 'percentage'
  433. ? (labels.discountPercent ? fillTemplate(labels.discountPercent, { percent: String(data.discountValue) }) : `Discount (${data.discountValue}%)`)
  434. : (labels.discount || 'Discount')}
  435. </Text>
  436. <Text style={{ ...styles.totalValue, color: '#dc2626' }}>
  437. {formatCurrency(-disc, currencyCode)}
  438. </Text>
  439. </View>
  440. )}
  441. {data.taxRate > 0 && (
  442. <View style={styles.totalRow}>
  443. <Text style={styles.totalLabel}>{labels.tax ? fillTemplate(labels.tax, { rate: String(data.taxRate) }) : `Tax (${data.taxRate}%)`}</Text>
  444. <Text style={styles.totalValue}>{formatCurrency(tax, currencyCode)}</Text>
  445. </View>
  446. )}
  447. <View style={styles.totalDivider} />
  448. <View style={styles.grandTotalRow}>
  449. <Text style={styles.grandTotalLabel}>{labels.total || 'Total'}</Text>
  450. <Text style={styles.grandTotalValue}>
  451. {formatCurrency(total, currencyCode)}
  452. </Text>
  453. </View>
  454. </View>
  455. )
  456. })()}
  457. {torqvoiceLogoDataUri && (
  458. <View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', gap: 3, marginTop: 6 }}>
  459. <Text style={{ fontSize: 7, color: gray }}>{labels.poweredBy || 'Powered by'}</Text>
  460. <Image src={torqvoiceLogoDataUri} style={{ width: 12, height: 12 }} />
  461. <Text style={{ fontSize: 7, color: gray, fontFamily: fontBold }}>Torqvoice</Text>
  462. </View>
  463. )}
  464. {data.description && (
  465. <View style={styles.notesSection}>
  466. <Text style={styles.notesLabel}>Description</Text>
  467. <Text style={styles.notesText}>{data.description}</Text>
  468. </View>
  469. )}
  470. {portalUrl && (
  471. <View style={{ marginTop: 8 }}>
  472. <Text style={{ fontSize: 8, color: gray, textAlign: 'center' }}>
  473. {labels.viewPortal ? fillTemplate(labels.viewPortal, { url: portalUrl }) : `View your portal: ${portalUrl}`}
  474. </Text>
  475. </View>
  476. )}
  477. {/* Document attachment names */}
  478. {(otherAttachments.length > 0 || pdfAttachmentNames.length > 0) && (
  479. <View style={{ marginTop: 10 }}>
  480. <Text style={styles.sectionTitle}>{labels.attachedDocuments || 'Attached Documents'}</Text>
  481. {otherAttachments.map((att, i) => (
  482. <Text key={`other-${i}`} style={{ fontSize: 9, color: gray, marginBottom: 2 }}>
  483. {att.fileName}
  484. </Text>
  485. ))}
  486. {pdfAttachmentNames.map((name, i) => (
  487. <Text key={`pdf-${i}`} style={{ fontSize: 9, color: gray, marginBottom: 2 }}>
  488. {labels.attached ? fillTemplate(labels.attached, { name }) : `${name} (attached)`}
  489. </Text>
  490. ))}
  491. </View>
  492. )}
  493. {torqvoiceLogoDataUri ? (
  494. <View style={{
  495. ...styles.footer,
  496. flexDirection: 'row',
  497. alignItems: 'center',
  498. justifyContent: 'center',
  499. gap: 4,
  500. }}>
  501. <Text style={{ fontSize: 8, color: gray }}>
  502. {validDate
  503. ? (labels.validityFooterUntil ? fillTemplate(labels.validityFooterUntil, { date: validDate }) : `This quote is valid until ${validDate}`)
  504. : (labels.validityFooter30 || 'This quote is valid for 30 days')} ·{' '}
  505. </Text>
  506. <Text style={{ fontSize: 7, color: gray }}>{labels.poweredBy || 'Powered by'}</Text>
  507. <Image src={torqvoiceLogoDataUri} style={{ width: 14, height: 14 }} />
  508. <Text style={{ fontSize: 7, color: gray, fontFamily: fontBold }}>Torqvoice</Text>
  509. </View>
  510. ) : (
  511. <Text style={styles.footer}>
  512. {validDate
  513. ? (labels.validityFooterUntil ? fillTemplate(labels.validityFooterUntil, { date: validDate }) : `This quote is valid until ${validDate}`)
  514. : (labels.validityFooter30 || 'This quote is valid for 30 days')} · {shopName}
  515. </Text>
  516. )}
  517. </Page>
  518. {imageAttachments.length > 0 && (
  519. <Page size="A4" style={styles.page}>
  520. <Text style={styles.sectionTitle}>{labels.quoteImages || 'Quote Images'}</Text>
  521. <View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 12 }}>
  522. {imageAttachments.map((img, i) => (
  523. <View key={i} style={{ width: '48%', marginBottom: 8 }}>
  524. <Image
  525. src={img.dataUri}
  526. style={{
  527. maxHeight: 250,
  528. borderRadius: 4,
  529. objectFit: 'contain',
  530. objectPosition: 'left',
  531. }}
  532. />
  533. {img.description ? (
  534. <Text style={{ fontSize: 8, color: gray, marginTop: 2 }}>{img.description}</Text>
  535. ) : (
  536. <Text style={{ fontSize: 8, color: gray, marginTop: 2 }}>{img.fileName}</Text>
  537. )}
  538. </View>
  539. ))}
  540. </View>
  541. <Text style={styles.footer}>
  542. {quoteNum} · {shopName}
  543. </Text>
  544. </Page>
  545. )}
  546. </Document>
  547. )
  548. }