diff --git a/.idea/misc.xml b/.idea/misc.xml index c1d50387..8dc5c6c7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,6 @@ + diff --git a/src/main/resources/reports/active_by_product_term_monthly/README.md b/src/main/resources/reports/active_by_product_term_monthly/README.md index ed75eea9..6ce2bfbb 100644 --- a/src/main/resources/reports/active_by_product_term_monthly/README.md +++ b/src/main/resources/reports/active_by_product_term_monthly/README.md @@ -15,9 +15,12 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_active_by_product_term_monthly", "reportType": "TIMELINE", - "reportPrettyName": "Monthly active subscriptions", + "reportPrettyName": "Monthly Active Subscriptions by Product Term", "sourceTableName": "report_active_by_product_term_monthly", "refreshProcedureName": "refresh_active_by_product_term_monthly", "refreshFrequency": "DAILY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## 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/src/main/resources/reports/active_by_product_term_monthly/monthly-active-subs-by-product-term.png new file mode 100644 index 00000000..3b169e45 Binary files /dev/null and b/src/main/resources/reports/active_by_product_term_monthly/monthly-active-subs-by-product-term.png differ diff --git a/src/main/resources/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl b/src/main/resources/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl index fdc00ba4..972619be 100644 --- a/src/main/resources/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl +++ b/src/main/resources/reports/active_by_product_term_monthly/report_active_by_product_term_monthly.ddl @@ -11,27 +11,7 @@ DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; START TRANSACTION; delete from report_active_by_product_term_monthly; - insert into report_active_by_product_term_monthly - select - x.tenant_record_id - , cal.d day - , x.product_name - , x.billing_period - , x.count - from calendar cal - join ( - select - tenant_record_id - , last_day(day) day - , product_name - , billing_period - , count - from - v_report_active_by_product_term_monthly - where 1=1 - ) x on last_day(cal.d) = x.day - where 1=1 - ; + insert into report_active_by_product_term_monthly select * from v_report_active_by_product_term_monthly; COMMIT; END; diff --git a/src/main/resources/reports/cancellations_daily/README.md b/src/main/resources/reports/cancellations_daily/README.md index 38086d8d..9c1787e5 100644 --- a/src/main/resources/reports/cancellations_daily/README.md +++ b/src/main/resources/reports/cancellations_daily/README.md @@ -15,9 +15,12 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_cancellations_daily", "reportType": "TIMELINE", - "reportPrettyName": "Daily cancellations", + "reportPrettyName": "Daily Cancellations", "sourceTableName": "report_cancellations_daily", "refreshProcedureName": "refresh_report_cancellations_daily", "refreshFrequency": "DAILY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## 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/src/main/resources/reports/cancellations_daily/daily-cancellations.png new file mode 100644 index 00000000..1b66818f Binary files /dev/null and b/src/main/resources/reports/cancellations_daily/daily-cancellations.png differ diff --git a/src/main/resources/reports/conversion-total-dollar-amount/README.md b/src/main/resources/reports/conversion-total-dollar-amount/README.md new file mode 100644 index 00000000..cad736e4 --- /dev/null +++ b/src/main/resources/reports/conversion-total-dollar-amount/README.md @@ -0,0 +1,39 @@ +# Conversions Total Dollar Amount Report + +Compute (monthly) the total revenue from subscriptions converting out of trial, grouped by tenant and billing period. + +The snapshot view is: `v_report_conversions_total_dollar_monthly` + +## 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_conversions_total_dollar_monthly", + "reportType": "TIMELINE", + "reportPrettyName": "Conversions Total Dollar Amount", + "sourceTableName": "report_conversions_total_dollar_monthly", + "refreshProcedureName": "refresh_report_conversions_total_dollar_monthly", + "refreshFrequency": "DAILY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` + +## Sample Data + +|Tenant Record Id|Day |Billing Period| Count| +|--|--|--|--| +|1|2025-06-01 |WEEKLY |30| +|1|2025-07-01 |MONTHLY |30| +|1| 2025-07-01 |QUARTERLY |70| +|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`. + +## Report UI: + +![conversion-total-dollar-amount.png](conversion-total-dollar-amount.png) diff --git a/src/main/resources/reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png b/src/main/resources/reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png new file mode 100644 index 00000000..495f8ff5 Binary files /dev/null and b/src/main/resources/reports/conversion-total-dollar-amount/conversion-total-dollar-amount.png differ diff --git a/src/main/resources/reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl b/src/main/resources/reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl new file mode 100644 index 00000000..a0a82d40 --- /dev/null +++ b/src/main/resources/reports/conversion-total-dollar-amount/report_conversions_total_dollar_monthly.ddl @@ -0,0 +1,19 @@ +create table report_conversions_total_dollar_monthly as select * from v_report_conversions_total_dollar_monthly limit 0; + +drop procedure if exists refresh_report_conversions_total_dollar_monthly; +DELIMITER // +CREATE PROCEDURE refresh_report_conversions_total_dollar_monthly() +BEGIN + +DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; +DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK; + +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +START TRANSACTION; + delete from report_conversions_total_dollar_monthly; + insert into report_conversions_total_dollar_monthly select * from v_report_conversions_total_dollar_monthly; +COMMIT; + +END; +// +DELIMITER ; diff --git a/src/main/resources/reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl b/src/main/resources/reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl new file mode 100644 index 00000000..b9045e37 --- /dev/null +++ b/src/main/resources/reports/conversion-total-dollar-amount/v_report_conversions_total_dollar_monthly.ddl @@ -0,0 +1,21 @@ +create or replace view v_report_conversions_total_dollar_monthly as +select + ast.tenant_record_id, + date_format(next_start_date, '%Y-%m-01') day, + next_billing_period billing_period, + round(sum(converted_next_price)) count +from analytics_subscription_transitions ast +join ( + select distinct tenant_record_id, bundle_id + from analytics_invoice_items + where invoice_original_amount_charged > 0 + and invoice_balance = 0 +) paid_bundles + on ast.bundle_id = paid_bundles.bundle_id + and ast.tenant_record_id = paid_bundles.tenant_record_id +where report_group = 'default' + and next_service = 'entitlement-service' + and prev_phase = 'TRIAL' + and next_phase != 'TRIAL' + and event not like 'STOP_ENTITLEMENT%' +group by 1,2,3; diff --git a/src/main/resources/reports/conversion/refresh_report_conversions_total_dollar_monthly.prc b/src/main/resources/reports/conversion/refresh_report_conversions_total_dollar_monthly.prc deleted file mode 100644 index 9c730f04..00000000 --- a/src/main/resources/reports/conversion/refresh_report_conversions_total_dollar_monthly.prc +++ /dev/null @@ -1,39 +0,0 @@ -drop procedure if exists refresh_report_conversions_total_dollar_monthly; -DELIMITER // -CREATE PROCEDURE refresh_report_conversions_total_dollar_monthly() -BEGIN - - DELETE FROM report_conversions_total_dollar_monthly; - - create temporary table report_temp_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 - ; - - insert into report_conversions_total_dollar_monthly - select - ast.tenant_record_id - , date_format(next_start_date, '%Y-%m-01') day - , next_billing_period billing_period - , round(sum(converted_next_price)) count - from - analytics_subscription_transitions ast - join report_temp_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 prev_phase='TRIAL' - and next_phase!='TRIAL' - and event not like 'STOP_ENTITLEMENT%' - group by 1,2,3 - ; - -END; -// -DELIMITER ; diff --git a/src/main/resources/reports/conversion/report_conversions_total_dollar_monthly.ddl b/src/main/resources/reports/conversion/report_conversions_total_dollar_monthly.ddl deleted file mode 100644 index ebb29301..00000000 --- a/src/main/resources/reports/conversion/report_conversions_total_dollar_monthly.ddl +++ /dev/null @@ -1,2 +0,0 @@ -drop table if exists report_conversions_total_dollar_monthly; -create table report_conversions_total_dollar_monthly (tenant_record_id int(11), day date, term varchar(50), count int(10)); diff --git a/src/main/resources/reports/invoices_balance_daily/README.md b/src/main/resources/reports/invoices_balance_daily/README.md index 8fa1736f..fd80acc0 100644 --- a/src/main/resources/reports/invoices_balance_daily/README.md +++ b/src/main/resources/reports/invoices_balance_daily/README.md @@ -15,9 +15,12 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_invoices_balance_daily", "reportType": "TIMELINE", - "reportPrettyName": "Daily invoices balance", + "reportPrettyName": "Daily Invoices Balance", "sourceTableName": "report_invoices_balance_daily", "refreshProcedureName": "refresh_report_invoices_balance_daily", "refreshFrequency": "DAILY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` +## Report UI: + +![invoice-balance-daily.png](invoice-balance-daily.png) \ No newline at end of file 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 new file mode 100644 index 00000000..13fd54fc Binary files /dev/null and b/src/main/resources/reports/invoices_balance_daily/invoice-balance-daily.png differ diff --git a/src/main/resources/reports/invoices_daily/README.md b/src/main/resources/reports/invoices_daily/README.md index 6021359c..b3cc642c 100644 --- a/src/main/resources/reports/invoices_daily/README.md +++ b/src/main/resources/reports/invoices_daily/README.md @@ -15,9 +15,13 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_invoices_daily", "reportType": "TIMELINE", - "reportPrettyName": "Daily invoices value", + "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 new file mode 100644 index 00000000..83f27206 Binary files /dev/null and b/src/main/resources/reports/invoices_daily/invoice-amount-daily.png differ diff --git a/src/main/resources/reports/mrr/README.md b/src/main/resources/reports/mrr/README.md index 330450c8..6200a84a 100644 --- a/src/main/resources/reports/mrr/README.md +++ b/src/main/resources/reports/mrr/README.md @@ -1,6 +1,6 @@ # Daily MRR -Compute the Monthly Recurring Revenue (MRR) on a daily basis. +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` @@ -21,3 +21,18 @@ curl -v \ "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/mrr/daily-mrr.png b/src/main/resources/reports/mrr/daily-mrr.png new file mode 100644 index 00000000..9ed2a0dc Binary files /dev/null and b/src/main/resources/reports/mrr/daily-mrr.png differ diff --git a/src/main/resources/reports/new_accounts_daily/README.md b/src/main/resources/reports/new_accounts_daily/README.md index 924d4b3e..e410b52e 100644 --- a/src/main/resources/reports/new_accounts_daily/README.md +++ b/src/main/resources/reports/new_accounts_daily/README.md @@ -1,6 +1,6 @@ # Daily new accounts report -Compute the total amount of new accounts created per day. +Compute the total amount of new accounts created per day for each tenant. The snapshot view is: `v_report_new_accounts_daily` @@ -15,9 +15,13 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_new_accounts_daily", "reportType": "TIMELINE", - "reportPrettyName": "Daily new accounts", + "reportPrettyName": "Daily New Accounts", "sourceTableName": "report_new_accounts_daily", "refreshProcedureName": "refresh_report_new_accounts_daily", "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## 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/src/main/resources/reports/new_accounts_daily/daily-new-accounts.png new file mode 100644 index 00000000..0a27fe95 Binary files /dev/null and b/src/main/resources/reports/new_accounts_daily/daily-new-accounts.png differ diff --git a/src/main/resources/reports/payments_total_daily/README.md b/src/main/resources/reports/payments_total_daily/README.md index be71c95b..0f806f57 100644 --- a/src/main/resources/reports/payments_total_daily/README.md +++ b/src/main/resources/reports/payments_total_daily/README.md @@ -15,9 +15,13 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_payments_total_daily", "reportType": "TIMELINE", - "reportPrettyName": "Daily payments value", + "reportPrettyName": "Daily Payments Value", "sourceTableName": "report_payments_total_daily", "refreshProcedureName": "refresh_report_payments_total_daily", "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## 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/src/main/resources/reports/payments_total_daily/payments-total-daily.png new file mode 100644 index 00000000..4ab265a1 Binary files /dev/null and b/src/main/resources/reports/payments_total_daily/payments-total-daily.png differ diff --git a/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl b/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl index e1558f8a..c43a4b2e 100644 --- a/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl +++ b/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily.ddl @@ -1,9 +1,28 @@ create or replace view v_report_payments_total_daily as select - tenant_record_id -, day -, currency -, sum(count) as count -from v_report_payments_total_daily_sub1 -group by 1,2,3 -; + tenant_record_id, + date_format(created_date,'%Y-%m-%d') as day, + currency, + sum(ifnull(converted_amount, 0)) as count +from ( + select + ac.tenant_record_id, + ac.created_date, + ac.currency, + ac.converted_amount + from analytics_payment_captures ac + where ac.payment_transaction_status = 'SUCCESS' + and ac.report_group='default' + + union all + + select + ap.tenant_record_id, + ap.created_date, + ap.currency, + ap.converted_amount + from analytics_payment_purchases ap + where ap.payment_transaction_status = 'SUCCESS' + and ap.report_group='default' +) t +group by 1,2,3; diff --git a/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily_sub1.ddl b/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily_sub1.ddl deleted file mode 100644 index bbd885e5..00000000 --- a/src/main/resources/reports/payments_total_daily/v_report_payments_total_daily_sub1.ddl +++ /dev/null @@ -1,25 +0,0 @@ -create or replace view v_report_payments_total_daily_sub1 as -select - ac.tenant_record_id -, 'CAPTURE' as op -, date_format(ac.created_date,'%Y-%m-%d') as day -, ac.currency -, sum(ifnull(ac.converted_amount, 0)) as count -from analytics_payment_captures ac -where 1=1 - and ac.payment_transaction_status = 'SUCCESS' - and ac.report_group='default' -group by 1,2,3,4 -union -select - ap.tenant_record_id -, 'PURCHASE' as op -, date_format(ap.created_date,'%Y-%m-%d') as day -, ap.currency -, sum(ifnull(ap.converted_amount, 0)) as count -from analytics_payment_purchases ap -where 1=1 - and ap.payment_transaction_status = 'SUCCESS' - and ap.report_group='default' -group by 1,2,3,4 -; diff --git a/src/main/resources/reports/refunds_total_daily/README.md b/src/main/resources/reports/refunds_total_daily/README.md index 42fd3c40..34513365 100644 --- a/src/main/resources/reports/refunds_total_daily/README.md +++ b/src/main/resources/reports/refunds_total_daily/README.md @@ -1,6 +1,6 @@ # Daily refunds report -Compute the total value (in the reference currency) of refunds per day per currency. +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` @@ -15,9 +15,13 @@ curl -v \ -H 'Content-Type: application/json' \ -d '{"reportName": "report_refunds_total_daily", "reportType": "TIMELINE", - "reportPrettyName": "Daily refunds value", + "reportPrettyName": "Daily Refunds Value", "sourceTableName": "report_refunds_total_daily", "refreshProcedureName": "refresh_report_refunds_total_daily", "refreshFrequency": "HOURLY"}' \ "http://127.0.0.1:8080/plugins/killbill-analytics/reports" ``` + +## 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/src/main/resources/reports/refunds_total_daily/refunds-total-daily.png new file mode 100644 index 00000000..a4085c9e Binary files /dev/null and b/src/main/resources/reports/refunds_total_daily/refunds-total-daily.png differ diff --git a/src/main/resources/reports/refunds_total_daily/v_report_refunds_total_daily.ddl b/src/main/resources/reports/refunds_total_daily/v_report_refunds_total_daily.ddl index 3502c176..04b86804 100644 --- a/src/main/resources/reports/refunds_total_daily/v_report_refunds_total_daily.ddl +++ b/src/main/resources/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(ar.converted_amount) as count +, sum(abs(ar.converted_invoice_amount_refunded)) as count from analytics_payment_refunds ar where 1=1