commit c993da3397b65488d919d1b929cbd4638754601b Author: ncoronel <ncoronel@quo.ar> Date: Tue Jul 28 09:54:10 2026 -0300 feat(tickets): update ticket metadata layout for improved readability and clarity commit 140fa4676d84bed788894e1d7994b26dccac7a34 Author: ncoronel <ncoronel@quo.ar> Date: Tue Jul 28 09:43:21 2026 -0300 feat(tickets): enhance PDF ticket download with dynamic filename and improved styling commit 8875c047b198776e61e8353c99cf4c7b00bc8fc9 Author: ncoronel <ncoronel@quo.ar> Date: Tue Jul 28 09:03:17 2026 -0300 feat(tickets): add PDF download functionality for tickets - Implemented a new endpoint to download tickets as a PDF. - Created DownloadTicketsPdfRequest for validating ticket IDs. - Added TicketPdfService to handle PDF generation and QR code embedding. - Developed a Blade view for rendering ticket details in PDF format. - Updated API routes to include the new PDF download route. - Added tests to ensure authenticated users can download their tickets and that users cannot download tickets belonging to others. - Updated composer.json and composer.lock to include necessary dependencies for PDF generation and QR code creation.
49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticket\Controllers;
|
|
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use App\Domains\Ticket\Models\Ticket;
|
|
use App\Domains\Ticket\Requests\DownloadTicketsPdfRequest;
|
|
use App\Domains\Ticket\Resources\TicketResource;
|
|
use App\Domains\Ticket\Services\TicketPdfService;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class TicketController extends Controller
|
|
{
|
|
public function __construct(private readonly TicketPdfService $ticketPdfService) {}
|
|
|
|
public function index(Request $request, Tenant $tenant): JsonResponse
|
|
{
|
|
$tickets = Ticket::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('user_id', $request->user()->getKey())
|
|
->orderByDesc('id')
|
|
->get();
|
|
|
|
return TicketResource::collection($tickets)->response();
|
|
}
|
|
|
|
public function downloadPdf(DownloadTicketsPdfRequest $request, Tenant $tenant): Response
|
|
{
|
|
$ticketIds = $request->validated('ticket_ids');
|
|
$tickets = Ticket::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('user_id', $request->user()->getKey())
|
|
->whereIn('id', $ticketIds)
|
|
->orderByDesc('id')
|
|
->get();
|
|
|
|
abort_if(
|
|
$tickets->count() !== count($ticketIds),
|
|
404,
|
|
'Uno o más tickets no están disponibles.'
|
|
);
|
|
|
|
return $this->ticketPdfService->download($tenant, $tickets);
|
|
}
|
|
}
|