From 1b656c2a45b3b5edfc8c4aba2cc008e5031d6f19 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:48:42 -0700 Subject: [PATCH] ticdi-45 fix and grazing lease vars --- frontend/src/report/report.service.ts | 34 +++---- frontend/utils/util.ts | 139 +++++++++++++++++++++++--- 2 files changed, 141 insertions(+), 32 deletions(-) diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index 5c3a2fc0..44ac11e5 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -13,6 +13,7 @@ import { ProvisionJSON, VariableJSON } from "utils/types"; import { convertToSpecialCamelCase, formatMoney, + grazingLeaseVariables, nfrAddressBuilder, } from "utils/util"; const axios = require("axios"); @@ -167,30 +168,27 @@ export class ReportService { .then((res) => { return res.data; }); - const interestParcel = rawData.interestParcel[0]; + const interestParcel = rawData.interestParcel; const tenantAddr = rawData.tenantAddr; + const regVars = + { + regOfficeStreet: rawData && rawData.regOfficeStreet ? rawData.regOfficeStreet : '', + regOfficeCity: rawData && rawData.regOfficeCity ? rawData.regOfficeCity : '', + regOfficeProv: rawData && rawData.regOfficeProv ? rawData.regOfficeProv : '', + regOfficePostalCode: rawData && rawData.regOfficePostalCode ? rawData.regOfficePostalCode : '' + } + const glVariables = grazingLeaseVariables(tenantAddr, interestParcel, regVars); // TODO get these variables const data = { DB_File_Number: rawData.fileNum, DB_Document_Number: dtid, - DB_Address_Street_Tenant: "PLACEHOLDER", - DB_Address_Regional_Office: nfrAddressBuilder([ - { - addrLine1: rawData.regOfficeStreet, - city: rawData.regOfficeCity, - provAbbr: rawData.regOfficeProv, - postalCode: rawData.regOfficePostalCode, - }, - ]), - DB_Address_Mailing_Tenant: tenantAddr[0] - ? nfrAddressBuilder(tenantAddr) - : "", - DB_Name_Tenant: this.ttlsService.getLicenceHolder(tenantAddr), - DB_Name_Corporation: tenantAddr.contactCompanyName, - DB_Legal_Description: interestParcel - ? interestParcel.legalDescription - : "", + DB_Address_Street_Tenant: glVariables.streetAddress, + DB_Address_Regional_Office: glVariables.addressRegionalOffice, + DB_Address_Mailing_Tenant: glVariables.mailingAddress, + DB_Name_Tenant: glVariables.mailingName, + DB_Name_Corporation: glVariables.mailingCorp, + DB_Legal_Description: glVariables.legalDescription, }; // log the request diff --git a/frontend/utils/util.ts b/frontend/utils/util.ts index 508372bf..d997a724 100644 --- a/frontend/utils/util.ts +++ b/frontend/utils/util.ts @@ -33,7 +33,7 @@ export function formatPostalCode(value: string) { * */ export function nfrAddressBuilder(tenantAddr: any[]): string { - const addressMap = new Map(); + const formattedAddresses: string[] = [] for (const addressObj of tenantAddr) { const { legalName, @@ -41,10 +41,13 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { middleName, lastName, addrLine1, + addrLine2, + addrLine3, city, provAbbr, postalCode, } = addressObj; + console.log(addressObj) let name = null; @@ -57,6 +60,17 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { ); name = filteredParts.join(" "); } + let addrLines = ''; + if (addrLine1 && addrLine1.length > 0) { + addrLines = addrLine1; + } + if (addrLine2 && addrLine2.length > 0) { + addrLines = [addrLines, addrLine2].join('\n'); + } + if (addrLine3 && addrLine3.length > 0) { + addrLines = [addrLines, addrLine3].join('\n'); + } + const parts = []; if (city) { parts.push(city); @@ -69,24 +83,121 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { } const address = parts.join(" "); - const key = [addrLine1, address].join(","); - if (!addressMap.has(key)) { - addressMap.set(key, []); - } + // combine name, addrLines, and address + formattedAddresses.push([name, addrLines, address].join('\n')); + } + return formattedAddresses.join("\n"); +} - const addressParts = []; - if (name) { - addressParts.push(name); +export function grazingLeaseVariables(tenantAddr: [{ + addrLine1: string; + addrLine2: string; + addrLine3: string; + addrType: string; + firstName: string; + middleName: string; + lastName: string; + legalName: string; +}], interestParcel: [{ + legalDescription: string; +}], regVars: {regOfficeStreet: string, regOfficeCity: string, regOfficeProv: string, regOfficePostalCode: string}): +{streetAddress: string; streetName: string; streetCorp: string; mailingAddress: string; mailingName: string; mailingCorp: string; legalDescription: string; addressRegionalOffice: string} { + let streetAddress = ''; + let streetName = ''; + let streetCorp = ''; + let mailingAddress = ''; + let mailingName = ''; + let mailingCorp = ''; + let legalDescription = ''; + let addressRegionalOffice = ''; + + if (tenantAddr) { + for (let tenant of tenantAddr) { + if (tenant.addrType == 'MAILING') { + const tempMailingAddress = getMailingAddress(tenant); + mailingAddress = mailingAddress.length > 0 ? [mailingAddress, tempMailingAddress].join('\n ') : tempMailingAddress; + const tempMailingName = getFullName(tenant); + mailingName = mailingName.length > 0 ? [mailingName, tempMailingName].join('\n ') : tempMailingName; + const tempMailingCorp = getCorp(tenant); + mailingCorp = mailingCorp.length > 0 ? [mailingCorp, tempMailingCorp].join('\n ') : tempMailingCorp; + } else if (tenant.addrType == 'STREET') { + const tempStreetAddress = getMailingAddress(tenant); + streetAddress = streetAddress.length > 0 ? [streetAddress, tempStreetAddress].join('\n ') : tempStreetAddress; + const tempStreetName = getFullName(tenant); + streetName = streetName.length > 0 ? [streetName, tempStreetName].join('\n ') : tempStreetName; + const tempStreetCorp = getCorp(tenant); + streetCorp = streetCorp.length > 0 ? [streetCorp, tempStreetCorp].join('\n ') : tempStreetCorp; + } + } + + // if either address is empty, set it to the other + if (mailingAddress.length == 0) { + mailingAddress = streetAddress; + } + if (streetAddress.length == 0) { + streetAddress = mailingAddress; + } + // if either name is empty, set it to the other + if (mailingName.length == 0) { + mailingName = streetName; + } + if (streetName.length == 0) { + streetName = mailingName; + } + // if either corp is empty, set it to the other + if (mailingCorp.length == 0) { + mailingCorp = streetCorp; } - addressMap.get(key)?.push(addressParts.join("\n")); + if (streetCorp.length == 0) { + streetCorp = mailingCorp; + } + } + if (interestParcel) { + for (let parcel of interestParcel) { + const tempLegalDescription = parcel.legalDescription; + legalDescription = legalDescription.length > 0 ? [legalDescription, tempLegalDescription].join('\n ') : tempLegalDescription; + } + } + if (regVars.regOfficeStreet.length > 0) { + addressRegionalOffice = regVars.regOfficeStreet; + } + if (regVars.regOfficeCity.length > 0) { + addressRegionalOffice = [addressRegionalOffice, regVars.regOfficeCity].join(', '); } + if (regVars.regOfficeProv.length > 0) { + addressRegionalOffice = [addressRegionalOffice, regVars.regOfficeProv].join(', '); + } + if (regVars.regOfficePostalCode.length > 0) { + addressRegionalOffice = [addressRegionalOffice, regVars.regOfficePostalCode].join(', '); + } + + return {streetAddress, streetName, streetCorp, mailingAddress, mailingName, mailingCorp, legalDescription, addressRegionalOffice} +} - const formattedAddresses: string[] = []; - for (const [key, addresses] of addressMap.entries()) { - const [addrLine1, cityProvAbbrPostalCode] = key.split(","); - formattedAddresses.push(...addresses, addrLine1, cityProvAbbrPostalCode); +function getFullName(tenant: { + firstName: string; + middleName: string; + lastName: string; +}): string { + const nameParts = []; + if (tenant.firstName !== null) { + nameParts.push(tenant.firstName); } - return formattedAddresses.join("\n"); + if (tenant.middleName !== null) { + nameParts.push(tenant.middleName); + } + if (tenant.lastName !== null) { + nameParts.push(tenant.lastName); + } + const fullName = nameParts.join(' '); + + return fullName; +} + +function getCorp(tenant: { + legalName: string; +}): string { + return tenant.legalName??''; } export function getMailingAddress(tenantAddr: {