Credit Reporting & Aging
Relevant source files
The following files were used as context for generating this wiki page:
The Credit Reporting & Aging system in DRX is a comprehensive framework designed to manage customer debt, monitor business-wide credit exposure, and utilize AI-driven risk assessment. It allows businesses to extend credit lines to customers ("buy now, pay later"), track repayment behaviors, and categorize outstanding balances into aging buckets to identify delinquent accounts.
The system integrates real-time transaction data with automated risk scoring to provide managers with actionable insights into the financial health of their credit portfolio. This ensures that businesses can lend responsibly while maintaining visibility into potential defaults.
Sources: README.md:12-13, scripts/help-center-data.ts:587-593, supabase/functions/credit_risk/index.ts:161-180
System Architecture & Data Flow
The credit system operates through a combination of frontend dashboards, background edge functions, and database views. The core data resides in credit_transactions and credit_limits tables, which are processed to generate metrics for the CreditExposureDashboard and individual customer profiles.
Credit Data Processing Flow
The following diagram illustrates how raw credit transactions are processed into aging reports and risk scores:
The system fetches credit extensions and payments, categorizes them by due dates, and applies logic to determine risk levels.
Sources: supabase/functions/credit_risk/index.ts:31-90, app/(app)/credit/page.tsx:102-118
Credit Exposure Monitoring
The CreditExposureDashboard serves as the primary interface for managers to monitor the business's total financial risk. It aggregates data into key performance indicators (KPIs) and provides automated recommendations based on portfolio utilization.
Key Metrics
| Metric | Description | Source |
|---|---|---|
| Total Credit Limits | The sum of all credit lines extended to customers. | CreditExposureDashboard.tsx:116 |
| Current Balance | The total amount currently owed to the business across all accounts. | CreditExposureDashboard.tsx:124 |
| Utilization Ratio | The percentage of total credit limits currently being used (Balance / Limits). | CreditExposureDashboard.tsx:132 |
| At-Risk Customers | Count of customers with high delinquency or poor reliability scores. | CreditExposureDashboard.tsx:168 |
Utilization Thresholds
The system applies color-coded status indicators based on the utilization ratio:
- Low (< 60%): Green / Healthy - Regular monitoring recommended.
- High (60% - 80%): Yellow / Warning - Reviewing limits or collecting payments suggested.
- Critical (> 80%): Red / Danger - Immediate attention or credit holds required.
Sources: components/credit/CreditExposureDashboard.tsx:86-104, components/credit/CreditExposureDashboard.tsx:201-218
Credit Aging & Delinquency
Aging reporting categorizes outstanding debt based on how long a payment has been overdue. This logic is primarily handled in the credit_risk edge function and displayed in the CreditAgingTable.
Aging Buckets
The system segments overdue amounts into four distinct time periods:
- 1-7 Days: Recent overdue accounts.
- 8-14 Days: Moderate delinquency.
- 15-30 Days: High-priority collection.
- 31+ Days: Critical delinquency/potential default.
Sources: supabase/functions/credit_risk/index.ts:74-80, app/(app)/credit/page.tsx:105-107
Reliability Scoring
Customer reliability is calculated as a percentage based on historical repayment behavior:
reliabilityScore = (PaidOnTime / TotalExtensions) * 100
This score determines the risk_level assigned to each customer (Low, Medium, High, Critical).
Sources: supabase/functions/credit_risk/index.ts:130-153
AI-Powered Risk Insights
DRX leverages AI to provide deep analysis of the credit portfolio. The system sends delinquency data and aging bucket summaries to a language model (OpenAI) to generate strategic recommendations.
AI Processing Sequence
Component Overview
| Component | Responsibility | File Path |
|---|---|---|
CreditExposureDashboard | Displays aggregate risk metrics and AI recommendations. | components/credit/CreditExposureDashboard.tsx |
CreditAgingTable | Lists customers and their balances categorized by aging buckets. | app/(app)/credit/page.tsx |
AICreditPanel | Provides per-customer AI limit recommendations and risk scores. | app/(app)/customers/[id]/page.tsx |
CreditStats | Visual summary of pending transactions and total outstanding. | app/(app)/credit/page.tsx |
The CreditPage acts as the orchestrator, utilizing the useCreditManager hook to fetch data for these components and manage UI dialogs for payments and extensions.
Sources: app/(app)/credit/page.tsx:23-45, app/(app)/customers/[id]/page.tsx:132-152
Summary
Credit Reporting & Aging in DRX provides an end-to-end workflow for managing store credit risk. By combining traditional aging bucket analysis with modern AI-driven insights and reliability scoring, the system enables managers to identify financial bottlenecks, prioritize collections, and adjust credit limits dynamically based on actual customer behavior.