From 288aa7216a844cc649b718bacc26783dc1659775 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:42:33 -0700 Subject: [PATCH] display multiple interested parties properly --- frontend/src/report/report.service.ts | 33 ++++---- frontend/utils/util.ts | 114 ++++++++++++++++---------- 2 files changed, 91 insertions(+), 56 deletions(-) diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index 4619cb1a..64d21193 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -286,9 +286,10 @@ export class ReportService { } // Format the raw ttls data - const tenantAddr = rawData.tenantAddr[0]; + const tenantAddr = rawData.tenantAddr; const interestParcel = rawData.interestParcel[0]; - const DB_Address_Mailing_Tenant = tenantAddr + + const DB_Address_Mailing_Tenant = tenantAddr[0] ? nfrAddressBuilder(tenantAddr) : ""; @@ -493,12 +494,14 @@ export class ReportService { const ttlsData = { monies: monies, moniesTotal: moniesTotal, - DB_Address_Regional_Office: nfrAddressBuilder({ - addrLine1: rawData.regOfficeStreet, - city: rawData.regOfficeCity, - provAbbr: rawData.regOfficeProv, - postalCode: rawData.regOfficePostalCode, - }), + DB_Address_Regional_Office: nfrAddressBuilder([ + { + addrLine1: rawData.regOfficeStreet, + city: rawData.regOfficeCity, + provAbbr: rawData.regOfficeProv, + postalCode: rawData.regOfficePostalCode, + }, + ]), DB_Name_BCAL_Contact: idirName, DB_File_Number: rawData.fileNum, DB_Address_Mailing_Tenant: DB_Address_Mailing_Tenant, @@ -518,12 +521,14 @@ export class ReportService { DB_FP_Asterisk: DB_FP_Asterisk, DB_Total_GST_Amount: formatMoney(DB_Total_GST_Amount), DB_Total_Monies_Payable: formatMoney(DB_Total_Monies_Payable), - DB_Address_Line_Regional_Office: nfrAddressBuilder({ - addrLine1: rawData.regOfficeStreet, - city: rawData.regOfficeCity, - provAbbr: rawData.regOfficeProv, - postalCode: rawData.regOfficePostalCode, - }), + DB_Address_Line_Regional_Office: nfrAddressBuilder([ + { + addrLine1: rawData.regOfficeStreet, + city: rawData.regOfficeCity, + provAbbr: rawData.regOfficeProv, + postalCode: rawData.regOfficePostalCode, + }, + ]), }; // parse out the rawData, variableJson, and provisionJson into something useable // combine the formatted TTLS data, variables, and provision sections diff --git a/frontend/utils/util.ts b/frontend/utils/util.ts index 9cdc998c..508372bf 100644 --- a/frontend/utils/util.ts +++ b/frontend/utils/util.ts @@ -11,52 +11,82 @@ export function formatPostalCode(value: string) { } } -export function nfrAddressBuilder(tenantAddr: any): string { - const { - legalName, - firstName, - middleName, - lastName, - addrLine1, - city, - provAbbr, - postalCode, - } = tenantAddr; - const addressParts = []; - let name = null; - if (legalName) { - name = legalName; - } else if (firstName || middleName || lastName) { - const parts = [firstName, middleName, lastName]; - const filteredParts = parts.filter( - (part) => part !== null && part !== undefined - ); - name = filteredParts.join(" "); - } - if (name) { - addressParts.push(name); - } - if (addrLine1) { - addressParts.push(addrLine1); - } +/** + * Outputs a string: + * + * + * + * + * If there are two individuals that share an address, then: + * + * + * + * + * + * Combined example: + * - different address from Name 2/3 + * + * + * + * - same address as Name 2 + * + * + */ +export function nfrAddressBuilder(tenantAddr: any[]): string { + const addressMap = new Map(); + for (const addressObj of tenantAddr) { + const { + legalName, + firstName, + middleName, + lastName, + addrLine1, + city, + provAbbr, + postalCode, + } = addressObj; - const parts = []; - if (city) { - parts.push(city); - } - if (provAbbr) { - parts.push(provAbbr); - } - if (postalCode) { - parts.push(formatPostalCode(postalCode)); - } - const address = parts.join(" "); + let name = null; - if (address) { - addressParts.push(address); + if (legalName) { + name = legalName; + } else if (firstName || middleName || lastName) { + const parts = [firstName, middleName, lastName]; + const filteredParts = parts.filter( + (part) => part !== null && part !== undefined + ); + name = filteredParts.join(" "); + } + const parts = []; + if (city) { + parts.push(city); + } + if (provAbbr) { + parts.push(provAbbr); + } + if (postalCode) { + parts.push(formatPostalCode(postalCode)); + } + const address = parts.join(" "); + + const key = [addrLine1, address].join(","); + if (!addressMap.has(key)) { + addressMap.set(key, []); + } + + const addressParts = []; + if (name) { + addressParts.push(name); + } + addressMap.get(key)?.push(addressParts.join("\n")); } - return addressParts.join("\n"); + const formattedAddresses: string[] = []; + for (const [key, addresses] of addressMap.entries()) { + const [addrLine1, cityProvAbbrPostalCode] = key.split(","); + formattedAddresses.push(...addresses, addrLine1, cityProvAbbrPostalCode); + } + return formattedAddresses.join("\n"); } export function getMailingAddress(tenantAddr: {