Skip to content

Commit

Permalink
ticdi-45 fix and grazing lease vars
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtennant committed Oct 31, 2023
1 parent 06b40e2 commit 1b656c2
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 32 deletions.
34 changes: 16 additions & 18 deletions frontend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ProvisionJSON, VariableJSON } from "utils/types";
import {
convertToSpecialCamelCase,
formatMoney,
grazingLeaseVariables,
nfrAddressBuilder,
} from "utils/util";
const axios = require("axios");
Expand Down Expand Up @@ -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
Expand Down
139 changes: 125 additions & 14 deletions frontend/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ export function formatPostalCode(value: string) {
* <city prov postalCode>
*/
export function nfrAddressBuilder(tenantAddr: any[]): string {
const addressMap = new Map<string, string[]>();
const formattedAddresses: string[] = []
for (const addressObj of tenantAddr) {
const {
legalName,
firstName,
middleName,
lastName,
addrLine1,
addrLine2,
addrLine3,
city,
provAbbr,
postalCode,
} = addressObj;
console.log(addressObj)

let name = null;

Expand All @@ -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);
Expand All @@ -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: {
Expand Down

0 comments on commit 1b656c2

Please sign in to comment.