diff --git a/jobs/correction-ben-statement/.env.sample b/jobs/correction-ben-statement/.env.sample
new file mode 100644
index 0000000000..c88f0b4cd3
--- /dev/null
+++ b/jobs/correction-ben-statement/.env.sample
@@ -0,0 +1,14 @@
+# Configuration for running the notebooks. Copy this file to .env and fill in the values.
+ENVIRONMENT=
+ACCOUNT_SVC_AUTH_URL=
+
+# entity notebook service account is used
+ACCOUNT_SVC_CLIENT_ID=
+ACCOUNT_SVC_CLIENT_SECRET=
+
+LEGAL_API_BASE_URL=
+ENTITY_DATABASE_USERNAME=
+ENTITY_DATABASE_PASSWORD=
+ENTITY_DATABASE_HOST=
+ENTITY_DATABASE_NAME=
+ENTITY_DATABASE_PORT=
\ No newline at end of file
diff --git a/jobs/correction-ben-statement/add_corrections_alterations.ipynb b/jobs/correction-ben-statement/add_corrections_alterations.ipynb
index 129683660c..afe6c82f77 100644
--- a/jobs/correction-ben-statement/add_corrections_alterations.ipynb
+++ b/jobs/correction-ben-statement/add_corrections_alterations.ipynb
@@ -24,10 +24,12 @@
"metadata": {},
"outputs": [],
"source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
"import os\n",
"from dotenv import load_dotenv, find_dotenv\n",
- "import psycopg2\n",
- "import pandas as pd\n",
+ "from sqlalchemy import create_engine, text\n",
"\n",
"# this will load all the envars from a .env file located in the project root (api)\n",
"load_dotenv(find_dotenv())\n",
@@ -45,19 +47,11 @@
" os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
" os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
" os.getenv('ENTITY_DATABASE_NAME', '');\n",
- "connect_to_db\n",
- " \n",
- "%sql $connect_to_db"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "%%sql \n",
- "select now() AT TIME ZONE 'PST' as current_date"
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfullyto {os.getenv('ENVIRONMENT', '')}\")"
]
},
{
@@ -67,7 +61,6 @@
"outputs": [],
"source": [
"import requests\n",
- "import os\n",
"from datetime import datetime\n",
"\n",
"# token_url, client_id, client_secret, base_url - update based on environment\n",
@@ -91,6 +84,7 @@
"else:\n",
" print(f\"Failed to make POST request. Status code: {res.status_code}\")\n",
" print(res.text) # Print the error message if the request fails\n",
+ "\n",
"\n"
]
},
@@ -129,82 +123,91 @@
"skipped_identifiers = []\n",
"\n",
"# loop through list of businesses to create filing\n",
- "for identifier in businesses:\n",
- " filing_details = %sql \\\n",
- " SELECT f.id, f.filing_date \\\n",
- " FROM businesses b \\\n",
- " JOIN filings f ON b.id = f.business_id \\\n",
- " WHERE f.filing_type = 'alteration' \\\n",
- " AND f.meta_data->'alteration'->>'fromLegalType' IN ('BC', 'ULC', 'CC', 'C', 'CUL', 'CCC') \\\n",
- " AND f.meta_data->'alteration'->>'toLegalType' IN ('BEN', 'CBEN') \\\n",
- " AND b.identifier = :identifier\n",
- " \n",
- " if filing_details:\n",
- " filing_id = filing_details[0]['id']\n",
- " filing_date = filing_details[0]['filing_date']\n",
- "\n",
- " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
- " \n",
- " draft_details = %sql \\\n",
- " SELECT b.state, \\\n",
- " (SELECT COUNT(1) \\\n",
- " FROM filings f \\\n",
- " WHERE f.business_id = b.id \\\n",
- " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \\\n",
- " FROM businesses b \\\n",
- " WHERE b.identifier = :identifier\n",
- " state = None\n",
- " has_draft = None\n",
- " if draft_details:\n",
- " state = draft_details[0]['state']\n",
- " has_draft = draft_details[0]['has_draft']\n",
- " \n",
- " if state != 'ACTIVE' or has_draft:\n",
- " skipped_identifiers.append(identifier)\n",
- " continue\n",
- " \n",
- " correction_filing_data = {\n",
- " \"filing\": {\n",
- " \"header\": {\n",
- " \"name\": \"correction\",\n",
- " \"date\": current_date,\n",
- " \"certifiedBy\": \"system\",\n",
- " \"correctionBenStatement\": True,\n",
- " \"waiveFees\": True\n",
- " },\n",
- " \"business\": {\n",
- " \"identifier\": identifier,\n",
- " \"legalType\": \"BEN\"\n",
- " },\n",
- " \"correction\": {\n",
- " \"details\": \"BEN Correction statement\",\n",
- " \"correctedFilingId\": filing_id,\n",
- " \"correctedFilingType\": \"alteration\",\n",
- " \"commentOnly\": True,\n",
- " \"comment\": f\"\"\"Correction for Alteration filed on {formatted_filing_date} \\n{correction_statement}\"\"\"\n",
+ "with engine.connect() as conn:\n",
+ " for identifier in businesses:\n",
+ " filing_details_query = text(\"\"\"\n",
+ " SELECT f.id, f.filing_date \n",
+ " FROM businesses b \n",
+ " JOIN filings f ON b.id = f.business_id \n",
+ " WHERE f.filing_type = 'alteration' \n",
+ " AND f.meta_data->'alteration'->>'fromLegalType' IN ('BC', 'ULC', 'CC', 'C', 'CUL', 'CCC') \n",
+ " AND f.meta_data->'alteration'->>'toLegalType' IN ('BEN', 'CBEN') \n",
+ " AND b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " filing_details_query_result = conn.execute(filing_details_query, {\"identifier\": identifier})\n",
+ " filing_details = filing_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " if filing_details:\n",
+ " filing_id = filing_details['id']\n",
+ " filing_date = filing_details['filing_date']\n",
+ "\n",
+ " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
+ " \n",
+ " draft_details_query = text(\"\"\"\n",
+ " SELECT b.state,\n",
+ " (SELECT COUNT(1)\n",
+ " FROM filings f\n",
+ " WHERE f.business_id = b.id\n",
+ " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft\n",
+ " FROM businesses b\n",
+ " WHERE b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " \n",
+ " draft_details_query_result = conn.execute(draft_details_query, {\"identifier\": identifier})\n",
+ " draft_details = draft_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " state = None\n",
+ " has_draft = None\n",
+ " if draft_details:\n",
+ " state = draft_details['state']\n",
+ " has_draft = draft_details['has_draft']\n",
+ " \n",
+ " if state != 'ACTIVE' or has_draft:\n",
+ " skipped_identifiers.append(identifier)\n",
+ " continue\n",
+ " \n",
+ " correction_filing_data = {\n",
+ " \"filing\": {\n",
+ " \"header\": {\n",
+ " \"name\": \"correction\",\n",
+ " \"date\": current_date,\n",
+ " \"certifiedBy\": \"system\",\n",
+ " \"correctionBenStatement\": True,\n",
+ " \"waiveFees\": True\n",
+ " },\n",
+ " \"business\": {\n",
+ " \"identifier\": identifier,\n",
+ " \"legalType\": \"BEN\"\n",
+ " },\n",
+ " \"correction\": {\n",
+ " \"details\": \"BEN Correction statement\",\n",
+ " \"correctedFilingId\": filing_id,\n",
+ " \"correctedFilingType\": \"alteration\",\n",
+ " \"commentOnly\": True,\n",
+ " \"comment\": f\"\"\"Correction for Alteration filed on {formatted_filing_date} \\n{correction_statement}\"\"\"\n",
+ " }\n",
" }\n",
" }\n",
- " }\n",
- "\n",
- " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
- " rv = requests.post(filing_url, headers=headers, json=correction_filing_data)\n",
- "\n",
- " # Check the status code of the response\n",
- " if rv.status_code == 201:\n",
- " correction_filing_id = rv.json()[\"filing\"][\"header\"][\"filingId\"]\n",
- " successful_identifiers.append(identifier)\n",
- " else:\n",
- " failed_identifiers.append(identifier)\n",
- " print(f\"Failed to make POST request. Status code: {rv.status_code}: {rv.text} for {identifier}\")\n",
- "print('Successfully filed Corrections for:', successful_identifiers) # Print the error message if the request fails \n",
- "print('Failed to file Corrections for:', failed_identifiers) # Print the error message if the request fails\n",
- "print('Skipped to file Corrections for:', skipped_identifiers) # Print the skipped identifiers\n"
+ "\n",
+ " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
+ " rv = requests.post(filing_url, headers=headers, json=correction_filing_data)\n",
+ "\n",
+ " # Check the status code of the response\n",
+ " if rv.status_code == 201:\n",
+ " correction_filing_id = rv.json()[\"filing\"][\"header\"][\"filingId\"]\n",
+ " successful_identifiers.append(identifier)\n",
+ " else:\n",
+ " failed_identifiers.append(identifier)\n",
+ " print(f\"Failed to make POST request. Status code: {rv.status_code}: {rv.text} for {identifier}\")\n",
+ " print('Successfully filed Corrections for:', successful_identifiers) # Print the error message if the request fails \n",
+ " print('Failed to file Corrections for:', failed_identifiers) # Print the error message if the request fails\n",
+ " print('Skipped to file Corrections for:', skipped_identifiers) # Print the skipped identifiers\n"
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "3.8.17",
+ "display_name": "3.11.15",
"language": "python",
"name": "python3"
},
@@ -218,7 +221,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.17"
+ "version": "3.11.15"
}
},
"nbformat": 4,
diff --git a/jobs/correction-ben-statement/add_corrections_ia.ipynb b/jobs/correction-ben-statement/add_corrections_ia.ipynb
index dc330cc548..ac2b7d0d09 100644
--- a/jobs/correction-ben-statement/add_corrections_ia.ipynb
+++ b/jobs/correction-ben-statement/add_corrections_ia.ipynb
@@ -20,14 +20,34 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Note: you may need to restart the kernel to use updated packages.\n",
+ "Requirement already satisfied: pandas in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (3.0.1)\n",
+ "Requirement already satisfied: requests in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (2.33.0)\n",
+ "Requirement already satisfied: numpy>=1.26.0 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from pandas) (2.4.3)\n",
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from pandas) (2.9.0.post0)\n",
+ "Requirement already satisfied: charset_normalizer<4,>=2 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from requests) (3.4.6)\n",
+ "Requirement already satisfied: idna<4,>=2.5 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from requests) (3.11)\n",
+ "Requirement already satisfied: urllib3<3,>=1.26 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from requests) (2.6.3)\n",
+ "Requirement already satisfied: certifi>=2023.5.7 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from requests) (2026.2.25)\n",
+ "Requirement already satisfied: six>=1.5 in /home/kdeodhar/.pyenv/versions/3.11.15/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n",
+ "Note: you may need to restart the kernel to use updated packages.\n"
+ ]
+ }
+ ],
"source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
"import os\n",
"from dotenv import load_dotenv, find_dotenv\n",
- "import psycopg2\n",
- "import pandas as pd\n",
+ "from sqlalchemy import create_engine, text\n",
"\n",
"# this will load all the envars from a .env file located in the project root (api)\n",
"load_dotenv(find_dotenv())\n",
@@ -37,37 +57,44 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Connected successfullyto DEV\n"
+ ]
+ }
+ ],
"source": [
"connect_to_db = 'postgresql://' + \\\n",
" os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
" os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
" os.getenv('ENTITY_DATABASE_NAME', '');\n",
- "connect_to_db\n",
- " \n",
- "%sql $connect_to_db"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "%%sql \n",
- "select now() AT TIME ZONE 'PST' as current_date"
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfullyto {os.getenv('ENVIRONMENT', '')}\")"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Access token returned successfully : https://business-api-dev-dy4loprnwa-nn.a.run.app/api/v2\n"
+ ]
+ }
+ ],
"source": [
"import requests\n",
- "import os\n",
"from datetime import datetime\n",
"\n",
"# token_url, client_id, client_secret, base_url - update based on environment\n",
@@ -90,8 +117,7 @@
" token = res.json()[\"access_token\"]\n",
"else:\n",
" print(f\"Failed to make POST request. Status code: {res.status_code}\")\n",
- " print(res.text) # Print the error message if the request fails\n",
- "\n"
+ " print(res.text) # Print the error message if the request fails"
]
},
{
@@ -103,9 +129,19 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Successfully filed Corrections for: ['BC0888396']\n",
+ "Failed to file Corrections for: []\n",
+ "Skipped to file Corrections for: []\n"
+ ]
+ }
+ ],
"source": [
"from urllib.parse import urljoin\n",
"from corrections_output_ia import businesses\n",
@@ -129,80 +165,87 @@
"skipped_identifiers = []\n",
"\n",
"# loop through list of businesses to create filing\n",
- "for identifier in businesses:\n",
- " filing_details = %sql \\\n",
- " SELECT f.id, f.filing_date \\\n",
- " FROM businesses b \\\n",
- " JOIN filings f ON b.id = f.business_id \\\n",
- " WHERE f.filing_type = 'incorporationApplication' \\\n",
- " AND b.identifier = :identifier\n",
- " \n",
- " if filing_details:\n",
- " filing_id = filing_details[0]['id']\n",
- " filing_date = filing_details[0]['filing_date']\n",
- "\n",
- " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
- " \n",
- " draft_details = %sql \\\n",
- " SELECT b.state, \\\n",
- " (SELECT COUNT(1) \\\n",
- " FROM filings f \\\n",
- " WHERE f.business_id = b.id \\\n",
- " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \\\n",
- " FROM businesses b \\\n",
- " WHERE b.identifier = :identifier\n",
- " \n",
- " state = None\n",
- " has_draft = None\n",
- " if draft_details:\n",
- " state = draft_details[0]['state']\n",
- " has_draft = draft_details[0]['has_draft']\n",
- " \n",
- " if state == 'HISTORICAL' or has_draft:\n",
- " skipped_identifiers.append(identifier)\n",
- " continue\n",
- " \n",
- " correction_filing_data = {\n",
- " \"filing\": {\n",
- " \"header\": {\n",
- " \"name\": \"correction\",\n",
- " \"date\": current_date,\n",
- " \"certifiedBy\": \"system\",\n",
- " \"correctionBenStatement\": True,\n",
- " \"waiveFees\": True\n",
- " },\n",
- " \"business\": {\n",
- " \"identifier\": identifier,\n",
- " \"legalType\": \"BEN\"\n",
- " },\n",
- " \"correction\": {\n",
- " \"details\": \"BEN Correction statement\",\n",
- " \"correctedFilingId\": filing_id,\n",
- " \"correctedFilingType\": \"incorporationApplication\",\n",
- " \"commentOnly\": True,\n",
- " \"comment\": f\"\"\"Correction for Incorporation Application filed on {formatted_filing_date} \\n{correction_statement}\"\"\"\n",
+ "with engine.connect() as conn:\n",
+ " for identifier in businesses:\n",
+ " filing_details_query = text(\"\"\"\n",
+ " SELECT f.id, f.filing_date \n",
+ " FROM businesses b \n",
+ " JOIN filings f ON b.id = f.business_id \n",
+ " WHERE f.filing_type = 'incorporationApplication' \n",
+ " AND b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " filing_details_query_result = conn.execute(filing_details_query, {\"identifier\": identifier})\n",
+ " filing_details = filing_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " if filing_details:\n",
+ " filing_id = filing_details['id']\n",
+ " filing_date = filing_details['filing_date']\n",
+ "\n",
+ " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
+ " \n",
+ " draft_details_query = text(\"\"\"\n",
+ " SELECT b.state, \n",
+ " (SELECT COUNT(1) \n",
+ " FROM filings f \n",
+ " WHERE f.business_id = b.id \n",
+ " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \n",
+ " FROM businesses b \n",
+ " WHERE b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " draft_details_query_result = conn.execute(draft_details_query, {\"identifier\": identifier})\n",
+ " draft_details = draft_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " state = None\n",
+ " has_draft = None\n",
+ " if draft_details:\n",
+ " state = draft_details['state']\n",
+ " has_draft = draft_details['has_draft']\n",
+ " \n",
+ " if state == 'HISTORICAL' or has_draft:\n",
+ " skipped_identifiers.append(identifier)\n",
+ " continue\n",
+ " \n",
+ " correction_filing_data = {\n",
+ " \"filing\": {\n",
+ " \"header\": {\n",
+ " \"name\": \"correction\",\n",
+ " \"date\": current_date,\n",
+ " \"certifiedBy\": \"system\",\n",
+ " \"correctionBenStatement\": True,\n",
+ " \"waiveFees\": True\n",
+ " },\n",
+ " \"business\": {\n",
+ " \"identifier\": identifier,\n",
+ " \"legalType\": \"BEN\"\n",
+ " },\n",
+ " \"correction\": {\n",
+ " \"details\": \"BEN Correction statement\",\n",
+ " \"correctedFilingId\": filing_id,\n",
+ " \"correctedFilingType\": \"incorporationApplication\",\n",
+ " \"commentOnly\": True,\n",
+ " \"comment\": f\"\"\"Correction for Incorporation Application filed on {formatted_filing_date} \\n{correction_statement}\"\"\"\n",
+ " }\n",
" }\n",
" }\n",
- " }\n",
- "\n",
- " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
- " rv = requests.post(filing_url, headers=headers, json=correction_filing_data)\n",
- "\n",
- " # Check the status code of the response\n",
- " if rv.status_code == 201:\n",
- " successful_identifiers.append(identifier)\n",
- " else:\n",
- " failed_identifiers.append(identifier)\n",
- " print(f\"Failed to make POST request. Status code: {rv.status_code}: {rv.text} for {identifier}\")\n",
- "print('Successfully filed Corrections for:', successful_identifiers) # Print the successful identifiers\n",
- "print('Failed to file Corrections for:', failed_identifiers) # Print the failed identifiers\n",
- "print('Skipped to file Corrections for:', skipped_identifiers) # Print the skipped identifiers\n"
+ "\n",
+ " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
+ " rv = requests.post(filing_url, headers=headers, json=correction_filing_data)\n",
+ "\n",
+ " # Check the status code of the response\n",
+ " if rv.status_code == 201:\n",
+ " successful_identifiers.append(identifier)\n",
+ " else:\n",
+ " failed_identifiers.append(identifier)\n",
+ " print(f\"Failed to make POST request. Status code: {rv.status_code}: {rv.text} for {identifier}\")\n",
+ " print('Successfully filed Corrections for:', successful_identifiers) # Print the successful identifiers\n",
+ " print('Failed to file Corrections for:', failed_identifiers) # Print the failed identifiers\n",
+ " print('Skipped to file Corrections for:', skipped_identifiers) # Print the skipped identifiers"
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "3.8.17",
+ "display_name": "3.11.15",
"language": "python",
"name": "python3"
},
@@ -216,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.17"
+ "version": "3.11.15"
}
},
"nbformat": 4,
diff --git a/jobs/correction-ben-statement/add_registrars_notation_alteration.ipynb b/jobs/correction-ben-statement/add_registrars_notation_alteration.ipynb
index 24ded64ccf..bcfd0fd2b3 100644
--- a/jobs/correction-ben-statement/add_registrars_notation_alteration.ipynb
+++ b/jobs/correction-ben-statement/add_registrars_notation_alteration.ipynb
@@ -24,10 +24,12 @@
"metadata": {},
"outputs": [],
"source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
"import os\n",
"from dotenv import load_dotenv, find_dotenv\n",
- "import psycopg2\n",
- "import pandas as pd\n",
+ "from sqlalchemy import create_engine, text\n",
"\n",
"# this will load all the envars from a .env file located in the project root (api)\n",
"load_dotenv(find_dotenv())\n",
@@ -45,19 +47,11 @@
" os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
" os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
" os.getenv('ENTITY_DATABASE_NAME', '');\n",
- "connect_to_db\n",
- " \n",
- "%sql $connect_to_db"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "%%sql \n",
- "select now() AT TIME ZONE 'PST' as current_date"
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfullyto {os.getenv('ENVIRONMENT', '')}\")"
]
},
{
@@ -67,7 +61,6 @@
"outputs": [],
"source": [
"import requests\n",
- "import os\n",
"from datetime import datetime\n",
"\n",
"# token_url, client_id, client_secret, base_url - update based on environment\n",
@@ -90,8 +83,7 @@
" token = res.json()[\"access_token\"]\n",
"else:\n",
" print(f\"Failed to make POST request. Status code: {res.status_code}\")\n",
- " print(res.text) # Print the error message if the request fails\n",
- "\n"
+ " print(res.text) # Print the error message if the request fails"
]
},
{
@@ -121,79 +113,87 @@
"skipped_identifiers = []\n",
"\n",
"# loop through list of businesses to create filing\n",
- "for identifier in businesses:\n",
- " filing_details = %sql \\\n",
- " SELECT f.id, f.filing_date \\\n",
- " FROM businesses b \\\n",
- " JOIN filings f ON b.id = f.business_id \\\n",
- " WHERE f.filing_type = 'alteration' \\\n",
- " AND f.meta_data->'alteration'->>'fromLegalType' IN ('BC', 'ULC', 'CC', 'C', 'CUL', 'CCC') \\\n",
- " AND f.meta_data->'alteration'->>'toLegalType' IN ('BEN', 'CBEN') \\\n",
- " AND b.identifier = :identifier\n",
- " \n",
- " if filing_details:\n",
- " filing_id = filing_details[0]['id']\n",
- " filing_date = filing_details[0]['filing_date']\n",
- "\n",
- " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
- " \n",
- " draft_details = %sql \\\n",
- " SELECT b.state, \\\n",
- " (SELECT COUNT(1) \\\n",
- " FROM filings f \\\n",
- " WHERE f.business_id = b.id \\\n",
- " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \\\n",
- " FROM businesses b \\\n",
- " WHERE b.identifier = :identifier\n",
- " \n",
- " if draft_details:\n",
- " state = draft_details[0]['state']\n",
- " has_draft = draft_details[0]['has_draft']\n",
- " \n",
- " if state == 'HISTORICAL' or has_draft:\n",
- " skipped_identifiers.append(identifier)\n",
- " continue\n",
- " \n",
- " filing_data = {\n",
- " \"filing\": {\n",
- " \"header\": {\n",
- " \"name\": \"registrarsNotation\",\n",
- " \"date\": current_date,\n",
- " \"certifiedBy\": \"system\"\n",
- " },\n",
- " \"business\": {\n",
- " \"identifier\": identifier,\n",
- " \"legalType\": \"BEN\"\n",
- " },\n",
- " \"registrarsNotation\": {\n",
- " \"orderDetails\": \"BC benefit company statement contained in notice of articles as required under \" + \n",
- " \"section 51.992 of the Business Corporations Act corrected from \" +\n",
- " \"\\\"This company is a benefit company and, as such, has purposes that include conducting its business \" +\n",
- " \" in a responsible and sustainable manner and promoting one or more public benefits\\\" to \" + \n",
- " \"\\\"This company is a benefit company and, as such, is committed to conducting its business in a \" + \n",
- " \"responsible and sustainable manner and promoting one or more public benefits\\\".\"\n",
+ "with engine.connect() as conn:\n",
+ " for identifier in businesses:\n",
+ " filing_details_query = text(\"\"\"\n",
+ " SELECT f.id, f.filing_date\n",
+ " FROM businesses b\n",
+ " JOIN filings f ON b.id = f.business_id\n",
+ " WHERE f.filing_type = 'alteration'\n",
+ " AND f.meta_data->'alteration'->>'fromLegalType' IN ('BC', 'ULC', 'CC', 'C', 'CUL', 'CCC')\n",
+ " AND f.meta_data->'alteration'->>'toLegalType' IN ('BEN', 'CBEN')\n",
+ " AND b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " filing_details_query_result = conn.execute(filing_details_query, {\"identifier\": identifier})\n",
+ " filing_details = filing_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " if filing_details:\n",
+ " filing_id = filing_details['id']\n",
+ " filing_date = filing_details['filing_date']\n",
+ "\n",
+ " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
+ " \n",
+ " draft_details_query = text(\"\"\"\n",
+ " SELECT b.state,\n",
+ " (SELECT COUNT(1)\n",
+ " FROM filings f\n",
+ " WHERE f.business_id = b.id\n",
+ " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft\n",
+ " FROM businesses b\n",
+ " WHERE b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " \n",
+ " draft_details_query_result = conn.execute(draft_details_query, {\"identifier\": identifier})\n",
+ " draft_details = draft_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " if draft_details:\n",
+ " state = draft_details['state']\n",
+ " has_draft = draft_details['has_draft']\n",
+ " \n",
+ " if state == 'HISTORICAL' or has_draft:\n",
+ " skipped_identifiers.append(identifier)\n",
+ " continue\n",
+ " \n",
+ " filing_data = {\n",
+ " \"filing\": {\n",
+ " \"header\": {\n",
+ " \"name\": \"registrarsNotation\",\n",
+ " \"date\": current_date,\n",
+ " \"certifiedBy\": \"system\"\n",
+ " },\n",
+ " \"business\": {\n",
+ " \"identifier\": identifier,\n",
+ " \"legalType\": \"BEN\"\n",
+ " },\n",
+ " \"registrarsNotation\": {\n",
+ " \"orderDetails\": \"BC benefit company statement contained in notice of articles as required under \" + \n",
+ " \"section 51.992 of the Business Corporations Act corrected from \" +\n",
+ " \"\\\"This company is a benefit company and, as such, has purposes that include conducting its business \" +\n",
+ " \" in a responsible and sustainable manner and promoting one or more public benefits\\\" to \" + \n",
+ " \"\\\"This company is a benefit company and, as such, is committed to conducting its business in a \" + \n",
+ " \"responsible and sustainable manner and promoting one or more public benefits\\\".\"\n",
+ " }\n",
" }\n",
" }\n",
- " }\n",
- "\n",
- " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
- " response = requests.post(filing_url, headers=headers, json=filing_data)\n",
- "\n",
- " # Check the status code of the response\n",
- " if response.status_code == 201:\n",
- " successful_identifiers.append(identifier)\n",
- " else:\n",
- " failed_identifiers.append(identifier)\n",
- " print(f\"Failed to make POST request. Status code: {response.status_code} for {identifier}\")\n",
- "print('Successfully filed Registrar Notation for:', successful_identifiers) # Print the successful identifiers\n",
- "print('Failed to file Registrar Notation for:', failed_identifiers) # Print the failed identifiers\n",
- "print('Skipped to file Registrar Notation for:', skipped_identifiers) # Print the skipped identifiers\n"
+ "\n",
+ " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
+ " response = requests.post(filing_url, headers=headers, json=filing_data)\n",
+ "\n",
+ " # Check the status code of the response\n",
+ " if response.status_code == 201:\n",
+ " successful_identifiers.append(identifier)\n",
+ " else:\n",
+ " failed_identifiers.append(identifier)\n",
+ " print(f\"Failed to make POST request. Status code: {response.status_code} for {identifier}\")\n",
+ " print('Successfully filed Registrar Notation for:', successful_identifiers) # Print the successful identifiers\n",
+ " print('Failed to file Registrar Notation for:', failed_identifiers) # Print the failed identifiers\n",
+ " print('Skipped to file Registrar Notation for:', skipped_identifiers) # Print the skipped identifiers\n"
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "3.8.17",
+ "display_name": "3.11.15",
"language": "python",
"name": "python3"
},
@@ -207,7 +207,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.17"
+ "version": "3.11.15"
}
},
"nbformat": 4,
diff --git a/jobs/correction-ben-statement/add_registrars_notation_historical.ipynb b/jobs/correction-ben-statement/add_registrars_notation_historical.ipynb
index fb5ad05dd3..8b9a43916a 100644
--- a/jobs/correction-ben-statement/add_registrars_notation_historical.ipynb
+++ b/jobs/correction-ben-statement/add_registrars_notation_historical.ipynb
@@ -24,10 +24,12 @@
"metadata": {},
"outputs": [],
"source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
"import os\n",
"from dotenv import load_dotenv, find_dotenv\n",
- "import psycopg2\n",
- "import pandas as pd\n",
+ "from sqlalchemy import create_engine, text\n",
"\n",
"# this will load all the envars from a .env file located in the project root (api)\n",
"load_dotenv(find_dotenv())\n",
@@ -43,11 +45,13 @@
"source": [
"connect_to_db = 'postgresql://' + \\\n",
" os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
- " os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5434') + '/' + \\\n",
+ " os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
" os.getenv('ENTITY_DATABASE_NAME', '');\n",
- "connect_to_db\n",
- " \n",
- "%sql $connect_to_db"
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfullyto {os.getenv('ENVIRONMENT', '')}\")"
]
},
{
@@ -67,7 +71,6 @@
"outputs": [],
"source": [
"import requests\n",
- "import os\n",
"from datetime import datetime\n",
"\n",
"# token_url, client_id, client_secret, base_url - update based on environment\n",
diff --git a/jobs/correction-ben-statement/add_registrars_notation_ia.ipynb b/jobs/correction-ben-statement/add_registrars_notation_ia.ipynb
index 292656df85..ebec795b83 100644
--- a/jobs/correction-ben-statement/add_registrars_notation_ia.ipynb
+++ b/jobs/correction-ben-statement/add_registrars_notation_ia.ipynb
@@ -24,10 +24,12 @@
"metadata": {},
"outputs": [],
"source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
"import os\n",
"from dotenv import load_dotenv, find_dotenv\n",
- "import psycopg2\n",
- "import pandas as pd\n",
+ "from sqlalchemy import create_engine, text\n",
"\n",
"# this will load all the envars from a .env file located in the project root (api)\n",
"load_dotenv(find_dotenv())\n",
@@ -45,19 +47,11 @@
" os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
" os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
" os.getenv('ENTITY_DATABASE_NAME', '');\n",
- "connect_to_db\n",
- " \n",
- "%sql $connect_to_db"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "%%sql \n",
- "select now() AT TIME ZONE 'PST' as current_date"
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfully to {os.getenv('ENVIRONMENT', '')}\")"
]
},
{
@@ -67,7 +61,6 @@
"outputs": [],
"source": [
"import requests\n",
- "import os\n",
"from datetime import datetime\n",
"\n",
"# token_url, client_id, client_secret, base_url - update based on environment\n",
@@ -121,80 +114,87 @@
"skipped_identifiers = []\n",
"\n",
"# loop through list of businesses to create filing\n",
- "for identifier in businesses:\n",
- " filing_details = %sql \\\n",
- " SELECT f.id, f.filing_date \\\n",
- " FROM businesses b \\\n",
- " JOIN filings f ON b.id = f.business_id \\\n",
- " WHERE f.filing_type = 'incorporationApplication' \\\n",
- " AND b.identifier = :identifier\n",
- " \n",
- " if filing_details:\n",
- " filing_id = filing_details[0]['id']\n",
- " filing_date = filing_details[0]['filing_date']\n",
- "\n",
- " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
- " \n",
- " draft_details = %sql \\\n",
- " SELECT b.state, \\\n",
- " (SELECT COUNT(1) \\\n",
- " FROM filings f \\\n",
- " WHERE f.business_id = b.id \\\n",
- " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \\\n",
- " FROM businesses b \\\n",
- " WHERE b.identifier = :identifier\n",
- " \n",
- " state = None\n",
- " has_draft = None\n",
- " \n",
- " if draft_details:\n",
- " state = draft_details[0]['state']\n",
- " has_draft = draft_details[0]['has_draft']\n",
- " \n",
- " if state == 'HISTORICAL' or has_draft:\n",
- " skipped_identifiers.append(identifier)\n",
- " continue\n",
+ "with engine.connect() as conn:\n",
+ " for identifier in businesses:\n",
+ " filing_details_query = text(\"\"\"\n",
+ " SELECT f.id, f.filing_date \n",
+ " FROM businesses b \n",
+ " JOIN filings f ON b.id = f.business_id \n",
+ " WHERE f.filing_type = 'incorporationApplication' \n",
+ " AND b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " filing_details_query_result = conn.execute(filing_details_query, {\"identifier\": identifier})\n",
+ " filing_details = filing_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " if filing_details:\n",
+ " filing_id = filing_details['id']\n",
+ " filing_date = filing_details['filing_date']\n",
+ "\n",
+ " formatted_filing_date = filing_date.strftime(\"%B %d, %Y\")\n",
+ " \n",
+ " draft_details_query = text(\"\"\"\n",
+ " SELECT b.state, \n",
+ " (SELECT COUNT(1) \n",
+ " FROM filings f \n",
+ " WHERE f.business_id = b.id \n",
+ " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \n",
+ " FROM businesses b \n",
+ " WHERE b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " draft_details_query_result = conn.execute(draft_details_query, {\"identifier\": identifier})\n",
+ " draft_details = draft_details_query_result.mappings().fetchone()\n",
+ " \n",
+ " state = None\n",
+ " has_draft = None\n",
+ " \n",
+ " if draft_details:\n",
+ " state = draft_details['state']\n",
+ " has_draft = draft_details['has_draft']\n",
+ " \n",
+ " if state == 'HISTORICAL' or has_draft:\n",
+ " skipped_identifiers.append(identifier)\n",
+ " continue\n",
" \n",
- " filing_data = {\n",
- " \"filing\": {\n",
- " \"header\": {\n",
- " \"name\": \"registrarsNotation\",\n",
- " \"date\": current_date,\n",
- " \"certifiedBy\": \"system\"\n",
- " },\n",
- " \"business\": {\n",
- " \"identifier\": identifier,\n",
- " \"legalType\": \"BEN\"\n",
- " },\n",
- " \"registrarsNotation\": {\n",
- " \"orderDetails\": \"BC benefit company statement contained in notice of articles as required under \" + \n",
- " \"section 51.992 of the Business Corporations Act corrected from \" +\n",
- " \"\\\"This company is a benefit company and, as such, has purposes that include conducting its business \" +\n",
- " \" in a responsible and sustainable manner and promoting one or more public benefits\\\" to \" + \n",
- " \"\\\"This company is a benefit company and, as such, is committed to conducting its business in a \" + \n",
- " \"responsible and sustainable manner and promoting one or more public benefits\\\".\"\n",
+ " filing_data = {\n",
+ " \"filing\": {\n",
+ " \"header\": {\n",
+ " \"name\": \"registrarsNotation\",\n",
+ " \"date\": current_date,\n",
+ " \"certifiedBy\": \"system\"\n",
+ " },\n",
+ " \"business\": {\n",
+ " \"identifier\": identifier,\n",
+ " \"legalType\": \"BEN\"\n",
+ " },\n",
+ " \"registrarsNotation\": {\n",
+ " \"orderDetails\": \"BC benefit company statement contained in notice of articles as required under \" + \n",
+ " \"section 51.992 of the Business Corporations Act corrected from \" +\n",
+ " \"\\\"This company is a benefit company and, as such, has purposes that include conducting its business \" +\n",
+ " \" in a responsible and sustainable manner and promoting one or more public benefits\\\" to \" + \n",
+ " \"\\\"This company is a benefit company and, as such, is committed to conducting its business in a \" + \n",
+ " \"responsible and sustainable manner and promoting one or more public benefits\\\".\"\n",
+ " }\n",
" }\n",
" }\n",
- " }\n",
- "\n",
- " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
- " response = requests.post(filing_url, headers=headers, json=filing_data)\n",
- "\n",
- " # Check the status code of the response\n",
- " if response.status_code == 201:\n",
- " successful_identifiers.append(identifier)\n",
- " else:\n",
- " failed_identifiers.append(identifier)\n",
- " print(f\"Failed to make POST request. Status code: {response.status_code} for {identifier}\")\n",
- "print('Successfully filed Registrar Notation for:', successful_identifiers) # Print the successful identifiers\n",
- "print('Failed to file Registrar Notation for:', failed_identifiers) # Print the failed identifiers\n",
- "print('Skipped to file Registrar Notation for:', skipped_identifiers) # Print the skipped identifiers\n"
+ "\n",
+ " filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n",
+ " response = requests.post(filing_url, headers=headers, json=filing_data)\n",
+ "\n",
+ " # Check the status code of the response\n",
+ " if response.status_code == 201:\n",
+ " successful_identifiers.append(identifier)\n",
+ " else:\n",
+ " failed_identifiers.append(identifier)\n",
+ " print(f\"Failed to make POST request. Status code: {response.status_code} for {identifier}\")\n",
+ " print('Successfully filed Registrar Notation for:', successful_identifiers) # Print the successful identifiers\n",
+ " print('Failed to file Registrar Notation for:', failed_identifiers) # Print the failed identifiers\n",
+ " print('Skipped to file Registrar Notation for:', skipped_identifiers) # Print the skipped identifiers\n"
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "3.8.17",
+ "display_name": "3.11.15",
"language": "python",
"name": "python3"
},
@@ -208,7 +208,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.17"
+ "version": "3.11.15"
}
},
"nbformat": 4,
diff --git a/jobs/correction-ben-statement/altered_to_ben/alt_to_ben_businesses_with_drafts.py b/jobs/correction-ben-statement/altered_to_ben/alt_to_ben_businesses_with_drafts.py
new file mode 100644
index 0000000000..22e0a15a8c
--- /dev/null
+++ b/jobs/correction-ben-statement/altered_to_ben/alt_to_ben_businesses_with_drafts.py
@@ -0,0 +1,3 @@
+businesses = [
+ 'BCXXXXX'
+]
\ No newline at end of file
diff --git a/jobs/correction-ben-statement/altered_to_ben/alt_to_ben_historical_businesses.py b/jobs/correction-ben-statement/altered_to_ben/alt_to_ben_historical_businesses.py
new file mode 100644
index 0000000000..22e0a15a8c
--- /dev/null
+++ b/jobs/correction-ben-statement/altered_to_ben/alt_to_ben_historical_businesses.py
@@ -0,0 +1,3 @@
+businesses = [
+ 'BCXXXXX'
+]
\ No newline at end of file
diff --git a/jobs/correction-ben-statement/altered_to_ben/check_elligible_altered_businesses.ipynb b/jobs/correction-ben-statement/altered_to_ben/check_elligible_altered_businesses.ipynb
new file mode 100644
index 0000000000..268baf340c
--- /dev/null
+++ b/jobs/correction-ben-statement/altered_to_ben/check_elligible_altered_businesses.ipynb
@@ -0,0 +1,167 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "9fe05f61",
+ "metadata": {},
+ "source": [
+ "# Check Altered to BEN elligible businesses by querying the PROD database"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "dbdd7b06",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
+ "import os\n",
+ "from dotenv import load_dotenv, find_dotenv\n",
+ "from sqlalchemy import create_engine, text\n",
+ "\n",
+ "# this will load all the envars from a .env file located in the project root (api)\n",
+ "load_dotenv(find_dotenv())\n",
+ "\n",
+ "%load_ext sql"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5c28660e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "connect_to_db = 'postgresql://' + \\\n",
+ " os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
+ " os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
+ " os.getenv('ENTITY_DATABASE_NAME', '');\n",
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfully to {os.getenv('ENVIRONMENT', '')}\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "dc21ea33",
+ "metadata": {},
+ "source": [
+ "This section checks if any of the DRAFTS are completed and businesses are elligible to run the notebooks\n",
+ "\n",
+ "If business is elligible:\n",
+ "- check if AR is due (check directly in the UI by logging in as Staff).
\n",
+ " - If AR is due, then Correction application cannot be filed. No further action required
\n",
+ " - If no AR due, run Registrar's Notation first with `add_registrars_notation_alteration.ipynb` notebook and then Corrections with `add_corrections_alterations.ipynb`.
\n",
+ "- check if status has changed to HISTORICAL\n",
+ " - no further action"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0ed16109",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from alt_to_ben_businesses_with_drafts import businesses\n",
+ "\n",
+ "elligible_businesses = []\n",
+ "non_elligible_businesses = []\n",
+ "\n",
+ "# loop through list of businesses to create filing\n",
+ "with engine.connect() as conn:\n",
+ " for identifier in businesses:\n",
+ " draft_details_query = text(\"\"\"\n",
+ " SELECT b.state, \n",
+ " (SELECT COUNT(1) \n",
+ " FROM filings f \n",
+ " WHERE f.business_id = b.id \n",
+ " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \n",
+ " FROM businesses b \n",
+ " WHERE b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " draft_details_query_result = conn.execute(draft_details_query, {\"identifier\": identifier})\n",
+ " draft_details = draft_details_query_result.mappings().fetchone()\n",
+ "\n",
+ " if draft_details:\n",
+ " state = draft_details['state']\n",
+ " has_draft = draft_details['has_draft']\n",
+ " \n",
+ " if not has_draft:\n",
+ " elligible_businesses.append((identifier, state))\n",
+ " continue\n",
+ "\n",
+ " if has_draft:\n",
+ " non_elligible_businesses.append((identifier, state))\n",
+ " continue\n",
+ "print('Eligible businesses to file Registrar Notation for:', elligible_businesses)\n",
+ "print('Non-eligible businesses to file Registrar Notation for:', non_elligible_businesses)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "26b6f214",
+ "metadata": {},
+ "source": [
+ "This section checks if any of the HISTORICAL business became ACTIVE\n",
+ "\n",
+ "\n",
+ "\n",
+ "If business becomes ACTIVE:\n",
+ "- check if AR is due (check directly in the UI by logging in as Staff).
\n",
+ " - If AR is due, then Correction application cannot be filed. No further action required
\n",
+ " - If no AR due, run Registrar's Notation first with `add_registrars_notation_alteration.ipynb` notebook and then Corrections with `add_corrections_alterations.ipynb`.
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "990448cc",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from alt_to_ben_historical_businesses import businesses\n",
+ "\n",
+ "elligible_businesses = []\n",
+ "non_elligible_businesses = []\n",
+ "\n",
+ "# loop through list of businesses to create filing\n",
+ "with engine.connect() as conn:\n",
+ " query = text(\"\"\"\n",
+ " SELECT b.identifier, b.state\n",
+ " FROM businesses b\n",
+ " WHERE b.identifier in :businesses\n",
+ " and b.state in ('ACTIVE')\n",
+ " \"\"\")\n",
+ " query_result = conn.execute(query, {\"businesses\": tuple(businesses)})\n",
+ " print('Businesses in historical list which became active:', query_result.fetchall())"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "3.11.15",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.15"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/jobs/correction-ben-statement/inorporated_as_ben/businesses_with_drafts.py b/jobs/correction-ben-statement/inorporated_as_ben/businesses_with_drafts.py
new file mode 100644
index 0000000000..7312ed631e
--- /dev/null
+++ b/jobs/correction-ben-statement/inorporated_as_ben/businesses_with_drafts.py
@@ -0,0 +1,3 @@
+businesses = [
+ 'BCXXXXX', 'BCXXXXX'
+]
\ No newline at end of file
diff --git a/jobs/correction-ben-statement/inorporated_as_ben/check_inc_as_ben_elligible_businesses.ipynb b/jobs/correction-ben-statement/inorporated_as_ben/check_inc_as_ben_elligible_businesses.ipynb
new file mode 100644
index 0000000000..63a1280a1f
--- /dev/null
+++ b/jobs/correction-ben-statement/inorporated_as_ben/check_inc_as_ben_elligible_businesses.ipynb
@@ -0,0 +1,167 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "9fe05f61",
+ "metadata": {},
+ "source": [
+ "# Check Incorporated as BEN elligible businesses by querying the PROD database"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "dbdd7b06",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%pip install -q psycopg2-binary\n",
+ "%pip install pandas requests\n",
+ "\n",
+ "import os\n",
+ "from dotenv import load_dotenv, find_dotenv\n",
+ "from sqlalchemy import create_engine, text\n",
+ "\n",
+ "# this will load all the envars from a .env file located in the project root (api)\n",
+ "load_dotenv(find_dotenv())\n",
+ "\n",
+ "%load_ext sql"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5c28660e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "connect_to_db = 'postgresql://' + \\\n",
+ " os.getenv('ENTITY_DATABASE_USERNAME', '') + \":\" + os.getenv('ENTITY_DATABASE_PASSWORD', '') +'@' + \\\n",
+ " os.getenv('ENTITY_DATABASE_HOST', '') + ':' + os.getenv('ENTITY_DATABASE_PORT', '5432') + '/' + \\\n",
+ " os.getenv('ENTITY_DATABASE_NAME', '');\n",
+ "engine = create_engine(connect_to_db)\n",
+ "\n",
+ "# Test connection\n",
+ "with engine.connect() as conn:\n",
+ " print(f\"Connected successfully to {os.getenv('ENVIRONMENT', '')}\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "dc21ea33",
+ "metadata": {},
+ "source": [
+ "This section checks if any of the DRAFTS are completed and businesses are elligible to run the notebooks\n",
+ "\n",
+ "If business is elligible:\n",
+ "- check if AR is due (check directly in the UI by logging in as Staff).
\n",
+ " - If AR is due, then Correction application cannot be filed. No further action required
\n",
+ " - If no AR due, run Registrar's Notation first with `add_registrars_notation_ia.ipynb` notebook and then Corrections with `add_corrections_ia.ipynb`.
\n",
+ "- check if status has changed to HISTORICAL\n",
+ " - no further action"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0ed16109",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from businesses_with_drafts import businesses\n",
+ "\n",
+ "elligible_businesses = []\n",
+ "non_elligible_businesses = []\n",
+ "\n",
+ "# loop through list of businesses to create filing\n",
+ "with engine.connect() as conn:\n",
+ " for identifier in businesses:\n",
+ " draft_details_query = text(\"\"\"\n",
+ " SELECT b.state, \n",
+ " (SELECT COUNT(1) \n",
+ " FROM filings f \n",
+ " WHERE f.business_id = b.id \n",
+ " AND f.status in ('DRAFT', 'PENDING')) <> 0 AS has_draft \n",
+ " FROM businesses b \n",
+ " WHERE b.identifier = :identifier\n",
+ " \"\"\")\n",
+ " draft_details_query_result = conn.execute(draft_details_query, {\"identifier\": identifier})\n",
+ " draft_details = draft_details_query_result.mappings().fetchone()\n",
+ "\n",
+ " if draft_details:\n",
+ " state = draft_details['state']\n",
+ " has_draft = draft_details['has_draft']\n",
+ " \n",
+ " if not has_draft:\n",
+ " elligible_businesses.append((identifier, state))\n",
+ " continue\n",
+ "\n",
+ " if has_draft:\n",
+ " non_elligible_businesses.append((identifier, state))\n",
+ " continue\n",
+ "print('Eligible businesses to file Registrar Notation for:', elligible_businesses)\n",
+ "print('Non-eligible businesses to file Registrar Notation for:', non_elligible_businesses)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "26b6f214",
+ "metadata": {},
+ "source": [
+ "This section checks if any of the HISTORICAL business became ACTIVE\n",
+ "\n",
+ "\n",
+ "\n",
+ "If business becomes ACTIVE:\n",
+ "- check if AR is due (check directly in the UI by logging in as Staff).
\n",
+ " - If AR is due, then Correction application cannot be filed. No further action required
\n",
+ " - If no AR due, run Registrar's Notation first with `add_registrars_notation_ia.ipynb` notebook and then Corrections with `add_corrections_ia.ipynb`.
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "990448cc",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from historical_businesses import businesses\n",
+ "\n",
+ "elligible_businesses = []\n",
+ "non_elligible_businesses = []\n",
+ "\n",
+ "# loop through list of businesses to create filing\n",
+ "with engine.connect() as conn:\n",
+ " query = text(\"\"\"\n",
+ " SELECT b.identifier, b.state\n",
+ " FROM businesses b\n",
+ " WHERE b.identifier in :businesses\n",
+ " and b.state in ('ACTIVE')\n",
+ " \"\"\")\n",
+ " query_result = conn.execute(query, {\"businesses\": tuple(businesses)})\n",
+ " print('Businesses in historical list which became active:', query_result.fetchall())"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "3.11.15",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.15"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/jobs/correction-ben-statement/inorporated_as_ben/historical_businesses.py b/jobs/correction-ben-statement/inorporated_as_ben/historical_businesses.py
new file mode 100644
index 0000000000..5de2847e27
--- /dev/null
+++ b/jobs/correction-ben-statement/inorporated_as_ben/historical_businesses.py
@@ -0,0 +1,2 @@
+businesses = [
+ 'BCXXXXXX', 'BCXXXXXX']
\ No newline at end of file