diff --git a/reports/README.md b/reports/README.md new file mode 100644 index 00000000..19f8c2b7 --- /dev/null +++ b/reports/README.md @@ -0,0 +1,165 @@ +# KillBill Analytics Reports Setup Script + +This script installs all necessary database DDLs and creates KillBill analytics reports for your KillBill environment. + +--- + +## Table of Contents + +- [Overview](#overview) +- [Prerequisites](#prerequisites) +- [Usage](#usage) +- [Environment Variables](#environment-variables) +- [Script Behavior](#script-behavior) +- [Examples](#examples) +- [Reports List](#reports_list) + + +--- + +## Overview + +This Bash script performs the following tasks: + +1. Installs database DDL files (`.sql` or `.ddl`) into the configured MySQL database. +2. Creates KillBill analytics reports via the KillBill Analytics plugin REST API. +3. Supports optional dropping of existing reports before creation. + +The script recursively installs DDL files, ensuring `v_report_*.ddl` files are installed before corresponding `report_*.ddl` files. If no `v_report_*.ddl` exists in a folder, all `.ddl` files in that folder are installed. + +--- + +## Prerequisites + +- **Bash shell** (Linux, macOS, or Windows Git Bash) +- **MySQL client** installed and accessible in PATH +- KillBill server running with the KillBill Analytics plugin installed +- Appropriate permissions for the MySQL database and KillBill API + +--- + +## Usage + +Run the script from the directory containing your DDL files: + +```bash +./setup_reports.sh +``` + +By default, the script installs DDLs and creates all reports. + +--- + +## Environment Variables + +The script uses environment variables to configure MySQL and KillBill settings. Defaults are provided if variables are not set: + +| Variable | Default | Description | +|--------------------------|--------------------------|---------------------------------------------------------------------------| +| `KILLBILL_HTTP_PROTOCOL` | `http` | KillBill API protocol | +| `KILLBILL_HOST` | `127.0.0.1` | KillBill host | +| `KILLBILL_PORT` | `8080` | KillBill port | +| `KILLBILL_USER` | `admin` | KillBill username | +| `KILLBILL_PASSWORD` | `password` | KillBill password | +| `KILLBILL_API_KEY` | `bob` | KillBill API key | +| `KILLBILL_API_SECRET` | `lazar` | KillBill API secret | +| `MYSQL_HOST` | `127.0.0.1` | MySQL host | +| `MYSQL_USER` | `root` | MySQL user | +| `MYSQL_PASSWORD` | `killbill` | MySQL password | +| `MYSQL_DATABASE` | `killbill` | MySQL database name | +| `INSTALL_DDL` | `true` | Whether to install DDL files (`true` or `false`) | +| `DROP_EXISTING_REPORT` | `true` | Whether to drop existing reports before creating them (`true` or `false`) | + +You can export environment variables before running the script to override defaults: + +```bash +export KILLBILL_HOST=192.168.1.10 +export MYSQL_PASSWORD=mysecret +export INSTALL_DDL=false + +./setup_reports.sh +``` + +--- + +## Script Behavior + +1. **DDL Installation** + - Installs ddl from the `utils` directory first. + - Recursively installs DDLs from the other subdirectories: + - If `v_report_*.ddl` files exist, they are installed first, followed by `report_*.ddl`. + - If no `v_report_*.ddl` exists, all `.ddl` files in the folder are installed. + +2. **Report Creation** + - All reports defined in the `create_all_reports` function are created. + - If `DROP_EXISTING_REPORT=true`, existing reports are deleted before creation. + - Reports are created via the KillBill Analytics plugin REST API. + +--- + +## Examples + +- **Run with default configuration:** + +```bash +./setup_reports.sh +``` + +- **Skip DDL installation:** + +```bash +export INSTALL_DDL=false +./setup_reports.sh +``` + +- **Disable dropping existing reports:** + +```bash +export DROP_EXISTING_REPORT=false +./setup_reports.sh +``` + +- **Override KillBill host and MySQL password:** + +```bash +export KILLBILL_HOST=192.168.1.10 +export MYSQL_PASSWORD=mysecret +./setup_reports.sh +``` + +## Reports List + +The script creates the following reports: + +|Report Name| Underlying Report Table |Report Description| +|--|---------------------------------------|--| +| [accounts_summary](accounts_summary/README.md) | report_accounts_summary |Provides an account summary. Provides details like account balance, account status, currency, etc.| +| [active_by_product_term_monthly](active_by_product_term_monthly/README.md) | report_active_by_product_term_monthly |Compute (at the end of each month) the total number of active subscriptions per product and billing period.| +| [bundles_summary](bundles_summary/README.md) | report_bundles_summary |Provides a subscription bundle summary. Provides details like CTD, plan name, price, for the base subscription in a bundle.| +| [cancellations_daily](cancellations_daily/README.md) | report_cancellations_daily |Compute the total number of cancellations per day per phase.| +| [chargebacks_daily](chargebacks_daily/README.md) | report_chargebacks_daily |Compute the total value (in the reference currency) of chargebacks per day per currency.| +| [conversion-total-dollar-amount](conversion-total-dollar-amount/README.md) | report_conversion-total-dollar-amount |Compute (monthly) the total revenue from subscriptions converting out of trial, grouped by tenant and billing period.| +| [invoice_aging](invoice_aging/README.md) | report_invoice_aging |This report lists all customer invoice aging with remaining balances, breaking them into standard aging buckets and converting amounts to USD for easy comparison.| +| [invoice_aging_no_payment](invoice_aging_no_payment/README.md) | report_invoice_aging_no_payment |This report lists all customer invoices with no payments recorded, categorizing outstanding amounts into standard aging buckets and converting balances into USD for comparison. +| +| [invoice_credits_daily](invoice_credits_daily/README.md) | report_invoice_credits_daily |Total of invoice credits per tenant, per currency and per day.| +| [invoice_credits_monthly](invoice_credits_monthly/README.md) | report_invoice_credits_monthly |Report of all invoice credits from the previous month, showing amounts in both original currency and USD equivalents.| +| [invoice_item_adjustments_daily](invoice_item_adjustments_daily/README.md) | report_invoice_item_adjustments_daily |Total of invoice item adjustments per tenant, per currency and per day.| +| [invoice_item_adjustments_monthly](invoice_item_adjustments_monthly/README.md) | report_invoice_item_adjustments_monthly |Report of all invoice item adjustments from the previous month, showing amounts in both original currency and USD equivalents.| +| [invoice_items_monthly](invoice_items_monthly/README.md) | report_invoice_items_monthly |Report of all invoice items from the previous month, showing amounts in both original currency and USD equivalents.| +| [invoices_balance_daily](invoices_balance_daily/README.md) | report_invoices_balance_daily |Compute the total sum of invoices balance (in the reference currency) per invoice created day. +| +| [invoices_daily](invoices_daily/README.md) | report_invoices_daily |Compute the total invoice amount charged (in the reference currency) per day per currency.| +| [invoices_monthly](invoices_monthly/README.md) | report_invoices_monthly |Report of all invoices from the previous month, showing amounts in both original currency and USD equivalents.| +| [mrr_daily](mrr_daily/README.md) | report_mrr_daily |Computes the total active MRR (monthly recurring revenue), broken down both by product and as a tenant-wide total (ALL) for each tenant and each day.| +| [new_accounts_daily](new_accounts_daily/README.md) | report_new_accounts_daily |Compute the total amount of new accounts created per day for each tenant.| +| [overdue-states-count-daily](overdue-states-count-daily/README.md) | report_overdue-states-count-daily |Count of overdue states per tenant and per day.| +| [payments_monthly](payments_monthly/README.md) | report_payments_monthly |Report of all payments from the previous month, showing amounts in both original currency and USD equivalents.| +| [payments_summary](payments_summary/README.md) | report_payments_summary |Provides payment summary. Provides details like payment_id, amount, etc.| +| [payments_total_daily](payments_total_daily/README.md) | report_payments_total_daily |Compute the total value (in the reference currency) of payments per day per currency.| +| [refunds-monthly](refunds-monthly/README.md) | report_refunds-monthly |Report of all refunds from the previous month, showing amounts in both original currency and USD equivalents.| +| [refunds_total_daily](refunds_total_daily/README.md) | report_refunds_total_daily |Compute the total value (in the reference currency) of refunds per day per currency for each tenant.| +| [subscribers-vs-non-subscribers](subscribers-vs-non-subscribers/README.md) | report_subscribers-vs-non-subscribers |Compute the total number of active (i.e. with at least one active subscription) and non-active accounts per tenant.| +| [trial-starts-count-daily](trial-starts-count-daily/README.md) | report_trial-starts-count-daily |Count of new trial subscriptions per tenant, per day and per product.| +| [trial-to-no-trial-conversions_daily](trial-to-no-trial-conversions_daily/README.md) | report_trial-to-no-trial-conversions_daily |Count of subscriptions converting from trial to non-trial per tenant per day.| + diff --git a/reports/accounts_summary/README.md b/reports/accounts_summary/README.md index 029e971e..8c83c977 100644 --- a/reports/accounts_summary/README.md +++ b/reports/accounts_summary/README.md @@ -1,10 +1,10 @@ -# Accounts summary report +# Accounts Summary Report Provides an account summary. Provides details like account balance, account status, currency, etc. The snapshot view is: `v_report_accounts_summary` -## Pie chart configuration +## Report Creation ``` curl -v \ @@ -15,9 +15,15 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_accounts_summary", "reportType": "TABLE", - "reportPrettyName": "Accounts summary", + "reportPrettyName": "Accounts Summary", "sourceTableName": "report_accounts_summary", "refreshProcedureName": "refresh_report_accounts_summary", "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## Report UI: + +![accounts-summary.png](accounts-summary.png) + + diff --git a/reports/accounts_summary/accounts-summary.png b/reports/accounts_summary/accounts-summary.png new file mode 100644 index 00000000..198607e3 Binary files /dev/null and b/reports/accounts_summary/accounts-summary.png differ diff --git a/reports/accounts_summary/v_report_account_summary.ddl b/reports/accounts_summary/v_report_accounts_summary.ddl similarity index 100% rename from reports/accounts_summary/v_report_account_summary.ddl rename to reports/accounts_summary/v_report_accounts_summary.ddl diff --git a/src/main/resources/reports/active_by_product_term_monthly/README.md b/reports/active_by_product_term_monthly/README.md similarity index 51% rename from src/main/resources/reports/active_by_product_term_monthly/README.md rename to reports/active_by_product_term_monthly/README.md index 6ce2bfbb..4cc33f94 100644 --- a/src/main/resources/reports/active_by_product_term_monthly/README.md +++ b/reports/active_by_product_term_monthly/README.md @@ -1,10 +1,10 @@ -# Monthly active subscriptions report +# Monthly Active Subscriptions Report Compute (at the end of each month) the total number of active subscriptions per product and billing period. The snapshot view is: `v_report_active_by_product_term_monthly` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -18,9 +18,23 @@ curl -v \ "reportPrettyName": "Monthly Active Subscriptions by Product Term", "sourceTableName": "report_active_by_product_term_monthly", "refreshProcedureName": "refresh_active_by_product_term_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## Sample Data + +| tenant_record_id | day | product_name | billing_period | count | +|------------------|------------|--------------|----------------|-------| +| 1 | 2025-08-31 | Gold | MONTHLY | 3 | +| 2 | 2025-08-31 | Gold | MONTHLY | 1 | +| 1 | 2025-08-31 | Gold | ANNUAL | 2 | +| 2 | 2025-09-30 | Silver | MONTHLY | 4 | +| 2 | 2025-09-30 | Gold | QUARTERLY | 1 | + +The first row in the above table indicates that on `2025-08-31` the `tenant_record_id=1` had 3 Monthly subscriptions for the `Gold` product. + + + ## Report UI: ![monthly-active-subs-by-product-term.png](monthly-active-subs-by-product-term.png) \ No newline at end of file diff --git a/src/main/resources/reports/active_by_product_term_monthly/monthly-active-subs-by-product-term.png b/reports/active_by_product_term_monthly/monthly-active-subs-by-product-term.png similarity index 100% rename from src/main/resources/reports/active_by_product_term_monthly/monthly-active-subs-by-product-term.png rename to reports/active_by_product_term_monthly/monthly-active-subs-by-product-term.png diff --git a/src/main/resources/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl b/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl similarity index 100% rename from src/main/resources/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl rename to reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl diff --git a/src/main/resources/reports/active_by_product_term_monthly/v_report_active_by_product_term_monthly.ddl b/reports/active_by_product_term_monthly/v_report_active_by_product_term_monthly.ddl similarity index 100% rename from src/main/resources/reports/active_by_product_term_monthly/v_report_active_by_product_term_monthly.ddl rename to reports/active_by_product_term_monthly/v_report_active_by_product_term_monthly.ddl diff --git a/reports/bundles_summary/README.md b/reports/bundles_summary/README.md index f96c8447..91eb6619 100644 --- a/reports/bundles_summary/README.md +++ b/reports/bundles_summary/README.md @@ -4,7 +4,7 @@ Provides a subscription bundle summary. Provides details like CTD, plan name, pr The snapshot view is: `v_report_bundles_summary` -## Pie chart configuration +## Report Creation ``` curl -v \ @@ -15,9 +15,13 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_bundles_summary", "reportType": "TABLE", - "reportPrettyName": "Bundles summary", + "reportPrettyName": "Bundles Summary", "sourceTableName": "report_bundles_summary", "refreshProcedureName": "refresh_report_bundles_summary", "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## Report UI: + +![bundles-summary.png](bundles-summary.png) \ No newline at end of file diff --git a/reports/bundles_summary/bundles-summary.png b/reports/bundles_summary/bundles-summary.png new file mode 100644 index 00000000..b6a3e683 Binary files /dev/null and b/reports/bundles_summary/bundles-summary.png differ diff --git a/src/main/resources/reports/cancellations_daily/README.md b/reports/cancellations_daily/README.md similarity index 50% rename from src/main/resources/reports/cancellations_daily/README.md rename to reports/cancellations_daily/README.md index 9c1787e5..a3cd9985 100644 --- a/src/main/resources/reports/cancellations_daily/README.md +++ b/reports/cancellations_daily/README.md @@ -1,10 +1,10 @@ -# Daily cancellations report +# Daily Cancellations Report Compute the total number of cancellations per day per phase. The snapshot view is: `v_report_cancellations_daily` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -18,9 +18,22 @@ curl -v \ "reportPrettyName": "Daily Cancellations", "sourceTableName": "report_cancellations_daily", "refreshProcedureName": "refresh_report_cancellations_daily", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## Sample Data + +| tenant_record_id | phase | day | count | +|------------------|-----------|------------|-------| +| 1 | EVERGREEN | 2025-09-10 | 9 | +| 1 | EVERGREEN | 2025-09-03 | 2 | +| 1 | EVERGREEN | 2025-09-22 | 5 | +| 2 | EVERGREEN | 2025-09-23 | 6 | +| 2 | EVERGREEN | 2025-09-24 | 6 | +| 1 | EVERGREEN | 2025-09-25 | 1 | + +The first row in the above table indicates that on `2025-09-10`, the `tenant_record_id=1` had 9 cancellations in `EVERGREEN` phase. + ## Report UI: ![daily-cancellations.png](daily-cancellations.png) \ No newline at end of file diff --git a/src/main/resources/reports/cancellations_daily/daily-cancellations.png b/reports/cancellations_daily/daily-cancellations.png similarity index 100% rename from src/main/resources/reports/cancellations_daily/daily-cancellations.png rename to reports/cancellations_daily/daily-cancellations.png diff --git a/src/main/resources/reports/cancellations_daily/report_cancellations_daily.ddl b/reports/cancellations_daily/report_cancellations_daily.ddl similarity index 100% rename from src/main/resources/reports/cancellations_daily/report_cancellations_daily.ddl rename to reports/cancellations_daily/report_cancellations_daily.ddl diff --git a/src/main/resources/reports/cancellations_daily/v_report_cancellations_daily.ddl b/reports/cancellations_daily/v_report_cancellations_daily.ddl similarity index 100% rename from src/main/resources/reports/cancellations_daily/v_report_cancellations_daily.ddl rename to reports/cancellations_daily/v_report_cancellations_daily.ddl diff --git a/reports/chargebacks_daily/README.md b/reports/chargebacks_daily/README.md new file mode 100644 index 00000000..374c788a --- /dev/null +++ b/reports/chargebacks_daily/README.md @@ -0,0 +1,40 @@ +# Daily Chargebacks Report + +Compute the total value (in the reference currency) of chargebacks per day per currency. + +The snapshot view is: `v_report_chargebacks_daily` + +## Report Creation + +``` +curl -v \ + -X POST \ + -u admin:password \ + -H "X-Killbill-ApiKey:bob" \ + -H "X-Killbill-ApiSecret:lazar" \ + -H 'Content-Type: application/json' \ + -d '{"reportName": "report_chargebacks_daily", + "reportType": "TIMELINE", + "reportPrettyName": "Daily Chargebacks Value", + "sourceTableName": "report_chargebacks_daily", + "refreshProcedureName": "refresh_report_chargebacks_daily", + "refreshFrequency": "HOURLY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Sample Data + +| tenant_record_id | day | currency | count | +|------------------|------------|----------|----------| +| 1 | 2025-09-18 | USD | 100.0000 | +| 1 | 2025-09-26 | USD | 50.0000 | +| 2 | 2025-09-11 | USD | 100.0000 | + +The first row in the above table indicates that on `2025-09-18`, the `tenant_record_id=1` had a total chargeback value of `$100` + + +## Report UI: + +![chargebacks-daily.png](chargebacks-daily.png) + + diff --git a/reports/chargebacks_daily/chargebacks-daily.png b/reports/chargebacks_daily/chargebacks-daily.png new file mode 100644 index 00000000..abf8e3d2 Binary files /dev/null and b/reports/chargebacks_daily/chargebacks-daily.png differ diff --git a/src/main/resources/reports/chargebacks_daily/report_chargebacks_daily.ddl b/reports/chargebacks_daily/report_chargebacks_daily.ddl similarity index 100% rename from src/main/resources/reports/chargebacks_daily/report_chargebacks_daily.ddl rename to reports/chargebacks_daily/report_chargebacks_daily.ddl diff --git a/src/main/resources/reports/chargebacks_daily/v_report_chargebacks_daily.ddl b/reports/chargebacks_daily/v_report_chargebacks_daily.ddl similarity index 87% rename from src/main/resources/reports/chargebacks_daily/v_report_chargebacks_daily.ddl rename to reports/chargebacks_daily/v_report_chargebacks_daily.ddl index 2580c78c..01cccd1c 100644 --- a/src/main/resources/reports/chargebacks_daily/v_report_chargebacks_daily.ddl +++ b/reports/chargebacks_daily/v_report_chargebacks_daily.ddl @@ -3,7 +3,7 @@ select ac.tenant_record_id , date_format(ac.created_date,'%Y-%m-%d') as day , ac.currency -, sum(ac.converted_amount) as count +, sum(ac.amount) as count from analytics_payment_chargebacks ac where 1=1 diff --git a/src/main/resources/reports/conversion-total-dollar-amount/README.md b/reports/conversion-total-dollar-amount/README.md similarity index 71% rename from src/main/resources/reports/conversion-total-dollar-amount/README.md rename to reports/conversion-total-dollar-amount/README.md index cad736e4..a89de416 100644 --- a/src/main/resources/reports/conversion-total-dollar-amount/README.md +++ b/reports/conversion-total-dollar-amount/README.md @@ -4,7 +4,7 @@ Compute (monthly) the total revenue from subscriptions converting out of trial, The snapshot view is: `v_report_conversions_total_dollar_monthly` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -18,7 +18,7 @@ curl -v \ "reportPrettyName": "Conversions Total Dollar Amount", "sourceTableName": "report_conversions_total_dollar_monthly", "refreshProcedureName": "refresh_report_conversions_total_dollar_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` @@ -32,7 +32,7 @@ curl -v \ |6| 2025-01-01 |ANNUAL|200| |1| 2025-04-01 |MONTHLY|30| -Here day represents the first day of the month representing that subscription's conversion month. So if the subscription converts from TRIAL to EVERGREEN phase on `2025-04-15`, the day will be `2025-04-01`. +Here `day` represents the first day of the month representing that subscription's conversion month. So if the subscription converts from TRIAL to EVERGREEN phase on `2025-04-15`, the `day` value will be `2025-04-01`. The first row in the above table indicates that in the month of June, a revenue of `$30` was generated when `WEEKLY` subscriptions moved out of `TRIAL` phase. ## Report UI: diff --git a/src/main/resources/reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png b/reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png similarity index 100% rename from src/main/resources/reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png rename to reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png diff --git a/src/main/resources/reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl b/reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl similarity index 100% rename from src/main/resources/reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl rename to reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl diff --git a/src/main/resources/reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl b/reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl similarity index 100% rename from src/main/resources/reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl rename to reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl diff --git a/src/main/resources/reports/invoice_aging/README.md b/reports/invoice_aging/README.md similarity index 95% rename from src/main/resources/reports/invoice_aging/README.md rename to reports/invoice_aging/README.md index c50631b2..178cc0a6 100644 --- a/src/main/resources/reports/invoice_aging/README.md +++ b/reports/invoice_aging/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Invoice Aging Report", "sourceTableName": "report_invoice_aging", "refreshProcedureName": "refresh_report_invoice_aging", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/invoice_aging/invoice-aging.png b/reports/invoice_aging/invoice-aging.png similarity index 100% rename from src/main/resources/reports/invoice_aging/invoice-aging.png rename to reports/invoice_aging/invoice-aging.png diff --git a/src/main/resources/reports/invoice_aging/report_invoice_aging.ddl b/reports/invoice_aging/report_invoice_aging.ddl similarity index 100% rename from src/main/resources/reports/invoice_aging/report_invoice_aging.ddl rename to reports/invoice_aging/report_invoice_aging.ddl diff --git a/src/main/resources/reports/invoice_aging/v_report_invoice_aging.ddl b/reports/invoice_aging/v_report_invoice_aging.ddl similarity index 100% rename from src/main/resources/reports/invoice_aging/v_report_invoice_aging.ddl rename to reports/invoice_aging/v_report_invoice_aging.ddl diff --git a/src/main/resources/reports/invoice_aging_no_payment/README.md b/reports/invoice_aging_no_payment/README.md similarity index 96% rename from src/main/resources/reports/invoice_aging_no_payment/README.md rename to reports/invoice_aging_no_payment/README.md index 76daefd9..dff5c681 100644 --- a/src/main/resources/reports/invoice_aging_no_payment/README.md +++ b/reports/invoice_aging_no_payment/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Invoice Aging No Payments Report", "sourceTableName": "report_invoice_aging_no_payment", "refreshProcedureName": "refresh_report_invoice_aging_no_payment", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/invoice_aging_no_payment/invoice-aging-no-payment.png b/reports/invoice_aging_no_payment/invoice-aging-no-payment.png similarity index 100% rename from src/main/resources/reports/invoice_aging_no_payment/invoice-aging-no-payment.png rename to reports/invoice_aging_no_payment/invoice-aging-no-payment.png diff --git a/src/main/resources/reports/invoice_aging_no_payment/report_invoice_aging_no_payment.ddl b/reports/invoice_aging_no_payment/report_invoice_aging_no_payment.ddl similarity index 100% rename from src/main/resources/reports/invoice_aging_no_payment/report_invoice_aging_no_payment.ddl rename to reports/invoice_aging_no_payment/report_invoice_aging_no_payment.ddl diff --git a/src/main/resources/reports/invoice_aging_no_payment/v_report_invoice_aging_no_payment.ddl b/reports/invoice_aging_no_payment/v_report_invoice_aging_no_payment.ddl similarity index 100% rename from src/main/resources/reports/invoice_aging_no_payment/v_report_invoice_aging_no_payment.ddl rename to reports/invoice_aging_no_payment/v_report_invoice_aging_no_payment.ddl diff --git a/src/main/resources/reports/invoice_credits_daily/README.md b/reports/invoice_credits_daily/README.md similarity index 86% rename from src/main/resources/reports/invoice_credits_daily/README.md rename to reports/invoice_credits_daily/README.md index 24e1dc2a..d323c0d8 100644 --- a/src/main/resources/reports/invoice_credits_daily/README.md +++ b/reports/invoice_credits_daily/README.md @@ -6,7 +6,7 @@ So if there is an unpaid invoice for `$20` on `2025-09-22`, and an account credi The snapshot view is: [v_report_invoice_item_credits_daily](v_report_invoice_item_credits_daily.ddl) -## Timeline configuration +## Report Creation ``` curl -v \ @@ -20,7 +20,7 @@ curl -v \ "reportPrettyName": "Invoice Credits Daily", "sourceTableName": "report_invoice_credits_daily", "refreshProcedureName": "refresh_report_invoice_credits_daily", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` @@ -28,13 +28,12 @@ curl -v \ | Tenant Record Id | Currency | Day | Count | |------------------|----------|------------|----------| -| 1 | USD | 2025-05-05 | 0.0000 | | 1 | USD | 2025-09-19 | 80.0000 | | 22 | USD | 2025-09-19 | 125.0000 | | 22 | EUR | 2025-09-22 | 45.0000 | | 22 | USD | 2025-09-18 | -10.0000 | -This means that on `2025-09-19`, there was a total invoice credit of `$80` for the tenant_record_id=1. +The first row in the above table indicates that on `2025-09-19`, there was a total invoice credit of `$80` for the tenant_record_id=1. ## Report UI: diff --git a/src/main/resources/reports/invoice_credits_daily/invoice-credits-daily.png b/reports/invoice_credits_daily/invoice-credits-daily.png similarity index 100% rename from src/main/resources/reports/invoice_credits_daily/invoice-credits-daily.png rename to reports/invoice_credits_daily/invoice-credits-daily.png diff --git a/src/main/resources/reports/invoice_credits_daily/report_invoice_credits_daily.ddl b/reports/invoice_credits_daily/report_invoice_credits_daily.ddl similarity index 100% rename from src/main/resources/reports/invoice_credits_daily/report_invoice_credits_daily.ddl rename to reports/invoice_credits_daily/report_invoice_credits_daily.ddl diff --git a/src/main/resources/reports/invoice_credits_daily/v_report_invoice_credits_daily.ddl b/reports/invoice_credits_daily/v_report_invoice_credits_daily.ddl similarity index 100% rename from src/main/resources/reports/invoice_credits_daily/v_report_invoice_credits_daily.ddl rename to reports/invoice_credits_daily/v_report_invoice_credits_daily.ddl diff --git a/src/main/resources/reports/invoice_credits_monthly/README.md b/reports/invoice_credits_monthly/README.md similarity index 96% rename from src/main/resources/reports/invoice_credits_monthly/README.md rename to reports/invoice_credits_monthly/README.md index d888b94e..24472ed8 100644 --- a/src/main/resources/reports/invoice_credits_monthly/README.md +++ b/reports/invoice_credits_monthly/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Invoice Credits Monthly Report", "sourceTableName": "report_invoice_credits_monthly", "refreshProcedureName": "refresh_report_invoice_credits_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/invoice_credits_monthly/invoice-credits-monthly.png b/reports/invoice_credits_monthly/invoice-credits-monthly.png similarity index 100% rename from src/main/resources/reports/invoice_credits_monthly/invoice-credits-monthly.png rename to reports/invoice_credits_monthly/invoice-credits-monthly.png diff --git a/src/main/resources/reports/invoice_credits_monthly/report_invoice_credits_monthly.ddl b/reports/invoice_credits_monthly/report_invoice_credits_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoice_credits_monthly/report_invoice_credits_monthly.ddl rename to reports/invoice_credits_monthly/report_invoice_credits_monthly.ddl diff --git a/src/main/resources/reports/invoice_credits_monthly/v_report_invoice_credits_monthly.ddl b/reports/invoice_credits_monthly/v_report_invoice_credits_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoice_credits_monthly/v_report_invoice_credits_monthly.ddl rename to reports/invoice_credits_monthly/v_report_invoice_credits_monthly.ddl diff --git a/src/main/resources/reports/invoice_item_adjustments_daily/README.md b/reports/invoice_item_adjustments_daily/README.md similarity index 89% rename from src/main/resources/reports/invoice_item_adjustments_daily/README.md rename to reports/invoice_item_adjustments_daily/README.md index 11d12fdb..fa1143a8 100644 --- a/src/main/resources/reports/invoice_item_adjustments_daily/README.md +++ b/reports/invoice_item_adjustments_daily/README.md @@ -6,7 +6,7 @@ So if there is an invoice for `$100` created on `2025-09-21` and the invoice is The snapshot view is: [v_report_invoice_item_adjustments_daily](v_report_invoice_item_adjustments_daily.ddl) -## Timeline configuration +## Report Creation ``` curl -v \ @@ -20,7 +20,7 @@ curl -v \ "reportPrettyName": "Invoice Item Adjustments Daily", "sourceTableName": "report_invoice_item_adjustments_daily", "refreshProcedureName": "refresh_report_invoice_item_adjustments_daily", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` @@ -38,7 +38,7 @@ curl -v \ | 1 | USD | 2025-09-19 | -19.3100 | | 489 | USD | 2025-09-19 | -10.0000 | -This means that on the date `2025-08-28`, the tenant with record id=1 had a total invoice adjustments of EUR 10. +The first row in the above table indicates that on the date `2025-08-28`, the tenant with record id=1 had a total invoice adjustments of EUR 10. ## Report UI: diff --git a/src/main/resources/reports/invoice_item_adjustments_daily/invoice_item_adjustments_daily.png b/reports/invoice_item_adjustments_daily/invoice_item_adjustments_daily.png similarity index 100% rename from src/main/resources/reports/invoice_item_adjustments_daily/invoice_item_adjustments_daily.png rename to reports/invoice_item_adjustments_daily/invoice_item_adjustments_daily.png diff --git a/src/main/resources/reports/invoice_item_adjustments_daily/report_invoice_item_adjustments_daily.ddl b/reports/invoice_item_adjustments_daily/report_invoice_item_adjustments_daily.ddl similarity index 100% rename from src/main/resources/reports/invoice_item_adjustments_daily/report_invoice_item_adjustments_daily.ddl rename to reports/invoice_item_adjustments_daily/report_invoice_item_adjustments_daily.ddl diff --git a/src/main/resources/reports/invoice_item_adjustments_daily/v_report_invoice_item_adjustments_daily.ddl b/reports/invoice_item_adjustments_daily/v_report_invoice_item_adjustments_daily.ddl similarity index 87% rename from src/main/resources/reports/invoice_item_adjustments_daily/v_report_invoice_item_adjustments_daily.ddl rename to reports/invoice_item_adjustments_daily/v_report_invoice_item_adjustments_daily.ddl index a6bd536b..ac67709d 100644 --- a/src/main/resources/reports/invoice_item_adjustments_daily/v_report_invoice_item_adjustments_daily.ddl +++ b/reports/invoice_item_adjustments_daily/v_report_invoice_item_adjustments_daily.ddl @@ -3,7 +3,7 @@ select aiia.tenant_record_id , aiia.currency , date_format(aiia.created_date,'%Y-%m-%d') as day -, sum(aiia.converted_amount) as count +, sum(aiia.amount) as count from analytics_invoice_item_adjustments aiia where 1=1 diff --git a/src/main/resources/reports/invoice_item_adjustments_monthly/README.md b/reports/invoice_item_adjustments_monthly/README.md similarity index 96% rename from src/main/resources/reports/invoice_item_adjustments_monthly/README.md rename to reports/invoice_item_adjustments_monthly/README.md index 62f06eab..a540971b 100644 --- a/src/main/resources/reports/invoice_item_adjustments_monthly/README.md +++ b/reports/invoice_item_adjustments_monthly/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Invoice Item Adjustments Monthly Report", "sourceTableName": "report_invoice_item_adjustments_monthly", "refreshProcedureName": "refresh_report_invoice_item_adjustments_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/invoice_item_adjustments_monthly/invoice-item-adjustments-monthly.png b/reports/invoice_item_adjustments_monthly/invoice-item-adjustments-monthly.png similarity index 100% rename from src/main/resources/reports/invoice_item_adjustments_monthly/invoice-item-adjustments-monthly.png rename to reports/invoice_item_adjustments_monthly/invoice-item-adjustments-monthly.png diff --git a/src/main/resources/reports/invoice_item_adjustments_monthly/report_invoice_item_adjustments_monthly.ddl b/reports/invoice_item_adjustments_monthly/report_invoice_item_adjustments_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoice_item_adjustments_monthly/report_invoice_item_adjustments_monthly.ddl rename to reports/invoice_item_adjustments_monthly/report_invoice_item_adjustments_monthly.ddl diff --git a/src/main/resources/reports/invoice_item_adjustments_monthly/v_report_invoice_item_adjustments_monthly.ddl b/reports/invoice_item_adjustments_monthly/v_report_invoice_item_adjustments_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoice_item_adjustments_monthly/v_report_invoice_item_adjustments_monthly.ddl rename to reports/invoice_item_adjustments_monthly/v_report_invoice_item_adjustments_monthly.ddl diff --git a/src/main/resources/reports/invoice_items_monthly/README.md b/reports/invoice_items_monthly/README.md similarity index 95% rename from src/main/resources/reports/invoice_items_monthly/README.md rename to reports/invoice_items_monthly/README.md index 52c715d5..8da1c735 100644 --- a/src/main/resources/reports/invoice_items_monthly/README.md +++ b/reports/invoice_items_monthly/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Invoice Items Monthly Report", "sourceTableName": "report_invoice_items_monthly", "refreshProcedureName": "refresh_report_invoice_items_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/invoice_items_monthly/invoice-items-monthly.png b/reports/invoice_items_monthly/invoice-items-monthly.png similarity index 100% rename from src/main/resources/reports/invoice_items_monthly/invoice-items-monthly.png rename to reports/invoice_items_monthly/invoice-items-monthly.png diff --git a/src/main/resources/reports/invoice_items_monthly/report_invoice_items_monthly.ddl b/reports/invoice_items_monthly/report_invoice_items_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoice_items_monthly/report_invoice_items_monthly.ddl rename to reports/invoice_items_monthly/report_invoice_items_monthly.ddl diff --git a/src/main/resources/reports/invoice_items_monthly/v_report_invoice_items_monthly.ddl b/reports/invoice_items_monthly/v_report_invoice_items_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoice_items_monthly/v_report_invoice_items_monthly.ddl rename to reports/invoice_items_monthly/v_report_invoice_items_monthly.ddl diff --git a/src/main/resources/reports/invoices_balance_daily/README.md b/reports/invoices_balance_daily/README.md similarity index 53% rename from src/main/resources/reports/invoices_balance_daily/README.md rename to reports/invoices_balance_daily/README.md index fd80acc0..914bf8c8 100644 --- a/src/main/resources/reports/invoices_balance_daily/README.md +++ b/reports/invoices_balance_daily/README.md @@ -1,10 +1,10 @@ -# Daily invoices balance report +# Daily Invoice Balance Report Compute the total sum of invoices balance (in the reference currency) per invoice created day. The snapshot view is: `v_report_invoices_balance_daily` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -18,9 +18,23 @@ curl -v \ "reportPrettyName": "Daily Invoices Balance", "sourceTableName": "report_invoices_balance_daily", "refreshProcedureName": "refresh_report_invoices_balance_daily", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## Sample Data + +| tenant_record_id | currency | day | count | +|------------------|----------|------------|---------| +| 1 | EUR | 2025-09-15 | 15.0000 | +| 1 | EUR | 2025-09-01 | 0.0000 | +| 1 | USD | 2025-09-15 | 42.9000 | +| 2 | USD | 2025-09-02 | 59.5000 | +| 2 | EUR | 2025-09-16 | 0.0000 | + + +The first row in the above table indicates that on the date `2025-09-15`, the tenant with record id=1 had a total invoice balance of EUR 15. + ## Report UI: ![invoice-balance-daily.png](invoice-balance-daily.png) \ No newline at end of file diff --git a/reports/invoices_balance_daily/invoice-balance-daily.png b/reports/invoices_balance_daily/invoice-balance-daily.png new file mode 100644 index 00000000..1dc78e5f Binary files /dev/null and b/reports/invoices_balance_daily/invoice-balance-daily.png differ diff --git a/src/main/resources/reports/invoices_balance_daily/report_invoices_balance_daily.ddl b/reports/invoices_balance_daily/report_invoices_balance_daily.ddl similarity index 100% rename from src/main/resources/reports/invoices_balance_daily/report_invoices_balance_daily.ddl rename to reports/invoices_balance_daily/report_invoices_balance_daily.ddl diff --git a/src/main/resources/reports/invoices_balance_daily/v_report_invoices_balance_daily.ddl b/reports/invoices_balance_daily/v_report_invoices_balance_daily.ddl similarity index 78% rename from src/main/resources/reports/invoices_balance_daily/v_report_invoices_balance_daily.ddl rename to reports/invoices_balance_daily/v_report_invoices_balance_daily.ddl index 7f60ffbc..35539cce 100644 --- a/src/main/resources/reports/invoices_balance_daily/v_report_invoices_balance_daily.ddl +++ b/reports/invoices_balance_daily/v_report_invoices_balance_daily.ddl @@ -1,11 +1,12 @@ create or replace view v_report_invoices_balance_daily as select ai.tenant_record_id +, ai.currency , date_format(ai.created_date,'%Y-%m-%d') as day -, sum(ai.converted_balance) as count +, sum(ai.balance) as count from analytics_invoices ai where 1=1 and ai.report_group='default' -group by 1,2 +group by 1,2,3 ; \ No newline at end of file diff --git a/reports/invoices_daily/README.md b/reports/invoices_daily/README.md new file mode 100644 index 00000000..6a7cb73f --- /dev/null +++ b/reports/invoices_daily/README.md @@ -0,0 +1,44 @@ +# Daily Invoices Report + +Compute the total invoice amount charged (in the reference currency) per day per currency. + +The snapshot view is: `v_report_invoices_daily` + +## Report Creation + +``` +curl -v \ + -X POST \ + -u admin:password \ + -H "X-Killbill-ApiKey:bob" \ + -H "X-Killbill-ApiSecret:lazar" \ + -H 'Content-Type: application/json' \ + -d '{"reportName": "report_invoices_daily", + "reportType": "TIMELINE", + "reportPrettyName": "Daily Invoices Value", + "sourceTableName": "report_invoices_daily", + "refreshProcedureName": "refresh_report_invoices_daily", + "refreshFrequency": "HOURLY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Sample Data + +| ID | Date | Currency | Amount | +|-----|------------|----------|-----------| +| 1 | 2025-09-05 | USD | 579.0700 | +| 1 | 2025-09-19 | USD | 728.4000 | +| 1 | 2025-09-22 | USD | 100.0000 | +| 489 | 2025-09-21 | USD | 250.0000 | +| 1 | 2025-09-25 | EUR | 59.9500 | +| 359 | 2025-09-25 | USD | 1009.3000 | +| 1 | 2025-09-11 | USD | 516.9500 | +| 1 | 2025-09-28 | EUR | 0.0000 | +| 359 | 2025-09-28 | USD | 356.6900 | + +The first row in the above table indicates that on the date `2025-09-05`, the tenant with record id=1 had a total invoice value of USD 579.0700. + + +## Report UI: + +![invoice-amount-daily.png](invoice-amount-daily.png) \ No newline at end of file diff --git a/reports/invoices_daily/invoice-amount-daily.png b/reports/invoices_daily/invoice-amount-daily.png new file mode 100644 index 00000000..6e05eeea Binary files /dev/null and b/reports/invoices_daily/invoice-amount-daily.png differ diff --git a/src/main/resources/reports/invoices_daily/report_invoices_daily.ddl b/reports/invoices_daily/report_invoices_daily.ddl similarity index 100% rename from src/main/resources/reports/invoices_daily/report_invoices_daily.ddl rename to reports/invoices_daily/report_invoices_daily.ddl diff --git a/src/main/resources/reports/invoices_daily/v_report_invoices_daily.ddl b/reports/invoices_daily/v_report_invoices_daily.ddl similarity index 81% rename from src/main/resources/reports/invoices_daily/v_report_invoices_daily.ddl rename to reports/invoices_daily/v_report_invoices_daily.ddl index af1a9153..ae6c0251 100644 --- a/src/main/resources/reports/invoices_daily/v_report_invoices_daily.ddl +++ b/reports/invoices_daily/v_report_invoices_daily.ddl @@ -3,7 +3,7 @@ select ai.tenant_record_id , date_format(ai.created_date,'%Y-%m-%d') as day , ai.currency -, sum(ai.converted_original_amount_charged) as count +, sum(ai.original_amount_charged) as count from analytics_invoices ai where 1=1 diff --git a/src/main/resources/reports/invoices_monthly/README.md b/reports/invoices_monthly/README.md similarity index 95% rename from src/main/resources/reports/invoices_monthly/README.md rename to reports/invoices_monthly/README.md index a6199c39..30541b85 100644 --- a/src/main/resources/reports/invoices_monthly/README.md +++ b/reports/invoices_monthly/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Invoices Monthly Report", "sourceTableName": "report_invoices_monthly", "refreshProcedureName": "refresh_report_invoices_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/invoices_monthly/invoices-monthly.png b/reports/invoices_monthly/invoices-monthly.png similarity index 100% rename from src/main/resources/reports/invoices_monthly/invoices-monthly.png rename to reports/invoices_monthly/invoices-monthly.png diff --git a/src/main/resources/reports/invoices_monthly/report_invoices_monthly.ddl b/reports/invoices_monthly/report_invoices_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoices_monthly/report_invoices_monthly.ddl rename to reports/invoices_monthly/report_invoices_monthly.ddl diff --git a/src/main/resources/reports/invoices_monthly/v_report_invoices_monthly.ddl b/reports/invoices_monthly/v_report_invoices_monthly.ddl similarity index 100% rename from src/main/resources/reports/invoices_monthly/v_report_invoices_monthly.ddl rename to reports/invoices_monthly/v_report_invoices_monthly.ddl diff --git a/reports/mrr_daily/README.md b/reports/mrr_daily/README.md new file mode 100644 index 00000000..e8d4bd04 --- /dev/null +++ b/reports/mrr_daily/README.md @@ -0,0 +1,41 @@ +# Daily MRR + +Computes the total active MRR (monthly recurring revenue), broken down both by product and as a tenant-wide total (ALL) for each tenant and each day. + +The snapshot view is: `v_report_mrr_daily` + +## Report Creation + +``` +curl -v \ + -X POST \ + -u admin:password \ + -H "X-Killbill-ApiKey:bob" \ + -H "X-Killbill-ApiSecret:lazar" \ + -H 'Content-Type: application/json' \ + -d '{"reportName": "report_mrr_daily", + "reportType": "TIMELINE", + "reportPrettyName": "Daily MRR", + "sourceTableName": "report_mrr_daily", + "refreshProcedureName": "refresh_report_mrr_daily", + "refreshFrequency": "HOURLY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Sample Data + +| tenant_record_id | currency | product | day | count | +|------------------|----------|---------------|------------|----------| +| 1 | USD | Pistol | 2025-08-07 | 224.6292 | +| 1 | USD | Blowdart | 2025-08-07 | 29.9500 | +| 1 | EUR | Knife | 2025-08-07 | 29.9500 | +| 1 | USD | Assault-Rifle | 2025-08-07 | 499.9958 | +| 2 | USD | Pistol | 2025-08-07 | 100.0000 | +| 2 | USD | All | 2025-08-07 | 100.0000 | + + +The first row in the above table indicates that on the date `2025-08-07`, the MRR for the `Pistol` product was $150 for `tenant_record_id=1`. + +## Report UI: + +![daily-mrr.png](daily-mrr.png) \ No newline at end of file diff --git a/src/main/resources/reports/mrr/daily-mrr.png b/reports/mrr_daily/daily-mrr.png similarity index 100% rename from src/main/resources/reports/mrr/daily-mrr.png rename to reports/mrr_daily/daily-mrr.png diff --git a/src/main/resources/reports/mrr/report_mrr_daily.ddl b/reports/mrr_daily/report_mrr_daily.ddl similarity index 100% rename from src/main/resources/reports/mrr/report_mrr_daily.ddl rename to reports/mrr_daily/report_mrr_daily.ddl diff --git a/src/main/resources/reports/mrr/v_report_mrr_daily.ddl b/reports/mrr_daily/v_report_mrr_daily.ddl similarity index 88% rename from src/main/resources/reports/mrr/v_report_mrr_daily.ddl rename to reports/mrr_daily/v_report_mrr_daily.ddl index bf64697d..5937a0fb 100644 --- a/src/main/resources/reports/mrr/v_report_mrr_daily.ddl +++ b/reports/mrr_daily/v_report_mrr_daily.ddl @@ -1,9 +1,10 @@ create or replace view v_report_mrr_daily as select ast.tenant_record_id +, ast.next_currency as currency , ifnull(ast.next_product_name, ast.prev_product_name) as product , date_format(cal.d,'%Y-%m-%d') as day -, sum(ast.converted_next_mrr) as count +, sum(ast.next_mrr) as count from calendar cal left join analytics_subscription_transitions ast on cast(date_format(ast.next_start_date, '%Y-%m-%d') as date) <= cast(date_format(cal.d, '%Y-%m-%d') as date) @@ -13,12 +14,13 @@ where 1=1 and ast.report_group='default' and ast.next_service='entitlement-service' and ifnull(ast.next_mrr, 0) > 0 -group by 1,2,3 +group by 1,2,3,4 union select ast.tenant_record_id +, ast.next_currency as currency , 'ALL' as product , date_format(cal.d,'%Y-%m-%d') as day -, sum(ast.converted_next_mrr) as count +, sum(ast.next_mrr) as count from calendar cal left join analytics_subscription_transitions ast on cast(date_format(ast.next_start_date, '%Y-%m-%d') as date) <= cast(date_format(cal.d, '%Y-%m-%d') as date) @@ -28,5 +30,5 @@ where 1=1 and ast.report_group='default' and ast.next_service='entitlement-service' and ifnull(ast.next_mrr, 0) > 0 -group by 1,2,3 -; +group by 1,2,3,4 +; \ No newline at end of file diff --git a/src/main/resources/reports/new_accounts_daily/README.md b/reports/new_accounts_daily/README.md similarity index 63% rename from src/main/resources/reports/new_accounts_daily/README.md rename to reports/new_accounts_daily/README.md index e410b52e..39b97121 100644 --- a/src/main/resources/reports/new_accounts_daily/README.md +++ b/reports/new_accounts_daily/README.md @@ -1,10 +1,10 @@ -# Daily new accounts report +# Daily New Accounts Report Compute the total amount of new accounts created per day for each tenant. The snapshot view is: `v_report_new_accounts_daily` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -22,6 +22,21 @@ curl -v \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## Sample Data + +| ID | Date | Value | +|----|------------|-------| +| 1 | 2025-09-18 | 4 | +| 1 | 2025-09-19 | 4 | +| 2 | 2025-09-19 | 4 | +| 1 | 2025-09-21 | 1 | +| 2 | 2025-09-21 | 1 | +| 1 | 2025-09-22 | 1 | + + +The first row in the above table indicates that on the date `2025-09-18`, the tenant with record id=1 had 4 new accounts created. + + ## Report UI: ![daily-new-accounts.png](daily-new-accounts.png) diff --git a/src/main/resources/reports/new_accounts_daily/daily-new-accounts.png b/reports/new_accounts_daily/daily-new-accounts.png similarity index 100% rename from src/main/resources/reports/new_accounts_daily/daily-new-accounts.png rename to reports/new_accounts_daily/daily-new-accounts.png diff --git a/src/main/resources/reports/new_accounts_daily/report_new_accounts_daily.ddl b/reports/new_accounts_daily/report_new_accounts_daily.ddl similarity index 100% rename from src/main/resources/reports/new_accounts_daily/report_new_accounts_daily.ddl rename to reports/new_accounts_daily/report_new_accounts_daily.ddl diff --git a/src/main/resources/reports/new_accounts_daily/v_report_new_accounts_daily.ddl b/reports/new_accounts_daily/v_report_new_accounts_daily.ddl similarity index 100% rename from src/main/resources/reports/new_accounts_daily/v_report_new_accounts_daily.ddl rename to reports/new_accounts_daily/v_report_new_accounts_daily.ddl diff --git a/src/main/resources/reports/overdue-states-count-daily/README.md b/reports/overdue-states-count-daily/README.md similarity index 89% rename from src/main/resources/reports/overdue-states-count-daily/README.md rename to reports/overdue-states-count-daily/README.md index e377e89b..075a235d 100644 --- a/src/main/resources/reports/overdue-states-count-daily/README.md +++ b/reports/overdue-states-count-daily/README.md @@ -4,7 +4,7 @@ Count of overdue states per tenant and per day. The snapshot view is: [v_report_overdue_states_count_daily](v_report_overdue_states_count_daily.ddl) -## Timeline configuration +## Report Creation ``` curl -v \ @@ -34,7 +34,8 @@ curl -v \ | 23 | BLOCKED | 2025-09-19 | 7 | | 45 | CANCELLATION | 2025-09-19 | 5 | -This means that on `2025-09-15`, 5 accounts were in `BLOCKED` overdue state for the tenant_record_id=1. + +The first row in the above table indicates that on the date `2025-09-15`, the tenant with record id=1 had 5 accounts in the `BLOCKED` overdue state. ## Report UI: diff --git a/src/main/resources/reports/overdue-states-count-daily/overdue-states-count-daily.png b/reports/overdue-states-count-daily/overdue-states-count-daily.png similarity index 100% rename from src/main/resources/reports/overdue-states-count-daily/overdue-states-count-daily.png rename to reports/overdue-states-count-daily/overdue-states-count-daily.png diff --git a/src/main/resources/reports/overdue-states-count-daily/report_overdue_states_count_daily.ddl b/reports/overdue-states-count-daily/report_overdue_states_count_daily.ddl similarity index 100% rename from src/main/resources/reports/overdue-states-count-daily/report_overdue_states_count_daily.ddl rename to reports/overdue-states-count-daily/report_overdue_states_count_daily.ddl diff --git a/src/main/resources/reports/overdue-states-count-daily/v_report_overdue_states_count_daily.ddl b/reports/overdue-states-count-daily/v_report_overdue_states_count_daily.ddl similarity index 100% rename from src/main/resources/reports/overdue-states-count-daily/v_report_overdue_states_count_daily.ddl rename to reports/overdue-states-count-daily/v_report_overdue_states_count_daily.ddl diff --git a/src/main/resources/reports/payments_monthly/README.md b/reports/payments_monthly/README.md similarity index 95% rename from src/main/resources/reports/payments_monthly/README.md rename to reports/payments_monthly/README.md index 2b44f716..aa72ab93 100644 --- a/src/main/resources/reports/payments_monthly/README.md +++ b/reports/payments_monthly/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Payments Monthly Report", "sourceTableName": "report_payments_monthly", "refreshProcedureName": "refresh_report_payments_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/payments_monthly/payments-monthly.png b/reports/payments_monthly/payments-monthly.png similarity index 100% rename from src/main/resources/reports/payments_monthly/payments-monthly.png rename to reports/payments_monthly/payments-monthly.png diff --git a/src/main/resources/reports/payments_monthly/report_payments_monthly.ddl b/reports/payments_monthly/report_payments_monthly.ddl similarity index 100% rename from src/main/resources/reports/payments_monthly/report_payments_monthly.ddl rename to reports/payments_monthly/report_payments_monthly.ddl diff --git a/src/main/resources/reports/payments_monthly/v_report_payments_monthly.ddl b/reports/payments_monthly/v_report_payments_monthly.ddl similarity index 100% rename from src/main/resources/reports/payments_monthly/v_report_payments_monthly.ddl rename to reports/payments_monthly/v_report_payments_monthly.ddl diff --git a/reports/payments_summary/README.md b/reports/payments_summary/README.md index 8d02c88c..81e7b9fd 100644 --- a/reports/payments_summary/README.md +++ b/reports/payments_summary/README.md @@ -4,7 +4,7 @@ Provides payment summary. Provides details like payment_id, amount, etc. The snapshot view is: `v_report_payments_summary` -## Pie chart configuration +## Report Creation ``` curl -v \ @@ -15,9 +15,13 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_payments_summary", "reportType": "TABLE", - "reportPrettyName": "Payments summary", + "reportPrettyName": "Payments Summary", "sourceTableName": "report_payments_summary", "refreshProcedureName": "refresh_report_payments_summary", "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## Report UI: + +![payments-summary.png](payments-summary.png) \ No newline at end of file diff --git a/reports/payments_summary/payments-summary.png b/reports/payments_summary/payments-summary.png new file mode 100644 index 00000000..d85d23ff Binary files /dev/null and b/reports/payments_summary/payments-summary.png differ diff --git a/reports/payments_summary/v_payments_summary.ddl b/reports/payments_summary/v_report_payments_summary.ddl similarity index 100% rename from reports/payments_summary/v_payments_summary.ddl rename to reports/payments_summary/v_report_payments_summary.ddl diff --git a/src/main/resources/reports/payments_total_daily/README.md b/reports/payments_total_daily/README.md similarity index 50% rename from src/main/resources/reports/payments_total_daily/README.md rename to reports/payments_total_daily/README.md index 0f806f57..44c44a08 100644 --- a/src/main/resources/reports/payments_total_daily/README.md +++ b/reports/payments_total_daily/README.md @@ -1,10 +1,10 @@ -# Daily payments report +# Daily Payments Report -Compute the total value (in the reference currency) of captured payments per day per currency. +Compute the total value (in the reference currency) of payments per day per currency. The snapshot view is: `v_report_payments_total_daily` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -22,6 +22,18 @@ curl -v \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## Sample Data + +| tenant_record_id | day | currency | amount | +|------------------|------------|----------|----------| +| 1 | 2025-05-01 | USD | 49.9000 | +| 1 | 2025-05-05 | USD | 26.0900 | +| 1 | 2025-05-05 | EUR | 79.8500 | +| 2 | 2025-07-03 | USD | 229.6000 | +| 2 | 2025-07-20 | EUR | 379.9000 | + +The first row in the above table indicates that on the date `2025-05-01`, the tenant with record id=1 had a total payment value of USD 49.9. + ## Report UI: ![payments-total-daily.png](payments-total-daily.png) \ No newline at end of file diff --git a/src/main/resources/reports/payments_total_daily/payments-total-daily.png b/reports/payments_total_daily/payments-total-daily.png similarity index 100% rename from src/main/resources/reports/payments_total_daily/payments-total-daily.png rename to reports/payments_total_daily/payments-total-daily.png diff --git a/src/main/resources/reports/payments_total_daily/report_payments_total_daily.ddl b/reports/payments_total_daily/report_payments_total_daily.ddl similarity index 100% rename from src/main/resources/reports/payments_total_daily/report_payments_total_daily.ddl rename to reports/payments_total_daily/report_payments_total_daily.ddl diff --git a/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl b/reports/payments_total_daily/v_report_payments_total_daily.ddl similarity index 86% rename from src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl rename to reports/payments_total_daily/v_report_payments_total_daily.ddl index c43a4b2e..1f90fd06 100644 --- a/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl +++ b/reports/payments_total_daily/v_report_payments_total_daily.ddl @@ -3,13 +3,13 @@ select tenant_record_id, date_format(created_date,'%Y-%m-%d') as day, currency, - sum(ifnull(converted_amount, 0)) as count + sum(ifnull(amount, 0)) as count from ( select ac.tenant_record_id, ac.created_date, ac.currency, - ac.converted_amount + ac.amount from analytics_payment_captures ac where ac.payment_transaction_status = 'SUCCESS' and ac.report_group='default' @@ -20,7 +20,7 @@ from ( ap.tenant_record_id, ap.created_date, ap.currency, - ap.converted_amount + ap.amount from analytics_payment_purchases ap where ap.payment_transaction_status = 'SUCCESS' and ap.report_group='default' diff --git a/src/main/resources/reports/refunds-monthly/README.md b/reports/refunds-monthly/README.md similarity index 95% rename from src/main/resources/reports/refunds-monthly/README.md rename to reports/refunds-monthly/README.md index 40b5fd51..19415169 100644 --- a/src/main/resources/reports/refunds-monthly/README.md +++ b/reports/refunds-monthly/README.md @@ -22,7 +22,7 @@ curl -v \ "reportPrettyName": "Refunds Monthly Report", "sourceTableName": "report_refunds_monthly", "refreshProcedureName": "refresh_report_refunds_monthly", - "refreshFrequency": "DAILY"}' \ + "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` diff --git a/src/main/resources/reports/refunds-monthly/refunds-monthly.png b/reports/refunds-monthly/refunds-monthly.png similarity index 100% rename from src/main/resources/reports/refunds-monthly/refunds-monthly.png rename to reports/refunds-monthly/refunds-monthly.png diff --git a/src/main/resources/reports/refunds-monthly/report_refunds_monthly.ddl b/reports/refunds-monthly/report_refunds_monthly.ddl similarity index 100% rename from src/main/resources/reports/refunds-monthly/report_refunds_monthly.ddl rename to reports/refunds-monthly/report_refunds_monthly.ddl diff --git a/src/main/resources/reports/refunds-monthly/v_report_refunds_monthly.ddl b/reports/refunds-monthly/v_report_refunds_monthly.ddl similarity index 100% rename from src/main/resources/reports/refunds-monthly/v_report_refunds_monthly.ddl rename to reports/refunds-monthly/v_report_refunds_monthly.ddl diff --git a/src/main/resources/reports/refunds_total_daily/README.md b/reports/refunds_total_daily/README.md similarity index 61% rename from src/main/resources/reports/refunds_total_daily/README.md rename to reports/refunds_total_daily/README.md index 34513365..19d1a81d 100644 --- a/src/main/resources/reports/refunds_total_daily/README.md +++ b/reports/refunds_total_daily/README.md @@ -1,10 +1,10 @@ -# Daily refunds report +# Daily Refunds Report Compute the total value (in the reference currency) of refunds per day per currency for each tenant. The snapshot view is: `v_report_refunds_total_daily` -## Timeline configuration +## Report Creation ``` curl -v \ @@ -22,6 +22,18 @@ curl -v \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## Sample Data + +| ID | Date | Currency | Amount | +|----|------------|----------|----------| +| 1 | 2025-09-02 | USD | 119.0000 | +| 1 | 2025-08-04 | USD | 29.9500 | +| 1 | 2025-08-04| EUR | 199.4000 | +| 2 | 2025-07-03 | USD | 29.9500 | +| 2 | 2025-09-18 | EUR | 15.0000 | + +The first row in the above table indicates that on the date `2025-09-02`, the tenant with record id=1 had a total refund value of USD 119. + ## Report UI: ![refunds-total-daily.png](refunds-total-daily.png) diff --git a/src/main/resources/reports/refunds_total_daily/refunds-total-daily.png b/reports/refunds_total_daily/refunds-total-daily.png similarity index 100% rename from src/main/resources/reports/refunds_total_daily/refunds-total-daily.png rename to reports/refunds_total_daily/refunds-total-daily.png diff --git a/src/main/resources/reports/refunds_total_daily/report_refunds_total_daily.ddl b/reports/refunds_total_daily/report_refunds_total_daily.ddl similarity index 100% rename from src/main/resources/reports/refunds_total_daily/report_refunds_total_daily.ddl rename to reports/refunds_total_daily/report_refunds_total_daily.ddl diff --git a/src/main/resources/reports/refunds_total_daily/v_report_refunds_total_daily.ddl b/reports/refunds_total_daily/v_report_refunds_total_daily.ddl similarity index 81% rename from src/main/resources/reports/refunds_total_daily/v_report_refunds_total_daily.ddl rename to reports/refunds_total_daily/v_report_refunds_total_daily.ddl index 04b86804..34965f49 100644 --- a/src/main/resources/reports/refunds_total_daily/v_report_refunds_total_daily.ddl +++ b/reports/refunds_total_daily/v_report_refunds_total_daily.ddl @@ -3,7 +3,7 @@ select ar.tenant_record_id , date_format(ar.created_date,'%Y-%m-%d') as day , ar.currency as currency -, sum(abs(ar.converted_invoice_amount_refunded)) as count +, sum(abs(ar.invoice_amount_refunded)) as count from analytics_payment_refunds ar where 1=1 diff --git a/reports/reports_setup.sh b/reports/reports_setup.sh new file mode 100644 index 00000000..7851913b --- /dev/null +++ b/reports/reports_setup.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +# +# Copyright 2020-2025 Equinix, Inc +# Copyright 2014-2025 The Billing Project, LLC +# +# The Billing Project licenses this file to you 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. +# + +HERE=`cd \`dirname $0\`; pwd` + +KILLBILL_HTTP_PROTOCOL=${KILLBILL_HTTP_PROTOCOL-"http"} +KILLBILL_HOST=${KILLBILL_HOST-"127.0.0.1"} +KILLBILL_PORT=${KILLBILL_PORT-"8080"} + +KILLBILL_USER=${KILLBILL_USER-"admin"} +KILLBILL_PASSWORD=${KILLBILL_PASSWORD-"password"} +KILLBILL_API_KEY=${KILLBILL_API_KEY-"bob"} +KILLBILL_API_SECRET=${KILLBILL_API_SECRET-"lazar"} + +MYSQL_HOST=${MYSQL_HOST-"127.0.0.1"} +MYSQL_USER=${MYSQL_USER-"root"} +MYSQL_PASSWORD=${MYSQL_PASSWORD-"killbill"} +MYSQL_DATABASE=${MYSQL_DATABASE-"killbill"} +INSTALL_DDL=true +DROP_EXISTING_REPORT=false + +REPORTS=$HERE + +function install_ddl() { + local ddl=$1 + mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "source $ddl" +} + +install_all_ddls() { + echo "Installing DDLs from utils directory first..." + ( + cd "$REPORTS" || exit 1 + + # Process utils first if it exists + if [ -d "./utils" ]; then + for ddl_pattern in "v_report_*.ddl" "report_*.ddl" "*.ddl" "*.sql"; do + shopt -s nullglob + for ddl in ./utils/$ddl_pattern; do + [ -f "$ddl" ] && install_ddl "$ddl" + done + shopt -u nullglob + done + fi + + echo "Installing other DDLs..." + # Loop over all directories except utils + find . -type d ! -path "./utils" -print0 | while IFS= read -r -d '' dir; do + for ddl_pattern in "v_report_*.ddl" "report_*.ddl"; do + shopt -s nullglob + for ddl in "$dir"/$ddl_pattern; do + [ -f "$ddl" ] && install_ddl "$ddl" + done + shopt -u nullglob + done + done + ) +} + + + +function create_report() { + local report_name=$1 + local report_pretty_name=$2 + local report_type=$3 + local source_table_name=$4 + local refresh_procedure_name=$5 + +if [[ "$DROP_EXISTING_REPORT" == "true" ]]; then + + curl -v \ + -X DELETE \ + -u "$KILLBILL_USER:$KILLBILL_PASSWORD" \ + -H "X-Killbill-ApiKey:$KILLBILL_API_KEY" \ + -H "X-Killbill-ApiSecret:$KILLBILL_API_SECRET" \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports/$report_name" +fi + + + curl -v \ + -X POST \ + -u $KILLBILL_USER:$KILLBILL_PASSWORD \ + -H "X-Killbill-ApiKey:$KILLBILL_API_KEY" \ + -H "X-Killbill-ApiSecret:$KILLBILL_API_SECRET" \ + -H 'Content-Type: application/json' \ + -d "{\"reportName\": \"$report_name\", + \"reportPrettyName\": \"$report_pretty_name\", + \"reportType\": \"$report_type\", + \"sourceTableName\": \"$source_table_name\", + \"refreshProcedureName\": \"$refresh_procedure_name\", + \"refreshFrequency\": \"HOURLY\" + }" \ + $KILLBILL_HTTP_PROTOCOL://$KILLBILL_HOST:$KILLBILL_PORT/plugins/killbill-analytics/reports +} + +# Create all Killbill reports +create_all_reports() { + declare -a reports=( + "accounts_summary|Account Summary|TABLE|report_accounts_summary|refresh_report_accounts_summary" + "active_by_product_term_monthly|Active Subscriptions|TIMELINE|report_active_by_product_term_monthly|refresh_report_active_by_product_term_monthly" + "bundles_summary|Bundles Summary|TABLE|report_bundles_summary|refresh_report_bundles_summary" + "cancellations_daily|Cancellations Daily|TIMELINE|report_cancellations_daily|refresh_report_cancellations_daily" + "chargebacks_daily|Chargebacks Daily|TIMELINE|report_chargebacks_daily|refresh_report_chargebacks_daily" + "conversion-total-dollar-amount|Conversions Daily|TIMELINE|report_conversions_daily|refresh_report_conversions_daily" + "invoice_aging|Invoice Aging|TABLE|report_invoice_aging|refresh_report_invoice_aging" + "invoice_aging_no_payments_monthly|Invoice Aging No Payments|TABLE|report_invoice_aging_no_payment|refresh_report_invoice_aging_no_payment" + "invoice_credits_daily|Invoice Credits Daily|TIMELINE|report_invoice_credits_daily|refresh_report_invoice_credits_daily" + "invoice_credits_monthly|Invoice Credits Monthly|TABLE|report_invoice_credits_monthly|refresh_report_invoice_credits_monthly" + "invoice_item_adjustments_daily|Invoice Item Adjustments Daily|TIMELINE|report_invoice_item_adjustments_daily|refresh_report_invoice_item_adjustments_daily" + "invoice_item_adjustments_monthly|Invoice Item Adjustments Monthly|TABLE|report_invoice_item_adjustments_monthly|refresh_report_invoice_item_adjustments_monthly" + "invoice_items_monthly|Invoice Items Monthly|TABLE|report_invoice_items_monthly|refresh_report_invoice_items_monthly" + "invoices_balance_daily|Invoice Balance|TIMELINE|report_invoices_balance_daily|refresh_report_invoices_balance_daily" + "invoices_daily|Invoices Daily|TIMELINE|report_invoices_daily|refresh_report_invoices_daily" + "invoices_monthly|Invoices Monthly|TABLE|report_invoices_monthly|refresh_report_invoices_monthly" + "mrr_daily|MRR|TIMELINE|report_mrr_daily|refresh_report_mrr_daily" + "new_accounts_daily|New Accounts Daily|TIMELINE|report_new_accounts_daily|refresh_report_new_accounts_daily" + "overdue_states_count_daily|Overdue States Count|TIMELINE|report_overdue_states_count_daily|refresh_report_overdue_states_count_daily" + "payments_monthly|Payments Monthly|TABLE|report_payments_monthly|refresh_report_payments_monthly" + "payments_summary|Payments Summary|TABLE|report_payments_summary|refresh_report_payments_summary" + "payments_total_daily|Payment Total Daily|TIMELINE|report_payments_total_daily|refresh_report_payments_total_daily" + "refunds_monthly|Refunds Monthly|TABLE|report_refunds_summary|refresh_report_refunds_summary" + "refunds_total_daily|Refunds Total Daily|TIMELINE|report_refunds_total_daily|refresh_report_refunds_total_daily" + "subscribers_vs_non_subscribers|Subscribers v/s Non Subscribers|COUNTERS|report_subscribers_vs_non_subscribers|refresh_report_subscribers_vs_non_subscribers" + "trial_starts_count_daily|Trials Start Count|TIMELINE|report_trial_starts_count_daily|refresh_report_trial_starts_count_daily" + "trial_to_no_trial_conversions_daily|Trial to No Trial Conversions Daily|TIMELINE|report_trial_to_no_trial_conversions_daily|refresh_report_trial_to_no_trial_conversions_daily" + ) + + for r in "${reports[@]}"; do + IFS="|" read -r name pretty type source refresh <<< "$r" + create_report "$name" "$pretty" "$type" "$source" "$refresh" + done +} + +# ======================== +# Main Execution +# ======================== + +if [[ "$INSTALL_DDL" == "true" ]]; then + install_all_ddls +else + echo "INSTALL_DDL is not true. Skipping DDL installation." +fi + +create_all_reports + diff --git a/reports/subscribers-vs-non-subscribers/README.md b/reports/subscribers-vs-non-subscribers/README.md new file mode 100644 index 00000000..751fbd3c --- /dev/null +++ b/reports/subscribers-vs-non-subscribers/README.md @@ -0,0 +1,42 @@ +# Subscribers vs Non-subscribers Report + +Compute the total number of active (i.e. with at least one active subscription) and non-active accounts per tenant. + +The snapshot view is: `v_report_subscribers_vs_non_subscribers` + +## Report Creation + +``` +curl -v \ + -X POST \ + -u admin:password \ + -H "X-Killbill-ApiKey:bob" \ + -H "X-Killbill-ApiSecret:lazar" \ + -H 'Content-Type: application/json' \ + -d '{"reportName": "report_subscribers_vs_non_subscribers", + "reportType": "COUNTERS", + "reportPrettyName": "Subscribers vs Non Subscribers", + "sourceTableName": "report_subscribers_vs_non_subscribers", + "refreshProcedureName": "refresh_report_subscribers_vs_non_subscribers", + "refreshFrequency": "HOURLY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Sample Data + +| ID | Type | Count | +|-----|----------------|-------| +| 1 | Non-subscriber | 74 | +| 1 | Subscriber | 18 | +| 2 | Subscriber | 1 | +| 5 | Non-subscriber | 1 | +| 5 | Subscriber | 3 | + +The first row in the above table indicates that the tenant with record id=1 had 74 non-subscribers (accounts with no active subscriptions). + + +## Report UI: + +![subscribers-vs-non-subscribers.png](subscribers-vs-non-subscribers.png) + + diff --git a/reports/subscribers-vs-non-subscribers/report_subscribers-vs-non-subscribers.ddl b/reports/subscribers-vs-non-subscribers/report_subscribers-vs-non-subscribers.ddl new file mode 100644 index 00000000..eca6176a --- /dev/null +++ b/reports/subscribers-vs-non-subscribers/report_subscribers-vs-non-subscribers.ddl @@ -0,0 +1,19 @@ +create table report_subscribers_vs_non_subscribers as select * from v_report_subscribers_vs_non_subscribers limit 0; + +drop procedure if exists refresh_report_subscribers_vs_non_subscribers; +DELIMITER // +CREATE PROCEDURE refresh_report_subscribers_vs_non_subscribers() +BEGIN + +DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; +DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK; + +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +START TRANSACTION; + delete from report_subscribers_vs_non_subscribers; + insert into report_subscribers_vs_non_subscribers select * from v_report_subscribers_vs_non_subscribers; +COMMIT; + +END; +// +DELIMITER ; diff --git a/reports/subscribers-vs-non-subscribers/subscribers-vs-non-subscribers.png b/reports/subscribers-vs-non-subscribers/subscribers-vs-non-subscribers.png new file mode 100644 index 00000000..d0f0bd23 Binary files /dev/null and b/reports/subscribers-vs-non-subscribers/subscribers-vs-non-subscribers.png differ diff --git a/src/main/resources/reports/accounts_summary/v_report_accounts_summary.ddl b/reports/subscribers-vs-non-subscribers/v_report_subscribers-vs-non-subscribers.ddl similarity index 79% rename from src/main/resources/reports/accounts_summary/v_report_accounts_summary.ddl rename to reports/subscribers-vs-non-subscribers/v_report_subscribers-vs-non-subscribers.ddl index a9b404ce..f3b8ea68 100644 --- a/src/main/resources/reports/accounts_summary/v_report_accounts_summary.ddl +++ b/reports/subscribers-vs-non-subscribers/v_report_subscribers-vs-non-subscribers.ddl @@ -1,4 +1,4 @@ -create or replace view v_report_accounts_summary as +create or replace view v_report_subscribers_vs_non_subscribers as select a.tenant_record_id , case when nb_active_bundles <= 0 then 'Non-subscriber' else 'Subscriber' end as label diff --git a/src/main/resources/reports/trial-starts-count-daily/README.md b/reports/trial-starts-count-daily/README.md similarity index 82% rename from src/main/resources/reports/trial-starts-count-daily/README.md rename to reports/trial-starts-count-daily/README.md index 1a1f2a60..4b0d2f02 100644 --- a/src/main/resources/reports/trial-starts-count-daily/README.md +++ b/reports/trial-starts-count-daily/README.md @@ -4,7 +4,7 @@ Count of new trial subscriptions per tenant, per day and per product. The snapshot view is: [v_report_trial_starts_count_daily](v_report_trial_starts_count_daily.md) -## Timeline configuration +## Report Creation ``` curl -v \ @@ -26,14 +26,14 @@ curl -v \ | Tenant Record Id | Day | Product | Count | |------------------|------------|---------------|-------| -| 1 | 2025-07-01 | Assault-Rifle | 1 | +| 1 | 2025-07-01 | Assault-Rifle | 3 | | 1 | 2025-05-05 | Pistol | 5 | | 22 | 2025-09-18 | Pistol | 2 | | 22 | 2025-07-01 | Pistol | 1 | | 44 | 2025-07-08 | Blowdart | 8 | | 44 | 2025-06-12 | Pistol | 6 | -This means that on `2025-09-18`, 2 new subscriptions were started in the `TRIAL` phase for the `Pistol` product and `tenant_record_id=1`. +The first row in the above table indicates that on the date `2025-07-01`, 3 new subscriptions were started in the `TRIAL` phase for the `Assault-Rifle` product for the `tenant_record_id=1`. ## Report UI: diff --git a/src/main/resources/reports/trial-starts-count-daily/daily-trials-count.png b/reports/trial-starts-count-daily/daily-trials-count.png similarity index 100% rename from src/main/resources/reports/trial-starts-count-daily/daily-trials-count.png rename to reports/trial-starts-count-daily/daily-trials-count.png diff --git a/src/main/resources/reports/trial-starts-count-daily/report_trial_starts_count_daily.ddl b/reports/trial-starts-count-daily/report_trial_starts_count_daily.ddl similarity index 100% rename from src/main/resources/reports/trial-starts-count-daily/report_trial_starts_count_daily.ddl rename to reports/trial-starts-count-daily/report_trial_starts_count_daily.ddl diff --git a/src/main/resources/reports/trial-starts-count-daily/v_report_trial_starts_count_daily.ddl b/reports/trial-starts-count-daily/v_report_trial_starts_count_daily.ddl similarity index 100% rename from src/main/resources/reports/trial-starts-count-daily/v_report_trial_starts_count_daily.ddl rename to reports/trial-starts-count-daily/v_report_trial_starts_count_daily.ddl diff --git a/src/main/resources/reports/trial-to-no-trial-conversions_daily/README.md b/reports/trial-to-no-trial-conversions_daily/README.md similarity index 86% rename from src/main/resources/reports/trial-to-no-trial-conversions_daily/README.md rename to reports/trial-to-no-trial-conversions_daily/README.md index e1528101..a11e3225 100644 --- a/src/main/resources/reports/trial-to-no-trial-conversions_daily/README.md +++ b/reports/trial-to-no-trial-conversions_daily/README.md @@ -4,7 +4,7 @@ Count of subscriptions converting from trial to non-trial per tenant per day. The snapshot view is: [v_report_trial_to_no_trial_conversions_daily](v_report_trial_to_no_trial_conversions_daily.ddl) -## Timeline configuration +## Report Creation ``` curl -v \ @@ -26,7 +26,6 @@ curl -v \ | Tenant Record Id | Day | Count | |------------------|------------|-------| -| 1 | 2025-06-04 | 1 | | 1 | 2025-10-18 | 3 | | 22 | 2025-08-07 | 1 | | 22 | 2025-07-12 | 1 | @@ -34,8 +33,8 @@ curl -v \ | 45 | 2025-04-04 | 1 | | 489 | 2025-09-05 | 1 | -This means that on `2025-10-18`, 3 subscriptions transitioned from the `TRIAL` phase to some other phase for the `tenant_record_id=1`. +The first row in the above table indicates that on the date `2025-10-18`, 3 subscriptions transitioned from the `TRIAL` phase to some other phase for the `tenant_record_id=1`. ## Report UI: diff --git a/src/main/resources/reports/trial-to-no-trial-conversions_daily/report_trial-to-no-trial-conversions_daily.ddl b/reports/trial-to-no-trial-conversions_daily/report_trial-to-no-trial-conversions_daily.ddl similarity index 100% rename from src/main/resources/reports/trial-to-no-trial-conversions_daily/report_trial-to-no-trial-conversions_daily.ddl rename to reports/trial-to-no-trial-conversions_daily/report_trial-to-no-trial-conversions_daily.ddl diff --git a/src/main/resources/reports/trial-to-no-trial-conversions_daily/trial-to-no-trial-conversions.png b/reports/trial-to-no-trial-conversions_daily/trial-to-no-trial-conversions.png similarity index 100% rename from src/main/resources/reports/trial-to-no-trial-conversions_daily/trial-to-no-trial-conversions.png rename to reports/trial-to-no-trial-conversions_daily/trial-to-no-trial-conversions.png diff --git a/src/main/resources/reports/trial-to-no-trial-conversions_daily/v_report_trial-to-no-trial-conversions_daily.ddl b/reports/trial-to-no-trial-conversions_daily/v_report_trial-to-no-trial-conversions_daily.ddl similarity index 100% rename from src/main/resources/reports/trial-to-no-trial-conversions_daily/v_report_trial-to-no-trial-conversions_daily.ddl rename to reports/trial-to-no-trial-conversions_daily/v_report_trial-to-no-trial-conversions_daily.ddl diff --git a/src/main/resources/reports/utils/README.md b/reports/utils/README.md similarity index 100% rename from src/main/resources/reports/utils/README.md rename to reports/utils/README.md diff --git a/src/main/resources/reports/calendar.sql b/reports/utils/calendar.sql similarity index 100% rename from src/main/resources/reports/calendar.sql rename to reports/utils/calendar.sql diff --git a/src/main/resources/reports/utils/insertMonthlyCurrencyConversionRates.ddl b/reports/utils/insertMonthlyCurrencyConversionRates.ddl similarity index 100% rename from src/main/resources/reports/utils/insertMonthlyCurrencyConversionRates.ddl rename to reports/utils/insertMonthlyCurrencyConversionRates.ddl diff --git a/src/main/resources/reports/README.md b/src/main/resources/reports/README.md deleted file mode 100644 index f9058539..00000000 --- a/src/main/resources/reports/README.md +++ /dev/null @@ -1,28 +0,0 @@ -Default set of report queries. - -* [churn](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/churn): procedure to compute monthly churn (as a percentage and in USD) -* [conversion](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/conversion): procedure to compute revenue converted per day and billing period -* [mrr](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/mrr): procedure to compute MRR per day and billing period -* [v_report_accounts_summary.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_accounts_summary.ddl): overall number of Non-subscribers vs subscribers (defined as having at least one active bundle) -* [v_report_active_by_product_term_monthly.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_active_by_product_term_monthly.ddl): number of active subscriptions created per day, product and billing period -* [v_report_cancellations_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_cancellations_daily.ddl): number of cancellations per day and phase -* [v_report_chargebacks_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_chargebacks_daily.ddl): amount of chargebacks reported per day and currency -* [v_report_conversions_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_conversions_daily.ddl): number of conversions (trial to non-trial), per day -* [v_report_invoice_adjustments_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_invoice_adjustments_daily.ddl): sum of invoices adjustments per day and currency -* [v_report_invoice_item_adjustments_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_invoice_item_adjustments_daily.ddl): sum of invoices item adjustments per day and currency -* [v_report_invoice_item_credits_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_invoice_item_credits_daily.ddl): sum of invoices credits per day and currency -* [v_report_invoices_balance_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_invoices_balance_daily.ddl): sum of invoices balance per day and currency -* [v_report_invoices_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_invoices_daily.ddl): sum of invoices original amount per day and currency -* [v_report_mrr_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_mrr_daily.ddl): daily MRR, broken down by product -* [v_report_new_accounts_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_new_accounts_daily.ddl): number of created accounts per day -* [v_report_overdue_states_count_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_overdue_states_count_daily.ddl): number of accounts per overdue state, per day -* [v_report_payments_total_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_payments_total_daily.ddl): sum of payments (purchases) per day and currency -* [v_report_refunds_total_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_refunds_total_daily.ddl): sum of refunds per day and currency -* [v_report_trial_starts_count_daily.ddl](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/v_report_trial_starts_count_daily.ddl): number of new trials, per product and day - - -Utility tables: - -* [calendar.sql](https://github.com/killbill/killbill-analytics-plugin/blob/master/src/main/resources/reports/calendar.sql): procedure to create a *calendar* table - - diff --git a/src/main/resources/reports/accounts_summary/README.md b/src/main/resources/reports/accounts_summary/README.md deleted file mode 100644 index c61b7c40..00000000 --- a/src/main/resources/reports/accounts_summary/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Accounts summary report - -Compute the total number of active (i.e. with at least one active subscription) and non-active accounts. - -The snapshot view is: `v_report_accounts_summary` - -## Pie chart configuration - -``` -curl -v \ - -X POST \ - -u admin:password \ - -H "X-Killbill-ApiKey:bob" \ - -H "X-Killbill-ApiSecret:lazar" \ - -H 'Content-Type: application/json' \ - -d '{"reportName": "report_accounts_summary", - "reportType": "COUNTERS", - "reportPrettyName": "Accounts summary", - "sourceTableName": "report_accounts_summary", - "refreshProcedureName": "refresh_report_accounts_summary", - "refreshFrequency": "HOURLY"}' \ - "http://127.0.0.1:8080/plugins/killbill-analytics/reports" -``` diff --git a/src/main/resources/reports/accounts_summary/report_accounts_summary.ddl b/src/main/resources/reports/accounts_summary/report_accounts_summary.ddl deleted file mode 100644 index bb307650..00000000 --- a/src/main/resources/reports/accounts_summary/report_accounts_summary.ddl +++ /dev/null @@ -1,19 +0,0 @@ -create table report_accounts_summary as select * from v_report_accounts_summary limit 0; - -drop procedure if exists refresh_report_accounts_summary; -DELIMITER // -CREATE PROCEDURE refresh_report_accounts_summary() -BEGIN - -DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; -DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK; - -SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; -START TRANSACTION; - delete from report_accounts_summary; - insert into report_accounts_summary select * from v_report_accounts_summary; -COMMIT; - -END; -// -DELIMITER ; diff --git a/src/main/resources/reports/chargebacks_daily/README.md b/src/main/resources/reports/chargebacks_daily/README.md deleted file mode 100644 index 98dbe96b..00000000 --- a/src/main/resources/reports/chargebacks_daily/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Daily chargebacks report - -Compute the total value (in the reference currency) of chargebacks per day per currency. - -The snapshot view is: `v_report_chargebacks_daily` - -## Timeline configuration - -``` -curl -v \ - -X POST \ - -u admin:password \ - -H "X-Killbill-ApiKey:bob" \ - -H "X-Killbill-ApiSecret:lazar" \ - -H 'Content-Type: application/json' \ - -d '{"reportName": "report_chargebacks_daily", - "reportType": "TIMELINE", - "reportPrettyName": "Daily chargebacks value", - "sourceTableName": "report_chargebacks_daily", - "refreshProcedureName": "refresh_report_chargebacks_daily", - "refreshFrequency": "DAILY"}' \ - "http://127.0.0.1:8080/plugins/killbill-analytics/reports" -``` diff --git a/src/main/resources/reports/churn/README.md b/src/main/resources/reports/churn/README.md new file mode 100644 index 00000000..ca872722 --- /dev/null +++ b/src/main/resources/reports/churn/README.md @@ -0,0 +1,49 @@ +# Churn (Monthly and Annual) Report + +This report tracks customer churn in dollar terms, showing both the total churned revenue and the churn percentage for monthly and annual subscriptions on a per-tenant, per-month basis. + +The snapshot view is: `v_report_churn_percent_and_total_usd` + +## Churn Percent Configuration + +``` +curl -v \ + -X POST \ + -u admin:password \ + -H "X-Killbill-ApiKey:bob" \ + -H "X-Killbill-ApiSecret:lazar" \ + -H 'Content-Type: application/json' \ + -d '{"reportName": "report_churn_percent", + "reportType": "TIMELINE", + "reportPrettyName": "Churn Percent (Monthly and Annual)", + "sourceTableName": "report_churn_percent", + "refreshProcedureName": "refresh_report_churn_percent", + "refreshFrequency": "DAILY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Churn Percentage Report UI + + + +## Churn Amount Configuration + +``` +curl -v \ + -X POST \ + -u admin:password \ + -H "X-Killbill-ApiKey:bob" \ + -H "X-Killbill-ApiSecret:lazar" \ + -H 'Content-Type: application/json' \ + -d '{"reportName": "report_churn_total_usd", + "reportType": "TIMELINE", + "reportPrettyName": "Churn Total USD (Monthly and Annual)", + "sourceTableName": "report_churn_total_usd", + "refreshProcedureName": "refresh_report_churn_total_usd", + "refreshFrequency": "DAILY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Churn Amount Report UI + + diff --git a/src/main/resources/reports/churn/refresh_report_churn_total_and_pct.prc b/src/main/resources/reports/churn/refresh_report_churn_total_and_pct.prc deleted file mode 100644 index 6cb735f3..00000000 --- a/src/main/resources/reports/churn/refresh_report_churn_total_and_pct.prc +++ /dev/null @@ -1,211 +0,0 @@ -drop procedure if exists refresh_report_churn_total_and_pct; -DELIMITER // -CREATE PROCEDURE refresh_report_churn_total_and_pct() -BEGIN - - -- Refresh Churn Dollars and Churn Percent for MONTHLY subscriptions - create temporary table report_temp_churn_monthly_paid_bundles (index (bundle_id)) as - select distinct - tenant_record_id - , bundle_id - from - analytics_invoice_items - where 1=1 - and invoice_original_amount_charged >0 - and invoice_balance = 0 - ; - - create temporary table report_temp_churn_monthly_paid_bundles2 (index (bundle_id)) as - select distinct - tenant_record_id - , bundle_id - from - analytics_invoice_items - where 1=1 - and invoice_original_amount_charged >0 - and invoice_balance = 0 - ; - - create temporary table report_temp_churn_monthly_dollars_pct_monthly as - select - active_sub_dollar.tenant_record_id - , active_sub_dollar.month - , round(churn_dollar.amount) churn_dollars_monthly - , round(churn_dollar.amount / active_sub_dollar.amount,4) churn_pct_monthly - from ( - select - ast.tenant_record_id - , date_format(next_start_date, '%Y-%m-01') month - , prev_billing_period - , sum(converted_prev_price) amount - from - analytics_subscription_transitions ast - join report_temp_churn_monthly_paid_bundles paid_bundles on ast.bundle_id = paid_bundles.bundle_id and ast.tenant_record_id = paid_bundles.tenant_record_id - where 1=1 - and report_group='default' - and next_service='entitlement-service' - and event like 'STOP_ENTITLEMENT%' - and prev_billing_period in ('MONTHLY') - group by 1,2,3 - ) churn_dollar join ( - select - ast.tenant_record_id - , cal.d month - , next_billing_period - , sum(converted_next_price) amount - from - analytics_subscription_transitions ast - join calendar cal on next_start_date < cal.d and (next_end_date > cal.d or next_end_date is null ) and (cal.d = date_format(cal.d, '%Y-%m-01')) and cal.d>='2013-01-01' and cal.d < sysdate() - join report_temp_churn_monthly_paid_bundles2 paid_bundles on ast.bundle_id = paid_bundles.bundle_id and ast.tenant_record_id = paid_bundles.tenant_record_id - where 1=1 - and report_group='default' - and next_service='entitlement-service' - and event not like 'STOP_ENTITLEMENT%' - and next_billing_period in ('MONTHLY') - group by 1,2,3 - ) active_sub_dollar on churn_dollar.month=active_sub_dollar.month and churn_dollar.prev_billing_period=active_sub_dollar.next_billing_period and churn_dollar.tenant_record_id=active_sub_dollar.tenant_record_id - ; - - DELETE FROM report_churn_total_usd_monthly; - DELETE FROM report_churn_percent_monthly; - - insert into report_churn_total_usd_monthly - select - tenant_record_id - , month day - , 'MONTHLY' - , churn_dollars_monthly count - from - report_temp_churn_monthly_dollars_pct_monthly - ; - - insert into report_churn_percent_monthly - select - tenant_record_id - , month day - , 'MONTHLY' - , churn_pct_monthly count - from - report_temp_churn_monthly_dollars_pct_monthly - ; - - -- Refresh Churn Dollars and Churn Percent for ANNUAL subscriptions - create temporary table report_temp_churn_annual_paid_bundles (index (bundle_id)) as - select distinct - tenant_record_id - , bundle_id - from ( - select - tenant_record_id - , bundle_id - from - analytics_invoice_items - where 1=1 - and invoice_original_amount_charged >0 - and invoice_balance = 0 - union - select - s.tenant_record_id - , s.bundle_id - from - subscription_events se - join subscriptions s on se.subscription_id = s.id and se.tenant_record_id = s.tenant_record_id - where 1=1 - and user_type in ('MIGRATE_ENTITLEMENT') - ) bundles - ; - - - create temporary table report_temp_churn_annual_paid_bundles2 (index (bundle_id)) as - select distinct - tenant_record_id - , bundle_id - , charged_through_date - from ( - select - tenant_record_id - , bundle_id - , end_date charged_through_date - from - analytics_invoice_items - where 1=1 - and invoice_original_amount_charged >0 - and invoice_balance = 0 - union - select - s.tenant_record_id - , s.bundle_id - , effective_date charged_through_date - from - subscription_events se - join subscriptions s on se.subscription_id = s.id and se.tenant_record_id = s.tenant_record_id - where 1=1 - and user_type in ('MIGRATE_ENTITLEMENT') - ) bundles - ; - - create temporary table report_temp_churn_annual_dollars_pct_monthly as - select - churn_dollar.tenant_record_id - , churn_dollar.month - , churn_dollar.amount churn_dollars_annual - , round(churn_dollar.amount /active_sub_dollar.amount,4) churn_pct_annual - from ( - select - ast.tenant_record_id - , date_format(next_start_date, '%Y-%m-01') month - , prev_billing_period - , round(sum(converted_prev_price)) amount - from - analytics_subscription_transitions ast - join report_temp_churn_annual_paid_bundles paid_bundles on ast.bundle_id = paid_bundles.bundle_id and ast.tenant_record_id = paid_bundles.tenant_record_id - where 1=1 - and report_group='default' - and next_service='entitlement-service' - and event like 'STOP_ENTITLEMENT%' - and prev_billing_period in ('ANNUAL') - group by 1,2,3 - ) churn_dollar join ( - select - ast.tenant_record_id - , cal.d month - , next_billing_period - , round(sum(converted_next_price)) amount - from - analytics_subscription_transitions ast - join calendar cal on next_start_date < cal.d and (next_end_date > cal.d or next_end_date is null ) and (cal.d = date_format(cal.d, '%Y-%m-01')) and cal.d>='2013-01-01' and cal.d < sysdate() - join report_temp_churn_annual_paid_bundles2 paid_bundles on ast.bundle_id = paid_bundles.bundle_id and ast.tenant_record_id = paid_bundles.tenant_record_id - where 1=1 - and report_group='default' - and next_service='entitlement-service' - and event not like 'STOP_ENTITLEMENT%' - and next_billing_period in ('ANNUAL') - and extract(month from date_add(charged_through_date,interval 1 day)) = extract(month from cal.d) - group by 1,2,3 - ) active_sub_dollar on churn_dollar.month=active_sub_dollar.month and churn_dollar.prev_billing_period=active_sub_dollar.next_billing_period and churn_dollar.tenant_record_id=active_sub_dollar.tenant_record_id - ; - - insert into report_churn_total_usd_monthly - select - tenant_record_id - , month day - , 'ANNUAL' - , churn_dollars_annual count - from - report_temp_churn_annual_dollars_pct_monthly - ; - - insert into report_churn_percent_monthly - select - tenant_record_id - , month day - , 'ANNUAL' - , churn_pct_annual count - from - report_temp_churn_annual_dollars_pct_monthly - ; - - -END; -// -DELIMITER ; diff --git a/src/main/resources/reports/churn/report_churn_percent.ddl b/src/main/resources/reports/churn/report_churn_percent.ddl new file mode 100644 index 00000000..8ee9ba72 --- /dev/null +++ b/src/main/resources/reports/churn/report_churn_percent.ddl @@ -0,0 +1,21 @@ +create table report_churn_percent as select tenant_record_id + , month day, billing_period, churn_pct count from v_report_churn_percent_and_total_usd limit 0; + +drop procedure if exists refresh_report_churn_percent; +DELIMITER // +CREATE PROCEDURE refresh_report_churn_percent() +BEGIN + +DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; +DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK; + +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +START TRANSACTION; + delete from report_churn_percent; + insert into report_churn_percent select tenant_record_id + , month day, billing_period, churn_pct count from v_report_churn_percent_and_total_usd; +COMMIT; + +END; +// +DELIMITER ; diff --git a/src/main/resources/reports/churn/report_churn_percent_monthly.ddl b/src/main/resources/reports/churn/report_churn_percent_monthly.ddl deleted file mode 100644 index 6b0802cd..00000000 --- a/src/main/resources/reports/churn/report_churn_percent_monthly.ddl +++ /dev/null @@ -1,2 +0,0 @@ -drop table if exists report_churn_percent_monthly; -create table report_churn_percent_monthly (tenant_record_id int(11), day date, term varchar(50), count decimal(5,4)); diff --git a/src/main/resources/reports/churn/report_churn_total_usd.ddl b/src/main/resources/reports/churn/report_churn_total_usd.ddl new file mode 100644 index 00000000..e9378f5f --- /dev/null +++ b/src/main/resources/reports/churn/report_churn_total_usd.ddl @@ -0,0 +1,21 @@ +create table report_churn_total_usd as select tenant_record_id + , month day, billing_period, churn_dollars count from v_report_churn_percent_and_total_usd limit 0; + +drop procedure if exists refresh_report_churn_total_usd; +DELIMITER // +CREATE PROCEDURE refresh_report_churn_total_usd() +BEGIN + +DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; +DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK; + +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +START TRANSACTION; + delete from report_churn_total_usd; + insert into report_churn_total_usd select tenant_record_id + , month day, billing_period, churn_dollars count from v_report_churn_percent_and_total_usd; +COMMIT; + +END; +// +DELIMITER ; diff --git a/src/main/resources/reports/churn/report_churn_total_usd_monthly.ddl b/src/main/resources/reports/churn/report_churn_total_usd_monthly.ddl deleted file mode 100644 index 1ba6ccde..00000000 --- a/src/main/resources/reports/churn/report_churn_total_usd_monthly.ddl +++ /dev/null @@ -1,2 +0,0 @@ -drop table if exists report_churn_total_usd_monthly; -create table report_churn_total_usd_monthly (tenant_record_id int(11), day date, term varchar(50), count int(8)); diff --git a/src/main/resources/reports/churn/v_report_churn_percent_and_total_usd.ddl b/src/main/resources/reports/churn/v_report_churn_percent_and_total_usd.ddl new file mode 100644 index 00000000..b748e367 --- /dev/null +++ b/src/main/resources/reports/churn/v_report_churn_percent_and_total_usd.ddl @@ -0,0 +1,143 @@ +create or replace view v_report_churn_percent_and_total_usd as +with paid_bundles_monthly as ( + select distinct tenant_record_id, bundle_id + from analytics_invoice_items + where invoice_original_amount_charged > 0 + and invoice_balance = 0 +), +paid_bundles_annual as ( + select distinct tenant_record_id, bundle_id + from ( + select tenant_record_id, bundle_id + from analytics_invoice_items + where invoice_original_amount_charged > 0 + and invoice_balance = 0 + union + select s.tenant_record_id, s.bundle_id + from subscription_events se + join subscriptions s + on se.subscription_id = s.id + and se.tenant_record_id = s.tenant_record_id + where user_type in ('MIGRATE_ENTITLEMENT') + ) bundles +), +paid_bundles_annual2 as ( + select distinct tenant_record_id, bundle_id, charged_through_date + from ( + select tenant_record_id, bundle_id, end_date as charged_through_date + from analytics_invoice_items + where invoice_original_amount_charged > 0 + and invoice_balance = 0 + union + select s.tenant_record_id, s.bundle_id, effective_date as charged_through_date + from subscription_events se + join subscriptions s + on se.subscription_id = s.id + and se.tenant_record_id = s.tenant_record_id + where user_type in ('MIGRATE_ENTITLEMENT') + ) bundles +) +-- ============================ +-- MONTHLY PART +-- ============================ +select + active_sub_dollar.tenant_record_id, + active_sub_dollar.month, + round(churn_dollar.amount) as churn_dollars, + round(churn_dollar.amount / active_sub_dollar.amount, 4) as churn_pct, + 'MONTHLY' as billing_period +from ( + select + ast.tenant_record_id, + date_format(next_start_date, '%Y-%m-01') as month, + prev_billing_period, + sum(converted_prev_price) as amount + from analytics_subscription_transitions ast + join paid_bundles_monthly b + on ast.bundle_id = b.bundle_id + and ast.tenant_record_id = b.tenant_record_id + where report_group = 'default' + and next_service = 'entitlement-service' + and event like 'STOP_ENTITLEMENT%' + and prev_billing_period in ('MONTHLY') + group by 1,2,3 +) churn_dollar +join ( + select + ast.tenant_record_id, + cal.d as month, + next_billing_period, + sum(converted_next_price) as amount + from analytics_subscription_transitions ast + join calendar cal + on next_start_date < cal.d + and (next_end_date > cal.d or next_end_date is null) + and cal.d = date_format(cal.d, '%Y-%m-01') + and cal.d >= '2013-01-01' + and cal.d < sysdate() + join paid_bundles_monthly b + on ast.bundle_id = b.bundle_id + and ast.tenant_record_id = b.tenant_record_id + where report_group = 'default' + and next_service = 'entitlement-service' + and event not like 'STOP_ENTITLEMENT%' + and next_billing_period in ('MONTHLY') + group by 1,2,3 +) active_sub_dollar + on churn_dollar.month = active_sub_dollar.month + and churn_dollar.prev_billing_period = active_sub_dollar.next_billing_period + and churn_dollar.tenant_record_id = active_sub_dollar.tenant_record_id + +union all + +-- ============================ +-- ANNUAL PART +-- ============================ +select + churn_dollar.tenant_record_id, + churn_dollar.month, + churn_dollar.amount as churn_dollars, + round(churn_dollar.amount / active_sub_dollar.amount, 4) as churn_pct, + 'ANNUAL' as billing_period +from ( + select + ast.tenant_record_id, + date_format(next_start_date, '%Y-%m-01') as month, + prev_billing_period, + round(sum(converted_prev_price)) as amount + from analytics_subscription_transitions ast + join paid_bundles_annual b + on ast.bundle_id = b.bundle_id + and ast.tenant_record_id = b.tenant_record_id + where report_group = 'default' + and next_service = 'entitlement-service' + and event like 'STOP_ENTITLEMENT%' + and prev_billing_period in ('ANNUAL') + group by 1,2,3 +) churn_dollar +join ( + select + ast.tenant_record_id, + cal.d as month, + next_billing_period, + round(sum(converted_next_price)) as amount + from analytics_subscription_transitions ast + join calendar cal + on next_start_date < cal.d + and (next_end_date > cal.d or next_end_date is null) + and cal.d = date_format(cal.d, '%Y-%m-01') + and cal.d >= '2013-01-01' + and cal.d < sysdate() + join paid_bundles_annual2 b + on ast.bundle_id = b.bundle_id + and ast.tenant_record_id = b.tenant_record_id + where report_group = 'default' + and next_service = 'entitlement-service' + and event not like 'STOP_ENTITLEMENT%' + and next_billing_period in ('ANNUAL') + and extract(month from date_add(charged_through_date, interval 1 day)) = extract(month from cal.d) + group by 1,2,3 +) active_sub_dollar + on churn_dollar.month = active_sub_dollar.month + and churn_dollar.prev_billing_period = active_sub_dollar.next_billing_period + and churn_dollar.tenant_record_id = active_sub_dollar.tenant_record_id; diff --git a/src/main/resources/reports/invoices_balance_daily/invoice-balance-daily.png b/src/main/resources/reports/invoices_balance_daily/invoice-balance-daily.png deleted file mode 100644 index 13fd54fc..00000000 Binary files a/src/main/resources/reports/invoices_balance_daily/invoice-balance-daily.png and /dev/null differ diff --git a/src/main/resources/reports/invoices_daily/README.md b/src/main/resources/reports/invoices_daily/README.md deleted file mode 100644 index b3cc642c..00000000 --- a/src/main/resources/reports/invoices_daily/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Daily invoices report - -Compute the total invoice amount charged (in the reference currency) per day per currency. - -The snapshot view is: `v_report_invoices_daily` - -## Timeline configuration - -``` -curl -v \ - -X POST \ - -u admin:password \ - -H "X-Killbill-ApiKey:bob" \ - -H "X-Killbill-ApiSecret:lazar" \ - -H 'Content-Type: application/json' \ - -d '{"reportName": "report_invoices_daily", - "reportType": "TIMELINE", - "reportPrettyName": "Daily Invoices Value", - "sourceTableName": "report_invoices_daily", - "refreshProcedureName": "refresh_report_invoices_daily", - "refreshFrequency": "DAILY"}' \ - "http://127.0.0.1:8080/plugins/killbill-analytics/reports" -``` - -## Report UI: - -![invoice-amount-daily.png](invoice-amount-daily.png) \ No newline at end of file diff --git a/src/main/resources/reports/invoices_daily/invoice-amount-daily.png b/src/main/resources/reports/invoices_daily/invoice-amount-daily.png deleted file mode 100644 index 83f27206..00000000 Binary files a/src/main/resources/reports/invoices_daily/invoice-amount-daily.png and /dev/null differ diff --git a/src/main/resources/reports/mrr/README.md b/src/main/resources/reports/mrr/README.md deleted file mode 100644 index 6200a84a..00000000 --- a/src/main/resources/reports/mrr/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Daily MRR - -Computes the total active MRR (monthly recurring revenue), broken down both by product and as a tenant-wide total (ALL) for each tenant and each day. - -The snapshot view is: `v_report_mrr_daily` - -## Timeline configuration - -``` -curl -v \ - -X POST \ - -u admin:password \ - -H "X-Killbill-ApiKey:bob" \ - -H "X-Killbill-ApiSecret:lazar" \ - -H 'Content-Type: application/json' \ - -d '{"reportName": "report_mrr_daily", - "reportType": "TIMELINE", - "reportPrettyName": "Daily MRR", - "sourceTableName": "report_mrr_daily", - "refreshProcedureName": "refresh_report_mrr_daily", - "refreshFrequency": "DAILY"}' \ - "http://127.0.0.1:8080/plugins/killbill-analytics/reports" -``` - -## Sample Data - -| tenant_record_id | product | day | count | -| ---------------- | ------- | ---------- |--------| -| 24 | Pistol | 2025-01-05 | 150.00 | -| 24 | Rifle | 2025-01-05 | 200.00 | -| 24 | ALL | 2025-01-05 | 350.00 | -| 24 | Pistol | 2025-01-06 | 150.00 | -| 24 | ALL | 2025-01-06 | 150.00 | - - -## Report UI: - -![daily-mrr.png](daily-mrr.png) \ No newline at end of file diff --git a/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub1.ddl b/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub1.ddl index f4d50c56..21697b0f 100644 --- a/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub1.ddl +++ b/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub1.ddl @@ -10,8 +10,8 @@ SELECT FROM analytics_payment_auths apa WHERE 1=1 -AND apa.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 15*60 - (UNIX_TIMESTAMP(NOW()) - 15*60)%(15*60)) -AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(apa.created_date) - UNIX_TIMESTAMP(apa.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 15*60 - (UNIX_TIMESTAMP(NOW()) - 15*60)%(15*60)) as time) +AND apa.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP()) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP()) - 15*60)%(15*60)) +AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(apa.created_date) - UNIX_TIMESTAMP(apa.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP()) - 15*60 - (UNIX_TIMESTAMP(NOW()) - 15*60)%(15*60)) as time) GROUP BY apa.plugin_name , ifnull(apa.plugin_property_4,'unknown') @@ -29,8 +29,8 @@ SELECT FROM analytics_payment_purchases app WHERE 1=1 -AND app.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 15*60 - (UNIX_TIMESTAMP(NOW()) - 15*60)%(15*60)) -AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(app.created_date) - UNIX_TIMESTAMP(app.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 15*60 - (UNIX_TIMESTAMP(NOW()) - 15*60)%(15*60)) as time) +AND app.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP()) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP()) - 15*60)%(15*60)) +AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(app.created_date) - UNIX_TIMESTAMP(app.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP()) - 15*60 - (UNIX_TIMESTAMP(NOW()) - 15*60)%(15*60)) as time) GROUP BY app.plugin_name , ifnull(app.plugin_property_4,'unknown') diff --git a/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub2.ddl b/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub2.ddl index 82c1a733..21b2fdf4 100644 --- a/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub2.ddl +++ b/src/main/resources/reports/payment_provider_conversion/v_report_payment_provider_conversion_sub2.ddl @@ -10,9 +10,9 @@ SELECT FROM analytics_payment_auths apa WHERE 1=1 -AND apa.created_date < FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60)%(15*60) + 15*60) -AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(apa.created_date) - UNIX_TIMESTAMP(apa.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60)%(15*60)) as time) -AND apa.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60)%(15*60)) +AND apa.created_date < FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60)%(15*60) + 15*60) +AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(apa.created_date) - UNIX_TIMESTAMP(apa.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60)%(15*60)) as time) +AND apa.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60)%(15*60)) GROUP BY apa.plugin_name , ifnull(apa.plugin_property_4,'unknown') @@ -30,9 +30,9 @@ SELECT FROM analytics_payment_purchases app WHERE 1=1 -AND app.created_date < FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60)%(15*60) + 15*60) -AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(app.created_date) - UNIX_TIMESTAMP(app.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60)%(15*60)) as time) -AND app.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60)%(15*60)) +AND app.created_date < FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60)%(15*60) + 15*60) +AND cast(FROM_UNIXTIME(UNIX_TIMESTAMP(app.created_date) - UNIX_TIMESTAMP(app.created_date)%(15*60)) as time) = cast(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60)%(15*60)) as time) +AND app.created_date >= FROM_UNIXTIME(UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60 - (UNIX_TIMESTAMP(UTC_TIMESTAMP() - interval '14' day) - 15*60)%(15*60)) GROUP BY app.plugin_name , ifnull(app.plugin_property_4,'unknown') diff --git a/src/main/resources/seed_reports.sh b/src/main/resources/seed_reports.sh deleted file mode 100644 index 1584501e..00000000 --- a/src/main/resources/seed_reports.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env bash - -# -# Copyright 2010-2014 Ning, Inc. -# Copyright 2014-2020 Groupon, Inc -# Copyright 2020-2020 Equinix, Inc -# Copyright 2014-2020 The Billing Project, LLC -# -# The Billing Project licenses this file to you 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. -# - -HERE=`cd \`dirname $0\`; pwd` - -KILLBILL_HTTP_PROTOCOL=${KILLBILL_HTTP_PROTOCOL-"http"} -KILLBILL_HOST=${KILLBILL_HOST-"127.0.0.1"} -KILLBILL_PORT=${KILLBILL_PORT-"8080"} - -KILLBILL_USER=${KILLBILL_USER-"admin"} -KILLBILL_PASSWORD=${KILLBILL_PASSWORD-"password"} -KILLBILL_API_KEY=${KILLBILL_API_KEY-"bob"} -KILLBILL_API_SECRET=${KILLBILL_API_SECRET-"lazar"} - -MYSQL_HOST=${MYSQL_HOST-"127.0.0.1"} -MYSQL_USER=${MYSQL_USER-"root"} -MYSQL_PASSWORD=${MYSQL_PASSWORD-"root"} -MYSQL_DATABASE=${MYSQL_DATABASE-"killbill"} - -REPORTS=$HERE/reports -SYSTEM=$HERE/system - -function install_ddl() { - local ddl=$1 - mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "source $ddl" -} - -function create_report() { - local report_name=$1 - local report_pretty_name=$2 - local report_type=$3 - local source_table_name=$4 - - curl -v \ - -X POST \ - -u $KILLBILL_USER:$KILLBILL_PASSWORD \ - -H "X-Killbill-ApiKey:$KILLBILL_API_KEY" \ - -H "X-Killbill-ApiSecret:$KILLBILL_API_SECRET" \ - -H 'Content-Type: application/json' \ - -d "{\"reportName\": \"$report_name\", - \"reportPrettyName\": \"$report_pretty_name\", - \"reportType\": \"$report_type\", - \"sourceTableName\": \"$source_table_name\"}" \ - $KILLBILL_HTTP_PROTOCOL://$KILLBILL_HOST:$KILLBILL_PORT/plugins/killbill-analytics/reports -} - -# Install the DDL - the calendar table needs to be first -install_ddl $REPORTS/calendar.sql -for r in `find $REPORTS -type f -name '*.sql' -o -name '*.ddl' -maxdepth 1`; do install_ddl $r; done -for r in `find $SYSTEM -type f -name '*.sql' -o -name '*.ddl' -maxdepth 1`; do install_ddl $r; done - -# Dashboard views -create_report 'accounts_summary' 'Account summary' 'COUNTERS' 'v_report_accounts_summary' -create_report 'active_by_product_term_monthly' 'Active subscriptions' 'TIMELINE' 'v_report_active_by_product_term_monthly' -create_report 'cancellations_count_daily' 'Cancellations' 'TIMELINE' 'v_report_cancellations_daily' -create_report 'chargebacks_daily' 'Chargebacks' 'TIMELINE' 'v_report_chargebacks_daily' -create_report 'conversions_daily' 'Conversions' 'TIMELINE' 'v_report_conversions_daily' -create_report 'invoice_adjustments_daily' 'Invoice adjustments' 'TIMELINE' 'v_report_invoice_adjustments_daily' -create_report 'invoice_item_adjustments_daily' 'Invoice item adjustments' 'TIMELINE' 'v_report_invoice_item_adjustments_daily' -create_report 'invoice_item_credits_daily' 'Invoice credits' 'TIMELINE' 'v_report_invoice_item_credits_daily' -create_report 'invoices_balance_daily' 'Invoice balance' 'TIMELINE' 'v_report_invoices_balance_daily' -create_report 'invoices_daily' 'Invoices' 'TIMELINE' 'v_report_invoices_daily' -create_report 'mrr_daily' 'MRR' 'TIMELINE' 'v_report_mrr_daily' -create_report 'new_accounts_daily' 'New accounts' 'TIMELINE' 'v_report_new_accounts_daily' -create_report 'overdue_states_count_daily' 'Overdue states' 'TIMELINE' 'v_report_overdue_states_count_daily' -create_report 'payments_total_daily' 'Payment ($ amount)' 'TIMELINE' 'v_report_payments_total_daily' -create_report 'refunds_total_daily' 'Refunds' 'TIMELINE' 'v_report_refunds_total_daily' -create_report 'trial_starts_count_daily' 'Trials' 'TIMELINE' 'v_report_trial_starts_count_daily' - -# System views -create_report 'system_report_control_tag_no_test' 'Control tags' 'COUNTERS' 'v_system_report_control_tag_no_test' -create_report 'system_report_notifications_per_queue_name' 'Notification queues' 'TIMELINE' 'v_system_report_notifications_per_queue_name' -create_report 'system_report_notifications_per_queue_name_late' 'Late notifications' 'COUNTERS' 'v_system_report_notifications_per_queue_name_late' -create_report 'system_report_payments' 'Payments status' 'COUNTERS' 'v_system_report_payments' -create_report 'system_report_payments_per_day' 'Payments' 'TIMELINE' 'v_system_report_payments_per_day'