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

18803 Add amalgamation email #2406

Merged
merged 10 commits into from
Jan 23, 2024
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
2 changes: 1 addition & 1 deletion queue_services/entity-emailer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ webcolors==1.13
Werkzeug==1.0.1
yarl==1.8.2
zipp==3.15.0
git+https://github.com/bcgov/business-schemas.git@2.18.17#egg=registry_schemas
git+https://github.com/bcgov/business-schemas.git@2.18.18#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api
git+https://github.com/bcgov/lear.git#egg=entity_queue_common&subdirectory=queue_services/common
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Email processing rules and actions for Amalgamation notifications."""
from __future__ import annotations

import base64
import re
from http import HTTPStatus
from pathlib import Path

import requests
from entity_queue_common.service_utils import logger
from flask import current_app
from jinja2 import Template
from legal_api.models import Filing

from entity_emailer.email_processors import get_filing_info, get_recipients, substitute_template_parts


def _get_pdfs(
status: str,
token: str,
business: dict,
filing: Filing,
filing_date_time: str,
effective_date: str) -> list:
# pylint: disable=too-many-locals, too-many-branches, too-many-statements, too-many-arguments
"""Get the outputs for the amalgamation notification."""
pdfs = []
attach_order = 1
headers = {
'Accept': 'application/pdf',
'Authorization': f'Bearer {token}'
}

if status == Filing.Status.PAID.value:
# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}',
headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
pdfs.append(
{
'fileName': 'Amalgamation Application.pdf',
'fileBytes': filing_pdf_encoded.decode('utf-8'),
'fileUrl': '',
'attachOrder': attach_order
}
)
attach_order += 1

corp_name = business.get('legalName')
receipt = requests.post(
f'{current_app.config.get("PAY_API_URL")}/{filing.payment_token}/receipts',
json={
'corpName': corp_name,
'filingDateTime': filing_date_time,
'effectiveDateTime': effective_date if effective_date != filing_date_time else '',
'filingIdentifier': str(filing.id),
'businessNumber': business.get('taxId', '')
},
headers=headers
)
if receipt.status_code != HTTPStatus.CREATED:
logger.error('Failed to get receipt pdf for filing: %s', filing.id)
else:
receipt_encoded = base64.b64encode(receipt.content)
pdfs.append(
{
'fileName': 'Receipt.pdf',
'fileBytes': receipt_encoded.decode('utf-8'),
'fileUrl': '',
'attachOrder': attach_order
}
)
attach_order += 1
elif status == Filing.Status.COMPLETED.value:
# add certificate of amalgamation
certificate = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=certificateOfAmalgamation',
headers=headers
)
if certificate.status_code != HTTPStatus.OK:
logger.error('Failed to get corrected registration statement pdf for filing: %s', filing.id)
else:
certificate_encoded = base64.b64encode(certificate.content)
pdfs.append(
{
'fileName': 'Certificate Of Amalgamation.pdf',
'fileBytes': certificate_encoded.decode('utf-8'),
'fileUrl': '',
'attachOrder': attach_order
}
)
attach_order += 1
# add notice of articles
noa = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=noticeOfArticles',
headers=headers
)
if noa.status_code != HTTPStatus.OK:
logger.error('Failed to get noa pdf for filing: %s', filing.id)
else:
noa_encoded = base64.b64encode(noa.content)
pdfs.append(
{
'fileName': 'Notice of Articles.pdf',
'fileBytes': noa_encoded.decode('utf-8'),
'fileUrl': '',
'attachOrder': attach_order
}
)
attach_order += 1
return pdfs


def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches
"""Build the email for Amalgamation notification."""
logger.debug('filing_notification: %s', email_info)
# get template and fill in parts
filing_type, status = email_info['type'], email_info['option']
# get template vars from filing
filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info(email_info['filingId'])
filing_name = filing.filing_type[0].upper() + ' '.join(re.findall('[a-zA-Z][^A-Z]*', filing.filing_type[1:]))

template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/AMALGA-{status}.html').read_text()
filled_template = substitute_template_parts(template)
# render template with vars
jnja_template = Template(filled_template, autoescape=True)
filing_data = (filing.json)['filing'][f'{filing_type}']
html_out = jnja_template.render(
business=business,
filing=filing_data,
header=(filing.json)['filing']['header'],
filing_date_time=leg_tmz_filing_date,
effective_date_time=leg_tmz_effective_date,
entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + business.get('identifier', ''),
email_header=filing_name.upper(),
filing_type=filing_type
)

# get attachments
pdfs = _get_pdfs(status, token, business, filing, leg_tmz_filing_date, leg_tmz_effective_date)

# get recipients
recipients = get_recipients(status, filing.filing_json, token, filing_type)
if not recipients:
return {}

# assign subject
legal_name = business.get('legalName', None)
subject = f'{legal_name} - Amalgamation'
if status == Filing.Status.COMPLETED.value:
subject = f'{legal_name} - Confirmation of Amalgamation'

return {
'recipients': recipients,
'requestBy': 'BCRegistries@gov.bc.ca',
'content': {
'subject': subject,
'body': f'{html_out}',
'attachments': pdfs
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Confirmation of amalgamation</title>
[[style.html]]
</head>

<body>
<table class="body-table" role="presentation">
<tr>
<td>
[[header.html]]

<div class="container">
<p class="title-message bold">
<span>Confirmation of amalgamation<span>
</p>

[[business-information.html]]

<p>The following documents are attached to this email:</p>
<ul class="outputs">
<li>Notice of Articles</li>
<li>Amalgamation Certificate</li>
</ul>

[[business-dashboard-link.html]]
[[whitespace-16px.html]]
[[20px.html]]
[[footer.html]]
</div>
</td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Amalgamation</title>
[[style.html]]
</head>

<body>
<table class="body-table" role="presentation">
<tr>
<td>
[[header.html]]

<div class="container">
<p class="title-message bold">
<span>We have received your incorporation application<span>
</p>

[[business-information.html]]

<p>The following documents are attached to this email:</p>
<ul class="outputs">
<li>Amalgamation Application</li>
<li>Receipt</li>
</ul>

[[business-dashboard-link.html]]

[[whitespace-16px.html]]

<p>On the effective date and time you selected, the business will be registered, and the company will receive the below outputs:</p>
<ul class="outputs">
<li>Notice of Articles</li>
<li>Amalgamation Certificate</li>
</ul>

[[whitespace-16px.html]]
[[20px.html]]
[[footer.html]]
</div>
</td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '2.98.0' # pylint: disable=invalid-name
__version__ = '2.98.1' # pylint: disable=invalid-name
4 changes: 4 additions & 0 deletions queue_services/entity-emailer/src/entity_emailer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
affiliation_notification,
agm_extension_notification,
agm_location_change_notification,
amalgamation_notification,
ar_reminder_notification,
bn_notification,
change_of_registration_notification,
Expand Down Expand Up @@ -183,6 +184,9 @@ def process_email(email_msg: dict, flask_app: Flask): # pylint: disable=too-man
elif etype == 'specialResolution':
email = special_resolution_notification.process(email_msg['email'], token)
send_email(email, token)
elif etype == 'amalgamationApplication':
email = amalgamation_notification.process(email_msg['email'], token)
send_email(email, token)
elif etype in filing_notification.FILING_TYPE_CONVERTER.keys():
if etype == 'annualReport' and option == Filing.Status.COMPLETED.value:
logger.debug('No email to send for: %s', email_msg)
Expand Down
36 changes: 36 additions & 0 deletions queue_services/entity-emailer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
AGM_LOCATION_CHANGE,
ALTERATION,
ALTERATION_FILING_TEMPLATE,
AMALGAMATION_APPLICATION,
ANNUAL_REPORT,
CHANGE_OF_DIRECTORS,
CHANGE_OF_REGISTRATION,
Expand Down Expand Up @@ -622,6 +623,41 @@ def prep_cp_special_resolution_correction_upload_memorandum_filing(session, busi
return filing


def prep_amalgamation_filing(session, identifier, payment_id, option, legal_name):
"""Return a new incorp filing prepped for email notification."""
business = create_business(identifier, legal_type=Business.LegalTypes.BCOMP.value, legal_name=legal_name)
filing_template = copy.deepcopy(FILING_HEADER)
filing_template['filing']['header']['name'] = 'amalgamationApplication'

filing_template['filing']['amalgamationApplication'] = copy.deepcopy(AMALGAMATION_APPLICATION)
filing_template['filing']['business'] = {
'identifier': business.identifier,
'legalType': Business.LegalTypes.BCOMP.value,
'legalName': legal_name
}
filing_template['filing']['business'] = {'identifier': business.identifier}
for party in filing_template['filing']['amalgamationApplication']['parties']:
for role in party['roles']:
if role['roleType'] == 'Completing Party':
party['officer']['email'] = 'comp_party@email.com'
filing_template['filing']['amalgamationApplication']['contactPoint']['email'] = 'test@test.com'

temp_identifier = 'Tb31yQIuBw'
temp_reg = RegistrationBootstrap()
temp_reg._identifier = temp_identifier
temp_reg.save()
filing = create_filing(token=payment_id, filing_json=filing_template,
business_id=business.id, bootstrap_id=temp_identifier)
filing.payment_completion_date = filing.filing_date
filing.save()
if option == Filing.Status.COMPLETED.value:
uow = versioning_manager.unit_of_work(session)
transaction = uow.create_transaction(session)
filing.transaction_id = transaction.id
filing.save()
return filing


class Obj:
"""Make a custom object hook used by dict_to_obj."""

Expand Down
Loading
Loading