@php use App\Services\Reports\ReportCatalog; use App\Services\Reports\ReportDefinition; use App\Services\Reports\ReportFormatter; use App\Services\Reports\ReportOperators; use App\Services\Reports\ReportRunner; $type = $def->effectiveType(); $typeLabel = ['tabular' => 'Tabular', 'summary' => 'Summary', 'matrix' => 'Matrix'][$def->type]; $types = collect($def->columns)->mapWithKeys(fn ($c) => [$c => $def->columnType($c)])->all(); $aggCols = $runner->aggregateColumns(); $groupType = $def->groupColumn ? $def->columnType($def->groupColumn) : null; $groupCounts = collect($groups['rows'] ?? [])->mapWithKeys(fn ($g) => [ReportRunner::bucket($g['__group']) => $g])->all(); $exportQuery = array_filter(['q' => $search, 'sort' => $sort, 'dir' => $dir]); @endphp Edit
@csrf
Print
All records (CSV) @if ($type === 'summary') Group subtotals (CSV) @endif @if ($type === 'matrix') Matrix (CSV) @endif
{{-- Meta strip --}}
{{ $typeLabel }} report {{ ReportCatalog::moduleLabel($def->primary) }}@if ($def->related) + {{ collect($def->related)->map(fn ($m) => ReportCatalog::moduleLabel($m))->join(', ') }}@endif • Updated {{ $report->updated_at?->format('d-m-Y H:i') ?? '—' }} @if ($def->groupColumn && $type !== 'tabular') • Grouped by {{ $def->label($def->groupColumn) }}@if ($type === 'matrix') × {{ $def->label($def->matrixColumn) }}@endif @endif
@if ($def->warnings)

This report was imported from the old system and needs attention:

    @foreach ($def->warnings as $w)
  • {{ $w }}
  • @endforeach
Fix it in the editor
@endif {{-- Filters --}} @if ($def->filters)
Filters @foreach ($def->filters as $i => $f) @if ($i > 0){{ $f['join'] }}@endif {{ $def->label($f['field']) }} {{ ReportOperators::ALL[$f['operator']][0] ?? $f['operator'] }} @if ($f['value'] !== ''){{ str_replace(',', ', ', $f['value']) }}@endif @endforeach
@endif @if ($error)
@else {{-- KPIs --}}
@if ($type === 'summary') @endif @if ($totals) @foreach (array_slice($aggCols, 0, $type === 'summary' ? 2 : 3, true) as $alias => [$fn, $key]) @endforeach @endif
{{-- Chart --}} @if ($chart || $type !== 'tabular') @if ($chart && $chart['labels'])
@elseif ($chart) @else @endif
@endif {{-- Matrix --}} @if ($matrix) @php $rType = $def->columnType($def->groupColumn); $cType = $def->columnType($def->matrixColumn); $max = collect($matrix['cells'])->flatten()->map(fn ($v) => (float) $v)->max() ?: 1; @endphp @if (! $matrix['rows']) @else
@foreach ($matrix['columns'] as $c => $_)@endforeach @foreach ($matrix['rows'] as $r => $rowTotal) @foreach ($matrix['columns'] as $c => $_) @php $v = $matrix['cells'][$r][$c] ?? null; @endphp @endforeach @endforeach @foreach ($matrix['columns'] as $colTotal)@endforeach
{{ $def->label($def->groupColumn) }}{{ ReportFormatter::bucket($c, $cType) }}Total
{{ ReportFormatter::bucket($r, $rType) }}{{ $v === null ? '·' : ReportFormatter::number($v) }}{{ ReportFormatter::number($rowTotal) }}
Total{{ ReportFormatter::number($colTotal) }}{{ ReportFormatter::number($matrix['grand']) }}
@endif
@endif {{-- Group subtotals --}} @if ($type === 'summary') @php $maxCount = max(1, collect($groups['rows'])->max('__count') ?? 1); @endphp @if (! $groups['rows']) @else
@foreach ($aggCols as [$fn, $key])@endforeach @foreach ($groups['rows'] as $g) @foreach ($aggCols as $alias => $_)@endforeach @endforeach
{{ $def->label($def->groupColumn) }} Records{{ ReportDefinition::AGGREGATE_LABELS[$fn] }} · {{ $def->label($key) }}
{{ ReportFormatter::bucket($g['__group'], $groupType) }}
{{ number_format($g['__count']) }}
{{ ReportFormatter::number($g[$alias]) }}
@endif
@endif {{-- Detail records --}}
@if ($rows->isEmpty()) @else
@foreach ($def->columns as $c) @endforeach @php $prevGroup = null; @endphp @foreach ($rows as $i => $row) @if ($type === 'summary' && ! $sort) @php $g = ReportRunner::bucket($row->__group ?? null); @endphp @if ($g !== $prevGroup) @php $prevGroup = $g; @endphp @endif @endif @foreach ($def->columns as $c) @php $val = ReportFormatter::cell($row->{ReportRunner::alias($c)} ?? null, $types[$c]); @endphp @endforeach @endforeach @if ($totals && $aggCols) @foreach (ReportDefinition::AGGREGATE_LABELS as $fn => $fnLabel) @continue(! $def->aggregates[$fn]) @foreach ($def->columns as $c) @php $alias = $fn.'__'.ReportRunner::alias($c); @endphp @endforeach @endforeach @endif
#
{{ $def->label($def->groupColumn) }}: {{ ReportFormatter::bucket($row->__group ?? null, $groupType) }} @isset($groupCounts[$g]) {{ number_format($groupCounts[$g]['__count']) }} records @foreach ($aggCols as $alias => [$fn, $key]) {{ ReportDefinition::AGGREGATE_LABELS[$fn] }} {{ $def->label($key) }}: {{ ReportFormatter::number($groupCounts[$g][$alias]) }} @endforeach @endisset
{{ number_format($rows->firstItem() + $loop->index) }} 40) title="{{ $val }}" @endif>{{ $val === '' ? '—' : $val }}
{{ $fnLabel }}{{ array_key_exists($alias, $totals['values']) ? ReportFormatter::number($totals['values'][$alias]) : '' }}
@if ($totals && collect($aggCols)->contains(fn ($a) => ! in_array($a[1], $def->columns, true)))
Totals of columns not displayed: @foreach ($aggCols as $alias => [$fn, $key]) @continue(in_array($key, $def->columns, true)) {{ ReportDefinition::AGGREGATE_LABELS[$fn] }} {{ $def->label($key) }}: {{ ReportFormatter::number($totals['values'][$alias] ?? null) }} @endforeach
@endif @endif
@endif {{-- Edit chart --}} @php $numeric = collect($def->availableColumns())->where('type', 'number'); $measureOptions = ['count' => 'Record count']; foreach (ReportDefinition::AGGREGATE_LABELS as $fn => $fnLabel) { foreach ($numeric as $key => $col) { $measureOptions["$fn:$key"] = $fnLabel.' of '.$def->label($key); } } $columnOptions = collect($def->availableColumns())->mapWithKeys(fn ($c, $k) => [$k => $def->label($k)])->all(); $chartCfg = $def->chart ?? ['type' => 'column', 'x_axis' => $def->groupColumn, 'measure' => 'count', 'series' => null]; @endphp
@csrf @method('PUT')
Chart type
@foreach (ReportDefinition::CHART_TYPES as $k => $label) @endforeach
@if ($def->chart) @else @endif
@if (! $error && $chart && $chart['labels']) @include('reports.partials.chart-script', ['chart' => $chart, 'canvas' => 'report-chart']) @endif