From db65506420173d83e652f3fd58e69c4f09fa0d81 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Wed, 22 May 2024 15:01:01 -0700 Subject: [PATCH] update grazing lease variables --- backend/src/report/report.service.ts | 33 ++++++++++++++++++++-------- backend/src/util.ts | 26 +++++++++++++++++++--- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/backend/src/report/report.service.ts b/backend/src/report/report.service.ts index 106371d7..51da0cf8 100644 --- a/backend/src/report/report.service.ts +++ b/backend/src/report/report.service.ts @@ -252,10 +252,13 @@ export class ReportService { DB_DOCUMENT_NUMBER: dtid, DB_DOCUMENT_TYPE: documentType.name, DB_FILE_NUMBER: rawData ? rawData.fileNum : null, - DB_ADDRESS_STREET_TENANT: glVariables.glStreetAddress || glVariables.glMailingAddress, - DB_ADDRESS_MAILING_TENANT: glVariables.glMailingAddress || glVariables.glStreetAddress, + // DB_ADDRESS_STREET_TENANT: glVariables.glStreetAddress || glVariables.glMailingAddress, + DB_ADDRESS_STREET_TENANT: glVariables.combinedAddress, + // DB_ADDRESS_MAILING_TENANT: glVariables.glMailingAddress || glVariables.glStreetAddress, + DB_ADDRESS_MAILING_TENANT: glVariables.combinedAddress, DB_ADDRESS_REGIONAL_OFFICE: glVariables.addressRegionalOffice, - DB_NAME_TENANT: glVariables.mailingName, + // DB_NAME_TENANT: glVariables.mailingName, + DB_NAME_TENANT: glVariables.combinedName, DB_NAME_TENANT_LIST: glVariables.mailingNameList, DB_NAME_CORPORATION: glVariables.mailingCorp, DB_LEGAL_DESCRIPTION: glVariables.legalDescription, @@ -265,14 +268,19 @@ export class ReportService { ? rawData.type.toLowerCase().charAt(0).toUpperCase() + rawData.type.toLowerCase().slice(1) : '', DB_REG_DOCUMENT_NUMBER: rawData ? rawData.documentNum : null, + DB_NAME_TENANTS: glVariables.combinedName, + DB_ADDRESS_TENANT: glVariables.combinedAddress, // provide the variables in non-all caps format as well DB_Document_Number: dtid, DB_Document_Type: documentType.name, DB_File_Number: rawData ? rawData.fileNum : null, - DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress, - DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress, + // DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress, + DB_Address_Street_Tenant: glVariables.combinedAddress, + // DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress, + DB_Address_Mailing_Tenant: glVariables.combinedAddress, DB_Address_Regional_Office: glVariables.addressRegionalOffice, - DB_Name_Tenant: glVariables.mailingName, + // DB_Name_Tenant: glVariables.mailingName, + DB_Name_Tenant: glVariables.combinedName, DB_Name_Tenant_List: glVariables.mailingNameList, DB_Name_Corporation: glVariables.mailingCorp, DB_Legal_Description: glVariables.legalDescription, @@ -282,6 +290,8 @@ export class ReportService { ? rawData.type.toLowerCase().charAt(0).toUpperCase() + rawData.type.slice(1).toLowerCase() : '', DB_Reg_Document_Number: rawData ? rawData.documentNum : null, + DB_Name_Tenants: glVariables.combinedName, + DB_Address_Tenant: glVariables.combinedAddress, }; } @@ -469,13 +479,18 @@ export class ReportService { const data = { DB_File_Number: rawData.fileNum, DB_Document_Number: dtid, - DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress, + // DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress, + DB_Address_Street_Tenant: glVariables.combinedAddress, DB_Address_Regional_Office: glVariables.addressRegionalOffice, - DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress, - DB_Name_Tenant: glVariables.mailingName, + // DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress, + DB_Address_Mailing_Tenant: glVariables.combinedAddress, + // DB_Name_Tenant: glVariables.mailingName, + DB_Name_Tenant: glVariables.combinedName, DB_Name_Tenant_List: glVariables.mailingNameList, DB_Name_Corporation: glVariables.mailingCorp, DB_Legal_Description: glVariables.legalDescription, + DB_Name_Tenants: glVariables.combinedName, + DB_Address_Tenant: glVariables.combinedAddress, }; // log the request diff --git a/backend/src/util.ts b/backend/src/util.ts index 5e6be075..4d7dd195 100644 --- a/backend/src/util.ts +++ b/backend/src/util.ts @@ -124,15 +124,16 @@ export function glAddressBuilder( provAbbr: string; postalCode: string; }[] -): { glMailingAddress: string; glStreetAddress: string } { +): { glMailingAddress: string; glStreetAddress: string; combinedAddress: string } { if (!tenantAddr) { - return { glMailingAddress: '', glStreetAddress: '' }; + return { glMailingAddress: '', glStreetAddress: '', combinedAddress: '' }; } const uniqueMailingAddresses = new Map< string, { names: Set; addressLines: string; cityProvPostal: string } >(); const uniqueStreetAddresses = new Map; addressLines: string; cityProvPostal: string }>(); + const uniqueAddresses = new Map; addressLines: string; cityProvPostal: string }>(); for (const addressObj of tenantAddr) { const { @@ -193,6 +194,12 @@ export function glAddressBuilder( uniqueStreetAddresses.set(key, { names: new Set([name]), addressLines: joinedAddressLines, cityProvPostal }); } } + if (uniqueAddresses.has(key)) { + const existingEntry = uniqueAddresses.get(key); + existingEntry.names.add(name); + } else { + uniqueAddresses.set(key, { names: new Set([name]), addressLines: joinedAddressLines, cityProvPostal }); + } } const formattedMailingAddresses: string[] = []; @@ -207,9 +214,16 @@ export function glAddressBuilder( formattedStreetAddresses.push(`${formattedNames}\n${addressLines}\n${cityProvPostal}\n`); } + const formattedAddresses: string[] = []; + for (const { names, addressLines, cityProvPostal } of uniqueAddresses.values()) { + const formattedNames = Array.from(names).join('\n'); + formattedAddresses.push(`${formattedNames}\n${addressLines}\n${cityProvPostal}\n`); + } + return { glMailingAddress: formattedMailingAddresses.join('\n'), glStreetAddress: formattedStreetAddresses.join('\n'), + combinedAddress: formattedAddresses.join('\n'), }; } @@ -225,6 +239,8 @@ export function grazingLeaseVariables( mailingName: string; mailingNameList: { name: string }[]; mailingCorp: string; + combinedAddress: string; + combinedName: string; legalDescription: string; addressRegionalOffice: string; glMailingAddress: string; @@ -238,9 +254,10 @@ export function grazingLeaseVariables( let mailingName = ''; let mailingNameList = []; let mailingCorp = ''; + let combinedName = ''; let legalDescription = ''; let addressRegionalOffice = ''; - const { glMailingAddress, glStreetAddress } = glAddressBuilder(tenantAddr); + const { glMailingAddress, glStreetAddress, combinedAddress } = glAddressBuilder(tenantAddr); if (tenantAddr) { for (let tenant of tenantAddr) { @@ -262,6 +279,7 @@ export function grazingLeaseVariables( const tempStreetCorp = getCorp(tenant); streetCorp = streetCorp.length > 0 ? [streetCorp, tempStreetCorp].join('\n ') : tempStreetCorp; } + combinedName = combinedName.length > 0 ? [combinedName, getFullName(tenant)].join('\n ') : getFullName(tenant); } // if either address is empty, set it to the other @@ -322,6 +340,8 @@ export function grazingLeaseVariables( addressRegionalOffice, glMailingAddress, glStreetAddress, + combinedAddress, + combinedName, }; }