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

# [Controller]Controllers

## Connections
[[_Reports]] · [[[Service]FinancialServices]] · [[[Service]SummaryServices]] · [[[Service]CustomerAgingService]] · [[[Service]UtilityServices]] · [[[Routes]Routes]]

## Source
`Modules/Reports/Http/Controllers/`

All controllers extend `TenantBaseController`. Every index method calls `SubscriptionReportStatusService` to gate by subscription package.

---

## Pattern (applies to almost every report)

```
index()  → validate → subscription check → Service::execute() → view or DataTables JSON
export() → validate → subscription check → ExportingService::execute() → PDF download
print()  → validate → subscription check → ExportingService::execute() → PDF inline
```

Excel export is a separate single-action controller in `Exporting/Excel/` subfolder.

---

## ReportController
`index` — lists all available reports via `IndexingReportsService`.

## ReportFavoriteController
`store` (POST) — `AddingToFavoritesService`  
`destroy` (DELETE `/{favorite}`) — `RemovingFromFavoritesService`

---

## Financial Statement Controllers

| Controller | Report | Notable Behaviour |
|---|---|---|
| AccountStatementController | Account Statement | AJAX DataTables; applies cost-center permission filter for non-owners |
| AccountSummaryController | Account Summary | Monthly grouping view |
| BalanceSheetController | Balance Sheet | Routes to BalanceSheetComparisonService when `compare_option_id` set |
| IncomeStatementController | Income Statement | Routes to IncomeStatementComparisonService when `compare_option_id` set |
| TrialBalanceController | Trial Balance (standard) | Uses TrialBalanceService |
| SaudiTrialBalanceController | Trial Balance (Saudi) | Uses SaudiTrialBalanceService; landscape PDF orientation |
| GeneralLedgerController | General Ledger | Max 10,000 records enforced for PDF/print exports |
| JournalReportController | Journal Report | AJAX DataTables; max 2,000 entries for PDF exports |
| CashFlowController | Cash Flow (indirect) | — |
| CashFlowDirectController | Cash Flow (direct) | Uses CashFlowDirectMainSectionsEnum for section structure |

---

## Summary & Operational Controllers

| Controller | Report | Notable Behaviour |
|---|---|---|
| NewTaxesReportController | Taxes Report | — |
| TaxReportController | Customer + Supplier Tax | Single controller handles both; `getCustomerTaxReport()` / `getSupplierTaxReport()` |
| CostCenterController | Cost Center | Non-owners must select a cost center |
| AssetDetailsController | Asset Details | — |
| SalesSummaryController | Sales Summary | Non-owners must select cost centers |
| PurchasesSummaryController | Purchases Summary | Non-owners must select cost centers |

---

## CustomerAgingController

Most complex controller. Handles both web (HTML/DataTables) and API (JSON) responses.

**Web methods:**
| Method | Purpose |
|---|---|
| index | AR Aging summary table (DataTables, AJAX-aware) |
| getDetailsHtml | Inline expansion rows for a single customer — returns HTML skeleton or DataTables JSON |
| exportPdf | Full summary PDF download (perPage = PHP_INT_MAX) |
| printSummary | Full summary PDF inline |
| printCustomer | Per-customer detail PDF (all transactions) |

**API methods** (returns JSON):
| Method | Route suffix |
|---|---|
| getSummary | /summary |
| getDetails | /details |
| getGrandTotals | /grand-totals |
| getCustomerBalance | /customer-balance |
| getPeriodLabels | /period-labels |

---

## Excel Export Controllers (`Exporting/Excel/`)

One single-action `__invoke` controller per report. All follow the same pattern:
1. Validate
2. Check subscription
3. Call service to get data
4. Return `Excel::download(new ExcelViewExport($data, $view), 'ReportName_Date.xlsx')`

Controllers: `AccountStatementController` · `AccountSummaryController` · `BalanceSheetController` · `CashFlowController` · `CashFlowDirectController` · `CostCenterController` · `CustomerAgingController` · `CustomerTaxReportController` · `GeneralLedgerController` · `IncomeStatementController` · `JournalReportController` · `PurchasesSummaryController` · `SalesSummaryController` · `SaudiTrialBalanceController` · `SupplierTaxReportController` · `TaxesReportController` · `AssetDetailsController`
