import fs from 'fs' import path from 'path' import { Font, Page, Text, View, StyleSheet } from '@react-pdf/renderer' import { radioEtcData, selectBoxOptions, supplementaryFacilities, roofMaterial } from '@/types/Survey' import { SurveyBasicInfo } from '@/types/Survey' Font.register({ family: 'NotoSansJP', src: `data:font/ttf;base64,${fs.readFileSync(path.resolve(process.cwd(), 'src/components/pdf/NotoSansJP-Regular.ttf')).toString('base64')}`, }) const styles = StyleSheet.create({ page: { padding: 15, fontFamily: 'NotoSansJP', fontSize: 8, backgroundColor: '#fff', }, header: { padding: '15px 15px 15px', borderBottom: '2px solid #2E3A59', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, title: { fontSize: 14, color: '#101010', fontWeight: 'bold', fontFamily: 'NotoSansJP', }, headerRight: { flexDirection: 'row', alignItems: 'flex-start', }, headerLeft: { marginRight: 15, alignItems: 'flex-end', }, headerLabel: { fontSize: 9, color: '#101010', fontWeight: 'bold', fontFamily: 'NotoSansJP', textAlign: 'right', margin: 0, }, headerValue: { fontSize: 9, color: '#FF5656', fontWeight: 400, fontFamily: 'NotoSansJP', margin: 0, }, section: { padding: '20px 15px 8px', }, sectionTitle: { fontSize: 10, fontFamily: 'NotoSansJP', color: '#101010', fontWeight: 'bold', marginBottom: 8, }, table: { width: '100%', }, tableRow: { flexDirection: 'row', minHeight: 28, }, tableHeader: { padding: 6, backgroundColor: '#F5F6FA', fontSize: 9, fontWeight: 'bold', color: '#101010', border: '1px solid #2E3A59', fontFamily: 'NotoSansJP', justifyContent: 'flex-start', alignItems: 'center', }, tableCell: { padding: 6, fontSize: 9, fontWeight: 500, color: '#FF5656', border: '1px solid #2E3A59', fontFamily: 'NotoSansJP', justifyContent: 'flex-start', alignItems: 'center', }, tableHeaderSmall: { width: 50, }, tableHeaderMedium: { width: 85, }, tableHeaderLarge: { width: 110, }, tableCellFlex1: { flex: 1, }, tableCellFlex2: { flex: 2, }, tableCellFlex07: { flex: 0.5745, }, memoBox: { padding: 6, fontSize: 9, fontWeight: 400, fontFamily: 'NotoSansJP', color: '#FF5656', border: '1px solid #2E3A59', minHeight: 100, width: '100%', }, sectionNoPadding: { padding: '10px 15px', }, marginL: { marginLeft: -1, }, marginT: { marginTop: -1, } }) export default function SurveySalePdf({ survey }: { survey: SurveyBasicInfo }) { return ( {/* Header */} HWJ 現地調査シート 現地調査販賣店名 {survey?.store ?? '-'} {survey?.constructionPoint && ( 現地調査施工店名 {survey?.constructionPoint ?? '-'} )} 現地阴買日 {survey?.investigationDate ?? '-'} {/* Customer Info */} お客様名 {survey?.customerName ?? '-'} ご住所 {survey?.postCode ? `(${survey?.postCode}) ${survey?.address} ${survey?.addressDetail}` : '-'} {/* Electric Info */} も気開係 雨気契约容国 {survey?.detailInfo?.contractCapacity ?? '-'} 電気契約会社 {survey?.detailInfo?.retailCompany ?? '-'} 電気付带設備 {survey?.detailInfo?.supplementaryFacilities ? supplementaryFacilities .filter((facility) => survey?.detailInfo?.supplementaryFacilities?.includes(facility.id.toString())) .map((facility) => facility.name) .join(', ') + (survey?.detailInfo?.supplementaryFacilitiesEtc ? `, ${survey?.detailInfo?.supplementaryFacilitiesEtc}` : '') : survey?.detailInfo?.supplementaryFacilitiesEtc ? `${survey?.detailInfo?.supplementaryFacilitiesEtc}` : '-'} 設置希望システム {survey?.detailInfo?.installationSystem === null && survey?.detailInfo?.installationSystemEtc === null ? '-' : survey?.detailInfo?.installationSystemEtc ? `${survey?.detailInfo?.installationSystemEtc}` : selectBoxOptions.installationSystem.find((system) => system.id.toString() === survey?.detailInfo?.installationSystem)?.name} {/* Roof Info */} 屋根眀係 築年数 {survey?.detailInfo?.constructionYear === '1' ? '新築' : survey?.detailInfo?.constructionYearEtc ? `既築 (${survey?.detailInfo?.constructionYear}年)` : '-'} 至根材 {survey?.detailInfo?.roofMaterial === null && survey?.detailInfo?.roofMaterialEtc === null ? '-' : roofMaterial .filter((material) => survey?.detailInfo?.roofMaterial?.includes(material.id.toString())) .map((material) => material.name) .join(', ')} {survey?.detailInfo?.roofMaterialEtc ? `, ${survey?.detailInfo?.roofMaterialEtc}` : ''} 座根形状 {selectBoxOptions.roofShape.find((shape) => shape.id.toString() === survey?.detailInfo?.roofShape)?.name ?? (survey?.detailInfo?.roofShapeEtc ? ` ${survey?.detailInfo?.roofShapeEtc}` : '-')} 座根勾配 {survey?.detailInfo?.roofSlope ? `${survey?.detailInfo?.roofSlope} 寸` : '-'} 住宅樠造 {radioEtcData.houseStructure.find((structure) => structure.id.toString() === survey?.detailInfo?.houseStructure)?.label ?? (survey?.detailInfo?.houseStructureEtc ? ` ${survey?.detailInfo?.houseStructureEtc}` : '-')} 並木材質 {radioEtcData.rafterMaterial.find((material) => material.id.toString() === survey?.detailInfo?.rafterMaterial)?.label ?? (survey?.detailInfo?.rafterMaterialEtc ? ` ${survey?.detailInfo?.rafterMaterialEtc}` : '-')} 垂木サイズ {selectBoxOptions.rafterSize.find((size) => size.id.toString() === survey?.detailInfo?.rafterSize)?.name ?? (survey?.detailInfo?.rafterSizeEtc ? ` ${survey?.detailInfo?.rafterSizeEtc}` : '-')} 垂木ピッチ {selectBoxOptions.rafterPitch.find((pitch) => pitch.id.toString() === survey?.detailInfo?.rafterPitch)?.name ?? (survey?.detailInfo?.rafterPitchEtc ? ` ${survey?.detailInfo?.rafterPitchEtc}` : '-')} 垂木方向 {radioEtcData.rafterDirection.find((direction) => direction.id.toString() === survey?.detailInfo?.rafterDirection)?.label ?? '-'} 野地板種類 {selectBoxOptions.openFieldPlateKind.find((kind) => kind.id.toString() === survey?.detailInfo?.openFieldPlateKind)?.name ?? (survey?.detailInfo?.openFieldPlateKindEtc ? `${survey?.detailInfo?.openFieldPlateKindEtc}` : '-')} 野地板厚さ {survey?.detailInfo?.openFieldPlateThickness ? `${survey?.detailInfo?.openFieldPlateThickness}mm` : '-'} 兩漏の形跡 {survey?.detailInfo?.leakTrace ? 'あり' : 'なし'} ルーフィング種類 {radioEtcData.waterproofMaterial.find((material) => material.id.toString() === survey?.detailInfo?.waterproofMaterial)?.label ?? (survey?.detailInfo?.waterproofMaterialEtc ? ` ${survey?.detailInfo?.waterproofMaterialEtc}` : '-')} 断熱材の有無 {radioEtcData.insulationPresence.find((presence) => presence.id.toString() === survey?.detailInfo?.insulationPresence)?.label} {survey?.detailInfo?.insulationPresenceEtc ? `, ${survey?.detailInfo?.insulationPresenceEtc}` : ''} 屋根構造の順番 {radioEtcData.structureOrder.find((order) => order.id.toString() === survey?.detailInfo?.structureOrder)?.label ?? (survey?.detailInfo?.structureOrderEtc ? `${survey?.detailInfo?.structureOrderEtc}` : '-')} {/* Installation Availability */} 区根製品名設置可否確認 {survey?.detailInfo?.installationAvailability === null && survey.detailInfo?.installationAvailabilityEtc === null ? '-' : selectBoxOptions.installationAvailability.find( (availability) => availability.id.toString() === survey?.detailInfo?.installationAvailability, )?.name} {survey?.detailInfo?.installationAvailabilityEtc ? `, ${survey?.detailInfo?.installationAvailabilityEtc}` : ''} {/* Memo */} メモ {survey?.detailInfo?.memo ?? '-'} ) }