From e945da2f6ea528e4da8655b5cd5c737fa52434a2 Mon Sep 17 00:00:00 2001 From: reshmabidikar Date: Mon, 15 Sep 2025 13:56:35 +0530 Subject: [PATCH 1/3] Additional reports for accounts, bundles and payment summary. --- reports/accounts_summary/README.md | 23 ++++++++++++++++++ .../report_accounts_summary.ddl | 19 +++++++++++++++ .../v_report_account_summary.ddl | 22 +++++++++++++++++ reports/bundles_summary/Readme.md | 23 ++++++++++++++++++ .../report_bundles_summary.ddl | 19 +++++++++++++++ .../v_report_bundles_summary.ddl | 24 +++++++++++++++++++ reports/payments_summary/Readme.md | 23 ++++++++++++++++++ .../report_payments_summary.ddl | 19 +++++++++++++++ .../payments_summary/v_payments_summary.ddl | 14 +++++++++++ 9 files changed, 186 insertions(+) create mode 100644 reports/accounts_summary/README.md create mode 100644 reports/accounts_summary/report_accounts_summary.ddl create mode 100644 reports/accounts_summary/v_report_account_summary.ddl create mode 100644 reports/bundles_summary/Readme.md create mode 100644 reports/bundles_summary/report_bundles_summary.ddl create mode 100644 reports/bundles_summary/v_report_bundles_summary.ddl create mode 100644 reports/payments_summary/Readme.md create mode 100644 reports/payments_summary/report_payments_summary.ddl create mode 100644 reports/payments_summary/v_payments_summary.ddl diff --git a/reports/accounts_summary/README.md b/reports/accounts_summary/README.md new file mode 100644 index 00000000..029e971e --- /dev/null +++ b/reports/accounts_summary/README.md @@ -0,0 +1,23 @@ +# 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 + +``` +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": "TABLE", + "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/reports/accounts_summary/report_accounts_summary.ddl b/reports/accounts_summary/report_accounts_summary.ddl new file mode 100644 index 00000000..bb307650 --- /dev/null +++ b/reports/accounts_summary/report_accounts_summary.ddl @@ -0,0 +1,19 @@ +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/reports/accounts_summary/v_report_account_summary.ddl b/reports/accounts_summary/v_report_account_summary.ddl new file mode 100644 index 00000000..f0d76a9d --- /dev/null +++ b/reports/accounts_summary/v_report_account_summary.ddl @@ -0,0 +1,22 @@ +create or replace view v_report_accounts_summary as +select + aa.tenant_record_id, + aa.account_id as AccountID, + aa.email as Email, + aa.created_date as CreatedDate, + aa.nb_active_bundles as ActiveBundlesCount, + aa.balance as AccountBalance, + aa.billing_cycle_day_local as BCD, + aa.currency as Currency, + pm.plugin_name as PaymentMethodName, + aat.state as AccountStatus +from analytics_accounts aa +left join payment_methods pm + on aa.payment_method_id = pm.id +left join analytics_account_transitions aat + on aa.account_id = aat.account_id + and aat.created_date = ( + select max(created_date) + from analytics_account_transitions + where account_id = aa.account_id + ); diff --git a/reports/bundles_summary/Readme.md b/reports/bundles_summary/Readme.md new file mode 100644 index 00000000..f96c8447 --- /dev/null +++ b/reports/bundles_summary/Readme.md @@ -0,0 +1,23 @@ +# Bundles Summary Report + +Provides a subscription bundle summary. Provides details like CTD, plan name, price, for the base subscription in a bundle. + +The snapshot view is: `v_report_bundles_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_bundles_summary", + "reportType": "TABLE", + "reportPrettyName": "Bundles summary", + "sourceTableName": "report_bundles_summary", + "refreshProcedureName": "refresh_report_bundles_summary", + "refreshFrequency": "HOURLY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` diff --git a/reports/bundles_summary/report_bundles_summary.ddl b/reports/bundles_summary/report_bundles_summary.ddl new file mode 100644 index 00000000..5387ba11 --- /dev/null +++ b/reports/bundles_summary/report_bundles_summary.ddl @@ -0,0 +1,19 @@ +create table report_bundles_summary as select * from v_report_bundles_summary limit 0; + +drop procedure if exists refresh_report_bundles_summary; +DELIMITER // +CREATE PROCEDURE refresh_report_bundles_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_bundles_summary; + insert into report_bundles_summary select * from v_report_bundles_summary; +COMMIT; + +END; +// +DELIMITER ; diff --git a/reports/bundles_summary/v_report_bundles_summary.ddl b/reports/bundles_summary/v_report_bundles_summary.ddl new file mode 100644 index 00000000..5a9e7519 --- /dev/null +++ b/reports/bundles_summary/v_report_bundles_summary.ddl @@ -0,0 +1,24 @@ +create or replace view v_report_bundles_summary as +select + ab.tenant_record_id, + ab.bundle_id as BundleId, + ab.account_id as AccountID, + ab.account_external_key as AccountExternalKey, + aa.email as AccountEmail, + ab.created_date as CreatedDate, + ab.current_start_date as StartDate, + ab.charged_through_date as ChargedThroughDate, + date_format(ab.created_date,'%Y-%m-%d') as day, + case + when ab.current_state in ('ENT_STARTED', 'START_BILLING') then 'ACTIVE' + when ab.current_state = 'STOP_BILLING' then 'CANCELLED' + else ab.current_state + end as Status, + -- Remove "-" from current_slug + left(ab.current_slug, length(ab.current_slug) - length(ab.current_phase) - 1) as PlanName, + ab.current_price as Price, + aa.currency as Currency +from analytics_bundles ab +left join analytics_accounts aa + on ab.account_record_id = aa.account_record_id; + diff --git a/reports/payments_summary/Readme.md b/reports/payments_summary/Readme.md new file mode 100644 index 00000000..8d02c88c --- /dev/null +++ b/reports/payments_summary/Readme.md @@ -0,0 +1,23 @@ +# Payments Summary Report + +Provides payment summary. Provides details like payment_id, amount, etc. + +The snapshot view is: `v_report_payments_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_payments_summary", + "reportType": "TABLE", + "reportPrettyName": "Payments summary", + "sourceTableName": "report_payments_summary", + "refreshProcedureName": "refresh_report_payments_summary", + "refreshFrequency": "HOURLY"}' \ + "http://127.0.0.1:8080/plugins/killbill-analytics/reports" +``` diff --git a/reports/payments_summary/report_payments_summary.ddl b/reports/payments_summary/report_payments_summary.ddl new file mode 100644 index 00000000..31fc1698 --- /dev/null +++ b/reports/payments_summary/report_payments_summary.ddl @@ -0,0 +1,19 @@ +create table report_payments_summary as select * from v_report_payments_summary limit 0; + +drop procedure if exists refresh_report_payments_summary; +DELIMITER // +CREATE PROCEDURE refresh_report_payments_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_payments_summary; + insert into report_payments_summary select * from v_report_payments_summary; +COMMIT; + +END; +// +DELIMITER ; diff --git a/reports/payments_summary/v_payments_summary.ddl b/reports/payments_summary/v_payments_summary.ddl new file mode 100644 index 00000000..55d2b4f5 --- /dev/null +++ b/reports/payments_summary/v_payments_summary.ddl @@ -0,0 +1,14 @@ +create or replace view v_report_payments_summary as +select app.payment_number as PaymentNumber, +app.payment_id as PaymentID, +app.created_date as PaymentDate, +app.payment_transaction_status as Status, +app.account_id as AccountID, +aa.email as AccountEmail, +app.account_external_key as AccountExternalKey, +app.plugin_name as PaymentProvider, +app.amount as PaymentAmount, +app.currency as Currency, +app.tenant_record_id +from analytics_payment_purchases app +left join analytics_accounts aa on app.account_id=aa.account_id \ No newline at end of file From 6870e818da0041af09290f9307a34a0ae21e93d9 Mon Sep 17 00:00:00 2001 From: reshmabidikar Date: Thu, 18 Sep 2025 09:04:03 +0530 Subject: [PATCH 2/3] Add NextInvoiceDate to accounts report/minor fix to payment report --- reports/accounts_summary/v_report_account_summary.ddl | 9 +++++++-- reports/payments_summary/v_payments_summary.ddl | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/reports/accounts_summary/v_report_account_summary.ddl b/reports/accounts_summary/v_report_account_summary.ddl index f0d76a9d..75a842d1 100644 --- a/reports/accounts_summary/v_report_account_summary.ddl +++ b/reports/accounts_summary/v_report_account_summary.ddl @@ -9,7 +9,9 @@ select aa.billing_cycle_day_local as BCD, aa.currency as Currency, pm.plugin_name as PaymentMethodName, - aat.state as AccountStatus + aat.state as AccountStatus, + date_format(aa.created_date,'%Y-%m-%d') as day, + n.effective_date as NextInvoiceDate from analytics_accounts aa left join payment_methods pm on aa.payment_method_id = pm.id @@ -19,4 +21,7 @@ left join analytics_account_transitions aat select max(created_date) from analytics_account_transitions where account_id = aa.account_id - ); + ) +left join notifications n +on aa.account_record_id=n.search_key1 +and n.class_name='org.killbill.billing.invoice.notification.NextBillingDateNotificationKey'; diff --git a/reports/payments_summary/v_payments_summary.ddl b/reports/payments_summary/v_payments_summary.ddl index 55d2b4f5..73abecb8 100644 --- a/reports/payments_summary/v_payments_summary.ddl +++ b/reports/payments_summary/v_payments_summary.ddl @@ -9,6 +9,7 @@ app.account_external_key as AccountExternalKey, app.plugin_name as PaymentProvider, app.amount as PaymentAmount, app.currency as Currency, -app.tenant_record_id +app.tenant_record_id, +date_format(app.created_date,'%Y-%m-%d') as day from analytics_payment_purchases app left join analytics_accounts aa on app.account_id=aa.account_id \ No newline at end of file From 35ddc954e330881ca961f2c377aa1c35f8037a7c Mon Sep 17 00:00:00 2001 From: reshmabidikar Date: Thu, 18 Sep 2025 12:06:55 +0530 Subject: [PATCH 3/3] Fix README capitalization --- reports/bundles_summary/{Readme.md => README.md} | 0 reports/payments_summary/{Readme.md => README.md} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename reports/bundles_summary/{Readme.md => README.md} (100%) rename reports/payments_summary/{Readme.md => README.md} (100%) diff --git a/reports/bundles_summary/Readme.md b/reports/bundles_summary/README.md similarity index 100% rename from reports/bundles_summary/Readme.md rename to reports/bundles_summary/README.md diff --git a/reports/payments_summary/Readme.md b/reports/payments_summary/README.md similarity index 100% rename from reports/payments_summary/Readme.md rename to reports/payments_summary/README.md