diff --git a/jobs/notebook-report/config.py b/jobs/notebook-report/config.py index 4ed8a3483..63236af41 100644 --- a/jobs/notebook-report/config.py +++ b/jobs/notebook-report/config.py @@ -35,6 +35,8 @@ class Config(object): NOTEBOOK_SERVICE_ACCOUNT_ID = os.getenv("NOTEBOOK_SERVICE_ACCOUNT_ID", "") NOTEBOOK_SERVICE_ACCOUNT_SECRET = os.getenv("NOTEBOOK_SERVICE_ACCOUNT_SECRET", "") JWT_OIDC_ISSUER = os.getenv("JWT_OIDC_ISSUER", "") + # Used for local dev runs. + DISABLE_EMAIL = os.getenv("DISABLE_EMAIL", 'false').lower() == 'true' PAY_USER = os.getenv("PAY_USER", "") PAY_PASSWORD = os.getenv("PAY_PASSWORD", "") diff --git a/jobs/notebook-report/monthly/reconciliation_summary.ipynb b/jobs/notebook-report/monthly/reconciliation_summary.ipynb index a482b57ec..98cec2a59 100644 --- a/jobs/notebook-report/monthly/reconciliation_summary.ipynb +++ b/jobs/notebook-report/monthly/reconciliation_summary.ipynb @@ -200,20 +200,26 @@ "source": [ "%%sql monthly_reconciliation_summary <<\n", "SELECT\n", - " id as transaction_id,\n", + " i.id as transaction_id,\n", " (created_on AT TIME ZONE 'UTC' AT TIME ZONE 'America/Vancouver')::date AS created_date_pacific,\n", + " created_name,\n", + " created_by,\n", + " pa.auth_account_id as account_number,\n", + " pa.name as account_name,\n", " total,\n", " service_fees,\n", " total - service_fees as subtotal,\n", " payment_method_code,\n", " corp_type_code,\n", - " created_by,\n", " payment_date,\n", " refund_date,\n", " invoice_status_code,\n", - " (select string_agg(quantity || 'x ' || description || ' $' || pli.total , ',') from payment_line_items pli where invoice_id = i.id) as payment_line_items\n", + " folio_number,\n", + " (select string_agg(quantity || 'x - ' || filing_type_code || ' - ' || description || ' - $' || pli.total, ',') from payment_line_items pli JOIN fee_schedules fs on fs.fee_schedule_id = pli.fee_schedule_id where invoice_id = i.id) as payment_line_items\n", "FROM\n", " invoices i\n", + "LEFT JOIN\n", + " payment_accounts pa ON i.payment_account_id = pa.id\n", "WHERE\n", " corp_type_code = :partner_code\n", " AND total > 0\n", @@ -293,8 +299,30 @@ "if partner_code in partners_for_disbursement_summary:\n", " print(f\"Partner code {partner_code} found in the list, executing SQL query.\")\n", " query = f\"\"\"\n", - " SELECT id as transaction_id, disbursement_date::date as disbursement_date_pacific, disbursement_reversal_date::date disbursement_reversal_date_pacific, total, service_fees, total - service_fees as subtotal, payment_method_code, corp_type_code, created_by, disbursement_status_code\n", - " FROM invoices\n", + " SELECT \n", + " i.id as transaction_id,\n", + " (created_on AT TIME ZONE 'UTC' AT TIME ZONE 'America/Vancouver')::date AS created_date_pacific,\n", + " created_name,\n", + " created_by,\n", + " pa.auth_account_id as account_number,\n", + " pa.name as account_name,\n", + " total,\n", + " service_fees,\n", + " total - service_fees as disbursed_amount,\n", + " payment_method_code,\n", + " corp_type_code,\n", + " payment_date,\n", + " refund_date,\n", + " invoice_status_code,\n", + " folio_number,\n", + " disbursement_date::date as disbursement_date_pacific,\n", + " disbursement_reversal_date::date disbursement_reversal_date_pacific,\n", + " disbursement_status_code,\n", + " (select string_agg(quantity || 'x - ' || filing_type_code || ' - ' || description || ' - $' || pli.total , ',') from payment_line_items pli join fee_schedules fs on fs.fee_schedule_id = pli.fee_schedule_id where invoice_id = i.id) as payment_line_items\n", + " FROM \n", + " invoices i\n", + " LEFT JOIN\n", + " payment_accounts pa ON i.payment_account_id = pa.id\n", " WHERE corp_type_code = :partner_code\n", " AND invoice_status_code = 'PAID'\n", " AND payment_method_code in ('PAD','EJV', 'EFT', 'DIRECT_PAY')\n", diff --git a/jobs/notebook-report/notebookreport.py b/jobs/notebook-report/notebookreport.py index 5e242ce28..d0d60c655 100644 --- a/jobs/notebook-report/notebookreport.py +++ b/jobs/notebook-report/notebookreport.py @@ -83,6 +83,8 @@ def send_email(file_processing, emailtype, errormessage, partner_code=None): message.attach(MIMEText("Please see the attachment(s).", "plain")) process_email_attachments(filenames, message) + if Config.DISABLE_EMAIL is True: + return message["Subject"] = subject server = smtplib.SMTP(Config.EMAIL_SMTP) email_list = recipients.strip("][").split(", ")