diff --git a/frontend/public/js/util.js b/frontend/public/js/util.js index 52117d25..0096474f 100644 --- a/frontend/public/js/util.js +++ b/frontend/public/js/util.js @@ -20,7 +20,6 @@ async function generateReport(documentType) { .catch(() => { location.reload(); }); - console.log(reportName) const data = { prdid: prdid, dtid: dtid, diff --git a/frontend/src/app.controller.ts b/frontend/src/app.controller.ts index 0aafb32b..ac80068b 100644 --- a/frontend/src/app.controller.ts +++ b/frontend/src/app.controller.ts @@ -406,16 +406,10 @@ export class AppController { console.log(err); console.log(err.response.data); }); - ttlsJSON = await this.ttlsService.sendToBackend(response); - ttlsJSON["cityProvPostal"] = this.ttlsService.concatCityProvPostal( - response.tenantAddr ? response.tenantAddr[0] : null - ); - if (ttlsJSON.inspected_date) { - ttlsJSON["inspected_date"] = this.ttlsService.formatInspectedDate( - ttlsJSON.inspected_date.toString() - ); - } - primaryContactName = ttlsJSON.licence_holder_name; + ttlsJSON = await this.ttlsService.formatNFRData(response); + primaryContactName = ttlsJSON.licenceHolderName; + const interestedParties = nfrInterestedParties(response.tenantAddr); + ttlsJSON["interestedParties"] = interestedParties; return res.render("grazing-lease", { title: title, idirUsername: session.data.activeAccount diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index d471a967..95b7019b 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -182,9 +182,9 @@ export class ReportService { const data = { DB_File_Number: rawData.fileNum, DB_Document_Number: dtid, - DB_Address_Street_Tenant: glVariables.streetAddress, + DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress, DB_Address_Regional_Office: glVariables.addressRegionalOffice, - DB_Address_Mailing_Tenant: glVariables.mailingAddress, + DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress, DB_Name_Tenant: glVariables.mailingName, DB_Name_Tenant_List: glVariables.mailingNameList, DB_Name_Corporation: glVariables.mailingCorp, diff --git a/frontend/utils/util.ts b/frontend/utils/util.ts index 13e84631..acbfbc74 100644 --- a/frontend/utils/util.ts +++ b/frontend/utils/util.ts @@ -14,22 +14,22 @@ export function formatPostalCode(value: string) { /** * 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 { @@ -97,6 +97,128 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { return formattedAddresses.join("\n"); } +/** + * Similar to nfrAddressBuilder, slightly modified for gl + * 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 glAddressBuilder(tenantAddr: { + addrLine1: string; + addrLine2: string; + addrLine3: string; + addrType: string; + firstName: string; + middleName: string; + lastName: string; + legalName: string; + city: string; + country: string; + provAbbr: string; + postalCode: string; +}[]): { glMailingAddress: string; glStreetAddress: string } { + if (!tenantAddr) { + return {glMailingAddress: '', glStreetAddress: ''}; + } + const uniqueMailingAddresses = new Map; addressLines: string; cityProvPostal: string }>(); + const uniqueStreetAddresses = new Map; addressLines: string; cityProvPostal: string }>(); + + for (const addressObj of tenantAddr) { + const { + legalName, + firstName, + middleName, + lastName, + addrLine1, + addrLine2, + addrLine3, + addrType, + city, + provAbbr, + postalCode, + } = addressObj; + + 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(" "); + } + + const parts = []; + if (city) { + parts.push(city); + } + if (provAbbr) { + parts.push(provAbbr); + } + if (postalCode) { + parts.push(formatPostalCode(postalCode)); + } + const cityProvPostal = parts.join(" "); + + let addressLines = []; + if (addrLine1) addressLines.push(addrLine1); + if (addrLine2) addressLines.push(addrLine2); + if (addrLine3) addressLines.push(addrLine3); + let joinedAddressLines = addressLines.join(', '); + + const key = joinedAddressLines + cityProvPostal; + + if (addrType === 'MAILING') { + if (uniqueMailingAddresses.has(key)) { + const existingEntry = uniqueMailingAddresses.get(key); + existingEntry.names.add(name); + } else { + uniqueMailingAddresses.set(key, { names: new Set([name]), addressLines: joinedAddressLines, cityProvPostal }); + } + } else if (addrType === 'STREET') { + if (uniqueStreetAddresses.has(key)) { + const existingEntry = uniqueStreetAddresses.get(key); + existingEntry.names.add(name); + } else { + uniqueStreetAddresses.set(key, { names: new Set([name]), addressLines: joinedAddressLines, cityProvPostal }); + } + } + } + + const formattedMailingAddresses: string[] = []; + for (const { names, addressLines, cityProvPostal } of uniqueMailingAddresses.values()) { + const formattedNames = Array.from(names).join("\n"); + formattedMailingAddresses.push(`${formattedNames}\n${addressLines}\n${cityProvPostal}\n`); + } + + const formattedStreetAddresses: string[] = []; + for (const { names, addressLines, cityProvPostal } of uniqueStreetAddresses.values()) { + const formattedNames = Array.from(names).join("\n"); + formattedStreetAddresses.push(`${formattedNames}\n${addressLines}\n${cityProvPostal}\n`); + } + + return { + glMailingAddress: formattedMailingAddresses.join("\n"), + glStreetAddress: formattedStreetAddresses.join("\n"), + }; +} + + export function grazingLeaseVariables(tenantAddr: [{ addrLine1: string; addrLine2: string; @@ -113,7 +235,8 @@ export function grazingLeaseVariables(tenantAddr: [{ }], interestParcel: [{ legalDescription: string; }], regVars: {regOfficeStreet: string, regOfficeCity: string, regOfficeProv: string, regOfficePostalCode: string}): -{streetAddress: string; streetName: string; streetCorp: string; mailingAddress: string; mailingName: string; mailingNameList: {name: string}[]; mailingCorp: string; legalDescription: string; addressRegionalOffice: string} { +{streetAddress: string; streetName: string; streetCorp: string; mailingAddress: string; mailingName: string; mailingNameList: {name: string}[]; + mailingCorp: string; legalDescription: string; addressRegionalOffice: string, glMailingAddress: string, glStreetAddress: string} { let streetAddress = ''; let streetName = ''; let streetNameList = []; @@ -124,6 +247,7 @@ export function grazingLeaseVariables(tenantAddr: [{ let mailingCorp = ''; let legalDescription = ''; let addressRegionalOffice = ''; + const {glMailingAddress, glStreetAddress} = glAddressBuilder(tenantAddr); if (tenantAddr) { for (let tenant of tenantAddr) { @@ -191,7 +315,7 @@ export function grazingLeaseVariables(tenantAddr: [{ addressRegionalOffice = [addressRegionalOffice, regVars.regOfficePostalCode].join(', '); } - return {streetAddress, streetName, streetCorp, mailingAddress, mailingName, mailingNameList, mailingCorp, legalDescription, addressRegionalOffice} + return {streetAddress, streetName, streetCorp, mailingAddress, mailingName, mailingNameList, mailingCorp, legalDescription, addressRegionalOffice, glMailingAddress, glStreetAddress} } function getFullName(tenant: { @@ -220,7 +344,20 @@ function getCorp(tenant: { return tenant.legalName??''; } +/** + * Used by grazingLeaseVariables, formats and returns a mailing address + * + * @param tenantAddr: {addrLine1, addrLine2, addrLine3, city, country, provAbbr, postalCode} + * @returns + * + * addrLine1, addrLine2, addrLine3 + * city, provAbbr postalCode + */ export function getMailingAddress(tenantAddr: { + firstName: string; + middleName: string; + lastName: string; + legalName: string; addrLine1: string; addrLine2: string; addrLine3: string; @@ -239,18 +376,15 @@ export function getMailingAddress(tenantAddr: { .filter(component => !!component) // Filter out undefined or empty components .join(', '); - const remainingComponents = [ - tenantAddr.city, - tenantAddr.provAbbr, - tenantAddr.country, - tenantAddr.postalCode - ]; - - const spaceSeparated = remainingComponents - .filter(component => !!component) // Filter out undefined or empty components - .join(' '); + const cityPostalCode = [ + tenantAddr.city, + tenantAddr.provAbbr, + tenantAddr.postalCode + ] + .filter(component => !!component) + .join(' '); - const mailingAddress = [combinedAddress, spaceSeparated].filter(part => !!part).join(', '); + const mailingAddress = [combinedAddress, cityPostalCode].filter(part => !!part).join('\n'); return mailingAddress; } diff --git a/frontend/views/pages/grazing-lease.hbs b/frontend/views/pages/grazing-lease.hbs index 182e19fc..90b3cfc2 100644 --- a/frontend/views/pages/grazing-lease.hbs +++ b/frontend/views/pages/grazing-lease.hbs @@ -7,51 +7,30 @@
DTID: {{message.dtid}}
-
Tenure File Number: {{message.tenure_file_number}}
+
Tenure File Number: {{message.fileNum}}
Primary Contact Name: {{primaryContactName}}
Disposition Transaction ID Details @@ -62,49 +41,51 @@
Type
-
{{ message.type_name }}
+
{{ message.type }}
Subtype
-
{{message.sub_type_name}}
+
{{message.subType}}
Purpose
-
{{ message.purpose_name }}
+
{{ message.purpose }}
Subpurpose
-
{{message.sub_purpose_name}}
+
{{message.subPurpose}}
Mailing Address
-
{{message.mailing_address}}
+
{{message.addrLine1}}
+
{{message.addrLine2}}
+
{{message.addrLine3}}
{{message.cityProvPostal}}
-
{{message.mailing_country}}
+
{{message.country}}
Location of Land
-
{{message.location_description}}
+
{{message.locLand}}
- Area + Interested Parties