50 lines
2.0 KiB
PHP
50 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Shared\Forms\Services;
|
|
|
|
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
|
use App\Domains\Commerce\Catalog\Models\Variant;
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
|
|
|
class DesfileEntryReservationFormService
|
|
{
|
|
/** @return array<string, mixed> */
|
|
public function get(Tenant $tenant): array
|
|
{
|
|
$entry = CatalogItem::query()->forTenantCatalog($tenant)->where('slug', 'entrada')
|
|
->with([
|
|
'variants' => fn ($query) => $query->orderBy('id'),
|
|
'variants.inventory',
|
|
'variants.definitions.itemAttribute.attribute',
|
|
'variants.eventDates',
|
|
'variants.eventDate',
|
|
])->first();
|
|
$variants = $entry?->visibleVariants()
|
|
->map(function (Variant $variant): array {
|
|
$values = $variant->selectionValues();
|
|
|
|
return [
|
|
'id' => $variant->id,
|
|
'tipo' => (string) $values->get('tipo'),
|
|
'sector' => (string) $values->get('sector'),
|
|
'fila' => (string) $values->get('fila'),
|
|
'asiento' => (string) $values->get('asiento'),
|
|
'price' => $variant->getPrice(),
|
|
];
|
|
})->values() ?? collect();
|
|
|
|
return [
|
|
'payment_types' => EntryReservationPaymentType::options(),
|
|
'fields' => collect(['tipo' => 'Tipo', 'sector' => 'Sector', 'fila' => 'Fila', 'asiento' => 'Asiento'])
|
|
->map(fn (string $label, string $key): array => [
|
|
'key' => $key,
|
|
'label' => $label,
|
|
'options' => $variants->pluck($key)->unique()->sort(SORT_NATURAL)->values()
|
|
->map(fn (string $value): array => ['value' => $value, 'label' => $value])->all(),
|
|
])->values()->all(),
|
|
'variants' => $variants->all(),
|
|
];
|
|
}
|
|
}
|