Skip to content

Issue #71 — Backend: Admin Analytics — Revenue & Invoice Stats #655

@yusuftomilola

Description

@yusuftomilola

Location: backend/src/dashboard/providers/admin-analytics.provider.ts

Description

The first set of admin analytics covers financial performance — total revenue ever, revenue this month, revenue last month, a 6-month revenue trend, and invoice summary counts. All revenue figures come from Payment records with status = SUCCESS. The 6-month trend groups payments by calendar month using DATE_TRUNC.

This is the first method on the AdminAnalyticsProvider class. Subsequent issues (#72 and #73) add more methods to the same class — contributors should coordinate to avoid merge conflicts on this file.

Acceptance Criteria

  • An AdminAnalyticsProvider class is created at backend/src/dashboard/providers/admin-analytics.provider.ts with @InjectRepository decorators for Payment and Invoice
  • A getRevenueStats(from?: string, to?: string) method is implemented that returns:
    • total — sum of amountKobo across all SUCCESS payments (filtered by date range if provided)
    • thisMonth — sum of amountKobo for SUCCESS payments where paidAt is in the current calendar month
    • lastMonth — sum of amountKobo for SUCCESS payments where paidAt is in the previous calendar month
    • trend — array of { month: string, totalKobo: number, totalNaira: number } for the last 6 calendar months, computed via DATE_TRUNC('month', "paidAt") grouped query, ordered oldest to newest
  • A getInvoiceStats(from?: string, to?: string) method is implemented that returns:
    • total — total count of all invoices
    • paid — count of invoices with status = PAID
    • pending — count of invoices with status = PENDING
    • totalAmountKobo — sum of amountKobo across all invoices
    • totalAmountNairatotalAmountKobo / 100
  • Both methods accept optional from and to date strings and apply them as filters on the relevant timestamp column when provided
  • npx tsc --noEmit passes with no errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions