---
tags: [reports, database]
module: Reports
---

# [DB]DatabaseTables

## Connections
[[_Reports]] · [[[Model]Models]] · [[[Job]Jobs]] · [[[Command]Commands]]

## Tables (tenant connection)

### favorites
| Column | Type | Notes |
|---|---|---|
| id | bigIncrements | PK |
| report_id | — | references ReportsEnum ID (no FK constraint) |
| created_at / updated_at | timestamps | |

Minimal table — just pins a report ID per user session. No user_id column visible in migration (likely set via tenant context).

---

### report_customer_aging
Pre-computed AR aging cache. Populated by `PopulateAgingReportForTenantJob`; read-only during report queries.

| Column | Type | Notes |
|---|---|---|
| id | bigIncrements | PK |
| customer_id | unsignedBigInteger | FK → customers.id (cascade delete) |
| transaction_id | unsignedBigInteger | polymorphic ID |
| transaction_type | enum | `invoice` / `invoice_return` / `debit_note` |
| reference | string | human-readable ref |
| cost_center_id | unsignedBigInteger | nullable · FK → cost_centers.id (set null) |
| fiscal_year_id | unsignedBigInteger | nullable · FK → fiscal_year.id (set null) |
| transaction_date | datetime | when the transaction occurred |
| transaction_due_date | datetime | used for aging bucket placement |
| amount | decimal 63,2 | positive = invoice; negative = return/credit |
| paid_amount | decimal 63,2 | default 0.00 |
| created_at / updated_at | timestamps | |

**Indexes:** `idx_customer_id` · `idx_transaction` · `idx_cost_center_id` · `idx_transaction_date` · `idx_due_date` · `idx_fiscal_year_id`

**Note:** `amount - paid_amount = outstanding balance` (computed in `ReportCustomerAging::getBalanceAttribute()`). Invoice returns stored as negative `amount`.

---

## Permissions (migration-only, no table)
Two permission-seeder migrations add role permissions at deploy time:
- `reports.customer-tax-report.{view|edit|create|delete|export}`
- `reports.supplier-tax-report.{view|edit|create|delete|export}`
- `reports.customer-aging.{view|edit|create|delete|export}`
