diff --git a/src/components/Amalgamation/AmalgamatingBusinesses.vue b/src/components/Amalgamation/AmalgamatingBusinesses.vue index 2cd13b5ba..fef689e01 100644 --- a/src/components/Amalgamation/AmalgamatingBusinesses.vue +++ b/src/components/Amalgamation/AmalgamatingBusinesses.vue @@ -149,11 +149,11 @@ import { Component, Mixins, Watch } from 'vue-property-decorator' import { Action, Getter } from 'pinia-class' import { useStore } from '@/store/store' -import { CommonMixin } from '@/mixins' -import { AuthServices, BusinessLookupServices, LegalServices } from '@/services' +import { AmalgamationMixin, CommonMixin } from '@/mixins' +import { BusinessLookupServices } from '@/services' import { BusinessLookup } from '@bcrs-shared-components/business-lookup' import { AmalgamatingBusinessIF, BusinessLookupResultIF, EmptyBusinessLookup } from '@/interfaces' -import { AmlRoles, AmlTypes, RestorationTypes } from '@/enums' +import { AmlRoles, AmlTypes } from '@/enums' import BusinessTable from '@/components/Amalgamation/BusinessTable.vue' import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module' @@ -163,15 +163,12 @@ import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module' BusinessTable } }) -export default class AmalgamatingBusinesses extends Mixins(CommonMixin) { +export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, 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) pushAmalgamatingBusiness!: (x: AmalgamatingBusinessIF) => void @Action(useStore) setAmalgamatingBusinessesValid!: (x: boolean) => void @@ -187,22 +184,11 @@ export default class AmalgamatingBusinesses extends Mixins(CommonMixin) { isAddingAmalgamatingForeignBusiness = false async saveAmalgamatingBusiness (businessLookup: BusinessLookupResultIF): Promise { - // 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)) - - const authInfo = data[0] - const businessInfo = data[1] - const addresses = data[2] - const firstFiling = data[3] + // Get the business information + const business = await this.fetchBusinessInfoForTing(businessLookup) // Check for unaffiliated business. - if (!authInfo) { + if (!business.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.' @@ -226,46 +212,31 @@ export default class AmalgamatingBusinesses extends Mixins(CommonMixin) { } // Check for Legal API fetch issues. - if (!businessInfo || !addresses || !firstFiling) { + if (!business.businessInfo || !business.addresses || !business.firstFiling) { this.snackbarText = 'Unable to add that business.' this.snackbar = true return } // Verify that identifier doesn't already exist. - if (this.getAmalgamatingBusinesses.find((b: any) => b.identifier === businessInfo.identifier)) { + if (this.getAmalgamatingBusinesses.find((b: any) => b.identifier === business.businessInfo.identifier)) { this.snackbarText = 'Business is already in table.' this.snackbar = true return } - // 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 => { - // 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 - ) - } - // 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() + identifier: business.businessInfo.identifier, + name: business.businessInfo.legalName, + email: business.authInfo.contacts[0].email, + legalType: business.businessInfo.legalType, + address: business.addresses.registeredOffice.mailingAddress, + isNotInGoodStanding: (business.businessInfo.goodStanding === false), + isFutureEffective: (business.firstFiling.isFutureEffective === true), + isLimitedRestoration: await this.isLimitedRestoration(business) } // Add the new business to the amalgamating businesses list. diff --git a/src/mixins/amalgamation-mixin.ts b/src/mixins/amalgamation-mixin.ts index de7bbc0ab..ba0f2ca0c 100644 --- a/src/mixins/amalgamation-mixin.ts +++ b/src/mixins/amalgamation-mixin.ts @@ -1,9 +1,10 @@ import { Component, Vue } from 'vue-property-decorator' -import { Getter } from 'pinia-class' +import { Action, Getter } from 'pinia-class' import { useStore } from '@/store/store' -import { AmlStatuses, AmlTypes } from '@/enums' +import { AmlRoles, AmlStatuses, AmlTypes, RestorationTypes } from '@/enums' import { AmalgamatingBusinessIF } from '@/interfaces' import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module' +import { AuthServices, LegalServices } from '@/services' /** * Mixin that provides amalgamation rules, etc. @@ -11,10 +12,13 @@ import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module' @Component({}) export default class AmalgamationMixin extends Vue { @Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[] + @Getter(useStore) getCurrentDate!: string @Getter(useStore) isRoleStaff!: boolean @Getter(useStore) isTypeBcCcc!: boolean @Getter(useStore) isTypeBcUlcCompany!: boolean + @Action(useStore) setAmalgamatingBusinesses!: (x: Array) => void + // *** TODO: finish this, maybe name them something recognizable... /** Iterable array of rule functions, sorted by importance. */ readonly rules = [ @@ -41,6 +45,87 @@ export default class AmalgamationMixin extends Vue { ) } + /** + * Get the business information, mailing address, email, and first filing if in LEAR. + * Otherwise, return error. + */ + async fetchBusinessInfoForTing (item: any): Promise { + // 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(item.identifier), + LegalServices.fetchBusinessInfo(item.identifier), + LegalServices.fetchAddresses(item.identifier), + LegalServices.fetchFirstOrOnlyFiling(item.identifier) + ]).then(results => results.map((result: any) => result.value)) + + const authInfo = data[0] + const businessInfo = data[1] + const addresses = data[2] + const firstFiling = data[3] + + return { + authInfo, + businessInfo, + addresses, + firstFiling + } + } + + /** + * 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. + * @param business The business to check if is in Limited Restoration or not. + */ + isLimitedRestoration = async (business: any): Promise => { + // check for no state filing + if (!business.businessInfo.stateFiling) return false + // check for expired restoration + if (this.getCurrentDate > business.businessInfo.restorationExpiryDate) return false + // fetch state filing + const stateFiling = await LegalServices.fetchFiling(business.businessInfo.stateFiling) + return ( + stateFiling.restoration.type === RestorationTypes.LIMITED || + stateFiling.restoration.type === RestorationTypes.LTD_EXTEND + ) + } + + /** + * Re-fetch the draft amalgamating businesses information and set in the store. + * Need to do that because the businesses might have changed from last draft save. + */ + async refetchAmalgamatingBusinessesInfo (): Promise { + const fetchTingInfo = async (item: any): Promise => { + let tingBusiness = await this.fetchBusinessInfoForTing(item) + if (!tingBusiness.authInfo) { + return { + type: AmlTypes.LEAR, + role: AmlRoles.AMALGAMATING, + identifier: item.identifier, + name: item.name, + legalType: item.legalType as unknown as CorpTypeCd + } + } else { + return { + type: AmlTypes.LEAR, + role: AmlRoles.AMALGAMATING, + identifier: tingBusiness.businessInfo.identifier, + name: tingBusiness.businessInfo.legalName, + email: tingBusiness.authInfo.contacts[0].email, + legalType: tingBusiness.businessInfo.legalType, + address: tingBusiness.addresses.registeredOffice.mailingAddress, + isNotInGoodStanding: (tingBusiness.businessInfo.goodStanding === false), + isFutureEffective: (tingBusiness.firstFiling.isFutureEffective === true), + isLimitedRestoration: await this.isLimitedRestoration(tingBusiness) + } + } + } + + this.setAmalgamatingBusinesses( + await Promise.all(this.getAmalgamatingBusinesses.map(fetchTingInfo)) + ) + } + // *** TODO // A BC Company cannot amalgamate with an existing Unlimited Liability Company from Alberta, // Nova Scotia, or the USA to form a BC Unlimited Liability Company. diff --git a/src/mixins/filing-template-mixin.ts b/src/mixins/filing-template-mixin.ts index 3a9fc91fd..75215ff55 100644 --- a/src/mixins/filing-template-mixin.ts +++ b/src/mixins/filing-template-mixin.ts @@ -1,9 +1,9 @@ import { Component, Mixins } from 'vue-property-decorator' import { Getter, Action } from 'pinia-class' import { useStore } from '@/store/store' -import { DateMixin } from '@/mixins' +import { AmalgamationMixin, DateMixin } from '@/mixins' import { - AmalgamatingBusinessIF, AmalgamationFilingIF, BusinessAddressIF, ContactPointIF, CertifyIF, CompletingPartyIF, + AmalgamationFilingIF, BusinessAddressIF, ContactPointIF, CertifyIF, CompletingPartyIF, CourtOrderIF, CourtOrderStepIF, CreateMemorandumIF, CreateResolutionIF, CreateRulesIF, DefineCompanyIF, DissolutionFilingIF, DissolutionStatementIF, DocumentDeliveryIF, EffectiveDateTimeIF, EmptyContactPoint, EmptyNaics, IncorporationAgreementIF, IncorporationFilingIF, NaicsIF, NameRequestFilingIF, @@ -21,10 +21,9 @@ import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module/' * Mixin that provides the integration with the Legal API. */ @Component({}) -export default class FilingTemplateMixin extends Mixins(DateMixin) { +export default class FilingTemplateMixin extends Mixins(AmalgamationMixin, DateMixin) { @Getter(useStore) getAddPeopleAndRoleStep!: PeopleAndRoleIF @Getter(useStore) getAffidavitStep!: UploadAffidavitIF - @Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[] @Getter(useStore) getAmalgamationCourtApproval!: boolean @Getter(useStore) getAmalgamationType!: AmalgamationTypes @Getter(useStore) getBusinessContact!: ContactPointIF @@ -65,7 +64,6 @@ export default class FilingTemplateMixin extends Mixins(DateMixin) { @Getter(useStore) getTempId!: string @Getter(useStore) getTransactionalFolioNumber!: string @Getter(useStore) isPremiumAccount!: boolean - @Getter(useStore) isRoleStaff!: boolean @Getter(useStore) isTypeCoop!: boolean @Getter(useStore) isTypeFirm!: boolean @Getter(useStore) isTypeSoleProp!: boolean @@ -226,6 +224,7 @@ export default class FilingTemplateMixin extends Mixins(DateMixin) { // restore the amalgamating businesses array if (draftFiling.amalgamation.amalgamatingBusinesses) { this.setAmalgamatingBusinesses(draftFiling.amalgamation.amalgamatingBusinesses) + this.refetchAmalgamatingBusinessesInfo() } // restore the amalgamation court approval