2026-08-24 12:32:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
use App\DTO\ReportFilters;
|
2026-08-28 13:04:28 +02:00
|
|
|
use App\Models\Project;
|
2026-09-01 14:44:11 +02:00
|
|
|
use App\Services\Report\DataAggregator;
|
|
|
|
|
use App\Services\Report\HtmlExporter;
|
|
|
|
|
use App\Services\Report\ExcelExporter;
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
2026-08-24 12:32:08 +02:00
|
|
|
|
|
|
|
|
class ReportGenerator
|
|
|
|
|
{
|
|
|
|
|
protected Project $project;
|
|
|
|
|
protected ReportFilters $filters;
|
|
|
|
|
|
2026-09-01 14:44:11 +02:00
|
|
|
protected DataAggregator $dataAggregator;
|
|
|
|
|
protected HtmlExporter $htmlExporter;
|
|
|
|
|
protected ExcelExporter $excelExporter;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
Project $project,
|
|
|
|
|
ReportFilters $filters,
|
|
|
|
|
?DataAggregator $dataAggregator = null,
|
|
|
|
|
?HtmlExporter $htmlExporter = null,
|
|
|
|
|
?ExcelExporter $excelExporter = null
|
|
|
|
|
) {
|
2026-08-24 12:32:08 +02:00
|
|
|
$this->project = $project;
|
|
|
|
|
$this->filters = $filters;
|
2026-09-01 14:44:11 +02:00
|
|
|
$this->dataAggregator = $dataAggregator ?? new DataAggregator($project, $filters);
|
|
|
|
|
$this->htmlExporter = $htmlExporter ?? new HtmlExporter();
|
|
|
|
|
$this->excelExporter = $excelExporter ?? new ExcelExporter();
|
2026-08-24 12:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function generate(): array
|
|
|
|
|
{
|
2026-09-01 14:44:11 +02:00
|
|
|
return $this->dataAggregator->aggregate();
|
2026-08-24 12:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-01 14:44:11 +02:00
|
|
|
public function renderHtml(): View
|
2026-08-24 12:32:08 +02:00
|
|
|
{
|
2026-09-01 14:44:11 +02:00
|
|
|
$data = $this->generate();
|
|
|
|
|
return $this->htmlExporter->export($this->project, $data);
|
2026-08-24 12:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-01 14:44:11 +02:00
|
|
|
public function renderPreview(): View
|
2026-08-24 12:32:08 +02:00
|
|
|
{
|
2026-09-01 14:44:11 +02:00
|
|
|
$data = $this->generate();
|
|
|
|
|
return $this->htmlExporter->exportPreview($data);
|
2026-08-24 12:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-01 14:44:11 +02:00
|
|
|
public function exportExcel(): BinaryFileResponse
|
2026-08-24 12:32:08 +02:00
|
|
|
{
|
2026-09-01 14:44:11 +02:00
|
|
|
$data = $this->generate();
|
|
|
|
|
return $this->excelExporter->export($this->project, $this->filters, $data);
|
2026-08-24 12:32:08 +02:00
|
|
|
}
|
2026-09-01 14:44:11 +02:00
|
|
|
}
|