Repository navigation
feat(analytics): add revenue-by-currency report - #1843
Merged
github-actions[bot] merged 2 commits intoOct 19, 2026
Merged
github-actions[bot] merged 2 commits into
github-actions[bot] merged 2 commits into
Conversation
Implements issue Smartdevs17#1757. Revenue is now grouped per currency with monthly/annual totals, subscription counts, averages, and percentage shares. Reports are exportable as CSV or JSON. New files backend/services/analytics/revenueByCurrencyReport.ts - RevenueByCurrencyReportService: generateReport() groups subscriptions by currency, computes per-currency MRR/ARR/average/percentage - toMonthlyEquivalent(): normalises billing cycles to monthly (monthly/yearly/weekly/custom) - exportReport(): CSV (with totals row) or pretty-printed JSON - Accepts SubscriptionRevenueInput[] — maps to both frontend Subscription.price and backend Subscription.amount backend/services/analytics/revenueByCurrencyRouter.ts - GET /reports/revenue-by-currency?merchantId=…&format=csv|json - CSV responses use text/csv with Content-Disposition for download - Injectable SubscriptionProvider for testability backend/services/analytics/__tests__/revenueByCurrencyReport.test.ts - 27 unit tests; all passing Modified backend/server.ts — wires the service and router; route placed before the 404 fallback Closes Smartdevs17#1757
|
@retkatmun Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1757
Summary
Multi-currency revenue is now grouped per currency with monthly/annual totals, subscription counts, averages, and percentage shares. Reports are exportable as CSV or JSON via a new HTTP endpoint.
Changes
New files:
backend/services/analytics/revenueByCurrencyReport.tsgenerateReport()groups subscriptions by currency, computing per-currency MRR, ARR, average, and percentage.toMonthlyEquivalent()normalises billing cycles (monthly/yearly/weekly/custom).exportReport()produces CSV (with totals row) or pretty-printed JSON.backend/services/analytics/revenueByCurrencyRouter.tsbackend/services/analytics/__tests__/revenueByCurrencyReport.test.tsModified:
backend/server.ts— wires the service and router; route placed before the 404 fallback.Design decisions
SubscriptionRevenueInput[]— a minimal shape withamount,currency,billingCycle, and optionalstatus. This maps to both the frontendSubscription.priceand backendSubscription.amountwithout coupling to either.toMonthlyEquivalent()converts yearly (÷12), weekly (×52/12), and custom/unknown (as-is) to a monthly equivalent so all currencies are comparable.Acceptance criteria (from issue)
?format=query parameterTesting
Covers:
toMonthlyEquivalent()for all billing cycles,generateReport()(empty input, status filtering, single/multi-currency, percentage calculation, sorting, currency normalisation, billing cycle normalisation),exportReport()JSON round-trip, CSV headers/rows/totals/escaping.