feat(desfile): download reserved ticket PDF
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Domains\Ticketing\Desfile\Resources\EntryReservationResource;
|
|||||||
use App\Domains\Ticketing\Desfile\Services\EntryReservationExcelService;
|
use App\Domains\Ticketing\Desfile\Services\EntryReservationExcelService;
|
||||||
use App\Domains\Ticketing\Desfile\Services\EntryReservationPdfService;
|
use App\Domains\Ticketing\Desfile\Services\EntryReservationPdfService;
|
||||||
use App\Domains\Ticketing\Desfile\Services\EntryReservationService;
|
use App\Domains\Ticketing\Desfile\Services\EntryReservationService;
|
||||||
|
use App\Domains\Ticketing\Ticket\Services\TicketPdfService;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
@@ -51,6 +52,20 @@ class EntryReservationController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadTicketPdf(
|
||||||
|
IndexEntryReservationsRequest $request,
|
||||||
|
int $reservation,
|
||||||
|
EntryReservationService $service,
|
||||||
|
TicketPdfService $pdf,
|
||||||
|
): Response {
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
return $pdf->download(
|
||||||
|
$user->tenant()->firstOrFail(),
|
||||||
|
collect([$service->reservationTicket($user, $reservation)]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function store(StoreEntryReservationsRequest $request, EntryReservationService $service): AnonymousResourceCollection
|
public function store(StoreEntryReservationsRequest $request, EntryReservationService $service): AnonymousResourceCollection
|
||||||
{
|
{
|
||||||
return EntryReservationResource::collection($service->reserve(
|
return EntryReservationResource::collection($service->reserve(
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ use App\Domains\Core\Auth\Models\User;
|
|||||||
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
||||||
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
||||||
use App\Domains\Ticketing\Ticket\Exceptions\TicketGenerationException;
|
use App\Domains\Ticketing\Ticket\Exceptions\TicketGenerationException;
|
||||||
|
use App\Domains\Ticketing\Ticket\Models\Ticket;
|
||||||
use App\Domains\Ticketing\Ticket\Services\TicketGeneratorService;
|
use App\Domains\Ticketing\Ticket\Services\TicketGeneratorService;
|
||||||
|
use App\Domains\Ticketing\Ticket\Services\TicketPresentationResolver;
|
||||||
|
use App\Domains\Ticketing\Ticket\Services\TicketValidityResolver;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -49,6 +52,25 @@ class EntryReservationService
|
|||||||
return $this->reservationsQuery($user, $filters)->get();
|
return $this->reservationsQuery($user, $filters)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function reservationTicket(User $user, int $reservationId): Ticket
|
||||||
|
{
|
||||||
|
abort_unless($user->tenant_codigo === 'desfile_pura_tendencia', 403);
|
||||||
|
|
||||||
|
$reservation = EntryReservation::query()
|
||||||
|
->whereKey($reservationId)
|
||||||
|
->whereNotNull('ticket_id')
|
||||||
|
->whereHas('variant.catalogItem', fn (Builder $query): Builder => $query
|
||||||
|
->where('tenant_code', $user->tenant_codigo)
|
||||||
|
->where('slug', 'entrada'))
|
||||||
|
->with(['ticket' => fn ($query) => $query->with([
|
||||||
|
...TicketValidityResolver::RELATIONS,
|
||||||
|
...TicketPresentationResolver::RELATIONS,
|
||||||
|
])])
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
return $reservation->ticket;
|
||||||
|
}
|
||||||
|
|
||||||
/** @param array{tipo_pago?: string|null} $filters */
|
/** @param array{tipo_pago?: string|null} $filters */
|
||||||
private function reservationsQuery(User $user, array $filters = []): Builder
|
private function reservationsQuery(User $user, array $filters = []): Builder
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ Route::get('v1/adminapp/tenant/desfile/entry-reservations/pdf', [EntryReservatio
|
|||||||
Route::get('v1/adminapp/tenant/desfile/entry-reservations/excel', [EntryReservationController::class, 'downloadExcel'])
|
Route::get('v1/adminapp/tenant/desfile/entry-reservations/excel', [EntryReservationController::class, 'downloadExcel'])
|
||||||
->middleware(['auth:sanctum', 'adminapp.tenant', 'tenant.menu:adminapp.desfile.reservas'])
|
->middleware(['auth:sanctum', 'adminapp.tenant', 'tenant.menu:adminapp.desfile.reservas'])
|
||||||
->name('adminapp.desfile.entry-reservations.excel');
|
->name('adminapp.desfile.entry-reservations.excel');
|
||||||
|
Route::get('v1/adminapp/tenant/desfile/entry-reservations/{reservation}/ticket/pdf', [EntryReservationController::class, 'downloadTicketPdf'])
|
||||||
|
->whereNumber('reservation')
|
||||||
|
->middleware(['auth:sanctum', 'adminapp.tenant', 'tenant.menu:adminapp.desfile.reservas'])
|
||||||
|
->name('adminapp.desfile.entry-reservations.ticket.pdf');
|
||||||
Route::post('v1/adminapp/tenant/desfile/entry-reservations', [EntryReservationController::class, 'store'])
|
Route::post('v1/adminapp/tenant/desfile/entry-reservations', [EntryReservationController::class, 'store'])
|
||||||
->middleware(['auth:sanctum', 'adminapp.tenant', 'tenant.menu:adminapp.desfile.reservas'])
|
->middleware(['auth:sanctum', 'adminapp.tenant', 'tenant.menu:adminapp.desfile.reservas'])
|
||||||
->name('adminapp.desfile.entry-reservations.store');
|
->name('adminapp.desfile.entry-reservations.store');
|
||||||
|
|||||||
@@ -353,6 +353,10 @@ class EntryReservationServiceTest extends TestCase
|
|||||||
$report = new EntryReservationReportService;
|
$report = new EntryReservationReportService;
|
||||||
|
|
||||||
$this->assertCount(1, $reservations);
|
$this->assertCount(1, $reservations);
|
||||||
|
$this->assertSame(
|
||||||
|
$reservations->sole()->ticket_id,
|
||||||
|
$service->reservationTicket($user, $reservations->sole()->id)->id,
|
||||||
|
);
|
||||||
$this->assertSame('Otro método', $report->rows($reservations)->sole()['pago']);
|
$this->assertSame('Otro método', $report->rows($reservations)->sole()['pago']);
|
||||||
|
|
||||||
$pdf = (new EntryReservationPdfService($report))->download(
|
$pdf = (new EntryReservationPdfService($report))->download(
|
||||||
|
|||||||
Reference in New Issue
Block a user