Добавил pdf шаблон и выгрузку
This commit is contained in:
20
app/Services/Analytics/Export/AnalyticsPdfExport.php
Normal file
20
app/Services/Analytics/Export/AnalyticsPdfExport.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Analytics\Export;
|
||||
|
||||
use App\Services\Analytics\AnalyticsResult;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Barryvdh\DomPDF\PDF as PdfDocument;
|
||||
|
||||
class AnalyticsPdfExport
|
||||
{
|
||||
public static function render(AnalyticsResult $result, string $title): PdfDocument
|
||||
{
|
||||
return Pdf::loadView('reports.analytics_pdf', [
|
||||
'title' => $title,
|
||||
'columns' => array_map(fn ($c) => $c->toArray(), $result->columns),
|
||||
'rows' => $result->rows,
|
||||
'generatedAt' => now('Asia/Yakutsk')->format('d.m.Y H:i'),
|
||||
])->setPaper('a4', 'landscape');
|
||||
}
|
||||
}
|
||||
43
resources/views/reports/analytics_pdf.blade.php
Normal file
43
resources/views/reports/analytics_pdf.blade.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ $title }}</title>
|
||||
<style>
|
||||
body { font-family: 'DejaVu Sans', sans-serif; font-size: 11px; color: #1f2430; }
|
||||
h1 { font-size: 16px; margin: 0 0 4px; }
|
||||
.sub { color: #6b7280; margin: 0 0 12px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { border: 1px solid #cfd4dc; padding: 4px 6px; text-align: left; vertical-align: top; }
|
||||
th { background: #eef2ff; font-weight: bold; }
|
||||
.empty { color: #6b7280; font-style: italic; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ $title }}</h1>
|
||||
<p class="sub">Сформирован {{ $generatedAt }}</p>
|
||||
|
||||
@if (empty($rows))
|
||||
<p class="empty">Нет данных за выбранный период.</p>
|
||||
@else
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach ($columns as $column)
|
||||
<th>{{ $column['label'] }}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($rows as $row)
|
||||
<tr>
|
||||
@foreach ($columns as $column)
|
||||
<td>{{ $row[$column['key']] ?? '' }}</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@endif
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user