Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18640 More amalgamating fetch / validations work #593

Merged
merged 8 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "5.6.10",
"version": "5.6.11",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand All @@ -17,7 +17,7 @@
"@bcrs-shared-components/approval-type": "1.0.19",
"@bcrs-shared-components/base-address": "2.0.3",
"@bcrs-shared-components/breadcrumb": "2.1.15",
"@bcrs-shared-components/business-lookup": "1.2.4",
"@bcrs-shared-components/business-lookup": "1.2.5",
"@bcrs-shared-components/certify": "2.1.15",
"@bcrs-shared-components/completing-party": "2.1.30",
"@bcrs-shared-components/confirm-dialog": "1.2.1",
Expand Down
6 changes: 2 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ import * as Views from '@/views'

// Mixins, interfaces, etc
import { CommonMixin, DateMixin, FilingTemplateMixin, NameRequestMixin } from '@/mixins'
import { AccountInformationIF, AddressIF, BreadcrumbIF, BusinessIF, BusinessWarningIF, CompletingPartyIF,
import { AccountInformationIF, AddressIF, BreadcrumbIF, BusinessWarningIF, CompletingPartyIF,
ConfirmDialogType, EmptyFees, FeesIF, FilingDataIF, NameRequestIF, OrgInformationIF, PartyIF, ResourceIF,
StepIF } from '@/interfaces'
import { AmalgamationRegResources, DissolutionResources, IncorporationResources, RegistrationResources,
Expand Down Expand Up @@ -1158,9 +1158,7 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi

/** Fetches and stores business info. */
private async loadBusinessInfo (businessId: string): Promise<void> {
const response = await LegalServices.fetchBusinessInfo(businessId)

const business = response?.data?.business as BusinessIF
const business = await LegalServices.fetchBusinessInfo(businessId).catch(() => {})
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

if (!business) {
throw new Error('Invalid business info')
Expand Down
212 changes: 123 additions & 89 deletions src/components/Amalgamation/AmalgamatingBusinesses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
color="primary"
class="btn-outlined-primary"
:disabled="isAddingAmalgamatingBusiness || isAddingAmalgamatingForeignBusiness"
@click="onAddBusinessClick()"
@click="isAddingAmalgamatingBusiness = true"
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
>
<v-icon>mdi-domain-plus</v-icon>
<span>Add an Amalgamating Business</span>
Expand All @@ -19,7 +19,7 @@
color="primary"
class="ml-2 btn-outlined-primary"
:disabled="isAddingAmalgamatingBusiness || isAddingAmalgamatingForeignBusiness"
@click="onAddForeignBusinessClick()"
@click="isAddingAmalgamatingForeignBusiness = true"
>
<v-icon>mdi-domain-plus</v-icon>
<span>Add an Amalgamating Foreign Business</span>
Expand All @@ -46,8 +46,8 @@
class="ml-8"
>
<span>Enter the name or the incorporation number of the registered BC business
to add to this application.
</span>
to add to this application.</span>
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

<BusinessLookup
:showErrors="false"
:businessLookup="initialBusinessLookupObject"
Expand All @@ -56,6 +56,7 @@
label="Business Name or Incorporation Number"
@setBusiness="saveAmalgamatingBusiness($event)"
/>

<v-row
class="justify-end mr-0 mt-2"
>
Expand All @@ -64,7 +65,7 @@
large
outlined
color="primary"
@click="addAmalgamatingBusinessCancel()"
@click="isAddingAmalgamatingBusiness = false"
>
<span>Cancel</span>
</v-btn>
Expand Down Expand Up @@ -95,37 +96,46 @@
class="ml-8"
>
<span>**TODO**</span>

<v-row
class="justify-end mr-0 mt-2"
>
<v-btn
id="app-cancel-btn"
large
outlined
color="primary"
@click="isAddingAmalgamatingForeignBusiness = false"
>
<span>Cancel</span>
</v-btn>
</v-row>
</v-col>

<!-- extra column is for possible action button -->
</v-row>
</v-card>
</v-expand-transition>

<!-- <v-row class="mt-4 ml-1">
<ul>
Amalgamating Businesses: <br><br>
<li
v-for="(business, index) in getAmalgamatingBusinesses"
:key="index"
<!-- snackbar to temporarily show fetch errors -->
<v-snackbar
v-model="snackbar"
timeout="5000"
>
{{ snackbarText }}

<template #action="{ attrs }">
<v-btn
color="error"
class="font-weight-bold"
text
v-bind="attrs"
@click="snackbar = false"
>
<template v-if="business.foundingDate">
Legal Name: {{ business.legalName }} <br>
Legal Type: {{ business.legalType }} <br>
Mailing Address: {{ business.officeAddress.registeredOffice.mailingAddress }} <br>
Email Address: {{ business.businessContact.email }} <br>
State: {{ business.state }} <br>
Good Standing: {{ business.goodStanding }} <br>
</template>
<template v-else>
Legal Name: {{ business.name }} <br>
Legal Type: {{ business.legalType }} <br>
Identifier: {{ business.identifier }} <br>
Status: {{ business.status }}
</template>
</li>
</ul>
</v-row> -->
Close
</v-btn>
</template>
</v-snackbar>

<BusinessTable
class="mt-8"
Expand All @@ -142,9 +152,10 @@ import { useStore } from '@/store/store'
import { CommonMixin } from '@/mixins'
import { AuthServices, BusinessLookupServices, LegalServices } from '@/services'
import { BusinessLookup } from '@bcrs-shared-components/business-lookup'
import { AmalgamatingBusinessIF, BusinessLookupIF, EmptyBusinessLookup } from '@/interfaces'
import { AmlRoles } from '@/enums'
import { AmalgamatingBusinessIF, BusinessLookupResultIF, EmptyBusinessLookup } from '@/interfaces'
import { AmlRoles, AmlTypes, RestorationTypes } from '@/enums'
import BusinessTable from '@/components/Amalgamation/BusinessTable.vue'
import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'

@Component({
components: {
Expand All @@ -153,92 +164,115 @@ import BusinessTable from '@/components/Amalgamation/BusinessTable.vue'
}
})
export default class AmalgamatingBusinesses extends Mixins(CommonMixin) {
readonly BusinessLookupServices = BusinessLookupServices

@Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[]
@Getter(useStore) getAmalgamatingBusinessesValid!: boolean
@Getter(useStore) getCurrentDate!: string
@Getter(useStore) getShowErrors!: boolean
@Getter(useStore) isAmalgamationFilingHorizontal!: boolean
@Getter(useStore) isRoleStaff!: boolean

@Action(useStore) setAmalgamatingBusinesses!: (x: Array<AmalgamatingBusinessIF>) => void
@Action(useStore) pushAmalgamatingBusiness!: (x: AmalgamatingBusinessIF) => void
@Action(useStore) setAmalgamatingBusinessesValid!: (x: boolean) => void

// Local properties
initialBusinessLookupObject = EmptyBusinessLookup
businessTableValid = false
snackbar = false
snackbarText = ''

// Button properties
isAddingAmalgamatingBusiness = false
isAddingAmalgamatingForeignBusiness = false

readonly BusinessLookupServices = BusinessLookupServices
async saveAmalgamatingBusiness (businessLookup: BusinessLookupResultIF): Promise<void> {
// Get the auth info, business info, addresses and filings in parallel.
// Return data array; if any call failed, that item will be undefined.
const data = await Promise.allSettled([
AuthServices.fetchAuthInfo(businessLookup.identifier),
LegalServices.fetchBusinessInfo(businessLookup.identifier),
LegalServices.fetchAddresses(businessLookup.identifier),
LegalServices.fetchFirstOrOnlyFiling(businessLookup.identifier)
]).then(results => results.map((result: any) => result.value))

// Cancel button in "Add an Amalgamating Business" is pressed.
addAmalgamatingBusinessCancel (): void {
this.isAddingAmalgamatingBusiness = false
this.setAmalgamatingBusinessesValid(true)
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
}
const authInfo = data[0]
const businessInfo = data[1]
const addresses = data[2]
const firstFiling = data[3]

// "Add an Amalgamating Business" button is pressed.
onAddBusinessClick (): void {
this.isAddingAmalgamatingBusiness = true
this.isAddingAmalgamatingForeignBusiness = false
this.setAmalgamatingBusinessesValid(false)
}
// Check for unaffiliated business.
if (!authInfo) {
// If a staff account couldn't fetch the auth info then the business doesn't exist.
if (this.isRoleStaff) {
this.snackbarText = 'Business doesn\'t exist in LEAR.'
this.snackbar = true
return
}

// "Add an Amalgamating Foreign Business" button is pressed.
onAddForeignBusinessClick (): void {
this.isAddingAmalgamatingBusiness = false
this.isAddingAmalgamatingForeignBusiness = true
this.setAmalgamatingBusinessesValid(false)
}
// Otherwise, assume the business is unaffiliated and add it to the table.
this.pushAmalgamatingBusiness({
type: AmlTypes.LEAR,
role: AmlRoles.AMALGAMATING,
identifier: businessLookup.identifier,
name: businessLookup.name,
legalType: businessLookup.legalType as unknown as CorpTypeCd
})

async saveAmalgamatingBusiness (businessLookup: BusinessLookupIF): Promise<void> {
let business = null
// Close the "Add an Amalgamating Business" panel.
this.isAddingAmalgamatingBusiness = false

// Get the amalgamating business information, mailing address, and email if in LEAR.
// Otherwise, return the businesslookup object.
const data = await Promise.all([
LegalServices.fetchBusinessInfo(businessLookup.identifier),
AuthServices.fetchAuthInfo(businessLookup.identifier),
LegalServices.fetchAddresses(businessLookup.identifier)
]).catch((error) => {
return error
})

if (data.length === 3) {
business = data[0].data?.business
business.businessContact = data[1].contacts[0]
business.officeAddress = data[2]
return
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
}

// If the business is not null (LEAR Entity), create from it a TING business following the interface.
// If the amalgamating businesses array is not empty, check if identifier already exists.
// If identifier already exists, don't add the business to the array.
if (business) {
const amalgamatingBusinesses = this.getAmalgamatingBusinesses
// Check for Legal API fetch issues.
if (!businessInfo || !addresses || !firstFiling) {
this.snackbarText = 'Unable to add that business.'
this.snackbar = true
return
}
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

const tingBusiness = {
type: 'lear',
role: AmlRoles.AMALGAMATING,
identifier: business.identifier,
name: business.legalName,
email: business.businessContact.email,
legalType: business.legalType,
address: business.officeAddress.registeredOffice.mailingAddress,
goodStanding: business.goodStanding
} as AmalgamatingBusinessIF

if (!amalgamatingBusinesses.find((b: any) => b.identifier === business.identifier)) {
amalgamatingBusinesses.push(tingBusiness)

// Set the new amalgamated businesses array in the store.
this.setAmalgamatingBusinesses(amalgamatingBusinesses)
}
// Verify that identifier doesn't already exist.
if (this.getAmalgamatingBusinesses.find((b: any) => b.identifier === businessInfo.identifier)) {
this.snackbarText = 'Business is already in table.'
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
this.snackbar = true
return
}

// Close the "Add an Amalgamating Business" Panel.
// If there is a state filing and restoration expiry date isn't in the past and the state filing is a
// limited restoration or limited restoration extension, then this business is in limited restoration.
const isLimitedRestoration = async (): Promise<boolean> => {
// check for no state filing
if (!businessInfo.stateFiling) return false
// check for expired restoration
if (this.getCurrentDate > businessInfo.restorationExpiryDate) return false
// fetch state filing
const stateFiling = await LegalServices.fetchFiling(businessInfo.stateFiling)
return (
stateFiling.restoration.type === RestorationTypes.LIMITED ||
stateFiling.restoration.type === RestorationTypes.LTD_EXTEND
)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One advantage of having this nested function is that businessInfo is already in scope so I don't have to pass it in as a formal parameter.


// Create amalgamating business object.
const tingBusiness: AmalgamatingBusinessIF = {
type: AmlTypes.LEAR,
role: AmlRoles.AMALGAMATING,
identifier: businessInfo.identifier,
name: businessInfo.legalName,
email: authInfo.contacts[0].email,
legalType: businessInfo.legalType,
address: addresses.registeredOffice.mailingAddress,
isNotInGoodStanding: (businessInfo.goodStanding === false),
isFutureEffective: (firstFiling.isFutureEffective === true),
isLimitedRestoration: await isLimitedRestoration()
}
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

// Add the new business to the amalgamating businesses list.
this.pushAmalgamatingBusiness(tingBusiness)

// Close the "Add an Amalgamating Business" panel.
this.isAddingAmalgamatingBusiness = false
this.setAmalgamatingBusinessesValid(true)
}

/** Sets validity according to various flags. */
Expand Down
Loading
Loading