52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticketing\Desfile\Services;
|
|
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
use Barryvdh\DomPDF\PDF as DomPdf;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class EntryReservationPdfService
|
|
{
|
|
public function __construct(private readonly EntryReservationReportService $report) {}
|
|
|
|
/** @param Collection<int, EntryReservation> $reservations */
|
|
public function download(Tenant $tenant, Collection $reservations, string $timeZone): Response
|
|
{
|
|
$generatedAt = now();
|
|
$rows = $this->report->rows($reservations);
|
|
$pdf = Pdf::loadView('pdf.adminapp.desfile-entry-reservations', [
|
|
'tenant' => $tenant,
|
|
'reservations' => $rows,
|
|
'generatedAt' => $generatedAt,
|
|
'timeZone' => $timeZone,
|
|
])->setPaper('a4', 'landscape');
|
|
|
|
$this->addPageNumbers($pdf);
|
|
|
|
return $pdf->download(
|
|
'reservas_entradas_'.$tenant->codigo.'_'
|
|
.$generatedAt->copy()->timezone($timeZone)->format('Ymd_His').'.pdf'
|
|
);
|
|
}
|
|
|
|
private function addPageNumbers(DomPdf $pdf): void
|
|
{
|
|
$pdf->render();
|
|
$domPdf = $pdf->getDomPDF();
|
|
$font = $domPdf->getFontMetrics()->getFont('DejaVu Sans');
|
|
|
|
$domPdf->getCanvas()->page_text(
|
|
385,
|
|
575,
|
|
'Página {PAGE_NUM} de {PAGE_COUNT}',
|
|
$font,
|
|
7,
|
|
[0.48, 0.52, 0.49],
|
|
);
|
|
}
|
|
}
|