Skip to content

Commit

Permalink
Improve the reporting a bit, organize it, add more fields (#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Dec 17, 2024
1 parent 7a0a262 commit 5d60322
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions jobs/notebook-report/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
38 changes: 33 additions & 5 deletions jobs/notebook-report/monthly/reconciliation_summary.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions jobs/notebook-report/notebookreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")
Expand Down

0 comments on commit 5d60322

Please sign in to comment.