Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
420 lines
14 KiB
Markdown
420 lines
14 KiB
Markdown
# Billing Dashboard Enhancement Project
|
||
|
||
## Project Overview
|
||
|
||
This project aims to enhance the billing dashboard by replacing dummy/static values with actual data calculated from the database. This involves introducing a comprehensive reporting module to gather and present real-time billing metrics.
|
||
|
||
## Current State Analysis
|
||
|
||
### Current Billing Dashboard Structure
|
||
|
||
The billing dashboard is implemented as a tabbed interface (`BillingDashboard.tsx`) with the following components:
|
||
|
||
- **Overview Tab**: Currently displays static values (15 active plans, 87 clients, $123,456 revenue)
|
||
- **Other Tabs**: Generate Invoices, Invoices, Invoice Templates, Tax Rates, Plans, Plan Bundles, Service Catalog, Billing Cycles, Time Periods, Usage Tracking, Credits, Reconciliation
|
||
|
||
### Current Overview Component Analysis
|
||
|
||
Located at: `server/src/components/billing-dashboard/Overview.tsx`
|
||
|
||
**Current Issues:**
|
||
- All metric values are hardcoded (static)
|
||
- No database integration
|
||
- No real-time data fetching
|
||
- Missing key billing insights
|
||
|
||
**Current Dummy Values:**
|
||
- Active Contract Lines: 15 (hardcoded)
|
||
- Total Clients: 87 (hardcoded)
|
||
- Monthly Revenue: $123,456 (hardcoded)
|
||
- Active Services: 15 (hardcoded)
|
||
|
||
## Database Structure Analysis
|
||
|
||
### Key Billing Tables Available
|
||
|
||
Based on comprehensive migration analysis, the following tables contain data needed for dashboard metrics:
|
||
|
||
#### Core Data Sources:
|
||
1. **`companies`** - Customer entities with billing settings
|
||
2. **`invoices`** - Invoice records with amounts, dates, status
|
||
3. **`invoice_items`** - Line items with detailed pricing
|
||
4. **`contract_lines`** - Available contract lines and configurations
|
||
5. **`client_contract_lines`** - Active plan assignments
|
||
6. **`service_catalog`** - Available services and default rates
|
||
7. **`time_entries`** - Billable time tracking
|
||
8. **`usage_tracking`** - Usage-based billing data
|
||
9. **`transactions`** - Financial transaction history
|
||
|
||
#### Advanced Tables:
|
||
- **`plan_bundles`** - Bundle definitions and assignments
|
||
- **`bucket_usage`** - Hour bucket consumption tracking
|
||
- **`tax_rates`** - Tax calculation data
|
||
- **`credit_tracking`** - Credit balances and applications
|
||
|
||
### Data Storage Patterns:
|
||
- **Monetary values**: Stored as integers in cents for precision
|
||
- **Multi-tenancy**: All tables include `tenant` UUID for isolation
|
||
- **Date handling**: Business dates use `date` type, timestamps use `timestamptz`
|
||
- **Indexes**: Optimized for tenant-based queries and billing operations
|
||
|
||
## Required Dashboard Metrics
|
||
|
||
### Primary Metrics (High Priority)
|
||
1. **Active Contract Lines Count**
|
||
- Source: `contract_lines` WHERE `is_active = true`
|
||
- Filter by tenant
|
||
|
||
2. **Active Billing Clients Count**
|
||
- Source: `companies` with active `client_contract_lines`
|
||
- Join companies with client_contract_lines WHERE `is_active = true`
|
||
|
||
3. **Monthly Revenue**
|
||
- Source: `invoices` WHERE status indicates completion
|
||
- Sum `total_amount` for current month
|
||
- Convert from cents to dollars for display
|
||
|
||
4. **Active Services Count**
|
||
- Source: `service_catalog` WHERE active/available
|
||
- Filter by tenant
|
||
|
||
### Secondary Metrics (Medium Priority)
|
||
5. **Outstanding Invoices Amount**
|
||
- Source: `invoices` WHERE status = 'open' or 'overdue'
|
||
- Sum `total_amount - credit_applied`
|
||
|
||
6. **Current Month Billable Hours**
|
||
- Source: `time_entries` WHERE `billable = true` AND current month
|
||
- Sum `billable_duration` and convert to hours
|
||
|
||
7. **Credit Balance Total**
|
||
- Source: `companies.credit_balance` or aggregate from `credit_tracking`
|
||
|
||
8. **Pending Time Entries**
|
||
- Source: `time_entries` WHERE `approval_status = 'pending'`
|
||
|
||
### Advanced Metrics (Low Priority)
|
||
9. **Revenue Trends** (monthly comparison)
|
||
10. **Top Services by Revenue**
|
||
11. **Client Payment Status Distribution**
|
||
12. **Bucket Usage Summary**
|
||
|
||
## Proposed Server Actions Structure
|
||
|
||
### Location
|
||
Create new directory: `/server/src/lib/actions/billing-dashboard-actions/`
|
||
|
||
### Action Files Structure
|
||
```
|
||
billing-dashboard-actions/
|
||
|