diff --git a/queue_services/entity-emailer/requirements.txt b/queue_services/entity-emailer/requirements.txt index 76b04b0d77..61ea0583a9 100644 --- a/queue_services/entity-emailer/requirements.txt +++ b/queue_services/entity-emailer/requirements.txt @@ -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.14#egg=registry_schemas +git+https://github.com/bcgov/business-schemas.git@2.18.17#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 diff --git a/queue_services/entity-emailer/src/entity_emailer/config.py b/queue_services/entity-emailer/src/entity_emailer/config.py index 8c5f703d56..eb36280244 100644 --- a/queue_services/entity-emailer/src/entity_emailer/config.py +++ b/queue_services/entity-emailer/src/entity_emailer/config.py @@ -144,6 +144,7 @@ class _Config(): # pylint: disable=too-few-public-methods CORP_FORMS_URL = os.getenv('CORP_FORMS_URL', '') SOCIETIES_URL = os.getenv('SOCIETIES_URL', '') + class DevConfig(_Config): # pylint: disable=too-few-public-methods """Creates the Development Config object.""" diff --git a/queue_services/entity-emailer/src/entity_emailer/email_processors/agm_extension_notification.py b/queue_services/entity-emailer/src/entity_emailer/email_processors/agm_extension_notification.py new file mode 100644 index 0000000000..67fc046ce6 --- /dev/null +++ b/queue_services/entity-emailer/src/entity_emailer/email_processors/agm_extension_notification.py @@ -0,0 +1,150 @@ +# Copyright © 2023 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 AGM Extension 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 Business, Filing + +from entity_emailer.email_processors import get_filing_info, get_recipient_from_auth, substitute_template_parts + + +def _get_pdfs( + 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 pdfs for the AGM Extension output.""" + pdfs = [] + attach_order = 1 + headers = { + 'Accept': 'application/pdf', + 'Authorization': f'Bearer {token}' + } + + # add filing pdf + filing_pdf = requests.get( + f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}' + '?type=letterOfAgmExtension', 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': 'Letter of AGM Extension Approval.pdf', + 'fileBytes': filing_pdf_encoded.decode('utf-8'), + 'fileUrl': '', + 'attachOrder': attach_order + } + ) + attach_order += 1 + + # add receipt pdf + corp_name = business.get('legalName') + business_data = Business.find_by_internal_id(filing.business_id) + 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_data.tax_id if business_data and business_data.tax_id else '' + }, + 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 + + return pdfs + + +def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, too-many-branches + """Build the email for AGM Extension notification.""" + logger.debug('agm_extension_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")}/AGM-EXT-{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') + + (filing.json)['filing']['business'].get('identifier', ''), + email_header=filing_name.upper(), + filing_type=filing_type + ) + + # get attachments + pdfs = _get_pdfs(token, business, filing, leg_tmz_filing_date, leg_tmz_effective_date) + + # get recipients + identifier = filing.filing_json['filing']['business']['identifier'] + recipients = [] + recipients.append(get_recipient_from_auth(identifier, token)) + + recipients = list(set(recipients)) + recipients = ', '.join(filter(None, recipients)).strip() + + # assign subject + subject = 'AGM Extension Documents from the Business Registry' + + legal_name = business.get('legalName', None) + legal_name = 'Numbered Company' if legal_name.startswith(identifier) else legal_name + subject = f'{legal_name} - {subject}' if legal_name else subject + + return { + 'recipients': recipients, + 'requestBy': 'BCRegistries@gov.bc.ca', + 'content': { + 'subject': subject, + 'body': f'{html_out}', + 'attachments': pdfs + } + } diff --git a/queue_services/entity-emailer/src/entity_emailer/email_processors/nr_notification.py b/queue_services/entity-emailer/src/entity_emailer/email_processors/nr_notification.py index 02f5d8a3f5..cd4a2aa75e 100644 --- a/queue_services/entity-emailer/src/entity_emailer/email_processors/nr_notification.py +++ b/queue_services/entity-emailer/src/entity_emailer/email_processors/nr_notification.py @@ -47,10 +47,12 @@ def __is_colin(legal_type): colin_list = ['CR', 'UL', 'CC', 'XCR', 'XUL', 'RLC'] return legal_type in colin_list + def _is_society(legal_type): - society_list = ['SO', 'XSO'] - return legal_type in society_list - + society_list = ['SO', 'XSO'] + return legal_type in society_list + + def __get_instruction_group(legal_type): if __is_modernized(legal_type): return 'modernized' diff --git a/queue_services/entity-emailer/src/entity_emailer/email_templates/AGM-EXT-COMPLETED.html b/queue_services/entity-emailer/src/entity_emailer/email_templates/AGM-EXT-COMPLETED.html new file mode 100644 index 0000000000..67285d9cf0 --- /dev/null +++ b/queue_services/entity-emailer/src/entity_emailer/email_templates/AGM-EXT-COMPLETED.html @@ -0,0 +1,56 @@ + + +
+
+ [[header.html]]
+
+
+
+ [[20px.html]]
+
+
+
+
+ [[whitespace-16px.html]]
+
+ In response to your request for an AGM extension, please see attached. + + [[whitespace-24px.html]] + [[divider.html]] + [[20px.html]] + + + + [[whitespace-16px.html]] + +The following documents are attached to this email: +
|
+