93 lines
3.6 KiB
TypeScript
93 lines
3.6 KiB
TypeScript
|
|
import type { Template } from '@pdfme/common';
|
||
|
|
|
||
|
|
export const clientSummaryTemplate: Template = {
|
||
|
|
basePdf: 'BLANK_PDF' as any,
|
||
|
|
schemas: [
|
||
|
|
[
|
||
|
|
{ name: 'portName', type: 'text', position: { x: 20, y: 15 }, width: 100, height: 10, fontSize: 16 },
|
||
|
|
{ name: 'title', type: 'text', position: { x: 20, y: 30 }, width: 170, height: 8, fontSize: 14 },
|
||
|
|
{ name: 'clientInfo', type: 'text', position: { x: 20, y: 45 }, width: 80, height: 40, fontSize: 9 },
|
||
|
|
{ name: 'contacts', type: 'text', position: { x: 110, y: 45 }, width: 80, height: 40, fontSize: 9 },
|
||
|
|
{ name: 'vesselInfo', type: 'text', position: { x: 20, y: 90 }, width: 170, height: 20, fontSize: 9 },
|
||
|
|
{ name: 'interests', type: 'text', position: { x: 20, y: 115 }, width: 170, height: 80, fontSize: 8 },
|
||
|
|
{ name: 'recentActivity', type: 'text', position: { x: 20, y: 200 }, width: 170, height: 60, fontSize: 8 },
|
||
|
|
{ name: 'generatedAt', type: 'text', position: { x: 20, y: 275 }, width: 170, height: 6, fontSize: 7 },
|
||
|
|
],
|
||
|
|
],
|
||
|
|
};
|
||
|
|
|
||
|
|
export function buildClientSummaryInputs(
|
||
|
|
client: any,
|
||
|
|
contacts: any[],
|
||
|
|
interestList: any[],
|
||
|
|
activity: any[],
|
||
|
|
port: any,
|
||
|
|
): Record<string, string> {
|
||
|
|
const clientInfo = [
|
||
|
|
`Name: ${client.fullName ?? 'N/A'}`,
|
||
|
|
client.companyName ? `Company: ${client.companyName}` : null,
|
||
|
|
client.nationality ? `Nationality: ${client.nationality}` : null,
|
||
|
|
client.source ? `Source: ${client.source}` : null,
|
||
|
|
client.isProxy ? `Proxy: Yes${client.proxyType ? ` (${client.proxyType})` : ''}` : null,
|
||
|
|
`Added: ${new Date(client.createdAt).toLocaleDateString('en-GB')}`,
|
||
|
|
]
|
||
|
|
.filter(Boolean)
|
||
|
|
.join('\n');
|
||
|
|
|
||
|
|
const contactsText = contacts.length > 0
|
||
|
|
? contacts
|
||
|
|
.map(
|
||
|
|
(c) =>
|
||
|
|
`${c.channel.charAt(0).toUpperCase() + c.channel.slice(1)}${c.isPrimary ? ' (primary)' : ''}: ${c.value}${c.label ? ` [${c.label}]` : ''}`,
|
||
|
|
)
|
||
|
|
.join('\n')
|
||
|
|
: 'No contacts on file';
|
||
|
|
|
||
|
|
const vesselInfo = [
|
||
|
|
client.yachtName ? `Yacht: ${client.yachtName}` : null,
|
||
|
|
client.yachtLengthFt
|
||
|
|
? `Length: ${client.yachtLengthFt}ft${client.yachtLengthM ? ` / ${client.yachtLengthM}m` : ''}`
|
||
|
|
: null,
|
||
|
|
client.yachtWidthFt
|
||
|
|
? `Beam: ${client.yachtWidthFt}ft${client.yachtWidthM ? ` / ${client.yachtWidthM}m` : ''}`
|
||
|
|
: null,
|
||
|
|
client.yachtDraftFt
|
||
|
|
? `Draft: ${client.yachtDraftFt}ft${client.yachtDraftM ? ` / ${client.yachtDraftM}m` : ''}`
|
||
|
|
: null,
|
||
|
|
client.berthSizeDesired ? `Desired berth size: ${client.berthSizeDesired}` : null,
|
||
|
|
]
|
||
|
|
.filter(Boolean)
|
||
|
|
.join(' | ') || 'No vessel information on file';
|
||
|
|
|
||
|
|
const interestsText =
|
||
|
|
interestList.length > 0
|
||
|
|
? interestList
|
||
|
|
.map(
|
||
|
|
(i) =>
|
||
|
|
`• ${i.pipelineStage ?? 'open'}${i.berthMooringNumber ? ` — Berth ${i.berthMooringNumber}` : ''}${i.leadCategory ? ` [${i.leadCategory}]` : ''} (${new Date(i.createdAt).toLocaleDateString('en-GB')})`,
|
||
|
|
)
|
||
|
|
.join('\n')
|
||
|
|
: 'No pipeline interests on file';
|
||
|
|
|
||
|
|
const activityText =
|
||
|
|
activity.length > 0
|
||
|
|
? activity
|
||
|
|
.map(
|
||
|
|
(a) =>
|
||
|
|
`${new Date(a.createdAt).toLocaleDateString('en-GB')} ${a.action} ${a.entityType}${a.fieldChanged ? ` (${a.fieldChanged})` : ''}`,
|
||
|
|
)
|
||
|
|
.join('\n')
|
||
|
|
: 'No recent activity';
|
||
|
|
|
||
|
|
return {
|
||
|
|
portName: port?.name ?? 'Port Nimara',
|
||
|
|
title: `Client Summary — ${client.fullName ?? ''}`,
|
||
|
|
clientInfo,
|
||
|
|
contacts: contactsText,
|
||
|
|
vesselInfo,
|
||
|
|
interests: `Pipeline Interests:\n${interestsText}`,
|
||
|
|
recentActivity: `Recent Activity:\n${activityText}`,
|
||
|
|
generatedAt: `Generated: ${new Date().toLocaleString('en-GB')}`,
|
||
|
|
};
|
||
|
|
}
|