Skip to content

Commit

Permalink
Merge pull request #106 from bcgov/multiple-interested-parties
Browse files Browse the repository at this point in the history
display multiple interested parties properly
  • Loading branch information
barrfalk authored Jul 24, 2023
2 parents 58bd192 + 288aa72 commit 57d9f80
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 56 deletions.
33 changes: 19 additions & 14 deletions frontend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
: "";

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
114 changes: 72 additions & 42 deletions frontend/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <Name 1>
* <addrLine1>
* <city prov postalCode>
*
* If there are two individuals that share an address, then:
* <Name 1>
* <Name 2>
* <addrLine1>
* <city prov postalCode>
*
* Combined example:
* <Name 1> - different address from Name 2/3
* <addrLine1>
* <city prov postalCode>
* <Name 2>
* <Name 3> - same address as Name 2
* <addrLine1>
* <city prov postalCode>
*/
export function nfrAddressBuilder(tenantAddr: any[]): string {
const addressMap = new Map<string, string[]>();
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: {
Expand Down

0 comments on commit 57d9f80

Please sign in to comment.