Fix PDF return data

This commit is contained in:
SepehrYahyaee
2026-08-31 12:29:31 +03:30
parent a5d2f5a2b9
commit a33466025d
3 changed files with 48 additions and 11 deletions

View File

@@ -477,28 +477,48 @@ function buildCarBodyInsuranceFields(
];
}
function buildOwnerSection(
damagedParty: ReportParty | null,
claim?: Record<string, unknown> | null,
): InsurerFileReportSection {
const person = damagedParty?.person as ReportRecord | undefined;
function buildPartyOwnerSection(
title: string,
party: ReportParty | null | undefined,
options?: {
claim?: Record<string, unknown> | null;
useClaimOwnerFallback?: boolean;
includeSheba?: boolean;
},
): InsurerFileReportSection | undefined {
const person = party?.person as ReportRecord | undefined;
const claim = options?.claim;
const money = claim?.money as
| { sheba?: string; nationalCodeOfInsurer?: string }
| undefined;
const claimOwner = claim?.owner as { fullName?: string } | undefined;
return buildSection(PR.ownerSection, [
{ label: PR.name, value: firstDefined(person?.fullName, claimOwner?.fullName) },
if (!person && !options?.useClaimOwnerFallback) return undefined;
return buildSection(title, [
{
label: PR.name,
value: options?.useClaimOwnerFallback
? firstDefined(person?.fullName, claimOwner?.fullName)
: firstDefined(person?.fullName),
},
{ label: PR.phone, value: asString(person?.phoneNumber) },
{
label: PR.nationalCode,
value: firstDefined(person?.nationalCodeOfInsurer, money?.nationalCodeOfInsurer),
value: options?.useClaimOwnerFallback
? firstDefined(person?.nationalCodeOfInsurer, money?.nationalCodeOfInsurer)
: firstDefined(person?.nationalCodeOfInsurer, person?.nationalCode),
},
{
label: PR.birthDate,
value: formatBirthDate(person?.insurerBirthday ?? person?.birthday),
value: formatBirthDate(
person?.insurerBirthday ?? person?.birthday ?? person?.driverBirthday,
),
},
{
label: PR.sheba,
value: options?.includeSheba ? money?.sheba : undefined,
},
{ label: PR.sheba, value: money?.sheba },
]);
}
@@ -838,7 +858,14 @@ export function buildInsurerFileReport(file: {
const sections = filterEmptySections([
buildCaseTimelineSection(overview, claim),
buildOwnerSection(damagedParty, claim),
buildPartyOwnerSection(PR.ownerSection, damagedParty, {
claim,
useClaimOwnerFallback: true,
includeSheba: true,
}),
includeGuiltySections
? buildPartyOwnerSection(PR.guiltyOwnerSection, guiltyParty)
: undefined,
buildDriverSection(damagedParty, blameContext),
buildSection(
PR.damagedThirdPartyInsuranceSection,